示例#1
0
 @Override
 public void layoutContainer(Container aContainer) {
   layouted
       .entrySet()
       .stream()
       .forEach(
           (entry) -> {
             Component comp = entry.getKey();
             if (comp.isVisible()) {
               Dimension containerSize = aContainer.getSize();
               MarginConstraints constraints = entry.getValue();
               Rectangle bounds =
                   constraints.toRectangle(containerSize.width, containerSize.height);
               comp.setBounds(bounds);
             }
           });
 }
示例#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();
 }
示例#3
0
 public static void ajustWidth(Component aChild, int aValue) {
   assert aChild.getParent().getLayout() instanceof MarginLayout;
   MarginLayout layout = (MarginLayout) aChild.getParent().getLayout();
   MarginConstraints anchors = layout.getLayoutConstraints(aChild);
   int containerWidth = aChild.getParent().getWidth();
   int childLeft = aChild.getLocation().x;
   if (anchors.getWidth() != null) {
     anchors.getWidth().setPlainValue(aValue, containerWidth);
   } else if (anchors.getLeft() != null && anchors.getRight() != null) {
     anchors.getRight().setPlainValue(containerWidth - childLeft - aValue, containerWidth);
   }
   aChild.getParent().revalidate();
   aChild.getParent().repaint();
 }
示例#4
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");
   }
 }