X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;fp=src%2Fjalview%2Fgui%2FDesktop.java;h=b125cc277b8af1d7bcc5c14036c2af4575d518b3;hb=d043ce47fc710d3eb2629ba926a8a7417bd67d8c;hp=16603df6309dbb4d184836d4710afcd47865729e;hpb=04c8f7bff663aa469127e9eed4164e02933782f1;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 16603df..b125cc2 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import java.util.Locale; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -62,10 +63,12 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.ListIterator; -import java.util.Locale; import java.util.Vector; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; import java.util.concurrent.Semaphore; import javax.swing.AbstractAction; @@ -99,6 +102,9 @@ import org.stackoverflowusers.file.WindowsShortcut; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; +import jalview.api.StructureSelectionManagerProvider; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.gui.ImageExporter.ImageWriterI; @@ -113,6 +119,8 @@ import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; +import jalview.jbgui.APQHandlers; +import jalview.jbgui.GDesktop; import jalview.jbgui.GSplitFrame; import jalview.jbgui.GStructureViewer; import jalview.project.Jalview2XML; @@ -124,9 +132,9 @@ import jalview.util.ImageMaker.TYPE; import jalview.util.LaunchUtils; import jalview.util.MessageManager; import jalview.util.Platform; -import jalview.util.ShortcutKeyMaskExWrapper; import jalview.util.UrlConstants; import jalview.viewmodel.AlignmentViewport; +import jalview.ws.WSDiscovererI; import jalview.ws.params.ParamManager; import jalview.ws.utils.UrlDownloadClient; @@ -137,17 +145,16 @@ import jalview.ws.utils.UrlDownloadClient; * @author $author$ * @version $Revision: 1.155 $ */ -public class Desktop extends jalview.jbgui.GDesktop +@SuppressWarnings("serial") +public class Desktop extends GDesktop implements DropTargetListener, ClipboardOwner, IProgressIndicator, - jalview.api.StructureSelectionManagerProvider + StructureSelectionManagerProvider, ApplicationSingletonI + { private static final String CITATION; - static - { - URL bg_logo_url = ChannelProperties.getImageURL( - "bg_logo." + String.valueOf(SplashScreen.logoSize)); - URL uod_logo_url = ChannelProperties.getImageURL( - "uod_banner." + String.valueOf(SplashScreen.logoSize)); + static { + URL bg_logo_url = ChannelProperties.getImageURL("bg_logo." + String.valueOf(SplashScreen.logoSize)); + URL uod_logo_url = ChannelProperties.getImageURL("uod_banner." + String.valueOf(SplashScreen.logoSize)); boolean logo = (bg_logo_url != null || uod_logo_url != null); StringBuilder sb = new StringBuilder(); sb.append( @@ -156,12 +163,9 @@ public class Desktop extends jalview.jbgui.GDesktop { sb.append("
"); } - sb.append(bg_logo_url == null ? "" - : "\"Barton"); + sb.append(bg_logo_url == null ? "" : "\"Barton"); sb.append(uod_logo_url == null ? "" - : " \"University"); + : " \"University"); sb.append( "

For help, see www.jalview.org/faq and join discourse.jalview.org"); sb.append("

If you use Jalview, please cite:" @@ -187,6 +191,7 @@ public class Desktop extends jalview.jbgui.GDesktop public static HashMap savingFiles = new HashMap(); + @SuppressWarnings("deprecation") private JalviewChangeSupport changeSupport = new JalviewChangeSupport(); public static boolean nosplash = false; @@ -202,6 +207,7 @@ public class Desktop extends jalview.jbgui.GDesktop * @param listener * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener) */ + @Deprecated public void addJalviewPropertyChangeListener( PropertyChangeListener listener) { @@ -214,6 +220,7 @@ public class Desktop extends jalview.jbgui.GDesktop * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String, * java.beans.PropertyChangeListener) */ + @Deprecated public void addJalviewPropertyChangeListener(String propertyName, PropertyChangeListener listener) { @@ -226,6 +233,7 @@ public class Desktop extends jalview.jbgui.GDesktop * @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String, * java.beans.PropertyChangeListener) */ + @Deprecated public void removeJalviewPropertyChangeListener(String propertyName, PropertyChangeListener listener) { @@ -233,31 +241,47 @@ public class Desktop extends jalview.jbgui.GDesktop listener); } - /** Singleton Desktop instance */ - public static Desktop instance; + private MyDesktopPane desktopPane; + + public static MyDesktopPane getDesktopPane() + { + Desktop desktop = getInstance(); + return desktop == null ? null : desktop.desktopPane; + } - public static MyDesktopPane desktop; + /** + * Answers an 'application scope' singleton instance of this class. Separate + * SwingJS 'applets' running in the same browser page will each have a + * distinct instance of Desktop. + * + * @return + */ + public static Desktop getInstance() + { + return Jalview.isHeadlessMode() ? null + : (Desktop) ApplicationSingletonProvider + .getInstance(Desktop.class); + } - public static MyDesktopPane getDesktop() + public static StructureSelectionManager getStructureSelectionManager() { - // BH 2018 could use currentThread() here as a reference to a - // Hashtable in JavaScript - return desktop; + return StructureSelectionManager + .getStructureSelectionManager(getInstance()); } - static int openFrameCount = 0; + int openFrameCount = 0; - static final int xOffset = 30; + final int xOffset = 30; - static final int yOffset = 30; + final int yOffset = 30; - public static jalview.ws.jws1.Discoverer discoverer; + public jalview.ws.jws1.Discoverer discoverer; - public static Object[] jalviewClipboard; + public Object[] jalviewClipboard; - public static boolean internalCopy = false; + public boolean internalCopy = false; - static int fileLoadingCount = 0; + int fileLoadingCount = 0; class MyDesktopManager implements DesktopManager { @@ -278,7 +302,7 @@ public class Desktop extends jalview.jbgui.GDesktop } catch (NullPointerException npe) { Point p = getMousePosition(); - instance.showPasteMenu(p.x, p.y); + showPasteMenu(p.x, p.y); } } @@ -326,14 +350,14 @@ public class Desktop extends jalview.jbgui.GDesktop public void endDraggingFrame(JComponent f) { delegate.endDraggingFrame(f); - desktop.repaint(); + desktopPane.repaint(); } @Override public void endResizingFrame(JComponent f) { delegate.endResizingFrame(f); - desktop.repaint(); + desktopPane.repaint(); } @Override @@ -383,33 +407,33 @@ public class Desktop extends jalview.jbgui.GDesktop } /** - * Creates a new Desktop object. + * Private constructor enforces singleton pattern. It is called by reflection + * from ApplicationSingletonProvider.getInstance(). */ - public Desktop() + private Desktop() { super(); - /** - * A note to implementors. It is ESSENTIAL that any activities that might - * block are spawned off as threads rather than waited for during this - * constructor. - */ - instance = this; + 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 + * constructor. + */ - doConfigureStructurePrefs(); - setTitle(ChannelProperties.getProperty("app_name") + " " - + Cache.getProperty("VERSION")); + doConfigureStructurePrefs(); + setTitle(ChannelProperties.getProperty("app_name") + " " + Cache.getProperty("VERSION")); /** * Set taskbar "grouped windows" name for linux desktops (works in GNOME and - * KDE). This uses sun.awt.X11.XToolkit.awtAppClassName which is not - * officially documented or guaranteed to exist, so we access it via - * reflection. There appear to be unfathomable criteria about what this - * string can contain, and it if doesn't meet those criteria then "java" - * (KDE) or "jalview-bin-Jalview" (GNOME) is used. "Jalview", "Jalview - * Develop" and "Jalview Test" seem okay, but "Jalview non-release" does - * not. The reflection access may generate a warning: WARNING: An illegal - * reflective access operation has occurred WARNING: Illegal reflective - * access by jalview.gui.Desktop () to field + * KDE). This uses sun.awt.X11.XToolkit.awtAppClassName which is not officially + * documented or guaranteed to exist, so we access it via reflection. There + * appear to be unfathomable criteria about what this string can contain, and it + * if doesn't meet those criteria then "java" (KDE) or "jalview-bin-Jalview" + * (GNOME) is used. "Jalview", "Jalview Develop" and "Jalview Test" seem okay, + * but "Jalview non-release" does not. The reflection access may generate a + * warning: WARNING: An illegal reflective access operation has occurred + * WARNING: Illegal reflective access by jalview.gui.Desktop () to field * sun.awt.X11.XToolkit.awtAppClassName which I don't think can be avoided. */ if (Platform.isLinux()) @@ -425,16 +449,12 @@ public class Desktop extends jalview.jbgui.GDesktop Field[] declaredFields = xToolkit.getClass().getDeclaredFields(); Field awtAppClassNameField = null; - if (Arrays.stream(declaredFields) - .anyMatch(f -> f.getName().equals("awtAppClassName"))) - { - awtAppClassNameField = xToolkit.getClass() - .getDeclaredField("awtAppClassName"); + if (Arrays.stream(declaredFields).anyMatch(f -> f.getName().equals("awtAppClassName"))) { + awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName"); } String title = ChannelProperties.getProperty("app_name"); - if (awtAppClassNameField != null) - { + if (awtAppClassNameField != null) { awtAppClassNameField.setAccessible(true); awtAppClassNameField.set(xToolkit, title); } @@ -449,159 +469,180 @@ public class Desktop extends jalview.jbgui.GDesktop } } + /** + * APQHandlers sets handlers for About, Preferences and Quit actions peculiar to + * macOS's application menu. APQHandlers will check to see if a handler is + * supported before setting it. + */ + try { + APQHandlers.setAPQHandlers(this); + } catch (Exception e) { + System.out.println("Cannot set APQHandlers"); + // e.printStackTrace(); + } catch (Throwable t) { + jalview.bin.Console.warn("Error setting APQHandlers: " + t.toString()); + jalview.bin.Console.trace(Cache.getStackTraceString(t)); + } + setIconImages(ChannelProperties.getIconList()); - addWindowListener(new WindowAdapter() - { + addWindowListener(new WindowAdapter() { @Override - public void windowClosing(WindowEvent ev) - { + public void windowClosing(WindowEvent ev) { quit(); } }); - boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false); + boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false); - boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false); - desktop = new MyDesktopPane(selmemusage); + boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false); + desktopPane = new MyDesktopPane(selmemusage); - showMemusage.setSelected(selmemusage); - desktop.setBackground(Color.white); + showMemusage.setSelected(selmemusage); + desktopPane.setBackground(Color.white); - getContentPane().setLayout(new BorderLayout()); - // alternate config - have scrollbars - see notes in JAL-153 - // JScrollPane sp = new JScrollPane(); - // sp.getViewport().setView(desktop); - // getContentPane().add(sp, BorderLayout.CENTER); + getContentPane().setLayout(new BorderLayout()); + // alternate config - have scrollbars - see notes in JAL-153 + // JScrollPane sp = new JScrollPane(); + // sp.getViewport().setView(desktop); + // getContentPane().add(sp, BorderLayout.CENTER); - // BH 2018 - just an experiment to try unclipped JInternalFrames. - if (Platform.isJS()) - { - getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); - } + // BH 2018 - just an experiment to try unclipped JInternalFrames. + if (Platform.isJS()) + { + getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); + } - getContentPane().add(desktop, BorderLayout.CENTER); - desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); + getContentPane().add(desktopPane, BorderLayout.CENTER); + desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); - // This line prevents Windows Look&Feel resizing all new windows to maximum - // if previous window was maximised - desktop.setDesktopManager(new MyDesktopManager( - (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager() - : Platform.isAMacAndNotJS() - ? new AquaInternalFrameManager( - desktop.getDesktopManager()) - : desktop.getDesktopManager()))); - Rectangle dims = getLastKnownDimensions(""); - if (dims != null) - { - setBounds(dims); - } - else - { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - int xPos = Math.max(5, (screenSize.width - 900) / 2); - int yPos = Math.max(5, (screenSize.height - 650) / 2); - setBounds(xPos, yPos, 900, 650); - } + // This line prevents Windows Look&Feel resizing all new windows to + // maximum + // if previous window was maximised + desktopPane.setDesktopManager(new MyDesktopManager( + (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager() + : Platform.isAMacAndNotJS() + ? new AquaInternalFrameManager( + desktopPane.getDesktopManager()) + : desktopPane.getDesktopManager()))); - if (!Platform.isJS()) - /** - * Java only - * - * @j2sIgnore - */ - { - jconsole = new Console(this, showjconsole); - jconsole.setHeader(Cache.getVersionDetailsForConsole()); - showConsole(showjconsole); + Rectangle dims = getLastKnownDimensions(""); + if (dims != null) + { + setBounds(dims); + } + else + { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + int xPos = Math.max(5, (screenSize.width - 900) / 2); + int yPos = Math.max(5, (screenSize.height - 650) / 2); + setBounds(xPos, yPos, 900, 650); + } - showNews.setVisible(false); + if (!Platform.isJS()) + /** + * Java only + * + * @j2sIgnore + */ + { + jconsole = new Console(this, showjconsole); + jconsole.setHeader(Cache.getVersionDetailsForConsole()); + showConsole(showjconsole); - experimentalFeatures.setSelected(showExperimental()); + showNews.setVisible(false); // not sure if we should only do this for interactive session? - getIdentifiersOrgData(); + experimentalFeatures.setSelected(showExperimental()); - checkURLLinks(); + getIdentifiersOrgData(); - // Spawn a thread that shows the splashscreen - if (!nosplash) - { - SwingUtilities.invokeLater(new Runnable() + if (Jalview.isInteractive()) { - @Override - public void run() - { - new SplashScreen(true); + // disabled for SeqCanvasTest + checkURLLinks(); + + // Spawn a thread that shows the splashscreen + if (!nosplash) { + SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + new SplashScreen(true); + } + }); } - }); + + // 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() + { + jalview.bin.Console.debug("Filechooser init thread started."); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser.forRead( + Cache.getProperty("LAST_DIRECTORY"), fileFormat); + jalview.bin.Console.debug("Filechooser init thread finished."); + } + }).start(); + // Add the service change listener + changeSupport.addJalviewPropertyChangeListener("services", + new PropertyChangeListener() + { + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + jalview.bin.Console.debug("Firing service changed event for " + + evt.getNewValue()); + JalviewServicesChanged(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() + this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); + + this.addWindowListener(new WindowAdapter() { @Override - public void run() + public void windowClosing(WindowEvent evt) { - jalview.bin.Console.debug("Filechooser init thread started."); - String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); - JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), - fileFormat); - jalview.bin.Console.debug("Filechooser init thread finished."); + quit(); } - }).start(); - // Add the service change listener - changeSupport.addJalviewPropertyChangeListener("services", - new PropertyChangeListener() - { - - @Override - public void propertyChange(PropertyChangeEvent evt) - { - jalview.bin.Console - .debug("Firing service changed event for " - + evt.getNewValue()); - JalviewServicesChanged(evt); - } - }); - } - - this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); - - this.addWindowListener(new WindowAdapter() - { - @Override - public void windowClosing(WindowEvent evt) - { - quit(); - } - }); + }); - MouseAdapter ma; - this.addMouseListener(ma = new MouseAdapter() - { - @Override - public void mousePressed(MouseEvent evt) + MouseAdapter ma; + this.addMouseListener(ma = new MouseAdapter() { - if (evt.isPopupTrigger()) // Mac + @Override + public void mousePressed(MouseEvent evt) { - showPasteMenu(evt.getX(), evt.getY()); + if (evt.isPopupTrigger()) // Mac + { + showPasteMenu(evt.getX(), evt.getY()); + } } - } - - @Override - public void mouseReleased(MouseEvent evt) - { - if (evt.isPopupTrigger()) // Windows + @Override + public void mouseReleased(MouseEvent evt) { - showPasteMenu(evt.getX(), evt.getY()); + if (evt.isPopupTrigger()) // Windows + { + showPasteMenu(evt.getX(), evt.getY()); + } } - } - }); - desktop.addMouseListener(ma); + }); + desktopPane.addMouseListener(ma); + } catch (Throwable t) + { + t.printStackTrace(); + } } /** @@ -620,32 +661,23 @@ public class Desktop extends jalview.jbgui.GDesktop public void doConfigureStructurePrefs() { // configure services - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(this); - if (Cache.getDefault(Preferences.ADD_SS_ANN, true)) - { - ssm.setAddTempFacAnnot( - Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true)); - ssm.setProcessSecondaryStructure( - Cache.getDefault(Preferences.STRUCT_FROM_PDB, true)); + StructureSelectionManager ssm = StructureSelectionManager.getStructureSelectionManager(this); + if (Cache.getDefault(Preferences.ADD_SS_ANN, true)) { + ssm.setAddTempFacAnnot(Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true)); + ssm.setProcessSecondaryStructure(Cache.getDefault(Preferences.STRUCT_FROM_PDB, true)); // JAL-3915 - RNAView is no longer an option so this has no effect - ssm.setSecStructServices( - Cache.getDefault(Preferences.USE_RNAVIEW, false)); - } - else - { + ssm.setSecStructServices(Cache.getDefault(Preferences.USE_RNAVIEW, false)); + } else { ssm.setAddTempFacAnnot(false); ssm.setProcessSecondaryStructure(false); ssm.setSecStructServices(false); } } - public void checkForNews() - { + public void checkForNews() { final Desktop me = this; // Thread off the news reader, in case there are connection problems. - new Thread(new Runnable() - { + new Thread(new Runnable() { @Override public void run() { @@ -657,36 +689,30 @@ public class Desktop extends jalview.jbgui.GDesktop }).start(); } - public void getIdentifiersOrgData() - { - if (Cache.getProperty("NOIDENTIFIERSSERVICE") == null) - {// Thread off the identifiers fetcher - new Thread(new Runnable() - { + public void getIdentifiersOrgData() { + if (Cache.getProperty("NOIDENTIFIERSSERVICE") == null) { + // Thread off the identifiers fetcher + new Thread(new Runnable() { @Override public void run() { - jalview.bin.Console - .debug("Downloading data from identifiers.org"); + jalview.bin.Console.debug("Downloading data from identifiers.org"); try { UrlDownloadClient.download(IdOrgSettings.getUrl(), IdOrgSettings.getDownloadLocation()); } catch (IOException e) { - jalview.bin.Console - .debug("Exception downloading identifiers.org data" + jalview.bin.Console.debug("Exception downloading identifiers.org data" + e.getMessage()); } } }).start(); - ; } } @Override - protected void showNews_actionPerformed(ActionEvent e) - { + protected void showNews_actionPerformed(ActionEvent e) { showNews(showNews.isSelected()); } @@ -702,10 +728,10 @@ public class Desktop extends jalview.jbgui.GDesktop public void run() { long now = System.currentTimeMillis(); - Desktop.instance.setProgressBar( - MessageManager.getString("status.refreshing_news"), now); + setProgressBar(MessageManager.getString("status.refreshing_news"), + now); jvnews.refreshNews(); - Desktop.instance.setProgressBar(null, now); + setProgressBar(null, now); jvnews.showNews(); } }).start(); @@ -728,19 +754,15 @@ public class Desktop extends jalview.jbgui.GDesktop String y = Cache.getProperty(windowName + "SCREEN_Y"); String width = Cache.getProperty(windowName + "SCREEN_WIDTH"); String height = Cache.getProperty(windowName + "SCREEN_HEIGHT"); - if ((x != null) && (y != null) && (width != null) && (height != null)) - { - int ix = Integer.parseInt(x), iy = Integer.parseInt(y), - iw = Integer.parseInt(width), ih = Integer.parseInt(height); - if (Cache.getProperty("SCREENGEOMETRY_WIDTH") != null) - { + if ((x != null) && (y != null) && (width != null) && (height != null)) { + int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer.parseInt(width), + ih = Integer.parseInt(height); + if (Cache.getProperty("SCREENGEOMETRY_WIDTH") != null) { // attempt #1 - try to cope with change in screen geometry - this // version doesn't preserve original jv aspect ratio. // take ratio of current screen size vs original screen size. - double sw = ((1f * screenSize.width) / (1f * Integer - .parseInt(Cache.getProperty("SCREENGEOMETRY_WIDTH")))); - double sh = ((1f * screenSize.height) / (1f * Integer - .parseInt(Cache.getProperty("SCREENGEOMETRY_HEIGHT")))); + double sw = ((1f * screenSize.width) / (1f * Integer.parseInt(Cache.getProperty("SCREENGEOMETRY_WIDTH")))); + double sh = ((1f * screenSize.height) / (1f * Integer.parseInt(Cache.getProperty("SCREENGEOMETRY_HEIGHT")))); // rescale the bounds depending upon the current screen geometry. ix = (int) (ix * sw); iw = (int) (iw * sw); @@ -811,48 +833,11 @@ public class Desktop extends jalview.jbgui.GDesktop } } - /** - * Adds and opens the given frame to the desktop - * - * @param frame - * Frame to show - * @param title - * Visible Title - * @param w - * width - * @param h - * height - */ - public static synchronized void addInternalFrame( - final JInternalFrame frame, String title, int w, int h) - { - addInternalFrame(frame, title, true, w, h, true, false); - } - /** - * Add an internal frame to the Jalview desktop - * - * @param frame - * Frame to show - * @param title - * Visible Title - * @param makeVisible - * When true, display frame immediately, otherwise, caller must call - * setVisible themselves. - * @param w - * width - * @param h - * height - */ - public static synchronized void addInternalFrame( - final JInternalFrame frame, String title, boolean makeVisible, - int w, int h) - { - addInternalFrame(frame, title, makeVisible, w, h, true, false); - } /** - * Add an internal frame to the Jalview desktop and make it visible + * Adds and opens the given frame to the desktop that is visible, allowed to + * resize, and has a 300px minimum width. * * @param frame * Frame to show @@ -862,18 +847,19 @@ public class Desktop extends jalview.jbgui.GDesktop * width * @param h * height - * @param resizable - * Allow resize */ public static synchronized void addInternalFrame( - final JInternalFrame frame, String title, int w, int h, - boolean resizable) + final JInternalFrame frame, String title, int w, int h) { - addInternalFrame(frame, title, true, w, h, resizable, false); + // 58 classes + + addInternalFrame(frame, title, Desktop.FRAME_MAKE_VISIBLE, w, h, + FRAME_ALLOW_RESIZE, FRAME_SET_MIN_SIZE_300); } /** - * Add an internal frame to the Jalview desktop + * Add an internal frame to the Jalview desktop that may optionally be + * visible, resizable, and allowed to be any size * * @param frame * Frame to show @@ -895,6 +881,8 @@ public class Desktop extends jalview.jbgui.GDesktop final JInternalFrame frame, String title, boolean makeVisible, int w, int h, boolean resizable, boolean ignoreMinSize) { + // 15 classes call this method directly. + // TODO: allow callers to determine X and Y position of frame (eg. via // bounds object). @@ -906,22 +894,40 @@ public class Desktop extends jalview.jbgui.GDesktop { frame.setSize(w, h); } - // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN - // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN - // IF JALVIEW IS RUNNING HEADLESS - // /////////////////////////////////////////////// - if (instance == null || (System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true"))) - { - return; - } + if (getInstance() != null) + getInstance().addFrame(frame, makeVisible, resizable, + ignoreMinSize); + } + + // These can now by put into a single int flag, if desired: + + public final static boolean FRAME_MAKE_VISIBLE = true; + + public final static boolean FRAME_NOT_VISIBLE = false; + + public final static boolean FRAME_ALLOW_RESIZE = true; + + public final static boolean FRAME_NOT_RESIZABLE = false; + + public final static boolean FRAME_ALLOW_ANY_SIZE = true; + + public final static boolean FRAME_SET_MIN_SIZE_300 = false; + + private void addFrame(JInternalFrame frame, + boolean makeVisible, boolean resizable, + boolean ignoreMinSize) + { openFrameCount++; + + boolean isEmbedded = (Platform.getEmbeddedAttribute(frame, "id") != null); + boolean hasEmbeddedSize = (Platform.getDimIfEmbedded(frame, -1, -1) != null); + // Web page embedding allows us to ignore minimum size + ignoreMinSize |= hasEmbeddedSize; + if (!ignoreMinSize) { - frame.setMinimumSize( - new Dimension(DEFAULT_MIN_WIDTH, DEFAULT_MIN_HEIGHT)); // Set default dimension for Alignment Frame window. // The Alignment Frame window could be added from a number of places, @@ -931,6 +937,10 @@ public class Desktop extends jalview.jbgui.GDesktop { frame.setMinimumSize(new Dimension(ALIGN_FRAME_DEFAULT_MIN_WIDTH, ALIGN_FRAME_DEFAULT_MIN_HEIGHT)); + } else { + frame.setMinimumSize( + new Dimension(DEFAULT_MIN_WIDTH, DEFAULT_MIN_HEIGHT)); + } } @@ -941,23 +951,23 @@ public class Desktop extends jalview.jbgui.GDesktop frame.setIconifiable(resizable); frame.setOpaque(Platform.isJS()); - if (frame.getX() < 1 && frame.getY() < 1) + if (!isEmbedded && frame.getX() < 1 && frame.getY() < 1) { frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount - 1) % 10) + yOffset); } /* - * add an entry for the new frame in the Window menu (and remove it when the - * frame is closed) + * add an entry for the new frame in the Window menu + * (and remove it when the frame is closed) */ - final JMenuItem menuItem = new JMenuItem(title); + final JMenuItem menuItem = new JMenuItem(frame.getTitle()); frame.addInternalFrameListener(new InternalFrameAdapter() { @Override public void internalFrameActivated(InternalFrameEvent evt) { - JInternalFrame itf = desktop.getSelectedFrame(); + JInternalFrame itf = getDesktopPane().getSelectedFrame(); if (itf != null) { if (itf instanceof AlignFrame) @@ -974,7 +984,8 @@ public class Desktop extends jalview.jbgui.GDesktop PaintRefresher.RemoveComponent(frame); /* - * defensive check to prevent frames being added half off the window + * defensive check to prevent frames being + * added half off the window */ if (openFrameCount > 0) { @@ -988,7 +999,7 @@ public class Desktop extends jalview.jbgui.GDesktop { menuItem.removeActionListener(menuItem.getActionListeners()[0]); } - windowMenu.remove(menuItem); + getInstance().windowMenu.remove(menuItem); } }); @@ -1003,6 +1014,7 @@ public class Desktop extends jalview.jbgui.GDesktop frame.setIcon(false); } catch (java.beans.PropertyVetoException ex) { + // System.err.println(ex.toString()); } } @@ -1010,9 +1022,9 @@ public class Desktop extends jalview.jbgui.GDesktop setKeyBindings(frame); - desktop.add(frame); + getDesktopPane().add(frame); - windowMenu.add(menuItem); + getInstance().windowMenu.add(menuItem); frame.toFront(); try @@ -1050,10 +1062,8 @@ public class Desktop extends jalview.jbgui.GDesktop /* * set up key bindings for Ctrl-W and Cmd-W, with the same (Close) action */ - KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, - InputEvent.CTRL_DOWN_MASK); - KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, - ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()); + KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK); + KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, Platform.SHORTCUT_KEY_MASK); InputMap inputMap = frame .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); @@ -1070,7 +1080,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (!internalCopy) { - Desktop.jalviewClipboard = null; + jalviewClipboard = null; } internalCopy = false; @@ -1115,7 +1125,7 @@ public class Desktop extends jalview.jbgui.GDesktop try { - Desktop.transferFromDropTarget(files, protocols, evt, t); + transferFromDropTarget(files, protocols, evt, t); } catch (Exception e) { e.printStackTrace(); @@ -1192,8 +1202,8 @@ public class Desktop extends jalview.jbgui.GDesktop /* * Call IdentifyFile to verify the file contains what its extension implies. - * Skip this step for dynamically added file formats, because IdentifyFile does - * not know how to recognise them. + * Skip this step for dynamically added file formats, because + * IdentifyFile does not know how to recognise them. */ if (FileFormats.getInstance().isIdentifiable(format)) { @@ -1231,8 +1241,9 @@ public class Desktop extends jalview.jbgui.GDesktop panel.add(label); /* - * the URL to fetch is input in Java: an editable combobox with history JS: - * (pending JAL-3038) a plain text field + * the URL to fetch is + * Java: an editable combobox with history + * JS: (pending JAL-3038) a plain text field */ JComponent history; String urlBase = "https://www."; @@ -1271,26 +1282,16 @@ public class Desktop extends jalview.jbgui.GDesktop public void run() { @SuppressWarnings("unchecked") - String url = (history instanceof JTextField - ? ((JTextField) history).getText() - : ((JComboBox) history).getEditor().getItem() - .toString().trim()); - - if (url.toLowerCase(Locale.ROOT).endsWith(".jar")) - { - if (viewport != null) - { - new FileLoader().LoadFile(viewport, url, DataSourceType.URL, - FileFormat.Jalview); - } - else - { - new FileLoader().LoadFile(url, DataSourceType.URL, - FileFormat.Jalview); + String url = (history instanceof JTextField ? ((JTextField) history).getText() + : ((JComboBox) history).getEditor().getItem().toString().trim()); + + if (url.toLowerCase(Locale.ROOT).endsWith(".jar")) { + if (viewport != null) { + new FileLoader().LoadFile(viewport, url, DataSourceType.URL, FileFormat.Jalview); + } else { + new FileLoader().LoadFile(url, DataSourceType.URL, FileFormat.Jalview); } - } - else - { + } else { FileFormatI format = null; try { @@ -1305,7 +1306,7 @@ public class Desktop extends jalview.jbgui.GDesktop { String msg = MessageManager .formatMessage("label.couldnt_locate", url); - JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg, + JvOptionPane.showInternalMessageDialog(getDesktopPane(), msg, MessageManager.getString("label.url_not_found"), JvOptionPane.WARNING_MESSAGE); @@ -1326,7 +1327,7 @@ public class Desktop extends jalview.jbgui.GDesktop }; String dialogOption = MessageManager .getString("label.input_alignment_from_url"); - JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action) + JvOptionPane.newOptionDialog(desktopPane).setResponseHandler(0, action) .showInternalDialog(panel, dialogOption, JvOptionPane.YES_NO_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null, options, @@ -1346,9 +1347,10 @@ public class Desktop extends jalview.jbgui.GDesktop { CutAndPasteTransfer cap = new CutAndPasteTransfer(); cap.setForInput(viewPanel); - Desktop.addInternalFrame(cap, - MessageManager.getString("label.cut_paste_alignmen_file"), true, - 600, 500); + addInternalFrame(cap, + MessageManager.getString("label.cut_paste_alignmen_file"), + FRAME_MAKE_VISIBLE, 600, 500, FRAME_ALLOW_RESIZE, + FRAME_SET_MIN_SIZE_300); } /* @@ -1429,40 +1431,28 @@ public class Desktop extends jalview.jbgui.GDesktop public String getAboutMessage() { StringBuilder message = new StringBuilder(1024); - message.append("
") - .append("

Version: ") - .append(Cache.getProperty("VERSION")).append("

") - .append("Built: ") - .append(Cache.getDefault("BUILD_DATE", "unknown")) - .append(" from ").append(Cache.getBuildDetailsForSplash()) - .append(""); + message.append("
").append("

Version: ") + .append(Cache.getProperty("VERSION")).append("

").append("Built: ") + .append(Cache.getDefault("BUILD_DATE", "unknown")).append(" from ") + .append(Cache.getBuildDetailsForSplash()).append(""); String latestVersion = Cache.getDefault("LATEST_VERSION", "Checking"); - if (latestVersion.equals("Checking")) - { + if (latestVersion.equals("Checking")) { // JBP removed this message for 2.11: May be reinstated in future version // message.append("
...Checking latest version...
"); - } - else if (!latestVersion.equals(Cache.getProperty("VERSION"))) - { + } else if (!latestVersion.equals(Cache.getProperty("VERSION"))) { boolean red = false; - if (Cache.getProperty("VERSION").toLowerCase(Locale.ROOT) - .indexOf("automated build") == -1) - { + if (Cache.getProperty("VERSION").toLowerCase(Locale.ROOT).indexOf("automated build") == -1) { red = true; // Displayed when code version and jnlp version do not match and code // version is not a development build message.append("
"); } - message.append("
!! Version ") - .append(Cache.getDefault("LATEST_VERSION", "..Checking..")) - .append(" is available for download from ") - .append(Cache.getDefault("www.jalview.org", - "https://www.jalview.org")) - .append(" !!"); - if (red) - { + message.append("
!! Version ").append(Cache.getDefault("LATEST_VERSION", "..Checking..")) + .append(" is available for download from ") + .append(Cache.getDefault("www.jalview.org", "https://www.jalview.org")).append(" !!"); + if (red) { message.append("
"); } } @@ -1479,15 +1469,11 @@ public class Desktop extends jalview.jbgui.GDesktop * Action on requesting Help documentation */ @Override - public void documentationMenuItem_actionPerformed() - { - try - { - if (Platform.isJS()) - { + public void documentationMenuItem_actionPerformed() { + try { + if (Platform.isJS()) { BrowserLauncher.openURL("https://www.jalview.org/help.html"); - } - else + } else /** * Java only * @@ -1496,8 +1482,7 @@ public class Desktop extends jalview.jbgui.GDesktop { Help.showHelpWindow(); } - } catch (Exception ex) - { + } catch (Exception ex) { System.err.println("Error opening help: " + ex.getMessage()); } } @@ -1506,7 +1491,7 @@ public class Desktop extends jalview.jbgui.GDesktop public void closeAll_actionPerformed(ActionEvent e) { // TODO show a progress bar while closing? - JInternalFrame[] frames = desktop.getAllFrames(); + JInternalFrame[] frames = desktopPane.getAllFrames(); for (int i = 0; i < frames.length; i++) { try @@ -1566,13 +1551,14 @@ public class Desktop extends jalview.jbgui.GDesktop /* * (non-Javadoc) * - * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event. - * ActionEvent ) + * @see + * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent + * ) */ @Override protected void showMemusage_actionPerformed(ActionEvent e) { - desktop.showMemoryUsage(showMemusage.isSelected()); + desktopPane.showMemoryUsage(showMemusage.isSelected()); } /* @@ -1609,13 +1595,14 @@ public class Desktop extends jalview.jbgui.GDesktop void reorderAssociatedWindows(boolean minimize, boolean close) { - JInternalFrame[] frames = desktop.getAllFrames(); + JInternalFrame[] frames = desktopPane.getAllFrames(); if (frames == null || frames.length < 1) { return; } - AlignmentViewport source = null, target = null; + AlignViewportI source = null; + AlignViewportI target = null; if (frames[0] instanceof AlignFrame) { source = ((AlignFrame) frames[0]).getCurrentView(); @@ -1691,8 +1678,7 @@ public class Desktop extends jalview.jbgui.GDesktop * DOCUMENT ME! */ @Override - protected void preferences_actionPerformed(ActionEvent e) - { + protected void preferences_actionPerformed(ActionEvent e) { Preferences.openPreferences(); } @@ -1736,8 +1722,7 @@ public class Desktop extends jalview.jbgui.GDesktop } } - if (approveSave || autoSave) - { + if (approveSave || autoSave) { final Desktop me = this; final java.io.File chosenFile = projectFile; new Thread(new Runnable() @@ -1846,7 +1831,7 @@ public class Desktop extends jalview.jbgui.GDesktop { jalview.bin.Console.error( "Problems whilst loading project from " + choice, ex); - JvOptionPane.showMessageDialog(Desktop.desktop, + JvOptionPane.showMessageDialog(getDesktopPane(), MessageManager.formatMessage( "label.error_whilst_loading_project_from", new Object[] @@ -1890,7 +1875,7 @@ public class Desktop extends jalview.jbgui.GDesktop { progressPanel = new JPanel(new GridLayout(1, 1)); totalProgressCount = 0; - instance.getContentPane().add(progressPanel, BorderLayout.SOUTH); + getContentPane().add(progressPanel, BorderLayout.SOUTH); } JPanel thisprogress = new JPanel(new BorderLayout(10, 5)); JProgressBar progressBar = new JProgressBar(); @@ -1903,7 +1888,7 @@ public class Desktop extends jalview.jbgui.GDesktop ((GridLayout) progressPanel.getLayout()).setRows( ((GridLayout) progressPanel.getLayout()).getRows() + 1); ++totalProgressCount; - instance.validate(); + validate(); return thisprogress; } @@ -1957,7 +1942,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ public static AlignmentPanel[] getAlignmentPanels(String alignmentId) { - if (Desktop.desktop == null) + if (getDesktopPane() == null) { // no frames created and in headless mode // TODO: verify that frames are recoverable when in headless mode @@ -1999,9 +1984,9 @@ public class Desktop extends jalview.jbgui.GDesktop public static AlignmentViewport[] getViewports(String sequenceSetId) { List viewp = new ArrayList<>(); - if (desktop != null) + if (getDesktopPane() != null) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = getAlignFrames(); for (AlignFrame afr : frames) { @@ -2067,8 +2052,9 @@ public class Desktop extends jalview.jbgui.GDesktop } /* - * Restore the view's last exploded frame geometry if known. Multiple views from - * one exploded frame share and restore the same (frame) position and size. + * Restore the view's last exploded frame geometry if known. Multiple + * views from one exploded frame share and restore the same (frame) + * position and size. */ Rectangle geometry = ap.av.getExplodedGeometry(); if (geometry != null) @@ -2109,7 +2095,7 @@ public class Desktop extends jalview.jbgui.GDesktop { source.viewport.setGatherViewsHere(true); source.viewport.setExplodedGeometry(source.getBounds()); - JInternalFrame[] frames = desktop.getAllFrames(); + JInternalFrame[] frames = desktopPane.getAllFrames(); String viewId = source.viewport.getSequenceSetId(); for (int t = 0; t < frames.length; t++) { @@ -2162,7 +2148,7 @@ public class Desktop extends jalview.jbgui.GDesktop public JInternalFrame[] getAllFrames() { - return desktop.getAllFrames(); + return desktopPane.getAllFrames(); } /** @@ -2248,7 +2234,7 @@ public class Desktop extends jalview.jbgui.GDesktop }); msgPanel.add(jcb); - JvOptionPane.showMessageDialog(Desktop.desktop, msgPanel, + JvOptionPane.showMessageDialog(desktopPane, msgPanel, MessageManager .getString("label.SEQUENCE_ID_no_longer_used"), JvOptionPane.WARNING_MESSAGE); @@ -2353,7 +2339,7 @@ public class Desktop extends jalview.jbgui.GDesktop } // output debug scale message. Important for jalview.bin.HiDPISettingTest2 - Desktop.debugScaleMessage(Desktop.getDesktop().getGraphics()); + Desktop.debugScaleMessage(Desktop.getDesktopPane().getGraphics()); } } @@ -2366,11 +2352,10 @@ public class Desktop extends jalview.jbgui.GDesktop { if (Jalview.isHeadlessMode()) { - // Desktop.desktop is null in headless mode - return new AlignFrame[] { Jalview.currentAlignFrame }; + return new AlignFrame[] { Jalview.getInstance().currentAlignFrame }; } - JInternalFrame[] frames = Desktop.desktop.getAllFrames(); + JInternalFrame[] frames = getDesktopPane().getAllFrames(); if (frames == null) { @@ -2415,7 +2400,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ public GStructureViewer[] getJmols() { - JInternalFrame[] frames = Desktop.desktop.getAllFrames(); + JInternalFrame[] frames = desktopPane.getAllFrames(); if (frames == null) { @@ -2451,7 +2436,7 @@ public class Desktop extends jalview.jbgui.GDesktop } catch (Exception ex) { jalview.bin.Console.error("Groovy Shell Creation failed.", ex); - JvOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(desktopPane, MessageManager.getString("label.couldnt_create_groovy_shell"), MessageManager.getString("label.groovy_support_failed"), @@ -2472,9 +2457,9 @@ public class Desktop extends jalview.jbgui.GDesktop /* * We allow only one console at a time, so that AlignFrame menu option - * 'Calculate | Run Groovy script' is unambiguous. Disable 'Groovy Console', and - * enable 'Run script', when the console is opened, and the reverse when it is - * closed + * 'Calculate | Run Groovy script' is unambiguous. + * Disable 'Groovy Console', and enable 'Run script', when the console is + * opened, and the reverse when it is closed */ Window window = (Window) groovyConsole.getFrame(); window.addWindowListener(new WindowAdapter() @@ -2497,8 +2482,8 @@ public class Desktop extends jalview.jbgui.GDesktop ((Window) groovyConsole.getFrame()).setVisible(true); /* - * if we got this far, enable 'Run Groovy' in AlignFrame menus and disable - * opening a second console + * if we got this far, enable 'Run Groovy' in AlignFrame menus + * and disable opening a second console */ enableExecuteGroovy(true); } @@ -2509,12 +2494,10 @@ public class Desktop extends jalview.jbgui.GDesktop */ protected void addQuitHandler() { - getRootPane() - .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke - .getKeyStroke(KeyEvent.VK_Q, - jalview.util.ShortcutKeyMaskExWrapper - .getMenuShortcutKeyMaskEx()), + + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) + .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, + Platform.SHORTCUT_KEY_MASK), "Quit"); getRootPane().getActionMap().put("Quit", new AbstractAction() { @@ -2535,8 +2518,8 @@ public class Desktop extends jalview.jbgui.GDesktop public void enableExecuteGroovy(boolean enabled) { /* - * disable opening a second Groovy console (or re-enable when the console is - * closed) + * disable opening a second Groovy console + * (or re-enable when the console is closed) */ groovyShell.setEnabled(!enabled); @@ -2565,6 +2548,8 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void setProgressBar(String message, long id) { + // Platform.timeCheck("Desktop " + message, Platform.TIME_MARK); + if (progressBars == null) { progressBars = new Hashtable<>(); @@ -2585,6 +2570,13 @@ public class Desktop extends jalview.jbgui.GDesktop progressBars.put(Long.valueOf(id), addProgressPanel(message)); } } + + @Override + public void removeProgressBar(long id) + { + //TODO + throw new UnsupportedOperationException("not implemented"); + } /* * (non-Javadoc) @@ -2650,7 +2642,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ public static AlignFrame getAlignFrameFor(AlignViewportI viewport) { - if (desktop != null) + if (getDesktopPane() != null) { AlignmentPanel[] aps = getAlignmentPanels( viewport.getSequenceSetId()); @@ -2712,61 +2704,48 @@ public class Desktop extends jalview.jbgui.GDesktop */ public void startServiceDiscovery(boolean blocking) { - startServiceDiscovery(blocking, false); - } + jalview.bin.Console.debug("Starting service discovery"); - /** - * start service discovery threads - * - * @param blocking - * - false means call returns immediately - * @param ignore_SHOW_JWS2_SERVICES_preference - * - when true JABA services are discovered regardless of user's JWS2 - * discovery preference setting - */ - public void startServiceDiscovery(boolean blocking, - boolean ignore_SHOW_JWS2_SERVICES_preference) - { - boolean alive = true; - Thread t0 = null, t1 = null, t2 = null; + var tasks = new ArrayList>(); // JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release - if (true) + + System.out.println("loading services"); + + /** @j2sIgnore */ { // todo: changesupport handlers need to be transferred if (discoverer == null) { - discoverer = new jalview.ws.jws1.Discoverer(); + discoverer = jalview.ws.jws1.Discoverer.getInstance(); // register PCS handler for desktop. discoverer.addPropertyChangeListener(changeSupport); } // JAL-940 - disabled JWS1 service configuration - always start discoverer // until we phase out completely - (t0 = new Thread(discoverer)).start(); + var f = new FutureTask(discoverer, null); + new Thread(f).start(); + tasks.add(f); } - if (ignore_SHOW_JWS2_SERVICES_preference - || Cache.getDefault("SHOW_JWS2_SERVICES", true)) + if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { - t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() - .startDiscoverer(changeSupport); + tasks.add(jalview.ws.jws2.Jws2Discoverer.getInstance().startDiscoverer()); } - Thread t3 = null; + if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true)) { - // TODO: do rest service discovery + tasks.add(jalview.ws.slivkaws.SlivkaWSDiscoverer.getInstance().startDiscoverer()); } if (blocking) { - while (alive) - { + for (Future task : tasks) { try { - Thread.sleep(15); + // block until all discovery tasks are done + task.get(); } catch (Exception e) { + e.printStackTrace(); } - alive = (t1 != null && t1.isAlive()) || (t2 != null && t2.isAlive()) - || (t3 != null && t3.isAlive()) - || (t0 != null && t0.isAlive()); } } } @@ -2780,8 +2759,10 @@ public class Desktop extends jalview.jbgui.GDesktop { if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector) { - final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() - .getErrorMessages(); + final WSDiscovererI discoverer = jalview.ws.jws2.Jws2Discoverer + .getInstance(); + final String ermsg = discoverer.getErrorMessages(); + // CONFLICT:ALT:? final String ermsg = jalview.ws.jws2.Jws2Discoverer.getInstance() if (ermsg != null) { if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true)) @@ -2798,23 +2779,28 @@ public class Desktop extends jalview.jbgui.GDesktop /* * JalviewDialog jd =new JalviewDialog() { * - * @Override protected void cancelPressed() { // TODO Auto-generated method stub + * @Override protected void cancelPressed() { // TODO + * Auto-generated method stub * - * }@Override protected void okPressed() { // TODO Auto-generated method stub + * }@Override protected void okPressed() { // TODO + * Auto-generated method stub * - * }@Override protected void raiseClosed() { // TODO Auto-generated method stub + * }@Override protected void raiseClosed() { // TODO + * Auto-generated method stub * - * } }; jd.initDialogFrame(new JLabel("
" + - * ermsg + + * } }; jd.initDialogFrame(new + * JLabel("
" + ermsg + * "
It may be that you have invalid JABA URLs in your web service preferences," * + " or mis-configured HTTP proxy settings.
" + - * "Check the Connections and Web services tab of the" + - * " Tools->Preferences dialog box to change them.
" ), - * true, true, "Web Service Configuration Problem", 450, 400); + * "Check the Connections and Web services tab of the" + * + + * " Tools->Preferences dialog box to change them.
" + * ), true, true, "Web Service Configuration Problem", 450, + * 400); * * jd.waitForInput(); */ - JvOptionPane.showConfirmDialog(Desktop.desktop, + JvOptionPane.showConfirmDialog(desktopPane, new JLabel("
" + ermsg + "
" + "

It may be that you have invalid JABA URLs
in your web service preferences," @@ -2851,7 +2837,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ public static void showUrl(final String url) { - showUrl(url, Desktop.instance); + showUrl(url, getInstance()); } /** @@ -2880,7 +2866,7 @@ public class Desktop extends jalview.jbgui.GDesktop jalview.util.BrowserLauncher.openURL(url); } catch (Exception ex) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(getDesktopPane(), MessageManager .getString("label.web_browser_not_found_unix"), MessageManager.getString("label.web_browser_not_found"), @@ -2920,13 +2906,13 @@ public class Desktop extends jalview.jbgui.GDesktop try { url = e.getURL().toString(); - Desktop.showUrl(url); + showUrl(url); } catch (Exception x) { if (url != null) { - jalview.bin.Console - .error("Couldn't handle string " + url + " as a URL."); + // TODO does error send to stderr if no log exists ? + jalview.bin.Console.error("Couldn't handle string " + url + " as a URL."); } // ignore any exceptions due to dud links. } @@ -2972,7 +2958,7 @@ public class Desktop extends jalview.jbgui.GDesktop { } } - if (instance == null) + if (Jalview.isHeadlessMode()) { return; } @@ -2981,8 +2967,7 @@ public class Desktop extends jalview.jbgui.GDesktop SwingUtilities.invokeAndWait(prompter); } catch (Exception q) { - jalview.bin.Console.warn("Unexpected Exception in dialog thread.", - q); + jalview.bin.Console.warn("Unexpected Exception in dialog thread.", q); } } }); @@ -3055,15 +3040,16 @@ public class Desktop extends jalview.jbgui.GDesktop } /* - * Processing in reverse order works, forwards order leaves the first panels not - * visible. I don't know why! + * Processing in reverse order works, forwards order leaves the first panels + * not visible. I don't know why! */ for (int i = viewCount - 1; i >= 0; i--) { /* - * Make new top and bottom frames. These take over the respective AlignmentPanel - * objects, including their AlignmentViewports, so the cdna/protein - * relationships between the viewports is carried over to the new split frames. + * Make new top and bottom frames. These take over the respective + * AlignmentPanel objects, including their AlignmentViewports, so the + * cdna/protein relationships between the viewports is carried over to the + * new split frames. * * explodedGeometry holds the (x, y) position of the previously exploded * SplitFrame, and the (width, height) of the AlignFrame component @@ -3098,12 +3084,12 @@ public class Desktop extends jalview.jbgui.GDesktop { splitFrame.setLocation(geometry.getLocation()); } - Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1); + addInternalFrame(splitFrame, sf.getTitle(), -1, -1); } /* - * Clear references to the panels (now relocated in the new SplitFrames) before - * closing the old SplitFrame. + * Clear references to the panels (now relocated in the new SplitFrames) + * before closing the old SplitFrame. */ topPanels.clear(); bottomPanels.clear(); @@ -3136,7 +3122,7 @@ public class Desktop extends jalview.jbgui.GDesktop String topViewId = myTopFrame.viewport.getSequenceSetId(); String bottomViewId = myBottomFrame.viewport.getSequenceSetId(); - JInternalFrame[] frames = desktop.getAllFrames(); + JInternalFrame[] frames = desktopPane.getAllFrames(); for (JInternalFrame frame : frames) { if (frame instanceof SplitFrame && frame != source) @@ -3199,11 +3185,34 @@ public class Desktop extends jalview.jbgui.GDesktop * - the payload from the drop event * @throws Exception */ + @SuppressWarnings("unchecked") public static void transferFromDropTarget(List files, List protocols, DropTargetDropEvent evt, Transferable t) throws Exception { + // BH 2018 changed List to List to allow for File from + // SwingJS + + // DataFlavor[] flavors = t.getTransferDataFlavors(); + // for (int i = 0; i < flavors.length; i++) { + // if (flavors[i].isFlavorJavaFileListType()) { + // evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); + // List list = (List) t.getTransferData(flavors[i]); + // for (int j = 0; j < list.size(); j++) { + // File file = (File) list.get(j); + // byte[] data = getDroppedFileBytes(file); + // fileName.setText(file.getName() + " - " + data.length + " " + + // evt.getLocation()); + // JTextArea target = (JTextArea) ((DropTarget) + // evt.getSource()).getComponent(); + // target.setText(new String(data)); + // } + // dtde.dropComplete(true); + // return; + // } + // + DataFlavor uriListFlavor = new DataFlavor( "text/uri-list;class=java.lang.String"), urlFlavour = null; try @@ -3249,7 +3258,7 @@ public class Desktop extends jalview.jbgui.GDesktop { // Works on Windows and MacOSX jalview.bin.Console.debug("Drop handled as javaFileListFlavor"); - for (Object file : (List) t + for (File file : (List) t .getTransferData(DataFlavor.javaFileListFlavor)) { files.add(file); @@ -3345,8 +3354,7 @@ public class Desktop extends jalview.jbgui.GDesktop } else { - jalview.bin.Console - .debug("Couldn't resolve dataflavor for drop: " + jalview.bin.Console.debug("Couldn't resolve dataflavor for drop: " + t.toString()); } } @@ -3354,8 +3362,7 @@ public class Desktop extends jalview.jbgui.GDesktop } if (Platform.isWindowsAndNotJS()) { - jalview.bin.Console - .debug("Scanning dropped content for Windows Link Files"); + jalview.bin.Console.debug("Scanning dropped content for Windows Link Files"); // resolve any .lnk files in the file drop for (int f = 0; f < files.size(); f++) @@ -3416,7 +3423,7 @@ public class Desktop extends jalview.jbgui.GDesktop Class structureViewerClass) { List result = new ArrayList<>(); - JInternalFrame[] frames = Desktop.instance.getAllFrames(); + JInternalFrame[] frames = getAllFrames(); for (JInternalFrame frame : frames) { @@ -3440,18 +3447,14 @@ public class Desktop extends jalview.jbgui.GDesktop private static boolean debugScaleMessageDone = false; - public static void debugScaleMessage(Graphics g) - { - if (debugScaleMessageDone) - { + public static void debugScaleMessage(Graphics g) { + if (debugScaleMessageDone) { return; } // output used by tests to check HiDPI scaling settings in action - try - { + try { Graphics2D gg = (Graphics2D) g; - if (gg != null) - { + if (gg != null) { AffineTransform t = gg.getTransform(); double scaleX = t.getScaleX(); double scaleY = t.getScaleY();