@Test public void testMoveForward() throws Exception { final Coords base = new Coords(0, 0); final Coords northMove = NORTH.moveForward(NORTH.moveForward(NORTH.moveForward(base))); assertEquals(new Coords(0, 3), northMove); final Coords southMove = SOUTH.moveForward(SOUTH.moveForward(SOUTH.moveForward(base))); assertEquals(new Coords(0, -3), southMove); final Coords eastMove = EAST.moveForward(EAST.moveForward(EAST.moveForward(base))); assertEquals(new Coords(3, 0), eastMove); final Coords westMove = WEST.moveForward(WEST.moveForward(WEST.moveForward(base))); assertEquals(new Coords(-3, 0), westMove); }
@Test public void testTurnLeft() throws Exception { assertEquals(NORTH.turnLeft(), WEST); assertEquals(WEST.turnLeft(), SOUTH); assertEquals(SOUTH.turnLeft(), EAST); assertEquals(EAST.turnLeft(), NORTH); }
/** * Returns the location where to dock the given {@code JToolBar}, at the given constraint * position. The constraint position must be one of the constants {@code BorderLayout.NORTH * NORTH}, {@code BorderLayout.EAST EAST}, {@code BorderLayout.SOUTH SOUTH}, or {@code * BorderLayout.WEST WEST}. * * <p><b>Note:</b> This method is accessed in the current executing thread. Such thread may or may * not be the event dispatch thread (EDT.) Client code must call this method from the EDT. * * @param toolBar the target {@code JToolBar}. * @param dock the container where to dock the {@code JToolBar} to. * @param constraint the constraint position. * @return the location where to dock the given {@code JToolBar}. * @throws IllegalArgumentException if the constraint has an invalid value. */ @RunsInCurrentThread public @Nonnull Point dockLocation( @Nonnull JToolBar toolBar, @Nonnull Container dock, @Nonnull String constraint) { checkValid(constraint); Insets insets = dock.getInsets(); // BasicToolBarUI prioritizes location N/E/W/S by proximity to the respective border. Close to // top border is N, even // if close to the left or right border. int offset = isHorizontal(toolBar) ? toolBar.getHeight() : toolBar.getWidth(); Dimension dockSize = dock.getSize(); if (NORTH.equals(constraint)) { return new Point(dockSize.width / 2, insets.top); } if (EAST.equals(constraint)) { return new Point( dockSize.width - insets.right - 1, verticalDockingYCoordinate(dockSize.height, insets, offset)); } if (WEST.equals(constraint)) { return new Point(insets.left, verticalDockingYCoordinate(dockSize.height, insets, offset)); } int x = dockSize.width / 2; // Make sure we don't get mistaken for EAST or WEST if (x < insets.left + offset) { x = insets.left + offset; } else if (x > dockSize.width - insets.right - offset - 1) { x = dockSize.width - insets.right - offset - 1; } return new Point(x, dockSize.height - insets.bottom - 1); }
/** {@inheritDoc} */ @Override public void add(IComponent pComponent, Object pConstraints, int pIndex) { if (pConstraints == null || CENTER.equals(pConstraints)) { resource.setCenter((Node) pComponent.getResource()); } else if (EAST.equals(pConstraints)) { resource.setRight((Node) pComponent.getResource()); } else if (NORTH.equals(pConstraints)) { resource.setTop((Node) pComponent.getResource()); } else if (SOUTH.equals(pConstraints)) { resource.setBottom((Node) pComponent.getResource()); } else if (WEST.equals(pConstraints)) { resource.setLeft((Node) pComponent.getResource()); } else { resource.setCenter((Node) pComponent.getResource()); } BorderPane.setAlignment((Node) pComponent.getResource(), Pos.CENTER); updateGaps(); }