X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FDesktop.java;h=195a313056796b5f48d7780215b7bae01453f1a9;hb=3ffda7877bae6500636fcccaf1a9eae8bff2f45c;hp=21092e6216abe340031580387bf9b0307bf5689d;hpb=3cea8af5f3d2849ebe7062972c0865af1f86c5f7;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 21092e6..195a313 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,13 +48,16 @@ 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; import java.io.FileWriter; import java.io.IOException; +import java.lang.reflect.Field; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Hashtable; import java.util.List; @@ -114,6 +118,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; @@ -134,12 +139,35 @@ public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener, ClipboardOwner, IProgressIndicator, jalview.api.StructureSelectionManagerProvider { - private static final String CITATION = "

Development managed by The Barton Group, University of Dundee, Scotland, UK.
" - + "

For help, see the FAQ at www.jalview.org/faq and/or join the jalview-discuss@jalview.org mailing list" - + "

If you use Jalview, please cite:" - + "
Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)" - + "
Jalview Version 2 - a multiple sequence alignment editor and analysis workbench" - + "
Bioinformatics doi: 10.1093/bioinformatics/btp033"; + 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)); + boolean logo = (bg_logo_url != null || uod_logo_url != null); + StringBuilder sb = new StringBuilder(); + sb.append( + "

Development managed by The Barton Group, University of Dundee, Scotland, UK."); + if (logo) + { + sb.append("
"); + } + sb.append(bg_logo_url == null ? "" + : "\"Barton"); + sb.append(uod_logo_url == null ? "" + : " \"University"); + sb.append( + "

For help, see the FAQ at www.jalview.org/faq and/or join the jalview-discuss@jalview.org mailing list"); + sb.append("

If you use Jalview, please cite:" + + "
Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)" + + "
Jalview Version 2 - a multiple sequence alignment editor and analysis workbench" + + "
Bioinformatics doi: 10.1093/bioinformatics/btp033"); + CITATION = sb.toString(); + } private static final String DEFAULT_AUTHORS = "The Jalview Authors (See AUTHORS file for current list)"; @@ -159,6 +187,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,26 +394,65 @@ public class Desktop extends jalview.jbgui.GDesktop instance = this; doConfigureStructurePrefs(); - setTitle("Jalview " + Cache.getProperty("VERSION")); - /* - if (!Platform.isAMac()) - { - // this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - } - else + 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 sun.awt.X11.XToolkit.awtAppClassName + * which I don't think can be avoided. + */ + if (Platform.isLinux()) { - this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + try + { + Toolkit xToolkit = Toolkit.getDefaultToolkit(); + Field[] declaredFields = xToolkit.getClass().getDeclaredFields(); + Field awtAppClassNameField = null; + + if (Arrays.stream(declaredFields).anyMatch(f -> f.getName().equals("awtAppClassName"))) + { + awtAppClassNameField = xToolkit.getClass() + .getDeclaredField("awtAppClassName"); + } + + String title = ChannelProperties.getProperty("app_name"); + if (awtAppClassNameField != null) + { + awtAppClassNameField.setAccessible(true); + awtAppClassNameField.set(xToolkit, title); + } + else + { + Cache.log.debug("XToolkit: awtAppClassName not found"); + } + } catch (Exception e) + { + Cache.debug("Error setting awtAppClassName"); + Cache.trace(Cache.getStackTraceString(e)); + } } - */ + /** + * 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 (Throwable t) { - System.out.println("Error setting APQHandlers: " + t.toString()); - // t.printStackTrace(); + Cache.warn("Error setting APQHandlers: " + t.toString()); + Cache.trace(Cache.getStackTraceString(t)); } + setIconImages(ChannelProperties.getIconList()); addWindowListener(new WindowAdapter() { @@ -403,6 +472,8 @@ public class Desktop extends jalview.jbgui.GDesktop 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(); @@ -460,15 +531,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 @@ -533,7 +606,6 @@ public class Desktop extends jalview.jbgui.GDesktop } }); desktop.addMouseListener(ma); - } /** @@ -952,7 +1024,7 @@ public class Desktop extends jalview.jbgui.GDesktop } catch (java.lang.ClassCastException cex) { Cache.log.warn( - "Squashed a possible GUI implementation error. If you can recreate this, please look at http://issues.jalview.org/browse/JAL-869", + "Squashed a possible GUI implementation error. If you can recreate this, please look at https://issues.jalview.org/browse/JAL-869", cex); } } @@ -1159,12 +1231,12 @@ public class Desktop extends jalview.jbgui.GDesktop panel.add(label); /* - * the URL to fetch is + * the URL to fetch is input in * Java: an editable combobox with history * JS: (pending JAL-3038) a plain text field */ JComponent history; - String urlBase = "http://www."; + String urlBase = "https://www."; if (Platform.isJS()) { history = new JTextField(urlBase, 35); @@ -1202,8 +1274,8 @@ public class Desktop extends jalview.jbgui.GDesktop @SuppressWarnings("unchecked") String url = (history instanceof JTextField ? ((JTextField) history).getText() - : ((JComboBox) history).getSelectedItem() - .toString()); + : ((JComboBox) history).getEditor().getItem() + .toString().trim()); if (url.toLowerCase().endsWith(".jar")) { @@ -1358,7 +1430,8 @@ public class Desktop extends jalview.jbgui.GDesktop public String getAboutMessage() { StringBuilder message = new StringBuilder(1024); - message.append("

Version: ") + message.append("
") + .append("

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

") .append("Built: ") .append(Cache.getDefault("BUILD_DATE", "unknown")) @@ -1387,7 +1460,7 @@ public class Desktop extends jalview.jbgui.GDesktop .append(Cache.getDefault("LATEST_VERSION", "..Checking..")) .append(" is available for download from ") .append(Cache.getDefault("www.jalview.org", - "http://www.jalview.org")) + "https://www.jalview.org")) .append(" !!"); if (red) { @@ -1398,6 +1471,8 @@ public class Desktop extends jalview.jbgui.GDesktop message.append(Cache.getDefault("AUTHORFNAMES", DEFAULT_AUTHORS)); message.append(CITATION); + message.append("
"); + return message.toString(); } @@ -1411,7 +1486,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (Platform.isJS()) { - BrowserLauncher.openURL("http://www.jalview.org/help.html"); + BrowserLauncher.openURL("https://www.jalview.org/help.html"); } else /** @@ -2278,6 +2353,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()); } } @@ -3367,4 +3445,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)); + } + } }