Revision: 1017
Author: heuermh
Date: Wed Apr 28 09:48:20 2010
Log: Issue 177 ; adding additional unit tests and applying patch
http://code.google.com/p/piccolo2d/source/detail?r=1017
Modified:
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/event/PSelectionEventHandlerTest.java
=======================================
---
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
Mon Jan 18 16:07:38 2010
+++
/piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java
Wed Apr 28 09:48:20 2010
@@ -783,13 +783,14 @@
* @param e the key press event
*/
public void keyPressed(final PInputEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_DELETE && deleteKeyActive) {
+ if (e.getKeyCode() == KeyEvent.VK_DELETE && deleteKeyActive
&& !selection.isEmpty()) {
final Iterator selectionEn = selection.keySet().iterator();
while (selectionEn.hasNext()) {
final PNode node = (PNode) selectionEn.next();
node.removeFromParent();
}
selection.clear();
+ postSelectionChanged();
}
}
=======================================
---
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/event/PSelectionEventHandlerTest.java
Tue Apr 27 13:58:11 2010
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/event/PSelectionEventHandlerTest.java
Wed Apr 28 09:48:20 2010
@@ -53,6 +53,24 @@
{
selectionChanged = false;
}
+
+ public void testSelectionChange()
+ {
+ PCanvas canvas = new PCanvas();
+ PLayer layer = canvas.getLayer();
+ PNode node = new PNode();
+ layer.addChild(node);
+
+ PSelectionEventHandler selectionHandler = new
PSelectionEventHandler(layer, layer);
+ assertTrue(selectionHandler.getSelectionReference().isEmpty());
+
+ PNotificationCenter notificationCenter =
PNotificationCenter.defaultCenter();
+ notificationCenter.addListener(this, "selectionChanged",
PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, null);
+
+ selectionHandler.select(node);
+
assertTrue(selectionHandler.getSelectionReference().contains(node));
+ assertTrue(selectionChanged);
+ }
/**
* {...@link http://code.google.com/p/piccolo2d/issues/detail?id=177}
@@ -76,15 +94,56 @@
PInputEvent event = new PInputEvent(null, keyEvent);
selectionHandler.keyPressed(event);
assertTrue(selectionHandler.getSelectionReference().isEmpty());
-
- // fix this assertion to fix issue 177 linked above
- //assertTrue(selectionChanged);
+ assertTrue(selectionChanged);
+ }
+
+ public void testKeyboardDeleteInactive()
+ {
+ PCanvas canvas = new PCanvas();
+ PLayer layer = canvas.getLayer();
+ PNode node = new PNode();
+ layer.addChild(node);
+
+ PSelectionEventHandler selectionHandler = new
PSelectionEventHandler(layer, layer);
+ selectionHandler.setDeleteKeyActive(false);
+ selectionHandler.select(node);
+
assertTrue(selectionHandler.getSelectionReference().contains(node));
+
+ PNotificationCenter notificationCenter =
PNotificationCenter.defaultCenter();
+ notificationCenter.addListener(this, "selectionChanged",
PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, null);
+
+ KeyEvent keyEvent = new KeyEvent(canvas, -1,
System.currentTimeMillis(), 0, KeyEvent.VK_DELETE);
+ PInputEvent event = new PInputEvent(null, keyEvent);
+ selectionHandler.keyPressed(event);
+
assertTrue(selectionHandler.getSelectionReference().contains(node));
+ assertFalse(selectionChanged);
+ }
+
+ public void testKeyboardDeleteEmptySelection()
+ {
+ PCanvas canvas = new PCanvas();
+ PLayer layer = canvas.getLayer();
+
+ PSelectionEventHandler selectionHandler = new
PSelectionEventHandler(layer, layer);
+ selectionHandler.setDeleteKeyActive(true);
+ assertTrue(selectionHandler.getSelectionReference().isEmpty());
+
+ PNotificationCenter notificationCenter =
PNotificationCenter.defaultCenter();
+ notificationCenter.addListener(this, "selectionChanged",
PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, null);
+
+ KeyEvent keyEvent = new KeyEvent(canvas, -1,
System.currentTimeMillis(), 0, KeyEvent.VK_DELETE);
+ PInputEvent event = new PInputEvent(null, keyEvent);
+ selectionHandler.keyPressed(event);
+ assertTrue(selectionHandler.getSelectionReference().isEmpty());
+ assertFalse(selectionChanged);
}
/**
* Selection changed, called by PNotificationCenter.
+ *
+ * @param notification notification
*/
- public void selectionChanged()
+ public void selectionChanged(final PNotification notification)
{
this.selectionChanged = true;
}
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en