Example #1
0
 @Override
 public void addLayoutComponent(Component aComponent, Object aConstraints) {
   if (aConstraints instanceof MarginConstraints) {
     MarginConstraints constraints = (MarginConstraints) aConstraints;
     // horizontal check
     if (constraints.getWidth() == null
         && (constraints.getLeft() == null || constraints.getRight() == null)) {
       throw new IllegalStateException(MarginConstraints.HORIZONTAL_VALUE_MISSING);
     } else if (constraints.getWidth() != null
         && constraints.getLeft() == null
         && constraints.getRight() == null) {
       throw new IllegalStateException(MarginConstraints.HORIZONTAL_VALUE_MISSING);
     }
     // vertical check
     if (constraints.getHeight() == null
         && (constraints.getTop() == null || constraints.getBottom() == null)) {
       throw new IllegalStateException(MarginConstraints.HORIZONTAL_VALUE_MISSING);
     } else if (constraints.getHeight() != null
         && constraints.getTop() == null
         && constraints.getBottom() == null) {
       throw new IllegalStateException(MarginConstraints.HORIZONTAL_VALUE_MISSING);
     }
     layouted.put(aComponent, constraints);
   } else {
     throw new IllegalArgumentException("The constraints must be instance of MarginConstraints");
   }
 }
Example #2
0
 public static void ajustHeight(java.awt.Component aChild, int aValue) {
   assert aChild.getParent().getLayout() instanceof MarginLayout;
   MarginLayout layout = (MarginLayout) aChild.getParent().getLayout();
   MarginConstraints anchors = layout.getLayoutConstraints(aChild);
   int containerHeight = aChild.getParent().getHeight();
   int childTop = aChild.getLocation().y;
   if (anchors.getHeight() != null) {
     anchors.getHeight().setPlainValue(aValue, containerHeight);
   } else if (anchors.getTop() != null && anchors.getBottom() != null) {
     anchors.getBottom().setPlainValue(containerHeight - childTop - aValue, containerHeight);
   }
   aChild.getParent().revalidate();
   aChild.getParent().repaint();
 }