From f4b18ae31d37e694b59875f26e0863179de248f1 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 8 Mar 2022 00:34:55 +0000 Subject: [PATCH] JAL-3103 Put jalview.jar first in getdown for .properties files. Remove now-not-needed exception handling from jalview code for openURL. Change Default browser input to JComboBox populated by BrowserLauncher2 --- build.gradle | 4 +- .../launching/misc/linuxUnixConfig.properties | 35 ++++++ .../ejalbert/launching/misc/sunOSConfig.properties | 32 +++++ .../launching/windows/windowsConfig.properties | 51 ++++++++ resources/lang/Messages.properties | 2 +- resources/lang/Messages_es.properties | 2 +- src/jalview/gui/Help.java | 31 +++-- src/jalview/gui/Preferences.java | 12 +- src/jalview/gui/StructureViewerBase.java | 122 ++++++++++++-------- src/jalview/io/HTMLOutput.java | 29 ++--- src/jalview/jbgui/GPreferences.java | 30 +++-- src/jalview/util/BrowserLauncher.java | 55 ++++++--- 12 files changed, 297 insertions(+), 108 deletions(-) create mode 100644 resources/edu/stanford/ejalbert/launching/misc/linuxUnixConfig.properties create mode 100644 resources/edu/stanford/ejalbert/launching/misc/sunOSConfig.properties create mode 100644 resources/edu/stanford/ejalbert/launching/windows/windowsConfig.properties diff --git a/build.gradle b/build.gradle index d51382e..9b1eb69 100644 --- a/build.gradle +++ b/build.gradle @@ -1607,7 +1607,9 @@ task getdownWebsite() { codeFiles += f } } - codeFiles.sort().each{f -> + def jalviewJar = jar.archiveFileName.getOrNull() + // put jalview.jar first for CLASSPATH and .properties files reasons + codeFiles.sort{a, b -> ( a.getName() == jalviewJar ? -1 : ( b.getName() == jalviewJar ? 1 : a <=> b ) ) }.each{f -> def name = f.getName() def line = "code = ${getdownAppDistDir}/${name}\n" getdownTextString += line diff --git a/resources/edu/stanford/ejalbert/launching/misc/linuxUnixConfig.properties b/resources/edu/stanford/ejalbert/launching/misc/linuxUnixConfig.properties new file mode 100644 index 0000000..c7f3f8c --- /dev/null +++ b/resources/edu/stanford/ejalbert/launching/misc/linuxUnixConfig.properties @@ -0,0 +1,35 @@ +# ************************************************ +# Copyright 2006,2007 Jeff Chapman +# +# This file is part of BrowserLauncher2. +# +# BrowserLauncher2 is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# BrowserLauncher2 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with BrowserLauncher2; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# ************************************************ +# $Id: linuxUnixConfig.properties,v 1.3 2007/06/13 19:25:54 jchapman0 Exp $ + +# delimiter for browser listing +delimchar=; + +# list of browsers and arguments for using them +# display name | executable name | start browser args | invoke already started browser | force new window +browser.mozilla=Mozilla;mozilla; ; -remote openURL() +browser.netscape=Netscape;netscape; ; -remote openURL() +browser.firefox=Firefox;firefox; ; -new-tab ; -new-window +browser.mozilla-firefox=Firefox;mozilla-firefox; ; -remote openURL(); -new-window +browser.konqueror=Konqueror;kfmclient; openURL ; newTab ; openURL +browser.opera=Opera;opera; ; -newpage ; -newwindow +browser.epiphany=Epiphany;epiphany; ; --new-tab +browser.chrome=Google Chrome;google-chrome; ; ; --new-window +browser.chrome-stable=Google Chrome;google-chrome-stable; ; ; --new-window diff --git a/resources/edu/stanford/ejalbert/launching/misc/sunOSConfig.properties b/resources/edu/stanford/ejalbert/launching/misc/sunOSConfig.properties new file mode 100644 index 0000000..af32b42 --- /dev/null +++ b/resources/edu/stanford/ejalbert/launching/misc/sunOSConfig.properties @@ -0,0 +1,32 @@ +# ************************************************ +# Copyright 2006 Jeff Chapman +# +# This file is part of BrowserLauncher2. +# +# BrowserLauncher2 is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# BrowserLauncher2 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with BrowserLauncher2; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# ************************************************ +# $Id: sunOSConfig.properties,v 1.2 2006/09/12 15:40:34 jchapman0 Exp $ + +# delimiter for browser listing +delimchar=; + +# list of browsers and arguments for using them +# display name | executable name | start browser args | invoke already started browser +browser.sdtwebclient=Default;sdtwebclient; ; -remote openURL() +browser.mozilla=Mozilla;mozilla; ; -remote openURL() +browser.netscape=Netscape;netscape; ; -remote openURL() +browser.firefox=FireFox;firefox; ; -remote openURL(); -new-window +browser.opera=Opera;opera; ; -newpage ; -newwindow + diff --git a/resources/edu/stanford/ejalbert/launching/windows/windowsConfig.properties b/resources/edu/stanford/ejalbert/launching/windows/windowsConfig.properties new file mode 100644 index 0000000..c4e0f2b --- /dev/null +++ b/resources/edu/stanford/ejalbert/launching/windows/windowsConfig.properties @@ -0,0 +1,51 @@ +# ************************************************ +# Copyright 2006,2007 Jeff Chapman +# +# This file is part of BrowserLauncher2. +# +# BrowserLauncher2 is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# BrowserLauncher2 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with BrowserLauncher2; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# ************************************************ +# $Id: windowsConfig.properties,v 1.6 2007/08/30 19:38:09 jchapman0 Exp $ + +# delimiter for browser listing +delimchar=; + +# windows versions and arguments for launching a browser +# default (will be used for Win10 and Win11) is winNT +# command for starting default browser | command for starting a specific browser | use registry +windows.winVista=cmd.exe /c start "" "";".exe" "";true +windows.win2000=cmd.exe /c start "" "";".exe" "";true +windows.win9x=command.com /c start "";".exe" "";true +windows.winNT=cmd.exe /c start "" "";".exe" "";true + +# properties used to find browsers in program files folder +program.files.template={0}:\\Program Files +# drive letters to try when looking for Program Files folder +drive.letters=C;D;E + +#windows.win2000=cmd.exe /c start "" "";cmd.exe /c start "" +#windows.win9x=command.com /c start "";command.com /c start "" +#windows.winNT=cmd.exe /c start "" "";cmd.exe /c start "" + +# list of browsers and arguments for using them and discovering them +# browser display name | browser exe name | new window argument | directory containing exe +browser.mozilla=Mozilla;mozilla;;mozilla.org +browser.netscape=Netscape;netscape;;Netscape +browser.mozilla-firefox=Mozilla Firefox;firefox;-new-window;Mozilla Firefox +browser.firefox=Firefox;firefox;-new-window;Firefox +browser.opera=Opera;opera;-newwindow;Opera +browser.edge=Microsoft Edge;msedge;;Microsoft +browser.kmeleon=K-Meleon;k-meleon;;K-Meleon +browser.chrome=Google Chrome;chrome;;Google diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 733e9e2..fa32f12 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -587,7 +587,7 @@ label.nuc_alignment_colour = Nucleotide Alignment Colour label.address = Address label.host = Host label.port = Port -label.default_browser_unix = Default Browser (Unix) +label.default_browser_unix_windows = Default Browser (Unix, Windows) label.send_usage_statistics = Send usage statistics label.check_for_questionnaires = Check for questionnaires label.check_for_latest_version = Check for latest version diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index e24585c..9e3c447 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -534,7 +534,7 @@ label.gap_symbol = S label.address = Dirección label.host = Host label.port = Puerto -label.default_browser_unix = Navegador por defecto (Unix) +label.default_browser_unix_windows = Navegador por defecto (Unix, Windows) label.send_usage_statistics = Enviar estadísticas de uso label.check_for_questionnaires = Comprobar los cuestionarios label.check_for_latest_version = Comprobar la última versión diff --git a/src/jalview/gui/Help.java b/src/jalview/gui/Help.java index 8bd01ea..658b34f 100644 --- a/src/jalview/gui/Help.java +++ b/src/jalview/gui/Help.java @@ -20,11 +20,7 @@ */ package jalview.gui; -import jalview.util.BrowserLauncher; -import jalview.util.Platform; - import java.awt.Point; -import java.io.IOException; import java.net.URL; import javax.help.BadIDException; @@ -32,6 +28,9 @@ import javax.help.HelpBroker; import javax.help.HelpSet; import javax.help.HelpSetException; +import jalview.util.BrowserLauncher; +import jalview.util.Platform; + /** * Utility class to show the help documentation window * @@ -42,18 +41,22 @@ public class Help private static final String HELP_PAGE_ROOT = "http://www.jalview.org/help/"; /** - * Defines selected help targets with links to inbuilt (Java) help page target, - * and externally hosted help page. Will need to be maintained manually if help - * pages are reorganised in future. + * Defines selected help targets with links to inbuilt (Java) help page + * target, and externally hosted help page. Will need to be maintained + * manually if help pages are reorganised in future. */ public enum HelpId { - Home("home", "help.html"), SequenceFeatureSettings("seqfeatures.settings", "html/features/featuresettings.html"), - StructureViewer("viewingpdbs", "html/features/viewingpdbs.html"), PdbFts("pdbfts", "html/features/pdbsequencefetcher.html#pdbfts"), - UniprotFts("uniprotfts", "html/features/uniprotsequencefetcher.html#uniprotfts"); + Home("home", "help.html"), + SequenceFeatureSettings("seqfeatures.settings", + "html/features/featuresettings.html"), + StructureViewer("viewingpdbs", "html/features/viewingpdbs.html"), + PdbFts("pdbfts", "html/features/pdbsequencefetcher.html#pdbfts"), + UniprotFts("uniprotfts", + "html/features/uniprotsequencefetcher.html#uniprotfts"); private String id; - + private String path; private HelpId(String hepLoc, String htmlPath) @@ -94,12 +97,16 @@ public class Help { if (Platform.isJS()) { + /* try { - BrowserLauncher.openURL(HELP_PAGE_ROOT + id.getPath()); + */ + BrowserLauncher.openURL(HELP_PAGE_ROOT + id.getPath()); + /* } catch (IOException e) { } + */ } else /** diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 7a4dbc0..17f6af6 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -641,7 +641,11 @@ public class Preferences extends GPreferences setCustomProxyEnabled(); applyProxyButtonEnabled(false); - defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", "")); + String browserPref = Cache.getDefault("DEFAULT_BROWSER", ""); + if (browserPref != null) + { + defaultBrowser.getModel().setSelectedItem(browserPref); + } usagestats.setSelected(Cache.getDefault("USAGESTATS", false)); // note antisense here: default is true @@ -889,7 +893,8 @@ public class Preferences extends GPreferences */ // Proxy settings set first (to catch web services) - Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText()); + Cache.setOrRemove("DEFAULT_BROWSER", + (String) defaultBrowser.getSelectedItem()); if (Cache.getProperty("DEFAULT_BROWSER") != null) { System.setProperty(IBrowserLaunching.BROWSER_SYSTEM_PROPERTY, @@ -1284,7 +1289,8 @@ public class Preferences extends GPreferences if (value == JFileChooser.APPROVE_OPTION) { - defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath()); + defaultBrowser.getModel().setSelectedItem( + chooser.getSelectedFile().getAbsolutePath()); } } } diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 349871d..ec5579c 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -156,9 +156,11 @@ public abstract class StructureViewerBase extends GStructureViewer { alignAddedStructures = alignAdded; } - + /** - * called by the binding model to indicate when adding structures is happening or has been completed + * called by the binding model to indicate when adding structures is happening + * or has been completed + * * @param addingStructures */ public synchronized void setAddingStructures(boolean addingStructures) @@ -443,8 +445,9 @@ public abstract class StructureViewerBase extends GStructureViewer { return; } - AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this - // cast fails + AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error + // if this + // cast fails useAlignmentPanelForSuperposition(alignPanel); addStructure(pdbentry, seq, chains, alignPanel.alignFrame); } @@ -581,9 +584,8 @@ public abstract class StructureViewerBase extends GStructureViewer public void changeColour_actionPerformed(String colourSchemeName) { AlignmentI al = getAlignmentPanel().av.getAlignment(); - ColourSchemeI cs = ColourSchemes.getInstance() - .getColourScheme(colourSchemeName, getAlignmentPanel().av, al, - null); + ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme( + colourSchemeName, getAlignmentPanel().av, al, null); getBinding().colourByJalviewColourScheme(cs); } @@ -1038,14 +1040,17 @@ public abstract class StructureViewerBase extends GStructureViewer { return false; } - int p=0; - for (String pdbid:pdbids) { + int p = 0; + for (String pdbid : pdbids) + { StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid); - if (sm!=null && sm.length>0 && sm[0]!=null) { + if (sm != null && sm.length > 0 && sm[0] != null) + { p++; } } - // only return true if there is a mapping for every structure file we have loaded + // only return true if there is a mapping for every structure file we have + // loaded if (p == 0 || p != pdbids.length) { return false; @@ -1137,12 +1142,12 @@ public abstract class StructureViewerBase extends GStructureViewer { String filePath = null; Pdb pdbclient = new Pdb(); - EBIAlfaFold afclient = new EBIAlfaFold(); + EBIAlfaFold afclient = new EBIAlfaFold(); AlignmentI pdbseq = null; String pdbid = processingEntry.getId(); long handle = System.currentTimeMillis() + Thread.currentThread().hashCode(); - + /* * Write 'fetching PDB' progress on AlignFrame as we are not yet visible */ @@ -1157,29 +1162,36 @@ public abstract class StructureViewerBase extends GStructureViewer { if (afclient.isValidReference(pdbid)) { - pdbseq = afclient.getSequenceRecords(pdbid,processingEntry.getRetrievalUrl()); - } else { - if (processingEntry.hasRetrievalUrl()) + pdbseq = afclient.getSequenceRecords(pdbid, + processingEntry.getRetrievalUrl()); + } + else + { + if (processingEntry.hasRetrievalUrl()) + { + String safePDBId = java.net.URLEncoder.encode(pdbid, "UTF-8") + .replace("%", "__"); + + // retrieve from URL to new local tmpfile + File tmpFile = File.createTempFile(safePDBId, + "." + (PDBEntry.Type.MMCIF.toString().equals( + processingEntry.getType().toString()) ? "cif" + : "pdb")); + String fromUrl = processingEntry.getRetrievalUrl(); + UrlDownloadClient.download(fromUrl, tmpFile); + + // may not need this check ? + String file = tmpFile.getAbsolutePath(); + if (file != null) { - String safePDBId = java.net.URLEncoder.encode(pdbid,"UTF-8").replace("%","__"); - - // retrieve from URL to new local tmpfile - File tmpFile = File.createTempFile(safePDBId, - "." + (PDBEntry.Type.MMCIF.toString().equals( - processingEntry.getType().toString()) ? "cif" - : "pdb")); - String fromUrl = processingEntry.getRetrievalUrl(); - UrlDownloadClient.download(fromUrl, tmpFile); - - // may not need this check ? - String file = tmpFile.getAbsolutePath(); - if (file != null) - { - pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl,tmpFile,pdbid,null,null,null); - } - } else { - pdbseq = pdbclient.getSequenceRecords(pdbid); + pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl, + tmpFile, pdbid, null, null, null); } + } + else + { + pdbseq = pdbclient.getSequenceRecords(pdbid); + } } } catch (Exception e) { @@ -1213,22 +1225,28 @@ public abstract class StructureViewerBase extends GStructureViewer */ public File saveSession() { - if (getBinding() == null) { return null;} + if (getBinding() == null) + { + return null; + } File session = getBinding().saveSession(); long l = session.length(); - int wait=50; - do { - try { + int wait = 50; + do + { + try + { Thread.sleep(5); - } catch (InterruptedException e) { - } + } catch (InterruptedException e) + { + } long nextl = session.length(); - if (nextl!=l) + if (nextl != l) { wait = 50; - l=nextl; + l = nextl; } - } while (--wait>0); + } while (--wait > 0); return session; } @@ -1284,20 +1302,26 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void showHelp_actionPerformed() { + /* try { - String url = getBinding().getHelpURL(); - if (url != null) - { - BrowserLauncher.openURL(url); - } - } catch (IOException ex) + */ + String url = getBinding().getHelpURL(); + if (url != null) + { + BrowserLauncher.openURL(url); + } + /* + } + catch (IOException ex) { System.err .println("Show " + getViewerName() + " failed with: " + ex.getMessage()); } + */ } + @Override public boolean hasViewerActionsMenu() { diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index 54e7e4b..eb44180 100644 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -20,6 +20,13 @@ */ package jalview.io; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Objects; + import jalview.api.AlignExportSettingsI; import jalview.bin.Cache; import jalview.datamodel.AlignExportSettingsAdapter; @@ -28,13 +35,6 @@ import jalview.gui.AlignmentPanel; import jalview.gui.IProgressIndicator; import jalview.util.MessageManager; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.Objects; - public abstract class HTMLOutput implements Runnable { protected AlignmentPanel ap; @@ -59,7 +59,7 @@ public abstract class HTMLOutput implements Runnable * Constructor given an alignment panel (which should not be null) * * @param ap - * @param desc + * @param desc */ public HTMLOutput(AlignmentPanel ap, String desc) { @@ -261,14 +261,17 @@ public abstract class HTMLOutput implements Runnable { if (isLaunchInBrowserAfterExport() && !isHeadless()) { + /* try { - jalview.util.BrowserLauncher - .openURL("file:///" + getExportedFile()); + */ + jalview.util.BrowserLauncher.openURL("file:///" + getExportedFile()); + /* } catch (IOException e) { e.printStackTrace(); } + */ } } @@ -301,7 +304,7 @@ public abstract class HTMLOutput implements Runnable public void exportHTML(String outputFile) { setProgressMessage(MessageManager.formatMessage( - "status.exporting_alignment_as_x_file", getDescription())); + "status.exporting_alignment_as_x_file", getDescription())); try { if (outputFile == null) @@ -327,7 +330,7 @@ public abstract class HTMLOutput implements Runnable return; } new Thread(this).start(); - + } /** @@ -338,6 +341,6 @@ public abstract class HTMLOutput implements Runnable */ protected final String getDescription() { - return description; + return description; } } \ No newline at end of file diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index d281c8d..61b2f24 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -45,6 +45,8 @@ import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -91,6 +93,7 @@ import jalview.io.BackupFilenameParts; import jalview.io.BackupFiles; import jalview.io.BackupFilesPresetEntry; import jalview.io.IntKeyStringValueEntry; +import jalview.util.BrowserLauncher; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.StringUtils; @@ -269,7 +272,7 @@ public class GPreferences extends JPanel protected JPasswordField proxyAuthPasswordPB = new JPasswordField(); - protected JTextField defaultBrowser = new JTextField(); + protected JComboBox defaultBrowser = new JComboBox(); protected ButtonGroup proxyType = new ButtonGroup(); @@ -745,12 +748,12 @@ public class GPreferences extends JPanel browserLabel.setFont(LABEL_FONT); browserLabel.setHorizontalAlignment(SwingConstants.TRAILING); browserLabel.setText( - MessageManager.getString("label.default_browser_unix")); + MessageManager.getString("label.default_browser_unix_windows")); defaultBrowser.setFont(LABEL_FONT); - defaultBrowser.setText(""); final String tooltip = JvSwingUtils.wrapTooltip(true, MessageManager.getString("label.double_click_to_browse")); defaultBrowser.setToolTipText(tooltip); + /* defaultBrowser.addMouseListener(new MouseAdapter() { @Override @@ -762,6 +765,7 @@ public class GPreferences extends JPanel } } }); + */ JPanel proxyPanel = initConnTabProxyPanel(); initConnTabCheckboxes(); @@ -772,7 +776,15 @@ public class GPreferences extends JPanel GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 5, 5), 5, 1)); defaultBrowser.setFont(LABEL_FONT); - defaultBrowser.setText(""); + + ComboBoxModel cbModel = new DefaultComboBoxModel( + BrowserLauncher.getInstance().getBrowserList().toArray()); + String browserPref = Cache.getProperty("DEFAULT_BROWSER"); + if (browserPref != null) + { + cbModel.setSelectedItem(browserPref); + } + defaultBrowser.setModel(cbModel); connectTab.add(defaultBrowser, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, @@ -1818,8 +1830,8 @@ public class GPreferences extends JPanel } /** - * Show a dialog for the user to choose a file. Returns the chosen path, or null - * on Cancel. + * Show a dialog for the user to choose a file. Returns the chosen path, or + * null on Cancel. * * @return */ @@ -3487,7 +3499,7 @@ public class GPreferences extends JPanel * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void ok_actionPerformed(ActionEvent e) { @@ -3497,7 +3509,7 @@ public class GPreferences extends JPanel * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void cancel_actionPerformed(ActionEvent e) { @@ -3507,7 +3519,7 @@ public class GPreferences extends JPanel * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void annotations_actionPerformed(ActionEvent e) { diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java index 304fc59..cddbecb 100644 --- a/src/jalview/util/BrowserLauncher.java +++ b/src/jalview/util/BrowserLauncher.java @@ -1,17 +1,44 @@ package jalview.util; -import java.io.IOException; - import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException; import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException; import jalview.bin.Cache; import jalview.bin.Console; -public class BrowserLauncher +public class BrowserLauncher extends edu.stanford.ejalbert.BrowserLauncher { + private static BrowserLauncher INSTANCE = null; + + // get singleton BrowserLauncher instance + public static BrowserLauncher getInstance() + { + if (INSTANCE == null) + { + try + { + INSTANCE = new BrowserLauncher(); + } catch (BrowserLaunchingInitializingException e) + { + Console.warn(MessageManager.formatMessage( + "exception.browser_unable_to_launch", e.getMessage())); + } catch (UnsupportedOperatingSystemException e) + { + Console.warn(MessageManager.formatMessage("exception.")); + Console.debug(e.getMessage()); + } + } + return INSTANCE; + } + + public BrowserLauncher() throws BrowserLaunchingInitializingException, + UnsupportedOperatingSystemException + { + super(); + } + private static String preferredBrowser = null; - public static void openURL(String url) throws IOException + public static void openURL(String url) { if (Platform.isJS()) { @@ -25,19 +52,7 @@ public class BrowserLauncher * @j2sIgnore */ { - edu.stanford.ejalbert.BrowserLauncher bl = null; - try - { - bl = new edu.stanford.ejalbert.BrowserLauncher(); - } catch (BrowserLaunchingInitializingException e) - { - Console.warn(MessageManager.formatMessage( - "exception.browser_unable_to_launch", e.getMessage())); - } catch (UnsupportedOperatingSystemException e) - { - Console.warn(MessageManager.formatMessage("exception.")); - Console.debug(e.getMessage()); - } + BrowserLauncher bl = getInstance(); if (bl != null) { if (Platform.isMac() || preferredBrowser == null) @@ -46,11 +61,13 @@ public class BrowserLauncher } else { - System.err.println( - "**** OPENURL (" + preferredBrowser + ", " + url + ")"); bl.openURLinBrowser(preferredBrowser, url); } } + else + { + Console.warn("Could not open URL '" + url + "'"); + } } } -- 1.7.10.2