From d9f0a24d9662a0b530fd79b51108dd074d03d6e0 Mon Sep 17 00:00:00 2001 From: hansonr Date: Wed, 27 Mar 2019 05:40:22 -0400 Subject: [PATCH] isJS cleanup --- src/jalview/bin/Cache.java | 64 ++-- src/jalview/bin/Jalview.java | 84 ++--- src/jalview/bin/JalviewJS2.java | 15 +- src/jalview/fts/core/GFTSPanel.java | 4 +- src/jalview/fts/service/pdb/PDBFTSRestClient.java | 10 +- .../fts/service/uniprot/UniProtFTSRestClient.java | 5 + src/jalview/gui/AlignFrame.java | 12 +- src/jalview/gui/Desktop.java | 76 +++-- src/jalview/gui/FeatureSettings.java | 5 + src/jalview/gui/Help.java | 77 +++-- src/jalview/gui/IdPanel.java | 18 +- src/jalview/gui/JvOptionPane.java | 10 + src/jalview/gui/OverviewPanel.java | 6 +- src/jalview/gui/PopupMenu.java | 26 +- src/jalview/gui/Preferences.java | 10 +- src/jalview/gui/SeqPanel.java | 16 +- src/jalview/gui/SplashScreen.java | 41 ++- src/jalview/gui/UserDefinedColours.java | 74 ++--- src/jalview/io/JalviewFileChooser.java | 5 + src/jalview/renderer/AnnotationRenderer.java | 21 +- src/jalview/util/Platform.java | 325 ++++++++++---------- 21 files changed, 524 insertions(+), 380 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 3c919cb..e8c3151 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -278,8 +278,8 @@ public class Cache /** Default file is ~/.jalview_properties */ static String propertiesFile; - private static boolean propsAreReadOnly = /** @j2sNative true || */ - false; + private static boolean propsAreReadOnly = Platform.isJS();/// ** @j2sNative + /// true || */false; public static void initLogger() { @@ -390,22 +390,27 @@ public class Cache // LOAD THE AUTHORS FROM THE authors.props file boolean ignore = Platform.isJS(); if (!ignore) - try + /** + * @j2sNative + */ { - String authorDetails = "jar:" - .concat(Cache.class.getProtectionDomain().getCodeSource() - .getLocation().toString().concat("!/authors.props")); + try + { + String authorDetails = "jar:" + .concat(Cache.class.getProtectionDomain().getCodeSource() + .getLocation().toString().concat("!/authors.props")); - java.net.URL localJarFileURL = new java.net.URL(authorDetails); + java.net.URL localJarFileURL = new java.net.URL(authorDetails); - InputStream in = localJarFileURL.openStream(); - applicationProperties.load(in); - in.close(); - - } catch (Exception ex) - { - System.out.println("Error reading author details: " + ex); - ignore = true; + InputStream in = localJarFileURL.openStream(); + applicationProperties.load(in); + in.close(); + + } catch (Exception ex) + { + System.out.println("Error reading author details: " + ex); + ignore = true; + } } if (ignore) { @@ -420,21 +425,26 @@ public class Cache // BH 2019.01.25 switching to Platform.isJS() ignore = Platform.isJS(); if (!ignore) - try + /** + * @j2sNative + */ { - String buildDetails = "jar:".concat(Cache.class.getProtectionDomain() - .getCodeSource().getLocation().toString() - .concat("!/.build_properties")); + try + { + String buildDetails = "jar:".concat(Cache.class.getProtectionDomain() + .getCodeSource().getLocation().toString() + .concat("!/.build_properties")); - java.net.URL localJarFileURL = new java.net.URL(buildDetails); + java.net.URL localJarFileURL = new java.net.URL(buildDetails); - InputStream in = localJarFileURL.openStream(); - applicationProperties.load(in); - in.close(); - } catch (Exception ex) - { - System.out.println("Error reading build details: " + ex); - ignore = true; + InputStream in = localJarFileURL.openStream(); + applicationProperties.load(in); + in.close(); + } catch (Exception ex) + { + System.out.println("Error reading build details: " + ex); + ignore = true; + } } if (ignore) { diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 2595c4d..7cbbd7d 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -41,8 +41,6 @@ import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.jws2.Jws2Discoverer; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -67,7 +65,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.LookAndFeel; -import javax.swing.Timer; import javax.swing.UIManager; import groovy.lang.Binding; @@ -91,27 +88,17 @@ import groovy.util.GroovyScriptEngine; public class Jalview { /** - * @j2sNative - * - * // find first query parameter (if any) that doesn't start with j2s - * // and set as space-delimited arguments to Jalview main - * hr = decodeURI(document.location.href); - * pos = hr.indexOf("?"); - * if (pos > 0) - * { - * q = hr.substring(pos+1); - * args = q.split("&"); - * for (i = 0 ; i < args.length; i++) - * { - * arg1 = args[i]; - * if (!arg1.startsWith("j2s")) - * { - * thisApplet.__Info.args = arg1.split(" "); - * break; - * } - * } - * } - */ + * // find first query parameter (if any) that doesn't start with j2s // and + * set as space-delimited arguments to Jalview main + * + * @j2sNative + * + * var hr = decodeURI(document.location.href); var pos = + * hr.indexOf("?"); if (pos > 0) { q = hr.substring(pos+1); args = + * q.split("&"); for (i = 0 ; i < args.length; i++) { arg1 = + * args[i]; if (!arg1.startsWith("j2s")) { thisApplet.__Info.args = + * arg1.split(" "); break; } } } + */ /* * singleton instance of this class @@ -125,8 +112,13 @@ public class Jalview static { if (!Platform.isJS()) - { // BH 2018 - // grab all the rights we can for the JVM + /** + * Java only + * + * @j2sNative + */ + { + // grab all the rights we can for the JVM Policy.setPolicy(new Policy() { @Override @@ -236,7 +228,12 @@ public class Jalview private static void setLogging() { // BH - for event debugging in JavaScript (Java mode only) - if (!(/** @j2sNative true ||*/false)) + if (!Platform.isJS())// !(/** @j2sNative true ||*/false)) + /** + * Java only + * + * @j2sNative + */ { Logger.getLogger("").setLevel(Level.ALL); logClass("java.awt.EventDispatchThread"); @@ -279,8 +276,9 @@ public class Jalview "CMD [-props " + usrPropsFile + "] executed successfully!"); } + if (!Platform.isJS()) /** - * BH 2018 ignoring this section for JS + * ignore in JavaScript * * @j2sNative */ @@ -421,11 +419,11 @@ public class Jalview desktop.setInBatchMode(true); // indicate we are starting up desktop.setVisible(true); + if (!Platform.isJS()) /** - * BH 2018 JS bypass this section + * Java only * * @j2sNative - * */ { desktop.startServiceDiscovery(); @@ -595,14 +593,23 @@ public class Jalview } System.out.println("CMD [-open " + file + "] executed successfully!"); - if (!Platform.isJS() && !file.startsWith("http://")) + if (!Platform.isJS()) + /** + * ignore in JavaScript -- can't just file existence - could load it? + * + * @j2sNative + */ { - if (!(new File(file)).exists()) + if (!file.startsWith("http://") && !file.startsWith("https://")) + // BH 2019 added https check for Java { - System.out.println("Can't find " + file); - if (headless) + if (!(new File(file)).exists()) { - System.exit(1); + System.out.println("Can't find " + file); + if (headless) + { + System.exit(1); + } } } } @@ -819,9 +826,14 @@ public class Jalview // And the user // //////////////////// - if (/** @j2sNative false && */ // BH 2018 + if (!Platform.isJS() && // /** @j2sNative false && */ // BH 2018 !headless && file == null && vamsasImport == null && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)) + /** + * Java only + * + * @j2sNative + */ { file = jalview.bin.Cache.getDefault("STARTUP_FILE", jalview.bin.Cache.getDefault("www.jalview.org", diff --git a/src/jalview/bin/JalviewJS2.java b/src/jalview/bin/JalviewJS2.java index 0a02a8d..0413bc1 100644 --- a/src/jalview/bin/JalviewJS2.java +++ b/src/jalview/bin/JalviewJS2.java @@ -28,13 +28,10 @@ public class JalviewJS2 /** * @j2sNative * - * hr = decodeURI(document.location.href); - * pos = hr.indexOf("?"); - * // set space-delimited query parameters as arguments to Jalview main - * if (pos > 0) - * { - * thisApplet.__Info.args = hr.substring(pos+1).split(" "); - * } + * var hr = decodeURI(document.location.href); var pos = + * hr.indexOf("?"); // set space-delimited query parameters as + * arguments to Jalview main if (pos > 0) { + * thisApplet.__Info.args = hr.substring(pos+1).split(" "); } */ } @@ -65,7 +62,9 @@ private static void showFocusTimer() { t.setRepeats(true); if (/** @j2sNative true || */ false) - t.start(); + { + t.start(); + } } diff --git a/src/jalview/fts/core/GFTSPanel.java b/src/jalview/fts/core/GFTSPanel.java index 51363b2..47e9440 100644 --- a/src/jalview/fts/core/GFTSPanel.java +++ b/src/jalview/fts/core/GFTSPanel.java @@ -377,8 +377,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI btn_autosearch.setText(MessageManager.getString("option.autosearch")); btn_autosearch.setToolTipText( MessageManager.getString("option.enable_disable_autosearch")); - btn_autosearch.setSelected(Platform.isJS() ? false : - Cache.getDefault(getAutosearchPreference(), true)); + btn_autosearch.setSelected(!Platform.isJS() + && Cache.getDefault(getAutosearchPreference(), true)); btn_autosearch.addActionListener(new java.awt.event.ActionListener() { @Override diff --git a/src/jalview/fts/service/pdb/PDBFTSRestClient.java b/src/jalview/fts/service/pdb/PDBFTSRestClient.java index 402efff..3778212 100644 --- a/src/jalview/fts/service/pdb/PDBFTSRestClient.java +++ b/src/jalview/fts/service/pdb/PDBFTSRestClient.java @@ -132,8 +132,12 @@ public class PDBFTSRestClient extends FTSRestClient clientResponseClass = (Class) (Object) jalview.javascript.web.ClientResponse.class; } else + /** + * Java only + * + * @j2sNative + */ { - // Java only client = Client.create(new DefaultClientConfig()); clientResponseClass = ClientResponse.class; } @@ -301,7 +305,7 @@ public static String parseJsonExceptionString(String jsonErrorResponse) .valueOf(pdbResponse.get("numFound").toString()); if (numFound > 0) { - result = new ArrayList(); + result = new ArrayList<>(); List docs = (List) pdbResponse.get("docs"); for (Iterator docIter = docs.iterator(); docIter .hasNext();) @@ -455,7 +459,7 @@ public static String parseJsonExceptionString(String jsonErrorResponse) if (allDefaultDisplayedStructureDataColumns == null || allDefaultDisplayedStructureDataColumns.isEmpty()) { - allDefaultDisplayedStructureDataColumns = new ArrayList(); + allDefaultDisplayedStructureDataColumns = new ArrayList<>(); allDefaultDisplayedStructureDataColumns .addAll(super.getAllDefaultDisplayedFTSDataColumns()); } diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index e6620f8..1f4d56a 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -103,6 +103,11 @@ public class UniProtFTSRestClient extends FTSRestClient clientResponseClass = (Class) (Object) jalview.javascript.web.ClientResponse.class; } else + /** + * Java only + * + * @j2sNative + */ { // Java only client = Client.create(new DefaultClientConfig()); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 9522d00..ef57d5f 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -392,12 +392,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (Desktop.desktop != null) { this.setDropTarget(new java.awt.dnd.DropTarget(this, this)); - /** - * BH 2018 ignore service listeners - * - * @j2sNative - * - */ + if (!Platform.isJS()) { addServiceListeners(); } @@ -3323,6 +3318,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, ((JPanel) pane).add(textLabel, BorderLayout.NORTH); } else + /** + * Java only + * + * @j2sNative + */ { JEditorPane editPane = new JEditorPane("text/html", ""); editPane.setEditable(false); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 1e5904c..7d54255 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -346,10 +346,11 @@ public class Desktop extends jalview.jbgui.GDesktop */ public Desktop() { - super(); + super(); /** - * 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. + * 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. */ instance = this; if (!Platform.isJS()) @@ -365,8 +366,7 @@ public class Desktop extends jalview.jbgui.GDesktop boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE", false); desktop = new MyDesktopPane(selmemusage); - - + showMemusage.setSelected(selmemusage); desktop.setBackground(Color.white); getContentPane().setLayout(new BorderLayout()); @@ -374,16 +374,16 @@ public class Desktop extends jalview.jbgui.GDesktop // 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"); - } - + + // BH 2018 - just an experiment to try unclipped JInternalFrames. + if (Platform.isJS()) + { + getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); + } + getContentPane().add(desktop, BorderLayout.CENTER); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); - + // This line prevents Windows Look&Feel resizing all new windows to maximum // if previous window was maximised desktop.setDesktopManager(new MyDesktopManager( @@ -405,11 +405,16 @@ public class Desktop extends jalview.jbgui.GDesktop int yPos = Math.max(5, (screenSize.height - 650) / 2); setBounds(xPos, yPos, 900, 650); } - - boolean doFullLoad = /** @j2sNative ! */true; - - if (doFullLoad) { - + + // boolean doFullLoad = /** @j2sNative ! */true; + if (!Platform.isJS()) + /** + * Java only + * + * @j2sNative + */ + { + jconsole = new Console(this, showjconsole); // add essential build information jconsole.setHeader("Jalview Version: " @@ -444,7 +449,8 @@ public class Desktop extends jalview.jbgui.GDesktop } }); - // Thread off a new instance of the file chooser - this reduces the time it + // Thread off a new instance of the file chooser - this reduces the time + // it // takes to open it later on. new Thread(new Runnable() { @@ -473,7 +479,7 @@ public class Desktop extends jalview.jbgui.GDesktop }); - } + } this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); @@ -884,8 +890,7 @@ public class Desktop extends jalview.jbgui.GDesktop frame.setResizable(resizable); frame.setMaximizable(resizable); frame.setIconifiable(resizable); - frame.setOpaque(/** @j2sNative true || */ - false); + frame.setOpaque(Platform.isJS());/// ** @j2sNative true || */false); if (frame.getX() < 1 && frame.getY() < 1) { @@ -1172,7 +1177,7 @@ public class Desktop extends jalview.jbgui.GDesktop JPanel panel = new JPanel(new GridLayout(2, 1)); panel.add(label); - + /* * the URL to fetch is * Java: an editable combobox with history @@ -1185,6 +1190,11 @@ public class Desktop extends jalview.jbgui.GDesktop history = new JTextField(urlBase, 35); } else + /** + * Java only + * + * @j2sNative + */ { JComboBox asCombo = new JComboBox<>(); asCombo.setPreferredSize(new Dimension(400, 20)); @@ -1204,13 +1214,16 @@ public class Desktop extends jalview.jbgui.GDesktop Object[] options = new Object[] { MessageManager.getString("action.ok"), MessageManager.getString("action.cancel") }; - Runnable action = new Runnable() { + Runnable action = new Runnable() + { @Override public void run() { - String url = Platform.isJS() ? ((JTextField) history).getText() + @SuppressWarnings("unchecked") + String url = (history instanceof JTextField + ? ((JTextField) history).getText() : ((JComboBox) history).getSelectedItem() - .toString(); + .toString()); if (url.toLowerCase().endsWith(".jar")) { @@ -1239,7 +1252,8 @@ public class Desktop extends jalview.jbgui.GDesktop if (format == null) { - String msg = MessageManager.formatMessage("label.couldnt_locate", url); + String msg = MessageManager + .formatMessage("label.couldnt_locate", url); JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg, MessageManager.getString("label.url_not_found"), JvOptionPane.WARNING_MESSAGE); @@ -1257,7 +1271,8 @@ public class Desktop extends jalview.jbgui.GDesktop new FileLoader().LoadFile(url, DataSourceType.URL, format); } } - }}; + } + }; String dialogOption = MessageManager .getString("label.input_alignment_from_url"); JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action) @@ -1438,6 +1453,11 @@ public class Desktop extends jalview.jbgui.GDesktop BrowserLauncher.openURL("http://www.jalview.org/help.html"); } else + /** + * Java only + * + * @j2sNative + */ { Help.showHelpWindow(); } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 3dc7f98..0cd8620 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -1713,6 +1713,11 @@ class ColorEditor extends AbstractCellEditor */ chooser = new FeatureTypeSettings(fr, type); if (!Platform.isJS()) + /** + * Java only + * + * @j2sNative + */ { chooser.setRequestFocusEnabled(true); chooser.requestFocus(); diff --git a/src/jalview/gui/Help.java b/src/jalview/gui/Help.java index 83fcaf7..48f84c3 100644 --- a/src/jalview/gui/Help.java +++ b/src/jalview/gui/Help.java @@ -92,44 +92,53 @@ public class Help */ public static void showHelpWindow(HelpId id) throws HelpSetException { - if (Platform.isJS()) - { - try - { - BrowserLauncher.openURL(HELP_PAGE_ROOT + id.getPath()); - } catch (IOException e) {} - return; - } - - ClassLoader cl = Desktop.class.getClassLoader(); - URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$ - HelpSet hs = new HelpSet(cl, url); - - if (hb == null) + if (Platform.isJS()) { - /* - * create help broker first time (only) - */ - hb = hs.createHelpBroker(); + try + { + BrowserLauncher.openURL(HELP_PAGE_ROOT + id.getPath()); + } catch (IOException e) + { + } } - - try - { - hb.setCurrentID(id.getId()); - } catch (BadIDException bad) + else + /** + * Java only + * + * @j2sNative + */ { - System.out.println("Bad help link: " + id.getId() - + ": must match a target in help.jhm"); - throw bad; - } - /* - * set Help visible - at its current location if it is already shown, - * else at a location as determined by the window manager - */ - Point p = hb.getLocation(); - hb.setLocation(p); - hb.setDisplayed(true); + ClassLoader cl = Desktop.class.getClassLoader(); + URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$ + HelpSet hs = new HelpSet(cl, url); + + if (hb == null) + { + /* + * create help broker first time (only) + */ + hb = hs.createHelpBroker(); + } + + try + { + hb.setCurrentID(id.getId()); + } catch (BadIDException bad) + { + System.out.println("Bad help link: " + id.getId() + + ": must match a target in help.jhm"); + throw bad; + } + + /* + * set Help visible - at its current location if it is already shown, + * else at a location as determined by the window manager + */ + Point p = hb.getLocation(); + hb.setLocation(p); + hb.setDisplayed(true); + } } /** diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 5908810..8f97f9a 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -318,14 +318,7 @@ public class IdPanel extends JPanel void startScrolling(boolean up) { scrollThread = new ScrollThread(up); - if (!Platform.isJS()) - { - /* - * Java - run in a new thread - */ - scrollThread.start(); - } - else + if (Platform.isJS()) { /* * for JalviewJS using Swing Timer @@ -356,6 +349,15 @@ public class IdPanel extends JPanel }); t.start(); } + else + /** + * Java only + * + * @j2sNative + */ + { + scrollThread.start(); + } } /** diff --git a/src/jalview/gui/JvOptionPane.java b/src/jalview/gui/JvOptionPane.java index 5bbe75f..0e3d5ef 100644 --- a/src/jalview/gui/JvOptionPane.java +++ b/src/jalview/gui/JvOptionPane.java @@ -790,6 +790,11 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, * (for Javascript, see propertyChange) */ if (!Platform.isJS()) + /** + * Java only + * + * @j2sNative + */ { handleResponse(response); } @@ -819,6 +824,11 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, initresponse); } if (!Platform.isJS()) + /** + * Java only + * + * @j2sNative + */ { handleResponse(response); } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 0670616..84e3313 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -249,9 +249,11 @@ public class OverviewPanel extends JPanel * Javascript does not call componentResized on initial display, * so do the update here */ - boolean doUpdate = /** @j2sNative true || */ false; - if (doUpdate) + // boolean doUpdate = /** @j2sNative true || */ false; + if (Platform.isJS()) + { updateOverviewImage(); + } } /* diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index e78eaf2..37defd0 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -612,23 +612,28 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener protected void showFeatureDetails(SequenceFeature sf) { JInternalFrame details; - if (/** @j2sNative true || */ false) + if (Platform.isJS())// ** @j2sNative true || */ false) { details = new JInternalFrame(); JPanel panel = new JPanel(new BorderLayout()); panel.setOpaque(true); panel.setBackground(Color.white); // TODO JAL-3026 set style of table correctly for feature details - JLabel reprt = new JLabel(MessageManager.formatMessage("label.html_content", - new Object[] - { sf.getDetailsReport()})); + JLabel reprt = new JLabel(MessageManager + .formatMessage("label.html_content", new Object[] + { sf.getDetailsReport() })); reprt.setBackground(Color.WHITE); reprt.setOpaque(true); - panel.add(reprt,BorderLayout.CENTER); + panel.add(reprt, BorderLayout.CENTER); details.setContentPane(panel); details.pack(); } else + /** + * Java only + * + * @j2sNative + */ { CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer(); // it appears Java's CSS does not support border-collaps :-( @@ -1675,7 +1680,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } contents.append(""); String report = contents.toString(); - + JInternalFrame frame; if (Platform.isJS()) { @@ -1683,13 +1688,18 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener textLabel.setText(report); textLabel.setBackground(Color.WHITE); JPanel pane = new JPanel(new BorderLayout()); - ((JPanel) pane).setOpaque(true); + pane.setOpaque(true); pane.setBackground(Color.WHITE); - ((JPanel) pane).add(textLabel, BorderLayout.NORTH); + pane.add(textLabel, BorderLayout.NORTH); frame = new JInternalFrame(); frame.getContentPane().add(new JScrollPane(pane)); } else + /** + * Java only + * + * @j2sNative + */ { CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer(); cap.setText(report); diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index cd3b9e5..f961712 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -190,6 +190,11 @@ public class Preferences extends GPreferences frame = new JInternalFrame(); frame.setContentPane(this); if (!Platform.isJS()) + /** + * Java only + * + * @j2sNative + */ { wsPrefs = new WsPreferences(); wsTab.add(wsPrefs, BorderLayout.CENTER); @@ -1068,7 +1073,10 @@ public class Preferences extends GPreferences public void defaultBrowser_mouseClicked(MouseEvent e) { // TODO: JAL-3048 not needed for j2s - /* + if (!Platform.isJS()) // BH 2019 + /** + * Java only + * * @j2sNative */ { diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 9a67c27..2df55ad 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -2408,14 +2408,7 @@ public class SeqPanel extends JPanel { scrollThread = new ScrollThread(); scrollThread.setMousePosition(mousePos); - if (!Platform.isJS()) - { - /* - * Java - run in a new thread - */ - scrollThread.start(); - } - else + if (Platform.isJS()) { /* * Javascript - run every 20ms until scrolling stopped @@ -2448,6 +2441,13 @@ public class SeqPanel extends JPanel t.start(); } } + else + { + /* + * Java - run in a new thread + */ + scrollThread.start(); + } } /** diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index a122eb6..52bd64f 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -20,6 +20,8 @@ */ package jalview.gui; +import jalview.util.Platform; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -35,7 +37,6 @@ import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JPanel; -import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; @@ -54,7 +55,7 @@ public class SplashScreen extends JPanel JPanel iconimg = new JPanel(new BorderLayout()); /** - * either text area in javascript or in java text pane + * either text area in javascript or in java text pane */ Component authlist; @@ -86,7 +87,8 @@ public class SplashScreen extends JPanel { this.interactiveDialog = interactive; // show a splashscreen that will disapper - if (/** @j2sNative true || */ false) + if (Platform.isJS()) // BH 2019 + // if (/** @j2sNative true || */ false) { authlist = new JLabel(""); run(); @@ -94,6 +96,8 @@ public class SplashScreen extends JPanel else { /** + * Java only + * * @j2sNative */ { @@ -107,6 +111,7 @@ public class SplashScreen extends JPanel MouseAdapter closer = new MouseAdapter() { + @Override public void mousePressed(MouseEvent evt) { try @@ -135,7 +140,8 @@ public class SplashScreen extends JPanel java.net.URL urllogo = getClass() .getResource("/images/Jalview_Logo_small.png"); - if (/** @j2sNative false || */ url != null) + if (/** @j2sNative false || */ + url != null) { image = java.awt.Toolkit.getDefaultToolkit().createImage(url); Image logo = java.awt.Toolkit.getDefaultToolkit() @@ -171,6 +177,7 @@ public class SplashScreen extends JPanel iframe.setLayer(JLayeredPane.PALETTE_LAYER); /** * we add image directly in html for javascript ? + * * @j2sNative */ { @@ -200,14 +207,21 @@ public class SplashScreen extends JPanel { iframe.setVisible(false); oldtext = newtext.length(); - if (/** @j2sNative true || */ false) + if (Platform.isJS()) // BH 2019 + // if (/** @j2sNative true || */ false) { - authlist = new JLabel("


