X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=0f5a931bd037b4427162b3bbc57c656033bfc82d;hb=b6f8ec5c6678d0f363c521b97bda9574d04c6338;hp=59541bb1f66e5562e81919850a25452778ab790c;hpb=2e10281fc7181b019c7885a516cc743574403a43;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 59541bb..0f5a931 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -25,6 +25,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Point; import java.awt.Rectangle; @@ -47,6 +48,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.geom.AffineTransform; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; @@ -114,6 +116,7 @@ import jalview.project.Jalview2XML; import jalview.structure.StructureSelectionManager; import jalview.urls.IdOrgSettings; import jalview.util.BrowserLauncher; +import jalview.util.ChannelProperties; import jalview.util.ImageMaker.TYPE; import jalview.util.MessageManager; import jalview.util.Platform; @@ -159,6 +162,8 @@ public class Desktop extends jalview.jbgui.GDesktop private JalviewChangeSupport changeSupport = new JalviewChangeSupport(); + public static boolean nosplash = false; + /** * news reader - null if it was never started. */ @@ -364,7 +369,8 @@ public class Desktop extends jalview.jbgui.GDesktop instance = this; doConfigureStructurePrefs(); - setTitle("Jalview " + Cache.getProperty("VERSION")); + setTitle(ChannelProperties.getProperty("app_name") + " " + + Cache.getProperty("VERSION")); /* if (!Platform.isAMac()) { @@ -384,6 +390,7 @@ public class Desktop extends jalview.jbgui.GDesktop System.out.println("Error setting APQHandlers: " + t.toString()); // t.printStackTrace(); } + setIconImages(ChannelProperties.getIconList()); addWindowListener(new WindowAdapter() { @@ -395,16 +402,16 @@ public class Desktop extends jalview.jbgui.GDesktop } }); - boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", - false); + boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false); - boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", - false); + boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false); desktop = new MyDesktopPane(selmemusage); showMemusage.setSelected(selmemusage); desktop.setBackground(Color.white); + this.setIconImages(ChannelProperties.getIconList()); + getContentPane().setLayout(new BorderLayout()); // alternate config - have scrollbars - see notes in JAL-153 // JScrollPane sp = new JScrollPane(); @@ -462,15 +469,17 @@ public class Desktop extends jalview.jbgui.GDesktop checkURLLinks(); // Spawn a thread that shows the splashscreen - - SwingUtilities.invokeLater(new Runnable() + if (!nosplash) { - @Override - public void run() + SwingUtilities.invokeLater(new Runnable() { - new SplashScreen(true); - } - }); + @Override + public void run() + { + new SplashScreen(true); + } + }); + } // Thread off a new instance of the file chooser - this reduces the time // it @@ -535,7 +544,6 @@ public class Desktop extends jalview.jbgui.GDesktop } }); desktop.addMouseListener(ma); - } /** @@ -558,10 +566,10 @@ public class Desktop extends jalview.jbgui.GDesktop .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)); + ssm.setAddTempFacAnnot( + Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true)); + ssm.setProcessSecondaryStructure( + Cache.getDefault(Preferences.STRUCT_FROM_PDB, true)); ssm.setSecStructServices( Cache.getDefault(Preferences.USE_RNAVIEW, true)); } @@ -610,7 +618,7 @@ public class Desktop extends jalview.jbgui.GDesktop } } }).start(); - + } @Override @@ -655,10 +663,8 @@ public class Desktop extends jalview.jbgui.GDesktop Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); String x = Cache.getProperty(windowName + "SCREEN_X"); String y = Cache.getProperty(windowName + "SCREEN_Y"); - String width = Cache - .getProperty(windowName + "SCREEN_WIDTH"); - String height = Cache - .getProperty(windowName + "SCREEN_HEIGHT"); + 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), @@ -668,10 +674,10 @@ public class Desktop extends jalview.jbgui.GDesktop // 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); @@ -962,8 +968,8 @@ public class Desktop extends jalview.jbgui.GDesktop } /** - * Add key bindings to a JInternalFrame so that Ctrl-W and Cmd-W will close the - * window + * Add key bindings to a JInternalFrame so that Ctrl-W and Cmd-W will close + * the window * * @param frame */ @@ -1103,8 +1109,9 @@ public class Desktop extends jalview.jbgui.GDesktop public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport) { String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); - JalviewFileChooser chooser = JalviewFileChooser - .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, BackupFiles.getEnabled()); + JalviewFileChooser chooser = JalviewFileChooser.forRead( + Cache.getProperty("LAST_DIRECTORY"), fileFormat, + BackupFiles.getEnabled()); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( @@ -1290,10 +1297,8 @@ public class Desktop extends jalview.jbgui.GDesktop public void quit() { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - Cache.setProperty("SCREENGEOMETRY_WIDTH", - screen.width + ""); - Cache.setProperty("SCREENGEOMETRY_HEIGHT", - screen.height + ""); + Cache.setProperty("SCREENGEOMETRY_WIDTH", screen.width + ""); + Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height + ""); storeLastKnownDimensions("", new Rectangle(getBounds().x, getBounds().y, getWidth(), getHeight())); @@ -1324,9 +1329,9 @@ public class Desktop extends jalview.jbgui.GDesktop private void storeLastKnownDimensions(String string, Rectangle jc) { - Cache.log.debug("Storing last known dimensions for " - + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width - + " height:" + jc.height); + Cache.log.debug("Storing last known dimensions for " + string + ": x:" + + jc.x + " y:" + jc.y + " width:" + jc.width + " height:" + + jc.height); Cache.setProperty(string + "SCREEN_X", jc.x + ""); Cache.setProperty(string + "SCREEN_Y", jc.y + ""); @@ -1625,7 +1630,7 @@ public class Desktop extends jalview.jbgui.GDesktop @Override protected void preferences_actionPerformed(ActionEvent e) { - new Preferences(); + Preferences.openPreferences(); } /** @@ -1681,16 +1686,17 @@ public class Desktop extends jalview.jbgui.GDesktop setProgressBar(MessageManager.formatMessage( "label.saving_jalview_project", new Object[] { chosenFile.getName() }), chosenFile.hashCode()); - Cache.setProperty("LAST_DIRECTORY", - chosenFile.getParent()); + Cache.setProperty("LAST_DIRECTORY", chosenFile.getParent()); // TODO catch and handle errors for savestate // TODO prevent user from messing with the Desktop whilst we're saving try { - boolean doBackup = BackupFiles.getEnabled(); - BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile) : null; + boolean doBackup = BackupFiles.getEnabled(); + BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile) + : null; - new Jalview2XML().saveState(doBackup ? backupfiles.getTempFile() : chosenFile); + new Jalview2XML().saveState( + doBackup ? backupfiles.getTempFile() : chosenFile); if (doBackup) { @@ -1716,7 +1722,7 @@ public class Desktop extends jalview.jbgui.GDesktop setProgressBar(null, chosenFile.hashCode()); } }).start(); - } + } } @Override @@ -1747,8 +1753,10 @@ public class Desktop extends jalview.jbgui.GDesktop "Jalview Project (old)" }; JalviewFileChooser chooser = new JalviewFileChooser( Cache.getProperty("LAST_DIRECTORY"), suffix, desc, - "Jalview Project", true, BackupFiles.getEnabled()); // last two booleans: allFiles, - // allowBackupFiles + "Jalview Project", true, BackupFiles.getEnabled()); // last two + // booleans: + // allFiles, + // allowBackupFiles chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.restore_state")); chooser.setResponseHandler(0, new Runnable() @@ -1765,29 +1773,30 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void run() { - try + try { new Jalview2XML().loadJalviewAlign(selectedFile); } catch (OutOfMemoryError oom) - { - new OOMWarning("Whilst loading project from " + choice, oom); - } catch (Exception ex) - { - Cache.log.error( - "Problems whilst loading project from " + choice, ex); - JvOptionPane.showMessageDialog(Desktop.desktop, - MessageManager.formatMessage( - "label.error_whilst_loading_project_from", - new Object[] - { choice }), - MessageManager.getString("label.couldnt_load_project"), - JvOptionPane.WARNING_MESSAGE); - } + { + new OOMWarning("Whilst loading project from " + choice, oom); + } catch (Exception ex) + { + Cache.log.error( + "Problems whilst loading project from " + choice, ex); + JvOptionPane.showMessageDialog(Desktop.desktop, + MessageManager.formatMessage( + "label.error_whilst_loading_project_from", + new Object[] + { choice }), + MessageManager + .getString("label.couldnt_load_project"), + JvOptionPane.WARNING_MESSAGE); + } } - }).start(); + }, "Project Loader").start(); } }); - + chooser.showOpenDialog(this); } @@ -1976,9 +1985,7 @@ public class Desktop extends jalview.jbgui.GDesktop // FIXME: ideally should use UI interface API FeatureSettings viewFeatureSettings = (af.featureSettings != null - && af.featureSettings.isOpen()) - ? af.featureSettings - : null; + && af.featureSettings.isOpen()) ? af.featureSettings : null; Rectangle fsBounds = af.getFeatureSettingsGeometry(); for (int i = 0; i < size; i++) { @@ -2011,7 +2018,8 @@ public class Desktop extends jalview.jbgui.GDesktop addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); - // and materialise a new feature settings dialog instance for the new alignframe + // and materialise a new feature settings dialog instance for the new + // alignframe // (closes the old as if 'OK' was pressed) if (ap == af.alignPanel && newaf.featureSettings != null && newaf.featureSettings.isOpen() @@ -2029,9 +2037,9 @@ public class Desktop extends jalview.jbgui.GDesktop /** * Gather expanded views (separate AlignFrame's) with the same sequence set - * identifier back in to this frame as additional views, and close the expanded - * views. Note the expanded frames may themselves have multiple views. We take - * the lot. + * identifier back in to this frame as additional views, and close the + * expanded views. Note the expanded frames may themselves have multiple + * views. We take the lot. * * @param source */ @@ -2083,8 +2091,7 @@ public class Desktop extends jalview.jbgui.GDesktop } // refresh the feature setting UI for the source frame if it exists - if (source.featureSettings != null - && source.featureSettings.isOpen()) + if (source.featureSettings != null && source.featureSettings.isOpen()) { source.showFeatureSettingsUI(); } @@ -2189,12 +2196,12 @@ public class Desktop extends jalview.jbgui.GDesktop /** * Proxy class for JDesktopPane which optionally displays the current memory - * usage and highlights the desktop area with a red bar if free memory runs low. + * usage and highlights the desktop area with a red bar if free memory runs + * low. * * @author AMW */ - public class MyDesktopPane extends JDesktopPane - implements Runnable + public class MyDesktopPane extends JDesktopPane implements Runnable { private static final float ONE_MB = 1048576f; @@ -2281,6 +2288,9 @@ public class Desktop extends jalview.jbgui.GDesktop 10, getHeight() - fm.getHeight()); } } + + // output debug scale message. Important for jalview.bin.HiDPISettingTest2 + Desktop.debugScaleMessage(Desktop.getDesktop().getGraphics()); } } @@ -2431,14 +2441,17 @@ public class Desktop extends jalview.jbgui.GDesktop } /** - * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this binding - * when opened + * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this + * binding when opened */ 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, + jalview.util.ShortcutKeyMaskExWrapper + .getMenuShortcutKeyMaskEx()), "Quit"); getRootPane().getActionMap().put("Quit", new AbstractAction() { @@ -2567,8 +2580,9 @@ public class Desktop extends jalview.jbgui.GDesktop } /** - * This will return the first AlignFrame holding the given viewport instance. It - * will break if there are more than one AlignFrames viewing a particular av. + * This will return the first AlignFrame holding the given viewport instance. + * It will break if there are more than one AlignFrames viewing a particular + * av. * * @param viewport * @return alignFrame for viewport @@ -2945,8 +2959,8 @@ public class Desktop extends jalview.jbgui.GDesktop /** * Explode the views in the given SplitFrame into separate SplitFrame windows. - * This respects (remembers) any previous 'exploded geometry' i.e. the size and - * location last time the view was expanded (if any). However it does not + * This respects (remembers) any previous 'exploded geometry' i.e. the size + * and location last time the view was expanded (if any). However it does not * remember the split pane divider location - this is set to match the * 'exploding' frame. * @@ -3117,7 +3131,8 @@ public class Desktop extends jalview.jbgui.GDesktop Transferable t) throws Exception { - // BH 2018 changed List to List to allow for File from SwingJS + // BH 2018 changed List to List to allow for File from + // SwingJS // DataFlavor[] flavors = t.getTransferDataFlavors(); // for (int i = 0; i < flavors.length; i++) { @@ -3129,7 +3144,8 @@ public class Desktop extends jalview.jbgui.GDesktop // byte[] data = getDroppedFileBytes(file); // fileName.setText(file.getName() + " - " + data.length + " " + // evt.getLocation()); - // JTextArea target = (JTextArea) ((DropTarget) evt.getSource()).getComponent(); + // JTextArea target = (JTextArea) ((DropTarget) + // evt.getSource()).getComponent(); // target.setText(new String(data)); // } // dtde.dropComplete(true); @@ -3329,10 +3345,10 @@ public class Desktop extends jalview.jbgui.GDesktop } /** - * Answers a (possibly empty) list of any structure viewer frames (currently for - * either Jmol or Chimera) which are currently open. This may optionally be - * restricted to viewers of a specified class, or viewers linked to a specified - * alignment panel. + * Answers a (possibly empty) list of any structure viewer frames (currently + * for either Jmol or Chimera) which are currently open. This may optionally + * be restricted to viewers of a specified class, or viewers linked to a + * specified alignment panel. * * @param apanel * if not null, only return viewers linked to this panel @@ -3364,4 +3380,37 @@ public class Desktop extends jalview.jbgui.GDesktop } return result; } + + public static final String debugScaleMessage = "Desktop graphics transform scale="; + + private static boolean debugScaleMessageDone = false; + + public static void debugScaleMessage(Graphics g) + { + if (debugScaleMessageDone) + { + return; + } + // output used by tests to check HiDPI scaling settings in action + try + { + Graphics2D gg = (Graphics2D) g; + if (gg != null) + { + AffineTransform t = gg.getTransform(); + double scaleX = t.getScaleX(); + double scaleY = t.getScaleY(); + Cache.debug(debugScaleMessage + scaleX + " (X)"); + Cache.debug(debugScaleMessage + scaleY + " (Y)"); + debugScaleMessageDone = true; + } + else + { + Cache.debug("Desktop graphics null"); + } + } catch (Exception e) + { + Cache.debug(Cache.getStackTraceString(e)); + } + } }