2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.bin.Cache;
24 import java.awt.datatransfer.*;
25 import java.awt.dnd.*;
26 import java.awt.event.*;
27 import java.beans.PropertyChangeEvent;
28 import java.beans.PropertyChangeListener;
29 import java.io.BufferedInputStream;
30 import java.io.BufferedOutputStream;
32 import java.io.FileOutputStream;
33 import java.io.InputStream;
34 import java.lang.reflect.Constructor;
36 import java.net.URLConnection;
37 import java.nio.channels.ReadableByteChannel;
41 import javax.swing.event.MenuEvent;
42 import javax.swing.event.MenuListener;
51 public class Desktop extends jalview.jbgui.GDesktop implements
52 DropTargetListener, ClipboardOwner, IProgressIndicator
55 private class JalviewChangeSupport implements PropertyChangeListener
58 public void propertyChange(PropertyChangeEvent evt)
60 // Handle change events - most are simply routed to other sources
61 changeSupport.firePropertyChange(evt);
65 * change listeners are notified of changes to resources so they can update
66 * their state. E.g. - the 'services' property notifies when the available
67 * set of web service endpoints have changed.
69 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
75 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.lang.String,
76 * java.beans.PropertyChangeListener)
78 public void addJalviewPropertyChangeListener(String propertyName,
79 PropertyChangeListener listener)
81 changeSupport.addPropertyChangeListener(propertyName, listener);
86 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(
87 * java.beans.PropertyChangeListener)
89 public void addJalviewPropertyChangeListener(
90 PropertyChangeListener listener)
92 changeSupport.addPropertyChangeListener(listener);
103 * java.beans.PropertyChangeSupport#firePropertyChange(java.lang.String,
104 * java.lang.Object, java.lang.Object) public void firePropertyChange(String
105 * propertyName, Object oldValue, Object newValue) {
106 * changeSupport.firePropertyChange(propertyName, oldValue, newValue); }
110 * @param propertyName
112 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.lang.String,
113 * java.beans.PropertyChangeListener)
115 public void removeJalviewPropertyChangeListener(String propertyName,
116 PropertyChangeListener listener)
118 changeSupport.removePropertyChangeListener(propertyName, listener);
123 private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
127 * @see jalview.gui.Desktop.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
129 public void addJalviewPropertyChangeListener(
130 PropertyChangeListener listener)
132 changeSupport.addJalviewPropertyChangeListener(listener);
136 * @param propertyName
138 * @see jalview.gui.Desktop.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
139 * java.beans.PropertyChangeListener)
141 public void addJalviewPropertyChangeListener(String propertyName,
142 PropertyChangeListener listener)
144 changeSupport.addJalviewPropertyChangeListener(propertyName, listener);
148 * @param propertyName
150 * @see jalview.gui.Desktop.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
151 * java.beans.PropertyChangeListener)
153 public void removeJalviewPropertyChangeListener(String propertyName,
154 PropertyChangeListener listener)
156 changeSupport.removeJalviewPropertyChangeListener(propertyName,
160 /** Singleton Desktop instance */
161 public static Desktop instance;
163 public static MyDesktopPane desktop;
165 static int openFrameCount = 0;
167 static final int xOffset = 30;
169 static final int yOffset = 30;
171 public static jalview.ws.jws1.Discoverer discoverer;
173 public static Object[] jalviewClipboard;
175 public static boolean internalCopy = false;
177 static int fileLoadingCount = 0;
179 class MyDesktopManager implements DesktopManager
182 private DesktopManager delegate;
184 public MyDesktopManager(DesktopManager delegate)
186 this.delegate = delegate;
189 public void activateFrame(JInternalFrame f)
193 delegate.activateFrame(f);
194 } catch (NullPointerException npe)
196 Point p = getMousePosition();
197 instance.showPasteMenu(p.x, p.y);
201 public void beginDraggingFrame(JComponent f)
203 delegate.beginDraggingFrame(f);
206 public void beginResizingFrame(JComponent f, int direction)
208 delegate.beginResizingFrame(f, direction);
211 public void closeFrame(JInternalFrame f)
213 delegate.closeFrame(f);
216 public void deactivateFrame(JInternalFrame f)
218 delegate.deactivateFrame(f);
221 public void deiconifyFrame(JInternalFrame f)
223 delegate.deiconifyFrame(f);
226 public void dragFrame(JComponent f, int newX, int newY)
228 delegate.dragFrame(f, newX, newY);
231 public void endDraggingFrame(JComponent f)
233 delegate.endDraggingFrame(f);
236 public void endResizingFrame(JComponent f)
238 delegate.endResizingFrame(f);
241 public void iconifyFrame(JInternalFrame f)
243 delegate.iconifyFrame(f);
246 public void maximizeFrame(JInternalFrame f)
248 delegate.maximizeFrame(f);
251 public void minimizeFrame(JInternalFrame f)
253 delegate.minimizeFrame(f);
256 public void openFrame(JInternalFrame f)
258 delegate.openFrame(f);
261 public void resizeFrame(JComponent f, int newX, int newY, int newWidth,
264 delegate.resizeFrame(f, newX, newY, newWidth, newHeight);
267 public void setBoundsForFrame(JComponent f, int newX, int newY,
268 int newWidth, int newHeight)
270 delegate.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
273 // All other methods, simply delegate
278 * Creates a new Desktop object.
283 * A note to implementors. It is ESSENTIAL that any activities that might
284 * block are spawned off as threads rather than waited for during this
288 doVamsasClientCheck();
291 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
292 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
293 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",
295 boolean showjconsole = jalview.bin.Cache.getDefault(
296 "SHOW_JAVA_CONSOLE", false);
297 desktop = new MyDesktopPane(selmemusage);
298 showMemusage.setSelected(selmemusage);
299 desktop.setBackground(Color.white);
300 getContentPane().setLayout(new BorderLayout());
301 getContentPane().add(desktop, BorderLayout.CENTER);
302 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
304 // This line prevents Windows Look&Feel resizing all new windows to maximum
305 // if previous window was maximised
306 desktop.setDesktopManager(new MyDesktopManager(
307 new DefaultDesktopManager()));
308 Rectangle dims = getLastKnownDimensions("");
315 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
316 setBounds((int) (screenSize.width - 900) / 2,
317 (int) (screenSize.height - 650) / 2, 900, 650);
319 jconsole = new Console(this, showjconsole);
320 // add essential build information
321 jconsole.setHeader("Jalview Desktop "
322 + jalview.bin.Cache.getProperty("VERSION") + "\n"
324 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
325 + "Java version: " + System.getProperty("java.version") + "\n"
326 + System.getProperty("os.arch") + " "
327 + System.getProperty("os.name") + " "
328 + System.getProperty("os.version"));
330 showConsole(showjconsole);
332 this.addWindowListener(new WindowAdapter()
334 public void windowClosing(WindowEvent evt)
340 this.addMouseListener(new MouseAdapter()
342 public void mousePressed(MouseEvent evt)
344 if (SwingUtilities.isRightMouseButton(evt))
346 showPasteMenu(evt.getX(), evt.getY());
351 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
352 // Spawn a thread that shows the splashscreen
353 SwingUtilities.invokeLater(new Runnable()
362 // Thread off a new instance of the file chooser - this reduces the time it
363 // takes to open it later on.
364 new Thread(new Runnable()
368 Cache.log.debug("Filechooser init thread started.");
369 JalviewFileChooser chooser = new JalviewFileChooser(
370 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
371 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
372 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
373 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
374 Cache.log.debug("Filechooser init thread finished.");
380 * recover the last known dimensions for a jalview window
383 * - empty string is desktop, all other windows have unique prefix
384 * @return null or last known dimensions scaled to current geometry (if last
385 * window geom was known)
387 Rectangle getLastKnownDimensions(String windowName)
389 // TODO: lock aspect ratio for scaling desktop Bug #0058199
390 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
391 String x = jalview.bin.Cache.getProperty(windowName + "SCREEN_X");
392 String y = jalview.bin.Cache.getProperty(windowName + "SCREEN_Y");
393 String width = jalview.bin.Cache.getProperty(windowName
395 String height = jalview.bin.Cache.getProperty(windowName
397 if ((x != null) && (y != null) && (width != null) && (height != null))
399 int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer
400 .parseInt(width), ih = Integer.parseInt(height);
401 if (jalview.bin.Cache.getProperty("SCREENGEOMETRY_WIDTH") != null)
403 // attempt #1 - try to cope with change in screen geometry - this
404 // version doesn't preserve original jv aspect ratio.
405 // take ratio of current screen size vs original screen size.
406 double sw = ((1f * screenSize.width) / (1f * Integer
407 .parseInt(jalview.bin.Cache
408 .getProperty("SCREENGEOMETRY_WIDTH"))));
409 double sh = ((1f * screenSize.height) / (1f * Integer
410 .parseInt(jalview.bin.Cache
411 .getProperty("SCREENGEOMETRY_HEIGHT"))));
412 // rescale the bounds depending upon the current screen geometry.
413 ix = (int) (ix * sw);
414 iw = (int) (iw * sw);
415 iy = (int) (iy * sh);
416 ih = (int) (ih * sh);
417 jalview.bin.Cache.log.debug("Got last known dimensions for "
418 + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
421 // return dimensions for new instance
422 return new Rectangle(ix, iy, iw, ih);
427 private void doVamsasClientCheck()
429 if (jalview.bin.Cache.vamsasJarsPresent())
431 setupVamsasDisconnectedGui();
432 VamsasMenu.setVisible(true);
433 final Desktop us = this;
434 VamsasMenu.addMenuListener(new MenuListener()
436 // this listener remembers when the menu was first selected, and
437 // doesn't rebuild the session list until it has been cleared and
439 boolean refresh = true;
441 public void menuCanceled(MenuEvent e)
446 public void menuDeselected(MenuEvent e)
451 public void menuSelected(MenuEvent e)
455 us.buildVamsasStMenu();
460 vamsasStart.setVisible(true);
464 void showPasteMenu(int x, int y)
466 JPopupMenu popup = new JPopupMenu();
467 JMenuItem item = new JMenuItem("Paste To New Window");
468 item.addActionListener(new ActionListener()
470 public void actionPerformed(ActionEvent evt)
477 popup.show(this, x, y);
484 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
485 Transferable contents = c.getContents(this);
487 if (contents != null)
489 String file = (String) contents
490 .getTransferData(DataFlavor.stringFlavor);
492 String format = new IdentifyFile().Identify(file,
493 FormatAdapter.PASTE);
495 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
498 } catch (Exception ex)
501 .println("Unable to paste alignment from system clipboard:\n"
507 * Adds and opens the given frame to the desktop
518 public static synchronized void addInternalFrame(
519 final JInternalFrame frame, String title, int w, int h)
521 addInternalFrame(frame, title, w, h, true);
538 public static synchronized void addInternalFrame(
539 final JInternalFrame frame, String title, int w, int h,
543 // TODO: allow callers to determine X and Y position of frame (eg. via
545 // TODO: consider fixing method to update entries in the window submenu with
546 // the current window title
548 frame.setTitle(title);
549 if (frame.getWidth() < 1 || frame.getHeight() < 1)
553 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
554 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
555 // IF JALVIEW IS RUNNING HEADLESS
556 // ///////////////////////////////////////////////
557 if (System.getProperty("java.awt.headless") != null
558 && System.getProperty("java.awt.headless").equals("true"))
565 frame.setVisible(true);
566 frame.setClosable(true);
567 frame.setResizable(resizable);
568 frame.setMaximizable(resizable);
569 frame.setIconifiable(resizable);
570 frame.setFrameIcon(null);
572 if (frame.getX() < 1 && frame.getY() < 1)
574 frame.setLocation(xOffset * openFrameCount, yOffset
575 * ((openFrameCount - 1) % 10) + yOffset);
578 final JMenuItem menuItem = new JMenuItem(title);
580 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
582 public void internalFrameActivated(
583 javax.swing.event.InternalFrameEvent evt)
585 JInternalFrame itf = desktop.getSelectedFrame();
593 public void internalFrameClosed(
594 javax.swing.event.InternalFrameEvent evt)
596 PaintRefresher.RemoveComponent(frame);
598 windowMenu.remove(menuItem);
599 JInternalFrame itf = desktop.getSelectedFrame();
608 menuItem.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent e)
614 frame.setSelected(true);
615 frame.setIcon(false);
616 } catch (java.beans.PropertyVetoException ex)
623 windowMenu.add(menuItem);
629 frame.setSelected(true);
630 frame.requestFocus();
631 } catch (java.beans.PropertyVetoException ve)
636 public void lostOwnership(Clipboard clipboard, Transferable contents)
640 Desktop.jalviewClipboard = null;
643 internalCopy = false;
646 public void dragEnter(DropTargetDragEvent evt)
650 public void dragExit(DropTargetEvent evt)
654 public void dragOver(DropTargetDragEvent evt)
658 public void dropActionChanged(DropTargetDragEvent evt)
668 public void drop(DropTargetDropEvent evt)
670 Transferable t = evt.getTransferable();
671 java.util.List files = null;
672 java.util.List protocols = null;
676 DataFlavor uriListFlavor = new DataFlavor(
677 "text/uri-list;class=java.lang.String");
678 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
680 // Works on Windows and MacOSX
681 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
682 files = (java.util.List) t
683 .getTransferData(DataFlavor.javaFileListFlavor);
685 else if (t.isDataFlavorSupported(uriListFlavor))
687 // This is used by Unix drag system
688 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
689 String data = (String) t.getTransferData(uriListFlavor);
690 files = new java.util.ArrayList(1);
691 protocols = new java.util.ArrayList(1);
692 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
693 data, "\r\n"); st.hasMoreTokens();)
695 String s = st.nextToken();
696 if (s.startsWith("#"))
698 // the line is a comment (as per the RFC 2483)
701 java.net.URI uri = new java.net.URI(s);
702 if (uri.getScheme().toLowerCase().startsWith("http"))
704 protocols.add(FormatAdapter.URL);
705 files.add(uri.toString());
709 // otherwise preserve old behaviour: catch all for file objects
710 java.io.File file = new java.io.File(uri);
711 protocols.add(FormatAdapter.FILE);
712 files.add(file.toString());
716 } catch (Exception e)
724 for (int i = 0; i < files.size(); i++)
726 String file = files.get(i).toString();
727 String protocol = (protocols == null) ? FormatAdapter.FILE
728 : (String) protocols.get(i);
729 String format = null;
731 if (file.endsWith(".jar"))
738 format = new IdentifyFile().Identify(file, protocol);
741 new FileLoader().LoadFile(file, protocol, format);
744 } catch (Exception ex)
756 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
758 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
759 .getProperty("LAST_DIRECTORY"),
760 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
761 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
762 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
764 chooser.setFileView(new JalviewFileView());
765 chooser.setDialogTitle("Open local file");
766 chooser.setToolTipText("Open");
768 int value = chooser.showOpenDialog(this);
770 if (value == JalviewFileChooser.APPROVE_OPTION)
772 String choice = chooser.getSelectedFile().getPath();
773 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
774 .getSelectedFile().getParent());
776 String format = null;
777 if (chooser.getSelectedFormat().equals("Jalview"))
783 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
786 if (viewport != null)
788 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
793 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
804 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
806 // This construct allows us to have a wider textfield
808 JLabel label = new JLabel("Enter URL of Input File");
809 final JComboBox history = new JComboBox();
811 JPanel panel = new JPanel(new GridLayout(2, 1));
814 history.setPreferredSize(new Dimension(400, 20));
815 history.setEditable(true);
816 history.addItem("http://www.");
818 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
822 if (historyItems != null)
824 st = new StringTokenizer(historyItems, "\t");
826 while (st.hasMoreTokens())
828 history.addItem(st.nextElement());
832 int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
833 "Input Alignment From URL", JOptionPane.OK_CANCEL_OPTION);
835 if (reply != JOptionPane.OK_OPTION)
840 String url = history.getSelectedItem().toString();
842 if (url.toLowerCase().endsWith(".jar"))
844 if (viewport != null)
846 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
851 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
856 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
858 if (format.equals("URL NOT FOUND"))
860 JOptionPane.showInternalMessageDialog(Desktop.desktop,
861 "Couldn't locate " + url, "URL not found",
862 JOptionPane.WARNING_MESSAGE);
867 if (viewport != null)
869 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
873 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
884 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
886 CutAndPasteTransfer cap = new CutAndPasteTransfer();
887 cap.setForInput(viewport);
888 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
896 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
898 .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
899 jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
901 storeLastKnownDimensions("", new Rectangle(getBounds().x,
902 getBounds().y, getWidth(), getHeight()));
904 if (jconsole != null)
906 storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
907 jconsole.stopConsole();
912 private void storeLastKnownDimensions(String string, Rectangle jc)
914 jalview.bin.Cache.log.debug("Storing last known dimensions for "
915 + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
916 + " height:" + jc.height);
918 jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
919 jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
920 jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
921 jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
930 public void aboutMenuItem_actionPerformed(ActionEvent e)
932 StringBuffer message = new StringBuffer("Jalview version "
933 + jalview.bin.Cache.getProperty("VERSION") + "; last updated: "
934 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
936 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
937 jalview.bin.Cache.getProperty("VERSION")))
940 .append("\n\n!! Jalview version "
941 + jalview.bin.Cache.getProperty("LATEST_VERSION")
942 + " is available for download from http://www.jalview.org !!\n");
945 // TODO: update this text for each release or centrally store it for lite
948 .append("\nAuthors: Andrew Waterhouse, Jim Procter, Michele Clamp, James Cuff, Steve Searle,\n David Martin & Geoff Barton."
949 + "\nDevelopment managed by The Barton Group, University of Dundee, Scotland, UK.\n"
950 + "\nFor help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list\n"
951 + "\nIf you use Jalview, please cite:"
952 + "\nWaterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
953 + "\nJalview Version 2 - a multiple sequence alignment editor and analysis workbench"
954 + "\nBioinformatics doi: 10.1093/bioinformatics/btp033");
955 JOptionPane.showInternalMessageDialog(Desktop.desktop,
957 message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
966 public void documentationMenuItem_actionPerformed(ActionEvent e)
970 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
971 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
972 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
974 javax.help.HelpBroker hb = hs.createHelpBroker();
975 hb.setCurrentID("home");
976 hb.setDisplayed(true);
977 } catch (Exception ex)
982 public void closeAll_actionPerformed(ActionEvent e)
984 JInternalFrame[] frames = desktop.getAllFrames();
985 for (int i = 0; i < frames.length; i++)
989 frames[i].setClosed(true);
990 } catch (java.beans.PropertyVetoException ex)
994 System.out.println("ALL CLOSED");
995 if (v_client != null)
997 // TODO clear binding to vamsas document objects on close_all
1002 public void raiseRelated_actionPerformed(ActionEvent e)
1004 reorderAssociatedWindows(false, false);
1007 public void minimizeAssociated_actionPerformed(ActionEvent e)
1009 reorderAssociatedWindows(true, false);
1012 void closeAssociatedWindows()
1014 reorderAssociatedWindows(false, true);
1020 * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
1023 protected void garbageCollect_actionPerformed(ActionEvent e)
1025 // We simply collect the garbage
1026 jalview.bin.Cache.log.debug("Collecting garbage...");
1028 jalview.bin.Cache.log.debug("Finished garbage collection.");
1035 * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
1038 protected void showMemusage_actionPerformed(ActionEvent e)
1040 desktop.showMemoryUsage(showMemusage.isSelected());
1047 * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
1050 protected void showConsole_actionPerformed(ActionEvent e)
1052 showConsole(showConsole.isSelected());
1055 Console jconsole = null;
1058 * control whether the java console is visible or not
1062 void showConsole(boolean selected)
1064 showConsole.setSelected(selected);
1065 // TODO: decide if we should update properties file
1066 Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected)
1068 jconsole.setVisible(selected);
1071 void reorderAssociatedWindows(boolean minimize, boolean close)
1073 JInternalFrame[] frames = desktop.getAllFrames();
1074 if (frames == null || frames.length < 1)
1079 AlignViewport source = null, target = null;
1080 if (frames[0] instanceof AlignFrame)
1082 source = ((AlignFrame) frames[0]).getCurrentView();
1084 else if (frames[0] instanceof TreePanel)
1086 source = ((TreePanel) frames[0]).getViewPort();
1088 else if (frames[0] instanceof PCAPanel)
1090 source = ((PCAPanel) frames[0]).av;
1092 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
1094 source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
1099 for (int i = 0; i < frames.length; i++)
1102 if (frames[i] == null)
1106 if (frames[i] instanceof AlignFrame)
1108 target = ((AlignFrame) frames[i]).getCurrentView();
1110 else if (frames[i] instanceof TreePanel)
1112 target = ((TreePanel) frames[i]).getViewPort();
1114 else if (frames[i] instanceof PCAPanel)
1116 target = ((PCAPanel) frames[i]).av;
1118 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
1120 target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
1123 if (source == target)
1129 frames[i].setClosed(true);
1133 frames[i].setIcon(minimize);
1136 frames[i].toFront();
1140 } catch (java.beans.PropertyVetoException ex)
1154 protected void preferences_actionPerformed(ActionEvent e)
1165 public void saveState_actionPerformed(ActionEvent e)
1167 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1168 .getProperty("LAST_DIRECTORY"), new String[]
1169 { "jar" }, new String[]
1170 { "Jalview Project" }, "Jalview Project");
1172 chooser.setFileView(new JalviewFileView());
1173 chooser.setDialogTitle("Save State");
1175 int value = chooser.showSaveDialog(this);
1177 if (value == JalviewFileChooser.APPROVE_OPTION)
1179 java.io.File choice = chooser.getSelectedFile();
1180 JProgressBar progpanel = addProgressPanel("Saving jalview project "
1181 + choice.getName());
1182 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1183 // TODO catch and handle errors for savestate
1184 new Jalview2XML().SaveState(choice);
1185 removeProgressPanel(progpanel);
1196 public void loadState_actionPerformed(ActionEvent e)
1198 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1199 .getProperty("LAST_DIRECTORY"), new String[]
1200 { "jar" }, new String[]
1201 { "Jalview Project" }, "Jalview Project");
1202 chooser.setFileView(new JalviewFileView());
1203 chooser.setDialogTitle("Restore state");
1205 int value = chooser.showOpenDialog(this);
1207 if (value == JalviewFileChooser.APPROVE_OPTION)
1209 String choice = chooser.getSelectedFile().getAbsolutePath();
1210 setProgressBar("loading jalview project "
1211 + chooser.getSelectedFile().getName(), choice.hashCode());
1212 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
1213 .getSelectedFile().getParent());
1214 new Jalview2XML().LoadJalviewAlign(choice);
1215 setProgressBar(null, choice.hashCode());
1219 public void inputSequence_actionPerformed(ActionEvent e)
1221 new SequenceFetcher(this);
1224 JPanel progressPanel;
1226 public void startLoading(final String fileName)
1228 if (fileLoadingCount == 0)
1230 addProgressPanel("Loading File: " + fileName + " ");
1236 private JProgressBar addProgressPanel(String string)
1238 if (progressPanel == null)
1240 progressPanel = new JPanel(new BorderLayout());
1241 totalProgressCount = 0;
1243 JProgressBar progressBar = new JProgressBar();
1244 progressBar.setIndeterminate(true);
1246 progressPanel.add(new JLabel(string), BorderLayout.WEST);
1248 progressPanel.add(progressBar, BorderLayout.CENTER);
1250 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
1251 totalProgressCount++;
1256 int totalProgressCount = 0;
1258 private void removeProgressPanel(JProgressBar progbar)
1260 if (progressPanel != null)
1262 progressPanel.remove(progbar);
1263 if (--totalProgressCount < 1)
1265 this.getContentPane().remove(progressPanel);
1266 progressPanel = null;
1272 public void stopLoading()
1275 if (fileLoadingCount < 1)
1277 if (progressPanel != null)
1279 this.getContentPane().remove(progressPanel);
1280 progressPanel = null;
1282 fileLoadingCount = 0;
1287 public static int getViewCount(String viewId)
1289 AlignViewport[] aps = getViewports(viewId);
1290 return (aps == null) ? 0 : aps.length;
1296 * @return all AlignmentPanels concerning the viewId sequence set
1298 public static AlignmentPanel[] getAlignmentPanels(String viewId)
1301 if (Desktop.desktop == null)
1303 // no frames created and in headless mode
1304 // TODO: verify that frames are recoverable when in headless mode
1307 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1308 ArrayList aps = new ArrayList();
1309 for (int t = 0; t < frames.length; t++)
1311 if (frames[t] instanceof AlignFrame)
1313 AlignFrame af = (AlignFrame) frames[t];
1314 for (int a = 0; a < af.alignPanels.size(); a++)
1317 .equals(((AlignmentPanel) af.alignPanels.elementAt(a)).av
1318 .getSequenceSetId()))
1320 aps.add(af.alignPanels.elementAt(a));
1325 if (aps.size() == 0)
1329 AlignmentPanel[] vap = new AlignmentPanel[aps.size()];
1330 for (int t = 0; t < vap.length; t++)
1332 vap[t] = (AlignmentPanel) aps.get(t);
1338 * get all the viewports on an alignment.
1340 * @param sequenceSetId
1341 * unique alignment id
1342 * @return all viewports on the alignment bound to sequenceSetId
1344 public static AlignViewport[] getViewports(String sequenceSetId)
1346 Vector viewp = new Vector();
1347 if (desktop != null)
1349 javax.swing.JInternalFrame[] frames = instance.getAllFrames();
1351 for (int t = 0; t < frames.length; t++)
1353 if (frames[t] instanceof AlignFrame)
1355 AlignFrame afr = ((AlignFrame) frames[t]);
1356 if (afr.getViewport().getSequenceSetId().equals(sequenceSetId))
1358 if (afr.alignPanels != null)
1360 for (int a = 0; a < afr.alignPanels.size(); a++)
1362 if (sequenceSetId.equals(((AlignmentPanel) afr.alignPanels
1363 .elementAt(a)).av.getSequenceSetId()))
1365 viewp.addElement(((AlignmentPanel) afr.alignPanels
1372 viewp.addElement(((AlignFrame) frames[t]).getViewport());
1377 if (viewp.size() > 0)
1379 AlignViewport[] vp = new AlignViewport[viewp.size()];
1387 public void explodeViews(AlignFrame af)
1389 int size = af.alignPanels.size();
1395 for (int i = 0; i < size; i++)
1397 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
1398 AlignFrame newaf = new AlignFrame(ap);
1399 if (ap.av.explodedPosition != null
1400 && !ap.av.explodedPosition.equals(af.getBounds()))
1402 newaf.setBounds(ap.av.explodedPosition);
1405 ap.av.gatherViewsHere = false;
1407 addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1408 AlignFrame.DEFAULT_HEIGHT);
1411 af.alignPanels.clear();
1412 af.closeMenuItem_actionPerformed(true);
1416 public void gatherViews(AlignFrame source)
1418 source.viewport.gatherViewsHere = true;
1419 source.viewport.explodedPosition = source.getBounds();
1420 JInternalFrame[] frames = desktop.getAllFrames();
1421 String viewId = source.viewport.sequenceSetID;
1423 for (int t = 0; t < frames.length; t++)
1425 if (frames[t] instanceof AlignFrame && frames[t] != source)
1427 AlignFrame af = (AlignFrame) frames[t];
1428 boolean gatherThis = false;
1429 for (int a = 0; a < af.alignPanels.size(); a++)
1431 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
1432 if (viewId.equals(ap.av.getSequenceSetId()))
1435 ap.av.gatherViewsHere = false;
1436 ap.av.explodedPosition = af.getBounds();
1437 source.addAlignmentPanel(ap, false);
1443 af.alignPanels.clear();
1444 af.closeMenuItem_actionPerformed(true);
1451 jalview.gui.VamsasApplication v_client = null;
1453 public void vamsasImport_actionPerformed(ActionEvent e)
1455 if (v_client == null)
1457 // Load and try to start a session.
1458 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1459 .getProperty("LAST_DIRECTORY"));
1461 chooser.setFileView(new JalviewFileView());
1462 chooser.setDialogTitle("Open a saved VAMSAS session");
1464 .setToolTipText("select a vamsas session to be opened as a new vamsas session.");
1466 int value = chooser.showOpenDialog(this);
1468 if (value == JalviewFileChooser.APPROVE_OPTION)
1470 String fle = chooser.getSelectedFile().toString();
1471 if (!vamsasImport(chooser.getSelectedFile()))
1473 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1474 "Couldn't import '" + fle + "' as a new vamsas session.",
1475 "Vamsas Document Import Failed",
1476 JOptionPane.ERROR_MESSAGE);
1482 jalview.bin.Cache.log
1483 .error("Implementation error - load session from a running session is not supported.");
1488 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1491 * @return true if import was a success and a session was started.
1493 public boolean vamsasImport(URL url)
1495 // TODO: create progress bar
1496 if (v_client != null)
1499 jalview.bin.Cache.log
1500 .error("Implementation error - load session from a running session is not supported.");
1506 // copy the URL content to a temporary local file
1507 // TODO: be a bit cleverer here with nio (?!)
1508 File file = File.createTempFile("vdocfromurl", ".vdj");
1509 FileOutputStream fos = new FileOutputStream(file);
1510 BufferedInputStream bis = new BufferedInputStream(url.openStream());
1511 byte[] buffer = new byte[2048];
1513 while ((ln = bis.read(buffer)) > -1)
1515 fos.write(buffer, 0, ln);
1519 v_client = new jalview.gui.VamsasApplication(this, file, url
1521 } catch (Exception ex)
1523 jalview.bin.Cache.log.error(
1524 "Failed to create new vamsas session from contents of URL "
1528 setupVamsasConnectedGui();
1529 v_client.initial_update(); // TODO: thread ?
1530 return v_client.inSession();
1534 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1537 * @return true if import was a success and a session was started.
1539 public boolean vamsasImport(File file)
1541 if (v_client != null)
1544 jalview.bin.Cache.log
1545 .error("Implementation error - load session from a running session is not supported.");
1549 setProgressBar("Importing VAMSAS session from " + file.getName(), file
1553 v_client = new jalview.gui.VamsasApplication(this, file, null);
1554 } catch (Exception ex)
1556 setProgressBar("Importing VAMSAS session from " + file.getName(),
1558 jalview.bin.Cache.log.error(
1559 "New vamsas session from existing session file failed:", ex);
1562 setupVamsasConnectedGui();
1563 v_client.initial_update(); // TODO: thread ?
1564 setProgressBar("Importing VAMSAS session from " + file.getName(), file
1566 return v_client.inSession();
1569 public boolean joinVamsasSession(String mysesid)
1571 if (v_client != null)
1574 "Trying to join a vamsas session when another is already connected.");
1576 if (mysesid == null)
1578 throw new Error("Invalid vamsas session id.");
1580 v_client = new VamsasApplication(this, mysesid);
1581 setupVamsasConnectedGui();
1582 v_client.initial_update();
1583 return (v_client.inSession());
1586 public void vamsasStart_actionPerformed(ActionEvent e)
1588 if (v_client == null)
1591 // we just start a default session for moment.
1593 * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1594 * getProperty("LAST_DIRECTORY"));
1596 * chooser.setFileView(new JalviewFileView());
1597 * chooser.setDialogTitle("Load Vamsas file");
1598 * chooser.setToolTipText("Import");
1600 * int value = chooser.showOpenDialog(this);
1602 * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
1603 * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
1605 v_client = new VamsasApplication(this);
1606 setupVamsasConnectedGui();
1607 v_client.initial_update(); // TODO: thread ?
1611 // store current data in session.
1612 v_client.push_update(); // TODO: thread
1616 protected void setupVamsasConnectedGui()
1618 vamsasStart.setText("Session Update");
1619 vamsasSave.setVisible(true);
1620 vamsasStop.setVisible(true);
1621 vamsasImport.setVisible(false); // Document import to existing session is
1622 // not possible for vamsas-client-1.0.
1625 protected void setupVamsasDisconnectedGui()
1627 vamsasSave.setVisible(false);
1628 vamsasStop.setVisible(false);
1629 vamsasImport.setVisible(true);
1630 vamsasStart.setText("New Vamsas Session");
1633 public void vamsasStop_actionPerformed(ActionEvent e)
1635 if (v_client != null)
1637 v_client.end_session();
1639 setupVamsasDisconnectedGui();
1643 protected void buildVamsasStMenu()
1645 if (v_client == null)
1647 String[] sess = null;
1650 sess = VamsasApplication.getSessionList();
1651 } catch (Exception e)
1653 jalview.bin.Cache.log.warn(
1654 "Problem getting current sessions list.", e);
1659 jalview.bin.Cache.log.debug("Got current sessions list: "
1660 + sess.length + " entries.");
1661 VamsasStMenu.removeAll();
1662 for (int i = 0; i < sess.length; i++)
1664 JMenuItem sessit = new JMenuItem();
1665 sessit.setText(sess[i]);
1666 sessit.setToolTipText("Connect to session " + sess[i]);
1667 final Desktop dsktp = this;
1668 final String mysesid = sess[i];
1669 sessit.addActionListener(new ActionListener()
1672 public void actionPerformed(ActionEvent e)
1674 if (dsktp.v_client == null)
1676 Thread rthr = new Thread(new Runnable()
1681 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1682 dsktp.setupVamsasConnectedGui();
1683 dsktp.v_client.initial_update();
1691 VamsasStMenu.add(sessit);
1693 // don't show an empty menu.
1694 VamsasStMenu.setVisible(sess.length > 0);
1699 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1700 VamsasStMenu.removeAll();
1701 VamsasStMenu.setVisible(false);
1706 // Not interested in the content. Just hide ourselves.
1707 VamsasStMenu.setVisible(false);
1711 public void vamsasSave_actionPerformed(ActionEvent e)
1713 if (v_client != null)
1715 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1716 .getProperty("LAST_DIRECTORY"), new String[]
1717 { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1719 { "Vamsas Document" }, "Vamsas Document");
1721 chooser.setFileView(new JalviewFileView());
1722 chooser.setDialogTitle("Save Vamsas Document Archive");
1724 int value = chooser.showSaveDialog(this);
1726 if (value == JalviewFileChooser.APPROVE_OPTION)
1728 java.io.File choice = chooser.getSelectedFile();
1729 JProgressBar progpanel = addProgressPanel("Saving VAMSAS Document to "
1730 + choice.getName());
1731 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1732 String warnmsg = null;
1733 String warnttl = null;
1736 v_client.vclient.storeDocument(choice);
1739 warnttl = "Serious Problem saving Vamsas Document";
1740 warnmsg = ex.toString();
1741 jalview.bin.Cache.log.error("Error Whilst saving document to "
1744 } catch (Exception ex)
1746 warnttl = "Problem saving Vamsas Document.";
1747 warnmsg = ex.toString();
1748 jalview.bin.Cache.log.warn("Exception Whilst saving document to "
1752 removeProgressPanel(progpanel);
1753 if (warnmsg != null)
1755 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1757 warnmsg, warnttl, JOptionPane.ERROR_MESSAGE);
1763 JProgressBar vamUpdate = null;
1766 * hide vamsas user gui bits when a vamsas document event is being handled.
1769 * true to hide gui, false to reveal gui
1771 public void setVamsasUpdate(boolean b)
1773 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "
1774 + (b ? "in progress" : "finished"));
1776 if (vamUpdate != null)
1778 this.removeProgressPanel(vamUpdate);
1782 vamUpdate = this.addProgressPanel("Updating vamsas session");
1784 vamsasStart.setVisible(!b);
1785 vamsasStop.setVisible(!b);
1786 vamsasSave.setVisible(!b);
1789 public JInternalFrame[] getAllFrames()
1791 return desktop.getAllFrames();
1795 * Checks the given url to see if it gives a response indicating that the user
1796 * should be informed of a new questionnaire.
1800 public void checkForQuestionnaire(String url)
1802 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1803 // javax.swing.SwingUtilities.invokeLater(jvq);
1804 new Thread(jvq).start();
1808 * Proxy class for JDesktopPane which optionally displays the current memory
1809 * usage and highlights the desktop area with a red bar if free memory runs
1814 public class MyDesktopPane extends JDesktopPane implements Runnable
1817 boolean showMemoryUsage = false;
1821 java.text.NumberFormat df;
1823 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
1826 public MyDesktopPane(boolean showMemoryUsage)
1828 showMemoryUsage(showMemoryUsage);
1831 public void showMemoryUsage(boolean showMemoryUsage)
1833 this.showMemoryUsage = showMemoryUsage;
1834 if (showMemoryUsage)
1836 Thread worker = new Thread(this);
1841 public boolean isShowMemoryUsage()
1843 return showMemoryUsage;
1848 df = java.text.NumberFormat.getNumberInstance();
1849 df.setMaximumFractionDigits(2);
1850 runtime = Runtime.getRuntime();
1852 while (showMemoryUsage)
1856 maxMemory = runtime.maxMemory() / 1048576f;
1857 allocatedMemory = runtime.totalMemory() / 1048576f;
1858 freeMemory = runtime.freeMemory() / 1048576f;
1859 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1861 percentUsage = (totalFreeMemory / maxMemory) * 100;
1863 // if (percentUsage < 20)
1865 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12,
1867 // instance.set.setBorder(border1);
1870 // sleep after showing usage
1872 } catch (Exception ex)
1874 ex.printStackTrace();
1879 public void paintComponent(Graphics g)
1881 if (showMemoryUsage && g != null && df != null)
1883 if (percentUsage < 20)
1884 g.setColor(Color.red);
1885 FontMetrics fm = g.getFontMetrics();
1888 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1889 + "MB; Max Memory: " + df.format(maxMemory) + "MB; "
1890 + df.format(percentUsage) + "%", 10, getHeight()
1898 protected JMenuItem groovyShell;
1900 public void doGroovyCheck()
1902 if (jalview.bin.Cache.groovyJarsPresent())
1904 groovyShell = new JMenuItem();
1905 groovyShell.setText("Groovy Console...");
1906 groovyShell.addActionListener(new ActionListener()
1908 public void actionPerformed(ActionEvent e)
1910 groovyShell_actionPerformed(e);
1913 toolsMenu.add(groovyShell);
1914 groovyShell.setVisible(true);
1919 * Accessor method to quickly get all the AlignmentFrames loaded.
1921 public static AlignFrame[] getAlignframes()
1923 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1929 Vector avp = new Vector();
1933 for (int i = frames.length - 1; i > -1; i--)
1935 if (frames[i] instanceof AlignFrame)
1937 AlignFrame af = (AlignFrame) frames[i];
1941 } catch (Exception ex)
1943 ex.printStackTrace();
1945 if (avp.size() == 0)
1949 AlignFrame afs[] = new AlignFrame[avp.size()];
1950 for (int i = 0, j = avp.size(); i < j; i++)
1952 afs[i] = (AlignFrame) avp.elementAt(i);
1959 * Add Groovy Support to Jalview
1961 public void groovyShell_actionPerformed(ActionEvent e)
1963 // use reflection to avoid creating compilation dependency.
1964 if (!jalview.bin.Cache.groovyJarsPresent())
1967 "Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1971 Class gcClass = Desktop.class.getClassLoader().loadClass(
1972 "groovy.ui.Console");
1973 Constructor gccons = gcClass.getConstructor(null);
1974 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
1976 { String.class, Object.class });
1977 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1978 Object gc = gccons.newInstance(null);
1979 setvar.invoke(gc, new Object[]
1980 { "Jalview", this });
1981 run.invoke(gc, null);
1982 } catch (Exception ex)
1984 jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
1986 .showInternalMessageDialog(
1989 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.",
1990 "Jalview Groovy Support Failed",
1991 JOptionPane.ERROR_MESSAGE);
1996 * Progress bars managed by the IProgressIndicator method.
1998 private Hashtable progressBars, progressBarHandlers;
2003 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
2005 public void setProgressBar(String message, long id)
2007 if (progressBars == null)
2009 progressBars = new Hashtable();
2010 progressBarHandlers = new Hashtable();
2013 if (progressBars.get(new Long(id)) != null)
2015 JProgressBar progressPanel = (JProgressBar) progressBars
2016 .remove(new Long(id));
2017 if (progressBarHandlers.contains(new Long(id)))
2019 progressBarHandlers.remove(new Long(id));
2021 removeProgressPanel(progressPanel);
2025 progressBars.put(new Long(id), addProgressPanel(message));
2032 * @see jalview.gui.IProgressIndicator#registerHandler(long,
2033 * jalview.gui.IProgressIndicatorHandler)
2035 public void registerHandler(final long id,
2036 final IProgressIndicatorHandler handler)
2038 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
2041 "call setProgressBar before registering the progress bar's handler.");
2043 progressBarHandlers.put(new Long(id), handler);
2044 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
2045 if (handler.canCancel())
2047 JButton cancel = new JButton("Cancel");
2048 final IProgressIndicator us = this;
2049 cancel.addActionListener(new ActionListener()
2052 public void actionPerformed(ActionEvent e)
2054 handler.cancelActivity(id);
2055 us.setProgressBar("Cancelled "
2056 + ((JLabel) progressPanel.getComponent(0)).getText(), id);
2059 progressPanel.add(cancel, BorderLayout.EAST);
2064 * This will return the first AlignFrame viewing AlignViewport av. It will
2065 * break if there are more than one AlignFrames viewing a particular av. This
2068 * @return alignFrame for av
2070 public static AlignFrame getAlignFrameFor(AlignViewport av)
2072 if (desktop != null)
2074 AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId());
2075 for (int panel = 0; aps != null && panel < aps.length; panel++)
2077 if (aps[panel] != null && aps[panel].av == av)
2079 return aps[panel].alignFrame;
2086 public VamsasApplication getVamsasApplication()
2092 public void startServiceDiscovery()
2094 startServiceDiscovery(false);
2097 public void startServiceDiscovery(boolean blocking)
2099 boolean alive = true;
2100 Thread t0 = null, t1 = null, t2 = null;
2102 // todo: changesupport handlers need to be transferred
2103 if (discoverer == null)
2105 discoverer = new jalview.ws.jws1.Discoverer();
2106 // register PCS handler for desktop.
2107 discoverer.addPropertyChangeListener(changeSupport);
2109 if (Cache.getDefault("SHOW_JWS1_SERVICES", true))
2111 (t0 = new Thread(discoverer)).start();
2116 if (Cache.getDefault("SHOW_ENVISION2_SERVICES", true))
2118 // EnfinEnvision web service menu entries are rebuild every time the
2119 // menu is shown, so no changeSupport events are needed.
2120 jalview.ws.EnfinEnvision2OneWay.getInstance();
2121 (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
2124 } catch (Exception e)
2128 "Exception when trying to launch Envision2 workflow discovery.",
2130 Cache.log.info(e.getStackTrace());
2132 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
2134 jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
2135 .addPropertyChangeListener(changeSupport);
2136 (t2 = new Thread(jalview.ws.jws2.Jws2Discoverer.getDiscoverer()))
2146 } catch (Exception e)
2149 alive = (t1 != null && t1.isAlive())
2150 || (t2 != null && t2.isAlive())
2151 || (t0 != null && t0.isAlive());