From: BobHanson Date: Tue, 9 Jun 2020 06:42:17 +0000 (-0500) Subject: JAL-3446 from applet; JAL-3374 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=be8b1d254f658181eec3c29dc696114e3ffdd4df;p=jalview.git JAL-3446 from applet; JAL-3374 - JalviewJSApp interface updated - Jalview "noannotations" fixed - AlignFrame show annotations menu item when started with noannations fixed - reorganization of timing of setting range start/end and scrollbar values solves (many) timing issues in SeqCanvasTest and AlignmentPanelTest, which were due to asynchronous delayed repaints setting range values in paintComponent(g) way too late. - correction of font checking in AlignmentPanelTest - "VERY LONG LABEL" not long enough after adding "MMMM" in a prior test - corrections for "isMac()" (now "!isWin()") in tests - addition of Jalview.isInteractive for SeqCanvasTest -- still an occasional conflict with previous test when in batch mode - addition of Jalview.allowServices for simple tests (using -jabaws "none"), allowing them to not run unnecessary service look-up threads - centralization of AlignmentViewport firing of "alignment" property change for sanity only - adding of "sequence" property change for notification of need to refresh the horizontal scrollbar after changes in range and scrollbar update timing - still a minor issue with noannotation starting up ok, but the first annotation spilling over into scrollbar space (is that a filler?) --- diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index e1bfbde..311f1e7 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -773,8 +773,7 @@ public class APopupMenu extends java.awt.PopupMenu ap.alignFrame.addHistoryItem(editCommand); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } } } @@ -811,8 +810,7 @@ public class APopupMenu extends java.awt.PopupMenu ap.alignFrame.addHistoryItem(caseCommand); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 1a46585..fc1f26d 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -882,7 +882,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } else if (source == autoCalculate) { - viewport.autoCalculateConsensus = autoCalculate.getState(); + viewport.setAutoCalculateConsensusAndConservation(autoCalculate.getState()); } else if (source == sortByTree) { @@ -1701,8 +1701,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // viewport.getColumnSelection().getHiddenColumns() // != null; updateEditMenuBar(); - originalSource.firePropertyChange("alignment", null, - originalSource.getAlignment().getSequences()); + originalSource.notifyAlignment(); } /** @@ -1734,8 +1733,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // != null; updateEditMenuBar(); - originalSource.firePropertyChange("alignment", null, - originalSource.getAlignment().getSequences()); + originalSource.notifyAlignment(); } AlignmentViewport getOriginatingSource(CommandI command) @@ -2084,8 +2082,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight() - 1); // BH // 2019.04.18 viewport.getAlignment().getWidth(); - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); } @@ -2159,8 +2156,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.setSelectionGroup(null); viewport.getAlignment().deleteGroup(sg); - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); if (viewport.getAlignment().getHeight() < 1) { @@ -2372,7 +2368,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } } - viewport.firePropertyChange("alignment", null, al.getSequences()); + viewport.notifyAlignment(); } } @@ -2416,7 +2412,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // if (viewport.hasHiddenColumns) // viewport.getColumnSelection().compensateForEdits(shifts); ranges.setStartRes(seq.findIndex(startRes) - 1); - viewport.firePropertyChange("alignment", null, al.getSequences()); + viewport.notifyAlignment(); } @@ -2450,7 +2446,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ranges.setStartRes(seq.findIndex(startRes) - 1); - viewport.firePropertyChange("alignment", null, al.getSequences()); + viewport.notifyAlignment(); } diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 0324d8c..b379c2d 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -352,7 +352,7 @@ public class AlignViewport extends AlignmentViewport if (mappedCommand != null) { mappedCommand.doCommand(null); - firePropertyChange("alignment", null, getAlignment().getSequences()); + notifyAlignment(); // ap.scalePanelHolder.repaint(); // ap.repaint(); diff --git a/src/jalview/appletgui/RedundancyPanel.java b/src/jalview/appletgui/RedundancyPanel.java index bd36b0d..6488c61 100644 --- a/src/jalview/appletgui/RedundancyPanel.java +++ b/src/jalview/appletgui/RedundancyPanel.java @@ -227,8 +227,7 @@ public class RedundancyPanel extends SliderPanel ap.alignFrame.addHistoryItem(cut); PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } } @@ -243,8 +242,7 @@ public class RedundancyPanel extends SliderPanel { ap.av.getHistoryList().remove(command); ap.alignFrame.updateEditMenuBar(); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } ap.paintAlignment(true, true); diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 776e9ad..a1e2340 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -132,8 +132,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (editCommand != null && editCommand.getSize() > 0) { ap.alignFrame.addHistoryItem(editCommand); - av.firePropertyChange("alignment", null, - av.getAlignment().getSequences()); + av.notifyAlignment(); } startseq = -1; diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index cb26fb5..46d6c11 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -715,8 +715,10 @@ public class TreeCanvas extends Panel ap.updateAnnotation(); if (av.getCodingComplement() != null) { - ((AlignmentViewport) av.getCodingComplement()).firePropertyChange( - "alignment", null, ap.av.getAlignment().getSequences()); + ((AlignmentViewport) av.getCodingComplement()).notifyAlignment(); + // Technically, the property change is not the same because av is not necessarily getCodingComplement(), + // but this is the appletgui, so I am not going to worry about it. BH + //.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences()); } } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 81193e6..4a5c733 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -297,6 +297,8 @@ public class Jalview implements ApplicationSingletonI Cache.loadProperties(usrPropsFile); // must do this before + boolean allowServices = true; + if (isJS) { j2sAppletID = Platform.getAppID(null); @@ -336,7 +338,8 @@ public class Jalview implements ApplicationSingletonI // anything else! final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS); - if (jabawsUrl != null) + allowServices = !("none".equals(jabawsUrl)); + if (allowServices && jabawsUrl != null) { try { @@ -469,7 +472,8 @@ public class Jalview implements ApplicationSingletonI * @j2sIgnore */ { - desktop.startServiceDiscovery(); + if (allowServices) + desktop.startServiceDiscovery(); if (!aparser.contains("nousagestats")) { startUsageStats(desktop); @@ -525,9 +529,11 @@ public class Jalview implements ApplicationSingletonI } /** - * Parse all command-line String[] arguments as well as all JavaScript-derived parameters from Info. + * Parse all command-line String[] arguments as well as all JavaScript-derived + * parameters from Info. * - * We allow for this method to be run from JavaScript. Basically allowing simple scripting. + * We allow for this method to be run from JavaScript. Basically allowing + * simple scripting. * * @param aparser * @param isStartup @@ -573,6 +579,8 @@ public class Jalview implements ApplicationSingletonI System.exit(1); } + setDisplayParameters(aparser); + // time to open a file. long progress = -1; @@ -582,7 +590,65 @@ public class Jalview implements ApplicationSingletonI // Finally, deal with the remaining input data. AlignFrame af = null; - if (file != null) + JalviewJSApp jsApp = (isJS ? new JalviewJSApp(this, aparser) : null); + + if (file == null) + { + if (isJS) + { + // JalviewJS allows sequence1 sequence2 .... + + } + else if (!headless && Cache.getDefault("SHOW_STARTUP_FILE", true)) + /** + * Java only + * + * @j2sIgnore + */ + { + + // We'll only open the default file if the desktop is visible. + // And the user + // //////////////////// + + file = Cache.getDefault("STARTUP_FILE", + Cache.getDefault("www.jalview.org", + "http://www.jalview.org") + + "/examples/exampleFile_2_7.jar"); + if (file.equals( + "http://www.jalview.org/examples/exampleFile_2_3.jar")) + { + // hardwire upgrade of the startup file + file.replace("_2_3.jar", "_2_7.jar"); + // and remove the stale setting + Cache.removeProperty("STARTUP_FILE"); + } + + protocol = DataSourceType.FILE; + + if (file.indexOf("http:") > -1) + { + protocol = DataSourceType.URL; + } + + if (file.endsWith(".jar")) + { + format = FileFormat.Jalview; + } + else + { + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e) + { + // TODO what? + } + } + af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format); + } + } + else { if (!headless) { @@ -613,6 +679,7 @@ public class Jalview implements ApplicationSingletonI } } } + String fileFormat = (isJS ? (String) aparser.getAppletValue("format", null, true) : null); @@ -631,35 +698,11 @@ public class Jalview implements ApplicationSingletonI // TODO ? } - if (aparser.contains(ArgsParser.NOMENUBAR)) - { - noMenuBar = true; - System.out.println("CMD [nomenu] executed successfully!"); - } - - if (aparser.contains(ArgsParser.NOSTATUS)) - { - noStatus = true; - System.out.println("CMD [nostatus] executed successfully!"); - } - - if (aparser.contains(ArgsParser.NOANNOTATION) - || aparser.contains(ArgsParser.NOANNOTATION2)) - { - noAnnotation = true; - System.out.println("CMD no-annotation executed successfully!"); - } - if (aparser.contains(ArgsParser.NOCALCULATION)) - { - noCalculation = true; - System.out.println("CMD [nocalculation] executed successfully!"); - } - af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol, format); if (af == null) { - System.out.println("error"); + System.out.println("jalview error - AlignFrame was not created"); } else { @@ -694,133 +737,11 @@ public class Jalview implements ApplicationSingletonI } setCurrentAlignFrame(af); - String data = aparser.getValue(ArgsParser.COLOUR, true); - if (data != null) - { - data.replaceAll("%20", " "); - - ColourSchemeI cs = ColourSchemeProperty.getColourScheme( - af.getViewport(), af.getViewport().getAlignment(), data); - - if (cs != null) - { - System.out.println( - "CMD [-color " + data + "] executed successfully!"); - } - af.changeColour(cs); - } - - // Must maintain ability to use the groups flag - data = aparser.getValue(ArgsParser.GROUPS, true); - if (data != null) - { - af.parseFeaturesFile(data, - AppletFormatAdapter.checkProtocol(data)); - // System.out.println("Added " + data); - System.out.println( - "CMD groups[-" + data + "] executed successfully!"); - } - data = aparser.getValue(ArgsParser.FEATURES, true); - if (data != null) - { - af.parseFeaturesFile(data, - AppletFormatAdapter.checkProtocol(data)); - // System.out.println("Added " + data); - System.out.println( - "CMD [-features " + data + "] executed successfully!"); - } - data = aparser.getValue(ArgsParser.ANNOTATIONS, true); - if (data != null) - { - af.loadJalviewDataFile(data, null, null, null); - // System.out.println("Added " + data); - System.out.println( - "CMD [-annotations " + data + "] executed successfully!"); - } - - // JavaScript feature - - if (aparser.contains(ArgsParser.SHOWOVERVIEW)) - { - af.overviewMenuItem_actionPerformed(null); - System.out.println("CMD [showoverview] executed successfully!"); - } - - // set or clear the sortbytree flag. - if (aparser.contains(ArgsParser.SORTBYTREE)) - { - af.getViewport().setSortByTree(true); - if (af.getViewport().getSortByTree()) - { - System.out.println("CMD [-sortbytree] executed successfully!"); - } - } - - boolean doUpdateAnnotation = false; - /** - * we do this earlier in JalviewJS because of a complication with - * SHOWOVERVIEW - * - * For now, just fixing this in JalviewJS. - * - * - * @j2sIgnore - * - */ - { - if (aparser.contains(ArgsParser.NOANNOTATION) - || aparser.contains(ArgsParser.NOANNOTATION2)) - { - af.getViewport().setShowAnnotation(false); - if (!af.getViewport().isShowAnnotation()) - { - doUpdateAnnotation = true; - System.out - .println("CMD no-annotation executed successfully!"); - } - } - } - - if (aparser.contains(ArgsParser.NOSORTBYTREE)) - { - af.getViewport().setSortByTree(false); - if (!af.getViewport().getSortByTree()) - { - doUpdateAnnotation = true; - System.out - .println("CMD [-nosortbytree] executed successfully!"); - } - } - if (doUpdateAnnotation) - { // BH 2019.07.24 - af.setMenusForViewport(); - af.alignPanel.updateLayout(); - } - - data = aparser.getValue(ArgsParser.TREE, true); - if (data != null) - { - try - { - NewickFile nf = new NewickFile(data, - AppletFormatAdapter.checkProtocol(data)); - af.getViewport() - .setCurrentTree(af.showNewickTree(nf, data).getTree()); - System.out.println( - "CMD [-tree " + data + "] executed successfully!"); - } catch (IOException ex) - { - System.err.println("Couldn't add tree " + data); - ex.printStackTrace(System.err); - } - } - // TODO - load PDB structure(s) to alignment JAL-629 - // (associate with identical sequence in alignment, or a specified - // sequence) - + setFrameDependentProperties(aparser, af); + if (isJS) { - new JalviewJSApp(this, aparser, af); + jsApp.initFromParams(af); } else /** @@ -840,61 +761,10 @@ public class Jalview implements ApplicationSingletonI + "] executed successfully!"); groovyscript = null; } - createOutputFiles(aparser, af, format); - } - } - } - else - { - if (!isJS && !headless && Cache.getDefault("SHOW_STARTUP_FILE", true)) - /** - * Java only - * - * @j2sIgnore - */ - { - - // We'll only open the default file if the desktop is visible. - // And the user - // //////////////////// - - file = Cache.getDefault("STARTUP_FILE", - Cache.getDefault("www.jalview.org", - "http://www.jalview.org") - + "/examples/exampleFile_2_7.jar"); - if (file.equals( - "http://www.jalview.org/examples/exampleFile_2_3.jar")) - { - // hardwire upgrade of the startup file - file.replace("_2_3.jar", "_2_7.jar"); - // and remove the stale setting - Cache.removeProperty("STARTUP_FILE"); - } - - protocol = DataSourceType.FILE; - - if (file.indexOf("http:") > -1) - { - protocol = DataSourceType.URL; } - - if (file.endsWith(".jar")) - { - format = FileFormat.Jalview; + if (!isJS || !isStartup) { + createOutputFiles(aparser, format); } - else - { - try - { - format = new IdentifyFile().identify(file, protocol); - } catch (FileFormatException e) - { - // TODO what? - } - } - - af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format); - } } // extract groovy arguments before anything else. @@ -923,9 +793,170 @@ public class Jalview implements ApplicationSingletonI } desktop.setInBatchMode(false); } - + + if (jsApp != null) { + jsApp.callInitCallback(); + } } + /** + * Set general display parameters irrespective of file loading or headlessness. + * + * @param aparser + */ + private void setDisplayParameters(ArgsParser aparser) + { + if (aparser.contains(ArgsParser.NOMENUBAR)) + { + noMenuBar = true; + System.out.println("CMD [nomenu] executed successfully!"); + } + + if (aparser.contains(ArgsParser.NOSTATUS)) + { + noStatus = true; + System.out.println("CMD [nostatus] executed successfully!"); + } + + if (aparser.contains(ArgsParser.NOANNOTATION) + || aparser.contains(ArgsParser.NOANNOTATION2)) + { + noAnnotation = true; + System.out.println("CMD no-annotation executed successfully!"); + } + if (aparser.contains(ArgsParser.NOCALCULATION)) + { + noCalculation = true; + System.out.println("CMD [nocalculation] executed successfully!"); + } + } + + + private void setFrameDependentProperties(ArgsParser aparser, + AlignFrame af) + { + String data = aparser.getValue(ArgsParser.COLOUR, true); + if (data != null) + { + data.replaceAll("%20", " "); + + ColourSchemeI cs = ColourSchemeProperty.getColourScheme( + af.getViewport(), af.getViewport().getAlignment(), data); + + if (cs != null) + { + System.out.println( + "CMD [-color " + data + "] executed successfully!"); + } + af.changeColour(cs); + } + + // Must maintain ability to use the groups flag + data = aparser.getValue(ArgsParser.GROUPS, true); + if (data != null) + { + af.parseFeaturesFile(data, + AppletFormatAdapter.checkProtocol(data)); + // System.out.println("Added " + data); + System.out.println( + "CMD groups[-" + data + "] executed successfully!"); + } + data = aparser.getValue(ArgsParser.FEATURES, true); + if (data != null) + { + af.parseFeaturesFile(data, + AppletFormatAdapter.checkProtocol(data)); + // System.out.println("Added " + data); + System.out.println( + "CMD [-features " + data + "] executed successfully!"); + } + data = aparser.getValue(ArgsParser.ANNOTATIONS, true); + if (data != null) + { + af.loadJalviewDataFile(data, null, null, null); + // System.out.println("Added " + data); + System.out.println( + "CMD [-annotations " + data + "] executed successfully!"); + } + + // JavaScript feature + + if (aparser.contains(ArgsParser.SHOWOVERVIEW)) + { + af.overviewMenuItem_actionPerformed(null); + System.out.println("CMD [showoverview] executed successfully!"); + } + + // set or clear the sortbytree flag. + if (aparser.contains(ArgsParser.SORTBYTREE)) + { + af.getViewport().setSortByTree(true); + if (af.getViewport().getSortByTree()) + { + System.out.println("CMD [-sortbytree] executed successfully!"); + } + } + + boolean doUpdateAnnotation = false; + /** + * we do this earlier in JalviewJS because of a complication with + * SHOWOVERVIEW + * + * For now, just fixing this in JalviewJS. + * + * + * @j2sIgnore + * + */ + { + if (noAnnotation) + { + af.getViewport().setShowAnnotation(false); + if (!af.getViewport().isShowAnnotation()) + { + doUpdateAnnotation = true; + } + } + } + + if (aparser.contains(ArgsParser.NOSORTBYTREE)) + { + af.getViewport().setSortByTree(false); + if (!af.getViewport().getSortByTree()) + { + doUpdateAnnotation = true; + System.out + .println("CMD [-nosortbytree] executed successfully!"); + } + } + if (doUpdateAnnotation) + { // BH 2019.07.24 + af.setMenusForViewport(); + af.alignPanel.updateLayout(); + } + + data = aparser.getValue(ArgsParser.TREE, true); + if (data != null) + { + try + { + NewickFile nf = new NewickFile(data, + AppletFormatAdapter.checkProtocol(data)); + af.getViewport() + .setCurrentTree(af.showNewickTree(nf, data).getTree()); + System.out.println( + "CMD [-tree " + data + "] executed successfully!"); + } catch (IOException ex) + { + System.err.println("Couldn't add tree " + data); + ex.printStackTrace(System.err); + } + } + // TODO - load PDB structure(s) to alignment JAL-629 + // (associate with identical sequence in alignment, or a specified + // sequence) + + } /** * Writes an output file for each format (if any) specified in the @@ -943,12 +974,12 @@ public class Jalview implements ApplicationSingletonI * corresponding alignment image output. * * @param aparser - * @param af * @param format */ - private void createOutputFiles(ArgsParser aparser, AlignFrame af, + private void createOutputFiles(ArgsParser aparser, FileFormatI format) { + AlignFrame af = currentAlignFrame; while (aparser.getSize() >= 2) { String outputFormat = aparser.nextValue(); @@ -1265,5 +1296,18 @@ public class Jalview implements ApplicationSingletonI // System.out.println("Jalview worker " + worker.getClass().getSimpleName() // + " " + status); } - + + + private static boolean isInteractive = true; + + public static boolean isInteractive() + { + return isInteractive; + } + + public static void setInteractive(boolean tf) + { + isInteractive = tf; + } + } diff --git a/src/jalview/bin/JalviewJSApp.java b/src/jalview/bin/JalviewJSApp.java index 1ba7273..feab4ae 100644 --- a/src/jalview/bin/JalviewJSApp.java +++ b/src/jalview/bin/JalviewJSApp.java @@ -9,6 +9,8 @@ import java.util.List; import java.util.StringTokenizer; import java.util.Vector; +import javax.swing.SwingUtilities; + import jalview.api.JalviewJSApi; import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.Alignment; @@ -153,13 +155,11 @@ public class JalviewJSApp implements JalviewJSApi } - public JalviewJSApp(Jalview jalview, ArgsParser aparser, AlignFrame alf) + public JalviewJSApp(Jalview jalview, ArgsParser aparser) { Platform.setAppClass(this); this.jalview = jalview; this.aparser = aparser; - initFromParams(alf); - callInitCallback(); } @Override @@ -1270,15 +1270,23 @@ public class JalviewJSApp implements JalviewJSApi Object initjscallback = getParameterAsObject("oninit"); if (initjscallback != null) { - try - { - doSendCallback(initjscallback, new Object[0]); - } catch (Exception e) - { - System.err.println("Exception when executing _oninit callback '" - + initjscallback + "'."); - e.printStackTrace(); - } + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() + { + try + { + doSendCallback(initjscallback, new Object[] {this}); + } catch (Exception e) + { + System.err.println("Exception when executing _oninit callback '" + + initjscallback + "'."); + e.printStackTrace(); + } + } + + }); } } @@ -1328,7 +1336,7 @@ public class JalviewJSApp implements JalviewJSApi * * @param alf */ - private void initFromParams(AlignFrame alf) + void initFromParams(AlignFrame alf) { String sep = getParameter("separator"); if (sep != null && sep.length() > 0) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index f74eb32..b69ba88 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -20,59 +20,6 @@ */ package jalview.gui; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.dnd.DnDConstants; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DropTargetEvent; -import java.awt.dnd.DropTargetListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.print.PageFormat; -import java.awt.print.PrinterJob; -import java.beans.PropertyChangeEvent; -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Deque; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.List; -import java.util.Vector; - -import javax.swing.ButtonGroup; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; -import javax.swing.JEditorPane; -import javax.swing.JInternalFrame; -import javax.swing.JLabel; -import javax.swing.JLayeredPane; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; - -import ext.vamsas.ServiceHandle; import jalview.analysis.AlignmentSorter; import jalview.analysis.AlignmentUtils; import jalview.analysis.CrossRef; @@ -156,6 +103,60 @@ import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.seqfetcher.DbSourceProxy; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DropTargetDragEvent; +import java.awt.dnd.DropTargetDropEvent; +import java.awt.dnd.DropTargetEvent; +import java.awt.dnd.DropTargetListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.print.PageFormat; +import java.awt.print.PrinterJob; +import java.beans.PropertyChangeEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Deque; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import java.util.Vector; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComponent; +import javax.swing.JEditorPane; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JLayeredPane; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +import ext.vamsas.ServiceHandle; + /** * DOCUMENT ME! * @@ -168,7 +169,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { public static int frameCount; - + public static final int DEFAULT_WIDTH = 700; public static final int DEFAULT_HEIGHT = 500; @@ -292,9 +293,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width, int height, String sequenceSetId, String viewId) { - + id = (++frameCount); - + setSize(width, height); if (al.getDataset() == null) @@ -304,9 +305,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId); - alignPanel = new AlignmentPanel(this, viewport); - - addAlignmentPanel(alignPanel, true); + // JalviewJS needs to distinguish a new panel from an old one in init() + // alignPanel = new AlignmentPanel(this, viewport); + // addAlignmentPanel(alignPanel, true); init(); } @@ -326,8 +327,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { viewport.hideSequence(hiddenSeqs); } - alignPanel = new AlignmentPanel(this, viewport); - addAlignmentPanel(alignPanel, true); + // alignPanel = new AlignmentPanel(this, viewport); + // addAlignmentPanel(alignPanel, true); init(); } @@ -343,7 +344,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { viewport = ap.av; alignPanel = ap; - addAlignmentPanel(ap, false); + // addAlignmentPanel(ap, false); init(); } @@ -351,13 +352,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * initalise the alignframe from the underlying viewport data and the * configurations */ + void init() { + + boolean newPanel = (alignPanel == null); + viewport.setShowAutocalculatedAbove(isShowAutoCalculatedAbove()); + if (newPanel) + { + if (Platform.isJS()) + { + // need to set this up front if NOANNOTATION is + // used in conjunction with SHOWOVERVIEW. + + // I have not determined if this is appropriate for + // Jalview/Java, as it means we are setting this flag + // for all subsequent AlignFrames. For now, at least, + // I am setting it to be JalviewJS-only. + + boolean showAnnotation = Jalview.getInstance().getShowAnnotation(); + viewport.setShowAnnotation(showAnnotation); + } + alignPanel = new AlignmentPanel(this, viewport); + } + addAlignmentPanel(alignPanel, newPanel); + // setBackground(Color.white); // BH 2019 if (!Jalview.isHeadlessMode()) { progressBar = new ProgressBar(this.statusPanel, this.statusBar); + // JalviewJS options + statusPanel.setVisible(Jalview.getInstance().getShowStatus()); + alignFrameMenuBar.setVisible(Jalview.getInstance().getAllowMenuBar()); } avc = new jalview.controller.AlignViewController(this, viewport, @@ -372,7 +399,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // modifyPID.setEnabled(false); } - String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", + String sortby = jalview.bin.Cache.getDefault(Preferences.SORT_ALIGNMENT, "No sort"); if (sortby.equals("Id")) @@ -384,8 +411,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, sortPairwiseMenuItem_actionPerformed(null); } - this.alignPanel.av - .setShowAutocalculatedAbove(isShowAutoCalculatedAbove()); + // BH see above + // + // this.alignPanel.av + // .setShowAutocalculatedAbove(isShowAutoCalculatedAbove()); setMenusFromViewport(viewport); buildSortByAnnotationScoresMenu(); @@ -415,7 +444,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, wrapMenuItem_actionPerformed(null); } - if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false)) + if (jalview.bin.Cache.getDefault(Preferences.SHOW_OVERVIEW, false)) { this.overviewMenuItem_actionPerformed(null); } @@ -499,6 +528,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } addFocusListener(new FocusAdapter() { + @Override public void focusGained(FocusEvent e) { @@ -517,6 +547,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param format * format of file */ + public void setFileName(String file, FileFormatI format) { fileName = file; @@ -530,6 +561,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param file */ + public void setFileObject(File file) { this.fileObject = file; @@ -539,10 +571,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Add a KeyListener with handlers for various KeyPressed and KeyReleased * events */ + void addKeyListener() { addKeyListener(new KeyAdapter() { + @Override public void keyPressed(KeyEvent evt) { @@ -559,7 +593,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, switch (evt.getKeyCode()) { - case 27: // escape key + case KeyEvent.VK_ESCAPE: // escape key + // alignPanel.deselectAllSequences(); alignPanel.deselectAllSequences(); break; @@ -743,16 +778,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_LEFT: if (evt.isAltDown() || !viewport.cursorMode) { - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); } break; case KeyEvent.VK_RIGHT: if (evt.isAltDown() || !viewport.cursorMode) { - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); } break; } @@ -798,9 +831,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { ap.av.getAlignment().padGaps(); } - ap.av.updateConservation(ap); - ap.av.updateConsensus(ap); - ap.av.updateStrucConsensus(ap); + if (Jalview.getInstance().getStartCalculations()) + { + ap.av.updateConservation(ap); + ap.av.updateConsensus(ap); + ap.av.updateStrucConsensus(ap); + } } } @@ -826,6 +862,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.getInstance().addJalviewPropertyChangeListener("services", thisListener = new java.beans.PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { @@ -849,6 +886,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, }); addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() { + @Override public void internalFrameClosed( javax.swing.event.InternalFrameEvent evt) @@ -862,6 +900,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Finally, build the menu once to get current service state new Thread(new Runnable() { + @Override public void run() { @@ -874,6 +913,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Configure menu items that vary according to whether the alignment is * nucleotide or protein */ + public void setGUINucleotide() { AlignmentI al = getViewport().getAlignment(); @@ -898,6 +938,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * operation that affects the data in the current view (selection changed, * etc) to update the menus to reflect the new state. */ + @Override public void setMenusForViewport() { @@ -911,6 +952,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param av * AlignViewport */ + public void setMenusFromViewport(AlignViewport av) { padGapsMenuitem.setSelected(av.isPadGaps()); @@ -928,13 +970,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, scaleLeft.setVisible(av.getWrapAlignment()); scaleRight.setVisible(av.getWrapAlignment()); annotationPanelMenuItem.setState(av.isShowAnnotation()); - /* - * Show/hide annotations only enabled if annotation panel is shown - */ - showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState()); - hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState()); - showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState()); - hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState()); + // Show/hide annotations only enabled if annotation panel is shown + syncAnnotationMenuItems(av.isShowAnnotation()); viewBoxesMenuItem.setSelected(av.getShowBoxes()); viewTextMenuItem.setSelected(av.getShowText()); showNonconservedMenuItem.setSelected(av.getShowUnconserved()); @@ -952,7 +989,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, applyToAllGroups.setState(av.getColourAppliesToAllGroups()); showNpFeatsMenuitem.setSelected(av.isShowNPFeats()); showDbRefsMenuitem.setSelected(av.isShowDBRefs()); - autoCalculate.setSelected(av.autoCalculateConsensus); + autoCalculate + .setSelected(av.getAutoCalculateConsensusAndConservation()); sortByTree.setSelected(av.sortByTree); listenToViewSelections.setSelected(av.followSelection); @@ -967,6 +1005,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param b */ + public void setGroovyEnabled(boolean b) { runGroovy.setEnabled(b); @@ -979,6 +1018,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) */ + @Override public void setProgressBar(String message, long id) { @@ -996,6 +1036,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @return true if any progress bars are still active */ + @Override public boolean operationInProgress() { @@ -1007,6 +1048,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * will cause the status bar to be hidden, with possibly undesirable flicker * of the screen layout. */ + @Override public void setStatus(String text) { @@ -1016,6 +1058,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /* * Added so Castor Mapping file can obtain Jalview Version */ + public String getVersion() { return jalview.bin.Cache.getProperty("VERSION"); @@ -1041,84 +1084,87 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void reload_actionPerformed(ActionEvent e) { - if (fileName != null) + if (fileName == null) + { + return; + } + // TODO: JAL-1108 - ensure all associated frames are closed regardless of + // originating file's format + // TODO: work out how to recover feature settings for correct view(s) when + // file is reloaded. + if (FileFormat.Jalview.equals(currentFileFormat)) { - // TODO: JAL-1108 - ensure all associated frames are closed regardless of - // originating file's format - // TODO: work out how to recover feature settings for correct view(s) when - // file is reloaded. - if (FileFormat.Jalview.equals(currentFileFormat)) + JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames(); + for (int i = 0; i < frames.length; i++) { - JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames(); - for (int i = 0; i < frames.length; i++) + if (frames[i] instanceof AlignFrame && frames[i] != this + && ((AlignFrame) frames[i]).fileName != null + && ((AlignFrame) frames[i]).fileName.equals(fileName)) { - if (frames[i] instanceof AlignFrame && frames[i] != this - && ((AlignFrame) frames[i]).fileName != null - && ((AlignFrame) frames[i]).fileName.equals(fileName)) + try + { + frames[i].setSelected(true); + Desktop.getInstance().closeAssociatedWindows(); + } catch (java.beans.PropertyVetoException ex) { - try - { - frames[i].setSelected(true); - Desktop.getInstance().closeAssociatedWindows(); - } catch (java.beans.PropertyVetoException ex) - { - } } - } - Desktop.getInstance().closeAssociatedWindows(); - FileLoader loader = new FileLoader(); - DataSourceType protocol = fileName.startsWith("http:") - ? DataSourceType.URL - : DataSourceType.FILE; - loader.LoadFile(viewport, fileName, protocol, currentFileFormat); } - else - { - Rectangle bounds = this.getBounds(); + Desktop.getInstance().closeAssociatedWindows(); - FileLoader loader = new FileLoader(); + FileLoader loader = new FileLoader(); + DataSourceType protocol = fileName.startsWith("http:") + ? DataSourceType.URL + : DataSourceType.FILE; + loader.LoadFile(viewport, fileName, protocol, currentFileFormat); + } + else + { + Rectangle bounds = this.getBounds(); - AlignFrame newframe = null; + FileLoader loader = new FileLoader(); - if (fileObject == null) - { + AlignFrame newframe = null; - DataSourceType protocol = (fileName.startsWith("http:") - ? DataSourceType.URL - : DataSourceType.FILE); - newframe = loader.LoadFileWaitTillLoaded(fileName, protocol, - currentFileFormat); - } - else - { - newframe = loader.LoadFileWaitTillLoaded(fileObject, - DataSourceType.FILE, currentFileFormat); - } + if (fileObject == null) + { - newframe.setBounds(bounds); - if (featureSettings != null && featureSettings.isShowing()) + DataSourceType protocol = (fileName.startsWith("http:") + ? DataSourceType.URL + : DataSourceType.FILE); + newframe = loader.LoadFileWaitTillLoaded(fileName, protocol, + currentFileFormat); + } + else + { + newframe = loader.LoadFileWaitTillLoaded(fileObject, + DataSourceType.FILE, currentFileFormat); + } + + newframe.setBounds(bounds); + if (featureSettings != null && featureSettings.isShowing()) + { + final Rectangle fspos = featureSettings.frame.getBounds(); + // TODO: need a 'show feature settings' function that takes bounds - + // need to refactor Desktop.addFrame + newframe.featureSettings_actionPerformed(null); + final FeatureSettings nfs = newframe.featureSettings; + SwingUtilities.invokeLater(new Runnable() { - final Rectangle fspos = featureSettings.frame.getBounds(); - // TODO: need a 'show feature settings' function that takes bounds - - // need to refactor Desktop.addFrame - newframe.featureSettings_actionPerformed(null); - final FeatureSettings nfs = newframe.featureSettings; - SwingUtilities.invokeLater(new Runnable() + + @Override + public void run() { - @Override - public void run() - { - nfs.frame.setBounds(fspos); - } - }); - this.featureSettings.close(); - this.featureSettings = null; - } - this.closeMenuItem_actionPerformed(true); + nfs.frame.setBounds(fspos); + } + }); + this.featureSettings.close(); + this.featureSettings = null; } + this.closeMenuItem_actionPerformed(true); } + } @Override @@ -1152,6 +1198,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Saves the alignment to a file with a name chosen by the user, if necessary * warning if a file would be overwritten */ + @Override public void saveAs_actionPerformed() { @@ -1206,6 +1253,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @return true if last call to saveAlignment(file, format) was successful. */ + public boolean isSaveAlignmentSuccessful() { @@ -1238,6 +1286,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param file * @param format */ + public void saveAlignment(String file, FileFormatI format) { lastSaveSuccessful = true; @@ -1265,6 +1314,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignExportSettingsI options = new AlignExportSettingsAdapter(false); Runnable cancelAction = new Runnable() { + @Override public void run() { @@ -1273,6 +1323,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, }; Runnable outputAction = new Runnable() { + @Override public void run() { @@ -1347,6 +1398,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param fileFormatName */ + @Override protected void outputText_actionPerformed(String fileFormatName) { @@ -1355,6 +1407,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignExportSettingsI options = new AlignExportSettingsAdapter(false); Runnable outputAction = new Runnable() { + @Override public void run() { @@ -1405,6 +1458,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void htmlMenuItem_actionPerformed(ActionEvent e) { @@ -1419,12 +1473,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, bjs.exportHTML(null); } + // ?? + + public void createImageMap(File file, String image) + { + alignPanel.makePNGImageMap(file, image); + } + /** * Creates a PNG image of the alignment and writes it to the given file. If * the file is null, the user is prompted to choose a file. * * @param f */ + @Override public void createPNG(File f) { @@ -1437,6 +1499,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param f */ + @Override public void createEPS(File f) { @@ -1449,6 +1512,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param f */ + @Override public void createSVG(File f) { @@ -1468,6 +1532,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void printMenuItem_actionPerformed(ActionEvent e) { @@ -1500,6 +1565,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, chooser.setToolTipText(tooltip); chooser.setResponseHandler(0, new Runnable() { + @Override public void run() { @@ -1518,6 +1584,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param closeAllTabs */ + @Override public void closeMenuItem_actionPerformed(boolean closeAllTabs) { @@ -1572,6 +1639,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param panelToClose */ + public void closeView(AlignmentPanel panelToClose) { int index = tabbedPane.getSelectedIndex(); @@ -1595,6 +1663,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * DOCUMENT ME! */ + void updateEditMenuBar() { @@ -1648,6 +1717,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @return alignment objects for all views */ + AlignmentI[] getViewAlignments() { if (alignPanels != null) @@ -1673,6 +1743,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void undoMenuItem_actionPerformed(ActionEvent e) { @@ -1700,8 +1771,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // && viewport.getColumnSelection().getHiddenColumns() != null && // viewport.getColumnSelection() // .getHiddenColumns().size() > 0); - originalSource.firePropertyChange("alignment", null, - originalSource.getAlignment().getSequences()); + originalSource.notifyAlignment(); + } } @@ -1711,6 +1782,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void redoMenuItem_actionPerformed(ActionEvent e) { @@ -1740,8 +1812,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // && viewport.getColumnSelection().getHiddenColumns() != null && // viewport.getColumnSelection() // .getHiddenColumns().size() > 0); - originalSource.firePropertyChange("alignment", null, - originalSource.getAlignment().getSequences()); + originalSource.notifyAlignment(); + } } @@ -1793,6 +1865,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param up * DOCUMENT ME! */ + public void moveSelectedSequences(boolean up) { SequenceGroup sg = viewport.getSelectionGroup(); @@ -1917,6 +1990,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void copy_actionPerformed() { @@ -1939,9 +2013,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, StringSelection ss = new StringSelection(output); + Desktop d = Desktop.getInstance(); try { - Desktop.getInstance().internalCopy = true; + d.internalCopy = true; // Its really worth setting the clipboard contents // to empty before setting the large StringSelection!! Toolkit.getDefaultToolkit().getSystemClipboard() @@ -1968,7 +2043,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, hiddenCutoff, hiddenOffset); } - Desktop.getInstance().jalviewClipboard = new Object[] { seqs, + d.jalviewClipboard = new Object[] { seqs, viewport.getAlignment().getDataset(), hiddenColumns }; setStatus(MessageManager.formatMessage( "label.copied_sequences_to_clipboard", new Object[] @@ -1981,6 +2056,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void pasteNew_actionPerformed(ActionEvent e) { @@ -1993,6 +2069,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void pasteThis_actionPerformed(ActionEvent e) { @@ -2005,10 +2082,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param newAlignment * true to paste to a new alignment, otherwise add to this. */ + void paste(boolean newAlignment) { boolean externalPaste = true; - Desktop d = Desktop.getInstance(); try { Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -2041,6 +2118,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, boolean annotationAdded = false; AlignmentI alignment = null; + Desktop d = Desktop.getInstance(); + if (d.jalviewClipboard != null) { // The clipboard was filled from within Jalview, we must use the @@ -2272,8 +2351,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } buildSortByAnnotationScoresMenu(); } - viewport.firePropertyChange("alignment", null, - alignment.getSequences()); + viewport.notifyAlignment(); if (alignPanels != null) { for (AlignmentPanel ap : alignPanels) @@ -2389,6 +2467,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Action Cut (delete and copy) the selected region */ + @Override protected void cut_actionPerformed() { @@ -2399,6 +2478,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Performs menu option to Delete the currently selected region */ + @Override protected void delete_actionPerformed() { @@ -2411,6 +2491,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Runnable okAction = new Runnable() { + @Override public void run() { @@ -2427,8 +2508,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.sendSelection(); viewport.getAlignment().deleteGroup(sg); - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); + if (viewport.getAlignment().getHeight() < 1) { try @@ -2473,6 +2554,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void deleteGroups_actionPerformed(ActionEvent e) { @@ -2490,6 +2572,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) { @@ -2502,6 +2585,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) { @@ -2514,6 +2598,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void invertSequenceMenuItem_actionPerformed(ActionEvent e) { @@ -2553,6 +2638,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void remove2LeftMenuItem_actionPerformed(ActionEvent e) { @@ -2565,6 +2651,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void remove2RightMenuItem_actionPerformed(ActionEvent e) { @@ -2626,8 +2713,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); + } } @@ -2637,6 +2724,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) { @@ -2676,8 +2764,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // if (viewport.hasHiddenColumns) // viewport.getColumnSelection().compensateForEdits(shifts); ranges.setStartRes(seq.findIndex(startRes) - 1); - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); + } @@ -2687,6 +2775,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) { @@ -2714,9 +2803,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.getAlignment())); viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1); - - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); } @@ -2726,12 +2813,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void padGapsMenuitem_actionPerformed(ActionEvent e) { viewport.setPadGaps(padGapsMenuitem.isSelected()); - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); + } /** @@ -2740,6 +2828,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void findMenuItem_actionPerformed(ActionEvent e) { @@ -2749,6 +2838,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Create a new view of the current alignment. */ + @Override public void newView_actionPerformed(ActionEvent e) { @@ -2764,6 +2854,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * if true then duplicate all annnotation, groups and settings * @return new alignment panel, already displayed. */ + public AlignmentPanel newView(String viewTitle, boolean copyAnnotation) { /* @@ -2836,6 +2927,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param viewTitle * @return */ + protected String getNewViewName(String viewTitle) { int index = Desktop.getViewCount(viewport.getSequenceSetId()); @@ -2870,6 +2962,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param comps * @return */ + protected List getExistingViewNames(List comps) { List existingNames = new ArrayList<>(); @@ -2890,6 +2983,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Explode tabbed views into separate windows. */ + @Override public void expandViews_actionPerformed(ActionEvent e) { @@ -2899,6 +2993,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Gather views in separate windows back into a tabbed presentation. */ + @Override public void gatherViews_actionPerformed(ActionEvent e) { @@ -2911,6 +3006,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void font_actionPerformed(ActionEvent e) { @@ -2923,6 +3019,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void seqLimit_actionPerformed(ActionEvent e) { @@ -2952,6 +3049,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed() */ + @Override protected void followHighlight_actionPerformed() { @@ -2973,6 +3071,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void colourTextMenuItem_actionPerformed(ActionEvent e) { @@ -2986,6 +3085,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void wrapMenuItem_actionPerformed(ActionEvent e) { @@ -3022,6 +3122,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param toggleSeqs * @param toggleCols */ + protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols) { @@ -3089,6 +3190,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt. * event.ActionEvent) */ + @Override public void hideAllButSelection_actionPerformed(ActionEvent e) { @@ -3103,6 +3205,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event * .ActionEvent) */ + @Override public void hideAllSelection_actionPerformed(ActionEvent e) { @@ -3122,6 +3225,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event. * ActionEvent) */ + @Override public void showAllhidden_actionPerformed(ActionEvent e) { @@ -3153,6 +3257,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void scaleAbove_actionPerformed(ActionEvent e) { @@ -3167,6 +3272,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void scaleLeft_actionPerformed(ActionEvent e) { @@ -3181,6 +3287,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void scaleRight_actionPerformed(ActionEvent e) { @@ -3195,6 +3302,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { @@ -3208,6 +3316,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void viewTextMenuItem_actionPerformed(ActionEvent e) { @@ -3221,6 +3330,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void renderGapsMenuItem_actionPerformed(ActionEvent e) { @@ -3266,6 +3376,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param evt * DOCUMENT ME! */ + @Override public void showSeqFeatures_actionPerformed(ActionEvent evt) { @@ -3282,16 +3393,32 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param e */ + @Override public void annotationPanelMenuItem_actionPerformed(ActionEvent e) { final boolean setVisible = annotationPanelMenuItem.isSelected(); viewport.setShowAnnotation(setVisible); - this.showAllSeqAnnotations.setEnabled(setVisible); - this.hideAllSeqAnnotations.setEnabled(setVisible); - this.showAllAlAnnotations.setEnabled(setVisible); - this.hideAllAlAnnotations.setEnabled(setVisible); + syncAnnotationMenuItems(setVisible); alignPanel.updateLayout(); + repaint(); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() + { + alignPanel.updateScrollBarsFromRanges(); + } + + }); + } + + private void syncAnnotationMenuItems(boolean setVisible) + { + showAllSeqAnnotations.setEnabled(setVisible); + hideAllSeqAnnotations.setEnabled(setVisible); + showAllAlAnnotations.setEnabled(setVisible); + hideAllAlAnnotations.setEnabled(setVisible); } @Override @@ -3345,6 +3472,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void overviewMenuItem_actionPerformed(ActionEvent e) { @@ -3382,13 +3510,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, "resize") != "none"); Desktop.addInternalFrame(frame, MessageManager .formatMessage("label.overview_params", new Object[] - { this.getTitle() }), Desktop.FRAME_MAKE_VISIBLE, dim.width, dim.height, resizable, - Desktop.FRAME_ALLOW_ANY_SIZE); + { this.getTitle() }), Desktop.FRAME_MAKE_VISIBLE, dim.width, + dim.height, resizable, Desktop.FRAME_ALLOW_ANY_SIZE); frame.pack(); frame.setLayer(JLayeredPane.PALETTE_LAYER); frame.addInternalFrameListener( new javax.swing.event.InternalFrameAdapter() { + @Override public void internalFrameClosed( javax.swing.event.InternalFrameEvent evt) @@ -3417,6 +3546,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation * ()[0])); } */ + @Override public void annotationColour_actionPerformed() { @@ -3436,6 +3566,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param selected */ + @Override public void applyToAllGroups_actionPerformed(boolean selected) { @@ -3448,6 +3579,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param name * the name (not the menu item label!) of the colour scheme */ + @Override public void changeColour_actionPerformed(String name) { @@ -3475,6 +3607,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param cs */ + @Override public void changeColour(ColourSchemeI cs) { @@ -3489,6 +3622,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Show the PID threshold slider panel */ + @Override protected void modifyPID_actionPerformed() { @@ -3500,6 +3634,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Show the Conservation slider panel */ + @Override protected void modifyConservation_actionPerformed() { @@ -3511,6 +3646,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Action on selecting or deselecting (Colour) By Conservation */ + @Override public void conservationMenuItem_actionPerformed(boolean selected) { @@ -3532,6 +3668,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Action on selecting or deselecting (Colour) Above PID Threshold */ + @Override public void abovePIDThreshold_actionPerformed(boolean selected) { @@ -3560,6 +3697,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) { @@ -3577,6 +3715,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void sortIDMenuItem_actionPerformed(ActionEvent e) { @@ -3593,6 +3732,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void sortLengthMenuItem_actionPerformed(ActionEvent e) { @@ -3609,6 +3749,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void sortGroupMenuItem_actionPerformed(ActionEvent e) { @@ -3626,6 +3767,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) { @@ -3638,6 +3780,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) { @@ -3663,11 +3806,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void autoCalculate_actionPerformed(ActionEvent e) { - viewport.autoCalculateConsensus = autoCalculate.isSelected(); - if (viewport.autoCalculateConsensus) + viewport.setAutoCalculateConsensusAndConservation( + autoCalculate.isSelected()); + if (viewport.getAutoCalculateConsensusAndConservation()) + // ?? + // viewport.autoCalculateConsensus = autoCalculate.isSelected(); + // if (viewport.autoCalculateConsensus) { - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + viewport.notifyAlignment(); } } @@ -3693,6 +3839,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param options * parameters for the distance or similarity calculation */ + void newTreePanel(String type, String modelName, SimilarityParamsI options) { @@ -3754,6 +3901,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param order * DOCUMENT ME! */ + public void addSortByOrderMenuItem(String title, final AlignmentOrder order) { @@ -3763,6 +3911,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, sort.add(item); item.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { @@ -3789,6 +3938,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * the label used to retrieve scores for each sequence on the * alignment */ + public void addSortByAnnotScoreMenuItem(JMenu sort, final String scoreLabel) { @@ -3796,6 +3946,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, sort.add(item); item.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { @@ -3821,6 +3972,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * rebuilding in subsequence calls. * */ + @Override public void buildSortByAnnotationScoresMenu() { @@ -3867,6 +4019,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * closed, and adjust the tree leaf to sequence mapping when the alignment is * modified. */ + @Override public void buildTreeSortMenu() { @@ -3896,6 +4049,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, final JMenuItem item = new JMenuItem(tp.getTitle()); item.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { @@ -3927,6 +4081,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * be submitted for multiple alignment. * */ + public jalview.datamodel.AlignmentView gatherSequencesForAlignment() { // Now, check we have enough sequences @@ -3972,6 +4127,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * region or the whole alignment. (where the first sequence in the set is the * one that the prediction will be for). */ + public AlignmentView gatherSeqOrMsaForSecStrPrediction() { AlignmentView seqs = null; @@ -4005,6 +4161,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param e * DOCUMENT ME! */ + @Override protected void loadTreeMenuItem_actionPerformed(ActionEvent e) { @@ -4019,6 +4176,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, chooser.setResponseHandler(0, new Runnable() { + @Override public void run() { @@ -4083,6 +4241,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * position * @return TreePanel handle */ + public TreePanel showNewickTree(NewickFile nf, String treeTitle, AlignmentView input, int w, int h, int x, int y) { @@ -4128,6 +4287,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Generates menu items and listener event actions for web service clients * */ + public void BuildWebServiceMenu() { while (buildingMenu) @@ -4144,6 +4304,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, buildingMenu = true; new Thread(new Runnable() { + @Override public void run() { @@ -4179,8 +4340,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // JAL-940 - only show secondary structure prediction services from // the legacy server Hashtable> ds = Discoverer - .getServices(); - + .getInstance().getServices(); if (// Cache.getDefault("SHOW_JWS1_SERVICES", true) // && ds != null && (ds.size() > 0)) @@ -4222,6 +4382,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { @@ -4241,7 +4402,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, webService.add(me.webServiceNoServices); } // TODO: move into separate menu builder class. - boolean new_sspred = false; + // boolean new_sspred = false; if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { Jws2Discoverer jws2servs = Jws2Discoverer.getInstance(); @@ -4306,6 +4467,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param webService */ + protected void build_urlServiceMenu(JMenu webService) { // TODO: remove this code when 2.7 is released @@ -4314,7 +4476,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final * AlignFrame af = this; testAlView.addActionListener(new ActionListener() { * - * @Override public void actionPerformed(ActionEvent e) { + * public void actionPerformed(ActionEvent e) { * jalview.datamodel.AlignmentView * .testSelectionViews(af.viewport.getAlignment(), * af.viewport.getColumnSelection(), af.viewport.selectionGroup); } @@ -4343,6 +4505,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @return true if Show Cross-references menu should be enabled */ + public boolean canShowProducts() { SequenceI[] seqs = viewport.getAlignment().getSequencesArray(); @@ -4370,6 +4533,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, JMenuItem xtype = new JMenuItem(source); xtype.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { @@ -4402,6 +4566,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param source * the database to show cross-references for */ + protected void showProductsFor(final SequenceI[] sel, final boolean _odna, final String source) { @@ -4413,6 +4578,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Construct and display a new frame containing the translation of this * frame's DNA sequences to their aligned protein (amino acid) equivalents. */ + @Override public void showTranslation_actionPerformed(GeneticCodeI codeTable) { @@ -4470,6 +4636,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param format */ + public void setFileFormat(FileFormatI format) { this.currentFileFormat = format; @@ -4484,11 +4651,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * access mode of file (see jalview.io.AlignFile) * @return true if features file was parsed correctly. */ + public boolean parseFeaturesFile(Object file, DataSourceType sourceType) { // BH 2018 return avc.parseFeaturesFile(file, sourceType, - Cache.getDefault("RELAXEDSEQIDMATCHING", false)); + Cache.getDefault(Preferences.RELAXEDSEQIDMATCHING, false)); } @@ -4544,6 +4712,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { new Thread(new Runnable() { + @Override public void run() { @@ -4642,8 +4811,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int assocfiles = 0; if (filesmatched.size() > 0) { - boolean autoAssociate = Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", - false); + boolean autoAssociate = Cache + .getDefault(Preferences.AUTOASSOCIATE_PDBANDSEQS, false); if (!autoAssociate) { String msg = MessageManager.formatMessage( @@ -4665,10 +4834,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // associating PDB files which have no IDs. for (SequenceI toassoc : (SequenceI[]) fm[2]) { - PDBEntry pe = new AssociatePdbFileWithSeq() - .associatePdbWithSeq(fm[0].toString(), - (DataSourceType) fm[1], toassoc, false, - Desktop.getInstance()); + PDBEntry pe = AssociatePdbFileWithSeq.associatePdbWithSeq( + fm[0].toString(), (DataSourceType) fm[1], toassoc, + false); if (pe != null) { System.err.println("Associated file : " + (fm[0].toString()) @@ -4733,6 +4901,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param file * either a filename or a URL string. */ + public void loadJalviewDataFile(Object file, DataSourceType sourceType, FileFormatI format, SequenceI assocSeq) { @@ -4897,6 +5066,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param state * visible or invisible */ + public void setFeatureGroupState(String[] groups, boolean state) { jalview.api.FeatureRenderer fr = null; @@ -4918,6 +5088,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Method invoked by the ChangeListener on the tabbed pane, in other words * when a different tabbed pane is selected by the user or programmatically. */ + @Override public void tabSelectionChanged(int index) { @@ -4988,6 +5159,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * On right mouse click on view tab, prompt for and set new view name. */ + @Override public void tabbedPane_mousePressed(MouseEvent e) { @@ -5014,6 +5186,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Open the dialog for regex description parsing. */ + @Override protected void extractScores_actionPerformed(ActionEvent e) { @@ -5037,6 +5210,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent * ) */ + @Override protected void showDbRefs_actionPerformed(ActionEvent e) { @@ -5049,6 +5223,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event. * ActionEvent) */ + @Override protected void showNpFeats_actionPerformed(ActionEvent e) { @@ -5061,6 +5236,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param av */ + public boolean closeView(AlignViewportI av) { if (viewport == av) @@ -5104,6 +5280,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true)); trimrs.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { @@ -5125,6 +5302,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { new Thread(new Runnable() { + @Override public void run() { @@ -5136,6 +5314,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.alignFrame.featureSettings, isNucleotide); dbRefFetcher.addListener(new FetchFinishedListenerI() { + @Override public void finished() { @@ -5159,16 +5338,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, rfetch.add(fetchr); new Thread(new Runnable() { + @Override public void run() { - final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher - .getSequenceFetcherSingleton(); + // ?? + // final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher + // .getSequenceFetcherSingleton(); javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { + jalview.ws.SequenceFetcher sf = jalview.ws.SequenceFetcher + .getInstance(); String[] dbclasses = sf.getNonAlignmentSources(); List otherdb; JMenu dfetch = new JMenu(); @@ -5192,9 +5376,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (otherdb.size() == 1) { - final DbSourceProxy[] dassource = otherdb - .toArray(new DbSourceProxy[0]); DbSourceProxy src = otherdb.get(0); + DbSourceProxy[] dassource = new DbSourceProxy[] { src }; fetchr = new JMenuItem(src.getDbSource()); fetchr.addActionListener(new ActionListener() { @@ -5219,6 +5402,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, dbRefFetcher .addListener(new FetchFinishedListenerI() { + @Override public void finished() { @@ -5253,6 +5437,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { src.getDbSource() })); fetchr.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { @@ -5273,6 +5458,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, dbRefFetcher .addListener(new FetchFinishedListenerI() { + @Override public void finished() { @@ -5341,6 +5527,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, dbRefFetcher .addListener(new FetchFinishedListenerI() { + @Override public void finished() { @@ -5392,23 +5579,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Left justify the whole alignment. */ + @Override protected void justifyLeftMenuItem_actionPerformed(ActionEvent e) { - AlignmentI al = viewport.getAlignment(); - al.justify(false); - viewport.firePropertyChange("alignment", null, al); + viewport.getAlignment().justify(false); + viewport.notifyAlignment(); } /** * Right justify the whole alignment. */ + @Override protected void justifyRightMenuItem_actionPerformed(ActionEvent e) { - AlignmentI al = viewport.getAlignment(); - al.justify(true); - viewport.firePropertyChange("alignment", null, al); + viewport.getAlignment().justify(true); + viewport.notifyAlignment(); } @Override @@ -5425,6 +5612,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java. * awt.event.ActionEvent) */ + @Override protected void showUnconservedMenuItem_actionPerformed(ActionEvent e) { @@ -5439,6 +5627,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event * .ActionEvent) */ + @Override protected void showGroupConsensus_actionPerformed(ActionEvent e) { @@ -5454,6 +5643,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt * .event.ActionEvent) */ + @Override protected void showGroupConservation_actionPerformed(ActionEvent e) { @@ -5468,6 +5658,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt * .event.ActionEvent) */ + @Override protected void showConsensusHistogram_actionPerformed(ActionEvent e) { @@ -5482,6 +5673,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt * .event.ActionEvent) */ + @Override protected void showSequenceLogo_actionPerformed(ActionEvent e) { @@ -5511,6 +5703,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt * .event.ActionEvent) */ + @Override protected void makeGrpsFromSelection_actionPerformed(ActionEvent e) { @@ -5562,6 +5755,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param alignmentPanel */ + public void setDisplayedView(AlignmentPanel alignmentPanel) { if (!viewport.getSequenceSetId() @@ -5586,6 +5780,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param forAlignment * update non-sequence-related annotations */ + @Override protected void setAnnotationsVisibility(boolean visible, boolean forSequences, boolean forAlignment) @@ -5619,6 +5814,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Store selected annotation sort order for the view and repaint. */ + @Override protected void sortAnnotations_actionPerformed() { @@ -5632,6 +5828,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @return alignment panels in this alignment frame */ + public List getAlignPanels() { // alignPanels is never null @@ -5643,6 +5840,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Open a new alignment window, with the cDNA associated with this (protein) * alignment, aligned as is the protein. */ + protected void viewAsCdna_actionPerformed() { // TODO no longer a menu action - refactor as required @@ -5693,6 +5891,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param show */ + @Override protected void showComplement_actionPerformed(boolean show) { @@ -5707,6 +5906,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Generate the reverse (optionally complemented) of the selected sequences, * and add them to the alignment */ + @Override protected void showReverse_actionPerformed(boolean complement) { @@ -5732,6 +5932,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to * be targeted at this alignment. */ + @Override protected void runGroovy_actionPerformed() { @@ -5765,6 +5966,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param columnsContaining * @return */ + public boolean hideFeatureColumns(String featureType, boolean columnsContaining) { @@ -5797,6 +5999,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Rebuilds the Colour menu, including any user-defined colours which have * been loaded either on startup or during the session */ + public void buildColourMenu() { colourMenu.removeAll(); @@ -5824,6 +6027,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Open a dialog (if not already open) that allows the user to select and * calculate PCA or Tree analysis */ + protected void openTreePcaDialog() { if (alignPanel.getCalculationDialog() == null) @@ -5843,6 +6047,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, final AlignFrame us = this; chooser.setResponseHandler(0, new Runnable() { + @Override public void run() { @@ -5894,6 +6099,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * true is visible * @return list */ + public String[] getFeatureGroupsOfState(boolean visible) { jalview.api.FeatureRenderer fr = null; @@ -5911,6 +6117,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @return list of feature groups on the view */ + public String[] getFeatureGroups() { jalview.api.FeatureRenderer fr = null; @@ -5930,48 +6137,47 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.getSeqPanel().selection(sel, csel, hidden, null); } - public int getID() { return id; } -} - -class PrintThread extends Thread -{ - AlignmentPanel ap; - - public PrintThread(AlignmentPanel ap) - { - this.ap = ap; - } - - static PageFormat pf; - - @Override - public void run() + static class PrintThread extends Thread { - PrinterJob printJob = PrinterJob.getPrinterJob(); + AlignmentPanel ap; - if (pf != null) - { - printJob.setPrintable(ap, pf); - } - else + public PrintThread(AlignmentPanel ap) { - printJob.setPrintable(ap); + this.ap = ap; } - if (printJob.printDialog()) + static PageFormat pf; + + @Override + public void run() { - try + PrinterJob printJob = PrinterJob.getPrinterJob(); + + if (pf != null) { - printJob.print(); - } catch (Exception PrintException) + printJob.setPrintable(ap, pf); + } + else { - PrintException.printStackTrace(); + printJob.setPrintable(ap); + } + + if (printJob.printDialog()) + { + try + { + printJob.print(); + } catch (Exception PrintException) + { + PrintException.printStackTrace(); + } } } } } + diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index a5c899a..7ab84ad 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -223,7 +223,7 @@ f */ setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false)); setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false)); - autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true); + autoCalculateConsensusAndConservation = Cache.getDefault("AUTO_CALC_CONSENSUS", true); setPadGaps(Cache.getDefault("PAD_GAPS", true)); setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true)); @@ -754,7 +754,8 @@ f */ } ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18 - firePropertyChange("alignment", null, getAlignment().getSequences()); + notifyAlignment(); + } /** @@ -1147,4 +1148,5 @@ f */ { this.viewName = viewName; } + } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 5696c3a..cb2b3ed 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; @@ -63,11 +40,34 @@ import java.beans.PropertyChangeListener; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.List; import javax.swing.SwingUtilities; +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.AlignmentViewport; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; + /** * DOCUMENT ME! * @@ -123,7 +123,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)); @@ -174,6 +174,7 @@ public class AlignmentPanel extends GAlignmentPanel implements ranges.setViewportWidth(widthInRes); ranges.setViewportHeight(heightInSeq); } + repaint(); } }); @@ -184,10 +185,17 @@ public class AlignmentPanel extends GAlignmentPanel implements @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("alignment")) - { + switch (evt.getPropertyName()) { + case AlignmentViewport.PROPERTY_SEQUENCE: + updateScrollBarsFromRanges(); + if (annotationPanel != null) + annotationPanel.paintImmediately(0, 0, getWidth(), getHeight()); + break; + case AlignmentViewport.PROPERTY_ALIGNMENT: + updateScrollBarsFromRanges(); PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true); alignmentChanged(); + break; } } }; @@ -260,32 +268,37 @@ public class AlignmentPanel extends GAlignmentPanel implements int oldWidth = av.getIdWidth(); // calculate sensible default width when no preference is available - Dimension r = null; + Dimension d = null; if (av.getIdWidth() < 0) { - int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300); - int idWidth = Math.min(afwidth - 200, 2 * afwidth / 3); - int maxwidth = Math.max(IdwidthAdjuster.MIN_ID_WIDTH, idWidth); - r = calculateIdWidth(maxwidth); - av.setIdWidth(r.width); + int maxWidth = getMaxWidth(); + d = calculateIdWidth(maxWidth); + av.setIdWidth(d.width); } else { - r = new Dimension(); - r.width = av.getIdWidth(); - r.height = 0; + d = new Dimension(); + d.width = av.getIdWidth(); + d.height = 0; } /* * fudge: if desired width has changed, update layout * (see also paintComponent - updates layout on a repaint) */ - if (r.width != oldWidth) + if (d.width != oldWidth) { - idPanelHolder.setPreferredSize(r); + idPanelHolder.setPreferredSize(d); validate(); } - return r; + return d; + } + + public int getMaxWidth() + { + int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300); + int idWidth = Math.min(afwidth - 200, 2 * afwidth / 3); + return Math.max(IdwidthAdjuster.MIN_ID_WIDTH, idWidth); } /** @@ -297,10 +310,9 @@ public class AlignmentPanel extends GAlignmentPanel implements * @return Dimension giving the maximum width of the alignment label panel * that should be used. */ - protected Dimension calculateIdWidth(int maxwidth) + public Dimension calculateIdWidth(int maxwidth) { - Container c = new Container(); - + Container c = this;// new Container(); FontMetrics fm = c.getFontMetrics( new Font(av.font.getName(), Font.ITALIC, av.font.getSize())); @@ -308,10 +320,12 @@ public class AlignmentPanel extends GAlignmentPanel implements int i = 0; int idWidth = 0; + boolean withSuffix = av.getShowJVSuffix(); + while ((i < al.getHeight()) && (al.getSequenceAt(i) != null)) { SequenceI s = al.getSequenceAt(i); - String id = s.getDisplayId(av.getShowJVSuffix()); + String id = s.getDisplayId(withSuffix); int stringWidth = fm.stringWidth(id); idWidth = Math.max(idWidth, stringWidth); i++; @@ -472,8 +486,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 @@ -573,7 +586,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(); @@ -588,10 +600,10 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public void updateLayout() { + ViewportRanges ranges = av.getRanges(); fontChanged(); setAnnotationVisible(av.isShowAnnotation()); boolean wrap = av.getWrapAlignment(); - ViewportRanges ranges = av.getRanges(); ranges.setStartSeq(0); scalePanelHolder.setVisible(!wrap); hscroll.setVisible(!wrap); @@ -695,12 +707,17 @@ public class AlignmentPanel extends GAlignmentPanel implements x = 0; } - // update the scroll values - hscroll.setValues(x, hextent, 0, width); - vscroll.setValues(y, vextent, 0, height); + updateRanges(x, y); + updateScrollBars(x, y, width, height); } } + private void updateScrollBars(int x, int y, int width, int height) + { + hscroll.setValues(x, hextent, 0, width); + vscroll.setValues(y, vextent, 0, height); + } + /** * Respond to adjustment event when horizontal or vertical scrollbar is * changed @@ -717,41 +734,54 @@ public class AlignmentPanel extends GAlignmentPanel implements return; } - ViewportRanges ranges = av.getRanges(); - if (evt.getSource() == hscroll) { + if (!updateRanges(hscroll.getValue(), Integer.MIN_VALUE)) + return; + } + else if (evt.getSource() == vscroll) + { + if (!updateRanges(Integer.MIN_VALUE, vscroll.getValue())) + return; + } + repaint(); + } + + private boolean updateRanges(int x, int y) + { + ViewportRanges ranges = av.getRanges(); + boolean isChanged = false; + if (x != Integer.MIN_VALUE) + { int oldX = ranges.getStartRes(); int oldwidth = ranges.getViewportWidth(); - int x = hscroll.getValue(); int width = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); // if we're scrolling to the position we're already at, stop // this prevents infinite recursion of events when the scroll/viewport // ranges values are the same - if ((x == oldX) && (width == oldwidth)) + if (width > 0 && (x != oldX || width != oldwidth)) { - return; + ranges.setViewportStartAndWidth(x, width); + isChanged = true; } - ranges.setViewportStartAndWidth(x, width); } - else if (evt.getSource() == vscroll) + if (y != Integer.MIN_VALUE) { int oldY = ranges.getStartSeq(); int oldheight = ranges.getViewportHeight(); - int y = vscroll.getValue(); int height = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); // if we're scrolling to the position we're already at, stop // this prevents infinite recursion of events when the scroll/viewport // ranges values are the same - if ((y == oldY) && (height == oldheight)) + if (height > 0 && (y != oldY || height != oldheight)) { - return; + ranges.setViewportStartAndHeight(y, height); + isChanged = true; } - ranges.setViewportStartAndHeight(y, height); } - repaint(); + return isChanged; } /** @@ -830,7 +860,6 @@ public class AlignmentPanel extends GAlignmentPanel implements av.isShowAutocalculatedAbove()); sorter.sort(getAlignment().getAlignmentAnnotation(), av.getSortAnnotationsBy()); - repaint(); if (updateStructures) { @@ -838,11 +867,14 @@ public class AlignmentPanel extends GAlignmentPanel implements } if (updateOverview) { + alignFrame.repaint(); if (overviewPanel != null) { overviewPanel.updateOverviewImage(); } + } else { + repaint(); } } @@ -862,7 +894,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * though I still think this call should be elsewhere. */ ViewportRanges ranges = av.getRanges(); - setScrollValues(ranges.getStartRes(), ranges.getStartSeq()); + // setScrollValues(ranges.getStartRes(), ranges.getStartSeq()); super.paintComponent(g); } @@ -1021,8 +1053,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)) @@ -1066,8 +1098,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(); int annotationHeight = 0; @@ -1118,8 +1150,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 +1316,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 +1339,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()) @@ -1702,10 +1736,7 @@ public class AlignmentPanel extends GAlignmentPanel implements public void propertyChange(PropertyChangeEvent evt) { // update this panel's scroll values based on the new viewport ranges values - ViewportRanges ranges = av.getRanges(); - int x = ranges.getStartRes(); - int y = ranges.getStartSeq(); - setScrollValues(x, y); + updateScrollBarsFromRanges(); // now update any complementary alignment (its viewport ranges object // is different so does not get automatically updated) @@ -1717,6 +1748,12 @@ public class AlignmentPanel extends GAlignmentPanel implements } } + void updateScrollBarsFromRanges() + { + ViewportRanges ranges = av.getRanges(); + setScrollValues(ranges.getStartRes(), ranges.getStartSeq()); + } + /** * Set the reference to the PCA/Tree chooser dialog for this panel. This * reference should be nulled when the dialog is closed. @@ -1920,7 +1957,7 @@ public class AlignmentPanel extends GAlignmentPanel implements PaintRefresher.Refresh(this, av.getSequenceSetId()); } - public void selectSequences(List seqs) + public void selectSequences(List seqs) { SequenceGroup sg = new SequenceGroup(seqs); sg.setEndRes(av.getAlignment().getWidth() - 1); diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 35ae242..01be3b5 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -1009,23 +1009,28 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, g.setColor(Color.white); g.fillRect(0, 0, visibleRect.width, visibleRect.height); + ViewportRanges ranges = av.getRanges(); + + + if (image != null) { // BH 2018 optimizing generation of new Rectangle(). if (fastPaint || (visibleRect.width != (clipBounds = g.getClipBounds(clipBounds)).width) || (visibleRect.height != clipBounds.height)) { - - g.drawImage(image, 0, 0, this); fastPaint = false; return; } } - imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() + + imgWidth = (ranges.getEndRes() - ranges.getStartRes() + 1) * av.getCharWidth(); + if (imgWidth < 1) { + fastPaint = false; return; } Graphics2D gg; @@ -1068,8 +1073,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, gg = (Graphics2D) image.getGraphics(); } - - drawComponent(gg, av.getRanges().getStartRes(), + + drawComponent(gg, ranges.getStartRes(), av.getRanges().getEndRes() + 1); gg.dispose(); imageFresh = false; @@ -1077,11 +1082,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } /** - * set true to enable redraw timing debug output on stderr - */ - private final boolean debugRedraw = false; - - /** * non-Thread safe repaint * * @param horizontal @@ -1101,6 +1101,11 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, int sr = av.getRanges().getStartRes(); int er = av.getRanges().getEndRes() + 1; int transX = 0; + + if (er == sr + 1) { + fastPaint = false; + return; + } Graphics2D gg = (Graphics2D) image.getGraphics(); diff --git a/src/jalview/gui/AssociatePdbFileWithSeq.java b/src/jalview/gui/AssociatePdbFileWithSeq.java index 154582f..5b5bd18 100644 --- a/src/jalview/gui/AssociatePdbFileWithSeq.java +++ b/src/jalview/gui/AssociatePdbFileWithSeq.java @@ -20,18 +20,15 @@ */ package jalview.gui; -import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.StructureFile; -import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; -import javax.swing.JOptionPane; - /** - * GUI related routines for associating PDB files with sequences + * GUI related routines for associating PDB files with sequences. A single + * static method. * * @author JimP * @@ -39,58 +36,56 @@ import javax.swing.JOptionPane; public class AssociatePdbFileWithSeq { + private AssociatePdbFileWithSeq() + { + // inaccessible + } + /** - * assocate the given PDB file with + * Associate the given PDB file name or URL with a sequence. Do not map + * mouse-over events. * - * @param choice + * @param fileName + * or URL + * @param type + * will be DataType.FILE or DataType.URL * @param sequence + * to associate + * @param prompt + * true if the user should be asked what to do if the specified file + * does not seem to contain PDB information (StructureChooser only) + * @return null if file is not found */ - public PDBEntry associatePdbWithSeq(String choice, DataSourceType file, - SequenceI sequence, boolean prompt, - StructureSelectionManagerProvider ssmp) + public static PDBEntry associatePdbWithSeq(String fileName, + DataSourceType type, SequenceI sequence, boolean prompt) { PDBEntry entry = new PDBEntry(); StructureFile pdbfile = null; - pdbfile = StructureSelectionManager.getStructureSelectionManager(ssmp) + pdbfile = Desktop.getStructureSelectionManager() .setMapping(false, new SequenceI[] - { sequence }, null, choice, file); + { sequence }, null, fileName, type); if (pdbfile == null) { // stacktrace already thrown so just return return null; } - if (pdbfile.getId() == null) - { - String reply = null; - - if (prompt) - { - reply = JvOptionPane.showInternalInputDialog(Desktop.getDesktopPane(), - MessageManager - .getString("label.couldnt_find_pdb_id_in_file"), - MessageManager.getString("label.no_pdb_id_in_file"), - JvOptionPane.QUESTION_MESSAGE); - } - if (reply == null) - { - return null; - } - - entry.setId(reply); - } - else + String id = pdbfile.getId(); + if (id == null && (id = (prompt + ? JvOptionPane.showInternalInputDialog(Desktop.getDesktopPane(), + MessageManager + .getString("label.couldnt_find_pdb_id_in_file"), + MessageManager.getString("label.no_pdb_id_in_file"), + JvOptionPane.QUESTION_MESSAGE) + : null)) == null) { - entry.setId(pdbfile.getId()); + return null; } + entry.setId(id); entry.setType(PDBEntry.Type.FILE); - - if (pdbfile != null) - { - entry.setFile(choice); - sequence.getDatasetSequence().addPDBId(entry); - StructureSelectionManager.getStructureSelectionManager(ssmp) - .registerPDBEntry(entry); - } + entry.setFile(fileName); + sequence.getDatasetSequence().addPDBId(entry); + Desktop.getStructureSelectionManager() + .registerPDBEntry(entry); return entry; } } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 4b25ef2..a1d9a09 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -482,82 +482,89 @@ public class Desktop extends GDesktop experimentalFeatures.setSelected(showExperimental()); - checkURLLinks(); + if (Jalview.isInteractive()) + { + // disabled for SeqCanvasTest + checkURLLinks(); - // Spawn a thread that shows the splashscreen + checkURLLinks(); - SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - new SplashScreen(true); - } - }); + // Spawn a thread that shows the splashscreen - // Thread off a new instance of the file chooser - this reduces the time - // it - // takes to open it later on. - new Thread(new Runnable() - { - @Override - public void run() + SwingUtilities.invokeLater(new Runnable() { - Cache.log.debug("Filechooser init thread started."); - String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); - JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), - fileFormat); - Cache.log.debug("Filechooser init thread finished."); - } - }).start(); - // Add the service change listener - changeSupport.addJalviewPropertyChangeListener("services", - new PropertyChangeListener() - { + @Override + public void run() + { + new SplashScreen(true); + } + }); - @Override - public void propertyChange(PropertyChangeEvent evt) + // Thread off a new instance of the file chooser - this reduces the + // time + // it + // takes to open it later on. + new Thread(new Runnable() + { + @Override + public void run() + { + Cache.log.debug("Filechooser init thread started."); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser.forRead( + Cache.getProperty("LAST_DIRECTORY"), fileFormat); + Cache.log.debug("Filechooser init thread finished."); + } + }).start(); + // Add the service change listener + changeSupport.addJalviewPropertyChangeListener("services", + new PropertyChangeListener() { - Cache.log.debug("Firing service changed event for " - + evt.getNewValue()); - JalviewServicesChanged(evt); - } - }); - } - - this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); - this.addWindowListener(new WindowAdapter() - { - @Override - public void windowClosing(WindowEvent evt) - { - quit(); + @Override + public void propertyChange(PropertyChangeEvent evt) + { + Cache.log.debug("Firing service changed event for " + + evt.getNewValue()); + JalviewServicesChanged(evt); + } + }); } - }); - MouseAdapter ma; - this.addMouseListener(ma = new MouseAdapter() - { - @Override - public void mousePressed(MouseEvent evt) + this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); + + this.addWindowListener(new WindowAdapter() { - if (evt.isPopupTrigger()) // Mac + @Override + public void windowClosing(WindowEvent evt) { - showPasteMenu(evt.getX(), evt.getY()); + quit(); } - } + }); - @Override - public void mouseReleased(MouseEvent evt) + MouseAdapter ma; + this.addMouseListener(ma = new MouseAdapter() { - if (evt.isPopupTrigger()) // Windows + @Override + public void mousePressed(MouseEvent evt) { - showPasteMenu(evt.getX(), evt.getY()); + if (evt.isPopupTrigger()) // Mac + { + showPasteMenu(evt.getX(), evt.getY()); + } } - } - }); - desktopPane.addMouseListener(ma); + + @Override + public void mouseReleased(MouseEvent evt) + { + if (evt.isPopupTrigger()) // Windows + { + showPasteMenu(evt.getX(), evt.getY()); + } + } + }); + desktopPane.addMouseListener(ma); + } } catch (Throwable t) { t.printStackTrace(); diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index ff70162..dc7fea3 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -2040,8 +2040,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener ap.paintAlignment(false, false); } sequence.setDescription(dialog.getDescription()); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } }); } @@ -2172,9 +2171,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener startEnd, caseChange); ap.alignFrame.addHistoryItem(caseCommand); + ap.av.notifyAlignment(); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); } } @@ -2281,8 +2279,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment()); ap.alignFrame.addHistoryItem(editCommand); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } }); } diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index 1725a8a..c7e2b8e 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -263,8 +263,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable ap.alignFrame.addHistoryItem(cut); PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } } @@ -289,8 +288,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable { command.undoCommand(af.getViewAlignments()); ap.av.getHistoryList().remove(command); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.notifyAlignment(); af.updateEditMenuBar(); } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index a6b4b49..fda1e03 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -180,9 +180,7 @@ public class ScalePanel extends JPanel { av.showColumn(hiddenRange[0]); reveal = null; - ap.updateLayout(); - ap.paintAlignment(true, true); - av.sendSelection(); + updatePanel(); } }); pop.add(item); @@ -197,9 +195,7 @@ public class ScalePanel extends JPanel { av.showAllHiddenColumns(); reveal = null; - ap.updateLayout(); - ap.paintAlignment(true, true); - av.sendSelection(); + updatePanel(); } }); pop.add(item); @@ -221,10 +217,7 @@ public class ScalePanel extends JPanel { av.setSelectionGroup(null); } - - ap.updateLayout(); - ap.paintAlignment(true, true); - av.sendSelection(); + updatePanel(); } }); pop.add(item); @@ -232,6 +225,14 @@ public class ScalePanel extends JPanel return pop; } + protected void updatePanel() + { + ap.updateLayout(); + ap.paintAlignment(true, true); + ap.updateScrollBarsFromRanges(); + av.sendSelection(); + } + /** * Handles left mouse button press * diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 4e789b9..3de631f 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -423,8 +423,7 @@ public class SeqPanel extends JPanel if (editCommand != null && editCommand.getSize() > 0) { ap.alignFrame.addHistoryItem(editCommand); - av.firePropertyChange("alignment", null, - av.getAlignment().getSequences()); + ap.av.notifyAlignment(); } } finally { diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 5b94831..c30d8c7 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -1001,10 +1001,8 @@ public class StructureChooser extends GStructureChooser { selectedSequence = userSelectedSeq; } - PDBEntry fileEntry = new AssociatePdbFileWithSeq() - .associatePdbWithSeq(selectedPdbFileName, - DataSourceType.FILE, selectedSequence, true, - Desktop.getInstance()); + PDBEntry fileEntry = AssociatePdbFileWithSeq.associatePdbWithSeq(selectedPdbFileName, + DataSourceType.FILE, selectedSequence, true); sViewer = StructureViewer.launchStructureViewer(ap, new PDBEntry[] { fileEntry }, new SequenceI[] { selectedSequence }, superimpose, theViewer, diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 37b4dac..d242892 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -174,11 +174,12 @@ public class TreePanel extends GTreePanel { final PropertyChangeListener listener = new PropertyChangeListener() { + @SuppressWarnings("unchecked") @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("alignment")) - { + switch (evt.getPropertyName()) { + case AlignmentViewport.PROPERTY_ALIGNMENT: if (tree == null) { System.out.println("tree is null"); @@ -191,12 +192,14 @@ public class TreePanel extends GTreePanel { System.out.println( "new alignment sequences vector value is null"); + return; } tree.updatePlaceHolders((List) evt.getNewValue()); treeCanvas.nameHash.clear(); // reset the mapping between canvas // rectangles and leafnodes repaint(); + break; } } }; diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 4f399f0..4148c72 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -83,6 +83,9 @@ import java.util.Map; public abstract class AlignmentViewport implements AlignViewportI, CommandListener, VamsasSource { + public static final String PROPERTY_ALIGNMENT = "alignment"; + public static final String PROPERTY_SEQUENCE = "sequence"; + protected ViewportRanges ranges; protected ViewStyleI viewStyle = new ViewStyle(); @@ -605,10 +608,31 @@ public abstract class AlignmentViewport protected ColumnSelection colSel = new ColumnSelection(); - public boolean autoCalculateConsensus = true; + protected boolean autoCalculateConsensusAndConservation = true; + + public boolean getAutoCalculateConsensusAndConservation() + { // BH 2019.07.24 + return autoCalculateConsensusAndConservation; + } + + public void setAutoCalculateConsensusAndConservation(boolean b) + { + autoCalculateConsensusAndConservation = b; + } protected boolean autoCalculateStrucConsensus = true; + public boolean getAutoCalculateStrucConsensus() + { // BH 2019.07.24 + return autoCalculateStrucConsensus; + } + + public void setAutoCalculateStrucConsensus(boolean b) + { + autoCalculateStrucConsensus = b; + } + + protected boolean ignoreGapsInConsensusCalculation = false; protected ResidueShaderI residueShading = new ResidueShader(); @@ -824,7 +848,7 @@ public abstract class AlignmentViewport // see note in mantis : issue number 8585 if (alignment.isNucleotide() || (conservation == null && quality == null) - || !autoCalculateConsensus) + || !autoCalculateConsensusAndConservation) { return; } @@ -842,7 +866,7 @@ public abstract class AlignmentViewport public void updateConsensus(final AlignmentViewPanel ap) { // see note in mantis : issue number 8585 - if (consensus == null || !autoCalculateConsensus) + if (consensus == null || !autoCalculateConsensusAndConservation) { return; } @@ -1275,21 +1299,22 @@ public abstract class AlignmentViewport * checks current colsel against record of last hash value, and optionally * updates record. * - * @param b + * @param updateHash * update the record of last hash value * @return true if colsel changed since last call (when b is true) */ - public boolean isColSelChanged(boolean b) + public boolean isColSelChanged(boolean updateHash) { int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); if (hc != -1 && hc != colselhash) { - if (b) + if (updateHash) { colselhash = hc; } return true; } + notifySequence(); return false; } @@ -1350,22 +1375,6 @@ public abstract class AlignmentViewport } } - /** - * Property change listener for changes in alignment - * - * @param prop - * DOCUMENT ME! - * @param oldvalue - * DOCUMENT ME! - * @param newvalue - * DOCUMENT ME! - */ - public void firePropertyChange(String prop, Object oldvalue, - Object newvalue) - { - changeSupport.firePropertyChange(prop, oldvalue, newvalue); - } - // common hide/show column stuff public void hideSelectedColumns() @@ -1430,13 +1439,14 @@ public abstract class AlignmentViewport ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); - firePropertyChange("alignment", null, alignment.getSequences()); // used to set hasHiddenRows/hiddenRepSequences here, after the property // changed event + notifySequence(); sendSelection(); } } + public void showSequence(int index) { int startSeq = ranges.getStartSeq(); @@ -1459,8 +1469,7 @@ public abstract class AlignmentViewport } ranges.setStartEndSeq(startSeq, endSeq + tmp.size()); - - firePropertyChange("alignment", null, alignment.getSequences()); + notifyAlignment(); sendSelection(); } } @@ -1494,7 +1503,7 @@ public abstract class AlignmentViewport setSequenceAnnotationsVisible(seq[i], false); } ranges.setStartSeq(startSeq); - firePropertyChange("alignment", null, alignment.getSequences()); + notifyAlignment(); } } @@ -1859,11 +1868,11 @@ public abstract class AlignmentViewport { alignment.padGaps(); } - if (autoCalculateConsensus) + if (autoCalculateConsensusAndConservation) { updateConsensus(ap); } - if (hconsensus != null && autoCalculateConsensus) + if (hconsensus != null && autoCalculateConsensusAndConservation) { updateConservation(ap); } @@ -3078,4 +3087,22 @@ public abstract class AlignmentViewport codingComplement.setUpdateStructures(needToUpdateStructureViews); } } + + + /** + * Notify TreePanel and AlignmentPanel of some sort of alignment change. + */ + public void notifyAlignment() + { + changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences()); + } + + /** + * Notify AlignmentPanel of a sequence column selection or visibility changes. + */ + public void notifySequence() + { + changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null); + } + } diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 4f671da..5a4fc57 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -136,13 +136,25 @@ public class ViewportRanges extends ViewportProperties int[] oldvalues = updateStartEndRes(start, end); int oldstartres = oldvalues[0]; int oldendres = oldvalues[1]; + + if (oldstartres == startRes && oldendres == endRes) + { + return; // BH 2019.07.27 standard check for no changes + } + // "STARTRES" is a misnomer here -- really "STARTORENDRES" + // note that this could be "no change" if the range is just being expanded changeSupport.firePropertyChange(STARTRES, oldstartres, startRes); if (oldstartres == startRes) { + // only caught in ViewportRangesTest + // No listener cares about this + // "ENDRES" is a misnomer here -- really "ENDONLYRES" + // BH 2019.07.27 adds end change check + // fire only if only the end is changed // event won't be fired if start positions are same // fire an event for the end positions in case they changed - changeSupport.firePropertyChange(ENDRES, oldendres, endRes); + changeSupport.firePropertyChange(ENDRES, oldendres, endRes); } } @@ -797,4 +809,10 @@ public class ViewportRanges extends ViewportProperties return maxScroll; } + + + @Override + public String toString() { + return "[ViewportRange " + startSeq + "-" + endSeq + ", "+ startRes + "-" + endRes + "]"; + } } diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java index 24b658f..3d06bc8 100644 --- a/test/jalview/gui/AlignmentPanelTest.java +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -40,6 +40,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import jalview.util.Platform; import jalview.viewmodel.ViewportRanges; public class AlignmentPanelTest @@ -49,8 +50,9 @@ public class AlignmentPanelTest @BeforeMethod(alwaysRun = true) public void setUp() throws InvocationTargetException, InterruptedException { - Jalview.main(new String[] { "-nonews", "-props", - "test/jalview/testProps.jvprops" }); + Jalview.main(new String[] { "-nonews", + "-props", "test/jalview/testProps.jvprops", + "-jabaws", "none"}); Cache.setPropertyNoSave("SHOW_IDENTITY", Boolean.TRUE.toString()); @@ -94,22 +96,29 @@ public class AlignmentPanelTest af.alignPanel.setScrollValues(-1, 5); // setting -ve x value does not change residue + // no update necessary now assertEquals(ranges.getEndRes(), oldres); af.alignPanel.setScrollValues(0, 5); - + // no update necessary now // setting 0 as x value does not change residue + // no update necessary now assertEquals(ranges.getEndRes(), oldres); af.alignPanel.setScrollValues(5, 5); // setting x value to 5 extends endRes by 5 residues + System.out.println(ranges); + // no update necessary now assertEquals(ranges.getEndRes(), oldres + 5); // scroll to position after hidden columns sets endres to oldres (width) + // position - int scrollpos = 60; + + int scrollpos = 53; // was 60, but this is too high to allow full scrolling + // in Windows af.getViewport().hideColumns(30, 50); af.alignPanel.setScrollValues(scrollpos, 5); + // no update necessary now assertEquals(ranges.getEndRes(), oldres + scrollpos); // scroll to position within hidden columns, still sets endres to oldres + @@ -120,6 +129,7 @@ public class AlignmentPanelTest af.getViewport().showAllHiddenColumns(); af.getViewport().hideColumns(30, 50); af.alignPanel.setScrollValues(scrollpos, 5); + // no update necessary now assertEquals(ranges.getEndRes(), oldres + scrollpos); // scroll to position within distance of the end of the alignment @@ -127,8 +137,9 @@ public class AlignmentPanelTest scrollpos = 130; af.getViewport().showAllHiddenColumns(); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(ranges.getEndRes(), af.getViewport() - .getAlignment().getWidth() - 1); + // no update necessary now + assertEquals(ranges.getEndRes(), + af.getViewport().getAlignment().getWidth() - 1); // now hide some columns, and scroll to position within // distance of the end of the alignment @@ -136,9 +147,12 @@ public class AlignmentPanelTest // columns af.getViewport().hideColumns(30, 50); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(ranges.getEndRes(), af.getViewport() - .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden - // columns + // no update necessary now + assertEquals(ranges.getEndRes(), + af.getViewport().getAlignment().getWidth() - 1 - 21); // 21 is the + // number of + // hidden + // columns } /** @@ -192,8 +206,9 @@ public class AlignmentPanelTest * note 4 pixels padding are added to the longest sequence name width */ av.setIdWidth(-1); // force recalculation + d = af.alignPanel.calculateIdWidth(); - assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118" + assertEquals(d.width, Platform.isWin() ? 172 : 166); // 4 + pixel width of "Q93Z60_ARATH/1-118" assertEquals(d.height, 12); assertEquals(d.width, av.getIdWidth()); } @@ -215,7 +230,7 @@ public class AlignmentPanelTest * note 4 pixels 'padding' are added to the longest seq name/annotation label */ Dimension d = af.alignPanel.calculateIdWidth(2000); - assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118" + assertEquals(d.width, Platform.isWin() ? 172 : 166); // 4 + pixel width of "Q93Z60_ARATH/1-118" assertEquals(d.height, 12); // fixed value (not used?) assertEquals(av.getIdWidth(), 18); // not changed by this method @@ -224,11 +239,14 @@ public class AlignmentPanelTest */ SequenceI seq = af.viewport.getAlignment() .findSequenceMatch("Q93Z60_ARATH")[0]; - seq.setName(seq.getName() + "MMMMM"); + String orig = seq.getName(); + seq.setName(orig + "MMMMM"); d = af.alignPanel.calculateIdWidth(2000); - assertEquals(d.width, 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118" + assertEquals(d.width, Platform.isWin() ? 219 : 211); // 4 + pixel width of "Q93Z60_ARATHMMMMM/1-118" assertEquals(d.height, 12); assertEquals(av.getIdWidth(), 18); // unchanged + // for next test: + seq.setName(orig); /* * make the longest annotation name even longer @@ -239,17 +257,19 @@ public class AlignmentPanelTest FontMetrics fmfor = af.alignPanel .getFontMetrics(af.alignPanel.getAlabels().getFont()); // Assumption ID_WIDTH_PADDING == 4 + // AH! But with those added MMMM above, this was NOT the longest label! int expwidth = 4 + fmfor.stringWidth(aa.label); d = af.alignPanel.calculateIdWidth(2000); - assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED" + assertEquals(d.width, expwidth); // 191 == ID_WIDTH_PADDING + pixel width of "THIS IS A VERY LONG LABEL INDEED" assertEquals(d.height, 12); /* * override with maxwidth * note the 4 pixels padding is added to this value */ - d = af.alignPanel.calculateIdWidth(213); - assertEquals(d.width, 217); + // BH but we have to be under the max width + d = af.alignPanel.calculateIdWidth(180); + assertEquals(d.width, 184); assertEquals(d.height, 12); } @@ -261,7 +281,7 @@ public class AlignmentPanelTest */ int w = af.alignPanel.getVisibleIdWidth(true); assertEquals(w, af.alignPanel.getIdPanel().getWidth()); - assertEquals(w, 115); + assertEquals(w, Platform.isWin() ? 112 : 115); /* * width for offscreen rendering is the same @@ -281,6 +301,6 @@ public class AlignmentPanelTest * preference for auto id width overrides fixed width */ Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString()); - assertEquals(115, af.alignPanel.getVisibleIdWidth(false)); + assertEquals(Platform.isWin() ? 106 : 115, af.alignPanel.getVisibleIdWidth(false)); } } diff --git a/test/jalview/gui/PairwiseAlignmentPanelTest.java b/test/jalview/gui/PairwiseAlignmentPanelTest.java index 3322ee8..ca9ac22 100644 --- a/test/jalview/gui/PairwiseAlignmentPanelTest.java +++ b/test/jalview/gui/PairwiseAlignmentPanelTest.java @@ -37,7 +37,7 @@ public class PairwiseAlignmentPanelTest PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport); - String text = ((JTextArea) PA.getValue(testee, "textarea")).getText(); + String text = ((JTextArea) PA.getValue(testee, "textarea")).getText().replace("\r\n", "\n"); String expected = "Score = 80.0\n" + "Length of alignment = 4\n" + "Sequence FER1_PEA/29-32 (Sequence length = 7)\n" + "Sequence Q93XJ9_SOLTU/23-26 (Sequence length = 7)\n\n" @@ -62,7 +62,7 @@ public class PairwiseAlignmentPanelTest PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport); - String text = ((JTextArea) PA.getValue(testee, "textarea")).getText(); + String text = ((JTextArea) PA.getValue(testee, "textarea")).getText().replace("\r\n", "\n"); String expected = "Score = 80.0\n" + "Length of alignment = 4\n" + "Sequence FER1_PEA/29-32 (Sequence length = 7)\n" + "Sequence Q93XJ9_SOLTU/23-26 (Sequence length = 7)\n\n" diff --git a/test/jalview/gui/SeqCanvasTest.java b/test/jalview/gui/SeqCanvasTest.java index 78f6cd3..0e14a6b 100644 --- a/test/jalview/gui/SeqCanvasTest.java +++ b/test/jalview/gui/SeqCanvasTest.java @@ -23,10 +23,12 @@ package jalview.gui; import static org.testng.Assert.assertEquals; import jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.io.DataSourceType; import jalview.io.FileLoader; import jalview.util.Platform; +import jalview.viewmodel.ViewportRanges; import java.awt.Font; import java.awt.FontMetrics; @@ -41,6 +43,7 @@ public class SeqCanvasTest @BeforeClass(alwaysRun = true) public void setUp() { + Jalview.setInteractive(false); Cache.initLogger(); } @@ -65,8 +68,8 @@ public class SeqCanvasTest av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); - assertEquals(charHeight, Platform.isMac() ? 17 : 19); - assertEquals(charWidth, Platform.isMac() ? 12 : 11); + assertEquals(charHeight, !Platform.isWin() ? 17 : 19); + assertEquals(charWidth, !Platform.isWin() ? 12 : 11); /* * first with scales above, left, right @@ -78,7 +81,7 @@ public class SeqCanvasTest FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("000") + charWidth; assertEquals(labelWidth, - Platform.isMac() ? 3 * 9 + charWidth : 3 * 8 + charWidth); + !Platform.isWin() ? 3 * 9 + charWidth : 3 * 8 + charWidth); /* * width 400 pixels leaves (400 - 2*labelWidth) for residue columns @@ -200,7 +203,7 @@ public class SeqCanvasTest canvasWidth += 2; wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - assertEquals(wrappedWidth, Platform.isMac() ? 24 : 25); // 2px not enough + assertEquals(wrappedWidth, !Platform.isWin() ? 24 : 25); // 2px not enough canvasWidth += 1; wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); @@ -235,8 +238,8 @@ public class SeqCanvasTest int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); - assertEquals(charHeight, Platform.isMac() ? 17 : 19); - assertEquals(charWidth, Platform.isMac() ? 12 : 11); + assertEquals(charHeight, !Platform.isWin() ? 17 : 19); + assertEquals(charWidth, !Platform.isWin() ? 12 : 11); SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; @@ -251,7 +254,7 @@ public class SeqCanvasTest FontMetrics fm = testee.getFontMetrics(av.getFont()); int labelWidth = fm.stringWidth("000") + charWidth; assertEquals(labelWidth, - Platform.isMac() ? 3 * 9 + charWidth : 3 * 8 + charWidth); + !Platform.isWin() ? 3 * 9 + charWidth : 3 * 8 + charWidth); int annotationHeight = testee.getAnnotationHeight(); @@ -330,24 +333,31 @@ public class SeqCanvasTest AlignmentI al = av.getAlignment(); assertEquals(al.getWidth(), 157); assertEquals(al.getHeight(), 15); - av.getRanges().setStartEndSeq(0, 3); + + ViewportRanges ranges = av.getRanges(); + ranges.setStartEndSeq(0, 3); + System.out.println(ranges); av.setShowAnnotation(false); av.setScaleAboveWrapped(true); + System.out.println(ranges); SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; av.setWrapAlignment(true); + System.out.println(ranges); av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); + System.out.println(ranges); // Windows h=19, w=11. - assertEquals(charHeight, Platform.isMac() ? 17 : 19); - assertEquals(charWidth, Platform.isMac() ? 12 : 11); - + assertEquals(charHeight, !Platform.isWin() ? 17 : 19); + assertEquals(charWidth, !Platform.isWin() ? 12 : 11); + System.out.println(ranges); + int canvasWidth = 400; int canvasHeight = 300; testee.calculateWrappedGeometry(canvasWidth, canvasHeight); - - assertEquals(av.getRanges().getEndSeq(), 3); // unchanged + System.out.println(ranges); + assertEquals(ranges.getEndSeq(), 3); // unchanged int repeatingHeight = (int) PA.getValue(testee, "wrappedRepeatHeightPx"); int h = charHeight * (2 + al.getHeight());