Author: jfuerth
Date: Fri Nov 7 09:28:59 2008
New Revision: 2824
Modified:
branches/release-0.9.12/src/ca/sqlpower/architect/swingui/PlayPen.java
branches/release-0.9.12/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java
Log:
Merged r2718 - Fixed annoying 'select as you drag' behaviour
Modified:
branches/release-0.9.12/src/ca/sqlpower/architect/swingui/PlayPen.java
==============================================================================
--- branches/release-0.9.12/src/ca/sqlpower/architect/swingui/PlayPen.java
(original)
+++ branches/release-0.9.12/src/ca/sqlpower/architect/swingui/PlayPen.java
Fri Nov 7 09:28:59 2008
@@ -311,7 +311,8 @@
*/
protected boolean draggingTablePanes = false;
-
+ private boolean selectionInProgress = false;
+
/**
* A RenderingHints value of VALUE_ANTIALIAS_ON, VALUE_ANTIALIAS_OFF, or
VALUE_ANTIALIAS_DEFAULT.
*/
@@ -2262,7 +2263,8 @@
Point p = evt.getPoint();
unzoomPoint(p);
PlayPenComponent c = contentPane.getComponentAt(p);
-
+ selectionInProgress = true;
+
if (c instanceof PlayPenComponent) {
c.handleMouseEvent(evt);
} else {
@@ -2277,6 +2279,8 @@
public void mouseReleased(MouseEvent evt) {
draggingTablePanes = false;
+ selectionInProgress = false;
+
if (rubberBand != null && evt.getButton() ==
MouseEvent.BUTTON1) {
Rectangle dirtyRegion = rubberBand;
@@ -2382,6 +2386,15 @@
return rubberBand;
}
+ /**
+ * Returns true if there is a multi-select operation in progress. This
method
+ * is useful for selection listeners such as the selection
synchronizer that should
+ * not update their state while a selection is in progress.
+ */
+ public boolean isSelectionInProgress() {
+ return selectionInProgress;
+ }
+
public boolean isDraggingTablePanes() {
return draggingTablePanes;
}
Modified:
branches/release-0.9.12/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java
==============================================================================
---
branches/release-0.9.12/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java
(original)
+++
branches/release-0.9.12/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java
Fri Nov 7 09:28:59 2008
@@ -22,6 +22,8 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
@@ -76,6 +78,7 @@
pp.addSelectionListener(synchronizer);
dbTree.addTreeSelectionListener(synchronizer);
pp.getContentPane().addPlayPenContentListener(synchronizer);
+ pp.addMouseListener(synchronizer);
return pp;
}
@@ -235,7 +238,7 @@
}
static class SelectionSynchronizer implements SelectionListener,
ItemSelectionListener<SQLTable, SQLColumn>,
- TreeSelectionListener, PlayPenContentListener {
+ TreeSelectionListener, PlayPenContentListener, MouseListener {
private int eventDepth = 0;
@@ -255,8 +258,9 @@
*
*/
public void updateDBTree() {
- if (eventDepth != 1)
+ if (eventDepth != 1) {
return;
+ }
tree.clearSelection();
List<TreePath> selectionPaths = new ArrayList<TreePath>();
@@ -328,6 +332,9 @@
}
public void itemDeselected(SelectionEvent e) {
+ if (pp.isSelectionInProgress()) {
+ return;
+ }
try {
eventDepth++;
updateDBTree();
@@ -337,6 +344,9 @@
}
public void itemSelected(SelectionEvent e) {
+ if (pp.isSelectionInProgress()) {
+ return;
+ }
try {
eventDepth++;
updateDBTree();
@@ -346,6 +356,9 @@
}
public void itemsDeselected(ItemSelectionEvent<SQLTable,
SQLColumn> e) {
+ if (pp.isSelectionInProgress()) {
+ return;
+ }
try {
eventDepth++;
updateDBTree();
@@ -355,6 +368,9 @@
}
public void itemsSelected(ItemSelectionEvent<SQLTable, SQLColumn>
e) {
+ if (pp.isSelectionInProgress()) {
+ return;
+ }
try {
eventDepth++;
updateDBTree();
@@ -381,6 +397,33 @@
public void PlayPenComponentRemoved(PlayPenContentEvent e) {
if (e.getPlayPenComponent() instanceof ContainerPane<?, ?>) {
((ContainerPane<SQLTable, SQLColumn>)
e.getPlayPenComponent()).removeItemSelectionListener(this);
+ }
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ // don't care
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ // don't care
+ }
+
+ public void mouseExited(MouseEvent e) {
+ // don't care
+ }
+
+ public void mousePressed(MouseEvent e) {
+ // don't care
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if (e.getSource() == pp) {
+ eventDepth++;
+ try {
+ updateDBTree();
+ } finally {
+ eventDepth--;
+ }
}
}
}