X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=9dd46d648572dfa7ea924c4333fd3af16f7aa9cd;hb=4f77328104498504339216829abf5ea87e2791ec;hp=c3640a9243e74f8823419f0d29e7790bead3b037;hpb=ad16d6cce49a40ea1943431b980b85a6212bb9bf;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index c3640a9..9dd46d6 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -22,9 +22,6 @@ package jalview.gui; 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; @@ -39,7 +36,6 @@ import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; -import jalview.jbgui.GDesktop; import jalview.jbgui.GSplitFrame; import jalview.jbgui.GStructureViewer; import jalview.project.Jalview2XML; @@ -51,7 +47,6 @@ import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.UrlConstants; import jalview.viewmodel.AlignmentViewport; -import jalview.ws.jws1.Discoverer; import jalview.ws.params.ParamManager; import jalview.ws.utils.UrlDownloadClient; @@ -87,9 +82,11 @@ import java.beans.PropertyChangeListener; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.ListIterator; @@ -111,7 +108,6 @@ import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDesktopPane; -import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JMenuItem; @@ -137,28 +133,30 @@ import org.stackoverflowusers.file.WindowsShortcut; * @author $author$ * @version $Revision: 1.155 $ */ -@SuppressWarnings("serial") -public class Desktop extends GDesktop +public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener, ClipboardOwner, IProgressIndicator, - StructureSelectionManagerProvider, ApplicationSingletonI + jalview.api.StructureSelectionManagerProvider { + private static int DEFAULT_MIN_WIDTH = 300; - private final static int DEFAULT_MIN_WIDTH = 300; + private static int DEFAULT_MIN_HEIGHT = 250; - private final static int DEFAULT_MIN_HEIGHT = 250; + private static int ALIGN_FRAME_DEFAULT_MIN_WIDTH = 600; - private final static int ALIGN_FRAME_DEFAULT_MIN_WIDTH = 600; + private static int ALIGN_FRAME_DEFAULT_MIN_HEIGHT = 70; - private final static int ALIGN_FRAME_DEFAULT_MIN_HEIGHT = 70; + private static final String EXPERIMENTAL_FEATURES = "EXPERIMENTAL_FEATURES"; - private final static String EXPERIMENTAL_FEATURES = "EXPERIMENTAL_FEATURES"; + protected static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT"; + + public static HashMap savingFiles = new HashMap<>(); private JalviewChangeSupport changeSupport = new JalviewChangeSupport(); /** * news reader - null if it was never started. */ - BlogReader jvnews = null; + private BlogReader jvnews = null; private File projectFile; @@ -197,15 +195,16 @@ public class Desktop extends GDesktop listener); } - public static MyDesktopPane getDesktopPane() - { - return Desktop.getInstance().desktopPane; - } + /** Singleton Desktop instance */ + public static Desktop instance; + + public static MyDesktopPane desktop; - public StructureSelectionManager getStructureSelectionManager() + public static MyDesktopPane getDesktop() { - return StructureSelectionManager - .getStructureSelectionManager(this); + // BH 2018 could use currentThread() here as a reference to a + // Hashtable in JavaScript + return desktop; } static int openFrameCount = 0; @@ -214,20 +213,13 @@ public class Desktop extends GDesktop static final int yOffset = 30; - public Discoverer discoverer; - - public Object[] jalviewClipboard; + public static jalview.ws.jws1.Discoverer discoverer; - public boolean internalCopy = false; + public static Object[] jalviewClipboard; - private static int fileLoadingCount = 0; + public static boolean internalCopy = false; - public JInternalFrame conservationSlider, PIDSlider; - - /** - * just an instance (for testng, probably); no actual frames - */ - private boolean instanceOnly; + static int fileLoadingCount = 0; class MyDesktopManager implements DesktopManager { @@ -248,7 +240,7 @@ public class Desktop extends GDesktop } catch (NullPointerException npe) { Point p = getMousePosition(); - showPasteMenu(p.x, p.y); + instance.showPasteMenu(p.x, p.y); } } @@ -296,14 +288,14 @@ public class Desktop extends GDesktop public void endDraggingFrame(JComponent f) { delegate.endDraggingFrame(f); - desktopPane.repaint(); + desktop.repaint(); } @Override public void endResizingFrame(JComponent f) { delegate.endResizingFrame(f); - desktopPane.repaint(); + desktop.repaint(); } @Override @@ -352,83 +344,100 @@ public class Desktop extends GDesktop } - public MyDesktopPane desktopPane; - - /** - * 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 (Desktop) ApplicationSingletonProvider - .getInstance(Desktop.class); - } - /** - * For testing. - * - * @param forInstance + * Creates a new Desktop object. */ - public Desktop(boolean forInstance) - { - instanceOnly = true; - } - - /** - * Private constructor enforces singleton pattern. It is called by reflection - * from ApplicationSingletonProvider.getInstance(). - */ - @SuppressWarnings("unused") - private Desktop() + public 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; if (!Platform.isJS()) { doVamsasClientCheck(); } - + doConfigureStructurePrefs(); setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION")); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + /* + if (!Platform.isAMac()) + { + // this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + } + else + { + this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + } + */ + + try + { + if (!Platform.isJS()) + /* + * @j2sIgnore + */ + { + APQHandlers.setAPQHandlers(this); + } + } catch (Exception e) + { + System.out.println("Cannot set APQHandlers"); + // e.printStackTrace(); + } catch (Throwable t) + { + System.out.println("Cannot set APQHandlers"); + // t.printStackTrace(); + } + + + addWindowListener(new WindowAdapter() + { + + @Override + public void windowClosing(WindowEvent ev) + { + quit(); + } + }); + boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE", false); + boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE", false); - desktopPane = new MyDesktopPane(selmemusage); - + desktop = new MyDesktopPane(selmemusage); + showMemusage.setSelected(selmemusage); - desktopPane.setBackground(Color.white); + desktop.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); - + // BH 2018 - just an experiment to try unclipped JInternalFrames. if (Platform.isJS()) { getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); } - - getContentPane().add(desktopPane, BorderLayout.CENTER); - desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); - + + getContentPane().add(desktop, BorderLayout.CENTER); + desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); + // This line prevents Windows Look&Feel resizing all new windows to maximum // if previous window was maximised - desktopPane.setDesktopManager(new MyDesktopManager( + desktop.setDesktopManager(new MyDesktopManager( (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager() : Platform.isAMacAndNotJS() ? new AquaInternalFrameManager( - desktopPane.getDesktopManager()) - : desktopPane.getDesktopManager()))); - + desktop.getDesktopManager()) + : desktop.getDesktopManager()))); + Rectangle dims = getLastKnownDimensions(""); if (dims != null) { @@ -441,7 +450,7 @@ public class Desktop extends GDesktop int yPos = Math.max(5, (screenSize.height - 650) / 2); setBounds(xPos, yPos, 900, 650); } - + if (!Platform.isJS()) /** * Java only @@ -449,7 +458,7 @@ public class Desktop extends GDesktop * @j2sIgnore */ { - + jconsole = new Console(this, showjconsole); // add essential build information jconsole.setHeader("Jalview Version: " @@ -461,20 +470,27 @@ public class Desktop extends GDesktop + "Java version: " + System.getProperty("java.version") + "\n" + System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " - + System.getProperty("os.version")); - + + System.getProperty("os.version") + + (jalview.bin.Cache.getProperty("VERSION").equals("DEVELOPMENT") + ? "\nJava path:" + + System.getProperty( + "java.home") + + File.separator + "bin" + + File.separator + "java" + : "")); + showConsole(showjconsole); - + showNews.setVisible(false); - + experimentalFeatures.setSelected(showExperimental()); - + getIdentifiersOrgData(); - + checkURLLinks(); - + // Spawn a thread that shows the splashscreen - + SwingUtilities.invokeLater(new Runnable() { @Override @@ -483,10 +499,9 @@ public class Desktop extends GDesktop new SplashScreen(); } }); - + // Thread off a new instance of the file chooser - this reduces the time - // it - // takes to open it later on. + // it takes to open it later on. new Thread(new Runnable() { @Override @@ -503,7 +518,7 @@ public class Desktop extends GDesktop changeSupport.addJalviewPropertyChangeListener("services", new PropertyChangeListener() { - + @Override public void propertyChange(PropertyChangeEvent evt) { @@ -511,13 +526,13 @@ public class Desktop extends GDesktop + evt.getNewValue()); JalviewServicesChanged(evt); } - + }); - + } - - this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); - + + this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); + this.addWindowListener(new WindowAdapter() { @Override @@ -526,7 +541,7 @@ public class Desktop extends GDesktop quit(); } }); - + MouseAdapter ma; this.addMouseListener(ma = new MouseAdapter() { @@ -538,7 +553,7 @@ public class Desktop extends GDesktop showPasteMenu(evt.getX(), evt.getY()); } } - + @Override public void mouseReleased(MouseEvent evt) { @@ -548,7 +563,8 @@ public class Desktop extends GDesktop } } }); - desktopPane.addMouseListener(ma); + desktop.addMouseListener(ma); + } /** @@ -567,7 +583,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 @@ -611,10 +628,10 @@ public class Desktop extends GDesktop public void run() { Cache.log.debug("Downloading data from identifiers.org"); - // UrlDownloadClient client = new UrlDownloadClient(); + UrlDownloadClient client = new UrlDownloadClient(); try { - UrlDownloadClient.download(IdOrgSettings.getUrl(), + client.download(IdOrgSettings.getUrl(), IdOrgSettings.getDownloadLocation()); } catch (IOException e) { @@ -632,7 +649,7 @@ public class Desktop extends GDesktop showNews(showNews.isSelected()); } - protected void showNews(boolean visible) + void showNews(boolean visible) { Cache.log.debug((visible ? "Showing" : "Hiding") + " news."); showNews.setSelected(visible); @@ -644,10 +661,10 @@ public class Desktop extends GDesktop public void run() { long now = System.currentTimeMillis(); - setProgressBar( + Desktop.instance.setProgressBar( MessageManager.getString("status.refreshing_news"), now); jvnews.refreshNews(); - setProgressBar(null, now); + Desktop.instance.setProgressBar(null, now); jvnews.showNews(); } }).start(); @@ -752,7 +769,7 @@ public class Desktop extends GDesktop } } - protected void showPasteMenu(int x, int y) + void showPasteMenu(int x, int y) { JPopupMenu popup = new JPopupMenu(); JMenuItem item = new JMenuItem( @@ -894,7 +911,8 @@ public class Desktop extends GDesktop // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN // IF JALVIEW IS RUNNING HEADLESS // /////////////////////////////////////////////// - if (Desktop.getInstance().instanceOnly || Jalview.isHeadlessMode()) + if (instance == null || (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true"))) { return; } @@ -934,13 +952,13 @@ public class Desktop extends GDesktop * add an entry for the new frame in the Window menu * (and remove it when the frame is closed) */ - JMenuItem menuItem = new JMenuItem(title); + final JMenuItem menuItem = new JMenuItem(title); frame.addInternalFrameListener(new InternalFrameAdapter() { @Override public void internalFrameActivated(InternalFrameEvent evt) { - JInternalFrame itf = getDesktopPane().getSelectedFrame(); + JInternalFrame itf = desktop.getSelectedFrame(); if (itf != null) { if (itf instanceof AlignFrame) @@ -972,7 +990,7 @@ public class Desktop extends GDesktop { menuItem.removeActionListener(menuItem.getActionListeners()[0]); } - Desktop.getInstance().windowMenu.remove(menuItem); + windowMenu.remove(menuItem); } }); @@ -994,9 +1012,9 @@ public class Desktop extends GDesktop setKeyBindings(frame); - getDesktopPane().add(frame); + desktop.add(frame); - Desktop.getInstance().windowMenu.add(menuItem); + windowMenu.add(menuItem); frame.toFront(); try @@ -1021,6 +1039,7 @@ public class Desktop extends GDesktop */ private static void setKeyBindings(JInternalFrame frame) { + @SuppressWarnings("serial") final Action closeAction = new AbstractAction() { @Override @@ -1036,7 +1055,7 @@ public class Desktop extends GDesktop KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK); KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, - Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); + jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()); InputMap inputMap = frame .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); @@ -1053,7 +1072,7 @@ public class Desktop extends GDesktop { if (!internalCopy) { - Desktop.getInstance().jalviewClipboard = null; + Desktop.jalviewClipboard = null; } internalCopy = false; @@ -1155,7 +1174,7 @@ public class Desktop extends GDesktop { String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); JalviewFileChooser chooser = JalviewFileChooser - .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, true); + .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, BackupFiles.getEnabled()); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( @@ -1288,8 +1307,7 @@ public class Desktop extends GDesktop { String msg = MessageManager .formatMessage("label.couldnt_locate", url); - JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), - msg, + JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg, MessageManager.getString("label.url_not_found"), JvOptionPane.WARNING_MESSAGE); @@ -1310,8 +1328,7 @@ public class Desktop extends GDesktop }; String dialogOption = MessageManager .getString("label.input_alignment_from_url"); - JvOptionPane.newOptionDialog(getDesktopPane()) - .setResponseHandler(0, action) + JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action) .showInternalDialog(panel, dialogOption, JvOptionPane.YES_NO_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null, options, @@ -1397,7 +1414,7 @@ public class Desktop extends GDesktop public void aboutMenuItem_actionPerformed(ActionEvent e) { // StringBuffer message = getAboutMessage(false); - // JvOptionPane.showInternalMessageDialog(Desktop.getDesktop(), + // JvOptionPane.showInternalMessageDialog(Desktop.desktop, // // message.toString(), "About Jalview", JvOptionPane.INFORMATION_MESSAGE); new Thread(new Runnable() @@ -1506,12 +1523,8 @@ public class Desktop extends GDesktop @Override public void closeAll_actionPerformed(ActionEvent e) { - if (desktopPane == null) - { - return; - } // TODO show a progress bar while closing? - JInternalFrame[] frames = desktopPane.getAllFrames(); + JInternalFrame[] frames = desktop.getAllFrames(); for (int i = 0; i < frames.length; i++) { try @@ -1532,7 +1545,12 @@ public class Desktop extends GDesktop * reset state of singleton objects as appropriate (clear down session state * when all windows are closed) */ - getStructureSelectionManager().resetAll(); + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(this); + if (ssm != null) + { + ssm.resetAll(); + } } @Override @@ -1577,7 +1595,7 @@ public class Desktop extends GDesktop @Override protected void showMemusage_actionPerformed(ActionEvent e) { - getDesktopPane().showMemoryUsage(showMemusage.isSelected()); + desktop.showMemoryUsage(showMemusage.isSelected()); } /* @@ -1614,7 +1632,7 @@ public class Desktop extends GDesktop void reorderAssociatedWindows(boolean minimize, boolean close) { - JInternalFrame[] frames = getDesktopPane().getAllFrames(); + JInternalFrame[] frames = desktop.getAllFrames(); if (frames == null || frames.length < 1) { return; @@ -1798,7 +1816,7 @@ public class Desktop extends GDesktop saveState_actionPerformed(true); } - protected void setProjectFile(File choice) + private void setProjectFile(File choice) { this.projectFile = choice; } @@ -1820,7 +1838,7 @@ public class Desktop extends GDesktop "Jalview Project (old)" }; JalviewFileChooser chooser = new JalviewFileChooser( Cache.getProperty("LAST_DIRECTORY"), suffix, desc, - "Jalview Project", true, true); // last two booleans: allFiles, + "Jalview Project", true, BackupFiles.getEnabled()); // last two booleans: allFiles, // allowBackupFiles chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.restore_state")); @@ -1848,7 +1866,7 @@ public class Desktop extends GDesktop { Cache.log.error( "Problems whilst loading project from " + choice, ex); - JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), + JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager.formatMessage( "label.error_whilst_loading_project_from", new Object[] @@ -1891,7 +1909,7 @@ public class Desktop extends GDesktop { progressPanel = new JPanel(new GridLayout(1, 1)); totalProgressCount = 0; - getContentPane().add(progressPanel, BorderLayout.SOUTH); + instance.getContentPane().add(progressPanel, BorderLayout.SOUTH); } JPanel thisprogress = new JPanel(new BorderLayout(10, 5)); JProgressBar progressBar = new JProgressBar(); @@ -1904,7 +1922,7 @@ public class Desktop extends GDesktop ((GridLayout) progressPanel.getLayout()).setRows( ((GridLayout) progressPanel.getLayout()).getRows() + 1); ++totalProgressCount; - validate(); + instance.validate(); return thisprogress; } @@ -1958,7 +1976,7 @@ public class Desktop extends GDesktop */ public static AlignmentPanel[] getAlignmentPanels(String alignmentId) { - if (Desktop.getDesktopPane() == null) + if (Desktop.desktop == null) { // no frames created and in headless mode // TODO: verify that frames are recoverable when in headless mode @@ -2000,7 +2018,7 @@ public class Desktop extends GDesktop public static AlignmentViewport[] getViewports(String sequenceSetId) { List viewp = new ArrayList<>(); - if (getDesktopPane() != null) + if (desktop != null) { AlignFrame[] frames = Desktop.getAlignFrames(); @@ -2086,7 +2104,7 @@ public class Desktop extends GDesktop { source.viewport.setGatherViewsHere(true); source.viewport.setExplodedGeometry(source.getBounds()); - JInternalFrame[] frames = getAllFrames(); + JInternalFrame[] frames = desktop.getAllFrames(); String viewId = source.viewport.getSequenceSetId(); for (int t = 0; t < frames.length; t++) @@ -2143,7 +2161,7 @@ public class Desktop extends GDesktop String fle = chooser.getSelectedFile().toString(); if (!vamsasImport(chooser.getSelectedFile())) { - JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager.formatMessage( "label.couldnt_import_as_vamsas_session", new Object[] @@ -2444,7 +2462,7 @@ public class Desktop extends GDesktop removeProgressPanel(progpanel); if (warnmsg != null) { - JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), + JvOptionPane.showInternalMessageDialog(Desktop.desktop, warnmsg, warnttl, JvOptionPane.ERROR_MESSAGE); } @@ -2481,7 +2499,7 @@ public class Desktop extends GDesktop public JInternalFrame[] getAllFrames() { - return desktopPane.getAllFrames(); + return desktop.getAllFrames(); } /** @@ -2520,7 +2538,7 @@ public class Desktop extends GDesktop while (li.hasNext()) { String link = li.next(); - if (link.contains(UrlConstants.SEQUENCE_ID) + if (link.contains(jalview.util.UrlConstants.SEQUENCE_ID) && !UrlConstants.isDefaultString(link)) { check = true; @@ -2567,7 +2585,7 @@ public class Desktop extends GDesktop }); msgPanel.add(jcb); - JvOptionPane.showMessageDialog(desktopPane, msgPanel, + JvOptionPane.showMessageDialog(Desktop.desktop, msgPanel, MessageManager .getString("label.SEQUENCE_ID_no_longer_used"), JvOptionPane.WARNING_MESSAGE); @@ -2682,11 +2700,11 @@ public class Desktop extends GDesktop { if (Jalview.isHeadlessMode()) { - // Desktop.getDesktop() is null in headless mode - return new AlignFrame[] { Jalview.getCurrentAlignFrame() }; + // Desktop.desktop is null in headless mode + return new AlignFrame[] { Jalview.currentAlignFrame }; } - JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames(); + JInternalFrame[] frames = Desktop.desktop.getAllFrames(); if (frames == null) { @@ -2731,7 +2749,7 @@ public class Desktop extends GDesktop */ public GStructureViewer[] getJmols() { - JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames(); + JInternalFrame[] frames = Desktop.desktop.getAllFrames(); if (frames == null) { @@ -2767,7 +2785,7 @@ public class Desktop extends GDesktop } catch (Exception ex) { jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex); - JvOptionPane.showInternalMessageDialog(desktopPane, + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager.getString("label.couldnt_create_groovy_shell"), MessageManager.getString("label.groovy_support_failed"), @@ -2778,7 +2796,7 @@ public class Desktop extends GDesktop /** * Open the Groovy console */ - private void openGroovyConsole() + void openGroovyConsole() { if (groovyConsole == null) { @@ -2827,7 +2845,7 @@ public class Desktop extends GDesktop { getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, - Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()), "Quit"); getRootPane().getActionMap().put("Quit", new AbstractAction() { @@ -2886,18 +2904,18 @@ public class Desktop extends GDesktop progressBarHandlers = new Hashtable<>(); } - if (progressBars.get(new Long(id)) != null) + if (progressBars.get(Long.valueOf(id)) != null) { - JPanel panel = progressBars.remove(new Long(id)); - if (progressBarHandlers.contains(new Long(id))) + JPanel panel = progressBars.remove(Long.valueOf(id)); + if (progressBarHandlers.contains(Long.valueOf(id))) { - progressBarHandlers.remove(new Long(id)); + progressBarHandlers.remove(Long.valueOf(id)); } removeProgressPanel(panel); } else { - progressBars.put(new Long(id), addProgressPanel(message)); + progressBars.put(Long.valueOf(id), addProgressPanel(message)); } } @@ -2912,13 +2930,13 @@ public class Desktop extends GDesktop final IProgressIndicatorHandler handler) { if (progressBarHandlers == null - || !progressBars.containsKey(new Long(id))) + || !progressBars.containsKey(Long.valueOf(id))) { throw new Error(MessageManager.getString( "error.call_setprogressbar_before_registering_handler")); } - progressBarHandlers.put(new Long(id), handler); - final JPanel progressPanel = progressBars.get(new Long(id)); + progressBarHandlers.put(Long.valueOf(id), handler); + final JPanel progressPanel = progressBars.get(Long.valueOf(id)); if (handler.canCancel()) { JButton cancel = new JButton( @@ -2964,7 +2982,7 @@ public class Desktop extends GDesktop */ public static AlignFrame getAlignFrameFor(AlignViewportI viewport) { - if (getDesktopPane() != null) + if (desktop != null) { AlignmentPanel[] aps = getAlignmentPanels( viewport.getSequenceSetId()); @@ -3025,8 +3043,8 @@ public class Desktop extends GDesktop // todo: changesupport handlers need to be transferred if (discoverer == null) { - discoverer = Discoverer.getInstance(); - // register PCS handler for getDesktop(). + discoverer = new jalview.ws.jws1.Discoverer(); + // register PCS handler for desktop. discoverer.addPropertyChangeListener(changeSupport); } // JAL-940 - disabled JWS1 service configuration - always start discoverer @@ -3036,7 +3054,7 @@ public class Desktop extends GDesktop if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { - t2 = jalview.ws.jws2.Jws2Discoverer.getInstance() + t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() .startDiscoverer(changeSupport); } Thread t3 = null; @@ -3069,7 +3087,7 @@ public class Desktop extends GDesktop { if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector) { - final String ermsg = jalview.ws.jws2.Jws2Discoverer.getInstance() + final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() .getErrorMessages(); if (ermsg != null) { @@ -3108,7 +3126,7 @@ public class Desktop extends GDesktop * * jd.waitForInput(); */ - JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(), + JvOptionPane.showConfirmDialog(Desktop.desktop, new JLabel("
" + ermsg + "
" + "

It may be that you have invalid JABA URLs
in your web service preferences," @@ -3134,7 +3152,7 @@ public class Desktop extends GDesktop } } - Runnable serviceChangedDialog = null; + private Runnable serviceChangedDialog = null; /** * start a thread to open a URL in the configured browser. Pops up a warning @@ -3145,7 +3163,7 @@ public class Desktop extends GDesktop */ public static void showUrl(final String url) { - showUrl(url, Desktop.getInstance()); + showUrl(url, Desktop.instance); } /** @@ -3171,10 +3189,10 @@ public class Desktop extends GDesktop .formatMessage("status.opening_params", new Object[] { url }), this.hashCode()); } - BrowserLauncher.openURL(url); + jalview.util.BrowserLauncher.openURL(url); } catch (Exception ex) { - JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager .getString("label.web_browser_not_found_unix"), MessageManager.getString("label.web_browser_not_found"), @@ -3190,16 +3208,15 @@ public class Desktop extends GDesktop }).start(); } - private WsParamSetManager wsparamManager = null; + public static WsParamSetManager wsparamManager = null; public static ParamManager getUserParameterStore() { - Desktop d = Desktop.getInstance(); - if (d.wsparamManager == null) + if (wsparamManager == null) { - d.wsparamManager = new WsParamSetManager(); + wsparamManager = new WsParamSetManager(); } - return d.wsparamManager; + return wsparamManager; } /** @@ -3244,16 +3261,14 @@ public class Desktop extends GDesktop /** * flag indicating if dialogExecutor should try to acquire a permit */ - volatile boolean dialogPause = true; + private volatile boolean dialogPause = true; /** * pause the queue */ - java.util.concurrent.Semaphore block = new Semaphore(0); - - private groovy.ui.Console groovyConsole; + private java.util.concurrent.Semaphore block = new Semaphore(0); - public StructureViewer lastTargetedView; + private static groovy.ui.Console groovyConsole; /** * add another dialog thread to the queue @@ -3276,7 +3291,7 @@ public class Desktop extends GDesktop { } } - if (instanceOnly) + if (instance == null) { return; } @@ -3440,7 +3455,7 @@ public class Desktop extends GDesktop String topViewId = myTopFrame.viewport.getSequenceSetId(); String bottomViewId = myBottomFrame.viewport.getSequenceSetId(); - JInternalFrame[] frames = desktopPane.getAllFrames(); + JInternalFrame[] frames = desktop.getAllFrames(); for (JInternalFrame frame : frames) { if (frame instanceof SplitFrame && frame != source) @@ -3485,7 +3500,7 @@ public class Desktop extends GDesktop public static groovy.ui.Console getGroovyConsole() { - return Desktop.getInstance().groovyConsole; + return groovyConsole; } /** @@ -3503,7 +3518,6 @@ public class Desktop extends 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 @@ -3573,7 +3587,7 @@ public class Desktop extends GDesktop { // Works on Windows and MacOSX Cache.log.debug("Drop handled as javaFileListFlavor"); - for (Object file : (List) t + for (Object file : (List) t .getTransferData(DataFlavor.javaFileListFlavor)) { files.add(file); @@ -3737,7 +3751,7 @@ public class Desktop extends GDesktop Class structureViewerClass) { List result = new ArrayList<>(); - JInternalFrame[] frames = getAllFrames(); + JInternalFrame[] frames = Desktop.instance.getAllFrames(); for (JInternalFrame frame : frames) { @@ -3756,5 +3770,4 @@ public class Desktop extends GDesktop } return result; } - }