"+newtext); + authlist = new JLabel( + "


" + + newtext); ((JLabel) authlist).setOpaque(true); ((JLabel) authlist).setBackground(Color.white); - } else { + } + else + { /** - * @j2sNative + * Java only + * + * @j2sNative */ { authlist = new JTextPane(); @@ -218,7 +232,7 @@ public class SplashScreen extends JPanel } } authlist.addMouseListener(closer); - + authlist.setVisible(true); authlist.setSize(new Dimension(750, 375)); add(authlist, BorderLayout.CENTER); @@ -236,6 +250,7 @@ public class SplashScreen extends JPanel /** * Create splash screen, display it and clear it off again. */ + @Override public void run() { initSplashScreenWindow(); @@ -297,9 +312,10 @@ public class SplashScreen extends JPanel public SplashImage(Image todisplay) { image = todisplay; - if (image!=null) - { setPreferredSize(new Dimension(image.getWidth(this) + 8, - image.getHeight(this))); + if (image != null) + { + setPreferredSize(new Dimension(image.getWidth(this) + 8, + image.getHeight(this))); } } @@ -309,6 +325,7 @@ public class SplashScreen extends JPanel return new Dimension(image.getWidth(this) + 8, image.getHeight(this)); } + @Override public void paintComponent(Graphics g) { g.setColor(Color.white); diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 04266be..8720341 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -32,6 +32,7 @@ import jalview.schemes.UserColourScheme; import jalview.util.ColorUtils; import jalview.util.Format; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.xml.binding.jalview.JalviewUserColours; import jalview.xml.binding.jalview.JalviewUserColours.Colour; import jalview.xml.binding.jalview.ObjectFactory; @@ -484,46 +485,49 @@ public class UserDefinedColours extends GUserDefinedColours protected void warnIfUnsavedChanges() { // BH 2018 no warning in JavaScript TODO - - if (/** @j2sNative true || */ !changedButNotSaved) - { - return; - } - String name = schemeName.getText().trim(); - if (oldColourScheme != null && !"".equals(name) - && name.equals(oldColourScheme.getSchemeName())) - { - String message = MessageManager.formatMessage("label.scheme_changed", - name); - String title = MessageManager.getString("label.save_changes"); - String[] options = new String[] { title, - MessageManager.getString("label.dont_save_changes"), }; - final String question = JvSwingUtils.wrapTooltip(true, message); - int response = JvOptionPane.showOptionDialog(Desktop.desktop, - question, title, JvOptionPane.DEFAULT_OPTION, - JvOptionPane.PLAIN_MESSAGE, null, options, options[0]); - - if (response == 0) + if (!Platform.isJS() && changedButNotSaved) + /** + * Java only + * + * @j2sNative + */ + { + String name = schemeName.getText().trim(); + if (oldColourScheme != null && !"".equals(name) + && name.equals(oldColourScheme.getSchemeName())) { - /* - * prompt to save changes to file; if done, - * resets 'changed' flag to false - */ - savebutton_actionPerformed(); - } + String message = MessageManager + .formatMessage("label.scheme_changed", name); + String title = MessageManager.getString("label.save_changes"); + String[] options = new String[] { title, + MessageManager.getString("label.dont_save_changes"), }; + final String question = JvSwingUtils.wrapTooltip(true, message); + int response = JvOptionPane.showOptionDialog(Desktop.desktop, + question, title, JvOptionPane.DEFAULT_OPTION, + JvOptionPane.PLAIN_MESSAGE, null, options, options[0]); + + if (response == 0) + { + /* + * prompt to save changes to file; if done, + * resets 'changed' flag to false + */ + savebutton_actionPerformed(); + } - /* - * if user chooses not to save (either in this dialog or in the - * save as dialogs), treat this as a new user defined colour scheme - */ - if (changedButNotSaved) - { /* - * clear scheme name and re-apply as an anonymous scheme + * if user chooses not to save (either in this dialog or in the + * save as dialogs), treat this as a new user defined colour scheme */ - schemeName.setText(""); - applyButton_actionPerformed(); + if (changedButNotSaved) + { + /* + * clear scheme name and re-apply as an anonymous scheme + */ + schemeName.setText(""); + applyButton_actionPerformed(); + } } } } diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index ba66889..acd0e18 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -221,6 +221,11 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI, int value = super.showOpenDialog(this); if (!Platform.isJS()) + /** + * Java only + * + * @j2sNative + */ { /* * code here is not run in JalviewJS, instead diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 1311405..1cd3d3b 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -1389,7 +1389,8 @@ public class AnnotationRenderer boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE; boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE; float ht = normaliseProfile ? y - _aa.graphHeight : y1; - final double normaliseFactor = normaliseProfile ? _aa.graphHeight : (y2 - y1); + final double normaliseFactor = normaliseProfile ? _aa.graphHeight + : (y2 - y1); /** * Render a single base for a sequence profile, a base pair for @@ -1440,7 +1441,7 @@ public class AnnotationRenderer s = new String(dc); } // next profl[] position is profile % for the character(s) - + int percent = profl[c++]; if (percent == 0) { @@ -1473,9 +1474,9 @@ public class AnnotationRenderer // (int)(scl)); // g.setColor(profcolour.findColour(dc[0]).darker()); - double sx = 1f * charWidth / fm.charsWidth(dc, 0, dc.length); + double sx = 1f * charWidth / fm.charsWidth(dc, 0, dc.length); double sy = newHeight / asc; - double newAsc = asc * sy; + double newAsc = asc * sy; double newDec = dec * sy; // it is not necessary to recalculate lm for the new font. // note: lm.getBaselineOffsets()[lm.getBaselineIndex()]) must be 0 @@ -1501,10 +1502,14 @@ public class AnnotationRenderer ht2 += newHeight; } else + /** + * Java only + * + * @j2sNative + */ { - /* - * Java ('normal') method is to scale the font to fit - */ + // Java ('normal') method is to scale the font to fit + final int hght = (int) (ht + (newAsc - newDec)); Font font = ofont .deriveFont(AffineTransform.getScaleInstance(sx, sy)); @@ -1523,7 +1528,7 @@ public class AnnotationRenderer Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 3f, new float[] - { 5f, 3f }, 0f)); + { 5f, 3f }, 0f)); y2 = (int) (y - ((_aa.threshold.value - min) / range) * _aa.graphHeight); diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 0bc49fa..e4ee197 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -35,29 +35,36 @@ import javax.swing.SwingUtilities; public class Platform { - private static boolean isJS = /** @j2sNative true || */false; + private static boolean isJS = /** @j2sNative true || */ + false; + + private static Boolean isNoJSMac = null, isNoJSWin = null, isMac = null, + isWin = null; - private static Boolean isNoJSMac = null, isNoJSWin = null, - isMac = null, isWin = null; - private static Boolean isHeadless = null; /** * added to group mouse events into Windows and nonWindows (mac, unix, linux) + * * @return */ public static boolean isMac() { - return (isMac == null ? (isMac = (System.getProperty("os.name").indexOf("Mac") >= 0)) : isMac); + return (isMac == null + ? (isMac = (System.getProperty("os.name").indexOf("Mac") >= 0)) + : isMac); } /** * added to group mouse events into Windows and nonWindows (mac, unix, linux) + * * @return */ - public static boolean isWin() + public static boolean isWin() { - return (isWin == null ? (isWin = (System.getProperty("os.name").indexOf("Win") >= 0)) : isWin); + return (isWin == null + ? (isWin = (System.getProperty("os.name").indexOf("Win") >= 0)) + : isWin); } /** @@ -66,7 +73,7 @@ public class Platform */ public static boolean isJS() { - return isJS; + return isJS; } /** @@ -78,18 +85,18 @@ public class Platform */ public static boolean isAMacAndNotJS() { - return (isNoJSMac == null ? (isNoJSMac = !isJS && isMac()) : isNoJSMac); + return (isNoJSMac == null ? (isNoJSMac = !isJS && isMac()) : isNoJSMac); } -/** + /** * Check if we are on a Microsoft plaform... * * @return true if we have to cope with another platform variation */ public static boolean isWindowsAndNotJS() { - return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin); - } + return (isNoJSWin == null ? (isNoJSWin = !isJS && isWin()) : isNoJSWin); + } /** * @@ -137,8 +144,8 @@ public class Platform /** * Answers true if the mouse event has Meta-down (Command key on Mac) or * Ctrl-down (on other o/s). Note this answers _false_ if the Ctrl key is - * pressed instead of the Meta/Cmd key on Mac. To test for Ctrl-pressed on Mac, - * you can use e.isPopupTrigger(). + * pressed instead of the Meta/Cmd key on Mac. To test for Ctrl-pressed on + * Mac, you can use e.isPopupTrigger(). * * @param e * @return @@ -157,14 +164,16 @@ public class Platform */ protected static boolean isControlDown(MouseEvent e, boolean aMac) { - if (!aMac) { - return e.isControlDown(); + if (!aMac) + { + return e.isControlDown(); } - // answer false for right mouse button - // shortcut key will be META for a Mac - return !e.isPopupTrigger() - && (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() & e.getModifiers()) != 0; - // could we use e.isMetaDown() here? + // answer false for right mouse button + // shortcut key will be META for a Mac + return !e.isPopupTrigger() + && (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + & e.getModifiers()) != 0; + // could we use e.isMetaDown() here? } // BH: I don't know about that previous method. Here is what SwingJS uses. @@ -196,204 +205,212 @@ public class Platform // /** - * Windows (not Mac, Linux, or Unix) and right button - * to test for the right-mouse pressed event in Windows - * that would have opened a menu or a Mac. + * Windows (not Mac, Linux, or Unix) and right button to test for the + * right-mouse pressed event in Windows that would have opened a menu or a + * Mac. * * @param e * @return */ - public static boolean isWinRightButton(MouseEvent e) + public static boolean isWinRightButton(MouseEvent e) { - // was !isAMac(), but that is true also for Linux and Unix and JS, + // was !isAMac(), but that is true also for Linux and Unix and JS, - return isWin() && SwingUtilities.isRightMouseButton(e); + return isWin() && SwingUtilities.isRightMouseButton(e); } - - + /** - * Windows (not Mac, Linux, or Unix) and middle button -- for mouse wheeling + * Windows (not Mac, Linux, or Unix) and middle button -- for mouse wheeling * without pressing the button. * * @param e * @return */ - public static boolean isWinMiddleButton(MouseEvent e) + public static boolean isWinMiddleButton(MouseEvent e) { - // was !isAMac(), but that is true also for Linux and Unix and JS - return isWin() && SwingUtilities.isMiddleMouseButton(e); + // was !isAMac(), but that is true also for Linux and Unix and JS + return isWin() && SwingUtilities.isMiddleMouseButton(e); } - public static boolean allowMnemonics() + public static boolean allowMnemonics() { - return !isMac(); + return !isMac(); } - + public final static int TIME_RESET = 0; - public final static int TIME_MARK = 1; - public static final int TIME_SET = 2; - public static final int TIME_GET = 3; - + + public final static int TIME_MARK = 1; + + public static final int TIME_SET = 2; + + public static final int TIME_GET = 3; + public static long time, mark, set, duration; - - public static void timeCheck(String msg, int mode) { - long t = System.currentTimeMillis(); - switch (mode) { - case TIME_RESET: - time = mark = t; - if (msg != null) + + public static void timeCheck(String msg, int mode) + { + long t = System.currentTimeMillis(); + switch (mode) + { + case TIME_RESET: + time = mark = t; + if (msg != null) { System.err.println("Platform: timer reset\t\t\t" + msg); } - break; - case TIME_MARK: - if (set > 0) { - duration += (t - set); - } else { - if (time == 0) + break; + case TIME_MARK: + if (set > 0) { - time = mark = t; + duration += (t - set); } - if (msg != null) + else + { + if (time == 0) + { + time = mark = t; + } + if (msg != null) { - System.err.println("Platform: timer mark\t" + ((t - time)/1000f) + "\t" + ((t - mark)/1000f) + "\t" + msg); + System.err.println("Platform: timer mark\t" + ((t - time) / 1000f) + + "\t" + ((t - mark) / 1000f) + "\t" + msg); } - mark = t; - } - break; - case TIME_SET: - set = t; - break; - case TIME_GET: - if (msg != null) + mark = t; + } + break; + case TIME_SET: + set = t; + break; + case TIME_GET: + if (msg != null) { - System.err.println("Platform: timer dur\t" + ((t - time)/1000f) + "\t" + ((duration)/1000f) + "\t" + msg); + System.err.println("Platform: timer dur\t" + ((t - time) / 1000f) + + "\t" + ((duration) / 1000f) + "\t" + msg); } - set = 0; - break; - } + set = 0; + break; + } } - public static void cacheFileData(String path, byte[] data) - { - if (!isJS()) + public static void cacheFileData(String path, byte[] data) { - return; - /** - * @j2sNative - * - * swingjs.JSUtil.cacheFileData$S$O(path, data); - * - */ - } + if (!isJS()) + { + return; + } + /** + * @j2sNative + * + * swingjs.JSUtil.cacheFileData$S$O(path, data); + * + */ } - public static byte[] getFileBytes(File f) + public static byte[] getFileBytes(File f) { - return /** @j2sNative f && f._bytes || */null; + return /** @j2sNative f && f._bytes || */ + null; } - public static byte[] getFileAsBytes(String fileStr) + public static byte[] getFileAsBytes(String fileStr) { // BH 2018 hack for no support for access-origin - return /** @j2sNative swingjs.JSUtil.getFileAsBytes$O(fileStr) || */ null; + return /** @j2sNative swingjs.JSUtil.getFileAsBytes$O(fileStr) || */ + null; } - public static String getFileAsString(String data) + public static String getFileAsString(String data) { - return /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ null; + return /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ + null; } - public static boolean setFileBytes(File f, String urlstring) + public static boolean setFileBytes(File f, String urlstring) { - if (!isJS()) - { - return false; - } - @SuppressWarnings("unused") - byte[] bytes = getFileAsBytes(urlstring); - /** @j2sNative - * f._bytes = bytes; - */ - return true; + if (!isJS()) + { + return false; + } + @SuppressWarnings("unused") + byte[] bytes = getFileAsBytes(urlstring); + /** + * @j2sNative f._bytes = bytes; + */ + return true; } - public static void addJ2SBinaryType(String ext) { - /** - * @j2sNative - * - * J2S._binaryTypes.push("." + ext + "?"); - * - */ + /** + * @j2sNative + * + * J2S._binaryTypes.push("." + ext + "?"); + * + */ } - public static String encodeURI(String value) + public static String encodeURI(String value) { /** - * @j2sNative - * return encodeURIComponent(value); + * @j2sNative return encodeURIComponent(value); */ - return value; + return value; } - public static boolean openURL(String url) - { - if (!isJS()) + public static boolean openURL(String url) { - return false; - } - /** - * @j2sNative - * - * - * window.open(url); - */ - return true; + if (!isJS()) + { + return false; + } + /** + * @j2sNative + * + * + * window.open(url); + */ + return true; } - public static String getUniqueAppletID() { - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative return g.html5Applet._uniqueId; - * - */ - return null; + public static String getUniqueAppletID() + { + @SuppressWarnings("unused") + ThreadGroup g = Thread.currentThread().getThreadGroup(); + /** + * @j2sNative return g.html5Applet._uniqueId; + * + */ + return null; + + } - } /** - * Read the Info block for this applet. + * Read the Info block for this applet. * - * @param prefix "jalview_" + * @param prefix + * "jalview_" * @param p - * @return unique id for this applet + * @return unique id for this applet */ - public static void readInfoProperties(String prefix, Properties p) + public static void readInfoProperties(String prefix, Properties p) { - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); - String id = getUniqueAppletID(); - String key = "", value = ""; - /** - * @j2sNative - var info = g.html5Applet.__Info || {}; - for (var key in info) { - if (key.indexOf(prefix) == 0) { - value = "" + info[key]; - */ - - p.put(id + "_" + key, value); - - /** - * @j2sNative - - - } - } - */ - } + @SuppressWarnings("unused") + ThreadGroup g = Thread.currentThread().getThreadGroup(); + String id = getUniqueAppletID(); + String key = "", value = ""; + /** + * @j2sNative var info = g.html5Applet.__Info || {}; for (var key in info) { + * if (key.indexOf(prefix) == 0) { value = "" + info[key]; + */ + p.put(id + "_" + key, value); + + /** + * @j2sNative + * + * + * } } + */ + } } -- 1.7.10.2