EdgeLayout extends AbstractLayout { public void layout(Container container) { Map<Location, Drawable> comps = getComponentsByLocation(container); Drawable north = comps.get(Location.NORTH); Drawable northEast = comps.get(Location.NORTH_EAST); Drawable east = comps.get(Location.EAST); Drawable southEast = comps.get(Location.SOUTH_EAST); Drawable south = comps.get(Location.SOUTH); Drawable southWest = comps.get(Location.SOUTH_WEST); Drawable west = comps.get(Location.WEST); Drawable northWest = comps.get(Location.NORTH_WEST); Drawable center = comps.get(Location.CENTER); double widthWest = getMaxWidth(northWest, west, southWest); double widthEast = getMaxWidth(northEast, east, southEast); double heightNorth = getMaxHeight(northWest, north, northEast); double heightSouth = getMaxHeight(southWest, south, southEast); double gapWest = (widthWest > 0.0 && center != null) ? getGapX() : 0.0; double gapEast = (widthEast > 0.0 && center != null) ? getGapX() : 0.0; double gapNorth = (heightNorth > 0.0 && center != null) ? getGapY() : 0.0; double gapSouth = (heightSouth > 0.0 && center != null) ? getGapY() : 0.0; Rectangle2D bounds = container.getBounds(); Insets2D insets = container.getInsets(); if (insets == null) { insets = new Insets2D.Double(); } double xWest = bounds.getMinX() + insets.getLeft(); double xCenter = xWest + widthWest + gapWest; double xEast = bounds.getMaxX() - insets.getRight() - widthEast; double yNorth = bounds.getMinY() + insets.getTop(); double yCenter = yNorth + heightNorth + gapNorth; double ySouth = bounds.getMaxY() - insets.getBottom() - heightSouth; double widthAll = widthWest + widthEast; double heightAll = heightNorth + heightSouth; double gapHAll = gapWest + gapEast; double gapVAll = gapNorth - gapSouth; layoutComponent(northWest, xWest, yNorth, widthWest, heightNorth ); layoutComponent(north, xCenter, yNorth, bounds.getWidth() - insets.getHorizontal() - widthAll - gapHAll, heightNorth ); layoutComponent(northEast, xEast, yNorth, widthEast, heightNorth ); layoutComponent(east, xEast, yCenter, widthEast, bounds.getHeight() - insets.getVertical() - heightAll - gapVAll ); layoutComponent(southEast, xEast, ySouth, widthEast, heightSouth ); layoutComponent(south, xCenter, ySouth, bounds.getWidth() - insets.getHorizontal() - widthAll - gapHAll, heightSouth ); layoutComponent(southWest, xWest, ySouth, widthWest, heightSouth ); layoutComponent(west, xWest, yCenter, widthWest, bounds.getHeight() - insets.getVertical() - heightAll - gapVAll ); layoutComponent(center, xCenter, yCenter, bounds.getWidth() - insets.getLeft() - widthAll - insets.getRight() - gapHAll, bounds.getHeight() - insets.getTop() - heightAll - insets.getBottom() - gapVAll ); } EdgeLayout(double gapH, double gapV);  EdgeLayout(); void layout(Container container); Dimension2D getPreferredSize(Container container);  }
@Test public void testLayout() { Rectangle2D bounds = new Rectangle2D.Double(5.0, 5.0, 50.0, 50.0); container.setBounds(bounds); layout.layout(container); assertEquals(bounds.getMinX(), nw.getX(), DELTA); assertEquals(bounds.getMinX(), ww.getX(), DELTA); assertEquals(bounds.getMinX(), sw.getX(), DELTA); assertEquals(bounds.getMinX() + COMP_WIDTH + GAP_H, nn.getX(), DELTA); assertEquals(bounds.getMinX() + COMP_WIDTH + GAP_H, ce.getX(), DELTA); assertEquals(bounds.getMinX() + COMP_WIDTH + GAP_H, ss.getX(), DELTA); assertEquals(bounds.getMaxX() - COMP_WIDTH, ne.getX(), DELTA); assertEquals(bounds.getMaxX() - COMP_WIDTH, ee.getX(), DELTA); assertEquals(bounds.getMaxX() - COMP_WIDTH, se.getX(), DELTA); assertEquals(bounds.getMinY(), nw.getY(), DELTA); assertEquals(bounds.getMinY(), nn.getY(), DELTA); assertEquals(bounds.getMinY(), ne.getY(), DELTA); assertEquals(bounds.getMinY() + COMP_HEIGHT + GAP_V, ww.getY(), DELTA); assertEquals(bounds.getMinY() + COMP_HEIGHT + GAP_V, ce.getY(), DELTA); assertEquals(bounds.getMinY() + COMP_HEIGHT + GAP_V, ee.getY(), DELTA); assertEquals(bounds.getMaxY() - COMP_HEIGHT, sw.getY(), DELTA); assertEquals(bounds.getMaxY() - COMP_HEIGHT, ss.getY(), DELTA); assertEquals(bounds.getMaxY() - COMP_HEIGHT, se.getY(), DELTA); }