Revision: 1227
Author: heuermh
Date: Tue Nov 26 22:54:38 2013 UTC
Log: Issue 166 ; refactor PNode moveToBack and related
http://code.google.com/p/piccolo2d/source/detail?r=1227
Modified:
/piccolo2d.java/branches/3.0-spike/core/src/main/java/org/piccolo2d/PNode.java
/piccolo2d.java/branches/3.0-spike/core/src/main/java/org/piccolo2d/event/PDragEventHandler.java
/piccolo2d.java/branches/3.0-spike/core/src/test/java/org/piccolo2d/PNodeTest.java
/piccolo2d.java/branches/3.0-spike/core/src/test/java/org/piccolo2d/event/PDragEventHandlerTest.java
/piccolo2d.java/branches/3.0-spike/examples/src/main/java/org/piccolo2d/examples/GridExample.java
/piccolo2d.java/branches/3.0-spike/examples/src/main/java/org/piccolo2d/tutorial/PiccoloPresentation.java
=======================================
---
/piccolo2d.java/branches/3.0-spike/core/src/main/java/org/piccolo2d/PNode.java
Tue Sep 4 16:10:27 2012 UTC
+++
/piccolo2d.java/branches/3.0-spike/core/src/main/java/org/piccolo2d/PNode.java
Tue Nov 26 22:54:38 2013 UTC
@@ -3234,7 +3234,7 @@
/**
* Return true if this node descends from the root.
- *
+ *
* @return whether this node descends from root node
*/
public boolean isDescendentOfRoot() {
@@ -3242,37 +3242,43 @@
}
/**
- * Change the order of this node in its parent's children list so that
it
- * will draw in back of all of its other sibling nodes.
+ * Raise this node within the Z-order of its parent.
+ *
+ * @since 3.0
*/
- public void moveToBack() {
+ public void raise() {
final PNode p = parent;
if (p != null) {
- p.removeChild(this);
- p.addChild(0, this);
+ final int index = parent.indexOfChild(this);
+ final int siblingIndex = Math.min(parent.getChildrenCount() -
1, index + 1);
+ if (siblingIndex != index) {
+ raiseAbove(parent.getChild(siblingIndex));
+ }
}
}
/**
- * Change the order of this node in its parent's children list so that
it
- * will draw in back of the specified sibling node.
- *
- * @param sibling sibling to move in back of
+ * Lower this node within the Z-order of its parent.
+ *
+ * @since 3.0
*/
- public void moveInBackOf(final PNode sibling) {
+ public void lower() {
final PNode p = parent;
- if (p != null && p == sibling.getParent()) {
- p.removeChild(this);
- final int index = p.indexOfChild(sibling);
- p.addChild(index, this);
+ if (p != null) {
+ final int index = parent.indexOfChild(this);
+ final int siblingIndex = Math.max(0, index - 1);
+ if (siblingIndex != index) {
+ lowerBelow(parent.getChild(siblingIndex));
+ }
}
}
/**
- * Change the order of this node in its parent's children list so that
it
- * will draw in front of all of its other sibling nodes.
+ * Raise this node within the Z-order of its parent to the top.
+ *
+ * @since 3.0
*/
- public void moveToFront() {
+ public void raiseToTop() {
final PNode p = parent;
if (p != null) {
p.removeChild(this);
@@ -3281,19 +3287,95 @@
}
/**
- * Change the order of this node in its parent's children list so that
it
- * will draw in front of the specified sibling node.
- *
- * @param sibling sibling to move in front of
+ * Lower this node within the Z-order of its parent to the bottom.
+ *
+ * @since 3.0
*/
- public void moveInFrontOf(final PNode sibling) {
+ public void lowerToBottom() {
final PNode p = parent;
+ if (p != null) {
+ p.removeChild(this);
+ p.addChild(0, this);
+ }
+ }
+
+ /**
+ * Raise this node within the Z-order of its parent above the
specified sibling node.
+ *
+ * @since 3.0
+ * @param sibling sibling node to raise this node above
+ */
+ public void raiseAbove(final PNode sibling) {
+ final PNode p = parent;
if (p != null && p == sibling.getParent()) {
p.removeChild(this);
final int index = p.indexOfChild(sibling);
p.addChild(index + 1, this);
}
}
+
+ /**
+ * Lower this node within the Z-order of its parent below the
specified sibling node.
+ *
+ * @since 3.0
+ * @param sibling sibling node to lower this node below
+ */
+ public void lowerBelow(final PNode sibling) {
+ final PNode p = parent;
+ if (p != null && p == sibling.getParent()) {
+ p.removeChild(this);
+ final int index = p.indexOfChild(sibling);
+ p.addChild(index, this);
+ }
+ }
+
+ /**
+ * Raise the specified child node within the Z-order of this.
+ *
+ * @since 3.0
+ * @param child child node to raise
+ */
+ public void raise(final PNode child) {
+ if (children != null && children.contains(child) &&
this.equals(child.getParent())) {
+ child.raise();
+ }
+ }
+
+ /**
+ * Lower the specified child node within the Z-order of this.
+ *
+ * @since 3.0
+ * @param child child node to lower
+ */
+ public void lower(final PNode child) {
+ if (children != null && children.contains(child) &&
this.equals(child.getParent())) {
+ child.lower();
+ }
+ }
+
+ /**
+ * Raise the specified child node within the Z-order of this to the
top.
+ *
+ * @since 3.0
+ * @param child child node to raise to the top
+ */
+ public void raiseToTop(final PNode child) {
+ if (children != null && children.contains(child) &&
this.equals(child.getParent())) {
+ child.raiseToTop();
+ }
+ }
+
+ /**
+ * Lower the specified child node within the Z-order of this to the
bottom.
+ *
+ * @since 3.0
+ * @param child child node to lower to the bottom
+ */
+ public void lowerToBottom(final PNode child) {
+ if (children != null && children.contains(child) &&
this.equals(child.getParent())) {
+ child.lowerToBottom();
+ }
+ }
/**
* Return the parent of this node. This will be null if this node has
not
=======================================
---
/piccolo2d.java/branches/3.0-spike/core/src/main/java/org/piccolo2d/event/PDragEventHandler.java
Tue Mar 15 22:23:53 2011 UTC
+++
/piccolo2d.java/branches/3.0-spike/core/src/main/java/org/piccolo2d/event/PDragEventHandler.java
Tue Nov 26 22:54:38 2013 UTC
@@ -44,15 +44,15 @@
public class PDragEventHandler extends PDragSequenceEventHandler {
private PNode draggedNode;
- private boolean moveToFrontOnPress;
+ private boolean raiseToTopOnPress;
/**
- * Constructs a drag event handler which defaults to not moving the
node to
- * the front on drag.
+ * Constructs a drag event handler which defaults to not raising the
node to
+ * the top on drag.
*/
public PDragEventHandler() {
draggedNode = null;
- moveToFrontOnPress = false;
+ raiseToTopOnPress = false;
setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
}
@@ -88,15 +88,15 @@
/**
* Starts a drag event and moves the dragged node to the front if this
- * handler has been directed to do so with a call to
setMoveToFrontOnDrag.
+ * handler has been directed to do so with a call to
setRaiseToTopOnDrag.
*
* @param event The Event responsible for the start of the drag
*/
protected void startDrag(final PInputEvent event) {
super.startDrag(event);
draggedNode = event.getPickedNode();
- if (moveToFrontOnPress) {
- draggedNode.moveToFront();
+ if (raiseToTopOnPress) {
+ draggedNode.raiseToTop();
}
}
@@ -124,23 +124,23 @@
}
/**
- * Returns whether this drag event handler has been informed to move
nodes
- * to the front of all other on drag.
+ * Returns whether this drag event handler has been informed to raise
nodes
+ * to the top of all other on drag.
*
- * @return true if dragging a node will move it to the front
+ * @return true if dragging a node will raise it to the top
*/
- public boolean getMoveToFrontOnPress() {
- return moveToFrontOnPress;
+ public boolean getRaiseToTopOnPress() {
+ return raiseToTopOnPress;
}
/**
- * Informs this drag event handler whether it should move nodes to the
front
+ * Informs this drag event handler whether it should raise nodes to
the top
* when they are dragged. Default is false.
*
- * @param moveToFrontOnPress true if dragging a node should move it to
the
- * front
+ * @param raiseToTopOnPress true if dragging a node should raise it to
the
+ * top
*/
- public void setMoveToFrontOnPress(final boolean moveToFrontOnPress) {
- this.moveToFrontOnPress = moveToFrontOnPress;
+ public void setRaiseToTopOnPress(final boolean raiseToTopOnPress) {
+ this.raiseToTopOnPress = raiseToTopOnPress;
}
}
=======================================
---
/piccolo2d.java/branches/3.0-spike/core/src/test/java/org/piccolo2d/PNodeTest.java
Tue Mar 15 22:23:53 2011 UTC
+++
/piccolo2d.java/branches/3.0-spike/core/src/test/java/org/piccolo2d/PNodeTest.java
Tue Nov 26 22:54:38 2013 UTC
@@ -1315,38 +1315,166 @@
assertFalse(grandChild.isDescendentOf(unrelated));
}
- public void testMoveToBackMovesNodeToBeFirstChild() {
+ public void testRaise() {
final PNode parent = new PNode();
+ parent.addChild(node);
parent.addChild(new PNode());
parent.addChild(new PNode());
+ node.raise();
+ assertEquals(1, parent.indexOfChild(node));
+ }
+
+ public void testRaiseOnly() {
+ final PNode parent = new PNode();
parent.addChild(node);
- node.moveToBack();
+ node.raise();
assertEquals(0, parent.indexOfChild(node));
}
- public void testMoveToFrontMovesNodeToBeLastChild() {
+ public void testLower() {
final PNode parent = new PNode();
+ parent.addChild(new PNode());
+ parent.addChild(new PNode());
parent.addChild(node);
+ node.lower();
+ assertEquals(1, parent.indexOfChild(node));
+ }
+
+ public void testLowerOnly() {
+ final PNode parent = new PNode();
+ parent.addChild(node);
+ node.lower();
+ assertEquals(0, parent.indexOfChild(node));
+ }
+
+ public void testRaiseToTop() {
+ final PNode parent = new PNode();
+ parent.addChild(node);
parent.addChild(new PNode());
parent.addChild(new PNode());
- node.moveToFront();
+ node.raiseToTop();
assertEquals(2, parent.indexOfChild(node));
}
- public void testMoveInBackOfMovesNodeToBeforeSibling() {
+ public void testRaiseToTopOnly() {
final PNode parent = new PNode();
+ parent.addChild(node);
+ node.raiseToTop();
+ assertEquals(0, parent.indexOfChild(node));
+ }
+
+ public void testLowerToBottom() {
+ final PNode parent = new PNode();
+ parent.addChild(new PNode());
+ parent.addChild(new PNode());
+ parent.addChild(node);
+ node.lowerToBottom();
+ assertEquals(0, parent.indexOfChild(node));
+ }
+
+ public void testLowerToBottomOnly() {
+ final PNode parent = new PNode();
+ parent.addChild(node);
+ node.lowerToBottom();
+ assertEquals(0, parent.indexOfChild(node));
+ }
+
+ public void testRaiseAbove() {
+ final PNode parent = new PNode();
+ parent.addChild(node);
final PNode sibling = new PNode();
+ parent.addChild(sibling);
+ parent.addChild(new PNode());
+ node.raiseAbove(sibling);
+ assertEquals(1, parent.indexOfChild(node));
+ }
+ public void testLowerBelow() {
+ final PNode parent = new PNode();
+ parent.addChild(new PNode());
+ final PNode sibling = new PNode();
+ parent.addChild(sibling);
+ parent.addChild(node);
+ node.lowerBelow(sibling);
+ assertEquals(1, parent.indexOfChild(node));
+ }
+
+ public void testRaiseChild() {
+ final PNode child0 = new PNode();
+ final PNode child1 = new PNode();
+ final PNode child2 = new PNode();
+ node.addChild(child0);
+ node.addChild(child1);
+ node.addChild(child2);
+ node.raise(child0);
+ assertEquals(1, node.indexOfChild(child0));
+ }
+
+ public void testLowerChild() {
+ final PNode child0 = new PNode();
+ final PNode child1 = new PNode();
+ final PNode child2 = new PNode();
+ node.addChild(child0);
+ node.addChild(child1);
+ node.addChild(child2);
+ node.lower(child2);
+ assertEquals(1, node.indexOfChild(child2));
+ }
+
+ public void testRaiseChildToTop() {
+ final PNode child0 = new PNode();
+ final PNode child1 = new PNode();
+ final PNode child2 = new PNode();
+ node.addChild(child0);
+ node.addChild(child1);
+ node.addChild(child2);
+ node.raiseToTop(child0);
+ assertEquals(2, node.indexOfChild(child0));
+ }
+
+ public void testLowerChildToBottom() {
+ final PNode child0 = new PNode();
+ final PNode child1 = new PNode();
+ final PNode child2 = new PNode();
+ node.addChild(child0);
+ node.addChild(child1);
+ node.addChild(child2);
+ node.lowerToBottom(child2);
+ assertEquals(0, node.indexOfChild(child2));
+ }
+
+ public void testLowerToBottomMovesNodeToBeFirstChild() {
+ final PNode parent = new PNode();
+ parent.addChild(new PNode());
+ parent.addChild(new PNode());
+ parent.addChild(node);
+ node.lowerToBottom();
+ assertEquals(0, parent.indexOfChild(node));
+ }
+
+ public void testRaiseToTopMovesNodeToBeLastChild() {
+ final PNode parent = new PNode();
+ parent.addChild(node);
+ parent.addChild(new PNode());
+ parent.addChild(new PNode());
+ node.raiseToTop();
+ assertEquals(2, parent.indexOfChild(node));
+ }
+
+ public void testLowerBelowMovesNodeToBeforeSibling() {
+ final PNode parent = new PNode();
+ final PNode sibling = new PNode();
+
parent.addChild(node);
parent.addChild(new PNode());
parent.addChild(new PNode());
parent.addChild(sibling);
- node.moveInBackOf(sibling);
+ node.lowerBelow(sibling);
assertEquals(2, parent.indexOfChild(node));
}
- public void testMoveInFrontOfMovesNodeToAfterSibling() {
+ public void testRaiseAboveMovesNodeToAfterSibling() {
final PNode parent = new PNode();
final PNode sibling = new PNode();
@@ -1355,11 +1483,11 @@
parent.addChild(new PNode());
parent.addChild(sibling);
- node.moveInFrontOf(sibling);
+ node.raiseAbove(sibling);
assertEquals(3, parent.indexOfChild(node));
}
- public void testMoveInFrontOfDoesNothingIfNotSibling() {
+ public void testRaiseAboveDoesNothingIfNotSibling() {
final PNode parent = new PNode();
final PNode stranger = new PNode();
@@ -1367,11 +1495,11 @@
parent.addChild(new PNode());
parent.addChild(new PNode());
- node.moveInFrontOf(stranger);
+ node.raiseAbove(stranger);
assertEquals(0, parent.indexOfChild(node));
}
- public void testMoveInBackOfDoesNothingIfNotSibling() {
+ public void testLowerBelowDoesNothingIfNotSibling() {
final PNode parent = new PNode();
final PNode stranger = new PNode();
@@ -1379,7 +1507,7 @@
parent.addChild(new PNode());
parent.addChild(new PNode());
- node.moveInBackOf(stranger);
+ node.lowerBelow(stranger);
assertEquals(0, parent.indexOfChild(node));
}
=======================================
---
/piccolo2d.java/branches/3.0-spike/core/src/test/java/org/piccolo2d/event/PDragEventHandlerTest.java
Tue Mar 15 22:23:53 2011 UTC
+++
/piccolo2d.java/branches/3.0-spike/core/src/test/java/org/piccolo2d/event/PDragEventHandlerTest.java
Tue Nov 26 22:54:38 2013 UTC
@@ -42,13 +42,13 @@
handler = new PDragEventHandler();
}
- public void testMoveToFrontOnPressDefaultToFalse() {
- assertFalse(handler.getMoveToFrontOnPress());
+ public void testRaiseToTopOnPressDefaultToFalse() {
+ assertFalse(handler.getRaiseToTopOnPress());
}
- public void testMoveToFrontOnPressPersists() {
- handler.setMoveToFrontOnPress(true);
- assertTrue(handler.getMoveToFrontOnPress());
+ public void testRaiseToTopOnPressPersists() {
+ handler.setRaiseToTopOnPress(true);
+ assertTrue(handler.getRaiseToTopOnPress());
}
}
=======================================
---
/piccolo2d.java/branches/3.0-spike/examples/src/main/java/org/piccolo2d/examples/GridExample.java
Tue Mar 15 22:23:53 2011 UTC
+++
/piccolo2d.java/branches/3.0-spike/examples/src/main/java/org/piccolo2d/examples/GridExample.java
Tue Nov 26 22:54:38 2013 UTC
@@ -155,7 +155,7 @@
protected void startDrag(final PInputEvent event) {
super.startDrag(event);
draggedNode = event.getPickedNode();
- draggedNode.moveToFront();
+ draggedNode.raiseToTop();
nodeStartPosition = draggedNode.getOffset();
}
=======================================
---
/piccolo2d.java/branches/3.0-spike/examples/src/main/java/org/piccolo2d/tutorial/PiccoloPresentation.java
Tue Mar 15 22:23:53 2011 UTC
+++
/piccolo2d.java/branches/3.0-spike/examples/src/main/java/org/piccolo2d/tutorial/PiccoloPresentation.java
Tue Nov 26 22:54:38 2013 UTC
@@ -74,7 +74,7 @@
final PNode picked = event.getPickedNode();
if (picked.getParent() == slideBar) {
- picked.moveToFront();
+ picked.raiseToTop();
if (picked.getScale() == 1) {
goToSlide(null);
}
@@ -100,7 +100,7 @@
currentSlide = slide;
if (currentSlide != null) {
- currentSlide.moveToFront();
+ currentSlide.raiseToTop();
currentSlide.animateToTransform((AffineTransform)
currentSlide.getAttribute("large"), 1000);
}
}
--
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
---
You received this message because you are subscribed to the Google Groups "Piccolo2D Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.