+ public void actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ frame.setSelected(true);
+ frame.setIcon(false);
+ } catch (java.beans.PropertyVetoException ex)
+ {
+
+ }
+ }
+ });
+ menuItem.addMouseListener(new MouseListener()
+ {
+
+ @Override
+ public void mouseReleased(MouseEvent e)
+ {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e)
+ {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e)
+ {
+ try
+ {
+ frame.setSelected(false);
+ } catch (PropertyVetoException e1)
+ {
+ }
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e)
+ {
+ try
+ {
+ frame.setSelected(true);
+ } catch (PropertyVetoException e1)
+ {
+ }
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e)
+ {
+
+ }
+ });
+
+ windowMenu.add(menuItem);
+
+ desktop.add(frame);
+ frame.toFront();
+ try
+ {
+ frame.setSelected(true);
+ frame.requestFocus();
+ } catch (java.beans.PropertyVetoException ve)
+ {
+ } catch (java.lang.ClassCastException cex)
+ {
+ Cache.log
+ .warn("Squashed a possible GUI implementation error. If you can recreate this, please look at http://issues.jalview.org/browse/JAL-869",
+ cex);
+ }
+ }
+
+ public void lostOwnership(Clipboard clipboard, Transferable contents)
+ {
+ if (!internalCopy)
+ {
+ Desktop.jalviewClipboard = null;
+ }
+
+ internalCopy = false;
+ }
+
+ public void dragEnter(DropTargetDragEvent evt)
+ {
+ }
+
+ public void dragExit(DropTargetEvent evt)
+ {
+ }
+
+ public void dragOver(DropTargetDragEvent evt)
+ {
+ }
+
+ @Override
+ public void dropActionChanged(DropTargetDragEvent evt)
+ {
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt
+ * DOCUMENT ME!
+ */
+ public void drop(DropTargetDropEvent evt)
+ {
+ boolean success = true;
+ Transferable t = evt.getTransferable();
+ java.util.List files = null;
+ java.util.List protocols = null;
+
+ try
+ {
+ DataFlavor uriListFlavor = new DataFlavor(
+ "text/uri-list;class=java.lang.String");
+ if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
+ {
+ // Works on Windows and MacOSX
+ evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+ files = (java.util.List) t
+ .getTransferData(DataFlavor.javaFileListFlavor);
+ }
+ else if (t.isDataFlavorSupported(uriListFlavor))
+ {
+ // This is used by Unix drag system
+ evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+ String data = (String) t.getTransferData(uriListFlavor);
+ files = new java.util.ArrayList(1);
+ protocols = new java.util.ArrayList(1);
+ for (java.util.StringTokenizer st = new java.util.StringTokenizer(
+ data, "\r\n"); st.hasMoreTokens();)
+ {
+ String s = st.nextToken();
+ if (s.startsWith("#"))
+ {
+ // the line is a comment (as per the RFC 2483)
+ continue;
+ }
+ java.net.URI uri = new java.net.URI(s);
+ if (uri.getScheme().toLowerCase().startsWith("http"))
+ {
+ protocols.add(FormatAdapter.URL);
+ files.add(uri.toString());
+ }
+ else
+ {
+ // otherwise preserve old behaviour: catch all for file objects
+ java.io.File file = new java.io.File(uri);
+ protocols.add(FormatAdapter.FILE);
+ files.add(file.toString());
+ }
+ }
+ }
+ } catch (Exception e)
+ {
+ success = false;
+ }
+
+ if (files != null)
+ {
+ try
+ {
+ for (int i = 0; i < files.size(); i++)
+ {
+ String file = files.get(i).toString();
+ String protocol = (protocols == null) ? FormatAdapter.FILE
+ : (String) protocols.get(i);
+ String format = null;
+
+ if (file.endsWith(".jar"))
+ {
+ format = "Jalview";
+
+ }
+ else
+ {
+ format = new IdentifyFile().Identify(file, protocol);
+ }
+
+ new FileLoader().LoadFile(file, protocol, format);
+
+ }
+ } catch (Exception ex)
+ {
+ success = false;
+ }
+ }
+ evt.dropComplete(success); // need this to ensure input focus is properly
+ // transfered to any new windows created
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ @Override
+ public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
+ jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
+ jalview.io.AppletFormatAdapter.READABLE_FNAMES,
+ jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager
+ .getString("label.open_local_file"));
+ chooser.setToolTipText(MessageManager.getString("action.open"));
+
+ int value = chooser.showOpenDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ String choice = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
+ .getSelectedFile().getParent());
+
+ String format = null;
+ if (chooser.getSelectedFormat() != null
+ && chooser.getSelectedFormat().equals("Jalview"))
+ {
+ format = "Jalview";
+ }
+ else
+ {
+ format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
+ }
+
+ if (viewport != null)
+ {
+ 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
+ {
+ new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ @Override
+ public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
+ {
+ // This construct allows us to have a wider textfield
+ // for viewing
+ JLabel label = new JLabel(
+ MessageManager.getString("label.input_file_url"));
+ final JComboBox history = new JComboBox();
+
+ JPanel panel = new JPanel(new GridLayout(2, 1));
+ panel.add(label);
+ panel.add(history);
+ history.setPreferredSize(new Dimension(400, 20));
+ history.setEditable(true);
+ history.addItem("http://www.");
+
+ String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
+
+ StringTokenizer st;
+
+ if (historyItems != null)
+ {
+ st = new StringTokenizer(historyItems, "\t");
+
+ while (st.hasMoreTokens())
+ {
+ history.addItem(st.nextElement());
+ }
+ }
+
+ int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
+ MessageManager.getString("label.input_alignment_from_url"),
+ JOptionPane.OK_CANCEL_OPTION);
+
+ if (reply != JOptionPane.OK_OPTION)
+ {
+ return;
+ }
+
+ String url = history.getSelectedItem().toString();
+
+ if (url.toLowerCase().endsWith(".jar"))
+ {
+ if (viewport != null)
+ {
+ new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
+ "Jalview");
+ }
+ else
+ {
+ new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
+ }
+ }
+ else
+ {
+ String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
+
+ if (format.equals("URL NOT FOUND"))
+ {
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ MessageManager.formatMessage("label.couldnt_locate",
+ new Object[] { url }), MessageManager
+ .getString("label.url_not_found"),
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+
+ if (viewport != null)
+ {
+ new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
+ }
+ else
+ {
+ new FileLoader().LoadFile(url, FormatAdapter.URL, format);
+ }
+ }
+ }
+
+ /**
+ * Opens the CutAndPaste window for the user to paste an alignment in to
+ *
+ * @param viewPanel
+ * - if not null, the pasted alignment is added to the current
+ * alignment; if null, to a new alignment window
+ */
+ @Override
+ public void inputTextboxMenuItem_actionPerformed(
+ AlignmentViewPanel viewPanel)
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ cap.setForInput(viewPanel);
+ Desktop.addInternalFrame(cap,
+ MessageManager.getString("label.cut_paste_alignmen_file"),
+ true, 600, 500);
+ }
+
+ /*
+ * Exit the program
+ */
+ @Override
+ public void quit()
+ {
+ Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
+ jalview.bin.Cache
+ .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
+ jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
+ + "");
+ storeLastKnownDimensions("", new Rectangle(getBounds().x,
+ getBounds().y, getWidth(), getHeight()));
+
+ if (jconsole != null)
+ {
+ storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
+ jconsole.stopConsole();
+ }
+ if (jvnews != null)
+ {
+ storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
+
+ }
+ if (dialogExecutor != null)
+ {
+ dialogExecutor.shutdownNow();
+ }
+ closeAll_actionPerformed(null);
+ System.exit(0);
+ }
+
+ private void storeLastKnownDimensions(String string, Rectangle jc)
+ {
+ jalview.bin.Cache.log.debug("Storing last known dimensions for "
+ + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
+ + " height:" + jc.height);
+
+ jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
+ jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
+ jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
+ jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ @Override
+ public void aboutMenuItem_actionPerformed(ActionEvent e)
+ {
+ // StringBuffer message = getAboutMessage(false);
+ // JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ //
+ // message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ new SplashScreen(true);
+ }
+ }).start();
+ }
+
+ public StringBuffer getAboutMessage(boolean shortv)
+ {
+ StringBuffer message = new StringBuffer();
+ message.append("<html>");
+ if (shortv)
+ {
+ message.append("<h1><strong>Version: "
+ + jalview.bin.Cache.getProperty("VERSION") + "</strong></h1>");
+ message.append("<strong>Last Updated: <em>"
+ + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")
+ + "</em></strong>");
+
+ }
+ else
+ {
+
+ message.append("<strong>Version "
+ + jalview.bin.Cache.getProperty("VERSION")
+ + "; last updated: "
+ + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
+ }
+
+ if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
+ "Checking"))
+ {
+ message.append("<br>...Checking latest version...</br>");
+ }
+ else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
+ .equals(jalview.bin.Cache.getProperty("VERSION")))
+ {
+ boolean red = false;
+ if (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
+ .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("<div style=\"color: #FF0000;font-style: bold;\">");
+ }
+
+ message.append("<br>!! Version "
+ + jalview.bin.Cache.getDefault("LATEST_VERSION",
+ "..Checking..")
+ + " is available for download from "
+ + jalview.bin.Cache.getDefault("www.jalview.org",
+ "http://www.jalview.org") + " !!");
+ if (red)
+ {
+ message.append("</div>");
+ }
+ }
+ message.append("<br>Authors: "
+ + jalview.bin.Cache
+ .getDefault("AUTHORFNAMES",
+ "The Jalview Authors (See AUTHORS file for current list)")
+ + "<br><br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
+ + "<br><br>For help, see the FAQ at <a href=\"http://www.jalview.org/faq\">www.jalview.org/faq</a> and/or join the jalview-discuss@jalview.org mailing list"
+ + "<br><br>If you use Jalview, please cite:"
+ + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
+ + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
+ + "<br>Bioinformatics doi: 10.1093/bioinformatics/btp033"
+ + "</html>");
+ return message;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ @Override
+ public void documentationMenuItem_actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ Help.showHelpWindow();
+ } catch (Exception ex)
+ {
+ }
+ }
+
+ @Override
+ public void closeAll_actionPerformed(ActionEvent e)
+ {
+ JInternalFrame[] frames = desktop.getAllFrames();
+ for (int i = 0; i < frames.length; i++)
+ {
+ try
+ {
+ frames[i].setClosed(true);
+ } catch (java.beans.PropertyVetoException ex)
+ {
+ }
+ }
+ System.out.println("ALL CLOSED");
+ 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);
+ }
+
+ void closeAssociatedWindows()
+ {
+ reorderAssociatedWindows(false, true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
+ * ActionEvent)
+ */
+ @Override
+ protected void garbageCollect_actionPerformed(ActionEvent e)
+ {
+ // We simply collect the garbage
+ jalview.bin.Cache.log.debug("Collecting garbage...");
+ System.gc();
+ jalview.bin.Cache.log.debug("Finished garbage collection.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
+ * )
+ */
+ @Override
+ protected void showMemusage_actionPerformed(ActionEvent e)
+ {
+ desktop.showMemoryUsage(showMemusage.isSelected());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
+ * )
+ */
+ @Override
+ protected void showConsole_actionPerformed(ActionEvent e)
+ {
+ showConsole(showConsole.isSelected());
+ }
+
+ Console jconsole = null;
+
+ /**
+ * control whether the java console is visible or not
+ *
+ * @param selected
+ */
+ void showConsole(boolean selected)
+ {
+ showConsole.setSelected(selected);
+ // TODO: decide if we should update properties file
+ Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected)
+ .toString());
+ jconsole.setVisible(selected);
+ }
+
+ void reorderAssociatedWindows(boolean minimize, boolean close)
+ {
+ JInternalFrame[] frames = desktop.getAllFrames();
+ if (frames == null || frames.length < 1)
+ {
+ return;
+ }
+
+ AlignmentViewport source = null, target = null;
+ if (frames[0] instanceof AlignFrame)
+ {
+ source = ((AlignFrame) frames[0]).getCurrentView();
+ }
+ else if (frames[0] instanceof TreePanel)
+ {
+ source = ((TreePanel) frames[0]).getViewPort();
+ }
+ else if (frames[0] instanceof PCAPanel)
+ {
+ source = ((PCAPanel) frames[0]).av;
+ }
+ else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
+ {
+ source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
+ }
+
+ if (source != null)
+ {
+ for (int i = 0; i < frames.length; i++)
+ {
+ target = null;
+ if (frames[i] == null)
+ {
+ continue;
+ }
+ if (frames[i] instanceof AlignFrame)
+ {
+ target = ((AlignFrame) frames[i]).getCurrentView();
+ }
+ else if (frames[i] instanceof TreePanel)
+ {
+ target = ((TreePanel) frames[i]).getViewPort();
+ }
+ else if (frames[i] instanceof PCAPanel)
+ {
+ target = ((PCAPanel) frames[i]).av;
+ }
+ else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
+ {
+ target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
+ }
+
+ if (source == target)
+ {
+ try
+ {
+ if (close)
+ {
+ frames[i].setClosed(true);
+ }
+ else
+ {
+ frames[i].setIcon(minimize);
+ if (!minimize)
+ {
+ frames[i].toFront();
+ }
+ }
+
+ } catch (java.beans.PropertyVetoException ex)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ @Override
+ protected void preferences_actionPerformed(ActionEvent e)
+ {
+ new Preferences();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @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");
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager.getString("label.save_state"));
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ final Desktop me = this;
+ final java.io.File choice = chooser.getSelectedFile();
+ setProjectFile(choice);
+
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ // 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);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Whilst saving current state to "
+ + choice.getName(), oom);
+ } catch (Exception ex)
+ {
+ 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 Object[] { choice.getName() }), MessageManager
+ .getString("label.couldnt_save_project"),
+ JOptionPane.WARNING_MESSAGE);
+ }
+ setProgressBar(null, choice.hashCode());
+ }
+ }).start();
+ }
+ }
+
+ 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");
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
+
+ int value = chooser.showOpenDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ final File selectedFile = chooser.getSelectedFile();
+ setProjectFile(selectedFile);
+ final String choice = selectedFile.getAbsolutePath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY",
+ selectedFile.getParent());
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ setProgressBar(
+ MessageManager.formatMessage(
+ "label.loading_jalview_project",
+ new Object[] { choice }), choice.hashCode());
+ try
+ {
+ new Jalview2XML().loadJalviewAlign(choice);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Whilst loading project from " + choice, oom);
+ } catch (Exception ex)
+ {
+ Cache.log.error("Problems whilst loading project from "
+ + choice, ex);
+ 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());
+ }
+ }).start();
+ }
+ }
+
+ @Override
+ public void inputSequence_actionPerformed(ActionEvent e)
+ {
+ new SequenceFetcher(this);
+ }
+
+ JPanel progressPanel;
+
+ ArrayList<JPanel> fileLoadingPanels = new ArrayList<JPanel>();
+
+ public void startLoading(final String fileName)
+ {
+ if (fileLoadingCount == 0)
+ {
+ fileLoadingPanels.add(addProgressPanel(MessageManager.formatMessage(
+ "label.loading_file", new Object[] { fileName })));
+ }
+ fileLoadingCount++;
+ }
+
+ private JPanel addProgressPanel(String string)
+ {
+ if (progressPanel == null)
+ {
+ progressPanel = new JPanel(new GridLayout(1, 1));
+ totalProgressCount = 0;
+ instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
+ }
+ JPanel thisprogress = new JPanel(new BorderLayout(10, 5));
+ JProgressBar progressBar = new JProgressBar();
+ progressBar.setIndeterminate(true);
+
+ thisprogress.add(new JLabel(string), BorderLayout.WEST);
+
+ thisprogress.add(progressBar, BorderLayout.CENTER);
+ progressPanel.add(thisprogress);
+ ((GridLayout) progressPanel.getLayout())
+ .setRows(((GridLayout) progressPanel.getLayout()).getRows() + 1);
+ ++totalProgressCount;
+ instance.validate();
+ return thisprogress;
+ }
+
+ int totalProgressCount = 0;
+
+ 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)
+ {
+ this.getContentPane().remove(progressPanel);
+ progressPanel = null;
+ }
+ }
+ }
+ validate();
+ }
+
+ public void stopLoading()
+ {
+ fileLoadingCount--;
+ if (fileLoadingCount < 1)
+ {
+ while (fileLoadingPanels.size() > 0)
+ {
+ removeProgressPanel(fileLoadingPanels.remove(0));
+ }
+ fileLoadingPanels.clear();
+ fileLoadingCount = 0;
+ }
+ validate();
+ }
+
+ public static int getViewCount(String 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)
+ {
+ if (Desktop.desktop == null)
+ {
+ // no frames created and in headless mode
+ // TODO: verify that frames are recoverable when in headless mode
+ return null;
+ }
+ List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>();
+ AlignFrame[] frames = getAlignFrames();
+ if (frames == null)
+ {
+ return null;
+ }
+ for (AlignFrame af : frames)
+ {
+ for (AlignmentPanel ap : af.alignPanels)
+ {
+ if (alignmentId == null
+ || alignmentId.equals(ap.av.getSequenceSetId()))
+ {
+ aps.add(ap);
+ }
+ }
+ }
+ if (aps.size() == 0)
+ {
+ return null;
+ }
+ AlignmentPanel[] vap = aps.toArray(new AlignmentPanel[aps.size()]);
+ return vap;
+ }
+
+ /**
+ * get all the viewports on an alignment.
+ *
+ * @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)
+ {
+ List<AlignmentViewport> viewp = new ArrayList<AlignmentViewport>();
+ 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()))
+ {
+ viewp.add(ap.av);
+ }
+ }
+ }
+ else
+ {
+ viewp.add(afr.getViewport());
+ }
+ }
+ }
+ if (viewp.size() > 0)
+ {
+ 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();
+ if (size < 2)
+ {
+ return;
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ AlignmentPanel ap = af.alignPanels.get(i);
+ AlignFrame newaf = new AlignFrame(ap);
+
+ /*
+ * 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(geometry);
+ }
+
+ ap.av.setGatherViewsHere(false);
+
+ addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ }
+
+ af.alignPanels.clear();
+ af.closeMenuItem_actionPerformed(true);
+
+ }
+
+ /**
+ * 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.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)
+ {
+ AlignFrame af = (AlignFrame) frames[t];
+ boolean gatherThis = false;
+ for (int a = 0; a < af.alignPanels.size(); a++)
+ {
+ AlignmentPanel ap = af.alignPanels.get(a);
+ if (viewId.equals(ap.av.getSequenceSetId()))
+ {
+ gatherThis = true;
+ ap.av.setGatherViewsHere(false);
+ ap.av.setExplodedGeometry(af.getBounds());
+ source.addAlignmentPanel(ap, false);
+ }
+ }
+
+ if (gatherThis)
+ {
+ af.alignPanels.clear();
+ af.closeMenuItem_actionPerformed(true);
+ }
+ }
+ }
+
+ }
+
+ jalview.gui.VamsasApplication v_client = null;
+
+ @Override
+ public void vamsasImport_actionPerformed(ActionEvent e)
+ {
+ if (v_client == null)
+ {
+ // Load and try to start a session.
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager
+ .getString("label.open_saved_vamsas_session"));
+ chooser.setToolTipText(MessageManager
+ .getString("label.select_vamsas_session_opened_as_new_vamsas_session"));
+
+ int value = chooser.showOpenDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ String fle = chooser.getSelectedFile().toString();
+ if (!vamsasImport(chooser.getSelectedFile()))
+ {
+ JOptionPane
+ .showInternalMessageDialog(
+ Desktop.desktop,
+ MessageManager.formatMessage(
+ "label.couldnt_import_as_vamsas_session",
+ new Object[] { fle }),
+ MessageManager
+ .getString("label.vamsas_document_import_failed"),
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+ else
+ {
+ jalview.bin.Cache.log
+ .error("Implementation error - load session from a running session is not supported.");
+ }
+ }
+
+ /**
+ * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
+ *
+ * @param file
+ * @return true if import was a success and a session was started.
+ */
+ public boolean vamsasImport(URL url)
+ {
+ // TODO: create progress bar
+ if (v_client != null)
+ {
+
+ jalview.bin.Cache.log
+ .error("Implementation error - load session from a running session is not supported.");
+ return false;
+ }
+
+ try
+ {
+ // copy the URL content to a temporary local file
+ // TODO: be a bit cleverer here with nio (?!)
+ File file = File.createTempFile("vdocfromurl", ".vdj");
+ FileOutputStream fos = new FileOutputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(url.openStream());
+ byte[] buffer = new byte[2048];
+ int ln;
+ while ((ln = bis.read(buffer)) > -1)
+ {
+ fos.write(buffer, 0, ln);
+ }
+ bis.close();
+ fos.close();
+ v_client = new jalview.gui.VamsasApplication(this, file,
+ url.toExternalForm());
+ } catch (Exception ex)
+ {
+ jalview.bin.Cache.log.error(
+ "Failed to create new vamsas session from contents of URL "
+ + url, ex);
+ return false;
+ }
+ setupVamsasConnectedGui();
+ v_client.initial_update(); // TODO: thread ?
+ return v_client.inSession();
+ }
+
+ /**
+ * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
+ *
+ * @param file
+ * @return true if import was a success and a session was started.
+ */
+ public boolean vamsasImport(File file)
+ {
+ if (v_client != null)
+ {
+
+ jalview.bin.Cache.log
+ .error("Implementation error - load session from a running session is not supported.");
+ return false;
+ }
+
+ 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 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 Object[] { file.getName() }), file.hashCode());
+ return v_client.inSession();
+ }
+
+ public boolean joinVamsasSession(String mysesid)
+ {
+ if (v_client != null)
+ {
+ throw new Error(
+ MessageManager
+ .getString("error.try_join_vamsas_session_another"));
+ }
+ if (mysesid == null)
+ {
+ throw new Error(
+ MessageManager.getString("error.invalid_vamsas_session_id"));
+ }
+ v_client = new VamsasApplication(this, mysesid);
+ setupVamsasConnectedGui();
+ v_client.initial_update();
+ return (v_client.inSession());
+ }
+
+ @Override
+ public void vamsasStart_actionPerformed(ActionEvent e)
+ {
+ if (v_client == null)
+ {
+ // Start a session.
+ // we just start a default session for moment.
+ /*
+ * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ * getProperty("LAST_DIRECTORY"));
+ *
+ * chooser.setFileView(new JalviewFileView());
+ * chooser.setDialogTitle("Load Vamsas file");
+ * chooser.setToolTipText("Import");
+ *
+ * int value = chooser.showOpenDialog(this);
+ *
+ * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
+ * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
+ */
+ v_client = new VamsasApplication(this);
+ setupVamsasConnectedGui();
+ v_client.initial_update(); // TODO: thread ?
+ }
+ else
+ {
+ // store current data in session.
+ v_client.push_update(); // TODO: thread
+ }
+ }
+
+ protected void setupVamsasConnectedGui()
+ {
+ vamsasStart.setText(MessageManager.getString("label.session_update"));
+ vamsasSave.setVisible(true);
+ vamsasStop.setVisible(true);
+ vamsasImport.setVisible(false); // Document import to existing session is
+ // not possible for vamsas-client-1.0.
+ }
+
+ protected void setupVamsasDisconnectedGui()
+ {
+ vamsasSave.setVisible(false);
+ vamsasStop.setVisible(false);
+ vamsasImport.setVisible(true);
+ vamsasStart.setText(MessageManager
+ .getString("label.new_vamsas_session"));
+ }
+
+ @Override
+ public void vamsasStop_actionPerformed(ActionEvent e)
+ {
+ if (v_client != null)
+ {
+ v_client.end_session();
+ v_client = null;
+ setupVamsasDisconnectedGui();
+ }
+ }
+
+ protected void buildVamsasStMenu()
+ {
+ if (v_client == null)
+ {
+ String[] sess = null;
+ try
+ {
+ sess = VamsasApplication.getSessionList();
+ } catch (Exception e)
+ {
+ jalview.bin.Cache.log.warn(
+ "Problem getting current sessions list.", e);
+ sess = null;
+ }
+ if (sess != null)
+ {
+ jalview.bin.Cache.log.debug("Got current sessions list: "
+ + sess.length + " entries.");
+ VamsasStMenu.removeAll();
+ for (int i = 0; i < sess.length; i++)
+ {
+ JMenuItem sessit = new JMenuItem();
+ sessit.setText(sess[i]);
+ sessit.setToolTipText(MessageManager.formatMessage(
+ "label.connect_to_session", new Object[] { sess[i] }));
+ final Desktop dsktp = this;
+ final String mysesid = sess[i];
+ sessit.addActionListener(new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (dsktp.v_client == null)
+ {
+ Thread rthr = new Thread(new Runnable()
+ {
+
+ public void run()
+ {
+ dsktp.v_client = new VamsasApplication(dsktp, mysesid);
+ dsktp.setupVamsasConnectedGui();
+ dsktp.v_client.initial_update();
+ }
+
+ });
+ rthr.start();
+ }
+ };
+ });
+ VamsasStMenu.add(sessit);
+ }
+ // don't show an empty menu.
+ VamsasStMenu.setVisible(sess.length > 0);
+
+ }
+ else
+ {
+ jalview.bin.Cache.log.debug("No current vamsas sessions.");
+ VamsasStMenu.removeAll();
+ VamsasStMenu.setVisible(false);
+ }
+ }
+ else
+ {
+ // Not interested in the content. Just hide ourselves.
+ VamsasStMenu.setVisible(false);
+ }
+ }
+
+ @Override
+ public void vamsasSave_actionPerformed(ActionEvent e)
+ {
+ if (v_client != null)
+ {
+ 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");
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager
+ .getString("label.save_vamsas_document_archive"));
+
+ int value = chooser.showSaveDialog(this);