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;
/** 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()
{
public static void loadProperties(String propsFile)
{
propertiesFile = propsFile;
- if (propsFile == null)
+ if (propsFile == null && !propsAreReadOnly)
{
propertiesFile = System.getProperty("user.home") + File.separatorChar
+ ".jalview_properties";
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", ""),
}
// 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");
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;
import java.util.logging.Logger;
import javax.swing.LookAndFeel;
-import javax.swing.Timer;
import javax.swing.UIManager;
import groovy.lang.Binding;
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()
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");
void doMain(String[] args)
{
- if (!isJS())
+ if (!Platform.isJS())
{
System.setSecurityManager(null);
}
"CMD [-props " + usrPropsFile + "] executed successfully!");
}
- /**
- * BH 2018 ignoring this section for JS
- *
- * @j2sNative
- */
- {
+ if (!Platform.isJS()) {
if (aparser.contains("help") || aparser.contains("h"))
{
showUsage();
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"))
{
}
System.out.println("CMD [-open " + file + "] executed successfully!");
- if (!isJS() && !file.startsWith("http://"))
+ if (!Platform.isJS() && !file.startsWith("http://"))
{
if (!(new File(file)).exists())
{
// 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",
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()
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)
void doMain(String[] args)
{
- if (!isJS())
+ if (!Platform.isJS())
{
System.setSecurityManager(null);
}
}
System.out.println("CMD [-open " + file + "] executed successfully!");
- if (!isJS() && !file.startsWith("http://"))
+ if (!Platform.isJS() && !file.startsWith("http://"))
{
if (!(new File(file)).exists())
{
package jalview.bin;
+import jalview.util.Platform;
+
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
});
t.setRepeats(true);
- if (/** @j2sNative true || */
- false)
+ if (Platform.isJS())
t.start();
}
*/
package jalview.datamodel;
+import jalview.util.Platform;
+
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
public static String[] allSources()
{
+ if (Platform.isJS()) {
+ return allTypes;
+ }
/**
* @j2sNative
*
- * return C$.allTypes;
- *
*/
{
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
{
private String filePath;
private String pdbId;
-
+
private List<SequenceI> seqList;
// TODO and possibly a list of chains?
/**
* Constructor given structure file path and id.
*
+ * Curiously, only called by Jalview2XML.
+ *
* @param pdbFile
* @param id
*/
*/
package jalview.fts.service.pdb;
-import jalview.bin.Jalview;
import jalview.datamodel.SequenceI;
import jalview.fts.api.FTSData;
import jalview.fts.api.FTSDataColumnI;
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;
// different from the ones in Java yet still allow this to be correct for Java
Client client;
Class<ClientResponse> clientResponseClass;
- if (Jalview.isJS())
+ if (Platform.isJS())
{
// JavaScript only -- coerce types to Java types for Java
client = (Client) (Object) new jalview.javascript.web.Client();
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;
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;
// Java
Client client;
Class<ClientResponse> clientResponseClass;
- if (Jalview.isJS())
+ if (Platform.isJS())
{
// JavaScript only -- coerce types to Java types for Java
client = (Client) (Object) new jalview.javascript.web.Client();
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;
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;
if (Desktop.desktop != null)
{
this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
- /**
- * BH 2018 ignore service listeners
- *
- * @j2sNative
- *
- */
+ if (!Platform.isJS())
{
addServiceListeners();
}
{ contents.toString() });
contents = null;
- if (Jalview.isJS())
+ if (Platform.isJS())
{
JLabel textLabel = new JLabel();
textLabel.setText(content);
* are spawned off as threads rather than waited for during this constructor.
*/
instance = this;
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
doVamsasClientCheck();
}
// 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");
}
setBounds(xPos, yPos, 900, 650);
}
- boolean doFullLoad = /** @j2sNative ! */true;
+ boolean doFullLoad = !Platform.isJS();
if (doFullLoad) {
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)
{
*/
JComponent history;
String urlBase = "http://www.";
- if (Jalview.isJS())
+ if (Platform.isJS())
{
history = new JTextField(urlBase, 35);
}
@Override
public void run()
{
- String url = Jalview.isJS() ? ((JTextField) history).getText()
+ String url = Platform.isJS() ? ((JTextField) history).getText()
: ((JComboBox<String>) history).getSelectedItem()
.toString();
{
try
{
- if (Jalview.isJS())
+ if (Platform.isJS())
{
BrowserLauncher.openURL("http://www.jalview.org/help.html");
}
/**
* 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)
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;
* variable colour and filters dialog
*/
chooser = new FeatureTypeSettings(fr, type);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
chooser.setRequestFocusEnabled(true);
chooser.requestFocus();
*/
package jalview.gui;
-import jalview.bin.Jalview;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
void startScrolling(boolean up)
{
scrollThread = new ScrollThread(up);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
/*
* Java - run in a new thread
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;
String renderStyle = Cache.getDefault(
imageType.getName() + "_RENDERING",
LineartOptions.PROMPT_EACH_TIME);
- if (Jalview.isJS())
+ if (Platform.isJS())
{
renderStyle = "Text";
}
/**
* DOCUMENT ME!
*
- * @param file
+ * @param fileName
* DOCUMENT ME!
*/
public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
package jalview.gui;
-import jalview.bin.Jalview;
+import jalview.util.Platform;
import jalview.util.dialogrunner.DialogRunnerI;
import java.awt.Component;
public JvOptionPane(final Component parent)
{
- this.parentComponent = Jalview.isJS() ? this : parent;
+ this.parentComponent = Platform.isJS() ? this : parent;
}
public static int showConfirmDialog(Component parentComponent,
String prefix = "";
// JavaScript only
- if (Jalview.isJS())
+ if (Platform.isJS())
{
switch (messageType)
{
* In Java, the response is returned to this thread and handled here;
* (for Javascript, see propertyChange)
*/
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
handleResponse(response);
}
yesNoCancelOption, questionMessage, icon, options,
initresponse);
}
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
handleResponse(response);
}
* 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();
}
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;
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;
protected void showFeatureDetails(SequenceFeature sf)
{
JInternalFrame details;
- if (/** @j2sNative true || */ false)
+ if (Platform.isJS())
{
details = new JInternalFrame();
JPanel panel = new JPanel(new BorderLayout());
String report = contents.toString();
JInternalFrame frame;
- if (Jalview.isJS())
+ if (Platform.isJS())
{
JLabel textLabel = new JLabel();
textLabel.setText(report);
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;
super();
frame = new JInternalFrame();
frame.setContentPane(this);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
wsPrefs = new WsPreferences();
wsTab.add(wsPrefs, BorderLayout.CENTER);
/*
* 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"))
{
Cache.applicationProperties.setProperty("PAD_GAPS",
Boolean.toString(padGaps.isSelected()));
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
wsPrefs.updateAndRefreshWsMenuConfig(false);
}
{
try
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
wsPrefs.updateWsMenuConfig(true);
wsPrefs.refreshWs_actionPerformed(e);
public void defaultBrowser_mouseClicked(MouseEvent e)
{
// TODO: JAL-3048 not needed for j2s
+ if (Platform.isJS())
+ return;
/*
* @j2sNative
*/
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;
{
scrollThread = new ScrollThread();
scrollThread.setMousePosition(mousePos);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
/*
* Java - run in a new thread
*/
package jalview.gui;
+import jalview.util.Platform;
+
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
{
this.interactiveDialog = interactive;
// show a splashscreen that will disapper
- if (/** @j2sNative true || */ false)
+ if (Platform.isJS())
{
authlist = new JLabel("");
run();
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()
{
iframe.setVisible(false);
oldtext = newtext.length();
- if (/** @j2sNative true || */ false)
+ if (Platform.isJS())
{
authlist = new JLabel("<html><br/><br/><img src=\"swingjs/j2s/images/Jalview_Logo.png\"/><br/>"+newtext);
((JLabel) authlist).setOpaque(true);
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;
*/
protected void warnIfUnsavedChanges()
{
- // BH 2018 no warning in JavaScript TODO
-
- if (/** @j2sNative true || */ !changedButNotSaved)
+ if (Platform.isJS() || !changedButNotSaved)
{
return;
}
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)
{
}
{
protocol = DataSourceType.URL;
}
- else if (jalview.bin.Jalview.isJS())
+ else if (jalview.util.Platform.isJS())
{
protocol = DataSourceType.RELATIVE_URL;
}
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;
* @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));
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureSettingsModelI;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
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;
}
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;
package jalview.io;
import jalview.bin.Cache;
-import jalview.bin.Jalview;
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
import jalview.util.Platform;
{
int value = super.showOpenDialog(this);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
/*
* code here is not run in JalviewJS, instead
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;
public JvCacheableInputBox(String newCacheKey)
{
super();
- if (Jalview.isJS())
+ if (Platform.isJS())
{
textField = new JTextField();
return;
*/
public void updateCache()
{
- if (Jalview.isJS())
+ if (Platform.isJS())
{
return;
}
*/
public void persistCache()
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
appCache.persistCache(cacheKey);
}
*/
public String getUserInput()
{
- if (Jalview.isJS())
+ if (Platform.isJS())
{
return textField.getText().trim();
}
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);
}
public void addDocumentListener(DocumentListener listener)
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
((JTextComponent) comboBox.getEditor().getEditorComponent())
.getDocument().addDocumentListener(listener);
public void addFocusListener(FocusListener focusListener)
{
- if (Jalview.isJS())
+ if (Platform.isJS())
{
textField.addFocusListener(focusListener);
}
public void addKeyListener(KeyListener kl)
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
comboBox.getEditor().getEditorComponent().addKeyListener(kl);
}
public void setEditable(boolean b)
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
comboBox.setEditable(b);
}
public void setPrototypeDisplayValue(String string)
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
comboBox.setPrototypeDisplayValue(string);
}
public void setSelectedItem(String userInput)
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
comboBox.setSelectedItem(userInput);
}
public boolean isPopupVisible()
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
return comboBox.isPopupVisible();
}
public void addCaretListener(CaretListener caretListener)
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
((JTextComponent) comboBox.getEditor().getEditorComponent())
.addCaretListener(caretListener);
public void addItem(String item)
{
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
comboBox.addItem(item);
}
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
package jalview.javascript.web;
+import jalview.util.Platform;
+
import java.net.URI;
import java.net.URISyntaxException;
public WebResource queryParam(String key, String value)
{
params += (params == "" ? "?" : "&") + key + "=";
- /**
- * @j2sNative
- * value = encodeURIComponent(value);
- */
- params += value;
+ params += Platform.encodeURI(value);
return this;
}
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);
}
}
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;
alignFrameMenuBar.add(formatMenu);
alignFrameMenuBar.add(colourMenu);
alignFrameMenuBar.add(calculateMenu);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
alignFrameMenuBar.add(webService);
}
fileMenu.add(exportAnnotations);
fileMenu.add(loadTreeMenuItem);
fileMenu.add(associatedData);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
fileMenu.add(loadVcf);
}
calculateMenu.addSeparator();
calculateMenu.add(expandAlignment);
calculateMenu.add(extractScores);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
calculateMenu.addSeparator();
calculateMenu.add(runGroovy);
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);
}
package jalview.jbgui;
import jalview.api.AlignmentViewPanel;
-import jalview.bin.Jalview;
import jalview.io.FileFormatException;
import jalview.util.MessageManager;
import jalview.util.Platform;
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();
}
FileMenu.addSeparator();
FileMenu.add(saveAsJaxb);
FileMenu.add(loadAsJaxb);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
FileMenu.add(saveState);
FileMenu.add(loadState);
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);
*/
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;
/*
* 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"));
outputTab.add(userIdWidth);
outputTab.add(userIdWidthlabel);
outputTab.add(modellerOutput);
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
/*
* JalviewJS doesn't support Lineart option or SVG output
/*
* hide Chimera options in JalviewJS
*/
- if (Jalview.isJS())
+ if (Platform.isJS())
{
pathLabel.setVisible(false);
chimeraPath.setVisible(false);
visualTab.add(fontSizeCB);
visualTab.add(fontStyleCB);
- if (Jalview.isJS())
+ if (Platform.isJS())
{
startupCheckbox.setVisible(false);
startupFileTextfield.setVisible(false);
*/
private double dividerRatio;
+ private static boolean doSetDivider = !Platform.isJS(); // BH why? Old?
+
/**
* Constructor
*
* project
*/
int topFrameHeight = topFrame.getHeight();
- /**
- * TODO SplitFrame.setDividerLocation
- *
- * @j2sNative
- */
+ if (doSetDivider)
{
splitPane.setDividerSize(DIVIDER_SIZE);
if (topFrameHeight == 0)
}
else
{
- /**
- * @j2sNative
- */
+ if (doSetDivider)
{
((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null);
((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null);
public void setRelativeDividerLocation(double r)
{
this.dividerRatio = r;
- /**
- * @j2sNative
- */
+ // BH why?
+ if (!Platform.isJS())
{
splitPane.setDividerLocation(r);
}
*/
protected void setDividerLocation(int p)
{
- /**
- * @j2sNative
- */
+ if (doSetDivider )
{
splitPane.setDividerLocation(p);
}
// 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_";
// 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;
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;
// int hght = (int) (ht + (newAsc - newDec);
// - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
- if (Jalview.isJS())
+ if (Platform.isJS())
{
/*
* SwingJS does not implement font.deriveFont()
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.
*/
private static boolean loadClasses()
{
- /**
- * @j2sNative
- *
- */
+ if (!Platform.isJS())
{
switch (jvm)
{
*/
private static Object locateBrowser()
{
+ if (Platform.isJS())
+ return browser;
/**
* @j2sNative
*
public static void openURL(String url) throws IOException
{
+ if (Platform.openURL(url))
+ return;
/**
* @j2sNative
*
- * window.open(url);
- *
*
*/
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
+import java.io.File;
import javax.swing.SwingUtilities;
}
/**
+ * 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;
}
/**
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;
+}
+
+
}
* 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
import jalview.datamodel.DBRefSource;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
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;
package jalview.ws.utils;
+import jalview.util.Platform;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
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);
- */
}
}