Control and shift for col selection
authoramwaterhouse <Andrew Waterhouse>
Thu, 10 Aug 2006 13:40:59 +0000 (13:40 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 10 Aug 2006 13:40:59 +0000 (13:40 +0000)
src/jalview/appletgui/ScalePanel.java
src/jalview/gui/ScalePanel.java

index f72ea7b..5419d27 100755 (executable)
@@ -63,34 +63,18 @@ public class ScalePanel
 \r
     min = res;\r
     max = res;\r
-    if (reveal != null\r
-        && (evt.getModifiers() & InputEvent.BUTTON3_MASK)\r
+    if ((evt.getModifiers() & InputEvent.BUTTON3_MASK)\r
         == InputEvent.BUTTON3_MASK)\r
     {\r
-\r
-      MenuItem item = new MenuItem("Reveal");\r
-      item.addActionListener(new ActionListener()\r
-      {\r
-        public void actionPerformed(ActionEvent e)\r
-        {\r
-          av.showColumn(reveal[0]);\r
-          reveal = null;\r
-          ap.repaint();\r
-          if (ap.overviewPanel != null)\r
-            ap.overviewPanel.updateOverviewImage();\r
-        }\r
-      });\r
       PopupMenu pop = new PopupMenu();\r
-      pop.add(item);\r
-\r
-      if (av.getColumnSelection().getHiddenColumns().size() > 1)\r
+      if (reveal != null)\r
       {\r
-        item = new MenuItem("Reveal All");\r
+        MenuItem item = new MenuItem("Reveal");\r
         item.addActionListener(new ActionListener()\r
         {\r
           public void actionPerformed(ActionEvent e)\r
           {\r
-            av.showAllHiddenColumns();\r
+            av.showColumn(reveal[0]);\r
             reveal = null;\r
             ap.repaint();\r
             if (ap.overviewPanel != null)\r
@@ -98,16 +82,26 @@ public class ScalePanel
           }\r
         });\r
         pop.add(item);\r
-      }\r
 \r
-      this.add(pop);\r
-      pop.show(this, evt.getX(), evt.getY());\r
-\r
-    }\r
-    else if (av.getColumnSelection().contains(res))\r
-    {\r
-      if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK)\r
-          == InputEvent.BUTTON3_MASK)\r
+        if (av.getColumnSelection().getHiddenColumns().size() > 1)\r
+        {\r
+          item = new MenuItem("Reveal All");\r
+          item.addActionListener(new ActionListener()\r
+          {\r
+            public void actionPerformed(ActionEvent e)\r
+            {\r
+              av.showAllHiddenColumns();\r
+              reveal = null;\r
+              ap.repaint();\r
+              if (ap.overviewPanel != null)\r
+                ap.overviewPanel.updateOverviewImage();\r
+            }\r
+          });\r
+          pop.add(item);\r
+        }\r
+        pop.show(this, evt.getX(), evt.getY());\r
+      }\r
+      else if (av.getColumnSelection().contains(res))\r
       {\r
         MenuItem item = new MenuItem("Hide Columns");\r
         item.addActionListener(new ActionListener()\r
@@ -120,22 +114,19 @@ public class ScalePanel
               ap.overviewPanel.updateOverviewImage();\r
           }\r
         });\r
-        PopupMenu pop = new PopupMenu();\r
         pop.add(item);\r
-        this.add(pop);\r
         pop.show(this, evt.getX(), evt.getY());\r
       }\r
-      else\r
-      {\r
-        av.getColumnSelection().removeElement(res);\r
-        av.setSelectionGroup(null);\r
-      }\r
     }\r
-    else\r
+    else // LEFT MOUSE TO SELECT\r
     {\r
+      if (!evt.isControlDown() && !evt.isShiftDown())\r
+      {\r
+        av.getColumnSelection().clear();\r
+      }\r
+\r
       av.getColumnSelection().addElement(res);\r
       SequenceGroup sg = new SequenceGroup();\r
-\r
       for (int i = 0; i < av.alignment.getSequences().size(); i++)\r
       {\r
         sg.addSequence(av.alignment.getSequenceAt(i), false);\r
@@ -144,7 +135,20 @@ public class ScalePanel
       sg.setStartRes(res);\r
       sg.setEndRes(res);\r
       av.setSelectionGroup(sg);\r
+\r
+      if(evt.isShiftDown())\r
+      {\r
+        int min = Math.min(av.getColumnSelection().getMin(), res);\r
+        int max = Math.max(av.getColumnSelection().getMax(), res);\r
+        for (int i = min; i<max; i++)\r
+        {\r
+            av.getColumnSelection().addElement(i);\r
+        }\r
+        sg.setStartRes(min);\r
+        sg.setEndRes(max);\r
+      }\r
     }\r
+\r
     ap.repaint();\r
   }\r
 \r
