[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] libvob/org/nongnu/libvob/mouse MouseMultiplexer...
From: |
Matti Katila |
Subject: |
[ff-cvs] libvob/org/nongnu/libvob/mouse MouseMultiplexer... |
Date: |
Thu, 11 Sep 2003 11:32:09 -0400 |
CVSROOT: /cvsroot/libvob
Module name: libvob
Branch:
Changes by: Matti Katila <address@hidden> 03/09/11 11:32:09
Modified files:
org/nongnu/libvob/mouse: MouseMultiplexer.java
RelativeAdapter.java multiplex.test
Log message:
post checkking the commit, fixes ugly bug of dragging and click events
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/mouse/MouseMultiplexer.java.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/mouse/RelativeAdapter.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/mouse/multiplex.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: libvob/org/nongnu/libvob/mouse/MouseMultiplexer.java
diff -u libvob/org/nongnu/libvob/mouse/MouseMultiplexer.java:1.8
libvob/org/nongnu/libvob/mouse/MouseMultiplexer.java:1.9
--- libvob/org/nongnu/libvob/mouse/MouseMultiplexer.java:1.8 Sat Aug 9
10:39:45 2003
+++ libvob/org/nongnu/libvob/mouse/MouseMultiplexer.java Thu Sep 11
11:32:09 2003
@@ -163,6 +163,14 @@
currentDrag = null;
}
+ /** Whether a drag from a mouse press and a
+ * subsequent mouse motion event has been started.
+ * It is extremely not allowed to call the
+ * endDrag() method if there were no drag events,
+ * otherwise clicked and endDrag methods
+ * are probably both called.
+ */
+ private boolean dragStarted = false;
/** Send an event to the correct listener.
* @return true if the event was used by this multiplexer.
@@ -175,12 +183,14 @@
if(mpl == null) return false;
currentDrag = mpl.pressed(e.getX(), e.getY());
if(currentDrag != null) {
+ dragStarted = false;
currentDragButton = e.getButton();
currentDrag.startDrag(e.getX(), e.getY());
return true;
}
} else if(e.getType() == e.MOUSE_DRAGGED) {
if(currentDrag != null) {
+ dragStarted = true;
currentDrag.drag(e.getX(), e.getY());
return true;
}
@@ -188,7 +198,8 @@
if(currentDragButton != 0 &&
e.getButton() == currentDragButton) {
currentDragButton = 0;
- currentDrag.endDrag(e.getX(), e.getY());
+ if (dragStarted)
+ currentDrag.endDrag(e.getX(), e.getY());
currentDrag = null;
return true;
}
Index: libvob/org/nongnu/libvob/mouse/RelativeAdapter.java
diff -u libvob/org/nongnu/libvob/mouse/RelativeAdapter.java:1.3
libvob/org/nongnu/libvob/mouse/RelativeAdapter.java:1.4
--- libvob/org/nongnu/libvob/mouse/RelativeAdapter.java:1.3 Mon Aug 18
11:21:52 2003
+++ libvob/org/nongnu/libvob/mouse/RelativeAdapter.java Thu Sep 11 11:32:09 2003
@@ -35,11 +35,7 @@
protected float multiplier = 1.0f;
public void endDrag(int x, int y) {
- /** endDrag comes when mouse released is done.
- * (mouse clicked is also done...)
- * ARGH!!
- */
- // *NOT* doIt(x,y);
+ doIt(x,y);
}
public void startDrag(int x, int y) {
x_=x; y_=y;
Index: libvob/org/nongnu/libvob/mouse/multiplex.test
diff -u libvob/org/nongnu/libvob/mouse/multiplex.test:1.1
libvob/org/nongnu/libvob/mouse/multiplex.test:1.2
--- libvob/org/nongnu/libvob/mouse/multiplex.test:1.1 Mon Sep 8 00:40:11 2003
+++ libvob/org/nongnu/libvob/mouse/multiplex.test Thu Sep 11 11:32:09 2003
@@ -34,3 +34,66 @@
vob.VobMouseEvent.MOUSE_PRESSED,
0, 0, 0, vob.VobMouseEvent.CONTROL_MASK, 1))
+
+
+def testClearClickAndDrag():
+ class ListenerAndDrag(vob.mouse.MousePressListener,
vob.mouse.MouseDragListener):
+ def __init__(self, test):
+ self.test = test
+ def pressed(self, x,y): return self
+ def startDrag(self, x,y):
+ pass
+ def drag(self, x,y):
+ self.test.chg()
+ def endDrag(self, x,y):
+ self.test.chg()
+ class Click(vob.mouse.MouseClickListener):
+ def __init__(self, test): self.test = test
+ def clicked(self, x,y): self.test.chg()
+
+ class Object:
+ def __init__(self): self.done = 0
+ def chg(self): self.done = 1
+
+ press = vob.VobMouseEvent(
+ vob.VobMouseEvent.MOUSE_PRESSED,
+ 0, 0, 0, 0, 1)
+ drag = vob.VobMouseEvent(
+ vob.VobMouseEvent.MOUSE_DRAGGED,
+ 0, 0, 0, 0, 1)
+ click = vob.VobMouseEvent(
+ vob.VobMouseEvent.MOUSE_CLICKED,
+ 0, 0, 0, 0, 1)
+ released = vob.VobMouseEvent(
+ vob.VobMouseEvent.MOUSE_RELEASED,
+ 0, 0, 0, 0, 1)
+
+ # no drag - test
+ clickTest = Object()
+ dragTest = Object()
+ mul = vob.mouse.MouseMultiplexer()
+ mul.setListener(1,0, 'click', Click(clickTest))
+ mul.setListener(1,0, 'drag', ListenerAndDrag(dragTest))
+
+ mul.deliverEvent(press)
+ mul.deliverEvent(released)
+ assert clickTest.done == 0
+ mul.deliverEvent(click)
+ assert clickTest.done == 1
+ assert dragTest.done == 0
+
+ # no click - test
+ clickTest = Object()
+ dragTest = Object()
+ mul = vob.mouse.MouseMultiplexer()
+ mul.setListener(1,0, 'click', Click(clickTest))
+ mul.setListener(1,0, 'drag', ListenerAndDrag(dragTest))
+
+ mul.deliverEvent(press)
+ assert dragTest.done == 0
+ mul.deliverEvent(drag)
+ assert dragTest.done == 1
+ mul.deliverEvent(released)
+ assert dragTest.done == 1
+ assert clickTest.done == 0
+
- [ff-cvs] libvob/org/nongnu/libvob/mouse MouseMultiplexer...,
Matti Katila <=