From: hansonr Date: Sun, 24 Mar 2019 03:48:31 +0000 (-0500) Subject: j2sNative references moved to Platform X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=2810f6cc6d3d820dde63b324efb1c8119ec2a818 j2sNative references moved to Platform --- diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 6d23bd0..b018f9c 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -28,6 +28,7 @@ import jalview.schemes.UserColourScheme; import jalview.structure.StructureImportSettings; import jalview.urls.IdOrgSettings; import jalview.util.ColorUtils; +import jalview.util.Platform; import jalview.ws.sifts.SiftsSettings; import java.awt.Color; @@ -286,8 +287,7 @@ public class Cache /** Default file is ~/.jalview_properties */ static String propertiesFile; - private static boolean propsAreReadOnly = /** @j2sNative true || */ - false; + private static boolean propsAreReadOnly = Platform.isJS(); public static void initLogger() { @@ -340,7 +340,7 @@ public class Cache public static void loadProperties(String propsFile) { propertiesFile = propsFile; - if (propsFile == null) + if (propsFile == null && !propsAreReadOnly) { propertiesFile = System.getProperty("user.home") + File.separatorChar + ".jalview_properties"; @@ -351,38 +351,39 @@ public class Cache propsAreReadOnly = true; } - try - { - InputStream fis; - try - { - fis = new java.net.URL(propertiesFile).openStream(); - System.out.println( - "Loading jalview properties from : " + propertiesFile); - System.out.println( - "Disabling Jalview writing to user's local properties file."); - propsAreReadOnly = true; - - } catch (Exception ex) - { - fis = null; - } - if (fis == null) - { - fis = new FileInputStream(propertiesFile); - } - applicationProperties.clear(); - applicationProperties.load(fis); - - // remove any old build properties - - deleteBuildProperties(); - fis.close(); - } catch (Exception ex) - { - System.out.println("Error reading properties file: " + ex); + if (propertiesFile != null) { + try + { + InputStream fis; + try + { + fis = new java.net.URL(propertiesFile).openStream(); + System.out.println( + "Loading jalview properties from : " + propertiesFile); + System.out.println( + "Disabling Jalview writing to user's local properties file."); + propsAreReadOnly = true; + + } catch (Exception ex) + { + fis = null; + } + if (fis == null) + { + fis = new FileInputStream(propertiesFile); + } + applicationProperties.clear(); + applicationProperties.load(fis); + + // remove any old build properties + + deleteBuildProperties(); + fis.close(); + } catch (Exception ex) + { + System.out.println("Error reading properties file: " + ex); + } } - if (getDefault("USE_PROXY", false)) { String proxyServer = getDefault("PROXY_SERVER", ""), @@ -396,47 +397,55 @@ public class Cache } // LOAD THE AUTHORS FROM THE authors.props file + String authorDetails = (Platform.isJS() ? null : + "jar:" + .concat(Cache.class.getProtectionDomain().getCodeSource() + .getLocation().toString().concat("!/authors.props"))); + try { - String authorDetails = /** @j2sNative "xxx" || */ - "jar:" - .concat(Cache.class.getProtectionDomain().getCodeSource() - .getLocation().toString().concat("!/authors.props")); - - java.net.URL localJarFileURL = new java.net.URL(authorDetails); - - InputStream in = localJarFileURL.openStream(); - applicationProperties.load(in); - in.close(); - } catch (Exception ex) + if (authorDetails != null) { + 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); + authorDetails = null; + } + if (authorDetails == null) { - System.out.println("Error reading author details: " + ex); - applicationProperties.remove("AUTHORS"); - applicationProperties.remove("AUTHORFNAMES"); - applicationProperties.remove("YEAR"); + applicationProperties.remove("AUTHORS"); + applicationProperties.remove("AUTHORFNAMES"); + applicationProperties.remove("YEAR"); } // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW - try + String buildDetails = (Platform.isJS() ? null : + "jar:".concat(Cache.class.getProtectionDomain() + .getCodeSource().getLocation().toString() + .concat("!/.build_properties"))); + if (buildDetails != null) { - String buildDetails = /** @j2sNative "xxx" || */ - "jar:".concat(Cache.class.getProtectionDomain() - .getCodeSource().getLocation().toString() - .concat("!/.build_properties")); - - java.net.URL localJarFileURL = new java.net.URL(buildDetails); - - InputStream in = localJarFileURL.openStream(); - applicationProperties.load(in); - in.close(); - } catch (Exception ex) + try + { + 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); + buildDetails = null; + } + } + if (buildDetails == null) { - System.out.println("Error reading build details: " + ex); - applicationProperties.remove("VERSION"); + applicationProperties.remove("VERSION"); } - String jnlpVersion = System.getProperty("jalview.version"); String codeVersion = getProperty("VERSION"); String codeInstallation = getProperty("INSTALLATION"); diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 474c707..fbdb65f 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; @@ -102,21 +99,9 @@ public class Jalview public static AlignFrame currentAlignFrame; - /** - * Answers true if Jalview is running as Javascript, else false. The value is - * set at compile time. - * - * @return - */ - public static boolean isJS() - { - return /** @j2sNative true || */ - false; - } - static { - if (!isJS()) + if (!Platform.isJS()) { // BH 2018 // grab all the rights we can the JVM Policy.setPolicy(new Policy() @@ -229,7 +214,7 @@ public class Jalview private static void setLogging() { // BH - for event debugging in JavaScript (Java mode only) - if (!(/** @j2sNative true ||*/false)) + if (!Platform.isJS()) { Logger.getLogger("").setLevel(Level.ALL); logClass("java.awt.EventDispatchThread"); @@ -250,7 +235,7 @@ public class Jalview void doMain(String[] args) { - if (!isJS()) + if (!Platform.isJS()) { System.setSecurityManager(null); } @@ -272,12 +257,7 @@ public class Jalview "CMD [-props " + usrPropsFile + "] executed successfully!"); } - /** - * BH 2018 ignoring this section for JS - * - * @j2sNative - */ - { + if (!Platform.isJS()) { if (aparser.contains("help") || aparser.contains("h")) { showUsage(); @@ -413,13 +393,8 @@ public class Jalview desktop.setInBatchMode(true); // indicate we are starting up desktop.setVisible(true); - /** - * BH 2018 JS bypass this section - * - * @j2sNative - * - */ - { + + if (!Platform.isJS()) { desktop.startServiceDiscovery(); if (!aparser.contains("nousagestats")) { @@ -590,7 +565,7 @@ public class Jalview } System.out.println("CMD [-open " + file + "] executed successfully!"); - if (!isJS() && !file.startsWith("http://")) + if (!Platform.isJS() && !file.startsWith("http://")) { if (!(new File(file)).exists()) { @@ -834,8 +809,7 @@ public class Jalview // And the user // //////////////////// - if (/** @j2sNative false && */ // BH 2018 - !headless && file == null && vamsasImport == null + if (!Platform.isJS() && !headless && file == null && vamsasImport == null && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)) { file = jalview.bin.Cache.getDefault("STARTUP_FILE", diff --git a/src/jalview/bin/JalviewJS.java b/src/jalview/bin/JalviewJS.java index d7c4d19..70430ad 100644 --- a/src/jalview/bin/JalviewJS.java +++ b/src/jalview/bin/JalviewJS.java @@ -102,21 +102,9 @@ public class JalviewJS public static AlignFrame currentAlignFrame; - /** - * Answers true if Jalview is running as Javascript, else false. The value is - * set at compile time. - * - * @return - */ - public static boolean isJS() - { - return /** @j2sNative true || */ - false; - } - static { - if (!isJS()) + if (!Platform.isJS()) { // BH 2018 // grab all the rights we can the JVM Policy.setPolicy(new Policy() @@ -211,7 +199,9 @@ public class JalviewJS public static void main(String[] args) { instance = new JalviewJS(); - instance.doMain(new String[] {"open","http://www.jalview.org/examples/uniref50.fa", "-features","http://www.jalview.org/examples/exampleFeatures.txt"}); + instance.doMain( + Platform.isJS() ? new String[0] + : new String[] {"open","http://www.jalview.org/examples/uniref50.fa", "-features","http://www.jalview.org/examples/exampleFeatures.txt"}); } private static void logClass(String name) @@ -249,7 +239,7 @@ public class JalviewJS void doMain(String[] args) { - if (!isJS()) + if (!Platform.isJS()) { System.setSecurityManager(null); } @@ -589,7 +579,7 @@ public class JalviewJS } System.out.println("CMD [-open " + file + "] executed successfully!"); - if (!isJS() && !file.startsWith("http://")) + if (!Platform.isJS() && !file.startsWith("http://")) { if (!(new File(file)).exists()) { diff --git a/src/jalview/bin/JalviewJS2.java b/src/jalview/bin/JalviewJS2.java index eff5334..ad01256 100644 --- a/src/jalview/bin/JalviewJS2.java +++ b/src/jalview/bin/JalviewJS2.java @@ -1,5 +1,7 @@ package jalview.bin; +import jalview.util.Platform; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -60,8 +62,7 @@ private static void showFocusTimer() { }); t.setRepeats(true); - if (/** @j2sNative true || */ - false) + if (Platform.isJS()) t.start(); } diff --git a/src/jalview/datamodel/DBRefSource.java b/src/jalview/datamodel/DBRefSource.java index 47d1082..008bb7c 100755 --- a/src/jalview/datamodel/DBRefSource.java +++ b/src/jalview/datamodel/DBRefSource.java @@ -20,6 +20,8 @@ */ package jalview.datamodel; +import jalview.util.Platform; + import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; @@ -128,11 +130,12 @@ public class DBRefSource public static String[] allSources() { + if (Platform.isJS()) { + return allTypes; + } /** * @j2sNative * - * return C$.allTypes; - * */ { diff --git a/src/jalview/datamodel/StructureViewerModel.java b/src/jalview/datamodel/StructureViewerModel.java index 1b78948..b271afb 100644 --- a/src/jalview/datamodel/StructureViewerModel.java +++ b/src/jalview/datamodel/StructureViewerModel.java @@ -27,7 +27,8 @@ import java.util.List; import java.util.Map; /** - * A data bean to hold stored data about a structure viewer. + * A data bean to hold stored data about a structure viewer + * in the process of creating XML. */ public class StructureViewerModel { @@ -59,7 +60,7 @@ public class StructureViewerModel private String filePath; private String pdbId; - + private List seqList; // TODO and possibly a list of chains? @@ -67,6 +68,8 @@ public class StructureViewerModel /** * Constructor given structure file path and id. * + * Curiously, only called by Jalview2XML. + * * @param pdbFile * @param id */ diff --git a/src/jalview/fts/service/pdb/PDBFTSRestClient.java b/src/jalview/fts/service/pdb/PDBFTSRestClient.java index b4e5660..402efff 100644 --- a/src/jalview/fts/service/pdb/PDBFTSRestClient.java +++ b/src/jalview/fts/service/pdb/PDBFTSRestClient.java @@ -20,7 +20,6 @@ */ package jalview.fts.service.pdb; -import jalview.bin.Jalview; import jalview.datamodel.SequenceI; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; @@ -30,6 +29,7 @@ import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import jalview.util.JSONUtils; import jalview.util.MessageManager; +import jalview.util.Platform; import java.net.URI; import java.util.ArrayList; @@ -125,7 +125,7 @@ public class PDBFTSRestClient extends FTSRestClient // different from the ones in Java yet still allow this to be correct for Java Client client; Class clientResponseClass; - if (Jalview.isJS()) + if (Platform.isJS()) { // JavaScript only -- coerce types to Java types for Java client = (Client) (Object) new jalview.javascript.web.Client(); diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index c3ca893..e6620f8 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -22,7 +22,6 @@ package jalview.fts.service.uniprot; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; @@ -30,6 +29,7 @@ import jalview.fts.core.FTSRestClient; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import jalview.util.MessageManager; +import jalview.util.Platform; import java.util.ArrayList; import java.util.Collection; @@ -96,7 +96,7 @@ public class UniProtFTSRestClient extends FTSRestClient // Java Client client; Class clientResponseClass; - if (Jalview.isJS()) + if (Platform.isJS()) { // JavaScript only -- coerce types to Java types for Java client = (Client) (Object) new jalview.javascript.web.Client(); @@ -132,7 +132,7 @@ public class UniProtFTSRestClient extends FTSRestClient throw new Exception(errorMessage); } - int xTotalResults = Jalview.isJS() ? 1 + int xTotalResults = Platform.isJS() ? 1 : Integer.valueOf(clientResponse.getHeaders() .get("X-Total-Results").get(0)); clientResponse = null; diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 71ba94a..395fd98 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -89,6 +89,7 @@ import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.util.ImageMaker.TYPE; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; @@ -387,12 +388,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(); } @@ -3289,7 +3285,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { contents.toString() }); contents = null; - if (Jalview.isJS()) + if (Platform.isJS()) { JLabel textLabel = new JLabel(); textLabel.setText(content); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index f1b8025..1554079 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -350,7 +350,7 @@ public class Desktop extends jalview.jbgui.GDesktop * are spawned off as threads rather than waited for during this constructor. */ instance = this; - if (!Jalview.isJS()) + if (!Platform.isJS()) { doVamsasClientCheck(); } @@ -374,7 +374,7 @@ public class Desktop extends jalview.jbgui.GDesktop // getContentPane().add(sp, BorderLayout.CENTER); // BH 2018 - just an experiment to try unclipped JInternalFrames. - if (Jalview.isJS()) + if (Platform.isJS()) { getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); } @@ -404,7 +404,7 @@ public class Desktop extends jalview.jbgui.GDesktop setBounds(xPos, yPos, 900, 650); } - boolean doFullLoad = /** @j2sNative ! */true; + boolean doFullLoad = !Platform.isJS(); if (doFullLoad) { @@ -882,8 +882,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()); // BH this should not be necessary if (frame.getX() < 1 && frame.getY() < 1) { @@ -1178,7 +1177,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ JComponent history; String urlBase = "http://www."; - if (Jalview.isJS()) + if (Platform.isJS()) { history = new JTextField(urlBase, 35); } @@ -1206,7 +1205,7 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void run() { - String url = Jalview.isJS() ? ((JTextField) history).getText() + String url = Platform.isJS() ? ((JTextField) history).getText() : ((JComboBox) history).getSelectedItem() .toString(); @@ -1431,7 +1430,7 @@ public class Desktop extends jalview.jbgui.GDesktop { try { - if (Jalview.isJS()) + if (Platform.isJS()) { BrowserLauncher.openURL("http://www.jalview.org/help.html"); } @@ -2087,7 +2086,7 @@ public class Desktop extends jalview.jbgui.GDesktop /** * import file into a new vamsas session (uses jalview.gui.VamsasApplication) * - * @param file + * @param fileName * @return true if import was a success and a session was started. */ public boolean vamsasImport(URL url) diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 26cb104..b657ed3 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -22,7 +22,6 @@ package jalview.gui; import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsControllerI; -import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.datamodel.features.FeatureMatcher; @@ -1765,7 +1764,7 @@ class ColorEditor extends AbstractCellEditor * variable colour and filters dialog */ chooser = new FeatureTypeSettings(fr, type); - if (!Jalview.isJS()) + if (!Platform.isJS()) { chooser.setRequestFocusEnabled(true); chooser.requestFocus(); diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 9ee4750..d34c653 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.bin.Jalview; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -281,7 +280,7 @@ public class IdPanel extends JPanel void startScrolling(boolean up) { scrollThread = new ScrollThread(up); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * Java - run in a new thread diff --git a/src/jalview/gui/ImageExporter.java b/src/jalview/gui/ImageExporter.java index a43eef0..5fb6951 100644 --- a/src/jalview/gui/ImageExporter.java +++ b/src/jalview/gui/ImageExporter.java @@ -7,6 +7,7 @@ import jalview.io.JalviewFileView; import jalview.util.ImageMaker; import jalview.util.ImageMaker.TYPE; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.Component; import java.awt.Graphics; @@ -124,7 +125,7 @@ public class ImageExporter String renderStyle = Cache.getDefault( imageType.getName() + "_RENDERING", LineartOptions.PROMPT_EACH_TIME); - if (Jalview.isJS()) + if (Platform.isJS()) { renderStyle = "Text"; } diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index 9548839..465b5f9 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -104,7 +104,7 @@ public class Jalview2XML_V1 /** * DOCUMENT ME! * - * @param file + * @param fileName * DOCUMENT ME! */ public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider) diff --git a/src/jalview/gui/JvOptionPane.java b/src/jalview/gui/JvOptionPane.java index 2290b52..5bbe75f 100644 --- a/src/jalview/gui/JvOptionPane.java +++ b/src/jalview/gui/JvOptionPane.java @@ -21,7 +21,7 @@ package jalview.gui; -import jalview.bin.Jalview; +import jalview.util.Platform; import jalview.util.dialogrunner.DialogRunnerI; import java.awt.Component; @@ -58,7 +58,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, public JvOptionPane(final Component parent) { - this.parentComponent = Jalview.isJS() ? this : parent; + this.parentComponent = Platform.isJS() ? this : parent; } public static int showConfirmDialog(Component parentComponent, @@ -720,7 +720,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, String prefix = ""; // JavaScript only - if (Jalview.isJS()) + if (Platform.isJS()) { switch (messageType) { @@ -789,7 +789,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, * In Java, the response is returned to this thread and handled here; * (for Javascript, see propertyChange) */ - if (!Jalview.isJS()) + if (!Platform.isJS()) { handleResponse(response); } @@ -818,7 +818,7 @@ public class JvOptionPane extends JOptionPane implements DialogRunnerI, yesNoCancelOption, questionMessage, icon, options, initresponse); } - if (!Jalview.isJS()) + if (!Platform.isJS()) { handleResponse(response); } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 66634ee..34138aa 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -246,7 +246,7 @@ public class OverviewPanel extends JPanel * Javascript does not call componentResized on initial display, * so do the update here */ - boolean doUpdate = /** @j2sNative true || */ false; + boolean doUpdate = Platform.isJS(); if (doUpdate) updateOverviewImage(); } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 5f58d51..ec7ff22 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -25,7 +25,6 @@ import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; import jalview.analysis.Conservation; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.commands.ChangeCaseCommand; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; @@ -51,6 +50,7 @@ import jalview.schemes.PIDColourScheme; import jalview.util.GroupUrlLink; import jalview.util.GroupUrlLink.UrlStringTooLongException; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.util.StringUtils; import jalview.util.UrlLink; @@ -597,7 +597,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener protected void showFeatureDetails(SequenceFeature sf) { JInternalFrame details; - if (/** @j2sNative true || */ false) + if (Platform.isJS()) { details = new JInternalFrame(); JPanel panel = new JPanel(new BorderLayout()); @@ -1650,7 +1650,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener String report = contents.toString(); JInternalFrame frame; - if (Jalview.isJS()) + if (Platform.isJS()) { JLabel textLabel = new JLabel(); textLabel.setText(report); diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 6a558d5..6d1f79a 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -22,7 +22,6 @@ package jalview.gui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; import jalview.io.FileFormatI; @@ -189,7 +188,7 @@ public class Preferences extends GPreferences super(); frame = new JInternalFrame(); frame.setContentPane(this); - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsPrefs = new WsPreferences(); wsTab.add(wsPrefs, BorderLayout.CENTER); @@ -555,7 +554,7 @@ public class Preferences extends GPreferences /* * JalviewJS doesn't support Lineart so force it to Text */ - String defaultOption = Jalview.isJS() ? "Text" + String defaultOption = Platform.isJS() ? "Text" : Cache.getDefault(propertyKey, "Prompt each time"); if (defaultOption.equalsIgnoreCase("Text")) { @@ -820,7 +819,7 @@ public class Preferences extends GPreferences Cache.applicationProperties.setProperty("PAD_GAPS", Boolean.toString(padGaps.isSelected())); - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsPrefs.updateAndRefreshWsMenuConfig(false); } @@ -897,7 +896,7 @@ public class Preferences extends GPreferences { try { - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsPrefs.updateWsMenuConfig(true); wsPrefs.refreshWs_actionPerformed(e); @@ -1041,6 +1040,8 @@ public class Preferences extends GPreferences public void defaultBrowser_mouseClicked(MouseEvent e) { // TODO: JAL-3048 not needed for j2s + if (Platform.isJS()) + return; /* * @j2sNative */ diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 5e117ca..59f239f 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -22,7 +22,6 @@ package jalview.gui; import jalview.api.AlignViewportI; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; @@ -2054,7 +2053,7 @@ public class SeqPanel extends JPanel { scrollThread = new ScrollThread(); scrollThread.setMousePosition(mousePos); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * Java - run in a new thread diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index a122eb6..9f66402 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; @@ -86,7 +88,7 @@ public class SplashScreen extends JPanel { this.interactiveDialog = interactive; // show a splashscreen that will disapper - if (/** @j2sNative true || */ false) + if (Platform.isJS()) { authlist = new JLabel(""); run(); @@ -135,7 +137,7 @@ public class SplashScreen extends JPanel java.net.URL urllogo = getClass() .getResource("/images/Jalview_Logo_small.png"); - if (/** @j2sNative false || */ url != null) + if (!Platform.isJS() || url != null) { image = java.awt.Toolkit.getDefaultToolkit().createImage(url); Image logo = java.awt.Toolkit.getDefaultToolkit() @@ -200,7 +202,7 @@ public class SplashScreen extends JPanel { iframe.setVisible(false); oldtext = newtext.length(); - if (/** @j2sNative true || */ false) + if (Platform.isJS()) { authlist = new JLabel("


"+newtext); ((JLabel) authlist).setOpaque(true); diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 04266be..94f9a37 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; @@ -483,9 +484,7 @@ public class UserDefinedColours extends GUserDefinedColours */ protected void warnIfUnsavedChanges() { - // BH 2018 no warning in JavaScript TODO - - if (/** @j2sNative true || */ !changedButNotSaved) + if (Platform.isJS() || !changedButNotSaved) { return; } @@ -747,12 +746,12 @@ public class UserDefinedColours extends GUserDefinedColours if (ColourSchemes.getInstance().nameExists(name)) { // BH 2018 SwingJS bypasses this question with YES_OPTION - int reply = /** @j2sNative 0 && */ JvOptionPane.showInternalConfirmDialog(Desktop.desktop, + int reply = (Platform.isJS() ? 0 : JvOptionPane.showInternalConfirmDialog(Desktop.desktop, MessageManager.formatMessage( "label.colour_scheme_exists_overwrite", new Object[] { name, name }), MessageManager.getString("label.duplicate_scheme_name"), - JvOptionPane.YES_NO_OPTION); + JvOptionPane.YES_NO_OPTION)); if (reply != JvOptionPane.YES_OPTION) { } diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 8c376fc..f4c1b89 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -444,7 +444,7 @@ public class AppletFormatAdapter { protocol = DataSourceType.URL; } - else if (jalview.bin.Jalview.isJS()) + else if (jalview.util.Platform.isJS()) { protocol = DataSourceType.RELATIVE_URL; } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index f244d14..4be15d9 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -39,6 +39,7 @@ import jalview.project.Jalview2XML; import jalview.schemes.ColourSchemeI; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.ws.utils.UrlDownloadClient; import java.io.BufferedReader; @@ -646,12 +647,11 @@ public class FileLoader implements Runnable * @return * @throws FileNotFoundException */ - @SuppressWarnings("unused") public static BufferedReader getBuffereReader(Object file) throws FileNotFoundException { if (file instanceof String) return new BufferedReader(new FileReader((String) file)); - byte[] bytes = /** @j2sNative file._bytes || */ null; + byte[] bytes = Platform.getFileBytes((File) file); if (bytes != null) return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes))); return new BufferedReader(new FileReader((File) file)); diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 809bc8f..80b6836 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -25,6 +25,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsModelI; import jalview.util.MessageManager; +import jalview.util.Platform; import java.io.BufferedReader; import java.io.ByteArrayInputStream; @@ -333,12 +334,7 @@ public class FileParse private void parse(File file, String fileStr, DataSourceType sourceType, boolean isFileObject) throws MalformedURLException, IOException { - /** - * @j2sNative - * - * this.bytes = file && file._bytes; - * - */ + bytes = Platform.getFileBytes(file); this.dataSourceType = sourceType; error = false; @@ -375,15 +371,7 @@ public class FileParse } else if (sourceType == DataSourceType.RELATIVE_URL) { - /** - * BH 2018 hack for no support for access-origin - * - * @j2sNative - * - * this.bytes = swingjs.JSUtil.getFileAsBytes$O(fileStr); - * - */ - + bytes = Platform.getFileAsBytes(fileStr); dataIn = new BufferedReader(new java.io.InputStreamReader(new ByteArrayInputStream(bytes))); dataName = fileStr; diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index f6455bf..67f1115 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -22,7 +22,6 @@ package jalview.io; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.gui.JvOptionPane; import jalview.util.MessageManager; import jalview.util.Platform; @@ -194,7 +193,7 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI, { int value = super.showOpenDialog(this); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * code here is not run in JalviewJS, instead diff --git a/src/jalview/io/cache/JvCacheableInputBox.java b/src/jalview/io/cache/JvCacheableInputBox.java index b1b7ac5..cf21c62 100644 --- a/src/jalview/io/cache/JvCacheableInputBox.java +++ b/src/jalview/io/cache/JvCacheableInputBox.java @@ -21,8 +21,8 @@ package jalview.io.cache; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -92,7 +92,7 @@ public class JvCacheableInputBox public JvCacheableInputBox(String newCacheKey) { super(); - if (Jalview.isJS()) + if (Platform.isJS()) { textField = new JTextField(); return; @@ -202,7 +202,7 @@ public class JvCacheableInputBox */ public void updateCache() { - if (Jalview.isJS()) + if (Platform.isJS()) { return; } @@ -278,7 +278,7 @@ public class JvCacheableInputBox */ public void persistCache() { - if (!Jalview.isJS()) + if (!Platform.isJS()) { appCache.persistCache(cacheKey); } @@ -291,7 +291,7 @@ public class JvCacheableInputBox */ public String getUserInput() { - if (Jalview.isJS()) + if (Platform.isJS()) { return textField.getText().trim(); } @@ -301,12 +301,12 @@ public class JvCacheableInputBox public JComponent getComponent() { - return Jalview.isJS() ? textField : comboBox; + return Platform.isJS() ? textField : comboBox; } public void addActionListener(ActionListener actionListener) { - if (Jalview.isJS()) + if (Platform.isJS()) { textField.addActionListener(actionListener); } @@ -318,7 +318,7 @@ public class JvCacheableInputBox public void addDocumentListener(DocumentListener listener) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { ((JTextComponent) comboBox.getEditor().getEditorComponent()) .getDocument().addDocumentListener(listener); @@ -327,7 +327,7 @@ public class JvCacheableInputBox public void addFocusListener(FocusListener focusListener) { - if (Jalview.isJS()) + if (Platform.isJS()) { textField.addFocusListener(focusListener); } @@ -339,7 +339,7 @@ public class JvCacheableInputBox public void addKeyListener(KeyListener kl) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.getEditor().getEditorComponent().addKeyListener(kl); } @@ -347,7 +347,7 @@ public class JvCacheableInputBox public void setEditable(boolean b) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.setEditable(b); } @@ -355,7 +355,7 @@ public class JvCacheableInputBox public void setPrototypeDisplayValue(String string) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.setPrototypeDisplayValue(string); } @@ -363,7 +363,7 @@ public class JvCacheableInputBox public void setSelectedItem(String userInput) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.setSelectedItem(userInput); } @@ -371,7 +371,7 @@ public class JvCacheableInputBox public boolean isPopupVisible() { - if (!Jalview.isJS()) + if (!Platform.isJS()) { return comboBox.isPopupVisible(); } @@ -380,7 +380,7 @@ public class JvCacheableInputBox public void addCaretListener(CaretListener caretListener) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { ((JTextComponent) comboBox.getEditor().getEditorComponent()) .addCaretListener(caretListener); @@ -389,7 +389,7 @@ public class JvCacheableInputBox public void addItem(String item) { - if (!Jalview.isJS()) + if (!Platform.isJS()) { comboBox.addItem(item); } diff --git a/src/jalview/javascript/json/JSON.java b/src/jalview/javascript/json/JSON.java index a1de56e..714f04f 100644 --- a/src/jalview/javascript/json/JSON.java +++ b/src/jalview/javascript/json/JSON.java @@ -162,7 +162,7 @@ public class JSON { public JSONReader(String json) { super((Reader) (Object) ""); - data = toObject(/** @j2sNative swingjs.JSUtil.parseJSON$S(json)|| */null); + data = toObject(/** @j2sNative swingjs.JSUtil.parseJSONRaw$S(json)|| */null); } @Override diff --git a/src/jalview/javascript/web/WebResource.java b/src/jalview/javascript/web/WebResource.java index 6d12932..588dd49 100644 --- a/src/jalview/javascript/web/WebResource.java +++ b/src/jalview/javascript/web/WebResource.java @@ -1,5 +1,7 @@ package jalview.javascript.web; +import jalview.util.Platform; + import java.net.URI; import java.net.URISyntaxException; @@ -19,11 +21,7 @@ public class WebResource public WebResource queryParam(String key, String value) { params += (params == "" ? "?" : "&") + key + "="; - /** - * @j2sNative - * value = encodeURIComponent(value); - */ - params += value; + params += Platform.encodeURI(value); return this; } @@ -60,7 +58,7 @@ public class WebResource public ClientResponse get(Class c) { String data = uri.toString(); // c will be ClientResponse - data = /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ null; + data = Platform.getFileAsString(data); return new ClientResponse(data, encoding); } } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 15d5713..2e6aab8 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -23,7 +23,6 @@ package jalview.jbgui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.api.SplitContainerI; import jalview.bin.Cache; -import jalview.bin.Jalview; import jalview.gui.JvSwingUtils; import jalview.gui.Preferences; import jalview.io.FileFormats; @@ -1711,7 +1710,7 @@ public class GAlignFrame extends JInternalFrame alignFrameMenuBar.add(formatMenu); alignFrameMenuBar.add(colourMenu); alignFrameMenuBar.add(calculateMenu); - if (!Jalview.isJS()) + if (!Platform.isJS()) { alignFrameMenuBar.add(webService); } @@ -1732,7 +1731,7 @@ public class GAlignFrame extends JInternalFrame fileMenu.add(exportAnnotations); fileMenu.add(loadTreeMenuItem); fileMenu.add(associatedData); - if (!Jalview.isJS()) + if (!Platform.isJS()) { fileMenu.add(loadVcf); } @@ -1830,7 +1829,7 @@ public class GAlignFrame extends JInternalFrame calculateMenu.addSeparator(); calculateMenu.add(expandAlignment); calculateMenu.add(extractScores); - if (!Jalview.isJS()) + if (!Platform.isJS()) { calculateMenu.addSeparator(); calculateMenu.add(runGroovy); @@ -1839,14 +1838,14 @@ public class GAlignFrame extends JInternalFrame webServiceNoServices = new JMenuItem( MessageManager.getString("label.no_services")); webService.add(webServiceNoServices); - if (!Jalview.isJS()) + if (!Platform.isJS()) { exportImageMenu.add(htmlMenuItem); } exportImageMenu.add(epsFile); exportImageMenu.add(createPNG); exportImageMenu.add(createBioJS); - if (!Jalview.isJS()) + if (!Platform.isJS()) { exportImageMenu.add(createSVG); } diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index b301f6e..7dfc3d4 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -21,7 +21,6 @@ package jalview.jbgui; import jalview.api.AlignmentViewPanel; -import jalview.bin.Jalview; import jalview.io.FileFormatException; import jalview.util.MessageManager; import jalview.util.Platform; @@ -48,17 +47,7 @@ public class GDesktop extends JFrame public static javax.swing.JTabbedPane createTabbedPane() { - // now just always return JTabbedPane return new javax.swing.JTabbedPane(); -// // BH 2018 coercing jalview.jbgui.swing.JTabbedPane() for now -// if (/** @j2sNative false && */ -// true) -// { -// // Java -// return new javax.swing.JTabbedPane(); -// } -// // JavaScript -// return (javax.swing.JTabbedPane) (Object) new jalview.jbgui.swing.JTabbedPane(); } @@ -464,7 +453,7 @@ public class GDesktop extends JFrame FileMenu.addSeparator(); FileMenu.add(saveAsJaxb); FileMenu.add(loadAsJaxb); - if (!Jalview.isJS()) + if (!Platform.isJS()) { FileMenu.add(saveState); FileMenu.add(loadState); @@ -480,12 +469,12 @@ public class GDesktop extends JFrame VamsasMenu.add(vamsasSave); VamsasMenu.add(vamsasStop); toolsMenu.add(preferences); - if (!Jalview.isJS()) + if (!Platform.isJS()) { toolsMenu.add(showMemusage); toolsMenu.add(showConsole); } - if (!Jalview.isJS()) + if (!Platform.isJS()) { toolsMenu.add(showNews); toolsMenu.add(garbageCollect); diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 9fc0398..1e01cc3 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -20,13 +20,13 @@ */ package jalview.jbgui; -import jalview.bin.Jalview; import jalview.fts.core.FTSDataColumnPreferences; import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource; import jalview.fts.service.pdb.PDBFTSRestClient; import jalview.gui.JvSwingUtils; import jalview.gui.StructureViewer.ViewerType; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.BorderLayout; import java.awt.Color; @@ -329,7 +329,7 @@ public class GPreferences extends JPanel /* * See WsPreferences for the real work of configuring this tab. */ - if (!Jalview.isJS()) + if (!Platform.isJS()) { wsTab.setLayout(new BorderLayout()); tabbedPane.add(wsTab, MessageManager.getString("label.web_services")); @@ -514,7 +514,7 @@ public class GPreferences extends JPanel outputTab.add(userIdWidth); outputTab.add(userIdWidthlabel); outputTab.add(modellerOutput); - if (!Jalview.isJS()) + if (!Platform.isJS()) { /* * JalviewJS doesn't support Lineart option or SVG output @@ -1289,7 +1289,7 @@ public class GPreferences extends JPanel /* * hide Chimera options in JalviewJS */ - if (Jalview.isJS()) + if (Platform.isJS()) { pathLabel.setVisible(false); chimeraPath.setVisible(false); @@ -1674,7 +1674,7 @@ public class GPreferences extends JPanel visualTab.add(fontSizeCB); visualTab.add(fontStyleCB); - if (Jalview.isJS()) + if (Platform.isJS()) { startupCheckbox.setVisible(false); startupFileTextfield.setVisible(false); diff --git a/src/jalview/jbgui/GSplitFrame.java b/src/jalview/jbgui/GSplitFrame.java index a40e260..db346b8 100644 --- a/src/jalview/jbgui/GSplitFrame.java +++ b/src/jalview/jbgui/GSplitFrame.java @@ -49,6 +49,8 @@ public class GSplitFrame extends JInternalFrame */ private double dividerRatio; + private static boolean doSetDivider = !Platform.isJS(); // BH why? Old? + /** * Constructor * @@ -79,11 +81,7 @@ public class GSplitFrame extends JInternalFrame * project */ int topFrameHeight = topFrame.getHeight(); - /** - * TODO SplitFrame.setDividerLocation - * - * @j2sNative - */ + if (doSetDivider) { splitPane.setDividerSize(DIVIDER_SIZE); if (topFrameHeight == 0) @@ -118,9 +116,7 @@ public class GSplitFrame extends JInternalFrame } else { - /** - * @j2sNative - */ + if (doSetDivider) { ((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null); ((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null); @@ -212,9 +208,8 @@ public class GSplitFrame extends JInternalFrame public void setRelativeDividerLocation(double r) { this.dividerRatio = r; - /** - * @j2sNative - */ + // BH why? + if (!Platform.isJS()) { splitPane.setDividerLocation(r); } @@ -227,9 +222,7 @@ public class GSplitFrame extends JInternalFrame */ protected void setDividerLocation(int p) { - /** - * @j2sNative - */ + if (doSetDivider ) { splitPane.setDividerLocation(p); } diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 646cab5..efe643e 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -191,21 +191,9 @@ public class Jalview2XML // BH 2018 we add the .jvp binary extension to J2S so that // it will declare that binary when we do the file save from the browser - private static void addJ2SBinaryType(String ext) - { - ext = "." + ext + "?"; - - /** - * @j2sNative - * - * J2S._binaryTypes.push(ext); - * - */ - } - static { - addJ2SBinaryType(".jvp?"); + Platform.addJ2SBinaryType(".jvp?"); } private static final String VIEWER_PREFIX = "viewer_"; @@ -2531,8 +2519,7 @@ public class Jalview2XML // BH 2018 allow for bytes already attached to File object try { String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString()); - byte[] bytes = /** @j2sNative ofile._bytes || */ - null; + byte[] bytes = Platform.getFileBytes((File) ofile); URL url = null; errorMessage = null; uniqueSetSuffix = null; diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 4d3445b..ed266ae 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -25,7 +25,6 @@ import jalview.analysis.CodingUtils; import jalview.analysis.Rna; import jalview.analysis.StructureFrequency; import jalview.api.AlignViewportI; -import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; @@ -1485,7 +1484,7 @@ public class AnnotationRenderer // int hght = (int) (ht + (newAsc - newDec); // - lm.getBaselineOffsets()[lm.getBaselineIndex()])); - if (Jalview.isJS()) + if (Platform.isJS()) { /* * SwingJS does not implement font.deriveFont() diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java index a55a65c..5ce996d 100755 --- a/src/jalview/util/BrowserLauncher.java +++ b/src/jalview/util/BrowserLauncher.java @@ -236,87 +236,88 @@ public class BrowserLauncher loadedWithoutErrors = true; - /** - * - * @j2sNative - * - */ - { - String osName = System.getProperty("os.name"); - - if (osName.startsWith("Mac OS")) - { - String mrjVersion = System.getProperty("mrj.version"); - String majorMRJVersion; - if (mrjVersion == null) - { - // must be on some later build with mrj support - majorMRJVersion = "3.1"; - } - else - { - majorMRJVersion = mrjVersion.substring(0, 3); - } - - try - { - double version = Double.valueOf(majorMRJVersion).doubleValue(); - - if (version == 2) - { - jvm = MRJ_2_0; - } - else if ((version >= 2.1) && (version < 3)) - { - // Assume that all 2.x versions of MRJ work the same. MRJ 2.1 actually - // works via Runtime.exec() and 2.2 supports that but has an openURL() - // method - // as well that we currently ignore. - jvm = MRJ_2_1; - } - else if (version == 3.0) - { - jvm = MRJ_3_0; - } - else if (version >= 3.1) - { - // Assume that all 3.1 and later versions of MRJ work the same. - jvm = MRJ_3_1; - } - else - { - loadedWithoutErrors = false; - errorMessage = "Unsupported MRJ version: " + version; - } - } catch (NumberFormatException nfe) - { - loadedWithoutErrors = false; - errorMessage = "Invalid MRJ version: " + mrjVersion; - } - } - else if (osName.startsWith("Windows")) - { - if (osName.indexOf("9") != -1) - { - jvm = WINDOWS_9x; - } - else - { - jvm = WINDOWS_NT; - } - } - else - { - jvm = OTHER; - } - - if (loadedWithoutErrors) - { // if we haven't hit any errors yet - loadedWithoutErrors = loadClasses(); - } - } + if (!Platform.isJS()) { + /** + * + * @j2sNative + * + */ + { + String osName = System.getProperty("os.name"); + + if (osName.startsWith("Mac OS")) + { + String mrjVersion = System.getProperty("mrj.version"); + String majorMRJVersion; + if (mrjVersion == null) + { + // must be on some later build with mrj support + majorMRJVersion = "3.1"; + } + else + { + majorMRJVersion = mrjVersion.substring(0, 3); + } + + try + { + double version = Double.valueOf(majorMRJVersion).doubleValue(); + + if (version == 2) + { + jvm = MRJ_2_0; + } + else if ((version >= 2.1) && (version < 3)) + { + // Assume that all 2.x versions of MRJ work the same. MRJ 2.1 actually + // works via Runtime.exec() and 2.2 supports that but has an openURL() + // method + // as well that we currently ignore. + jvm = MRJ_2_1; + } + else if (version == 3.0) + { + jvm = MRJ_3_0; + } + else if (version >= 3.1) + { + // Assume that all 3.1 and later versions of MRJ work the same. + jvm = MRJ_3_1; + } + else + { + loadedWithoutErrors = false; + errorMessage = "Unsupported MRJ version: " + version; + } + } catch (NumberFormatException nfe) + { + loadedWithoutErrors = false; + errorMessage = "Invalid MRJ version: " + mrjVersion; + } + } + else if (osName.startsWith("Windows")) + { + if (osName.indexOf("9") != -1) + { + jvm = WINDOWS_9x; + } + else + { + jvm = WINDOWS_NT; + } + } + else + { + jvm = OTHER; + } + + if (loadedWithoutErrors) + { // if we haven't hit any errors yet + loadedWithoutErrors = loadClasses(); + } + } + } } - /** * This class should be never be instantiated; this just ensures so. */ @@ -334,10 +335,7 @@ public class BrowserLauncher private static boolean loadClasses() { - /** - * @j2sNative - * - */ + if (!Platform.isJS()) { switch (jvm) { @@ -538,6 +536,8 @@ public class BrowserLauncher */ private static Object locateBrowser() { + if (Platform.isJS()) + return browser; /** * @j2sNative * @@ -735,11 +735,11 @@ public class BrowserLauncher public static void openURL(String url) throws IOException { + if (Platform.openURL(url)) + return; /** * @j2sNative * - * window.open(url); - * * */ diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 1f03f88..0a788d9 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -22,6 +22,7 @@ package jalview.util; import java.awt.Toolkit; import java.awt.event.MouseEvent; +import java.io.File; import javax.swing.SwingUtilities; @@ -59,12 +60,14 @@ public class Platform } /** + * Answers true if Jalview is running as Javascript, else false. The value is + * set at compile time. * - * @return true if HTML5 JavaScript + * @return */ public static boolean isJS() { - return isJS; + return /** @j2sNative true || */ false; } /** @@ -219,5 +222,74 @@ public class Platform break; } } + +public static void cacheFileData(String path, byte[] data) { + if (!isJS()) + return; + /** + * @j2sNative + * + * swingjs.JSUtil.cacheFileData$S$O(path, data); + * + */ +} + +public static byte[] getFileBytes(File f) { + return /** @j2sNative f && f._bytes || */null; +} + +public static byte[] getFileAsBytes(String fileStr) { + // BH 2018 hack for no support for access-origin + return /** @j2sNative swingjs.JSUtil.getFileAsBytes$O(fileStr) || */ null; +} + +public static String getFileAsString(String data) { + return /** @j2sNative swingjs.JSUtil.getFileAsString$S(data) || */ null; +} + +public static boolean setFileBytes(File f, String urlstring) { + if (!isJS()) + return false; + @SuppressWarnings("unused") + byte[] bytes = getFileAsBytes(urlstring); + /** @j2sNative + * f._bytes = bytes; + */ + return true; +} + +public static void addJ2SBinaryType(String ext) +{ + ext = "." + ext + "?"; + + /** + * @j2sNative + * + * J2S._binaryTypes.push(ext); + * + */ +} + +public static String encodeURI(String value) { + /** + * @j2sNative + * return encodeURIComponent(value); + */ + return value; +} + +public static boolean openURL(String url) { + if (!isJS()) + return false; + /** + * @j2sNative + * + * + * window.open(url); + */ + return true; +} + + } diff --git a/src/jalview/ws/dbsources/EmblXmlSource.java b/src/jalview/ws/dbsources/EmblXmlSource.java index 668aab5..6d0c60b 100644 --- a/src/jalview/ws/dbsources/EmblXmlSource.java +++ b/src/jalview/ws/dbsources/EmblXmlSource.java @@ -116,7 +116,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy * either EMBL or EMBLCDS strings are allowed - anything else will * not retrieve emblxml * @param query - * @param file + * @param fileName * the EMBL XML file containing the results of a query * @return * @throws Exception diff --git a/src/jalview/ws/ebi/EBIFetchClient.java b/src/jalview/ws/ebi/EBIFetchClient.java index 5dc3c94..d8bd1dd 100644 --- a/src/jalview/ws/ebi/EBIFetchClient.java +++ b/src/jalview/ws/ebi/EBIFetchClient.java @@ -22,6 +22,7 @@ package jalview.ws.ebi; import jalview.datamodel.DBRefSource; import jalview.util.MessageManager; +import jalview.util.Platform; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -216,12 +217,14 @@ public class EBIFetchClient InputStream is = new BufferedInputStream(conn.getInputStream()); if (outFile != null) { + if (Platform.isJS()) { /**@j2sNative * if (outFile._isTemp) { * outFile._bytes = is.$in.$in.buf; * return null; * } */ + } FileOutputStream fio = new FileOutputStream(outFile); byte[] bb = new byte[32 * 1024]; int l; diff --git a/src/jalview/ws/utils/UrlDownloadClient.java b/src/jalview/ws/utils/UrlDownloadClient.java index cfe080c..77fbd5b 100644 --- a/src/jalview/ws/utils/UrlDownloadClient.java +++ b/src/jalview/ws/utils/UrlDownloadClient.java @@ -21,6 +21,8 @@ package jalview.ws.utils; +import jalview.util.Platform; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; @@ -114,13 +116,8 @@ public class UrlDownloadClient public static void download(String urlstring, File tempFile) throws IOException { - if (/** @j2sNative 1?false: */true) { - download(urlstring, tempFile.toString()); + if (!Platform.setFileBytes(tempFile, urlstring)) { + download(urlstring, tempFile.toString()); } - // JavaScript only - - /** @j2sNative - * tempFile._bytes = swingjs.JSUtil.getFileAsBytes(urlstring); - */ } }