X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=8ba21e5a08bab761334ccb73b059b9a8f3e802c1;hb=e1767448d422ab26a6920bae2173804eda662e31;hp=7407cbaf33e35a1ddd73deec7cc209f7079f0ef6;hpb=ab43013b7e357b84b4abade0dba949668dfb2a0e;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 7407cba..8ba21e5 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,15 +20,22 @@ */ package jalview.gui; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.io.FileLoader; import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; +import jalview.jbgui.GSplitFrame; +import jalview.jbgui.GStructureViewer; import jalview.structure.StructureSelectionManager; import jalview.util.ImageMaker; import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.ParamManager; import java.awt.BorderLayout; @@ -68,6 +75,7 @@ import java.lang.reflect.Constructor; import java.net.URL; import java.util.ArrayList; import java.util.Hashtable; +import java.util.List; import java.util.StringTokenizer; import java.util.Vector; import java.util.concurrent.ExecutorService; @@ -113,6 +121,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ private BlogReader jvnews = null; + private File projectFile; + /** * @param listener * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener) @@ -159,6 +169,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements static final int yOffset = 30; + private static AlignFrame currentAlignFrame; + public static jalview.ws.jws1.Discoverer discoverer; public static Object[] jalviewClipboard; @@ -177,6 +189,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements this.delegate = delegate; } + @Override public void activateFrame(JInternalFrame f) { try @@ -189,31 +202,37 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void beginDraggingFrame(JComponent f) { delegate.beginDraggingFrame(f); } + @Override public void beginResizingFrame(JComponent f, int direction) { delegate.beginResizingFrame(f, direction); } + @Override public void closeFrame(JInternalFrame f) { delegate.closeFrame(f); } + @Override public void deactivateFrame(JInternalFrame f) { delegate.deactivateFrame(f); } + @Override public void deiconifyFrame(JInternalFrame f) { delegate.deiconifyFrame(f); } + @Override public void dragFrame(JComponent f, int newX, int newY) { if (newY < 0) @@ -223,40 +242,46 @@ public class Desktop extends jalview.jbgui.GDesktop implements delegate.dragFrame(f, newX, newY); } + @Override public void endDraggingFrame(JComponent f) { delegate.endDraggingFrame(f); } + @Override public void endResizingFrame(JComponent f) { delegate.endResizingFrame(f); } + @Override public void iconifyFrame(JInternalFrame f) { delegate.iconifyFrame(f); } + @Override public void maximizeFrame(JInternalFrame f) { delegate.maximizeFrame(f); } + @Override public void minimizeFrame(JInternalFrame f) { delegate.minimizeFrame(f); } + @Override public void openFrame(JInternalFrame f) { delegate.openFrame(f); } + @Override public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) { - Rectangle b = desktop.getBounds(); if (newY < 0) { newY = 0; @@ -264,6 +289,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements delegate.resizeFrame(f, newX, newY, newWidth, newHeight); } + @Override public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) { @@ -295,6 +321,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements boolean showjconsole = jalview.bin.Cache.getDefault( "SHOW_JAVA_CONSOLE", false); desktop = new MyDesktopPane(selmemusage); + if (Platform.isAMac()) + { + desktop.setDoubleBuffered(false); + } showMemusage.setSelected(selmemusage); desktop.setBackground(Color.white); getContentPane().setLayout(new BorderLayout()); @@ -327,8 +357,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements + jalview.bin.Cache.getProperty("VERSION") + "\n" + "Jalview Installation: " + jalview.bin.Cache.getDefault("INSTALLATION", "unknown") - + "\n" - + "Build Date: " + + "\n" + "Build Date: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n" + "Java version: " + System.getProperty("java.version") + "\n" + System.getProperty("os.arch") + " " @@ -341,6 +370,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements this.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent evt) { quit(); @@ -350,6 +380,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements MouseAdapter ma; this.addMouseListener(ma = new MouseAdapter() { + @Override public void mousePressed(MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) @@ -382,6 +413,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // Spawn a thread that shows the splashscreen SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { new SplashScreen(); @@ -393,10 +425,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements // takes to open it later on. new Thread(new Runnable() { + @Override public void run() { Cache.log.debug("Filechooser init thread started."); - JalviewFileChooser chooser = new JalviewFileChooser( + new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY"), jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS, jalview.io.AppletFormatAdapter.READABLE_FNAMES, @@ -429,9 +462,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements { ssm.setAddTempFacAnnot(jalview.bin.Cache.getDefault( Preferences.ADD_TEMPFACT_ANN, true)); - ssm.setProcessSecondaryStructure(jalview.bin.Cache.getDefault(Preferences.STRUCT_FROM_PDB, true)); - ssm.setSecStructServices(jalview.bin.Cache.getDefault(Preferences.USE_RNAVIEW, - true)); + ssm.setProcessSecondaryStructure(jalview.bin.Cache.getDefault( + Preferences.STRUCT_FROM_PDB, true)); + ssm.setSecStructServices(jalview.bin.Cache.getDefault( + Preferences.USE_RNAVIEW, true)); } else { @@ -459,6 +493,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements }); } + @Override protected void showNews_actionPerformed(ActionEvent e) { showNews(showNews.isSelected()); @@ -476,10 +511,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements @Override public void run() { - long instance = System.currentTimeMillis(); - Desktop.instance.setProgressBar(MessageManager.getString("status.refreshing_news"), instance); + long now = System.currentTimeMillis(); + Desktop.instance.setProgressBar( + MessageManager.getString("status.refreshing_news"), now); jvnews.refreshNews(); - Desktop.instance.setProgressBar(null, instance); + Desktop.instance.setProgressBar(null, now); jvnews.showNews(); } }).start(); @@ -561,16 +597,19 @@ public class Desktop extends jalview.jbgui.GDesktop implements // reselected again. boolean refresh = true; + @Override public void menuCanceled(MenuEvent e) { refresh = true; } + @Override public void menuDeselected(MenuEvent e) { refresh = true; } + @Override public void menuSelected(MenuEvent e) { if (refresh) @@ -591,6 +630,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements MessageManager.getString("label.paste_new_window")); item.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent evt) { paste(); @@ -645,7 +685,6 @@ public class Desktop extends jalview.jbgui.GDesktop implements addInternalFrame(frame, title, true, w, h, true); } - /** * Add an internal frame to the Jalview desktop * @@ -739,8 +778,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements frame.setResizable(resizable); frame.setMaximizable(resizable); frame.setIconifiable(resizable); - frame.setFrameIcon(null); - + if (Platform.isAMac()) + { + frame.setIconifiable(false); + frame.setFrameIcon(null); + // frame.setDesktopIcon(null); + frame.setDoubleBuffered(false); + } if (frame.getX() < 1 && frame.getY() < 1) { frame.setLocation(xOffset * openFrameCount, yOffset @@ -750,6 +794,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements final JMenuItem menuItem = new JMenuItem(title); frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() { + @Override public void internalFrameActivated( javax.swing.event.InternalFrameEvent evt) { @@ -761,6 +806,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } + @Override public void internalFrameClosed( javax.swing.event.InternalFrameEvent evt) { @@ -778,6 +824,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements menuItem.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { try @@ -850,6 +897,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { if (!internalCopy) @@ -860,18 +908,22 @@ public class Desktop extends jalview.jbgui.GDesktop implements internalCopy = false; } + @Override public void dragEnter(DropTargetDragEvent evt) { } + @Override public void dragExit(DropTargetEvent evt) { } + @Override public void dragOver(DropTargetDragEvent evt) { } + @Override public void dropActionChanged(DropTargetDragEvent evt) { } @@ -882,6 +934,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param evt * DOCUMENT ME! */ + @Override public void drop(DropTargetDropEvent evt) { boolean success = true; @@ -975,6 +1028,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param e * DOCUMENT ME! */ + @Override public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport) { JalviewFileChooser chooser = new JalviewFileChooser( @@ -1011,6 +1065,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements { new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format); + // viewport.setShowSequenceFeatures(JSONFile.isSeqFeaturesEnabled()); + // AlignFrame af = viewport.getAlignPanel().alignFrame; + // if (af != null) + // { + // af.changeColour(JSONFile.getColourScheme()); + // af.setMenusForViewport(); + // } } else { @@ -1025,6 +1086,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param e * DOCUMENT ME! */ + @Override public void inputURLMenuItem_actionPerformed(AlignViewport viewport) { // This construct allows us to have a wider textfield @@ -1084,7 +1146,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (format.equals("URL NOT FOUND")) { JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.formatMessage("label.couldnt_locate", new String[]{url}), MessageManager.getString("label.url_not_found"), + MessageManager.formatMessage("label.couldnt_locate", + new Object[] { url }), MessageManager + .getString("label.url_not_found"), JOptionPane.WARNING_MESSAGE); return; @@ -1102,15 +1166,18 @@ public class Desktop extends jalview.jbgui.GDesktop implements } /** - * DOCUMENT ME! + * Opens the CutAndPaste window for the user to paste an alignment in to * - * @param e - * DOCUMENT ME! + * @param viewPanel + * - if not null, the pasted alignment is added to the current + * alignment; if null, to a new alignment window */ - public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport) + @Override + public void inputTextboxMenuItem_actionPerformed( + AlignmentViewPanel viewPanel) { CutAndPasteTransfer cap = new CutAndPasteTransfer(); - cap.setForInput(viewport); + cap.setForInput(viewPanel); Desktop.addInternalFrame(cap, MessageManager.getString("label.cut_paste_alignmen_file"), true, 600, 500); @@ -1119,6 +1186,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements /* * Exit the program */ + @Override public void quit() { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); @@ -1143,7 +1211,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { dialogExecutor.shutdownNow(); } - + closeAll_actionPerformed(null); System.exit(0); } @@ -1165,6 +1233,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param e * DOCUMENT ME! */ + @Override public void aboutMenuItem_actionPerformed(ActionEvent e) { // StringBuffer message = getAboutMessage(false); @@ -1173,6 +1242,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE); new Thread(new Runnable() { + @Override public void run() { new SplashScreen(true); @@ -1187,8 +1257,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (shortv) { message.append("

Version: " - + jalview.bin.Cache.getProperty("VERSION") - + "

"); + + jalview.bin.Cache.getProperty("VERSION") + ""); message.append("Last Updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + ""); @@ -1234,8 +1303,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } message.append("
Authors: " + jalview.bin.Cache - .getDefault( - "AUTHORFNAMES", + .getDefault("AUTHORFNAMES", "The Jalview Authors (See AUTHORS file for current list)") + "

Development managed by The Barton Group, University of Dundee, Scotland, UK.
" + "

For help, see the FAQ at www.jalview.org/faq and/or join the jalview-discuss@jalview.org mailing list" @@ -1253,6 +1321,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param e * DOCUMENT ME! */ + @Override public void documentationMenuItem_actionPerformed(ActionEvent e) { try @@ -1263,6 +1332,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void closeAll_actionPerformed(ActionEvent e) { JInternalFrame[] frames = desktop.getAllFrames(); @@ -1279,15 +1349,27 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (v_client != null) { // TODO clear binding to vamsas document objects on close_all + } + /* + * reset state of singleton objects as appropriate (clear down session state + * when all windows are closed) + */ + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(this); + if (ssm != null) + { + ssm.resetAll(); } } + @Override public void raiseRelated_actionPerformed(ActionEvent e) { reorderAssociatedWindows(false, false); } + @Override public void minimizeAssociated_actionPerformed(ActionEvent e) { reorderAssociatedWindows(true, false); @@ -1304,6 +1386,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event. * ActionEvent) */ + @Override protected void garbageCollect_actionPerformed(ActionEvent e) { // We simply collect the garbage @@ -1319,6 +1402,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent * ) */ + @Override protected void showMemusage_actionPerformed(ActionEvent e) { desktop.showMemoryUsage(showMemusage.isSelected()); @@ -1331,6 +1415,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent * ) */ + @Override protected void showConsole_actionPerformed(ActionEvent e) { showConsole(showConsole.isSelected()); @@ -1360,7 +1445,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements return; } - AlignViewport source = null, target = null; + AlignmentViewport source = null, target = null; if (frames[0] instanceof AlignFrame) { source = ((AlignFrame) frames[0]).getCurrentView(); @@ -1435,6 +1520,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param e * DOCUMENT ME! */ + @Override protected void preferences_actionPerformed(ActionEvent e) { new Preferences(); @@ -1446,12 +1532,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param e * DOCUMENT ME! */ + @Override public void saveState_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "jvp" }, new String[] - { "Jalview Project" }, "Jalview Project"); + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), + new String[] { "jvp" }, new String[] { "Jalview Project" }, + "Jalview Project"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.save_state")); @@ -1462,20 +1549,24 @@ public class Desktop extends jalview.jbgui.GDesktop implements { final Desktop me = this; final java.io.File choice = chooser.getSelectedFile(); + setProjectFile(choice); + new Thread(new Runnable() { + @Override public void run() { - - setProgressBar(MessageManager.formatMessage("label.saving_jalview_project", new String[]{choice.getName()}), - choice.hashCode()); + // TODO: refactor to Jalview desktop session controller action. + setProgressBar(MessageManager.formatMessage( + "label.saving_jalview_project", + new Object[] { choice.getName() }), choice.hashCode()); jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); // TODO catch and handle errors for savestate // TODO prevent user from messing with the Desktop whilst we're saving try { - new Jalview2XML().SaveState(choice); + new Jalview2XML().saveState(choice); } catch (OutOfMemoryError oom) { new OOMWarning("Whilst saving current state to " @@ -1485,10 +1576,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements Cache.log.error( "Problems whilst trying to save to " + choice.getName(), ex); - JOptionPane.showMessageDialog( - me, - MessageManager.formatMessage("label.error_whilst_saving_current_state_to", new String[]{ choice.getName()}), - MessageManager.getString("label.couldnt_save_project"), + JOptionPane.showMessageDialog(me, MessageManager.formatMessage( + "label.error_whilst_saving_current_state_to", + new Object[] { choice.getName() }), MessageManager + .getString("label.couldnt_save_project"), JOptionPane.WARNING_MESSAGE); } setProgressBar(null, choice.hashCode()); @@ -1497,19 +1588,29 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + private void setProjectFile(File choice) + { + this.projectFile = choice; + } + + public File getProjectFile() + { + return this.projectFile; + } + /** * DOCUMENT ME! * * @param e * DOCUMENT ME! */ + @Override public void loadState_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "jvp", "jar" }, new String[] - { "Jalview Project", "Jalview Project (old)" }, - "Jalview Project"); + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] { + "jvp", "jar" }, new String[] { "Jalview Project", + "Jalview Project (old)" }, "Jalview Project"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.restore_state")); @@ -1517,18 +1618,23 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (value == JalviewFileChooser.APPROVE_OPTION) { - final String choice = chooser.getSelectedFile().getAbsolutePath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser - .getSelectedFile().getParent()); + final File selectedFile = chooser.getSelectedFile(); + setProjectFile(selectedFile); + final String choice = selectedFile.getAbsolutePath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + selectedFile.getParent()); new Thread(new Runnable() { + @Override public void run() { - setProgressBar(MessageManager.formatMessage("label.loading_jalview_project", new String[]{choice}), - choice.hashCode()); + setProgressBar( + MessageManager.formatMessage( + "label.loading_jalview_project", + new Object[] { choice }), choice.hashCode()); try { - new Jalview2XML().LoadJalviewAlign(choice); + new Jalview2XML().loadJalviewAlign(choice); } catch (OutOfMemoryError oom) { new OOMWarning("Whilst loading project from " + choice, oom); @@ -1536,9 +1642,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements { Cache.log.error("Problems whilst loading project from " + choice, ex); - JOptionPane.showMessageDialog(Desktop.desktop, - MessageManager.formatMessage("label.error_whilst_loading_project_from", new String[]{choice}), - MessageManager.getString("label.couldnt_load_project"), JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(Desktop.desktop, MessageManager + .formatMessage( + "label.error_whilst_loading_project_from", + new Object[] { choice }), MessageManager + .getString("label.couldnt_load_project"), + JOptionPane.WARNING_MESSAGE); } setProgressBar(null, choice.hashCode()); } @@ -1546,6 +1655,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void inputSequence_actionPerformed(ActionEvent e) { new SequenceFetcher(this); @@ -1559,7 +1669,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements { if (fileLoadingCount == 0) { - fileLoadingPanels.add(addProgressPanel(MessageManager.formatMessage("label.loading_file", new String[]{fileName}))); + fileLoadingPanels.add(addProgressPanel(MessageManager.formatMessage( + "label.loading_file", new Object[] { fileName }))); } fileLoadingCount++; } @@ -1625,38 +1736,38 @@ public class Desktop extends jalview.jbgui.GDesktop implements public static int getViewCount(String alignmentId) { - AlignViewport[] aps = getViewports(alignmentId); + AlignmentViewport[] aps = getViewports(alignmentId); return (aps == null) ? 0 : aps.length; } /** * * @param alignmentId + * - if null, all sets are returned * @return all AlignmentPanels concerning the alignmentId sequence set */ public static AlignmentPanel[] getAlignmentPanels(String alignmentId) { - int count = 0; if (Desktop.desktop == null) { // no frames created and in headless mode // TODO: verify that frames are recoverable when in headless mode return null; } - JInternalFrame[] frames = Desktop.desktop.getAllFrames(); - ArrayList aps = new ArrayList(); - for (int t = 0; t < frames.length; t++) + List aps = new ArrayList(); + AlignFrame[] frames = getAlignFrames(); + if (frames == null) + { + return null; + } + for (AlignFrame af : frames) { - if (frames[t] instanceof AlignFrame) + for (AlignmentPanel ap : af.alignPanels) { - AlignFrame af = (AlignFrame) frames[t]; - for (int a = 0; a < af.alignPanels.size(); a++) + if (alignmentId == null + || alignmentId.equals(ap.av.getSequenceSetId())) { - if (alignmentId.equals(((AlignmentPanel) af.alignPanels - .elementAt(a)).av.getSequenceSetId())) - { - aps.add(af.alignPanels.elementAt(a)); - } + aps.add(ap); } } } @@ -1664,11 +1775,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { return null; } - AlignmentPanel[] vap = new AlignmentPanel[aps.size()]; - for (int t = 0; t < vap.length; t++) - { - vap[t] = (AlignmentPanel) aps.get(t); - } + AlignmentPanel[] vap = aps.toArray(new AlignmentPanel[aps.size()]); return vap; } @@ -1676,52 +1783,53 @@ public class Desktop extends jalview.jbgui.GDesktop implements * get all the viewports on an alignment. * * @param sequenceSetId - * unique alignment id + * unique alignment id (may be null - all viewports returned in that + * case) * @return all viewports on the alignment bound to sequenceSetId */ - public static AlignViewport[] getViewports(String sequenceSetId) + public static AlignmentViewport[] getViewports(String sequenceSetId) { - Vector viewp = new Vector(); + List viewp = new ArrayList(); if (desktop != null) { - javax.swing.JInternalFrame[] frames = instance.getAllFrames(); + AlignFrame[] frames = Desktop.getAlignFrames(); - for (int t = 0; t < frames.length; t++) + for (AlignFrame afr : frames) { - if (frames[t] instanceof AlignFrame) + if (sequenceSetId == null + || afr.getViewport().getSequenceSetId() + .equals(sequenceSetId)) { - AlignFrame afr = ((AlignFrame) frames[t]); - if (afr.getViewport().getSequenceSetId().equals(sequenceSetId)) + if (afr.alignPanels != null) { - if (afr.alignPanels != null) + for (AlignmentPanel ap : afr.alignPanels) { - for (int a = 0; a < afr.alignPanels.size(); a++) + if (sequenceSetId == null + || sequenceSetId.equals(ap.av.getSequenceSetId())) { - if (sequenceSetId.equals(((AlignmentPanel) afr.alignPanels - .elementAt(a)).av.getSequenceSetId())) - { - viewp.addElement(((AlignmentPanel) afr.alignPanels - .elementAt(a)).av); - } + viewp.add(ap.av); } } - else - { - viewp.addElement(((AlignFrame) frames[t]).getViewport()); - } + } + else + { + viewp.add(afr.getViewport()); } } } if (viewp.size() > 0) { - AlignViewport[] vp = new AlignViewport[viewp.size()]; - viewp.copyInto(vp); - return vp; + return viewp.toArray(new AlignmentViewport[viewp.size()]); } } return null; } + /** + * Explode the views in the given frame into separate AlignFrame + * + * @param af + */ public void explodeViews(AlignFrame af) { int size = af.alignPanels.size(); @@ -1732,15 +1840,21 @@ public class Desktop extends jalview.jbgui.GDesktop implements for (int i = 0; i < size; i++) { - AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i); + AlignmentPanel ap = af.alignPanels.get(i); AlignFrame newaf = new AlignFrame(ap); - if (ap.av.explodedPosition != null - && !ap.av.explodedPosition.equals(af.getBounds())) + + /* + * Restore the view's last exploded frame geometry if known. Multiple + * views from one exploded frame share and restore the same (frame) + * position and size. + */ + Rectangle geometry = ap.av.getExplodedGeometry(); + if (geometry != null) { - newaf.setBounds(ap.av.explodedPosition); + newaf.setBounds(geometry); } - ap.av.gatherViewsHere = false; + ap.av.setGatherViewsHere(false); addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); @@ -1751,10 +1865,18 @@ public class Desktop extends jalview.jbgui.GDesktop implements } + /** + * 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. + * + * @param source + */ public void gatherViews(AlignFrame source) { - source.viewport.gatherViewsHere = true; - source.viewport.explodedPosition = source.getBounds(); + source.viewport.setGatherViewsHere(true); + source.viewport.setExplodedGeometry(source.getBounds()); JInternalFrame[] frames = desktop.getAllFrames(); String viewId = source.viewport.getSequenceSetId(); @@ -1766,12 +1888,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements boolean gatherThis = false; for (int a = 0; a < af.alignPanels.size(); a++) { - AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a); + AlignmentPanel ap = af.alignPanels.get(a); if (viewId.equals(ap.av.getSequenceSetId())) { gatherThis = true; - ap.av.gatherViewsHere = false; - ap.av.explodedPosition = af.getBounds(); + ap.av.setGatherViewsHere(false); + ap.av.setExplodedGeometry(af.getBounds()); source.addAlignmentPanel(ap, false); } } @@ -1788,6 +1910,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements jalview.gui.VamsasApplication v_client = null; + @Override public void vamsasImport_actionPerformed(ActionEvent e) { if (v_client == null) @@ -1797,7 +1920,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle(MessageManager.getString("label.open_saved_vamsas_session")); + chooser.setDialogTitle(MessageManager + .getString("label.open_saved_vamsas_session")); chooser.setToolTipText(MessageManager .getString("label.select_vamsas_session_opened_as_new_vamsas_session")); @@ -1813,8 +1937,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements Desktop.desktop, MessageManager.formatMessage( "label.couldnt_import_as_vamsas_session", - new String[] - { fle }), + new Object[] { fle }), MessageManager .getString("label.vamsas_document_import_failed"), JOptionPane.ERROR_MESSAGE); @@ -1890,23 +2013,26 @@ public class Desktop extends jalview.jbgui.GDesktop implements return false; } - setProgressBar(MessageManager.formatMessage("status.importing_vamsas_session_from", new String[]{file.getName()}), - file.hashCode()); + setProgressBar(MessageManager.formatMessage( + "status.importing_vamsas_session_from", + new Object[] { file.getName() }), file.hashCode()); try { v_client = new jalview.gui.VamsasApplication(this, file, null); } catch (Exception ex) { - setProgressBar(MessageManager.formatMessage("status.importing_vamsas_session_from", new String[]{file.getName()}), - file.hashCode()); + setProgressBar(MessageManager.formatMessage( + "status.importing_vamsas_session_from", + new Object[] { file.getName() }), file.hashCode()); jalview.bin.Cache.log.error( "New vamsas session from existing session file failed:", ex); return false; } setupVamsasConnectedGui(); v_client.initial_update(); // TODO: thread ? - setProgressBar(MessageManager.formatMessage("status.importing_vamsas_session_from", new String[]{file.getName()}), - file.hashCode()); + setProgressBar(MessageManager.formatMessage( + "status.importing_vamsas_session_from", + new Object[] { file.getName() }), file.hashCode()); return v_client.inSession(); } @@ -1914,11 +2040,14 @@ public class Desktop extends jalview.jbgui.GDesktop implements { if (v_client != null) { - throw new Error(MessageManager.getString("error.try_join_vamsas_session_another")); + throw new Error( + MessageManager + .getString("error.try_join_vamsas_session_another")); } if (mysesid == null) { - throw new Error(MessageManager.getString("error.invalid_vamsas_session_id")); + throw new Error( + MessageManager.getString("error.invalid_vamsas_session_id")); } v_client = new VamsasApplication(this, mysesid); setupVamsasConnectedGui(); @@ -1926,6 +2055,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements return (v_client.inSession()); } + @Override public void vamsasStart_actionPerformed(ActionEvent e) { if (v_client == null) @@ -1974,6 +2104,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements .getString("label.new_vamsas_session")); } + @Override public void vamsasStop_actionPerformed(ActionEvent e) { if (v_client != null) @@ -2008,13 +2139,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements JMenuItem sessit = new JMenuItem(); sessit.setText(sess[i]); sessit.setToolTipText(MessageManager.formatMessage( - "label.connect_to_session", new String[] - { sess[i] })); + "label.connect_to_session", new Object[] { sess[i] })); final Desktop dsktp = this; final String mysesid = sess[i]; sessit.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (dsktp.v_client == null) @@ -2022,6 +2153,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements Thread rthr = new Thread(new Runnable() { + @Override public void run() { dsktp.v_client = new VamsasApplication(dsktp, mysesid); @@ -2054,6 +2186,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void vamsasSave_actionPerformed(ActionEvent e) { if (v_client != null) @@ -2061,18 +2194,20 @@ public class Desktop extends jalview.jbgui.GDesktop implements JalviewFileChooser chooser = new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ - new String[] - { "Vamsas Document" }, "Vamsas Document"); + new String[] { "Vamsas Document" }, "Vamsas Document"); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle(MessageManager.getString("label.save_vamsas_document_archive")); + chooser.setDialogTitle(MessageManager + .getString("label.save_vamsas_document_archive")); int value = chooser.showSaveDialog(this); if (value == JalviewFileChooser.APPROVE_OPTION) { java.io.File choice = chooser.getSelectedFile(); - JPanel progpanel = addProgressPanel(MessageManager.formatMessage("label.saving_vamsas_doc", new String[]{choice.getName()})); + JPanel progpanel = addProgressPanel(MessageManager.formatMessage( + "label.saving_vamsas_doc", + new Object[] { choice.getName() })); jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); String warnmsg = null; String warnttl = null; @@ -2124,7 +2259,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements } if (b) { - vamUpdate = this.addProgressPanel(MessageManager.getString("label.updating_vamsas_session")); + vamUpdate = this.addProgressPanel(MessageManager + .getString("label.updating_vamsas_session")); } vamsasStart.setVisible(!b); vamsasStop.setVisible(!b); @@ -2159,6 +2295,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements public class MyDesktopPane extends JDesktopPane implements Runnable { + private static final float ONE_MB = 1048576f; + boolean showMemoryUsage = false; Runtime runtime; @@ -2173,10 +2311,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements showMemoryUsage(showMemoryUsage); } - public void showMemoryUsage(boolean showMemoryUsage) + public void showMemoryUsage(boolean showMemory) { - this.showMemoryUsage = showMemoryUsage; - if (showMemoryUsage) + this.showMemoryUsage = showMemory; + if (showMemory) { Thread worker = new Thread(this); worker.start(); @@ -2188,6 +2326,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements return showMemoryUsage; } + @Override public void run() { df = java.text.NumberFormat.getNumberInstance(); @@ -2198,9 +2337,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements { try { - maxMemory = runtime.maxMemory() / 1048576f; - allocatedMemory = runtime.totalMemory() / 1048576f; - freeMemory = runtime.freeMemory() / 1048576f; + maxMemory = runtime.maxMemory() / ONE_MB; + allocatedMemory = runtime.totalMemory() / ONE_MB; + freeMemory = runtime.freeMemory() / ONE_MB; totalFreeMemory = freeMemory + (maxMemory - allocatedMemory); percentUsage = (totalFreeMemory / maxMemory) * 100; @@ -2221,6 +2360,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void paintComponent(Graphics g) { if (showMemoryUsage && g != null && df != null) @@ -2234,9 +2374,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements { g.drawString(MessageManager.formatMessage( "label.memory_stats", - new String[] - { df.format(totalFreeMemory), df.format(maxMemory), - df.format(percentUsage) }), 10, + new Object[] { df.format(totalFreeMemory), + df.format(maxMemory), df.format(percentUsage) }), 10, getHeight() - fm.getHeight()); } } @@ -2262,9 +2401,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements groovyShell.setText(MessageManager.getString("label.groovy_console")); groovyShell.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - groovyShell_actionPerformed(e); + groovyShell_actionPerformed(); } }); toolsMenu.add(groovyShell); @@ -2274,45 +2414,61 @@ public class Desktop extends jalview.jbgui.GDesktop implements /** * Accessor method to quickly get all the AlignmentFrames loaded. + * + * @return an array of AlignFrame, or null if none found */ - public static AlignFrame[] getAlignframes() + public static AlignFrame[] getAlignFrames() { + if (Jalview.isHeadlessMode()) + { + // Desktop.desktop is null in headless mode + return new AlignFrame[] { currentAlignFrame }; + } + JInternalFrame[] frames = Desktop.desktop.getAllFrames(); if (frames == null) { return null; } - Vector avp = new Vector(); - try + List avp = new ArrayList(); + // REVERSE ORDER + for (int i = frames.length - 1; i > -1; i--) { - // REVERSE ORDER - for (int i = frames.length - 1; i > -1; i--) + if (frames[i] instanceof AlignFrame) { - if (frames[i] instanceof AlignFrame) + avp.add((AlignFrame) frames[i]); + } + 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) { - AlignFrame af = (AlignFrame) frames[i]; - avp.addElement(af); + avp.add((AlignFrame) sf.getTopFrame()); + } + if (sf.getBottomFrame() instanceof AlignFrame) + { + avp.add((AlignFrame) sf.getBottomFrame()); } } - } catch (Exception ex) - { - ex.printStackTrace(); } if (avp.size() == 0) { return null; } - AlignFrame afs[] = new AlignFrame[avp.size()]; - for (int i = 0, j = avp.size(); i < j; i++) - { - afs[i] = (AlignFrame) avp.elementAt(i); - } - avp.clear(); + AlignFrame afs[] = avp.toArray(new AlignFrame[avp.size()]); return afs; } - public AppJmol[] getJmols() + /** + * Returns an array of any AppJmol frames in the Desktop (or null if none). + * + * @return + */ + public GStructureViewer[] getJmols() { JInternalFrame[] frames = Desktop.desktop.getAllFrames(); @@ -2320,68 +2476,55 @@ public class Desktop extends jalview.jbgui.GDesktop implements { return null; } - Vector avp = new Vector(); - try + List avp = new ArrayList(); + // REVERSE ORDER + for (int i = frames.length - 1; i > -1; i--) { - // REVERSE ORDER - for (int i = frames.length - 1; i > -1; i--) + if (frames[i] instanceof AppJmol) { - if (frames[i] instanceof AppJmol) - { - AppJmol af = (AppJmol) frames[i]; - avp.addElement(af); - } + GStructureViewer af = (GStructureViewer) frames[i]; + avp.add(af); } - } catch (Exception ex) - { - ex.printStackTrace(); } if (avp.size() == 0) { return null; } - AppJmol afs[] = new AppJmol[avp.size()]; - for (int i = 0, j = avp.size(); i < j; i++) - { - afs[i] = (AppJmol) avp.elementAt(i); - } - avp.clear(); + GStructureViewer afs[] = avp.toArray(new GStructureViewer[avp.size()]); return afs; } /** * Add Groovy Support to Jalview */ - public void groovyShell_actionPerformed(ActionEvent e) + public void groovyShell_actionPerformed() { // use reflection to avoid creating compilation dependency. if (!jalview.bin.Cache.groovyJarsPresent()) { - throw new Error(MessageManager.getString("error.implementation_error_cannot_create_groovyshell")); + throw new Error( + MessageManager + .getString("error.implementation_error_cannot_create_groovyshell")); } try { - Class gcClass = Desktop.class.getClassLoader().loadClass( + Class gcClass = Desktop.class.getClassLoader().loadClass( "groovy.ui.Console"); - Constructor gccons = gcClass.getConstructor(null); + Constructor gccons = gcClass.getConstructor(); java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", - new Class[] - { String.class, Object.class }); - java.lang.reflect.Method run = gcClass.getMethod("run", null); - Object gc = gccons.newInstance(null); - setvar.invoke(gc, new Object[] - { "Jalview", this }); - run.invoke(gc, null); + new Class[] { String.class, Object.class }); + java.lang.reflect.Method run = gcClass.getMethod("run"); + Object gc = gccons.newInstance(); + setvar.invoke(gc, new Object[] { "Jalview", this }); + run.invoke(gc); } catch (Exception ex) { jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex); - JOptionPane - .showInternalMessageDialog( - Desktop.desktop, + JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.couldnt_create_groovy_shell"), - MessageManager.getString("label.groovy_support_failed"), - JOptionPane.ERROR_MESSAGE); + MessageManager.getString("label.couldnt_create_groovy_shell"), + MessageManager.getString("label.groovy_support_failed"), + JOptionPane.ERROR_MESSAGE); } } @@ -2397,6 +2540,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) */ + @Override public void setProgressBar(String message, long id) { if (progressBars == null) @@ -2407,12 +2551,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (progressBars.get(new Long(id)) != null) { - JPanel progressPanel = progressBars.remove(new Long(id)); + JPanel panel = progressBars.remove(new Long(id)); if (progressBarHandlers.contains(new Long(id))) { progressBarHandlers.remove(new Long(id)); } - removeProgressPanel(progressPanel); + removeProgressPanel(panel); } else { @@ -2426,12 +2570,16 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @see jalview.gui.IProgressIndicator#registerHandler(long, * jalview.gui.IProgressIndicatorHandler) */ + @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) { - if (progressBarHandlers == null || !progressBars.contains(new Long(id))) + if (progressBarHandlers == null + || !progressBars.containsKey(new Long(id))) { - throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler")); + throw new Error( + MessageManager + .getString("error.call_setprogressbar_before_registering_handler")); } progressBarHandlers.put(new Long(id), handler); final JPanel progressPanel = progressBars.get(new Long(id)); @@ -2443,10 +2591,14 @@ public class Desktop extends jalview.jbgui.GDesktop implements cancel.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { handler.cancelActivity(id); - us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new String[]{((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); @@ -2468,20 +2620,21 @@ public class Desktop extends jalview.jbgui.GDesktop implements } /** - * This will return the first AlignFrame viewing AlignViewport av. It will - * break if there are more than one AlignFrames viewing a particular av. This + * 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 av - * @return alignFrame for av + * @param viewport + * @return alignFrame for viewport */ - public static AlignFrame getAlignFrameFor(AlignViewport av) + public static AlignFrame getAlignFrameFor(AlignViewportI viewport) { if (desktop != null) { - AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId()); + AlignmentPanel[] aps = getAlignmentPanels(viewport.getSequenceSetId()); for (int panel = 0; aps != null && panel < aps.length; panel++) { - if (aps[panel] != null && aps[panel].av == av) + if (aps[panel] != null && aps[panel].av == viewport) { return aps[panel].alignFrame; } @@ -2545,28 +2698,6 @@ public class Desktop extends jalview.jbgui.GDesktop implements (t0 = new Thread(discoverer)).start(); } - // ENFIN services are EOLed as of Jalview 2.8.1 release - if (false) - { - try - { - if (Cache.getDefault("SHOW_ENFIN_SERVICES", true)) - { - // EnfinEnvision web service menu entries are rebuild every time the - // menu is shown, so no changeSupport events are needed. - jalview.ws.EnfinEnvision2OneWay.getInstance(); - (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance())) - .start(); - } - } catch (Exception e) - { - Cache.log - .info("Exception when trying to launch Envision2 workflow discovery.", - e); - Cache.log.info(e.getStackTrace()); - } - } - if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning()) @@ -2619,6 +2750,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // only run if we aren't already displaying one of these. addDialogThread(serviceChangedDialog = new Runnable() { + @Override public void run() { @@ -2702,23 +2834,25 @@ public class Desktop extends jalview.jbgui.GDesktop implements { new Thread(new Runnable() { + @Override public void run() { try { if (progress != null) { - progress.setProgressBar(MessageManager.formatMessage("status.opening_params", new String[]{url}), this.hashCode()); + progress.setProgressBar(MessageManager.formatMessage( + "status.opening_params", new Object[] { url }), this + .hashCode()); } jalview.util.BrowserLauncher.openURL(url); } catch (Exception ex) { - JOptionPane - .showInternalMessageDialog( - Desktop.desktop, - MessageManager.getString("label.web_browser_not_found_unix"), - MessageManager.getString("label.web_browser_not_found"), - JOptionPane.WARNING_MESSAGE); + JOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager + .getString("label.web_browser_not_found_unix"), + MessageManager.getString("label.web_browser_not_found"), + JOptionPane.WARNING_MESSAGE); ex.printStackTrace(); } @@ -2799,6 +2933,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { dialogExecutor.submit(new Runnable() { + @Override public void run() { if (dialogPause) @@ -2833,6 +2968,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements dialogPause = false; block.release(); } + @Override protected void snapShotWindow_actionPerformed(ActionEvent e) { @@ -2841,15 +2977,179 @@ public class Desktop extends jalview.jbgui.GDesktop implements ImageMaker im = new jalview.util.ImageMaker(this, ImageMaker.TYPE.EPS, "View of Desktop", getWidth(), getHeight(), of = new File( "Jalview_snapshot" + System.currentTimeMillis() - + ".eps"), "View of desktop"); - try { + + ".eps"), "View of desktop", null, 0, false); + try + { paintAll(im.getGraphics()); im.writeImage(); } catch (Exception q) { - Cache.log.error("Couldn't write snapshot to "+of.getAbsolutePath(),q); + Cache.log.error("Couldn't write snapshot to " + of.getAbsolutePath(), + q); return; } - Cache.log.info("Successfully written snapshot to file "+of.getAbsolutePath()); + Cache.log.info("Successfully written snapshot to file " + + of.getAbsolutePath()); } + + /** + * 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 + * remember the split pane divider location - this is set to match the + * 'exploding' frame. + * + * @param sf + */ + public void explodeViews(SplitFrame sf) + { + AlignFrame oldTopFrame = (AlignFrame) sf.getTopFrame(); + AlignFrame oldBottomFrame = (AlignFrame) sf.getBottomFrame(); + List topPanels = oldTopFrame + .getAlignPanels(); + List bottomPanels = oldBottomFrame + .getAlignPanels(); + int viewCount = topPanels.size(); + if (viewCount < 2) + { + return; + } + + /* + * 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--) + { + /* + * Make new top and bottom frames. These take over the respective + * AlignmentPanel objects, including their AlignmentViewports, so the + * cdna/protein relationships between the viewports is carried over to the + * new split frames. + * + * explodedGeometry holds the (x, y) position of the previously exploded + * SplitFrame, and the (width, height) of the AlignFrame component + */ + AlignmentPanel topPanel = (AlignmentPanel) topPanels.get(i); + AlignFrame newTopFrame = new AlignFrame(topPanel); + newTopFrame.setSize(oldTopFrame.getSize()); + newTopFrame.setVisible(true); + Rectangle geometry = ((AlignViewport) topPanel.getAlignViewport()) + .getExplodedGeometry(); + if (geometry != null) + { + newTopFrame.setSize(geometry.getSize()); + } + + AlignmentPanel bottomPanel = (AlignmentPanel) bottomPanels.get(i); + AlignFrame newBottomFrame = new AlignFrame(bottomPanel); + newBottomFrame.setSize(oldBottomFrame.getSize()); + newBottomFrame.setVisible(true); + 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) + { + splitFrame.setLocation(geometry.getLocation()); + } + Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1); + } + + /* + * Clear references to the panels (now relocated in the new SplitFrames) + * before closing the old SplitFrame. + */ + topPanels.clear(); + bottomPanels.clear(); + sf.close(); + } + + /** + * Gather expanded split frames, sharing the same pairs of sequence set ids, + * back into the given SplitFrame as additional views. Note that the gathered + * frames may themselves have multiple views. + * + * @param 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, + * height) of the AlignFrame component + */ + 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.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) + { + 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++) + { + AlignmentPanel topPanel = topFrame.alignPanels.get(a); + AlignmentPanel bottomPanel = bottomFrame.alignPanels.get(a); + if (topViewId.equals(topPanel.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())); + myTopFrame.addAlignmentPanel(topPanel, false); + myBottomFrame.addAlignmentPanel(bottomPanel, false); + } + } + + if (gatherThis) + { + topFrame.getAlignPanels().clear(); + bottomFrame.getAlignPanels().clear(); + sf.close(); + } + } + } + + /* + * The dust settles...give focus to the tab we did this from. + */ + myTopFrame.setDisplayedView(myTopFrame.alignPanel); + + } + + public static AlignFrame getCurrentAlignFrame() + { + return currentAlignFrame; + } + + public static void setCurrentAlignFrame(AlignFrame currentAlignFrame) + { + Desktop.currentAlignFrame = currentAlignFrame; + } + }