import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.gui.ImageExporter.ImageWriterI;
+import jalview.io.BackupFiles;
import jalview.io.DataSourceType;
import jalview.io.FileFormat;
import jalview.io.FileFormatException;
import jalview.io.JalviewFileView;
import jalview.jbgui.GSplitFrame;
import jalview.jbgui.GStructureViewer;
+import jalview.project.Jalview2XML;
import jalview.structure.StructureSelectionManager;
import jalview.urls.IdOrgSettings;
import jalview.util.BrowserLauncher;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.util.UrlConstants;
-import jalview.util.dialogrunner.RunResponse;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.ParamManager;
import jalview.ws.utils.UrlDownloadClient;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
-import java.util.StringTokenizer;
import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
*/
public Desktop()
{
+ super();
/**
- * A note to implementors. It is ESSENTIAL that any activities that might block
- * are spawned off as threads rather than waited for during this constructor.
+ * A note to implementors. It is ESSENTIAL that any activities that might
+ * block are spawned off as threads rather than waited for during this
+ * constructor.
*/
instance = this;
- if (!Jalview.isJS())
+ if (!Platform.isJS())
{
doVamsasClientCheck();
}
boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE",
false);
desktop = new MyDesktopPane(selmemusage);
+
showMemusage.setSelected(selmemusage);
desktop.setBackground(Color.white);
getContentPane().setLayout(new BorderLayout());
// JScrollPane sp = new JScrollPane();
// sp.getViewport().setView(desktop);
// getContentPane().add(sp, BorderLayout.CENTER);
+
+ // BH 2018 - just an experiment to try unclipped JInternalFrames.
+ if (Platform.isJS())
+ {
+ getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
+ }
+
getContentPane().add(desktop, BorderLayout.CENTER);
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
// This line prevents Windows Look&Feel resizing all new windows to maximum
// if previous window was maximised
desktop.setDesktopManager(new MyDesktopManager(
- (Platform.isWindows() ? new DefaultDesktopManager()
- : Platform.isAMac()
+ (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager()
+ : Platform.isAMacAndNotJS()
? new AquaInternalFrameManager(
desktop.getDesktopManager())
: desktop.getDesktopManager())));
int yPos = Math.max(5, (screenSize.height - 650) / 2);
setBounds(xPos, yPos, 900, 650);
}
-
- boolean doFullLoad = /** @j2sNative ! */true;
-
- if (doFullLoad) {
-
+
+ if (!Platform.isJS())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
+ {
+
jconsole = new Console(this, showjconsole);
// add essential build information
jconsole.setHeader("Jalview Version: "
}
});
- // Thread off a new instance of the file chooser - this reduces the time it
+ // Thread off a new instance of the file chooser - this reduces the time
+ // it
// takes to open it later on.
new Thread(new Runnable()
{
});
- }
+ }
this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
frame.setResizable(resizable);
frame.setMaximizable(resizable);
frame.setIconifiable(resizable);
- frame.setOpaque(/** @j2sNative true || */
- false);
+ frame.setOpaque(Platform.isJS());
if (frame.getX() < 1 && frame.getY() < 1)
{
{
format = new IdentifyFile().identify(file, protocol);
}
-
+ if (file instanceof File)
+ {
+ Platform.cacheFileData((File) file);
+ }
new FileLoader().LoadFile(null, file, protocol, format);
}
{
String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
JalviewFileChooser chooser = JalviewFileChooser
- .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
+ .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat, true);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(
MessageManager.getString("label.open_local_file"));
chooser.setToolTipText(MessageManager.getString("action.open"));
- chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
-
@Override
public void run()
{
new FileLoader().LoadFile(viewport, selectedFile,
DataSourceType.FILE, format);
}
- }).openDialog(this);
+ });
+ chooser.showOpenDialog(this);
}
/**
JPanel panel = new JPanel(new GridLayout(2, 1));
panel.add(label);
-
+
/*
* the URL to fetch is
* Java: an editable combobox with history
*/
JComponent history;
String urlBase = "http://www.";
- if (Jalview.isJS())
+ if (Platform.isJS())
{
history = new JTextField(urlBase, 35);
}
else
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
{
JComboBox<String> asCombo = new JComboBox<>();
asCombo.setPreferredSize(new Dimension(400, 20));
Object[] options = new Object[] { MessageManager.getString("action.ok"),
MessageManager.getString("action.cancel") };
- RunResponse action = new RunResponse(JvOptionPane.OK_OPTION) {
+ Runnable action = new Runnable()
+ {
@Override
public void run()
{
- String url = Jalview.isJS() ? ((JTextField) history).getText()
+ @SuppressWarnings("unchecked")
+ String url = (history instanceof JTextField
+ ? ((JTextField) history).getText()
: ((JComboBox<String>) history).getSelectedItem()
- .toString();
+ .toString());
if (url.toLowerCase().endsWith(".jar"))
{
if (format == null)
{
- String msg = MessageManager.formatMessage("label.couldnt_locate", url);
+ String msg = MessageManager
+ .formatMessage("label.couldnt_locate", url);
JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
MessageManager.getString("label.url_not_found"),
JvOptionPane.WARNING_MESSAGE);
new FileLoader().LoadFile(url, DataSourceType.URL, format);
}
}
- }};
+ }
+ };
String dialogOption = MessageManager
.getString("label.input_alignment_from_url");
- JvOptionPane.newOptionDialog(desktop).response(action)
+ JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action)
.showInternalDialog(panel, dialogOption,
JvOptionPane.YES_NO_CANCEL_OPTION,
JvOptionPane.PLAIN_MESSAGE, null, options,
{
try
{
- if (Jalview.isJS())
+ if (Platform.isJS())
{
BrowserLauncher.openURL("http://www.jalview.org/help.html");
}
else
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
{
Help.showHelpWindow();
}
* Jalview project file
*/
@Override
- public void saveState_actionPerformed(boolean asCastor)
+ public void saveState_actionPerformed()
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- asCastor ? "jvp" : "jvx",
- "Jalview Project");
+ saveState_actionPerformed(false);
+ }
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_state"));
- int option = chooser.showSaveDialog(this);
- if (option == JalviewFileChooser.APPROVE_OPTION)
+ public void saveState_actionPerformed(boolean saveAs)
+ {
+ java.io.File projectFile = getProjectFile();
+ // autoSave indicates we already have a file and don't need to ask
+ boolean autoSave = projectFile != null && !saveAs
+ && BackupFiles.getEnabled();
+
+ // System.out.println("autoSave="+autoSave+", projectFile='"+projectFile+"',
+ // saveAs="+saveAs+", Backups
+ // "+(BackupFiles.getEnabled()?"enabled":"disabled"));
+
+ boolean approveSave = false;
+ if (!autoSave)
{
- File choice = chooser.getSelectedFile();
- setProjectFile(choice);
+ JalviewFileChooser chooser = new JalviewFileChooser("jvp",
+ "Jalview Project");
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager.getString("label.save_state"));
+
+ int value = chooser.showSaveDialog(this);
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ projectFile = chooser.getSelectedFile();
+ setProjectFile(projectFile);
+ approveSave = true;
+ }
+ }
+
+ if (approveSave || autoSave)
+ {
+ final Desktop me = this;
+ final java.io.File chosenFile = projectFile;
new Thread(new Runnable()
{
@Override
// TODO: refactor to Jalview desktop session controller action.
setProgressBar(MessageManager.formatMessage(
"label.saving_jalview_project", new Object[]
- { choice.getName() }), choice.hashCode());
+ { chosenFile.getName() }), chosenFile.hashCode());
jalview.bin.Cache.setProperty("LAST_DIRECTORY",
- choice.getParent());
+ chosenFile.getParent());
// TODO catch and handle errors for savestate
// TODO prevent user from messing with the Desktop whilst we're saving
try
{
- if (asCastor)
- {
- new Jalview2XML().saveState(choice);
- }
- else
+ boolean doBackup = BackupFiles.getEnabled();
+ BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile) : null;
+
+ new Jalview2XML().saveState(doBackup ? backupfiles.getTempFile() : chosenFile);
+
+ if (doBackup)
{
- new jalview.project.Jalview2XML().saveState(choice);
+ backupfiles.setWriteSuccess(true);
+ backupfiles.rollBackupsAndRenameTempFile();
}
} catch (OutOfMemoryError oom)
{
- new OOMWarning(
- "Whilst saving current state to " + choice.getName(),
- oom);
+ new OOMWarning("Whilst saving current state to "
+ + chosenFile.getName(), oom);
} catch (Exception ex)
{
- Cache.log.error(
- "Problems whilst trying to save to " + choice.getName(),
- ex);
- JvOptionPane.showMessageDialog(Desktop.this,
+ Cache.log.error("Problems whilst trying to save to "
+ + chosenFile.getName(), ex);
+ JvOptionPane.showMessageDialog(me,
MessageManager.formatMessage(
"label.error_whilst_saving_current_state_to",
new Object[]
- { choice.getName() }),
+ { chosenFile.getName() }),
MessageManager.getString("label.couldnt_save_project"),
JvOptionPane.WARNING_MESSAGE);
}
- setProgressBar(null, choice.hashCode());
+ setProgressBar(null, chosenFile.hashCode());
}
}).start();
}
}
- void setProjectFile(File choice)
+ @Override
+ public void saveAsState_actionPerformed(ActionEvent e)
+ {
+ saveState_actionPerformed(true);
+ }
+
+ private void setProjectFile(File choice)
{
this.projectFile = choice;
}
}
/**
- * Prompts the user to choose a file and loads in as a Jalview project file
+ * Shows a file chooser dialog and tries to read in the selected file as a
+ * Jalview project
*/
@Override
- public void loadState_actionPerformed(boolean asCastor)
- {
- // TODO: GET RID OF .JVX BEFORE RELEASE JIM!
- final String[] suffix = asCastor ? new String[] { "jvp", "jar" }
- : new String[]
- { "jvx" };
- final String[] desc = asCastor
- ? new String[]
- { "Jalview Project", "Jalview Project (old)" }
- : new String[]
- { "Jalview Project" };
+ public void loadState_actionPerformed()
+ {
+ final String[] suffix = new String[] { "jvp", "jar" };
+ final String[] desc = new String[] { "Jalview Project",
+ "Jalview Project (old)" };
JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), suffix,
- desc,
- "Jalview Project");
+ Cache.getProperty("LAST_DIRECTORY"), suffix, desc,
+ "Jalview Project", true, true); // last two booleans: allFiles,
+ // allowBackupFiles
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
- chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
{
File selectedFile = chooser.getSelectedFile();
setProjectFile(selectedFile);
- final String choice = selectedFile.getAbsolutePath();
+ String choice = selectedFile.getAbsolutePath();
Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
new Thread(new Runnable()
{
@Override
public void run()
{
- try {
- if (asCastor)
- {
- new Jalview2XML().loadJalviewAlign(choice);
- }
- else
- {
- new jalview.project.Jalview2XML().loadJalviewAlign(choice);
- }
- } catch (OutOfMemoryError oom)
+ try
{
- new OOMWarning("Whilst loading project from " + choice, oom);
- } catch (Exception ex)
- {
- Cache.log.error(
- "Problems whilst loading project from " + choice, ex);
- JvOptionPane.showMessageDialog(Desktop.desktop,
- MessageManager.formatMessage(
- "label.error_whilst_loading_project_from",
- new Object[]
- { choice }),
- MessageManager.getString("label.couldnt_load_project"),
- JvOptionPane.WARNING_MESSAGE);
- }
+ new Jalview2XML().loadJalviewAlign(choice);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Whilst loading project from " + choice, oom);
+ } catch (Exception ex)
+ {
+ Cache.log.error(
+ "Problems whilst loading project from " + choice, ex);
+ JvOptionPane.showMessageDialog(Desktop.desktop,
+ MessageManager.formatMessage(
+ "label.error_whilst_loading_project_from",
+ new Object[]
+ { choice }),
+ MessageManager.getString("label.couldnt_load_project"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
}
}).start();
}
@Override
public void setProgressBar(String message, long id)
{
+ Platform.timeCheck("Desktop " + message, Platform.TIME_MARK);
+
if (progressBars == null)
{
progressBars = new Hashtable<>();
}
else
{
- if (Platform.isAMac())
+ if (Platform.isAMacAndNotJS())
{
System.err.println(
"Please ignore plist error - occurs due to problem with java 8 on OSX");
}
}
}
- if (Platform.isWindows())
-
+ if (Platform.isWindowsAndNotJS())
{
Cache.log.debug("Scanning dropped content for Windows Link Files");