From e2399fe0a610faf5dee11a68a8643c34e3ef2490 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 11 Jan 2016 12:37:52 +0000 Subject: [PATCH] JAL-1989 additional ways to 'mirror' show/hide columns in split frame --- src/jalview/appletgui/AlignFrame.java | 13 +++ src/jalview/appletgui/ScalePanel.java | 185 +++++++++++++++++++-------------- src/jalview/gui/AlignFrame.java | 5 + src/jalview/gui/ScalePanel.java | 179 +++++++++++++++++-------------- 4 files changed, 224 insertions(+), 158 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index cd679fc..b7e7899 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -759,6 +759,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { viewport.showAllHiddenColumns(); } + viewport.sendSelection(); } } @@ -1080,11 +1081,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, else if (source == invertSequenceMenuItem) { invertSequenceMenuItem_actionPerformed(); + // uncomment to slave sequence selections in split frame + // viewport.sendSelection(); } else if (source == invertColSel) { viewport.invertColumnSelection(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } else if (source == remove2LeftMenuItem) { @@ -1118,27 +1122,34 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { viewport.showAllHiddenColumns(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } else if (source == showSeqs) { viewport.showAllHiddenSeqs(); alignPanel.paintAlignment(true); + // uncomment if we want to slave sequence selections in split frame + // viewport.sendSelection(); } else if (source == hideColumns) { viewport.hideSelectedColumns(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } else if (source == hideSequences && viewport.getSelectionGroup() != null) { viewport.hideAllSelectedSeqs(); alignPanel.paintAlignment(true); + // uncomment if we want to slave sequence selections in split frame + // viewport.sendSelection(); } else if (source == hideAllButSelection) { toggleHiddenRegions(false, false); alignPanel.paintAlignment(true); + viewport.sendSelection(); } else if (source == hideAllSelection) { @@ -1147,12 +1158,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.hideAllSelectedSeqs(); viewport.hideSelectedColumns(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } else if (source == showAllHidden) { viewport.showAllHiddenColumns(); viewport.showAllHiddenSeqs(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } else if (source == showGroupConsensus) { diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index cd50f3f..3c6a4f1 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -89,112 +89,137 @@ public class ScalePanel extends Panel implements MouseMotionListener, max = res; if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - PopupMenu pop = new PopupMenu(); - if (reveal != null) + rightMouseButtonPressed(evt, res); + } + else + { + leftMouseButtonPressed(evt, res); + } + } + + /** + * Handles left mouse button pressed (selection / clear selections) + * + * @param evt + * @param res + */ + protected void leftMouseButtonPressed(MouseEvent evt, final int res) + { + if (!evt.isControlDown() && !evt.isShiftDown()) + { + av.getColumnSelection().clear(); + } + + av.getColumnSelection().addElement(res); + SequenceGroup sg = new SequenceGroup(); + for (int i = 0; i < av.getAlignment().getSequences().size(); i++) + { + sg.addSequence(av.getAlignment().getSequenceAt(i), false); + } + + sg.setStartRes(res); + sg.setEndRes(res); + av.setSelectionGroup(sg); + + if (evt.isShiftDown()) + { + int min = Math.min(av.getColumnSelection().getMin(), res); + int max = Math.max(av.getColumnSelection().getMax(), res); + for (int i = min; i < max; i++) { - MenuItem item = new MenuItem( - MessageManager.getString("label.reveal")); - item.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - av.showColumn(reveal[0]); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - pop.add(item); + av.getColumnSelection().addElement(i); + } + sg.setStartRes(min); + sg.setEndRes(max); + } + ap.paintAlignment(true); + av.sendSelection(); + } - if (av.getColumnSelection().hasManyHiddenColumns()) + /** + * Handles right mouse button press. If pressed in a selected column, opens + * context menu for 'Hide Columns'. If pressed on a hidden columns marker, + * opens context menu for 'Reveal / Reveal All'. Else does nothing. + * + * @param evt + * @param res + */ + protected void rightMouseButtonPressed(MouseEvent evt, final int res) + { + PopupMenu pop = new PopupMenu(); + if (reveal != null) + { + MenuItem item = new MenuItem( + MessageManager.getString("label.reveal")); + item.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) { - item = new MenuItem(MessageManager.getString("action.reveal_all")); - item.addActionListener(new ActionListener() + av.showColumn(reveal[0]); + reveal = null; + ap.paintAlignment(true); + if (ap.overviewPanel != null) { - @Override - public void actionPerformed(ActionEvent e) - { - av.showAllHiddenColumns(); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - pop.add(item); + ap.overviewPanel.updateOverviewImage(); + } + av.sendSelection(); } - this.add(pop); - pop.show(this, evt.getX(), evt.getY()); - } - else if (av.getColumnSelection().contains(res)) + }); + pop.add(item); + + if (av.getColumnSelection().hasManyHiddenColumns()) { - MenuItem item = new MenuItem( - MessageManager.getString("label.hide_columns")); + item = new MenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - av.hideColumns(res, res); - if (av.getSelectionGroup() != null - && av.getSelectionGroup().getSize() == av - .getAlignment().getHeight()) - { - av.setSelectionGroup(null); - } - + av.showAllHiddenColumns(); + reveal = null; ap.paintAlignment(true); if (ap.overviewPanel != null) { ap.overviewPanel.updateOverviewImage(); } + av.sendSelection(); } }); pop.add(item); - this.add(pop); - pop.show(this, evt.getX(), evt.getY()); } + this.add(pop); + pop.show(this, evt.getX(), evt.getY()); } - else - // LEFT MOUSE TO SELECT + else if (av.getColumnSelection().contains(res)) { - if (!evt.isControlDown() && !evt.isShiftDown()) - { - av.getColumnSelection().clear(); - } - - av.getColumnSelection().addElement(res); - SequenceGroup sg = new SequenceGroup(); - for (int i = 0; i < av.getAlignment().getSequences().size(); i++) - { - sg.addSequence(av.getAlignment().getSequenceAt(i), false); - } - - sg.setStartRes(res); - sg.setEndRes(res); - av.setSelectionGroup(sg); - - if (evt.isShiftDown()) + MenuItem item = new MenuItem( + MessageManager.getString("label.hide_columns")); + item.addActionListener(new ActionListener() { - int min = Math.min(av.getColumnSelection().getMin(), res); - int max = Math.max(av.getColumnSelection().getMax(), res); - for (int i = min; i < max; i++) + @Override + public void actionPerformed(ActionEvent e) { - av.getColumnSelection().addElement(i); + av.hideColumns(res, res); + if (av.getSelectionGroup() != null + && av.getSelectionGroup().getSize() == av + .getAlignment().getHeight()) + { + av.setSelectionGroup(null); + } + + ap.paintAlignment(true); + if (ap.overviewPanel != null) + { + ap.overviewPanel.updateOverviewImage(); + } + av.sendSelection(); } - sg.setStartRes(min); - sg.setEndRes(max); - } + }); + pop.add(item); + this.add(pop); + pop.show(this, evt.getX(), evt.getY()); } - - ap.paintAlignment(true); - av.sendSelection(); } @Override diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 8aae64f..c615f6c 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -2966,6 +2966,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { viewport.showAllHiddenColumns(); repaint(); + viewport.sendSelection(); } @Override @@ -3056,6 +3057,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void hideAllButSelection_actionPerformed(ActionEvent e) { toggleHiddenRegions(false, false); + viewport.sendSelection(); } /* @@ -3073,6 +3075,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.hideAllSelectedSeqs(); viewport.hideSelectedColumns(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } /* @@ -3088,6 +3091,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.showAllHiddenColumns(); viewport.showAllHiddenSeqs(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } @Override @@ -3095,6 +3099,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { viewport.hideSelectedColumns(); alignPanel.paintAlignment(true); + viewport.sendSelection(); } @Override diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 10963b6..b2c9a12 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -109,66 +109,56 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (SwingUtilities.isRightMouseButton(evt)) { - JPopupMenu pop = new JPopupMenu(); - if (reveal != null) + rightMouseButtonPressed(evt, res); + } + else + { + leftMouseButtonPressed(evt, res); + } + } + + /** + * Handles right mouse button press. If pressed in a selected column, opens + * context menu for 'Hide Columns'. If pressed on a hidden columns marker, + * opens context menu for 'Reveal / Reveal All'. Else does nothing. + * + * @param evt + * @param res + */ + protected void rightMouseButtonPressed(MouseEvent evt, final int res) + { + JPopupMenu pop = new JPopupMenu(); + if (reveal != null) + { + JMenuItem item = new JMenuItem( + MessageManager.getString("label.reveal")); + item.addActionListener(new ActionListener() { - JMenuItem item = new JMenuItem( - MessageManager.getString("label.reveal")); - item.addActionListener(new ActionListener() + @Override + public void actionPerformed(ActionEvent e) { - @Override - public void actionPerformed(ActionEvent e) + av.showColumn(reveal[0]); + reveal = null; + ap.paintAlignment(true); + if (ap.overviewPanel != null) { - av.showColumn(reveal[0]); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } + ap.overviewPanel.updateOverviewImage(); } - }); - pop.add(item); - - if (av.getColumnSelection().hasHiddenColumns()) - { - item = new JMenuItem( - MessageManager.getString("action.reveal_all")); - item.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - av.showAllHiddenColumns(); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - pop.add(item); + av.sendSelection(); } - pop.show(this, evt.getX(), evt.getY()); - } - else if (av.getColumnSelection().contains(res)) + }); + pop.add(item); + + if (av.getColumnSelection().hasHiddenColumns()) { - JMenuItem item = new JMenuItem( - MessageManager.getString("label.hide_columns")); + item = new JMenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - av.hideColumns(res, res); - if (av.getSelectionGroup() != null - && av.getSelectionGroup().getSize() == av - .getAlignment().getHeight()) - { - av.setSelectionGroup(null); - } - + av.showAllHiddenColumns(); + reveal = null; ap.paintAlignment(true); if (ap.overviewPanel != null) { @@ -178,44 +168,77 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } }); pop.add(item); - pop.show(this, evt.getX(), evt.getY()); } + pop.show(this, evt.getX(), evt.getY()); } - else - // LEFT MOUSE TO SELECT + else if (av.getColumnSelection().contains(res)) { - if (!evt.isControlDown() && !evt.isShiftDown()) + JMenuItem item = new JMenuItem( + MessageManager.getString("label.hide_columns")); + item.addActionListener(new ActionListener() { - av.getColumnSelection().clear(); - } + @Override + public void actionPerformed(ActionEvent e) + { + av.hideColumns(res, res); + if (av.getSelectionGroup() != null + && av.getSelectionGroup().getSize() == av.getAlignment() + .getHeight()) + { + av.setSelectionGroup(null); + } - av.getColumnSelection().addElement(res); - SequenceGroup sg = new SequenceGroup(); - // try to be as quick as possible - SequenceI[] iVec = av.getAlignment().getSequencesArray(); - for (int i = 0; i < iVec.length; i++) - { - sg.addSequence(iVec[i], false); - iVec[i] = null; - } - iVec = null; - sg.setStartRes(res); - sg.setEndRes(res); + ap.paintAlignment(true); + if (ap.overviewPanel != null) + { + ap.overviewPanel.updateOverviewImage(); + } + av.sendSelection(); + } + }); + pop.add(item); + pop.show(this, evt.getX(), evt.getY()); + } + } - if (evt.isShiftDown()) + /** + * Handles left mouse button press + * + * @param evt + * @param res + */ + protected void leftMouseButtonPressed(MouseEvent evt, final int res) + { + if (!evt.isControlDown() && !evt.isShiftDown()) + { + av.getColumnSelection().clear(); + } + + av.getColumnSelection().addElement(res); + SequenceGroup sg = new SequenceGroup(); + // try to be as quick as possible + SequenceI[] iVec = av.getAlignment().getSequencesArray(); + for (int i = 0; i < iVec.length; i++) + { + sg.addSequence(iVec[i], false); + iVec[i] = null; + } + iVec = null; + sg.setStartRes(res); + sg.setEndRes(res); + + if (evt.isShiftDown()) + { + int min = Math.min(av.getColumnSelection().getMin(), res); + int max = Math.max(av.getColumnSelection().getMax(), res); + for (int i = min; i < max; i++) { - int min = Math.min(av.getColumnSelection().getMin(), res); - int max = Math.max(av.getColumnSelection().getMax(), res); - for (int i = min; i < max; i++) - { - av.getColumnSelection().addElement(i); - } - sg.setStartRes(min); - sg.setEndRes(max); + av.getColumnSelection().addElement(i); } - av.setSelectionGroup(sg); + sg.setStartRes(min); + sg.setEndRes(max); } - + av.setSelectionGroup(sg); ap.paintAlignment(false); av.sendSelection(); } -- 1.7.10.2