+ frame.setSize(w, h);
+ }
+ // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
+ // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
+ // IF JALVIEW IS RUNNING HEADLESS
+ // ///////////////////////////////////////////////
+ if (instance == null
+ || (System.getProperty("java.awt.headless") != null && System
+ .getProperty("java.awt.headless").equals("true")))
+ {
+ return;
+ }
+
+ openFrameCount++;
+
+ frame.setVisible(true);
+ frame.setClosable(true);
+ frame.setResizable(resizable);
+ frame.setMaximizable(resizable);
+ frame.setIconifiable(resizable);
+ frame.setFrameIcon(null);
+
+ if (frame.getX() < 1 && frame.getY() < 1)
+ {
+ frame.setLocation(xOffset * openFrameCount, yOffset
+ * ((openFrameCount - 1) % 10) + yOffset);
+ }
+
+ final JMenuItem menuItem = new JMenuItem(title);
+ frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+ {
+ public void internalFrameActivated(
+ javax.swing.event.InternalFrameEvent evt)
+ {
+ JInternalFrame itf = desktop.getSelectedFrame();
+ if (itf != null)
+ {
+ itf.requestFocus();
+ }
+
+ }
+
+ public void internalFrameClosed(
+ javax.swing.event.InternalFrameEvent evt)
+ {
+ PaintRefresher.RemoveComponent(frame);
+ openFrameCount--;
+ windowMenu.remove(menuItem);
+ JInternalFrame itf = desktop.getSelectedFrame();
+ if (itf != null)
+ {
+ itf.requestFocus();
+ }
+ System.gc();
+ };
+ });
+
+ menuItem.addActionListener(new ActionListener()
+ {
+ 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)
+ {
+ }
+
+ 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!
+ */
+ 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);
+ }
+ else
+ {
+ new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ 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 String[]{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);
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ cap.setForInput(viewport);
+ Desktop.addInternalFrame(cap, MessageManager.getString("label.cut_paste_alignmen_file"), 600, 500);
+ }
+
+ /*
+ * Exit the program
+ */
+ 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();
+ }
+
+ 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!
+ */
+ 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!
+ */
+ public void documentationMenuItem_actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ Help.showHelpWindow();
+ } catch (Exception ex)
+ {
+ }
+ }
+
+ 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
+
+ }
+ }
+
+ public void raiseRelated_actionPerformed(ActionEvent e)
+ {
+ reorderAssociatedWindows(false, false);
+ }
+
+ 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)
+ */
+ 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
+ * )
+ */
+ protected void showMemusage_actionPerformed(ActionEvent e)
+ {
+ desktop.showMemoryUsage(showMemusage.isSelected());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
+ * )
+ */
+ 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;
+ }
+
+ AlignViewport 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!
+ */
+ protected void preferences_actionPerformed(ActionEvent e)
+ {
+ new Preferences();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ 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();
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+
+ setProgressBar(MessageManager.formatMessage("label.saving_jalview_project", new String[]{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 String[]{ choice.getName()}),
+ MessageManager.getString("label.couldnt_save_project"),
+ JOptionPane.WARNING_MESSAGE);
+ }
+ setProgressBar(null, choice.hashCode());
+ }
+ }).start();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ 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 String choice = chooser.getSelectedFile().getAbsolutePath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
+ .getSelectedFile().getParent());
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ setProgressBar(MessageManager.formatMessage("label.loading_jalview_project", new String[]{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 String[]{choice}),
+ MessageManager.getString("label.couldnt_load_project"), JOptionPane.WARNING_MESSAGE);
+ }
+ setProgressBar(null, choice.hashCode());
+ }
+ }).start();
+ }
+ }
+
+ 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 String[]{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)
+ {
+ AlignViewport[] aps = getViewports(alignmentId);
+ return (aps == null) ? 0 : aps.length;
+ }
+
+ /**
+ *
+ * @param alignmentId
+ * @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++)
+ {
+ if (frames[t] instanceof AlignFrame)
+ {
+ AlignFrame af = (AlignFrame) frames[t];
+ for (int a = 0; a < af.alignPanels.size(); a++)
+ {
+ if (alignmentId.equals(((AlignmentPanel) af.alignPanels
+ .elementAt(a)).av.getSequenceSetId()))
+ {
+ aps.add(af.alignPanels.elementAt(a));
+ }
+ }
+ }
+ }
+ if (aps.size() == 0)
+ {
+ return null;
+ }
+ AlignmentPanel[] vap = new AlignmentPanel[aps.size()];
+ for (int t = 0; t < vap.length; t++)
+ {
+ vap[t] = (AlignmentPanel) aps.get(t);
+ }
+ return vap;
+ }
+
+ /**
+ * get all the viewports on an alignment.
+ *
+ * @param sequenceSetId
+ * unique alignment id
+ * @return all viewports on the alignment bound to sequenceSetId
+ */
+ public static AlignViewport[] getViewports(String sequenceSetId)
+ {
+ Vector viewp = new Vector();
+ if (desktop != null)
+ {
+ javax.swing.JInternalFrame[] frames = instance.getAllFrames();
+