diff options
| author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-05-06 14:29:37 +0100 | 
|---|---|---|
| committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-05-06 14:29:37 +0100 | 
| commit | 8189116ea4b5db4675e31dfd04a5687d55e29262 (patch) | |
| tree | c1815021452a888f8838f1628d8fb4689777e73e /src/jcgp/gui/dragresize | |
| parent | aa9e74e7f67789f6353fc26e02ee8e68e40609a2 (diff) | |
Added javadocs, made minor changes to the comments
Diffstat (limited to 'src/jcgp/gui/dragresize')
| -rw-r--r-- | src/jcgp/gui/dragresize/HorizontalDragResize.java | 51 | ||||
| -rw-r--r-- | src/jcgp/gui/dragresize/VerticalDragResize.java | 46 | 
2 files changed, 91 insertions, 6 deletions
| diff --git a/src/jcgp/gui/dragresize/HorizontalDragResize.java b/src/jcgp/gui/dragresize/HorizontalDragResize.java index 84c322f..b618b74 100644 --- a/src/jcgp/gui/dragresize/HorizontalDragResize.java +++ b/src/jcgp/gui/dragresize/HorizontalDragResize.java @@ -7,9 +7,11 @@ import javafx.scene.layout.Region;  import jcgp.gui.GUI;  /** - *  - * Decorator pattern. - *  + * This class adds horizontal drag resize functionality to any  + * arbitrary region provided. This is done by using the static + * method {@code makeDragResizable()}. + * <br><br> + * This is based on a class by Andrew Till found on:   * http://andrewtill.blogspot.co.uk/2012/12/dragging-to-resize-javafx-region.html   *    */ @@ -18,13 +20,29 @@ public class HorizontalDragResize {  	private boolean dragging = false;  	private final Region region; +	/** +	 * For internal use only, creates an instance of the actual +	 * resizer used. +	 *  +	 * @param region the region to make resizable. +	 */  	private HorizontalDragResize(Region region) {  		this.region = region;  	} +	/** +	 * Makes the specified region drag resizable. +	 * This particular implementation only creates a resize  +	 * click-and-drag area on the left side of the region.  +	 * The resize area is defined by {@code GUI.RESIZE_MARGIN}. +	 *  +	 * @param region the region to make resizable. +	 */  	public static void makeDragResizable(final Region region) { +		// make the instance, this actually performs the resizing  		final HorizontalDragResize dr = new HorizontalDragResize(region); +		// set mouse listeners  		region.setOnMousePressed(new EventHandler<MouseEvent>() {  			@Override  			public void handle(MouseEvent event) { @@ -52,12 +70,22 @@ public class HorizontalDragResize {  	} +	/** +	 * If the press happened in the resize area, raise the drag flag. +	 *  +	 * @param event the associated mouse event. +	 */  	private void mousePressed(MouseEvent event) {  		if(isInDraggableZone(event)) {  	        dragging = true;          }  	} +	/** +	 * If drag flag is high, resize the region to match the mouse position. +	 *  +	 * @param event the associated mouse event. +	 */  	private void mouseDragged(MouseEvent event) {  		if(dragging) {  			double newWidth = region.getWidth() - event.getX(); @@ -69,20 +97,33 @@ public class HorizontalDragResize {  		}  	} +	/** +	 * Change the cursor if the mouse position overlaps with the resize area. +	 *  +	 * @param event the associated mouse event. +	 */  	private void mouseMoved(MouseEvent event) {  		if(isInDraggableZone(event) || dragging) {  			region.setCursor(Cursor.H_RESIZE); -		} -		else { +		} else {  			region.setCursor(Cursor.DEFAULT);  		}  	} +	/** +	 * Finish resizing. +	 */  	private void mouseReleased() {  		dragging = false;  		region.setCursor(Cursor.DEFAULT);  	} +	/** +	 * Assert whether the mouse cursor is in the draggable area defined by {@code GUI.RESIZE_MARGIN}. +	 *  +	 * @param event the associated mouse event. +	 * @return true if the mouse position is in the draggable area. +	 */  	private boolean isInDraggableZone(MouseEvent event) {  		return event.getX() < (GUI.RESIZE_MARGIN);  	} diff --git a/src/jcgp/gui/dragresize/VerticalDragResize.java b/src/jcgp/gui/dragresize/VerticalDragResize.java index 9397e5d..06186c6 100644 --- a/src/jcgp/gui/dragresize/VerticalDragResize.java +++ b/src/jcgp/gui/dragresize/VerticalDragResize.java @@ -7,7 +7,11 @@ import javafx.scene.layout.Region;  import jcgp.gui.GUI;  /** - *  + * This class adds vertical drag resize functionality to any  + * arbitrary region provided. This is done by using the static + * method {@code makeDragResizable()}. + * <br><br> + * This is based on a class by Andrew Till found on:   * http://andrewtill.blogspot.co.uk/2012/12/dragging-to-resize-javafx-region.html   *    */ @@ -16,13 +20,29 @@ public class VerticalDragResize {  	private boolean dragging = false;  	private final Region region; +	/** +	 * For internal use only, creates an instance of the actual +	 * resizer used. +	 *  +	 * @param region the region to make resizable. +	 */  	private VerticalDragResize(Region region) {  		this.region = region;  	} +	/** +	 * Makes the specified region drag resizable. +	 * This particular implementation only creates a resize  +	 * click-and-drag area on the top side of the region.  +	 * The resize area is defined by {@code GUI.RESIZE_MARGIN}. +	 *  +	 * @param region the region to make resizable. +	 */  	public static void makeDragResizable(final Region region) { +		// make the instance, this actually performs the resizing  		final VerticalDragResize dr = new VerticalDragResize(region); +		// set mouse listeners  		region.setOnMousePressed(new EventHandler<MouseEvent>() {  			@Override  			public void handle(MouseEvent event) { @@ -50,12 +70,22 @@ public class VerticalDragResize {  	} +	/** +	 * If the press happened in the resize area, raise the drag flag. +	 *  +	 * @param event the associated mouse event. +	 */  	private void mousePressed(MouseEvent event) {  		if(isInDraggableZone(event)) {  	        dragging = true;          }  	} +	/** +	 * If drag flag is high, resize the region to match the mouse position. +	 *  +	 * @param event the associated mouse event. +	 */  	private void mouseDragged(MouseEvent event) {  		if(dragging) {  			double newHeight = region.getHeight() - event.getY(); @@ -67,6 +97,11 @@ public class VerticalDragResize {  		}  	} +	/** +	 * Change the cursor if the mouse position overlaps with the resize area. +	 *  +	 * @param event the associated mouse event. +	 */  	private void mouseMoved(MouseEvent event) {  		if(isInDraggableZone(event) || dragging) {  			region.setCursor(Cursor.V_RESIZE); @@ -76,11 +111,20 @@ public class VerticalDragResize {          }  	} +	/** +	 * Finish resizing. +	 */  	private void mouseReleased() {  		dragging = false;  		region.setCursor(Cursor.DEFAULT);  	} +	/** +	 * Assert whether the mouse cursor is in the draggable area defined by {@code GUI.RESIZE_MARGIN}. +	 *  +	 * @param event the associated mouse event. +	 * @return true if the mouse position is in the draggable area. +	 */  	private boolean isInDraggableZone(MouseEvent event) {  		return event.getY() < (GUI.RESIZE_MARGIN);  	} | 
