import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.Semaphore;
import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.ActionMap;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultDesktopManager;
import javax.swing.DesktopManager;
+import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
+import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
public static MyDesktopPane desktop;
+ public static MyDesktopPane getDesktop()
+ {
+ // BH 2018 could use currentThread() here as a reference to a
+ // Hashtable<Thread, MyDesktopPane> in JavaScript
+ return desktop;
+ }
+
static int openFrameCount = 0;
static final int xOffset = 30;
else
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- setBounds((screenSize.width - 900) / 2, (screenSize.height - 650) / 2,
- 900, 650);
+ int xPos = Math.max(5, (screenSize.width - 900) / 2);
+ int yPos = Math.max(5, (screenSize.height - 650) / 2);
+ setBounds(xPos, yPos, 900, 650);
}
- jconsole = new Console(this, showjconsole);
- // add essential build information
- jconsole.setHeader(
- "Jalview Version: " + jalview.bin.Cache.getProperty("VERSION")
- + "\n" + "Jalview Installation: "
- + jalview.bin.Cache.getDefault("INSTALLATION",
- "unknown")
- + "\n" + "Build Date: "
- + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")
- + "\n" + "Java version: "
- + System.getProperty("java.version") + "\n"
- + System.getProperty("os.arch") + " "
- + System.getProperty("os.name") + " "
- + System.getProperty("os.version"));
+ /**
+ * BH 2018
+ *
+ * @j2sNative
+ */
+ {
+
+ jconsole = new Console(this, showjconsole);
+ // add essential build information
+ jconsole.setHeader("Jalview Version: "
+ + jalview.bin.Cache.getProperty("VERSION") + "\n"
+ + "Jalview Installation: "
+ + jalview.bin.Cache.getDefault("INSTALLATION", "unknown")
+ + "\n" + "Build Date: "
+ + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
+ + "Java version: " + System.getProperty("java.version") + "\n"
+ + System.getProperty("os.arch") + " "
+ + System.getProperty("os.name") + " "
+ + System.getProperty("os.version"));
- showConsole(showjconsole);
+ showConsole(showjconsole);
+
+ showNews.setVisible(false);
+
+ experimentalFeatures.setSelected(showExperimental());
+
+ getIdentifiersOrgData();
+
+ checkURLLinks();
+
+ // Spawn a thread that shows the splashscreen
+
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ new SplashScreen();
+ }
+ });
- showNews.setVisible(false);
+ // Thread off a new instance of the file chooser - this reduces the time it
+ // takes to open it later on.
+ new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Cache.log.debug("Filechooser init thread started.");
+ String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
+ JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"),
+ fileFormat);
+ Cache.log.debug("Filechooser init thread finished.");
+ }
+ }).start();
+ // Add the service change listener
+ changeSupport.addJalviewPropertyChangeListener("services",
+ new PropertyChangeListener()
+ {
- experimentalFeatures.setSelected(showExperimental());
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ Cache.log.debug("Firing service changed event for "
+ + evt.getNewValue());
+ JalviewServicesChanged(evt);
+ }
- getIdentifiersOrgData();
+ });
- checkURLLinks();
+ } // end BH 2018 ignore
+
+ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
this.addWindowListener(new WindowAdapter()
{
});
desktop.addMouseListener(ma);
- this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
- // Spawn a thread that shows the splashscreen
- SwingUtilities.invokeLater(new Runnable()
- {
- @Override
- public void run()
- {
- new SplashScreen();
- }
- });
-
- // Thread off a new instance of the file chooser - this reduces the time it
- // takes to open it later on.
- new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- Cache.log.debug("Filechooser init thread started.");
- String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
- JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"),
- fileFormat);
- Cache.log.debug("Filechooser init thread finished.");
- }
- }).start();
- // Add the service change listener
- changeSupport.addJalviewPropertyChangeListener("services",
- new PropertyChangeListener()
- {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- Cache.log.debug("Firing service changed event for "
- + evt.getNewValue());
- JalviewServicesChanged(evt);
- }
-
- });
}
/**
public void checkForNews()
{
+
+ /**
+ * BH 2018
+ *
+ * @j2sNative
+ */
+ {
final Desktop me = this;
// Thread off the news reader, in case there are connection problems.
addDialogThread(new Runnable()
{
- @Override
- public void run()
- {
- Cache.log.debug("Starting news thread.");
+ @Override
+ public void run()
+ {
+ Cache.log.debug("Starting news thread.");
- jvnews = new BlogReader(me);
- showNews.setVisible(true);
- Cache.log.debug("Completed news thread.");
- }
+ jvnews = new BlogReader(me);
+ showNews.setVisible(true);
+ Cache.log.debug("Completed news thread.");
+ }
});
+ }
}
public void getIdentifiersOrgData()
void showNews(boolean visible)
{
+ /**
+ * BH 2018
+ *
+ * @j2sNative
+ *
+ */
{
Cache.log.debug((visible ? "Showing" : "Hiding") + " news.");
showNews.setSelected(visible);
private void doVamsasClientCheck()
{
- if (jalview.bin.Cache.vamsasJarsPresent())
+ if (/** @j2sNative false && */ // BH 2018
+ jalview.bin.Cache.vamsasJarsPresent())
{
setupVamsasDisconnectedGui();
VamsasMenu.setVisible(true);
frame.setResizable(resizable);
frame.setMaximizable(resizable);
frame.setIconifiable(resizable);
- frame.setOpaque(false);
+ frame.setOpaque(/** @j2sNative true || */
+ false);
if (frame.getX() < 1 && frame.getY() < 1)
{
}
});
+ setKeyBindings(frame);
+
desktop.add(frame);
windowMenu.add(menuItem);
}
}
+ /**
+ * Add key bindings to a JInternalFrame so that Ctrl-W and Cmd-W will close
+ * the window
+ *
+ * @param frame
+ */
+ private static void setKeyBindings(JInternalFrame frame)
+ {
+ @SuppressWarnings("serial")
+ final Action closeAction = new AbstractAction()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ frame.dispose();
+ }
+ };
+
+ /*
+ * set up key bindings for Ctrl-W and Cmd-W, with the same (Close) action
+ */
+ KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
+ InputEvent.CTRL_DOWN_MASK);
+ KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
+ Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
+
+ InputMap inputMap = frame
+ .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
+ String ctrlW = ctrlWKey.toString();
+ inputMap.put(ctrlWKey, ctrlW);
+ inputMap.put(cmdWKey, ctrlW);
+
+ ActionMap actionMap = frame.getActionMap();
+ actionMap.put(ctrlW, closeAction);
+ }
+
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents)
{
// Java's Transferable for native dnd
evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
Transferable t = evt.getTransferable();
- List<String> files = new ArrayList<>();
+ List<Object> files = new ArrayList<>();
List<DataSourceType> protocols = new ArrayList<>();
try
{
for (int i = 0; i < files.size(); i++)
{
- String file = files.get(i).toString();
+ // BH 2018 File or String
+ Object file = files.get(i);
+ String fileName = file.toString();
DataSourceType protocol = (protocols == null)
? DataSourceType.FILE
: protocols.get(i);
FileFormatI format = null;
- if (file.endsWith(".jar"))
+ if (fileName.endsWith(".jar"))
{
format = FileFormat.Jalview;
format = new IdentifyFile().identify(file, protocol);
}
- new FileLoader().LoadFile(file, protocol, format);
+ new FileLoader().LoadFile(null, file, protocol, format);
}
} catch (Exception ex)
MessageManager.getString("label.open_local_file"));
chooser.setToolTipText(MessageManager.getString("action.open"));
- int value = chooser.showOpenDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ chooser.setCallback(new Runnable()
{
- String choice = chooser.getSelectedFile().getPath();
- Cache.setProperty("LAST_DIRECTORY",
- chooser.getSelectedFile().getParent());
-
- FileFormatI format = chooser.getSelectedFormat();
- /*
- * Call IdentifyFile to verify the file contains what its extension implies.
- * Skip this step for dynamically added file formats, because
- * IdentifyFile does not know how to recognise them.
- */
- if (FileFormats.getInstance().isIdentifiable(format))
+ @Override
+ public void run()
{
- try
- {
- format = new IdentifyFile().identify(choice, DataSourceType.FILE);
- } catch (FileFormatException e)
+ File selectedFile = chooser.getSelectedFile();
+ Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
+
+ FileFormatI format = chooser.getSelectedFormat();
+
+ /*
+ * Call IdentifyFile to verify the file contains what its extension implies.
+ * Skip this step for dynamically added file formats, because
+ * IdentifyFile does not know how to recognise them.
+ */
+ if (FileFormats.getInstance().isIdentifiable(format))
{
- // format = null; //??
+ try
+ {
+ format = new IdentifyFile().identify(selectedFile,
+ DataSourceType.FILE);
+ } catch (FileFormatException e)
+ {
+ // format = null; //??
+ }
}
- }
- if (viewport != null)
- {
- new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE,
- format);
- }
- else
- {
- new FileLoader().LoadFile(choice, DataSourceType.FILE, format);
+ new FileLoader().LoadFile(viewport, selectedFile,
+ DataSourceType.FILE, format);
}
+ });
+
+ int value = chooser.showOpenDialog(this);
+ if (value == JFileChooser.APPROVE_OPTION)
+ {
+ chooser.getCallback().run();
}
+
}
/**
// for viewing
JLabel label = new JLabel(
MessageManager.getString("label.input_file_url"));
- final JComboBox history = new JComboBox();
+ JComboBox history = new JComboBox();
JPanel panel = new JPanel(new GridLayout(2, 1));
panel.add(label);
panel.add(history);
}
}
- int reply = JvOptionPane.showInternalConfirmDialog(desktop, panel,
- MessageManager.getString("label.input_alignment_from_url"),
- JvOptionPane.OK_CANCEL_OPTION);
-
- if (reply != JvOptionPane.OK_OPTION)
- {
- return;
- }
-
- String url = history.getSelectedItem().toString();
-
- if (url.toLowerCase().endsWith(".jar"))
- {
- if (viewport != null)
- {
- new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
- FileFormat.Jalview);
- }
- else
- {
- new FileLoader().LoadFile(url, DataSourceType.URL,
- FileFormat.Jalview);
- }
- }
- else
- {
- FileFormatI format = null;
- try
- {
- format = new IdentifyFile().identify(url, DataSourceType.URL);
- } catch (FileFormatException e)
- {
- // TODO revise error handling, distinguish between
- // URL not found and response not valid
- }
+ // BH 2018 -- providing a callback for SwingJS
+ // dialogOption is just a simple way to provide
+ // context for the modal-like response.
+ // The only requirement is that desktop implement
+ // PropertyChangeListener, which is used already in Java
+ // for changes in input value and such within the dialogs.
- if (format == null)
- {
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.formatMessage("label.couldnt_locate",
- new Object[]
- { url }),
- MessageManager.getString("label.url_not_found"),
- JvOptionPane.WARNING_MESSAGE);
+ String dialogOption = "label.input_alignment_from_url";
+ desktop.dialogData = new Object[] { dialogOption, viewport, history };
+ desktop.onDialogReturn(
+ JvOptionPane.showInternalConfirmDialog(desktop, panel,
+ MessageManager.getString(dialogOption),
+ JvOptionPane.OK_CANCEL_OPTION));
- return;
- }
+ // no code may follow this, as SwingJS will not block
+ // callback in JavaScript comes via a property change event,
+ // thus going into desktop.onDialogReturn(int) just the same as
+ // in Java.
- if (viewport != null)
- {
- new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
- format);
- }
- else
- {
- new FileLoader().LoadFile(url, DataSourceType.URL, format);
- }
- }
}
+
/**
* Opens the CutAndPaste window for the user to paste an alignment in to
*
*/
void showConsole(boolean selected)
{
- showConsole.setSelected(selected);
// TODO: decide if we should update properties file
- Cache.setProperty("SHOW_JAVA_CONSOLE",
- Boolean.valueOf(selected).toString());
- jconsole.setVisible(selected);
+ if (jconsole != null) // BH 2018
+ {
+ showConsole.setSelected(selected);
+ Cache.setProperty("SHOW_JAVA_CONSOLE",
+ Boolean.valueOf(selected).toString());
+ jconsole.setVisible(selected);
+ }
}
void reorderAssociatedWindows(boolean minimize, boolean close)
@Override
public void saveState_actionPerformed(ActionEvent e)
{
+ // TODO: JAL-3048 not needed for Jalview-JS
+
JalviewFileChooser chooser = new JalviewFileChooser("jvp",
"Jalview Project");
@Override
public void loadState_actionPerformed(ActionEvent e)
{
+ // TODO: JAL-3048 not needed for Jalview-JS
+
JalviewFileChooser chooser = new JalviewFileChooser(
Cache.getProperty("LAST_DIRECTORY"), new String[]
{ "jvp", "jar" },
ArrayList<JPanel> fileLoadingPanels = new ArrayList<>();
- public void startLoading(final String fileName)
+ public void startLoading(final Object fileName)
{
if (fileLoadingCount == 0)
{
@Override
public void vamsasImport_actionPerformed(ActionEvent e)
{
+ // TODO: JAL-3048 not needed for Jalview-JS
+
if (v_client == null)
{
// Load and try to start a session.
@Override
public void vamsasSave_actionPerformed(ActionEvent e)
{
+ // TODO: JAL-3048 not needed for Jalview-JS
+
if (v_client != null)
{
// TODO: VAMSAS DOCUMENT EXTENSION is VDJ
@Override
public void run()
{
- if (Cache.getDefault("CHECKURLLINKS", true))
+ if (/** @j2sNative false && */ // BH 2018
+ Cache.getDefault("CHECKURLLINKS", true))
{
// check what the actual links are - if it's just the default don't
// bother with the warning
*
* @author AMW
*/
- public class MyDesktopPane extends JDesktopPane implements Runnable
+ public class MyDesktopPane extends JDesktopPane
+ implements Runnable, PropertyChangeListener
{
+ public Object[] dialogData;
+
+ // @Override
+ @Override
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ Object val = event.getNewValue();
+ String name = event.getPropertyName();
+ System.out.println(name);
+ switch (event.getSource().getClass().getName())
+ {
+ case "javax.swing.JOptionPane":
+ switch (name)
+ {
+ case "inputValue":
+ onDialogReturn(val);
+ return;
+ case "value":
+ if (val instanceof Integer)
+ {
+ onDialogReturn(((Integer) val).intValue());
+ }
+ else
+ {
+ onDialogReturn(val);
+ }
+ return;
+ }
+ break;
+ case "javax.swing.ColorChooserDialog":
+ switch (name)
+ {
+ case "SelectedColor":
+ onDialogReturn(val);
+ return;
+ }
+ break;
+ case "javax.swing.JFileChooser":
+ switch (name)
+ {
+ case "SelectedFile":
+ // in JavaScript, this File object will have a _bytes property,
+ // because the file data has already been loaded
+ onDialogReturn(new Object[] { (File) val });
+ return;
+ }
+ break;
+ }
+ System.out.println(event.getSource().getClass().getName() + " "
+ + event.getPropertyName() + ": " + event.getNewValue());
+ }
+
+ // JSCOmponent.DialogCaller interface
+ void onDialogReturn(Object value)
+ {
+ switch ((String) dialogData[0])
+ {
+ case "SelectedFile":
+ case "runnable":
+ dialogData[0] = value;
+ ((Runnable) dialogData[1]).run();
+ break;
+ case "label.select_feature_colour":
+ ((FeatureRenderer) dialogData[1]).processColorDialog((Color) value);
+ break;
+ }
+ }
+
+ // JSCOmponent.DialogCaller interface
+ void onDialogReturn(int value)
+ {
+ if (value != Math.floor(value))
+ {
+ // in JavaScript, this will be NaN, oddly enough
+ return;
+ }
+
+ switch ((String) dialogData[0])
+ {
+ case "runnable":
+ dialogData[0] = Integer.valueOf(value);
+ ((Runnable) dialogData[1]).run();
+ break;
+ case "label.input_alignment_from_url":
+ // reconstruct the parameter data
+ int reply = value;
+ AlignViewport viewport = (AlignViewport) dialogData[1];
+ JComboBox history = (JComboBox) dialogData[2];
+ // the rest of this is unchangaed
+ if (reply != JvOptionPane.OK_OPTION)
+ {
+ return;
+ }
+
+ String url = history.getSelectedItem().toString();
+
+ if (url.toLowerCase().endsWith(".jar"))
+ {
+ if (viewport != null)
+ {
+ new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
+ FileFormat.Jalview);
+ }
+ else
+ {
+ new FileLoader().LoadFile(url, DataSourceType.URL,
+ FileFormat.Jalview);
+ }
+ }
+ else
+ {
+ FileFormatI format = null;
+ try
+ {
+ format = new IdentifyFile().identify(url, DataSourceType.URL);
+ } catch (FileFormatException e)
+ {
+ // TODO revise error handling, distinguish between
+ // URL not found and response not valid
+ }
+
+ if (format == null)
+ {
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ MessageManager.formatMessage("label.couldnt_locate",
+ new Object[]
+ { url }),
+ MessageManager.getString("label.url_not_found"),
+ JvOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+
+ if (viewport != null)
+ {
+ new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
+ format);
+ }
+ else
+ {
+ new FileLoader().LoadFile(url, DataSourceType.URL, format);
+ }
+ }
+
+ break;
+ }
+
+ }
+
private static final float ONE_MB = 1048576f;
boolean showMemoryUsage = false;
* - the payload from the drop event
* @throws Exception
*/
- public static void transferFromDropTarget(List<String> files,
+ public static void transferFromDropTarget(List<Object> files,
List<DataSourceType> protocols, DropTargetDropEvent evt,
Transferable t) throws Exception
{
+
+ // BH 2018 changed List<String> to List<Object> to allow for File from SwingJS
+
+// DataFlavor[] flavors = t.getTransferDataFlavors();
+// for (int i = 0; i < flavors.length; i++) {
+// if (flavors[i].isFlavorJavaFileListType()) {
+// evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+// List<File> list = (List<File>) t.getTransferData(flavors[i]);
+// for (int j = 0; j < list.size(); j++) {
+// File file = (File) list.get(j);
+// byte[] data = getDroppedFileBytes(file);
+// fileName.setText(file.getName() + " - " + data.length + " " + evt.getLocation());
+// JTextArea target = (JTextArea) ((DropTarget) evt.getSource()).getComponent();
+// target.setText(new String(data));
+// }
+// dtde.dropComplete(true);
+// return;
+// }
+//
DataFlavor uriListFlavor = new DataFlavor(
"text/uri-list;class=java.lang.String"), urlFlavour = null;
for (Object file : (List) t
.getTransferData(DataFlavor.javaFileListFlavor))
{
- files.add(((File) file).toString());
+ files.add(file);
protocols.add(DataSourceType.FILE);
}
}
// resolve any .lnk files in the file drop
for (int f = 0; f < files.size(); f++)
{
- String source = files.get(f).toLowerCase();
+ String source = files.get(f).toString().toLowerCase();
if (protocols.get(f).equals(DataSourceType.FILE)
&& (source.endsWith(".lnk") || source.endsWith(".url")
|| source.endsWith(".site")))
{
try {
- File lf = new File(files.get(f));
+ Object obj = files.get(f);
+ File lf = (obj instanceof File ? (File) obj : new File((String) obj));
// process link file to get a URL
Cache.log.debug("Found potential link file: " + lf);
WindowsShortcut wscfile = new WindowsShortcut(lf);