X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=85ec3aecf2c5b616c88a8e7e80522f6a69f42be2;hb=cb51e62fe2166b236ef488e0a8f35081fcd71388;hp=bc892cf134ec20d1a20b5523144f6b7d389d50f6;hpb=d82d17a7ba88f90e6b8b1b591245a7ee70b3975c;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index bc892cf..85ec3aecf 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -199,13 +199,14 @@ public class Desktop extends GDesktop public static MyDesktopPane getDesktopPane() { - return Desktop.getInstance().desktopPane; + Desktop desktop = Desktop.getInstance(); + return desktop == null ? null : desktop.desktopPane; } - public StructureSelectionManager getStructureSelectionManager() + public static StructureSelectionManager getStructureSelectionManager() { return StructureSelectionManager - .getStructureSelectionManager(this); + .getStructureSelectionManager(getInstance()); } static int openFrameCount = 0; @@ -222,10 +223,24 @@ public class Desktop extends GDesktop private static int fileLoadingCount = 0; - public JInternalFrame conservationSlider, PIDSlider; + public JInternalFrame conservationSlider; + + public JInternalFrame PIDSlider; /** * just an instance (for testng, probably); no actual frames + * + * This flag, when set true, allows a headless-like operation, with a Desktop + * object but no actual frames. The issue has to do with the mess-up of the + * Windows JInternalFrame implementation, which surreptitiously and + * unforgivingly accesses a native peer class, preventing headless operation. + * + * It is set by invoking the Desktop(true) constructor. + * + * It is possible that we can remove this option now, since headless mode is + * finally working on Windows through careful attention to not creating any + * JInternalFrame objects when in that mode. + * */ private boolean instanceOnly; @@ -363,17 +378,24 @@ public class Desktop extends GDesktop */ public static Desktop getInstance() { - return (Desktop) ApplicationSingletonProvider - .getInstance(Desktop.class); + return Jalview.isHeadlessMode() ? null + : (Desktop) ApplicationSingletonProvider + .getInstance(Desktop.class); } /** - * For testing. + * For testing purposes, this constructor can be utilized to allow the creation + * of a singleton Desktop instance without the formation of frames. The Cache is + * initialized, but that is all. + * + * It is not currently used. * * @param forInstance */ public Desktop(boolean forInstance) { + + Cache.initLogger(); instanceOnly = true; } @@ -384,171 +406,187 @@ public class Desktop extends GDesktop @SuppressWarnings("unused") private Desktop() { - /** - * 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. - */ - if (!Platform.isJS()) - { - doVamsasClientCheck(); - } - - doConfigureStructurePrefs(); - setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION")); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE", - false); - boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE", - false); - desktopPane = new MyDesktopPane(selmemusage); - - 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); - - // 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); - - // 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()))); - - 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); - } - - if (!Platform.isJS()) - /** - * Java only - * - * @j2sIgnore - */ + Cache.initLogger(); + try { - - jconsole = new Console(this, showjconsole); - // add essential build information - jconsole.setHeader("Jalview Version: " - + jalview.bin.Cache.getProperty("VERSION") + "\n" - + "Jalview Installation: " - + jalview.bin.Cache.getDefault("INSTALLATION", "unknown") - + "\n" + "Build Date: " - + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n" - + "Java version: " + System.getProperty("java.version") + "\n" - + System.getProperty("os.arch") + " " - + System.getProperty("os.name") + " " - + System.getProperty("os.version")); - - showConsole(showjconsole); - - showNews.setVisible(false); - - experimentalFeatures.setSelected(showExperimental()); - - getIdentifiersOrgData(); - - checkURLLinks(); - - // Spawn a thread that shows the splashscreen - - SwingUtilities.invokeLater(new Runnable() + /** + * 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. + */ + if (!Platform.isJS()) { - @Override - public void run() - { - new SplashScreen(); - } - }); - - // Thread off a new instance of the file chooser - this reduces the time - // it - // takes to open it later on. - new Thread(new Runnable() + doVamsasClientCheck(); + } + + doConfigureStructurePrefs(); + setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION")); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE", + false); + boolean showjconsole = jalview.bin.Cache + .getDefault("SHOW_JAVA_CONSOLE", false); + desktopPane = new MyDesktopPane(selmemusage); + + 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); + + // BH 2018 - just an experiment to try unclipped JInternalFrames. + if (Platform.isJS()) { - @Override - public void run() + getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); + } + + 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 + desktopPane.setDesktopManager(new MyDesktopManager( + (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager() + : Platform.isAMacAndNotJS() + ? new AquaInternalFrameManager( + desktopPane.getDesktopManager()) + : desktopPane.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); + } + + // Note that this next syntax, checking for Platform.isJS and also + // escaping the code using @j2sIgnore, serves two purposes. It gives + // us an easily findable tag, Platform.isJS(), to places in the code where + // there is something different about the SwingJS implementation. Second, + // it deletes the unneeded Java-only code form the JavaScript version + // completely (@j2sIgnore), since it will never be used there. + + if (!Platform.isJS()) + /** + * Java only + * + * @j2sIgnore + */ + { + + jconsole = new Console(this, showjconsole); + // add essential build information + jconsole.setHeader("Jalview Version: " + + jalview.bin.Cache.getProperty("VERSION") + "\n" + + "Jalview Installation: " + + jalview.bin.Cache.getDefault("INSTALLATION", "unknown") + + "\n" + "Build Date: " + + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + + "\n" + "Java version: " + + System.getProperty("java.version") + "\n" + + System.getProperty("os.arch") + " " + + System.getProperty("os.name") + " " + + System.getProperty("os.version")); + + showConsole(showjconsole); + + showNews.setVisible(false); + + experimentalFeatures.setSelected(showExperimental()); + + getIdentifiersOrgData(); + + checkURLLinks(); + + // Spawn a thread that shows the splashscreen + + SwingUtilities.invokeLater(new Runnable() { - Cache.log.debug("Filechooser init thread started."); - String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); - JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), - fileFormat); - Cache.log.debug("Filechooser init thread finished."); - } - }).start(); - // Add the service change listener - changeSupport.addJalviewPropertyChangeListener("services", - new PropertyChangeListener() - { - - @Override - public void propertyChange(PropertyChangeEvent evt) + @Override + public void run() + { + new SplashScreen(); + } + }); + + // Thread off a new instance of the file chooser - this reduces the time + // it + // takes to open it later on. + new Thread(new Runnable() + { + @Override + public void run() + { + Cache.log.debug("Filechooser init thread started."); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), + fileFormat); + Cache.log.debug("Filechooser init thread finished."); + } + }).start(); + // Add the service change listener + changeSupport.addJalviewPropertyChangeListener("services", + new PropertyChangeListener() { - Cache.log.debug("Firing service changed event for " - + evt.getNewValue()); - JalviewServicesChanged(evt); - } - - }); - - } - - this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); - - this.addWindowListener(new WindowAdapter() - { - @Override - public void windowClosing(WindowEvent evt) - { - quit(); + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + Cache.log.debug("Firing service changed event for " + + evt.getNewValue()); + JalviewServicesChanged(evt); + } + + }); + } - }); - - MouseAdapter ma; - this.addMouseListener(ma = new MouseAdapter() - { - @Override - public void mousePressed(MouseEvent evt) + + this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); + + this.addWindowListener(new WindowAdapter() { - if (evt.isPopupTrigger()) // Mac + @Override + public void windowClosing(WindowEvent evt) { - showPasteMenu(evt.getX(), evt.getY()); + quit(); } - } - - @Override - public void mouseReleased(MouseEvent evt) + }); + + MouseAdapter ma; + this.addMouseListener(ma = new MouseAdapter() { - if (evt.isPopupTrigger()) // Windows + @Override + public void mousePressed(MouseEvent evt) { - showPasteMenu(evt.getX(), evt.getY()); + if (evt.isPopupTrigger()) // Mac + { + showPasteMenu(evt.getX(), evt.getY()); + } } - } - }); - desktopPane.addMouseListener(ma); + + @Override + public void mouseReleased(MouseEvent evt) + { + if (evt.isPopupTrigger()) // Windows + { + showPasteMenu(evt.getX(), evt.getY()); + } + } + }); + desktopPane.addMouseListener(ma); + } catch (Throwable t) + { + t.printStackTrace(); + } } /** @@ -567,7 +605,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 @@ -880,13 +919,14 @@ public class Desktop extends GDesktop int w, int h, boolean resizable, boolean ignoreMinSize) { + // TODO: allow callers to determine X and Y position of frame (eg. via // bounds object). // TODO: consider fixing method to update entries in the window submenu with // the current window title frame.setTitle(title); - if (frame.getWidth() < 1 || frame.getHeight() < 1) + if (w > 0 && (frame.getWidth() < 1 || frame.getHeight() < 1)) { frame.setSize(w, h); } @@ -894,7 +934,7 @@ 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 (Jalview.isHeadlessMode() || Desktop.getInstance().instanceOnly) { return; } @@ -924,7 +964,8 @@ public class Desktop extends GDesktop frame.setIconifiable(resizable); frame.setOpaque(Platform.isJS()); - if (frame.getX() < 1 && frame.getY() < 1) + boolean isEmbedded = (Platform.getDimIfEmbedded(frame, -1, -1) != null); + if (!isEmbedded && frame.getX() < 1 && frame.getY() < 1) { frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount - 1) % 10) + yOffset); @@ -3485,7 +3526,8 @@ public class Desktop extends GDesktop public static groovy.ui.Console getGroovyConsole() { - return Desktop.getInstance().groovyConsole; + Desktop desktop = Desktop.getInstance(); + return desktop == null ? null : desktop.groovyConsole; } /**