")
+ .append("
Version: ")
+ .append(Cache.getProperty("VERSION")).append("
")
+ .append("
Built: ")
+ .append(Cache.getDefault("BUILD_DATE", "unknown"))
+ .append(" from ").append(Cache.getBuildDetailsForSplash())
+ .append("");
String latestVersion = Cache.getDefault("LATEST_VERSION", "Checking");
- if (latestVersion.equals("Checking")) {
+ if (latestVersion.equals("Checking"))
+ {
// JBP removed this message for 2.11: May be reinstated in future version
// message.append("
...Checking latest version...");
- } else if (!latestVersion.equals(Cache.getProperty("VERSION"))) {
+ }
+ else if (!latestVersion.equals(Cache.getProperty("VERSION")))
+ {
boolean red = false;
- if (Cache.getProperty("VERSION").toLowerCase(Locale.ROOT).indexOf("automated build") == -1) {
+ if (Cache.getProperty("VERSION").toLowerCase(Locale.ROOT)
+ .indexOf("automated build") == -1)
+ {
red = true;
// Displayed when code version and jnlp version do not match and code
// version is not a development build
message.append("
");
}
- message.append("
!! Version ").append(Cache.getDefault("LATEST_VERSION", "..Checking.."))
- .append(" is available for download from ")
- .append(Cache.getDefault("www.jalview.org", "https://www.jalview.org")).append(" !!");
- if (red) {
+ message.append("
!! Version ")
+ .append(Cache.getDefault("LATEST_VERSION", "..Checking.."))
+ .append(" is available for download from ")
+ .append(Cache.getDefault("www.jalview.org",
+ "https://www.jalview.org"))
+ .append(" !!");
+ if (red)
+ {
message.append("
");
}
}
@@ -1211,11 +1672,15 @@ public class Desktop extends jalview.jbgui.GDesktop
* Action on requesting Help documentation
*/
@Override
- public void documentationMenuItem_actionPerformed() {
- try {
- if (Platform.isJS()) {
+ public void documentationMenuItem_actionPerformed()
+ {
+ try
+ {
+ if (Platform.isJS())
+ {
BrowserLauncher.openURL("https://www.jalview.org/help.html");
- } else
+ }
+ else
/**
* Java only
*
@@ -1224,45 +1689,72 @@ public class Desktop extends jalview.jbgui.GDesktop
{
Help.showHelpWindow();
}
- } catch (Exception ex) {
- System.err.println("Error opening help: " + ex.getMessage());
+ } catch (Exception ex)
+ {
+ jalview.bin.Console
+ .errPrintln("Error opening help: " + ex.getMessage());
}
}
@Override
- public void closeAll_actionPerformed(ActionEvent e) {
+ public void closeAll_actionPerformed(ActionEvent e)
+ {
// TODO show a progress bar while closing?
JInternalFrame[] frames = desktop.getAllFrames();
- for (int i = 0; i < frames.length; i++) {
- try {
+ for (int i = 0; i < frames.length; i++)
+ {
+ try
+ {
frames[i].setClosed(true);
- } catch (java.beans.PropertyVetoException ex) {
+ } catch (java.beans.PropertyVetoException ex)
+ {
}
}
- Jalview.setCurrentAlignFrame(null);
- System.out.println("ALL CLOSED");
+ Jalview.getInstance().setCurrentAlignFrame(null);
+ jalview.bin.Console.info("ALL CLOSED");
/*
* reset state of singleton objects as appropriate (clear down session state
* when all windows are closed)
*/
- StructureSelectionManager ssm = StructureSelectionManager.getStructureSelectionManager(this);
- if (ssm != null) {
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(this);
+ if (ssm != null)
+ {
ssm.resetAll();
}
}
+ public int structureViewersStillRunningCount()
+ {
+ int count = 0;
+ JInternalFrame[] frames = desktop.getAllFrames();
+ for (int i = 0; i < frames.length; i++)
+ {
+ if (frames[i] != null
+ && frames[i] instanceof JalviewStructureDisplayI)
+ {
+ if (((JalviewStructureDisplayI) frames[i]).stillRunning())
+ count++;
+ }
+ }
+ return count;
+ }
+
@Override
- public void raiseRelated_actionPerformed(ActionEvent e) {
+ public void raiseRelated_actionPerformed(ActionEvent e)
+ {
reorderAssociatedWindows(false, false);
}
@Override
- public void minimizeAssociated_actionPerformed(ActionEvent e) {
+ public void minimizeAssociated_actionPerformed(ActionEvent e)
+ {
reorderAssociatedWindows(true, false);
}
- void closeAssociatedWindows() {
+ void closeAssociatedWindows()
+ {
reorderAssociatedWindows(false, true);
}
@@ -1273,7 +1765,8 @@ public class Desktop extends jalview.jbgui.GDesktop
* ActionEvent)
*/
@Override
- protected void garbageCollect_actionPerformed(ActionEvent e) {
+ protected void garbageCollect_actionPerformed(ActionEvent e)
+ {
// We simply collect the garbage
jalview.bin.Console.debug("Collecting garbage...");
System.gc();
@@ -1287,7 +1780,8 @@ public class Desktop extends jalview.jbgui.GDesktop
* ActionEvent )
*/
@Override
- protected void showMemusage_actionPerformed(ActionEvent e) {
+ protected void showMemusage_actionPerformed(ActionEvent e)
+ {
desktop.showMemoryUsage(showMemusage.isSelected());
}
@@ -1299,7 +1793,8 @@ public class Desktop extends jalview.jbgui.GDesktop
* )
*/
@Override
- protected void showConsole_actionPerformed(ActionEvent e) {
+ protected void showConsole_actionPerformed(ActionEvent e)
+ {
showConsole(showConsole.isSelected());
}
@@ -1310,61 +1805,89 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param selected
*/
- void showConsole(boolean selected) {
+ void showConsole(boolean selected)
+ {
// TODO: decide if we should update properties file
if (jconsole != null) // BH 2018
{
showConsole.setSelected(selected);
- Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected).toString());
+ Cache.setProperty("SHOW_JAVA_CONSOLE",
+ Boolean.valueOf(selected).toString());
jconsole.setVisible(selected);
}
}
- void reorderAssociatedWindows(boolean minimize, boolean close) {
+ void reorderAssociatedWindows(boolean minimize, boolean close)
+ {
JInternalFrame[] frames = desktop.getAllFrames();
- if (frames == null || frames.length < 1) {
+ if (frames == null || frames.length < 1)
+ {
return;
}
AlignmentViewport source = null, target = null;
- if (frames[0] instanceof AlignFrame) {
+ if (frames[0] instanceof AlignFrame)
+ {
source = ((AlignFrame) frames[0]).getCurrentView();
- } else if (frames[0] instanceof TreePanel) {
+ }
+ else if (frames[0] instanceof TreePanel)
+ {
source = ((TreePanel) frames[0]).getViewPort();
- } else if (frames[0] instanceof PCAPanel) {
+ }
+ else if (frames[0] instanceof PCAPanel)
+ {
source = ((PCAPanel) frames[0]).av;
- } else if (frames[0].getContentPane() instanceof PairwiseAlignPanel) {
+ }
+ else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
+ {
source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
}
- if (source != null) {
- for (int i = 0; i < frames.length; i++) {
+ if (source != null)
+ {
+ for (int i = 0; i < frames.length; i++)
+ {
target = null;
- if (frames[i] == null) {
+ if (frames[i] == null)
+ {
continue;
}
- if (frames[i] instanceof AlignFrame) {
+ if (frames[i] instanceof AlignFrame)
+ {
target = ((AlignFrame) frames[i]).getCurrentView();
- } else if (frames[i] instanceof TreePanel) {
+ }
+ else if (frames[i] instanceof TreePanel)
+ {
target = ((TreePanel) frames[i]).getViewPort();
- } else if (frames[i] instanceof PCAPanel) {
+ }
+ else if (frames[i] instanceof PCAPanel)
+ {
target = ((PCAPanel) frames[i]).av;
- } else if (frames[i].getContentPane() instanceof PairwiseAlignPanel) {
+ }
+ else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
+ {
target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
}
- if (source == target) {
- try {
- if (close) {
+ if (source == target)
+ {
+ try
+ {
+ if (close)
+ {
frames[i].setClosed(true);
- } else {
+ }
+ else
+ {
frames[i].setIcon(minimize);
- if (!minimize) {
+ if (!minimize)
+ {
frames[i].toFront();
}
}
- } catch (java.beans.PropertyVetoException ex) {
+ } catch (java.beans.PropertyVetoException ex)
+ {
}
}
}
@@ -1374,10 +1897,12 @@ public class Desktop extends jalview.jbgui.GDesktop
/**
* DOCUMENT ME!
*
- * @param e DOCUMENT ME!
+ * @param e
+ * DOCUMENT ME!
*/
@Override
- protected void preferences_actionPerformed(ActionEvent e) {
+ protected void preferences_actionPerformed(ActionEvent e)
+ {
Preferences.openPreferences();
}
@@ -1386,83 +1911,108 @@ public class Desktop extends jalview.jbgui.GDesktop
* Jalview project file
*/
@Override
- public void saveState_actionPerformed() {
+ public void saveState_actionPerformed()
+ {
saveState_actionPerformed(false);
}
- public void saveState_actionPerformed(boolean saveAs) {
+ 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();
+ boolean autoSave = projectFile != null && !saveAs
+ && BackupFiles.getEnabled();
- // System.out.println("autoSave="+autoSave+", projectFile='"+projectFile+"',
+ // jalview.bin.Console.outPrintln("autoSave="+autoSave+",
+ // projectFile='"+projectFile+"',
// saveAs="+saveAs+", Backups
// "+(BackupFiles.getEnabled()?"enabled":"disabled"));
boolean approveSave = false;
- if (!autoSave) {
- JalviewFileChooser chooser = new JalviewFileChooser("jvp", "Jalview Project");
+ if (!autoSave)
+ {
+ 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) {
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
projectFile = chooser.getSelectedFile();
setProjectFile(projectFile);
approveSave = true;
}
}
- if (approveSave || autoSave) {
+ if (approveSave || autoSave)
+ {
final Desktop me = this;
final java.io.File chosenFile = projectFile;
- new Thread(new Runnable() {
+ new Thread(new Runnable()
+ {
@Override
- public void run() {
+ public void run()
+ {
// TODO: refactor to Jalview desktop session controller action.
- setProgressBar(
- MessageManager.formatMessage("label.saving_jalview_project", new Object[] { chosenFile.getName() }),
- chosenFile.hashCode());
+ setProgressBar(MessageManager.formatMessage(
+ "label.saving_jalview_project", new Object[]
+ { chosenFile.getName() }),
+ IdUtils.newId(IdType.PROGRESS, chosenFile));
Cache.setProperty("LAST_DIRECTORY", chosenFile.getParent());
// TODO catch and handle errors for savestate
// TODO prevent user from messing with the Desktop whilst we're saving
- try {
+ try
+ {
boolean doBackup = BackupFiles.getEnabled();
- BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile) : null;
+ BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile)
+ : null;
- new Jalview2XML().saveState(doBackup ? backupfiles.getTempFile() : chosenFile);
+ new Jalview2XML().saveState(
+ doBackup ? backupfiles.getTempFile() : chosenFile);
- if (doBackup) {
+ if (doBackup)
+ {
backupfiles.setWriteSuccess(true);
backupfiles.rollBackupsAndRenameTempFile();
}
- } catch (OutOfMemoryError oom) {
- new OOMWarning("Whilst saving current state to " + chosenFile.getName(), oom);
- } catch (Exception ex) {
- jalview.bin.Console.error("Problems whilst trying to save to " + chosenFile.getName(), ex);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Whilst saving current state to "
+ + chosenFile.getName(), oom);
+ } catch (Exception ex)
+ {
+ jalview.bin.Console.error("Problems whilst trying to save to "
+ + chosenFile.getName(), ex);
JvOptionPane.showMessageDialog(me,
- MessageManager.formatMessage("label.error_whilst_saving_current_state_to",
- new Object[] { chosenFile.getName() }),
- MessageManager.getString("label.couldnt_save_project"), JvOptionPane.WARNING_MESSAGE);
+ MessageManager.formatMessage(
+ "label.error_whilst_saving_current_state_to",
+ new Object[]
+ { chosenFile.getName() }),
+ MessageManager.getString("label.couldnt_save_project"),
+ JvOptionPane.WARNING_MESSAGE);
}
- setProgressBar(null, chosenFile.hashCode());
+ setProgressBar(null, IdUtils.newId(IdType.PROGRESS, chosenFile));
}
}).start();
}
}
@Override
- public void saveAsState_actionPerformed(ActionEvent e) {
+ public void saveAsState_actionPerformed(ActionEvent e)
+ {
saveState_actionPerformed(true);
}
- private void setProjectFile(File choice) {
+ protected void setProjectFile(File choice)
+ {
this.projectFile = choice;
}
- public File getProjectFile() {
+ public File getProjectFile()
+ {
return this.projectFile;
}
@@ -1471,46 +2021,57 @@ public class Desktop extends jalview.jbgui.GDesktop
* Jalview project
*/
@Override
- public void loadState_actionPerformed() {
+ 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", true, BackupFiles.getEnabled()); // last two
- // booleans:
- // allFiles,
+ final String[] desc = new String[] { "Jalview Project",
+ "Jalview Project (old)" };
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ Cache.getProperty("LAST_DIRECTORY"), suffix, desc,
+ "Jalview Project", true, BackupFiles.getEnabled()); // last two
+ // booleans:
+ // allFiles,
// allowBackupFiles
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
- chooser.setResponseHandler(0, new Runnable() {
- @Override
- public void run() {
- File selectedFile = chooser.getSelectedFile();
- setProjectFile(selectedFile);
- String choice = selectedFile.getAbsolutePath();
- Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- new Jalview2XML().loadJalviewAlign(selectedFile);
- } catch (OutOfMemoryError oom) {
- new OOMWarning("Whilst loading project from " + choice, oom);
- } catch (Exception ex) {
- jalview.bin.Console.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);
- }
+ chooser.setResponseHandler(0, () -> {
+ File selectedFile = chooser.getSelectedFile();
+ setProjectFile(selectedFile);
+ String choice = selectedFile.getAbsolutePath();
+ Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
+ new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ new Jalview2XML().loadJalviewAlign(selectedFile);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Whilst loading project from " + choice, oom);
+ } catch (Exception ex)
+ {
+ jalview.bin.Console.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);
}
- }, "Project Loader").start();
- }
+ }
+ }, "Project Loader").start();
});
chooser.showOpenDialog(this);
}
@Override
- public void inputSequence_actionPerformed(ActionEvent e) {
+ public void inputSequence_actionPerformed(ActionEvent e)
+ {
new SequenceFetcher(this);
}
@@ -1518,16 +2079,21 @@ public class Desktop extends jalview.jbgui.GDesktop
ArrayList
fileLoadingPanels = new ArrayList<>();
- public void startLoading(final Object fileName) {
- if (fileLoadingCount == 0) {
- fileLoadingPanels
- .add(addProgressPanel(MessageManager.formatMessage("label.loading_file", new Object[] { fileName })));
+ public void startLoading(final Object fileName)
+ {
+ if (fileLoadingCount == 0)
+ {
+ fileLoadingPanels.add(addProgressPanel(MessageManager
+ .formatMessage("label.loading_file", new Object[]
+ { fileName })));
}
fileLoadingCount++;
}
- private JPanel addProgressPanel(String string) {
- if (progressPanel == null) {
+ private JPanel addProgressPanel(String string)
+ {
+ if (progressPanel == null)
+ {
progressPanel = new JPanel(new GridLayout(1, 1));
totalProgressCount = 0;
instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
@@ -1540,7 +2106,8 @@ public class Desktop extends jalview.jbgui.GDesktop
thisprogress.add(progressBar, BorderLayout.CENTER);
progressPanel.add(thisprogress);
- ((GridLayout) progressPanel.getLayout()).setRows(((GridLayout) progressPanel.getLayout()).getRows() + 1);
+ ((GridLayout) progressPanel.getLayout()).setRows(
+ ((GridLayout) progressPanel.getLayout()).getRows() + 1);
++totalProgressCount;
instance.validate();
return thisprogress;
@@ -1548,13 +2115,17 @@ public class Desktop extends jalview.jbgui.GDesktop
int totalProgressCount = 0;
- private void removeProgressPanel(JPanel progbar) {
- if (progressPanel != null) {
- synchronized (progressPanel) {
+ private void removeProgressPanel(JPanel progbar)
+ {
+ if (progressPanel != null)
+ {
+ synchronized (progressPanel)
+ {
progressPanel.remove(progbar);
GridLayout gl = (GridLayout) progressPanel.getLayout();
gl.setRows(gl.getRows() - 1);
- if (--totalProgressCount < 1) {
+ if (--totalProgressCount < 1)
+ {
this.getContentPane().remove(progressPanel);
progressPanel = null;
}
@@ -1563,10 +2134,13 @@ public class Desktop extends jalview.jbgui.GDesktop
validate();
}
- public void stopLoading() {
+ public void stopLoading()
+ {
fileLoadingCount--;
- if (fileLoadingCount < 1) {
- while (fileLoadingPanels.size() > 0) {
+ if (fileLoadingCount < 1)
+ {
+ while (fileLoadingPanels.size() > 0)
+ {
removeProgressPanel(fileLoadingPanels.remove(0));
}
fileLoadingPanels.clear();
@@ -1575,35 +2149,45 @@ public class Desktop extends jalview.jbgui.GDesktop
validate();
}
- public static int getViewCount(String alignmentId) {
+ public static int getViewCount(String alignmentId)
+ {
AlignmentViewport[] aps = getViewports(alignmentId);
return (aps == null) ? 0 : aps.length;
}
/**
*
- * @param alignmentId - if null, all sets are returned
+ * @param alignmentId
+ * - if null, all sets are returned
* @return all AlignmentPanels concerning the alignmentId sequence set
*/
- public static AlignmentPanel[] getAlignmentPanels(String alignmentId) {
- if (Desktop.desktop == null) {
+ public static AlignmentPanel[] getAlignmentPanels(String alignmentId)
+ {
+ if (Desktop.desktop == null)
+ {
// no frames created and in headless mode
// TODO: verify that frames are recoverable when in headless mode
return null;
}
List aps = new ArrayList<>();
- AlignFrame[] frames = getAlignFrames();
- if (frames == null) {
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
+ if (frames == null)
+ {
return null;
}
- for (AlignFrame af : frames) {
- for (AlignmentPanel ap : af.alignPanels) {
- if (alignmentId == null || alignmentId.equals(ap.av.getSequenceSetId())) {
+ for (AlignFrame af : frames)
+ {
+ for (AlignmentPanel ap : af.alignPanels)
+ {
+ if (alignmentId == null
+ || alignmentId.equals(ap.av.getSequenceSetId()))
+ {
aps.add(ap);
}
}
}
- if (aps.size() == 0) {
+ if (aps.size() == 0)
+ {
return null;
}
AlignmentPanel[] vap = aps.toArray(new AlignmentPanel[aps.size()]);
@@ -1613,29 +2197,42 @@ public class Desktop extends jalview.jbgui.GDesktop
/**
* get all the viewports on an alignment.
*
- * @param sequenceSetId unique alignment id (may be null - all viewports
- * returned in that case)
+ * @param sequenceSetId
+ * unique alignment id (may be null - all viewports returned in that
+ * case)
* @return all viewports on the alignment bound to sequenceSetId
*/
- public static AlignmentViewport[] getViewports(String sequenceSetId) {
+ public static AlignmentViewport[] getViewports(String sequenceSetId)
+ {
List viewp = new ArrayList<>();
- if (desktop != null) {
- AlignFrame[] frames = Desktop.getAlignFrames();
-
- for (AlignFrame afr : frames) {
- if (sequenceSetId == null || afr.getViewport().getSequenceSetId().equals(sequenceSetId)) {
- if (afr.alignPanels != null) {
- for (AlignmentPanel ap : afr.alignPanels) {
- if (sequenceSetId == null || sequenceSetId.equals(ap.av.getSequenceSetId())) {
+ if (desktop != null)
+ {
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
+
+ for (AlignFrame afr : frames)
+ {
+ if (sequenceSetId == null || afr.getViewport().getSequenceSetId()
+ .equals(sequenceSetId))
+ {
+ if (afr.alignPanels != null)
+ {
+ for (AlignmentPanel ap : afr.alignPanels)
+ {
+ if (sequenceSetId == null
+ || sequenceSetId.equals(ap.av.getSequenceSetId()))
+ {
viewp.add(ap.av);
}
}
- } else {
+ }
+ else
+ {
viewp.add(afr.getViewport());
}
}
}
- if (viewp.size() > 0) {
+ if (viewp.size() > 0)
+ {
return viewp.toArray(new AlignmentViewport[viewp.size()]);
}
}
@@ -1647,25 +2244,29 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param af
*/
- public static void explodeViews(AlignFrame af) {
+ public static void explodeViews(AlignFrame af)
+ {
int size = af.alignPanels.size();
- if (size < 2) {
+ if (size < 2)
+ {
return;
}
// FIXME: ideally should use UI interface API
- FeatureSettings viewFeatureSettings = (af.featureSettings != null && af.featureSettings.isOpen())
- ? af.featureSettings
- : null;
+ FeatureSettings viewFeatureSettings = (af.featureSettings != null
+ && af.featureSettings.isOpen()) ? af.featureSettings : null;
Rectangle fsBounds = af.getFeatureSettingsGeometry();
- for (int i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++)
+ {
AlignmentPanel ap = af.alignPanels.get(i);
AlignFrame newaf = new AlignFrame(ap);
// transfer reference for existing feature settings to new alignFrame
- if (ap == af.alignPanel) {
- if (viewFeatureSettings != null && viewFeatureSettings.fr.ap == ap) {
+ if (ap == af.alignPanel)
+ {
+ if (viewFeatureSettings != null && viewFeatureSettings.fr.ap == ap)
+ {
newaf.featureSettings = viewFeatureSettings;
}
newaf.setFeatureSettingsGeometry(fsBounds);
@@ -1676,18 +2277,22 @@ public class Desktop extends jalview.jbgui.GDesktop
* one exploded frame share and restore the same (frame) position and size.
*/
Rectangle geometry = ap.av.getExplodedGeometry();
- if (geometry != null) {
+ if (geometry != null)
+ {
newaf.setBounds(geometry);
}
ap.av.setGatherViewsHere(false);
- addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
// and materialise a new feature settings dialog instance for the new
// alignframe
// (closes the old as if 'OK' was pressed)
- if (ap == af.alignPanel && newaf.featureSettings != null && newaf.featureSettings.isOpen()
- && af.alignPanel.getAlignViewport().isShowSequenceFeatures()) {
+ if (ap == af.alignPanel && newaf.featureSettings != null
+ && newaf.featureSettings.isOpen()
+ && af.alignPanel.getAlignViewport().isShowSequenceFeatures())
+ {
newaf.showFeatureSettingsUI();
}
}
@@ -1700,24 +2305,29 @@ public class Desktop extends jalview.jbgui.GDesktop
/**
* Gather expanded views (separate AlignFrame's) with the same sequence set
- * identifier back in to this frame as additional views, and close the expanded
- * views. Note the expanded frames may themselves have multiple views. We take
- * the lot.
+ * identifier back in to this frame as additional views, and close the
+ * expanded views. Note the expanded frames may themselves have multiple
+ * views. We take the lot.
*
* @param source
*/
- public void gatherViews(AlignFrame source) {
+ public void gatherViews(AlignFrame source)
+ {
source.viewport.setGatherViewsHere(true);
source.viewport.setExplodedGeometry(source.getBounds());
JInternalFrame[] frames = desktop.getAllFrames();
String viewId = source.viewport.getSequenceSetId();
- for (int t = 0; t < frames.length; t++) {
- if (frames[t] instanceof AlignFrame && frames[t] != source) {
+ for (int t = 0; t < frames.length; t++)
+ {
+ if (frames[t] instanceof AlignFrame && frames[t] != source)
+ {
AlignFrame af = (AlignFrame) frames[t];
boolean gatherThis = false;
- for (int a = 0; a < af.alignPanels.size(); a++) {
+ for (int a = 0; a < af.alignPanels.size(); a++)
+ {
AlignmentPanel ap = af.alignPanels.get(a);
- if (viewId.equals(ap.av.getSequenceSetId())) {
+ if (viewId.equals(ap.av.getSequenceSetId()))
+ {
gatherThis = true;
ap.av.setGatherViewsHere(false);
ap.av.setExplodedGeometry(af.getBounds());
@@ -1725,13 +2335,19 @@ public class Desktop extends jalview.jbgui.GDesktop
}
}
- if (gatherThis) {
- if (af.featureSettings != null && af.featureSettings.isOpen()) {
- if (source.featureSettings == null) {
+ if (gatherThis)
+ {
+ if (af.featureSettings != null && af.featureSettings.isOpen())
+ {
+ if (source.featureSettings == null)
+ {
// preserve the feature settings geometry for this frame
source.featureSettings = af.featureSettings;
- source.setFeatureSettingsGeometry(af.getFeatureSettingsGeometry());
- } else {
+ source.setFeatureSettingsGeometry(
+ af.getFeatureSettingsGeometry());
+ }
+ else
+ {
// close it and forget
af.featureSettings.close();
}
@@ -1743,13 +2359,15 @@ public class Desktop extends jalview.jbgui.GDesktop
}
// refresh the feature setting UI for the source frame if it exists
- if (source.featureSettings != null && source.featureSettings.isOpen()) {
+ if (source.featureSettings != null && source.featureSettings.isOpen())
+ {
source.showFeatureSettingsUI();
}
}
- public JInternalFrame[] getAllFrames() {
+ public JInternalFrame[] getAllFrames()
+ {
return desktop.getAllFrames();
}
@@ -1759,37 +2377,49 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param url
*/
- public void checkForQuestionnaire(String url) {
+ public void checkForQuestionnaire(String url)
+ {
UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
// javax.swing.SwingUtilities.invokeLater(jvq);
new Thread(jvq).start();
}
- public void checkURLLinks() {
+ public void checkURLLinks()
+ {
// Thread off the URL link checker
- addDialogThread(new Runnable() {
+ addDialogThread(new Runnable()
+ {
@Override
- public void run() {
- if (Cache.getDefault("CHECKURLLINKS", true)) {
+ public void run()
+ {
+ if (Cache.getDefault("CHECKURLLINKS", true))
+ {
// check what the actual links are - if it's just the default don't
// bother with the warning
- List links = Preferences.sequenceUrlLinks.getLinksForMenu();
+ List links = Preferences.sequenceUrlLinks
+ .getLinksForMenu();
// only need to check links if there is one with a
// SEQUENCE_ID which is not the default EMBL_EBI link
ListIterator li = links.listIterator();
boolean check = false;
List urls = new ArrayList<>();
- while (li.hasNext()) {
+ while (li.hasNext())
+ {
String link = li.next();
- if (link.contains(jalview.util.UrlConstants.SEQUENCE_ID) && !UrlConstants.isDefaultString(link)) {
+ if (link.contains(jalview.util.UrlConstants.SEQUENCE_ID)
+ && !UrlConstants.isDefaultString(link))
+ {
check = true;
int barPos = link.indexOf("|");
- String urlMsg = barPos == -1 ? link : link.substring(0, barPos) + ": " + link.substring(barPos + 1);
+ String urlMsg = barPos == -1 ? link
+ : link.substring(0, barPos) + ": "
+ + link.substring(barPos + 1);
urls.add(new JLabel(urlMsg));
}
}
- if (!check) {
+ if (!check)
+ {
return;
}
@@ -1798,27 +2428,36 @@ public class Desktop extends jalview.jbgui.GDesktop
JPanel msgPanel = new JPanel();
msgPanel.setLayout(new BoxLayout(msgPanel, BoxLayout.PAGE_AXIS));
msgPanel.add(Box.createVerticalGlue());
- JLabel msg = new JLabel(MessageManager.getString("label.SEQUENCE_ID_for_DB_ACCESSION1"));
- JLabel msg2 = new JLabel(MessageManager.getString("label.SEQUENCE_ID_for_DB_ACCESSION2"));
+ JLabel msg = new JLabel(MessageManager
+ .getString("label.SEQUENCE_ID_for_DB_ACCESSION1"));
+ JLabel msg2 = new JLabel(MessageManager
+ .getString("label.SEQUENCE_ID_for_DB_ACCESSION2"));
msgPanel.add(msg);
- for (JLabel url : urls) {
+ for (JLabel url : urls)
+ {
msgPanel.add(url);
}
msgPanel.add(msg2);
- final JCheckBox jcb = new JCheckBox(MessageManager.getString("label.do_not_display_again"));
- jcb.addActionListener(new ActionListener() {
+ final JCheckBox jcb = new JCheckBox(
+ MessageManager.getString("label.do_not_display_again"));
+ jcb.addActionListener(new ActionListener()
+ {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent e)
+ {
// update Cache settings for "don't show this again"
boolean showWarningAgain = !jcb.isSelected();
- Cache.setProperty("CHECKURLLINKS", Boolean.valueOf(showWarningAgain).toString());
+ Cache.setProperty("CHECKURLLINKS",
+ Boolean.valueOf(showWarningAgain).toString());
}
});
msgPanel.add(jcb);
JvOptionPane.showMessageDialog(Desktop.desktop, msgPanel,
- MessageManager.getString("label.SEQUENCE_ID_no_longer_used"), JvOptionPane.WARNING_MESSAGE);
+ MessageManager
+ .getString("label.SEQUENCE_ID_no_longer_used"),
+ JvOptionPane.WARNING_MESSAGE);
}
}
});
@@ -1826,11 +2465,13 @@ public class Desktop extends jalview.jbgui.GDesktop
/**
* Proxy class for JDesktopPane which optionally displays the current memory
- * usage and highlights the desktop area with a red bar if free memory runs low.
+ * usage and highlights the desktop area with a red bar if free memory runs
+ * low.
*
* @author AMW
*/
- public class MyDesktopPane extends JDesktopPane implements Runnable {
+ public class MyDesktopPane extends JDesktopPane implements Runnable
+ {
private static final float ONE_MB = 1048576f;
boolean showMemoryUsage = false;
@@ -1839,33 +2480,41 @@ public class Desktop extends jalview.jbgui.GDesktop
java.text.NumberFormat df;
- float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
+ float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
+ percentUsage;
- public MyDesktopPane(boolean showMemoryUsage) {
+ public MyDesktopPane(boolean showMemoryUsage)
+ {
showMemoryUsage(showMemoryUsage);
}
- public void showMemoryUsage(boolean showMemory) {
+ public void showMemoryUsage(boolean showMemory)
+ {
this.showMemoryUsage = showMemory;
- if (showMemory) {
+ if (showMemory)
+ {
Thread worker = new Thread(this);
worker.start();
}
repaint();
}
- public boolean isShowMemoryUsage() {
+ public boolean isShowMemoryUsage()
+ {
return showMemoryUsage;
}
@Override
- public void run() {
+ public void run()
+ {
df = java.text.NumberFormat.getNumberInstance();
df.setMaximumFractionDigits(2);
runtime = Runtime.getRuntime();
- while (showMemoryUsage) {
- try {
+ while (showMemoryUsage)
+ {
+ try
+ {
maxMemory = runtime.maxMemory() / ONE_MB;
allocatedMemory = runtime.totalMemory() / ONE_MB;
freeMemory = runtime.freeMemory() / ONE_MB;
@@ -1882,24 +2531,30 @@ public class Desktop extends jalview.jbgui.GDesktop
repaint();
// sleep after showing usage
Thread.sleep(3000);
- } catch (Exception ex) {
+ } catch (Exception ex)
+ {
ex.printStackTrace();
}
}
}
@Override
- public void paintComponent(Graphics g) {
- if (showMemoryUsage && g != null && df != null) {
- if (percentUsage < 20) {
+ public void paintComponent(Graphics g)
+ {
+ if (showMemoryUsage && g != null && df != null)
+ {
+ if (percentUsage < 20)
+ {
g.setColor(Color.red);
}
FontMetrics fm = g.getFontMetrics();
- if (fm != null) {
- g.drawString(
- MessageManager.formatMessage("label.memory_stats",
- new Object[] { df.format(totalFreeMemory), df.format(maxMemory), df.format(percentUsage) }),
- 10, getHeight() - fm.getHeight());
+ if (fm != null)
+ {
+ g.drawString(MessageManager.formatMessage("label.memory_stats",
+ new Object[]
+ { df.format(totalFreeMemory), df.format(maxMemory),
+ df.format(percentUsage) }),
+ 10, getHeight() - fm.getHeight());
}
}
@@ -1913,36 +2568,46 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @return an array of AlignFrame, or null if none found
*/
- public static AlignFrame[] getAlignFrames() {
- if (Jalview.isHeadlessMode()) {
- // Desktop.desktop is null in headless mode
- return new AlignFrame[] { Jalview.currentAlignFrame };
+ @Override
+ public AlignFrame[] getAlignFrames()
+ {
+ if (desktop == null)
+ {
+ return null;
}
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
- if (frames == null) {
+ if (frames == null)
+ {
return null;
}
List avp = new ArrayList<>();
// REVERSE ORDER
- for (int i = frames.length - 1; i > -1; i--) {
- if (frames[i] instanceof AlignFrame) {
+ for (int i = frames.length - 1; i > -1; i--)
+ {
+ if (frames[i] instanceof AlignFrame)
+ {
avp.add((AlignFrame) frames[i]);
- } else if (frames[i] instanceof SplitFrame) {
+ }
+ else if (frames[i] instanceof SplitFrame)
+ {
/*
* Also check for a split frame containing an AlignFrame
*/
GSplitFrame sf = (GSplitFrame) frames[i];
- if (sf.getTopFrame() instanceof AlignFrame) {
+ if (sf.getTopFrame() instanceof AlignFrame)
+ {
avp.add((AlignFrame) sf.getTopFrame());
}
- if (sf.getBottomFrame() instanceof AlignFrame) {
+ if (sf.getBottomFrame() instanceof AlignFrame)
+ {
avp.add((AlignFrame) sf.getBottomFrame());
}
}
}
- if (avp.size() == 0) {
+ if (avp.size() == 0)
+ {
return null;
}
AlignFrame afs[] = avp.toArray(new AlignFrame[avp.size()]);
@@ -1950,25 +2615,49 @@ public class Desktop extends jalview.jbgui.GDesktop
}
/**
+ * static version
+ */
+ public static AlignFrame[] getDesktopAlignFrames()
+ {
+ if (Jalview.isHeadlessMode())
+ {
+ // Desktop.desktop is null in headless mode
+ return Jalview.getInstance().getAlignFrames();
+ }
+
+ if (instance != null && desktop != null)
+ {
+ return instance.getAlignFrames();
+ }
+
+ return null;
+ }
+
+ /**
* Returns an array of any AppJmol frames in the Desktop (or null if none).
*
* @return
*/
- public GStructureViewer[] getJmols() {
+ public GStructureViewer[] getJmols()
+ {
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
- if (frames == null) {
+ if (frames == null)
+ {
return null;
}
List avp = new ArrayList<>();
// REVERSE ORDER
- for (int i = frames.length - 1; i > -1; i--) {
- if (frames[i] instanceof AppJmol) {
+ for (int i = frames.length - 1; i > -1; i--)
+ {
+ if (frames[i] instanceof AppJmol)
+ {
GStructureViewer af = (GStructureViewer) frames[i];
avp.add(af);
}
}
- if (avp.size() == 0) {
+ if (avp.size() == 0)
+ {
return null;
}
GStructureViewer afs[] = avp.toArray(new GStructureViewer[avp.size()]);
@@ -1979,25 +2668,34 @@ public class Desktop extends jalview.jbgui.GDesktop
* Add Groovy Support to Jalview
*/
@Override
- public void groovyShell_actionPerformed() {
- try {
+ public void groovyShell_actionPerformed()
+ {
+ try
+ {
openGroovyConsole();
- } catch (Exception ex) {
- jalview.bin.Console.error("Groovy Shell Creation failed.", ex);
+ } catch (Exception ex)
+ {
+ jalview.bin.Console.error("Groovy Console creation failed.", ex);
JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.getString("label.couldnt_create_groovy_shell"),
- MessageManager.getString("label.groovy_support_failed"), JvOptionPane.ERROR_MESSAGE);
+ MessageManager.getString("label.couldnt_create_groovy_shell"),
+ MessageManager.getString("label.groovy_support_failed"),
+ JvOptionPane.ERROR_MESSAGE);
}
}
/**
* Open the Groovy console
*/
- void openGroovyConsole() {
- if (groovyConsole == null) {
- groovyConsole = new groovy.ui.Console();
- groovyConsole.setVariable("Jalview", this);
+ void openGroovyConsole()
+ {
+ if (groovyConsole == null)
+ {
+ JalviewObjectI j = new JalviewObject(this);
+ groovyConsole = new groovy.console.ui.Console();
+ groovyConsole.setVariable(JalviewObjectI.jalviewObjectName, j);
+ groovyConsole.setVariable(JalviewObjectI.currentAlFrameName,
+ getCurrentAlignFrame());
groovyConsole.run();
/*
@@ -2007,9 +2705,11 @@ public class Desktop extends jalview.jbgui.GDesktop
* closed
*/
Window window = (Window) groovyConsole.getFrame();
- window.addWindowListener(new WindowAdapter() {
+ window.addWindowListener(new WindowAdapter()
+ {
@Override
- public void windowClosed(WindowEvent e) {
+ public void windowClosed(WindowEvent e)
+ {
/*
* rebind CMD-Q from Groovy Console to Jalview Quit
*/
@@ -2032,17 +2732,24 @@ public class Desktop extends jalview.jbgui.GDesktop
}
/**
- * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this binding
- * when opened
- */
- protected void addQuitHandler() {
- getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
- KeyStroke.getKeyStroke(KeyEvent.VK_Q, jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx()),
- "Quit");
- getRootPane().getActionMap().put("Quit", new AbstractAction() {
+ * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this
+ * binding when opened
+ */
+ protected void addQuitHandler()
+ {
+ getRootPane()
+ .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+ KeyStroke
+ .getKeyStroke(KeyEvent.VK_Q,
+ jalview.util.ShortcutKeyMaskExWrapper
+ .getMenuShortcutKeyMaskEx()),
+ "Quit");
+ getRootPane().getActionMap().put("Quit", new AbstractAction()
+ {
@Override
- public void actionPerformed(ActionEvent e) {
- quit();
+ public void actionPerformed(ActionEvent e)
+ {
+ desktopQuit();
}
});
}
@@ -2050,18 +2757,22 @@ public class Desktop extends jalview.jbgui.GDesktop
/**
* Enable or disable 'Run Groovy script' in AlignFrame calculate menus
*
- * @param enabled true if Groovy console is open
+ * @param enabled
+ * true if Groovy console is open
*/
- public void enableExecuteGroovy(boolean enabled) {
+ public void enableExecuteGroovy(boolean enabled)
+ {
/*
* disable opening a second Groovy console (or re-enable when the console is
* closed)
*/
groovyShell.setEnabled(!enabled);
- AlignFrame[] alignFrames = getAlignFrames();
- if (alignFrames != null) {
- for (AlignFrame af : alignFrames) {
+ AlignFrame[] alignFrames = getDesktopAlignFrames();
+ if (alignFrames != null)
+ {
+ for (AlignFrame af : alignFrames)
+ {
af.setGroovyEnabled(enabled);
}
}
@@ -2080,19 +2791,25 @@ public class Desktop extends jalview.jbgui.GDesktop
* @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
*/
@Override
- public void setProgressBar(String message, long id) {
- if (progressBars == null) {
+ public void setProgressBar(String message, long id)
+ {
+ if (progressBars == null)
+ {
progressBars = new Hashtable<>();
progressBarHandlers = new Hashtable<>();
}
- if (progressBars.get(Long.valueOf(id)) != null) {
+ if (progressBars.get(Long.valueOf(id)) != null)
+ {
JPanel panel = progressBars.remove(Long.valueOf(id));
- if (progressBarHandlers.contains(Long.valueOf(id))) {
+ if (progressBarHandlers.contains(Long.valueOf(id)))
+ {
progressBarHandlers.remove(Long.valueOf(id));
}
removeProgressPanel(panel);
- } else {
+ }
+ else
+ {
progressBars.put(Long.valueOf(id), addProgressPanel(message));
}
}
@@ -2104,22 +2821,33 @@ public class Desktop extends jalview.jbgui.GDesktop
* jalview.gui.IProgressIndicatorHandler)
*/
@Override
- public void registerHandler(final long id, final IProgressIndicatorHandler handler) {
- if (progressBarHandlers == null || !progressBars.containsKey(Long.valueOf(id))) {
- throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler"));
+ public void registerHandler(final long id,
+ final IProgressIndicatorHandler handler)
+ {
+ if (progressBarHandlers == null
+ || !progressBars.containsKey(Long.valueOf(id)))
+ {
+ throw new Error(MessageManager.getString(
+ "error.call_setprogressbar_before_registering_handler"));
}
progressBarHandlers.put(Long.valueOf(id), handler);
final JPanel progressPanel = progressBars.get(Long.valueOf(id));
- if (handler.canCancel()) {
- JButton cancel = new JButton(MessageManager.getString("action.cancel"));
+ if (handler.canCancel())
+ {
+ JButton cancel = new JButton(
+ MessageManager.getString("action.cancel"));
final IProgressIndicator us = this;
- cancel.addActionListener(new ActionListener() {
+ cancel.addActionListener(new ActionListener()
+ {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent e)
+ {
handler.cancelActivity(id);
- us.setProgressBar(MessageManager.formatMessage("label.cancelled_params",
- new Object[] { ((JLabel) progressPanel.getComponent(0)).getText() }), id);
+ us.setProgressBar(MessageManager
+ .formatMessage("label.cancelled_params", new Object[]
+ { ((JLabel) progressPanel.getComponent(0)).getText() }),
+ id);
}
});
progressPanel.add(cancel, BorderLayout.EAST);
@@ -2131,25 +2859,33 @@ public class Desktop extends jalview.jbgui.GDesktop
* @return true if any progress bars are still active
*/
@Override
- public boolean operationInProgress() {
- if (progressBars != null && progressBars.size() > 0) {
+ public boolean operationInProgress()
+ {
+ if (progressBars != null && progressBars.size() > 0)
+ {
return true;
}
return false;
}
/**
- * This will return the first AlignFrame holding the given viewport instance. It
- * will break if there are more than one AlignFrames viewing a particular av.
+ * This will return the first AlignFrame holding the given viewport instance.
+ * It will break if there are more than one AlignFrames viewing a particular
+ * av.
*
* @param viewport
* @return alignFrame for viewport
*/
- public static AlignFrame getAlignFrameFor(AlignViewportI viewport) {
- if (desktop != null) {
- AlignmentPanel[] aps = getAlignmentPanels(viewport.getSequenceSetId());
- for (int panel = 0; aps != null && panel < aps.length; panel++) {
- if (aps[panel] != null && aps[panel].av == viewport) {
+ public static AlignFrame getAlignFrameFor(AlignViewportI viewport)
+ {
+ if (desktop != null)
+ {
+ AlignmentPanel[] aps = getAlignmentPanels(
+ viewport.getSequenceSetId());
+ for (int panel = 0; aps != null && panel < aps.length; panel++)
+ {
+ if (aps[panel] != null && aps[panel].av == viewport)
+ {
return aps[panel].alignFrame;
}
}
@@ -2157,7 +2893,8 @@ public class Desktop extends jalview.jbgui.GDesktop
return null;
}
- public VamsasApplication getVamsasApplication() {
+ public VamsasApplication getVamsasApplication()
+ {
// TODO: JAL-3311 remove remaining code from Jalview relating to VAMSAS
return null;
@@ -2173,7 +2910,8 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @return inBatchMode
*/
- public boolean isInBatchMode() {
+ public boolean isInBatchMode()
+ {
return inBatchMode;
}
@@ -2182,14 +2920,16 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param inBatchMode
*/
- public void setInBatchMode(boolean inBatchMode) {
+ public void setInBatchMode(boolean inBatchMode)
+ {
this.inBatchMode = inBatchMode;
}
/**
* start service discovery and wait till it is done
*/
- public void startServiceDiscovery() {
+ public void startServiceDiscovery()
+ {
startServiceDiscovery(false);
}
@@ -2198,26 +2938,31 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param blocking
*/
- public void startServiceDiscovery(boolean blocking) {
+ public void startServiceDiscovery(boolean blocking)
+ {
startServiceDiscovery(blocking, false);
}
/**
* start service discovery threads
*
- * @param blocking - false means call returns
- * immediately
- * @param ignore_SHOW_JWS2_SERVICES_preference - when true JABA services are
- * discovered regardless of user's
- * JWS2 discovery preference setting
- */
- public void startServiceDiscovery(boolean blocking, boolean ignore_SHOW_JWS2_SERVICES_preference) {
+ * @param blocking
+ * - false means call returns immediately
+ * @param ignore_SHOW_JWS2_SERVICES_preference
+ * - when true JABA services are discovered regardless of user's JWS2
+ * discovery preference setting
+ */
+ public void startServiceDiscovery(boolean blocking,
+ boolean ignore_SHOW_JWS2_SERVICES_preference)
+ {
boolean alive = true;
Thread t0 = null, t1 = null, t2 = null;
// JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
- if (true) {
+ if (true)
+ {
// todo: changesupport handlers need to be transferred
- if (discoverer == null) {
+ if (discoverer == null)
+ {
discoverer = new jalview.ws.jws1.Discoverer();
// register PCS handler for desktop.
discoverer.addPropertyChangeListener(changeSupport);
@@ -2227,21 +2972,29 @@ public class Desktop extends jalview.jbgui.GDesktop
(t0 = new Thread(discoverer)).start();
}
- if (ignore_SHOW_JWS2_SERVICES_preference || Cache.getDefault("SHOW_JWS2_SERVICES", true)) {
- t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(changeSupport);
+ if (ignore_SHOW_JWS2_SERVICES_preference
+ || Cache.getDefault("SHOW_JWS2_SERVICES", true))
+ {
+ t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
+ .startDiscoverer(changeSupport);
}
Thread t3 = null;
{
// TODO: do rest service discovery
}
- if (blocking) {
- while (alive) {
- try {
+ if (blocking)
+ {
+ while (alive)
+ {
+ try
+ {
Thread.sleep(15);
- } catch (Exception e) {
+ } catch (Exception e)
+ {
}
- alive = (t1 != null && t1.isAlive()) || (t2 != null && t2.isAlive()) || (t3 != null && t3.isAlive())
- || (t0 != null && t0.isAlive());
+ alive = (t1 != null && t1.isAlive()) || (t2 != null && t2.isAlive())
+ || (t3 != null && t3.isAlive())
+ || (t0 != null && t0.isAlive());
}
}
}
@@ -2251,16 +3004,24 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param evt
*/
- protected void JalviewServicesChanged(PropertyChangeEvent evt) {
- if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector) {
- final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().getErrorMessages();
- if (ermsg != null) {
- if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true)) {
- if (serviceChangedDialog == null) {
+ protected void JalviewServicesChanged(PropertyChangeEvent evt)
+ {
+ if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
+ {
+ final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
+ .getErrorMessages();
+ if (ermsg != null)
+ {
+ if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
+ {
+ if (serviceChangedDialog == null)
+ {
// only run if we aren't already displaying one of these.
- addDialogThread(serviceChangedDialog = new Runnable() {
+ addDialogThread(serviceChangedDialog = new Runnable()
+ {
@Override
- public void run() {
+ public void run()
+ {
/*
* JalviewDialog jd =new JalviewDialog() {
@@ -2282,19 +3043,26 @@ public class Desktop extends jalview.jbgui.GDesktop
* jd.waitForInput();
*/
JvOptionPane.showConfirmDialog(Desktop.desktop,
- new JLabel(""
- + "It may be that you have invalid JABA URLs
in your web service preferences,"
- + "
or as a command-line argument, or mis-configured HTTP proxy settings.
"
- + "Check the Connections and Web services tab
of the"
- + " Tools->Preferences dialog box to change them.
"),
- "Web Service Configuration Problem", JvOptionPane.DEFAULT_OPTION, JvOptionPane.ERROR_MESSAGE);
+ new JLabel(""
+ + "It may be that you have invalid JABA URLs
in your web service preferences,"
+ + "
or as a command-line argument, or mis-configured HTTP proxy settings.
"
+ + "Check the Connections and Web services tab
of the"
+ + " Tools->Preferences dialog box to change them.
"),
+ "Web Service Configuration Problem",
+ JvOptionPane.DEFAULT_OPTION,
+ JvOptionPane.ERROR_MESSAGE);
serviceChangedDialog = null;
}
});
}
- } else {
- jalview.bin.Console.error("Errors reported by JABA discovery service. Check web services preferences.\n" + ermsg);
+ }
+ else
+ {
+ jalview.bin.Console.error(
+ "Errors reported by JABA discovery service. Check web services preferences.\n"
+ + ermsg);
}
}
}
@@ -2309,35 +3077,58 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param url
*/
- public static void showUrl(final String url) {
- showUrl(url, Desktop.instance);
+ public static void showUrl(final String url)
+ {
+ if (url != null && !url.trim().equals(""))
+ {
+ jalview.bin.Console.info("Opening URL: " + url);
+ showUrl(url, Desktop.instance);
+ }
+ else
+ {
+ jalview.bin.Console.warn("Ignoring attempt to show an empty URL.");
+ }
+
}
/**
* Like showUrl but allows progress handler to be specified
*
* @param url
- * @param progress (null) or object implementing IProgressIndicator
+ * @param progress
+ * (null) or object implementing IProgressIndicator
*/
- public static void showUrl(final String url, final IProgressIndicator progress) {
- new Thread(new Runnable() {
+ public static void showUrl(final String url,
+ final IProgressIndicator progress)
+ {
+ new Thread(new Runnable()
+ {
@Override
- public void run() {
- try {
- if (progress != null) {
- progress.setProgressBar(MessageManager.formatMessage("status.opening_params", new Object[] { url }),
- this.hashCode());
+ public void run()
+ {
+ try
+ {
+ if (progress != null)
+ {
+ progress.setProgressBar(MessageManager
+ .formatMessage("status.opening_params", new Object[]
+ { url }), IdUtils.newId(IdType.PROGRESS, this));
}
jalview.util.BrowserLauncher.openURL(url);
- } catch (Exception ex) {
+ } catch (Exception ex)
+ {
JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.getString("label.web_browser_not_found_unix"),
- MessageManager.getString("label.web_browser_not_found"), JvOptionPane.WARNING_MESSAGE);
+ MessageManager
+ .getString("label.web_browser_not_found_unix"),
+ MessageManager.getString("label.web_browser_not_found"),
+ JvOptionPane.WARNING_MESSAGE);
ex.printStackTrace();
}
- if (progress != null) {
- progress.setProgressBar(null, this.hashCode());
+ if (progress != null)
+ {
+ progress.setProgressBar(null,
+ IdUtils.newId(IdType.PROGRESS, this));
}
}
}).start();
@@ -2345,8 +3136,10 @@ public class Desktop extends jalview.jbgui.GDesktop
public static WsParamSetManager wsparamManager = null;
- public static ParamManager getUserParameterStore() {
- if (wsparamManager == null) {
+ public static ParamManager getUserParameterStore()
+ {
+ if (wsparamManager == null)
+ {
wsparamManager = new WsParamSetManager();
}
return wsparamManager;
@@ -2357,15 +3150,21 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param e
*/
- public static void hyperlinkUpdate(HyperlinkEvent e) {
- if (e.getEventType() == EventType.ACTIVATED) {
+ public static void hyperlinkUpdate(HyperlinkEvent e)
+ {
+ if (e.getEventType() == EventType.ACTIVATED)
+ {
String url = null;
- try {
+ try
+ {
url = e.getURL().toString();
Desktop.showUrl(url);
- } catch (Exception x) {
- if (url != null) {
- jalview.bin.Console.error("Couldn't handle string " + url + " as a URL.");
+ } catch (Exception x)
+ {
+ if (url != null)
+ {
+ jalview.bin.Console
+ .error("Couldn't handle string " + url + " as a URL.");
}
// ignore any exceptions due to dud links.
}
@@ -2376,7 +3175,7 @@ public class Desktop extends jalview.jbgui.GDesktop
/**
* single thread that handles display of dialogs to user.
*/
- ExecutorService dialogExecutor = Executors.newSingleThreadExecutor();
+ ExecutorService dialogExecutor = Executors.newFixedThreadPool(3);
/**
* flag indicating if dialogExecutor should try to acquire a permit
@@ -2386,42 +3185,77 @@ public class Desktop extends jalview.jbgui.GDesktop
/**
* pause the queue
*/
- private java.util.concurrent.Semaphore block = new Semaphore(0);
+ private Semaphore block = new Semaphore(0);
- private static groovy.ui.Console groovyConsole;
+ private static groovy.console.ui.Console groovyConsole;
/**
* add another dialog thread to the queue
*
* @param prompter
*/
- public void addDialogThread(final Runnable prompter) {
- dialogExecutor.submit(new Runnable() {
+ public void addDialogThread(final Runnable prompter)
+ {
+ dialogExecutor.submit(new Runnable()
+ {
@Override
- public void run() {
- if (dialogPause) {
- try {
- block.acquire();
- } catch (InterruptedException x) {
- }
+ public void run()
+ {
+ if (dialogPause)
+ {
+ acquireDialogQueue();
}
- if (instance == null) {
+ if (instance == null)
+ {
return;
}
- try {
+ try
+ {
SwingUtilities.invokeAndWait(prompter);
- } catch (Exception q) {
- jalview.bin.Console.warn("Unexpected Exception in dialog thread.", q);
+ } catch (Exception q)
+ {
+ jalview.bin.Console.warn("Unexpected Exception in dialog thread.",
+ q);
}
}
});
}
- public void startDialogQueue() {
+ private boolean dialogQueueStarted = false;
+
+ public void startDialogQueue()
+ {
+ if (dialogQueueStarted)
+ {
+ return;
+ }
// set the flag so we don't pause waiting for another permit and semaphore
// the current task to begin
- dialogPause = false;
+ releaseDialogQueue();
+ dialogQueueStarted = true;
+ }
+
+ public void acquireDialogQueue()
+ {
+ try
+ {
+ block.acquire();
+ dialogPause = true;
+ } catch (InterruptedException e)
+ {
+ jalview.bin.Console.debug("Interruption when acquiring DialogueQueue",
+ e);
+ }
+ }
+
+ public void releaseDialogQueue()
+ {
+ if (!dialogPause)
+ {
+ return;
+ }
block.release();
+ dialogPause = false;
}
/**
@@ -2434,41 +3268,59 @@ public class Desktop extends jalview.jbgui.GDesktop
*
*/
@Override
- protected void snapShotWindow_actionPerformed(ActionEvent e) {
+ protected void snapShotWindow_actionPerformed(ActionEvent e)
+ {
// currently the menu option to do this is not shown
invalidate();
int width = getWidth();
int height = getHeight();
- File of = new File("Jalview_snapshot_" + System.currentTimeMillis() + ".eps");
- ImageWriterI writer = new ImageWriterI() {
+ File of = new File(
+ "Jalview_snapshot_" + System.currentTimeMillis() + ".eps");
+ ImageWriterI writer = new ImageWriterI()
+ {
@Override
- public void exportImage(Graphics g) throws Exception {
+ public void exportImage(Graphics g) throws Exception
+ {
paintAll(g);
- jalview.bin.Console.info("Successfully written snapshot to file " + of.getAbsolutePath());
+ jalview.bin.Console.info("Successfully written snapshot to file "
+ + of.getAbsolutePath());
}
};
String title = "View of desktop";
- ImageExporter exporter = new ImageExporter(writer, null, TYPE.EPS, title);
- exporter.doExport(of, this, width, height, title);
+ ImageExporter exporter = new ImageExporter(writer, null, TYPE.EPS,
+ title);
+ try
+ {
+ exporter.doExport(of, this, width, height, title);
+ } catch (ImageOutputException ioex)
+ {
+ jalview.bin.Console.error(
+ "Unexpected error whilst writing Jalview desktop snapshot as EPS",
+ ioex);
+ }
}
/**
* Explode the views in the given SplitFrame into separate SplitFrame windows.
- * This respects (remembers) any previous 'exploded geometry' i.e. the size and
- * location last time the view was expanded (if any). However it does not
+ * This respects (remembers) any previous 'exploded geometry' i.e. the size
+ * and location last time the view was expanded (if any). However it does not
* remember the split pane divider location - this is set to match the
* 'exploding' frame.
*
* @param sf
*/
- public void explodeViews(SplitFrame sf) {
+ public void explodeViews(SplitFrame sf)
+ {
AlignFrame oldTopFrame = (AlignFrame) sf.getTopFrame();
AlignFrame oldBottomFrame = (AlignFrame) sf.getBottomFrame();
- List extends AlignmentViewPanel> topPanels = oldTopFrame.getAlignPanels();
- List extends AlignmentViewPanel> bottomPanels = oldBottomFrame.getAlignPanels();
+ List extends AlignmentViewPanel> topPanels = oldTopFrame
+ .getAlignPanels();
+ List extends AlignmentViewPanel> bottomPanels = oldBottomFrame
+ .getAlignPanels();
int viewCount = topPanels.size();
- if (viewCount < 2) {
+ if (viewCount < 2)
+ {
return;
}
@@ -2476,7 +3328,8 @@ public class Desktop extends jalview.jbgui.GDesktop
* Processing in reverse order works, forwards order leaves the first panels not
* visible. I don't know why!
*/
- for (int i = viewCount - 1; i >= 0; i--) {
+ for (int i = viewCount - 1; i >= 0; i--)
+ {
/*
* Make new top and bottom frames. These take over the respective AlignmentPanel
* objects, including their AlignmentViewports, so the cdna/protein
@@ -2489,8 +3342,10 @@ public class Desktop extends jalview.jbgui.GDesktop
AlignFrame newTopFrame = new AlignFrame(topPanel);
newTopFrame.setSize(oldTopFrame.getSize());
newTopFrame.setVisible(true);
- Rectangle geometry = ((AlignViewport) topPanel.getAlignViewport()).getExplodedGeometry();
- if (geometry != null) {
+ Rectangle geometry = ((AlignViewport) topPanel.getAlignViewport())
+ .getExplodedGeometry();
+ if (geometry != null)
+ {
newTopFrame.setSize(geometry.getSize());
}
@@ -2498,15 +3353,19 @@ public class Desktop extends jalview.jbgui.GDesktop
AlignFrame newBottomFrame = new AlignFrame(bottomPanel);
newBottomFrame.setSize(oldBottomFrame.getSize());
newBottomFrame.setVisible(true);
- geometry = ((AlignViewport) bottomPanel.getAlignViewport()).getExplodedGeometry();
- if (geometry != null) {
+ geometry = ((AlignViewport) bottomPanel.getAlignViewport())
+ .getExplodedGeometry();
+ if (geometry != null)
+ {
newBottomFrame.setSize(geometry.getSize());
}
topPanel.av.setGatherViewsHere(false);
bottomPanel.av.setGatherViewsHere(false);
- JInternalFrame splitFrame = new SplitFrame(newTopFrame, newBottomFrame);
- if (geometry != null) {
+ JInternalFrame splitFrame = new SplitFrame(newTopFrame,
+ newBottomFrame);
+ if (geometry != null)
+ {
splitFrame.setLocation(geometry.getLocation());
}
Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1);
@@ -2528,7 +3387,8 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* @param source
*/
- public void gatherViews(GSplitFrame source) {
+ public void gatherViews(GSplitFrame source)
+ {
/*
* special handling of explodedGeometry for a view within a SplitFrame: - it
* holds the (x, y) position of the enclosing SplitFrame, and the (width,
@@ -2536,38 +3396,46 @@ public class Desktop extends jalview.jbgui.GDesktop
*/
AlignFrame myTopFrame = (AlignFrame) source.getTopFrame();
AlignFrame myBottomFrame = (AlignFrame) source.getBottomFrame();
- myTopFrame.viewport.setExplodedGeometry(
- new Rectangle(source.getX(), source.getY(), myTopFrame.getWidth(), myTopFrame.getHeight()));
- myBottomFrame.viewport.setExplodedGeometry(
- new Rectangle(source.getX(), source.getY(), myBottomFrame.getWidth(), myBottomFrame.getHeight()));
+ myTopFrame.viewport.setExplodedGeometry(new Rectangle(source.getX(),
+ source.getY(), myTopFrame.getWidth(), myTopFrame.getHeight()));
+ myBottomFrame.viewport
+ .setExplodedGeometry(new Rectangle(source.getX(), source.getY(),
+ myBottomFrame.getWidth(), myBottomFrame.getHeight()));
myTopFrame.viewport.setGatherViewsHere(true);
myBottomFrame.viewport.setGatherViewsHere(true);
String topViewId = myTopFrame.viewport.getSequenceSetId();
String bottomViewId = myBottomFrame.viewport.getSequenceSetId();
JInternalFrame[] frames = desktop.getAllFrames();
- for (JInternalFrame frame : frames) {
- if (frame instanceof SplitFrame && frame != source) {
+ for (JInternalFrame frame : frames)
+ {
+ if (frame instanceof SplitFrame && frame != source)
+ {
SplitFrame sf = (SplitFrame) frame;
AlignFrame topFrame = (AlignFrame) sf.getTopFrame();
AlignFrame bottomFrame = (AlignFrame) sf.getBottomFrame();
boolean gatherThis = false;
- for (int a = 0; a < topFrame.alignPanels.size(); a++) {
+ for (int a = 0; a < topFrame.alignPanels.size(); a++)
+ {
AlignmentPanel topPanel = topFrame.alignPanels.get(a);
AlignmentPanel bottomPanel = bottomFrame.alignPanels.get(a);
if (topViewId.equals(topPanel.av.getSequenceSetId())
- && bottomViewId.equals(bottomPanel.av.getSequenceSetId())) {
+ && bottomViewId.equals(bottomPanel.av.getSequenceSetId()))
+ {
gatherThis = true;
topPanel.av.setGatherViewsHere(false);
bottomPanel.av.setGatherViewsHere(false);
- topPanel.av.setExplodedGeometry(new Rectangle(sf.getLocation(), topFrame.getSize()));
- bottomPanel.av.setExplodedGeometry(new Rectangle(sf.getLocation(), bottomFrame.getSize()));
+ topPanel.av.setExplodedGeometry(
+ new Rectangle(sf.getLocation(), topFrame.getSize()));
+ bottomPanel.av.setExplodedGeometry(
+ new Rectangle(sf.getLocation(), bottomFrame.getSize()));
myTopFrame.addAlignmentPanel(topPanel, false);
myBottomFrame.addAlignmentPanel(bottomPanel, false);
}
}
- if (gatherThis) {
+ if (gatherThis)
+ {
topFrame.getAlignPanels().clear();
bottomFrame.getAlignPanels().clear();
sf.close();
@@ -2581,7 +3449,8 @@ public class Desktop extends jalview.jbgui.GDesktop
myTopFrame.setDisplayedView(myTopFrame.alignPanel);
}
- public static groovy.ui.Console getGroovyConsole() {
+ public static groovy.console.ui.Console getGroovyConsole()
+ {
return groovyConsole;
}
@@ -2590,88 +3459,127 @@ public class Desktop extends jalview.jbgui.GDesktop
*
* TODO refactor to desktop utilities class
*
- * @param files - Data source strings extracted from the drop event
- * @param protocols - protocol for each data source extracted from the drop
- * event
- * @param evt - the drop event
- * @param t - the payload from the drop event
+ * @param files
+ * - Data source strings extracted from the drop event
+ * @param protocols
+ * - protocol for each data source extracted from the drop event
+ * @param evt
+ * - the drop event
+ * @param t
+ * - the payload from the drop event
* @throws Exception
*/
- public static void transferFromDropTarget(List