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;
public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
{
String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
- JalviewFileChooser chooser = JalviewFileChooser
+ final JalviewFileChooser chooser = JalviewFileChooser
.forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
chooser.setFileView(new JalviewFileView());
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();
}
+
}
/**
switch (name)
{
case "SelectedFile":
- File file = (File) val;
- byte[] array = (val == null ? null
- : /** @j2sNative file._bytes || */
- null);
- onDialogReturn("fileName is '" + file.getName() + "'\n\n"
- + new String(array));
+ // 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;
}
// JSCOmponent.DialogCaller interface
- private void onDialogReturn(Object value)
+ void onDialogReturn(Object value)
{
- System.out.println("not implemented");
+ 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
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;