r2834 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing
Author: kmorin Date: 2014-05-16 18:04:19 +0200 (Fri, 16 May 2014) New Revision: 2834 Url: http://forge.nuiton.org/projects/jaxx/repository/revisions/2834 Log: fixes #3202 Enable the component resizer to resize only horizontally or vertically Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/ComponentResizer.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/ComponentResizer.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/ComponentResizer.java 2014-05-14 14:57:04 UTC (rev 2833) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/ComponentResizer.java 2014-05-16 16:04:19 UTC (rev 2834) @@ -47,6 +47,11 @@ * @since 2.5.10 */ public class ComponentResizer extends MouseAdapter { + + public static final String DIRECTION_VERTICAL = "vertical"; + public static final String DIRECTION_HORIZONTAL = "horizontal"; + public static final String DIRECTION_BOTH = "both"; + private final static Dimension MINIMUM_SIZE = new Dimension(10, 10); private final static Dimension MAXIMUM_SIZE = @@ -93,6 +98,8 @@ private Dimension maximumSize = MAXIMUM_SIZE; + protected Map<Component, String> authorizedDirectionByComponent = new HashMap<Component, String>(); + /** * Convenience contructor. All borders are resizable in increments of * a single pixel. Components must be registered separately. @@ -213,6 +220,7 @@ for (Component component : components) { component.removeMouseListener(this); component.removeMouseMotionListener(this); + authorizedDirectionByComponent.remove(component); } } @@ -222,9 +230,14 @@ * @param components the component the listeners are added to */ public void registerComponent(Component... components) { + registerComponent(DIRECTION_BOTH, components); + } + + public void registerComponent(String authorizedDirection, Component... components) { for (Component component : components) { component.addMouseListener(this); component.addMouseMotionListener(this); + authorizedDirectionByComponent.put(component, authorizedDirection); } } @@ -273,16 +286,18 @@ Point location = e.getPoint(); direction = 0; - if (location.x < dragInsets.left) + String authorizedDirection = authorizedDirectionByComponent.get(source); + + if (location.x < dragInsets.left && !DIRECTION_VERTICAL.equals(authorizedDirection)) direction += WEST; - if (location.x > source.getWidth() - dragInsets.right - 1) + if (location.x > source.getWidth() - dragInsets.right - 1 && !DIRECTION_VERTICAL.equals(authorizedDirection)) direction += EAST; - if (location.y < dragInsets.top) + if (location.y < dragInsets.top && !DIRECTION_HORIZONTAL.equals(authorizedDirection)) direction += NORTH; - if (location.y > source.getHeight() - dragInsets.bottom - 1) + if (location.y > source.getHeight() - dragInsets.bottom - 1 && !DIRECTION_HORIZONTAL.equals(authorizedDirection)) direction += SOUTH; // Mouse is no longer over a resizable border
participants (1)
-
kmorin@users.nuiton.org