index 262d1e1..8b53b46 100755 (executable)
@@ -73,9 +73,11 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList
         min = res;\r
         max = res;\r
 \r
-        if(reveal != null && SwingUtilities.isRightMouseButton(evt))\r
+        if (SwingUtilities.isRightMouseButton(evt))\r
+        {\r
+          JPopupMenu pop = new JPopupMenu();\r
+          if (reveal != null)\r
           {\r
-            JPopupMenu pop = new JPopupMenu();\r
             JMenuItem item = new JMenuItem("Reveal");\r
             item.addActionListener(new ActionListener()\r
             {\r
@@ -84,13 +86,13 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList
                 av.showColumn(reveal[0]);\r
                 reveal = null;\r
                 ap.repaint();\r
-                if(ap.overviewPanel != null)\r
-                    ap.overviewPanel.updateOverviewImage();\r
+                if (ap.overviewPanel != null)\r
+                  ap.overviewPanel.updateOverviewImage();\r
               }\r
             });\r
             pop.add(item);\r
 \r
-            if(av.getColumnSelection().getHiddenColumns().size()>1)\r
+            if (av.getColumnSelection().getHiddenColumns().size() > 1)\r
             {\r
               item = new JMenuItem("Reveal All");\r
               item.addActionListener(new ActionListener()\r
@@ -100,22 +102,16 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList
                   av.showAllHiddenColumns();\r
                   reveal = null;\r
                   ap.repaint();\r
-                  if(ap.overviewPanel != null)\r
+                  if (ap.overviewPanel != null)\r
                     ap.overviewPanel.updateOverviewImage();\r
                 }\r
               });\r
               pop.add(item);\r
             }\r
-\r
             pop.show(this, evt.getX(), evt.getY());\r
-\r
           }\r
-        else\r
-      if (av.getColumnSelection().contains(res))\r
-        {\r
-          if( SwingUtilities.isRightMouseButton(evt))\r
+          else if (av.getColumnSelection().contains(res))\r
           {\r
-            JPopupMenu pop = new JPopupMenu();\r
             JMenuItem item = new JMenuItem("Hide Columns");\r
             item.addActionListener(new ActionListener()\r
             {\r
@@ -123,33 +119,45 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList
               {\r
                 av.hideColumns(res, res);\r
                 ap.repaint();\r
-                if(ap.overviewPanel != null)\r
+                if (ap.overviewPanel != null)\r
                   ap.overviewPanel.updateOverviewImage();\r
               }\r
             });\r
             pop.add(item);\r
             pop.show(this, evt.getX(), evt.getY());\r
-\r
-          }\r
-          else\r
-          {\r
-            av.getColumnSelection().removeElement(res);\r
-            av.setSelectionGroup(null);\r
           }\r
         }\r
-        else\r
+        else // LEFT MOUSE TO SELECT\r
         {\r
-            av.getColumnSelection().addElement(res);\r
-            SequenceGroup sg = new SequenceGroup();\r
+          if (!evt.isControlDown() && !evt.isShiftDown())\r
+          {\r
+            av.getColumnSelection().clear();\r
+          }\r
+\r
+          av.getColumnSelection().addElement(res);\r
+          SequenceGroup sg = new SequenceGroup();\r
+          for (int i = 0; i < av.alignment.getSequences().size(); i++)\r
+          {\r
+            sg.addSequence(av.alignment.getSequenceAt(i), false);\r
+          }\r
+\r
+          sg.setStartRes(res);\r
+          sg.setEndRes(res);\r
+          av.setSelectionGroup(sg);\r
 \r
-            for (int i = 0; i < av.alignment.getSequences().size(); i++)\r
+          if(evt.isShiftDown())\r
+          {\r
+            int min = Math.min(av.getColumnSelection().getMin(), res);\r
+            int max = Math.max(av.getColumnSelection().getMax(), res);\r
+            for (int i = min; i<max; i++)\r
             {\r
-                sg.addSequence(av.alignment.getSequenceAt(i), false);\r
+                av.getColumnSelection().addElement(i);\r
             }\r
+            sg.setStartRes(min);\r
+            sg.setEndRes(max);\r
+          }\r
+\r
 \r
-            sg.setStartRes(res);\r
-            sg.setEndRes(res);\r
-            av.setSelectionGroup(sg);\r
         }\r
 \r
 \r