From: gmungoc Date: Mon, 11 Jan 2021 17:08:38 +0000 (+0000) Subject: JAL-3117 raise AlignFrame or SplitFrame when Overview clicked X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ffeature%2FJAL-3117_overviewFocusAlignment;p=jalview.git JAL-3117 raise AlignFrame or SplitFrame when Overview clicked --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 4a18067..604e813 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -38,6 +38,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyAdapter; @@ -412,7 +413,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false)) { - this.overviewMenuItem_actionPerformed(null); + this.overviewMenuItem_actionPerformed(); } addKeyListener(); @@ -479,7 +480,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } ap.updateLayout(); - ap.setSelected(true); + ap.setSelected(true, true); ap.alignFrame.setMenusForViewport(); } @@ -3423,13 +3424,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Opens a new Overview window for the current alignment view, unless one is + * open already, in which case does nothing. */ @Override - public void overviewMenuItem_actionPerformed(ActionEvent e) + public void overviewMenuItem_actionPerformed() { if (alignPanel.overviewPanel != null) { @@ -3460,24 +3459,43 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { frame.addKeyListener(getKeyListeners()[0]); } - - /* - * bring alignment panel to front when Overview gets focus - * (even after New View / eXpand / Gather!) - */ + final AlignmentPanel ap = alignPanel; frame.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { + /* + * bring alignment panel to front when Overview gets focus + * (AlignFrame, or SplitFrame if alignment is in a split frame) + */ + ap.setSelected(true, true); + + /* + * restore focus to the Overview + * (temporarily removing the focus listener) + */ + FocusListener me = frame.getFocusListeners()[0]; + frame.removeFocusListener(me); try { - ap.alignFrame.setSelected(true); - ap.alignFrame.setIcon(false); - ap.alignFrame.setDisplayedView(ap); + frame.setSelected(true); } catch (PropertyVetoException e1) { + } finally + { + /* + * restore the listener _after_ setSelected has run + */ + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + frame.addFocusListener(me); + } + }); } } }); diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 45e4b95..c2d94dc 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -20,29 +20,6 @@ */ package jalview.gui; -import jalview.analysis.AnnotationSorter; -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.bin.Cache; -import jalview.bin.Jalview; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.HiddenColumns; -import jalview.datamodel.SearchResultsI; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceGroup; -import jalview.datamodel.SequenceI; -import jalview.gui.ImageExporter.ImageWriterI; -import jalview.io.HTMLOutput; -import jalview.jbgui.GAlignmentPanel; -import jalview.math.AlignmentDimension; -import jalview.schemes.ResidueProperties; -import jalview.structure.StructureSelectionManager; -import jalview.util.Comparison; -import jalview.util.ImageMaker; -import jalview.util.MessageManager; -import jalview.viewmodel.ViewportListenerI; -import jalview.viewmodel.ViewportRanges; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; @@ -60,6 +37,7 @@ import java.awt.print.Printable; import java.awt.print.PrinterException; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; @@ -67,6 +45,30 @@ import java.util.List; import javax.swing.SwingUtilities; +import jalview.analysis.AnnotationSorter; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; +import jalview.api.SplitContainerI; +import jalview.bin.Cache; +import jalview.bin.Jalview; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.SearchResultsI; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.gui.ImageExporter.ImageWriterI; +import jalview.io.HTMLOutput; +import jalview.jbgui.GAlignmentPanel; +import jalview.math.AlignmentDimension; +import jalview.schemes.ResidueProperties; +import jalview.structure.StructureSelectionManager; +import jalview.util.Comparison; +import jalview.util.ImageMaker; +import jalview.util.MessageManager; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; + /** * DOCUMENT ME! * @@ -122,7 +124,7 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public AlignmentPanel(AlignFrame af, final AlignViewport av) { -// setBackground(Color.white); // BH 2019 + // setBackground(Color.white); // BH 2019 alignFrame = af; this.av = av; setSeqPanel(new SeqPanel(av, this)); @@ -471,8 +473,7 @@ public class AlignmentPanel extends GAlignmentPanel implements /* * Scroll down to make end of search results visible */ - setScrollValues(ranges.getStartRes(), starts + seqIndex - ends - + 1); + setScrollValues(ranges.getStartRes(), starts + seqIndex - ends + 1); } /* * Else results are already visible - no need to scroll @@ -572,7 +573,6 @@ public class AlignmentPanel extends GAlignmentPanel implements Dimension e = idPanel.getSize(); alabels.setSize(new Dimension(e.width, annotationHeight)); - annotationSpaceFillerHolder.setPreferredSize(new Dimension( annotationSpaceFillerHolder.getWidth(), annotationHeight)); annotationScroller.validate(); @@ -1020,8 +1020,8 @@ public class AlignmentPanel extends GAlignmentPanel implements * single graphics context), then reset to (0, scale height) */ alignmentGraphics.translate(alignmentGraphicsOffset, scaleHeight); - getSeqPanel().seqCanvas.drawPanelForPrinting(alignmentGraphics, startRes, - endRes, startSeq, endSeq - 1); + getSeqPanel().seqCanvas.drawPanelForPrinting(alignmentGraphics, + startRes, endRes, startSeq, endSeq - 1); alignmentGraphics.translate(-alignmentGraphicsOffset, 0); if (av.isShowAnnotation() && (endSeq == alignmentHeight)) @@ -1065,8 +1065,8 @@ public class AlignmentPanel extends GAlignmentPanel implements * * @throws PrinterException */ - public int printWrappedAlignment(int pageWidth, int pageHeight, int pageNumber, - Graphics g) throws PrinterException + public int printWrappedAlignment(int pageWidth, int pageHeight, + int pageNumber, Graphics g) throws PrinterException { getSeqPanel().seqCanvas.calculateWrappedGeometry(getWidth(), getHeight()); @@ -1118,8 +1118,8 @@ public class AlignmentPanel extends GAlignmentPanel implements g.translate(idWidth, 0); - getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(g, pageWidth - idWidth, - totalHeight, 0); + getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(g, + pageWidth - idWidth, totalHeight, 0); if ((pageNumber * pageHeight) < totalHeight) { @@ -1284,13 +1284,13 @@ public class AlignmentPanel extends GAlignmentPanel implements String triplet = null; if (av.getAlignment().isNucleotide()) { - triplet = ResidueProperties.nucleotideName.get(seq - .getCharAt(column) + ""); + triplet = ResidueProperties.nucleotideName + .get(seq.getCharAt(column) + ""); } else { - triplet = ResidueProperties.aa2Triplet.get(seq.getCharAt(column) - + ""); + triplet = ResidueProperties.aa2Triplet + .get(seq.getCharAt(column) + ""); } if (triplet == null) @@ -1307,7 +1307,8 @@ public class AlignmentPanel extends GAlignmentPanel implements text.append(" features = seq.findFeatures(column, column); + List features = seq.findFeatures(column, + column); for (SequenceFeature sf : features) { if (sf.isContactFeature()) @@ -1522,29 +1524,40 @@ public class AlignmentPanel extends GAlignmentPanel implements } /** - * Make/Unmake this alignment panel the current input focus + * Make/Unmake this alignment panel the current input focus, optionally + * restoring it if iconised * - * @param b + * @param sel + * @param deIconify */ - public void setSelected(boolean b) + public void setSelected(boolean sel, boolean deIconify) { try { - if (alignFrame.getSplitViewContainer() != null) + SplitContainerI splitFrame = alignFrame.getSplitViewContainer(); + if (splitFrame != null) { /* * bring enclosing SplitFrame to front first if there is one */ - ((SplitFrame) alignFrame.getSplitViewContainer()).setSelected(b); + ((SplitFrame) splitFrame).setSelected(sel); + if (sel && deIconify) + { + ((SplitFrame) splitFrame).setIcon(false); + } } - alignFrame.setSelected(b); - } catch (Exception ex) - { - } + alignFrame.setSelected(sel); - if (b) + if (sel) + { + if (deIconify) + { + alignFrame.setIcon(false); + } + alignFrame.setDisplayedView(this); + } + } catch (PropertyVetoException e) { - alignFrame.setDisplayedView(this); } } diff --git a/src/jalview/gui/ViewSelectionMenu.java b/src/jalview/gui/ViewSelectionMenu.java index a1529fc..d7909ac 100644 --- a/src/jalview/gui/ViewSelectionMenu.java +++ b/src/jalview/gui/ViewSelectionMenu.java @@ -20,9 +20,6 @@ */ package jalview.gui; -import jalview.api.AlignmentViewPanel; -import jalview.util.MessageManager; - import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -38,6 +35,9 @@ import javax.swing.JMenuItem; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; +import jalview.api.AlignmentViewPanel; +import jalview.util.MessageManager; + /** * this is an implementation of an abstract Jalview GUI class that provides a * dialog/menu which allows the user to select/deselect specific views from a @@ -268,7 +268,7 @@ public class ViewSelectionMenu extends JMenu { try { - ap.setSelected(false); + ap.setSelected(false, false); } catch (Exception ex) { } @@ -279,7 +279,7 @@ public class ViewSelectionMenu extends JMenu { try { - ap.setSelected(true); + ap.setSelected(true, false); } catch (Exception ex) { } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 6685c67..125dcb3 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -20,18 +20,6 @@ */ package jalview.jbgui; -import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; -import jalview.analysis.GeneticCodeI; -import jalview.analysis.GeneticCodes; -import jalview.api.SplitContainerI; -import jalview.bin.Cache; -import jalview.gui.JvSwingUtils; -import jalview.gui.Preferences; -import jalview.io.FileFormats; -import jalview.schemes.ResidueColourScheme; -import jalview.util.MessageManager; -import jalview.util.Platform; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridLayout; @@ -61,6 +49,18 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; +import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; +import jalview.analysis.GeneticCodeI; +import jalview.analysis.GeneticCodes; +import jalview.api.SplitContainerI; +import jalview.bin.Cache; +import jalview.gui.JvSwingUtils; +import jalview.gui.Preferences; +import jalview.io.FileFormats; +import jalview.schemes.ResidueColourScheme; +import jalview.util.MessageManager; +import jalview.util.Platform; + @SuppressWarnings("serial") public class GAlignFrame extends JInternalFrame { @@ -687,7 +687,7 @@ public class GAlignFrame extends JInternalFrame @Override public void actionPerformed(ActionEvent e) { - overviewMenuItem_actionPerformed(e); + overviewMenuItem_actionPerformed(); } }); @@ -2313,7 +2313,7 @@ public class GAlignFrame extends JInternalFrame { } - protected void overviewMenuItem_actionPerformed(ActionEvent e) + protected void overviewMenuItem_actionPerformed() { } diff --git a/test/jalview/gui/FreeUpMemoryTest.java b/test/jalview/gui/FreeUpMemoryTest.java index 3a5a9e4..956ba5c 100644 --- a/test/jalview/gui/FreeUpMemoryTest.java +++ b/test/jalview/gui/FreeUpMemoryTest.java @@ -204,7 +204,7 @@ public class FreeUpMemoryTest /* * open an Overview window */ - af.overviewMenuItem_actionPerformed(null); + af.overviewMenuItem_actionPerformed(); assertNotNull(af.alignPanel.overviewPanel); /*