Author: jfuerth
Date: Tue Sep 23 15:30:29 2008
New Revision: 2718

Modified:
   trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
   trunk/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java

Log:
Fixed the annoying "select as you drag" behaviour. Now the selection synchronization is deferred until the user releases the mouse button. Behaviour when changing the selection with the keyboard was fine before, and it remains unchanged.

Modified: trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/PlayPen.java        (original)
+++ trunk/src/ca/sqlpower/architect/swingui/PlayPen.java Tue Sep 23 15:30:29 2008
@@ -313,7 +313,8 @@
      */
        protected boolean draggingTablePanes = false;

-
+       private boolean selectionInProgress = false;
+       
        /**
* A RenderingHints value of VALUE_ANTIALIAS_ON, VALUE_ANTIALIAS_OFF, or VALUE_ANTIALIAS_DEFAULT.
         */
@@ -2277,7 +2278,8 @@
                        Point p = evt.getPoint();
                        unzoomPoint(p);
                        PlayPenComponent c = contentPane.getComponentAt(p);
-                       
+            selectionInProgress = true;
+
                        if (c instanceof PlayPenComponent) {
                            c.handleMouseEvent(evt);
                        } else {
@@ -2292,6 +2294,8 @@

                public void mouseReleased(MouseEvent evt) {
                        draggingTablePanes = false;
+            selectionInProgress = false;
+
                        if (rubberBand != null && evt.getButton() == 
MouseEvent.BUTTON1) {
                            Rectangle dirtyRegion = rubberBand;

@@ -2397,6 +2401,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: trunk/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/RelationalPlayPenFactory.java Tue Sep 23 15:30:29 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--;
+                }
             }
         }
     }

Reply via email to