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=f35a6a890366d42e77854fac5452aa0906ed6e4d;hpb=49db0dff1da16c3355b43a41498c1fc93ef47e91;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index f35a6a8..b125cc2 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -119,6 +119,7 @@ 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; @@ -128,9 +129,9 @@ import jalview.urls.IdOrgSettings; import jalview.util.BrowserLauncher; import jalview.util.ChannelProperties; 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; @@ -156,19 +157,21 @@ public class Desktop extends GDesktop 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( + "

Jalview is free software released under GPLv3.

Development is 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"); + "

For help, see www.jalview.org/faq and join discourse.jalview.org"); 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"); + + "
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(); } @@ -184,7 +187,7 @@ public class Desktop extends GDesktop private static final String EXPERIMENTAL_FEATURES = "EXPERIMENTAL_FEATURES"; - protected static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT"; + public static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT"; public static HashMap savingFiles = new HashMap(); @@ -192,6 +195,7 @@ public class Desktop extends GDesktop private JalviewChangeSupport changeSupport = new JalviewChangeSupport(); public static boolean nosplash = false; + /** * news reader - null if it was never started. */ @@ -409,7 +413,6 @@ public class Desktop extends GDesktop private Desktop() { super(); - Cache.initLogger(); try { /** @@ -433,8 +436,15 @@ public class Desktop extends GDesktop * 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()) { - try { + if (Platform.isLinux()) + { + if (LaunchUtils.getJavaVersion() >= 11) + { + jalview.bin.Console.info( + "Linux platform only! You may have the following warning next: \"WARNING: An illegal reflective access operation has occurred\"\nThis is expected and cannot be avoided, sorry about that."); + } + try + { Toolkit xToolkit = Toolkit.getDefaultToolkit(); Field[] declaredFields = xToolkit.getClass().getDeclaredFields(); Field awtAppClassNameField = null; @@ -447,12 +457,15 @@ public class Desktop extends GDesktop 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)); + else + { + jalview.bin.Console.debug("XToolkit: awtAppClassName not found"); + } + } catch (Exception e) + { + jalview.bin.Console.debug("Error setting awtAppClassName"); + jalview.bin.Console.trace(Cache.getStackTraceString(e)); } } @@ -467,9 +480,10 @@ public class Desktop extends GDesktop System.out.println("Cannot set APQHandlers"); // e.printStackTrace(); } catch (Throwable t) { - Cache.warn("Error setting APQHandlers: " + t.toString()); - Cache.trace(Cache.getStackTraceString(t)); + jalview.bin.Console.warn("Error setting APQHandlers: " + t.toString()); + jalview.bin.Console.trace(Cache.getStackTraceString(t)); } + setIconImages(ChannelProperties.getIconList()); addWindowListener(new WindowAdapter() { @@ -570,11 +584,11 @@ public class Desktop extends GDesktop @Override public void run() { - Cache.log.debug("Filechooser init thread started."); + jalview.bin.Console.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."); + jalview.bin.Console.debug("Filechooser init thread finished."); } }).start(); // Add the service change listener @@ -585,7 +599,7 @@ public class Desktop extends GDesktop @Override public void propertyChange(PropertyChangeEvent evt) { - Cache.log.debug("Firing service changed event for " + jalview.bin.Console.debug("Firing service changed event for " + evt.getNewValue()); JalviewServicesChanged(evt); } @@ -629,7 +643,6 @@ public class Desktop extends GDesktop { t.printStackTrace(); } - } /** @@ -666,11 +679,12 @@ public class Desktop extends GDesktop // Thread off the news reader, in case there are connection problems. new Thread(new Runnable() { @Override - public void run() { - Cache.log.debug("Starting news thread."); + public void run() + { + jalview.bin.Console.debug("Starting news thread."); jvnews = new BlogReader(me); showNews.setVisible(true); - Cache.log.debug("Completed news thread."); + jalview.bin.Console.debug("Completed news thread."); } }).start(); } @@ -680,12 +694,17 @@ public class Desktop extends GDesktop // Thread off the identifiers fetcher new Thread(new Runnable() { @Override - public void run() { - Cache.log.debug("Downloading data from identifiers.org"); - try { - UrlDownloadClient.download(IdOrgSettings.getUrl(), IdOrgSettings.getDownloadLocation()); - } catch (IOException e) { - Cache.log.debug("Exception downloading identifiers.org data" + e.getMessage()); + public void run() + { + 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" + + e.getMessage()); } } }).start(); @@ -699,7 +718,7 @@ public class Desktop extends GDesktop void showNews(boolean visible) { - Cache.log.debug((visible ? "Showing" : "Hiding") + " news."); + jalview.bin.Console.debug((visible ? "Showing" : "Hiding") + " news."); showNews.setSelected(visible); if (visible && !jvnews.isVisible()) { @@ -749,16 +768,21 @@ public class Desktop extends GDesktop iw = (int) (iw * sw); iy = (int) (iy * sh); ih = (int) (ih * sh); - while (ix >= screenSize.width) { - Cache.log.debug("Window geometry location recall error: shifting horizontal to within screenbounds."); + while (ix >= screenSize.width) + { + jalview.bin.Console.debug( + "Window geometry location recall error: shifting horizontal to within screenbounds."); ix -= screenSize.width; } - while (iy >= screenSize.height) { - Cache.log.debug("Window geometry location recall error: shifting vertical to within screenbounds."); + while (iy >= screenSize.height) + { + jalview.bin.Console.debug( + "Window geometry location recall error: shifting vertical to within screenbounds."); iy -= screenSize.height; } - Cache.log.debug("Got last known dimensions for " + windowName + ": x:" + ix + " y:" + iy + " width:" + iw - + " height:" + ih); + jalview.bin.Console.debug( + "Got last known dimensions for " + windowName + ": x:" + ix + + " y:" + iy + " width:" + iw + " height:" + ih); } // return dimensions for new instance return new Rectangle(ix, iy, iw, ih); @@ -991,6 +1015,7 @@ public class Desktop extends GDesktop } catch (java.beans.PropertyVetoException ex) { // System.err.println(ex.toString()); + } } }); @@ -1010,8 +1035,8 @@ public class Desktop extends 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", + jalview.bin.Console.warn( + "Squashed a possible GUI implementation error. If you can recreate this, please look at https://issues.jalview.org/browse/JAL-869", cex); } } @@ -1024,6 +1049,7 @@ public class Desktop extends GDesktop */ private static void setKeyBindings(JInternalFrame frame) { + @SuppressWarnings("serial") final Action closeAction = new AbstractAction() { @Override @@ -1037,7 +1063,7 @@ public class Desktop extends 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 cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, Platform.SHORTCUT_KEY_MASK); InputMap inputMap = frame .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); @@ -1220,7 +1246,7 @@ public class Desktop extends GDesktop * 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); @@ -1366,9 +1392,9 @@ public class Desktop extends 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); + jalview.bin.Console.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 + ""); @@ -1435,6 +1461,7 @@ public class Desktop extends GDesktop message.append(CITATION); message.append(""); + return message.toString(); } @@ -1516,9 +1543,9 @@ public class Desktop extends GDesktop protected void garbageCollect_actionPerformed(ActionEvent e) { // We simply collect the garbage - Cache.log.debug("Collecting garbage..."); + jalview.bin.Console.debug("Collecting garbage..."); System.gc(); - Cache.log.debug("Finished garbage collection."); + jalview.bin.Console.debug("Finished garbage collection."); } /* @@ -1694,6 +1721,7 @@ public class Desktop extends GDesktop approveSave = true; } } + if (approveSave || autoSave) { final Desktop me = this; final java.io.File chosenFile = projectFile; @@ -1729,7 +1757,7 @@ public class Desktop extends GDesktop + chosenFile.getName(), oom); } catch (Exception ex) { - Cache.log.error("Problems whilst trying to save to " + jalview.bin.Console.error("Problems whilst trying to save to " + chosenFile.getName(), ex); JvOptionPane.showMessageDialog(me, MessageManager.formatMessage( @@ -1801,7 +1829,7 @@ public class Desktop extends GDesktop new OOMWarning("Whilst loading project from " + choice, oom); } catch (Exception ex) { - Cache.log.error( + jalview.bin.Console.error( "Problems whilst loading project from " + choice, ex); JvOptionPane.showMessageDialog(getDesktopPane(), MessageManager.formatMessage( @@ -1816,6 +1844,7 @@ public class Desktop extends GDesktop }, "Project Loader").start(); } }); + chooser.showOpenDialog(this); } @@ -2114,6 +2143,7 @@ public class Desktop extends GDesktop { source.showFeatureSettingsUI(); } + } public JInternalFrame[] getAllFrames() @@ -2307,8 +2337,9 @@ public class Desktop extends GDesktop 10, getHeight() - fm.getHeight()); } } + // output debug scale message. Important for jalview.bin.HiDPISettingTest2 - Desktop.debugScaleMessage(Desktop.getDesktop().getGraphics()); + Desktop.debugScaleMessage(Desktop.getDesktopPane().getGraphics()); } } @@ -2404,7 +2435,7 @@ public class Desktop extends GDesktop openGroovyConsole(); } catch (Exception ex) { - Cache.log.error("Groovy Shell Creation failed.", ex); + jalview.bin.Console.error("Groovy Shell Creation failed.", ex); JvOptionPane.showInternalMessageDialog(desktopPane, MessageManager.getString("label.couldnt_create_groovy_shell"), @@ -2658,14 +2689,23 @@ public class Desktop extends GDesktop this.inBatchMode = inBatchMode; } + /** + * start service discovery and wait till it is done + */ public void startServiceDiscovery() { startServiceDiscovery(false); } + /** + * start service discovery threads - blocking or non-blocking + * + * @param blocking + */ public void startServiceDiscovery(boolean blocking) { - System.out.println("Starting service discovery"); + jalview.bin.Console.debug("Starting service discovery"); + var tasks = new ArrayList>(); // JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release @@ -2778,7 +2818,7 @@ public class Desktop extends GDesktop } else { - Cache.log.error( + jalview.bin.Console.error( "Errors reported by JABA discovery service. Check web services preferences.\n" + ermsg); } @@ -2871,15 +2911,8 @@ public class Desktop extends GDesktop { if (url != null) { - if (Cache.log != null) - { - Cache.log.error("Couldn't handle string " + url + " as a URL."); - } - else - { - System.err.println( - "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. } @@ -2934,7 +2967,7 @@ public class Desktop extends GDesktop SwingUtilities.invokeAndWait(prompter); } catch (Exception q) { - Cache.log.warn("Unexpected Exception in dialog thread.", q); + jalview.bin.Console.warn("Unexpected Exception in dialog thread.", q); } } }); @@ -2973,7 +3006,7 @@ public class Desktop extends GDesktop public void exportImage(Graphics g) throws Exception { paintAll(g); - Cache.log.info("Successfully written snapshot to file " + jalview.bin.Console.info("Successfully written snapshot to file " + of.getAbsolutePath()); } }; @@ -3188,7 +3221,8 @@ public class Desktop extends GDesktop "application/x-java-url; class=java.net.URL"); } catch (ClassNotFoundException cfe) { - Cache.log.debug("Couldn't instantiate the URL dataflavor.", cfe); + jalview.bin.Console.debug("Couldn't instantiate the URL dataflavor.", + cfe); } if (urlFlavour != null && t.isDataFlavorSupported(urlFlavour)) @@ -3203,7 +3237,7 @@ public class Desktop extends GDesktop { protocols.add(DataSourceType.URL); files.add(url.toString()); - Cache.log.debug("Drop handled as URL dataflavor " + jalview.bin.Console.debug("Drop handled as URL dataflavor " + files.get(files.size() - 1)); return; } @@ -3217,13 +3251,13 @@ public class Desktop extends GDesktop } } catch (Throwable ex) { - Cache.log.debug("URL drop handler failed.", ex); + jalview.bin.Console.debug("URL drop handler failed.", ex); } } if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { // Works on Windows and MacOSX - Cache.log.debug("Drop handled as javaFileListFlavor"); + jalview.bin.Console.debug("Drop handled as javaFileListFlavor"); for (File file : (List) t .getTransferData(DataFlavor.javaFileListFlavor)) { @@ -3238,14 +3272,15 @@ public class Desktop extends GDesktop String data = null; if (t.isDataFlavorSupported(uriListFlavor)) { - Cache.log.debug("Drop handled as uriListFlavor"); + jalview.bin.Console.debug("Drop handled as uriListFlavor"); // This is used by Unix drag system data = (String) t.getTransferData(uriListFlavor); } if (data == null) { // fallback to text: workaround - on OSX where there's a JVM bug - Cache.log.debug("standard URIListFlavor failed. Trying text"); + jalview.bin.Console + .debug("standard URIListFlavor failed. Trying text"); // try text fallback DataFlavor textDf = new DataFlavor( "text/plain;class=java.lang.String"); @@ -3254,7 +3289,7 @@ public class Desktop extends GDesktop data = (String) t.getTransferData(textDf); } - Cache.log.debug("Plain text drop content returned " + jalview.bin.Console.debug("Plain text drop content returned " + (data == null ? "Null - failed" : data)); } @@ -3262,7 +3297,7 @@ public class Desktop extends GDesktop { while (protocols.size() < files.size()) { - Cache.log.debug("Adding missing FILE protocol for " + jalview.bin.Console.debug("Adding missing FILE protocol for " + files.get(protocols.size())); protocols.add(DataSourceType.FILE); } @@ -3277,7 +3312,7 @@ public class Desktop extends GDesktop continue; } java.net.URI uri = new java.net.URI(s); - if (uri.getScheme().toLowerCase().startsWith("http")) + if (uri.getScheme().toLowerCase(Locale.ROOT).startsWith("http")) { protocols.add(DataSourceType.URL); files.add(uri.toString()); @@ -3292,7 +3327,7 @@ public class Desktop extends GDesktop } } - if (Cache.log.isDebugEnabled()) + if (jalview.bin.Console.isDebugEnabled()) { if (data == null || !added) { @@ -3300,39 +3335,39 @@ public class Desktop extends GDesktop if (t.getTransferDataFlavors() != null && t.getTransferDataFlavors().length > 0) { - Cache.log.debug( + jalview.bin.Console.debug( "Couldn't resolve drop data. Here are the supported flavors:"); for (DataFlavor fl : t.getTransferDataFlavors()) { - Cache.log.debug( + jalview.bin.Console.debug( "Supported transfer dataflavor: " + fl.toString()); Object df = t.getTransferData(fl); if (df != null) { - Cache.log.debug("Retrieves: " + df); + jalview.bin.Console.debug("Retrieves: " + df); } else { - Cache.log.debug("Retrieved nothing"); + jalview.bin.Console.debug("Retrieved nothing"); } } } else { - Cache.log.debug("Couldn't resolve dataflavor for drop: " - + t.toString()); + jalview.bin.Console.debug("Couldn't resolve dataflavor for drop: " + + t.toString()); } } } } if (Platform.isWindowsAndNotJS()) { - Cache.log.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++) { - String source = files.get(f).toString().toLowerCase(); + String source = files.get(f).toString().toLowerCase(Locale.ROOT); if (protocols.get(f).equals(DataSourceType.FILE) && (source.endsWith(".lnk") || source.endsWith(".url") || source.endsWith(".site"))) @@ -3343,16 +3378,16 @@ public class Desktop extends GDesktop File lf = (obj instanceof File ? (File) obj : new File((String) obj)); // process link file to get a URL - Cache.log.debug("Found potential link file: " + lf); + jalview.bin.Console.debug("Found potential link file: " + lf); WindowsShortcut wscfile = new WindowsShortcut(lf); String fullname = wscfile.getRealFilename(); protocols.set(f, FormatAdapter.checkProtocol(fullname)); files.set(f, fullname); - Cache.log.debug("Parsed real filename " + fullname + jalview.bin.Console.debug("Parsed real filename " + fullname + " to extract protocol: " + protocols.get(f)); } catch (Exception ex) { - Cache.log.error( + jalview.bin.Console.error( "Couldn't parse " + files.get(f) + " as a link file.", ex); } @@ -3423,14 +3458,17 @@ public class Desktop extends GDesktop AffineTransform t = gg.getTransform(); double scaleX = t.getScaleX(); double scaleY = t.getScaleY(); - Cache.debug(debugScaleMessage + scaleX + " (X)"); - Cache.debug(debugScaleMessage + scaleY + " (Y)"); + jalview.bin.Console.debug(debugScaleMessage + scaleX + " (X)"); + jalview.bin.Console.debug(debugScaleMessage + scaleY + " (Y)"); debugScaleMessageDone = true; - } else { - Cache.debug("Desktop graphics null"); } - } catch (Exception e) { - Cache.debug(Cache.getStackTraceString(e)); + else + { + jalview.bin.Console.debug("Desktop graphics null"); + } + } catch (Exception e) + { + jalview.bin.Console.debug(Cache.getStackTraceString(e)); } } }