From fa8140d4e0510b5c91284ad38f296cbf14ba29a5 Mon Sep 17 00:00:00 2001 From: BobHanson Date: Tue, 2 Jun 2020 16:54:57 -0500 Subject: [PATCH] JAL-3446 from JAL-3253-applet Desktop and Jws2Discoverer getInstance() --- src/jalview/bin/Jalview.java | 2 +- src/jalview/gui/AlignFrame.java | 2 +- src/jalview/gui/AnnotationColourChooser.java | 2 +- src/jalview/gui/Desktop.java | 12 ++++++--- src/jalview/gui/FeatureEditor.java | 2 +- src/jalview/gui/PopupMenu.java | 2 +- src/jalview/gui/WsJobParameters.java | 4 +-- src/jalview/gui/WsPreferences.java | 10 ++++---- src/jalview/ws/jws2/Jws2Client.java | 4 +-- src/jalview/ws/jws2/Jws2Discoverer.java | 35 +++++++++++++------------- 10 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index e98ea63..f23ebfa 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -361,7 +361,7 @@ public class Jalview implements JalviewJSApi { try { - Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl); + Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl); System.out.println( "CMD [-jabaws " + jabawsUrl + "] executed successfully!"); } catch (MalformedURLException e) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 29f6a2e..a7018c3 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4260,7 +4260,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, boolean new_sspred = false; if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { - Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer(); + Jws2Discoverer jws2servs = Jws2Discoverer.getInstance(); if (jws2servs != null) { if (jws2servs.hasServices()) diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index e89c1c2..bd05be1 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -301,7 +301,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter updateView(); } }; - JalviewColourChooser.showColourChooser(Desktop.getDesktop(), ttl, + JalviewColourChooser.showColourChooser(Desktop.getDesktopPane(), ttl, colourPanel.getBackground(), listener); } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 1b85dd5..a894910 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -216,13 +216,19 @@ public class Desktop extends jalview.jbgui.GDesktop public static MyDesktopPane desktop; - public static MyDesktopPane getDesktop() + public static MyDesktopPane getDesktopPane() { // BH 2018 could use currentThread() here as a reference to a // Hashtable in JavaScript return desktop; } + public static StructureSelectionManager getStructureSelectionManager() + { + return StructureSelectionManager + .getStructureSelectionManager(getInstance()); + } + static int openFrameCount = 0; static final int xOffset = 30; @@ -2658,7 +2664,7 @@ public class Desktop extends jalview.jbgui.GDesktop if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { - t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() + t2 = jalview.ws.jws2.Jws2Discoverer.getInstance() .startDiscoverer(changeSupport); } Thread t3 = null; @@ -2691,7 +2697,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector) { - final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() + final String ermsg = jalview.ws.jws2.Jws2Discoverer.getInstance() .getErrorMessages(); if (ermsg != null) { diff --git a/src/jalview/gui/FeatureEditor.java b/src/jalview/gui/FeatureEditor.java index d547c58..57e2915 100644 --- a/src/jalview/gui/FeatureEditor.java +++ b/src/jalview/gui/FeatureEditor.java @@ -222,7 +222,7 @@ public class FeatureEditor updateColourButton(mainPanel, colour, featureColour); }; }; - JalviewColourChooser.showColourChooser(Desktop.getDesktop(), + JalviewColourChooser.showColourChooser(Desktop.getDesktopPane(), title, featureColour.getColour(), listener); } else diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 2a7fb9f..87912ab 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -2083,7 +2083,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener refresh(); } }; - JalviewColourChooser.showColourChooser(Desktop.getDesktop(), + JalviewColourChooser.showColourChooser(Desktop.getDesktopPane(), title, Color.BLUE, listener); } diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 976e551..2ee3629 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -963,13 +963,13 @@ public class WsJobParameters extends JPanel implements ItemListener, public static void main(String[] args) { jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer - .getDiscoverer(); + .getInstance(); int p = 0; if (args.length > 0) { Vector services = new Vector<>(); services.addElement(args[p++]); - Jws2Discoverer.getDiscoverer().setServiceUrls(services); + Jws2Discoverer.getInstance().setServiceUrls(services); } try { diff --git a/src/jalview/gui/WsPreferences.java b/src/jalview/gui/WsPreferences.java index 5186a26..fd6114b 100644 --- a/src/jalview/gui/WsPreferences.java +++ b/src/jalview/gui/WsPreferences.java @@ -65,7 +65,7 @@ public class WsPreferences extends GWsPreferences private void initFromPreferences() { - wsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls(); + wsUrls = Jws2Discoverer.getInstance().getServiceUrls(); if (!wsUrls.isEmpty()) { oldUrls = new Vector(wsUrls); @@ -122,7 +122,7 @@ public class WsPreferences extends GWsPreferences int r = 0; for (String url : wsUrls) { - int status = Jws2Discoverer.getDiscoverer().getServerStatusFor(url); + int status = Jws2Discoverer.getInstance().getServerStatusFor(url); tdat[r][1] = Integer.valueOf(status); tdat[r++][0] = url; } @@ -241,7 +241,7 @@ public class WsPreferences extends GWsPreferences private void updateServiceList() { - Jws2Discoverer.getDiscoverer().setServiceUrls(wsUrls); + Jws2Discoverer.getInstance().setServiceUrls(wsUrls); } private void updateRsbsServiceList() @@ -646,8 +646,8 @@ public class WsPreferences extends GWsPreferences @Override protected void resetWs_actionPerformed(ActionEvent e) { - Jws2Discoverer.getDiscoverer().setServiceUrls(null); - List nwsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls(); + Jws2Discoverer.getInstance().setServiceUrls(null); + List nwsUrls = Jws2Discoverer.getInstance().getServiceUrls(); if (!wsUrls.equals(nwsUrls)) { update++; diff --git a/src/jalview/ws/jws2/Jws2Client.java b/src/jalview/ws/jws2/Jws2Client.java index 0f1a25e..62f2a03 100644 --- a/src/jalview/ws/jws2/Jws2Client.java +++ b/src/jalview/ws/jws2/Jws2Client.java @@ -398,7 +398,7 @@ public abstract class Jws2Client extends jalview.ws.WSClient { // check service is actually in the list of currently avaialable // services - if (!Jws2Discoverer.getDiscoverer().getServices().contains(service)) + if (!Jws2Discoverer.getInstance().getServices().contains(service)) { // it isn't .. service = null; @@ -408,7 +408,7 @@ public abstract class Jws2Client extends jalview.ws.WSClient if (service == null) { // get the default service for AACon - service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null, + service = Jws2Discoverer.getInstance().getPreferredServiceFor(null, aaui.getServiceType()); } if (service == null) diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index 516a719..c3b0b30 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -74,6 +74,20 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI */ private static Jws2Discoverer discoverer; + /** + * Returns the singleton instance of this class. + * + * @return + */ + public static Jws2Discoverer getInstance() + { + if (discoverer == null) + { + discoverer = new Jws2Discoverer(); + } + return discoverer; + } + /* * Override for testing only */ @@ -591,19 +605,19 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI testUrls.add(url); } } - Thread runner = getDiscoverer() + Thread runner = getInstance() .startDiscoverer(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (getDiscoverer().services != null) + if (getInstance().services != null) { System.out.println("Changesupport: There are now " - + getDiscoverer().services.size() + " services"); + + getInstance().services.size() + " services"); int i = 1; - for (Jws2Instance instance : getDiscoverer().services) + for (Jws2Instance instance : getInstance().services) { System.out.println("Service " + i++ + " " + instance.getClass() + "@" + instance.getHost() @@ -630,19 +644,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } - /** - * Returns the singleton instance of this class. - * - * @return - */ - public static Jws2Discoverer getDiscoverer() - { - if (discoverer == null) - { - discoverer = new Jws2Discoverer(); - } - return discoverer; - } public boolean hasServices() { -- 1.7.10.2