From c4c37610dc373b9b3349e5c0915c6eddda2efe31 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 21 May 2019 11:29:59 +0100 Subject: [PATCH] JAL-3253-applet disabling button size setting by applet param. Whatever this should do in Java, it doesn't seem to do, and it looks better in JavaScript just to let the button set its own size. --- site-resources/swingjs/JalviewApplet.js | 4 +- src/jalview/datamodel/DBRefEntry.java | 3 +- src/jalview/gui/Console.java | 2 +- src/jalview/gui/Desktop.java | 28 ++++++++--- src/jalview/gui/JalviewDialog.java | 8 +-- src/jalview/gui/SplashScreen.java | 9 ++-- src/jalview/gui/StructureChooser.java | 20 ++++---- src/jalview/httpserver/HttpServer.java | 51 ++++++++++---------- src/jalview/io/HTMLOutput.java | 11 ----- src/jalview/io/JalviewFileFilter.java | 4 -- src/jalview/rest/RestHandler.java | 1 - .../structure/StructureSelectionManager.java | 3 +- src/jalview/urls/IdOrgSettings.java | 15 +++--- src/jalview/util/BrowserLauncher.java | 16 +++--- test/jalview/analysis/AlignmentSorterTest.java | 11 +++-- test/jalview/gui/SeqCanvasTest.java | 8 +++ test/jalview/io/FeaturesFileTest.java | 17 +++---- 17 files changed, 109 insertions(+), 102 deletions(-) diff --git a/site-resources/swingjs/JalviewApplet.js b/site-resources/swingjs/JalviewApplet.js index f410ec3..53f39c6 100644 --- a/site-resources/swingjs/JalviewApplet.js +++ b/site-resources/swingjs/JalviewApplet.js @@ -84,9 +84,9 @@ Jalview.processAppletElement = function(element, UserInfo) { var btn = document.createElement("button"); btn.appletElement = element; var a = element.getAttribute("width"); - btn.style.width = (a || 140) + "px"; + //a && (btn.style.width = (a || 140) + "px"); a = element.getAttribute("height"); - btn.style.height = (a || 25) + "px"; + //a && (btn.style.height = (a || 25) + "px"); btn.jvparent = parent; if (Info.startButton) { btn.innerHTML = Info.startButton; diff --git a/src/jalview/datamodel/DBRefEntry.java b/src/jalview/datamodel/DBRefEntry.java index 54e8379..0004abe 100755 --- a/src/jalview/datamodel/DBRefEntry.java +++ b/src/jalview/datamodel/DBRefEntry.java @@ -21,7 +21,6 @@ package jalview.datamodel; import jalview.api.DBRefEntryI; -import jalview.io.vamsas.Dbref; import jalview.util.DBRefUtils; import jalview.util.MapList; @@ -42,7 +41,7 @@ public class DBRefEntry implements DBRefEntryI private String version = ""; - private String ucversion; + private String ucversion = ""; private String accessionId = ""; diff --git a/src/jalview/gui/Console.java b/src/jalview/gui/Console.java index 3ff8c12..f44dae1 100644 --- a/src/jalview/gui/Console.java +++ b/src/jalview/gui/Console.java @@ -136,7 +136,7 @@ public class Console extends WindowAdapter } quit = false; // signals the Threads that they should exit - // Starting two seperate threads to read from the PipedInputStreams + // Starting two separate threads to read from the PipedInputStreams // reader = new Thread(this); reader.setDaemon(true); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index bc892cf..2a972e3 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -199,13 +199,14 @@ public class Desktop extends GDesktop public static MyDesktopPane getDesktopPane() { - return Desktop.getInstance().desktopPane; + Desktop desktop = Desktop.getInstance(); + return desktop == null ? null : desktop.desktopPane; } - public StructureSelectionManager getStructureSelectionManager() + public static StructureSelectionManager getStructureSelectionManager() { return StructureSelectionManager - .getStructureSelectionManager(this); + .getStructureSelectionManager(getInstance()); } static int openFrameCount = 0; @@ -222,7 +223,9 @@ public class Desktop extends GDesktop private static int fileLoadingCount = 0; - public JInternalFrame conservationSlider, PIDSlider; + public JInternalFrame conservationSlider; + + public JInternalFrame PIDSlider; /** * just an instance (for testng, probably); no actual frames @@ -363,8 +366,9 @@ public class Desktop extends GDesktop */ public static Desktop getInstance() { - return (Desktop) ApplicationSingletonProvider - .getInstance(Desktop.class); + return Jalview.isHeadlessMode() ? null + : (Desktop) ApplicationSingletonProvider + .getInstance(Desktop.class); } /** @@ -384,6 +388,8 @@ public class Desktop extends GDesktop @SuppressWarnings("unused") private Desktop() { + try + { /** * A note to implementors. It is ESSENTIAL that any activities that might * block are spawned off as threads rather than waited for during this @@ -549,6 +555,10 @@ public class Desktop extends GDesktop } }); desktopPane.addMouseListener(ma); + } catch (Throwable t) + { + t.printStackTrace(); + } } /** @@ -567,7 +577,8 @@ public class Desktop extends GDesktop public void doConfigureStructurePrefs() { // configure services - StructureSelectionManager ssm = getStructureSelectionManager(); + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(this); if (jalview.bin.Cache.getDefault(Preferences.ADD_SS_ANN, true)) { ssm.setAddTempFacAnnot(jalview.bin.Cache @@ -3485,7 +3496,8 @@ public class Desktop extends GDesktop public static groovy.ui.Console getGroovyConsole() { - return Desktop.getInstance().groovyConsole; + Desktop desktop = Desktop.getInstance(); + return desktop == null ? null : desktop.groovyConsole; } /** diff --git a/src/jalview/gui/JalviewDialog.java b/src/jalview/gui/JalviewDialog.java index 0ff5606..eb69230 100644 --- a/src/jalview/gui/JalviewDialog.java +++ b/src/jalview/gui/JalviewDialog.java @@ -77,12 +77,12 @@ public abstract class JalviewDialog extends JPanel protected void initDialogFrame(Container content, boolean modal, boolean block, String title, int width, int height) { - - frame = new JDialog(Desktop.getInstance(), modal); + Desktop desktop = Desktop.getInstance(); + frame = new JDialog(desktop, modal); frame.setTitle(title); - if (Desktop.getInstance() != null) + if (desktop != null) { - Rectangle deskr = Desktop.getInstance().getBounds(); + Rectangle deskr = desktop.getBounds(); frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2), (int) (deskr.getCenterY() - height / 2), width, height)); } diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index 98b24d1..f5648d2 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -101,7 +101,7 @@ public class SplashScreen extends JPanel */ { authlist = new JTextPane(); - Thread t = new Thread(this); + Thread t = new Thread(this, "SplashScreen"); t.start(); } } @@ -203,7 +203,8 @@ public class SplashScreen extends JPanel @SuppressWarnings("unused") protected boolean refreshText() { - String newtext = Desktop.getInstance().getAboutMessage(true).toString(); + Desktop desktop = Desktop.getInstance(); + String newtext = desktop.getAboutMessage(true).toString(); // System.err.println("Text found: \n"+newtext+"\nEnd of newtext."); if (oldtext != newtext.length()) { @@ -236,8 +237,8 @@ public class SplashScreen extends JPanel authlist.setSize(new Dimension(750, 375)); add(authlist, BorderLayout.CENTER); revalidate(); - iframe.setBounds((Desktop.getInstance().getWidth() - 750) / 2, - (Desktop.getInstance().getHeight() - 375) / 2, 750, + iframe.setBounds((desktop.getWidth() - 750) / 2, + (desktop.getHeight() - 375) / 2, 750, authlist.getHeight() + iconimg.getHeight()); iframe.validate(); iframe.setVisible(true); diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index cb09b7c..9c4f6c8 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -143,20 +143,22 @@ public class StructureChooser extends GStructureChooser */ protected void discoverStructureViews() { - if (Desktop.getInstance() != null) + Desktop desktop = Desktop.getInstance(); + if (desktop != null) { targetView.removeAllItems(); - Desktop d = Desktop.getInstance(); - if (d.lastTargetedView != null && !d.lastTargetedView.isVisible()) + if (desktop.lastTargetedView != null + && !desktop.lastTargetedView.isVisible()) { - d.lastTargetedView = null; + desktop.lastTargetedView = null; } int linkedViewsAt = 0; - for (StructureViewerBase view : Desktop.getInstance() + for (StructureViewerBase view : desktop .getStructureViewers(null, null)) { - StructureViewer viewHandler = (d.lastTargetedView != null - && d.lastTargetedView.sview == view) ? d.lastTargetedView + StructureViewer viewHandler = (desktop.lastTargetedView != null + && desktop.lastTargetedView.sview == view) + ? desktop.lastTargetedView : StructureViewer.reconfigure(view); if (view.isLinkedWith(ap)) @@ -177,9 +179,9 @@ public class StructureChooser extends GStructureChooser if (targetView.getItemCount() > 0) { targetView.setVisible(true); - if (d.lastTargetedView != null) + if (desktop.lastTargetedView != null) { - targetView.setSelectedItem(d.lastTargetedView); + targetView.setSelectedItem(desktop.lastTargetedView); } else { diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java index 8cb1846..f2daf2b 100644 --- a/src/jalview/httpserver/HttpServer.java +++ b/src/jalview/httpserver/HttpServer.java @@ -53,6 +53,31 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; */ public class HttpServer implements ApplicationSingletonI { + /* + * 'context root' - actually just prefixed to the path for each handler for + * now - see registerHandler + */ + private static final String JALVIEW_PATH = "jalview"; + + /* + * The Http server + */ + private Server server; + + /* + * Registered handlers for context paths + */ + private HandlerCollection contextHandlers; + + /* + * Lookup of ContextHandler by its wrapped handler + */ + Map myHandlers = new HashMap<>(); + + /* + * The context root for the server + */ + private URI contextRoot; /** * Returns the singleton instance of this class. @@ -86,32 +111,6 @@ public class HttpServer implements ApplicationSingletonI registerHandler(RestHandler.getInstance()); } - /* - * 'context root' - actually just prefixed to the path for each handler for - * now - see registerHandler - */ - private static final String JALVIEW_PATH = "jalview"; - - /* - * The Http server - */ - private Server server; - - /* - * Registered handlers for context paths - */ - private HandlerCollection contextHandlers; - - /* - * Lookup of ContextHandler by its wrapped handler - */ - Map myHandlers = new HashMap<>(); - - /* - * The context root for the server - */ - private URI contextRoot; - /** * Start the http server * diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index 9729ec8..e7054c7 100644 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -243,17 +243,6 @@ public abstract class HTMLOutput implements Runnable } } - // /** - // * Answers true if HTML export is invoke in headless mode or false otherwise - // * - // * @return - // */ - // protected boolean isHeadless() - // { - // return System.getProperty("java.awt.headless") != null - // && System.getProperty("java.awt.headless").equals("true"); - // } - /** * This method provides implementation of consistent behaviour which should * occur after a HTML file export. It MUST be called at the end of the diff --git a/src/jalview/io/JalviewFileFilter.java b/src/jalview/io/JalviewFileFilter.java index a702aae..cc63a22 100755 --- a/src/jalview/io/JalviewFileFilter.java +++ b/src/jalview/io/JalviewFileFilter.java @@ -30,8 +30,6 @@ import javax.swing.filechooser.FileFilter; public class JalviewFileFilter extends FileFilter { - // public static Hashtable suffixHash = new Hashtable(); - private Map filters = null; private String description = "no description"; @@ -135,8 +133,6 @@ public class JalviewFileFilter extends FileFilter { return filename.substring(i + 1).toLowerCase(); } - - ; } return ""; diff --git a/src/jalview/rest/RestHandler.java b/src/jalview/rest/RestHandler.java index fefdc57..7c8c9a6 100644 --- a/src/jalview/rest/RestHandler.java +++ b/src/jalview/rest/RestHandler.java @@ -33,7 +33,6 @@ import javax.servlet.http.HttpServletResponse; /** * A simple handler to process (or delegate) HTTP requests on /jalview/rest. - * Accessed only by HttpServer. */ public class RestHandler extends AbstractRequestHandler implements ApplicationSingletonI diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index e7835f3..012dff3 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -116,7 +116,8 @@ public class StructureSelectionManager implements ApplicationSingletonI /** * Answers an instance of this class scoped to the given context. The instance * is created on the first request for the context, thereafter the same - * instance is returned. + * instance is returned. Note that the context may be null (this is the case + * when running headless without a Desktop). * * @param context * @return diff --git a/src/jalview/urls/IdOrgSettings.java b/src/jalview/urls/IdOrgSettings.java index 10c3478..cd7e98e 100644 --- a/src/jalview/urls/IdOrgSettings.java +++ b/src/jalview/urls/IdOrgSettings.java @@ -29,11 +29,9 @@ import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; */ public class IdOrgSettings implements ApplicationSingletonI { + private String url; - private IdOrgSettings() - { - // private singleton - } + private String location; private static IdOrgSettings getInstance() { @@ -41,10 +39,6 @@ public class IdOrgSettings implements ApplicationSingletonI .getInstance(IdOrgSettings.class); } - private String url; - - private String location; - public static void setUrl(String seturl) { getInstance().url = seturl; @@ -64,4 +58,9 @@ public class IdOrgSettings implements ApplicationSingletonI { return getInstance().location; } + + private IdOrgSettings() + { + // private singleton + } } diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java index 94d66f4..ca2e55e 100755 --- a/src/jalview/util/BrowserLauncher.java +++ b/src/jalview/util/BrowserLauncher.java @@ -28,13 +28,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** - * - * SwingJS note: Do not use methods in this class directly. Use - * - * Platform.openURL(String url) only. - * - * JavaScript does not see this class. - * * BrowserLauncher is a class that provides two static methods: * * openURL(String url), which opens the default web browser for the current user @@ -42,7 +35,6 @@ import java.lang.reflect.Method; * * resetBrowser(), which allows switching browsers in Java. * - * * openURL may support other protocols depending on the system -- mailto, ftp, * etc. -- but that has not been rigorously tested and is not guaranteed to * work. @@ -92,6 +84,14 @@ import java.lang.reflect.Method; * "mailto:ejalbert@cs.stanford.edu">ejalbert@cs.stanford.edu) * @version 1.4b1 (Released June 20, 2001) */ +/* + * + * SwingJS note: Do not use methods in this class directly. Use + * + * Platform.openURL(String url) only. + * + * JavaScript does not see this class. + */ public class BrowserLauncher { /** diff --git a/test/jalview/analysis/AlignmentSorterTest.java b/test/jalview/analysis/AlignmentSorterTest.java index 3b9be23..090ae1a 100644 --- a/test/jalview/analysis/AlignmentSorterTest.java +++ b/test/jalview/analysis/AlignmentSorterTest.java @@ -11,10 +11,10 @@ import jalview.datamodel.SequenceI; import java.util.Arrays; import java.util.List; -import junit.extensions.PA; - import org.testng.annotations.Test; +import junit.extensions.PA; + public class AlignmentSorterTest { @Test(groups = "Functional") @@ -31,7 +31,10 @@ public class AlignmentSorterTest /* * sort with no score features does nothing */ - PA.setValue(AlignmentSorter.class, "sortByFeatureCriteria", null); + AlignmentSorter sorter = (AlignmentSorter) PA + .invokeMethod(AlignmentSorter.class, "getInstance()", + new Object[] {}); + PA.setValue(sorter, "sortByFeatureCriteria", null); AlignmentSorter.sortByFeature(null, null, 0, al.getWidth(), al, AlignmentSorter.FEATURE_SCORE); @@ -64,7 +67,7 @@ public class AlignmentSorterTest * sort by ascending score, no filter on feature type or group * NB sort order for the same feature set (none) gets toggled, so descending */ - PA.setValue(AlignmentSorter.class, "sortByFeatureAscending", true); + PA.setValue(sorter, "sortByFeatureAscending", true); AlignmentSorter.sortByFeature(null, null, 0, al.getWidth(), al, AlignmentSorter.FEATURE_SCORE); assertSame(al.getSequenceAt(3), seq3); // -0.5 diff --git a/test/jalview/gui/SeqCanvasTest.java b/test/jalview/gui/SeqCanvasTest.java index 73aeb79..7d0e256 100644 --- a/test/jalview/gui/SeqCanvasTest.java +++ b/test/jalview/gui/SeqCanvasTest.java @@ -22,6 +22,7 @@ package jalview.gui; import static org.testng.Assert.assertEquals; +import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.io.DataSourceType; import jalview.io.FileLoader; @@ -29,12 +30,19 @@ import jalview.io.FileLoader; import java.awt.Font; import java.awt.FontMetrics; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import junit.extensions.PA; public class SeqCanvasTest { + @BeforeClass(alwaysRun = true) + public void setUp() + { + Cache.initLogger(); + } + /** * Test the method that computes wrapped width in residues, height of wrapped * widths in pixels, and the number of widths visible diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index 59d024c..04ddeb0 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -61,6 +61,7 @@ import org.testng.annotations.Test; public class FeaturesFileTest { + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); private static String simpleGffFile = "examples/testdata/simpleGff3.gff"; @AfterClass(alwaysRun = true) @@ -69,7 +70,7 @@ public class FeaturesFileTest /* * remove any sequence mappings created so they don't pollute other tests */ - Desktop.getInstance().getStructureSelectionManager().resetAll(); + Desktop.getStructureSelectionManager().resetAll(); } @BeforeClass(alwaysRun = true) @@ -489,7 +490,7 @@ public class FeaturesFileTest + "desc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n\n" + "desc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n"; // NaN is not output assertEquals( - expected.replace("\n", System.getProperty("line.separator")), + expected.replace("\n", LINE_SEPARATOR), exported); /* @@ -646,7 +647,7 @@ public class FeaturesFileTest // METAL feature has null group: description used for column 2 expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"; assertEquals( - expected.replace("\n", System.getProperty("line.separator")), + expected.replace("\n", LINE_SEPARATOR), exported); /* @@ -659,7 +660,7 @@ public class FeaturesFileTest expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n" + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n"; assertEquals( - expected.replace("\n", System.getProperty("line.separator")), + expected.replace("\n", LINE_SEPARATOR), exported); /* @@ -673,14 +674,12 @@ public class FeaturesFileTest + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n" + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n" + "FER_CAPAN\tUniprot\tPfam\t20\t20\t0.0\t+\t2\tx=y;black=white\n"; - assertEquals( - expected.replace("\n", System.getProperty("line.separator")), - exported); + assertEquals(fixLineEnd(expected), exported); } private String fixLineEnd(String s) { - return s.replace("\n", System.getProperty("line.separator")); + return s.replace("\n", LINE_SEPARATOR); } /** @@ -888,7 +887,7 @@ public class FeaturesFileTest + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n" + "ENDGROUP\tgrp1\n"; assertEquals( - expected.replace("\n", System.getProperty("line.separator")), + expected.replace("\n", LINE_SEPARATOR), exported); /* -- 1.7.10.2