2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
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;
22 import jalview.ws.params.ParamManager;
25 import java.awt.datatransfer.*;
26 import java.awt.dnd.*;
27 import java.awt.event.*;
28 import java.beans.PropertyChangeEvent;
29 import java.beans.PropertyChangeListener;
30 import java.io.BufferedInputStream;
31 import java.io.BufferedOutputStream;
33 import java.io.FileOutputStream;
34 import java.io.InputStream;
35 import java.lang.reflect.Constructor;
37 import java.net.URLConnection;
38 import java.nio.channels.ReadableByteChannel;
42 import javax.swing.event.MenuEvent;
43 import javax.swing.event.MenuListener;
52 public class Desktop extends jalview.jbgui.GDesktop implements
53 DropTargetListener, ClipboardOwner, IProgressIndicator
56 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 while (ix>=screenSize.width) {
418 jalview.bin.Cache.log.debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
419 ix-=screenSize.width;
421 while (iy>=screenSize.height) {
422 jalview.bin.Cache.log.debug("Window geometry location recall error: shifting vertical to within screenbounds.");
423 iy-=screenSize.height;
425 jalview.bin.Cache.log.debug("Got last known dimensions for "
426 + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
429 // return dimensions for new instance
430 return new Rectangle(ix, iy, iw, ih);
435 private void doVamsasClientCheck()
437 if (jalview.bin.Cache.vamsasJarsPresent())
439 setupVamsasDisconnectedGui();
440 VamsasMenu.setVisible(true);
441 final Desktop us = this;
442 VamsasMenu.addMenuListener(new MenuListener()
444 // this listener remembers when the menu was first selected, and
445 // doesn't rebuild the session list until it has been cleared and
447 boolean refresh = true;
449 public void menuCanceled(MenuEvent e)
454 public void menuDeselected(MenuEvent e)
459 public void menuSelected(MenuEvent e)
463 us.buildVamsasStMenu();
468 vamsasStart.setVisible(true);
472 void showPasteMenu(int x, int y)
474 JPopupMenu popup = new JPopupMenu();
475 JMenuItem item = new JMenuItem("Paste To New Window");
476 item.addActionListener(new ActionListener()
478 public void actionPerformed(ActionEvent evt)
485 popup.show(this, x, y);
492 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
493 Transferable contents = c.getContents(this);
495 if (contents != null)
497 String file = (String) contents
498 .getTransferData(DataFlavor.stringFlavor);
500 String format = new IdentifyFile().Identify(file,
501 FormatAdapter.PASTE);
503 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
506 } catch (Exception ex)
509 .println("Unable to paste alignment from system clipboard:\n"
515 * Adds and opens the given frame to the desktop
526 public static synchronized void addInternalFrame(
527 final JInternalFrame frame, String title, int w, int h)
529 addInternalFrame(frame, title, w, h, true);
546 public static synchronized void addInternalFrame(
547 final JInternalFrame frame, String title, int w, int h,
551 // TODO: allow callers to determine X and Y position of frame (eg. via
553 // TODO: consider fixing method to update entries in the window submenu with
554 // the current window title
556 frame.setTitle(title);
557 if (frame.getWidth() < 1 || frame.getHeight() < 1)
561 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
562 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
563 // IF JALVIEW IS RUNNING HEADLESS
564 // ///////////////////////////////////////////////
565 if (System.getProperty("java.awt.headless") != null
566 && System.getProperty("java.awt.headless").equals("true"))
573 frame.setVisible(true);
574 frame.setClosable(true);
575 frame.setResizable(resizable);
576 frame.setMaximizable(resizable);
577 frame.setIconifiable(resizable);
578 frame.setFrameIcon(null);
580 if (frame.getX() < 1 && frame.getY() < 1)
582 frame.setLocation(xOffset * openFrameCount, yOffset
583 * ((openFrameCount - 1) % 10) + yOffset);
586 final JMenuItem menuItem = new JMenuItem(title);
588 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
590 public void internalFrameActivated(
591 javax.swing.event.InternalFrameEvent evt)
593 JInternalFrame itf = desktop.getSelectedFrame();
601 public void internalFrameClosed(
602 javax.swing.event.InternalFrameEvent evt)
604 PaintRefresher.RemoveComponent(frame);
606 windowMenu.remove(menuItem);
607 JInternalFrame itf = desktop.getSelectedFrame();
616 menuItem.addActionListener(new ActionListener()
618 public void actionPerformed(ActionEvent e)
622 frame.setSelected(true);
623 frame.setIcon(false);
624 } catch (java.beans.PropertyVetoException ex)
631 windowMenu.add(menuItem);
637 frame.setSelected(true);
638 frame.requestFocus();
639 } catch (java.beans.PropertyVetoException ve)
644 public void lostOwnership(Clipboard clipboard, Transferable contents)
648 Desktop.jalviewClipboard = null;
651 internalCopy = false;
654 public void dragEnter(DropTargetDragEvent evt)
658 public void dragExit(DropTargetEvent evt)
662 public void dragOver(DropTargetDragEvent evt)
666 public void dropActionChanged(DropTargetDragEvent evt)
676 public void drop(DropTargetDropEvent evt)
678 Transferable t = evt.getTransferable();
679 java.util.List files = null;
680 java.util.List protocols = null;
684 DataFlavor uriListFlavor = new DataFlavor(
685 "text/uri-list;class=java.lang.String");
686 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
688 // Works on Windows and MacOSX
689 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
690 files = (java.util.List) t
691 .getTransferData(DataFlavor.javaFileListFlavor);
693 else if (t.isDataFlavorSupported(uriListFlavor))
695 // This is used by Unix drag system
696 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
697 String data = (String) t.getTransferData(uriListFlavor);
698 files = new java.util.ArrayList(1);
699 protocols = new java.util.ArrayList(1);
700 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
701 data, "\r\n"); st.hasMoreTokens();)
703 String s = st.nextToken();
704 if (s.startsWith("#"))
706 // the line is a comment (as per the RFC 2483)
709 java.net.URI uri = new java.net.URI(s);
710 if (uri.getScheme().toLowerCase().startsWith("http"))
712 protocols.add(FormatAdapter.URL);
713 files.add(uri.toString());
717 // otherwise preserve old behaviour: catch all for file objects
718 java.io.File file = new java.io.File(uri);
719 protocols.add(FormatAdapter.FILE);
720 files.add(file.toString());
724 } catch (Exception e)
732 for (int i = 0; i < files.size(); i++)
734 String file = files.get(i).toString();
735 String protocol = (protocols == null) ? FormatAdapter.FILE
736 : (String) protocols.get(i);
737 String format = null;
739 if (file.endsWith(".jar"))
746 format = new IdentifyFile().Identify(file, protocol);
749 new FileLoader().LoadFile(file, protocol, format);
752 } catch (Exception ex)
764 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
766 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
767 .getProperty("LAST_DIRECTORY"),
768 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
769 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
770 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
772 chooser.setFileView(new JalviewFileView());
773 chooser.setDialogTitle("Open local file");
774 chooser.setToolTipText("Open");
776 int value = chooser.showOpenDialog(this);
778 if (value == JalviewFileChooser.APPROVE_OPTION)
780 String choice = chooser.getSelectedFile().getPath();
781 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
782 .getSelectedFile().getParent());
784 String format = null;
785 if (chooser.getSelectedFormat().equals("Jalview"))
791 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
794 if (viewport != null)
796 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
801 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
812 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
814 // This construct allows us to have a wider textfield
816 JLabel label = new JLabel("Enter URL of Input File");
817 final JComboBox history = new JComboBox();
819 JPanel panel = new JPanel(new GridLayout(2, 1));
822 history.setPreferredSize(new Dimension(400, 20));
823 history.setEditable(true);
824 history.addItem("http://www.");
826 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
830 if (historyItems != null)
832 st = new StringTokenizer(historyItems, "\t");
834 while (st.hasMoreTokens())
836 history.addItem(st.nextElement());
840 int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
841 "Input Alignment From URL", JOptionPane.OK_CANCEL_OPTION);
843 if (reply != JOptionPane.OK_OPTION)
848 String url = history.getSelectedItem().toString();
850 if (url.toLowerCase().endsWith(".jar"))
852 if (viewport != null)
854 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
859 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
864 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
866 if (format.equals("URL NOT FOUND"))
868 JOptionPane.showInternalMessageDialog(Desktop.desktop,
869 "Couldn't locate " + url, "URL not found",
870 JOptionPane.WARNING_MESSAGE);
875 if (viewport != null)
877 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
881 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
892 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
894 CutAndPasteTransfer cap = new CutAndPasteTransfer();
895 cap.setForInput(viewport);
896 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
904 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
906 .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
907 jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
909 storeLastKnownDimensions("", new Rectangle(getBounds().x,
910 getBounds().y, getWidth(), getHeight()));
912 if (jconsole != null)
914 storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
915 jconsole.stopConsole();
920 private void storeLastKnownDimensions(String string, Rectangle jc)
922 jalview.bin.Cache.log.debug("Storing last known dimensions for "
923 + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
924 + " height:" + jc.height);
926 jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
927 jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
928 jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
929 jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
938 public void aboutMenuItem_actionPerformed(ActionEvent e)
940 StringBuffer message = new StringBuffer("Jalview version "
941 + jalview.bin.Cache.getProperty("VERSION") + "; last updated: "
942 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
944 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
945 jalview.bin.Cache.getProperty("VERSION")))
948 .append("\n\n!! Jalview version "
949 + jalview.bin.Cache.getProperty("LATEST_VERSION")
950 + " is available for download from http://www.jalview.org !!\n");
953 // TODO: update this text for each release or centrally store it for lite
956 .append("\nAuthors: Andrew Waterhouse, Jim Procter, Michele Clamp, James Cuff, Steve Searle,\n David Martin & Geoff Barton."
957 + "\nDevelopment managed by The Barton Group, University of Dundee, Scotland, UK.\n"
958 + "\nFor help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list\n"
959 + "\nIf you use Jalview, please cite:"
960 + "\nWaterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
961 + "\nJalview Version 2 - a multiple sequence alignment editor and analysis workbench"
962 + "\nBioinformatics doi: 10.1093/bioinformatics/btp033");
963 JOptionPane.showInternalMessageDialog(Desktop.desktop,
965 message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
974 public void documentationMenuItem_actionPerformed(ActionEvent e)
978 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
979 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
980 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
982 javax.help.HelpBroker hb = hs.createHelpBroker();
983 hb.setCurrentID("home");
984 hb.setDisplayed(true);
985 } catch (Exception ex)
990 public void closeAll_actionPerformed(ActionEvent e)
992 JInternalFrame[] frames = desktop.getAllFrames();
993 for (int i = 0; i < frames.length; i++)
997 frames[i].setClosed(true);
998 } catch (java.beans.PropertyVetoException ex)
1002 System.out.println("ALL CLOSED");
1003 if (v_client != null)
1005 // TODO clear binding to vamsas document objects on close_all
1010 public void raiseRelated_actionPerformed(ActionEvent e)
1012 reorderAssociatedWindows(false, false);
1015 public void minimizeAssociated_actionPerformed(ActionEvent e)
1017 reorderAssociatedWindows(true, false);
1020 void closeAssociatedWindows()
1022 reorderAssociatedWindows(false, true);
1028 * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
1031 protected void garbageCollect_actionPerformed(ActionEvent e)
1033 // We simply collect the garbage
1034 jalview.bin.Cache.log.debug("Collecting garbage...");
1036 jalview.bin.Cache.log.debug("Finished garbage collection.");
1043 * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
1046 protected void showMemusage_actionPerformed(ActionEvent e)
1048 desktop.showMemoryUsage(showMemusage.isSelected());
1055 * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
1058 protected void showConsole_actionPerformed(ActionEvent e)
1060 showConsole(showConsole.isSelected());
1063 Console jconsole = null;
1066 * control whether the java console is visible or not
1070 void showConsole(boolean selected)
1072 showConsole.setSelected(selected);
1073 // TODO: decide if we should update properties file
1074 Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected)
1076 jconsole.setVisible(selected);
1079 void reorderAssociatedWindows(boolean minimize, boolean close)
1081 JInternalFrame[] frames = desktop.getAllFrames();
1082 if (frames == null || frames.length < 1)
1087 AlignViewport source = null, target = null;
1088 if (frames[0] instanceof AlignFrame)
1090 source = ((AlignFrame) frames[0]).getCurrentView();
1092 else if (frames[0] instanceof TreePanel)
1094 source = ((TreePanel) frames[0]).getViewPort();
1096 else if (frames[0] instanceof PCAPanel)
1098 source = ((PCAPanel) frames[0]).av;
1100 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
1102 source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
1107 for (int i = 0; i < frames.length; i++)
1110 if (frames[i] == null)
1114 if (frames[i] instanceof AlignFrame)
1116 target = ((AlignFrame) frames[i]).getCurrentView();
1118 else if (frames[i] instanceof TreePanel)
1120 target = ((TreePanel) frames[i]).getViewPort();
1122 else if (frames[i] instanceof PCAPanel)
1124 target = ((PCAPanel) frames[i]).av;
1126 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
1128 target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
1131 if (source == target)
1137 frames[i].setClosed(true);
1141 frames[i].setIcon(minimize);
1144 frames[i].toFront();
1148 } catch (java.beans.PropertyVetoException ex)
1162 protected void preferences_actionPerformed(ActionEvent e)
1173 public void saveState_actionPerformed(ActionEvent e)
1175 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1176 .getProperty("LAST_DIRECTORY"), new String[]
1177 { "jar" }, new String[]
1178 { "Jalview Project" }, "Jalview Project");
1180 chooser.setFileView(new JalviewFileView());
1181 chooser.setDialogTitle("Save State");
1183 int value = chooser.showSaveDialog(this);
1185 if (value == JalviewFileChooser.APPROVE_OPTION)
1187 java.io.File choice = chooser.getSelectedFile();
1188 setProgressBar("Saving jalview project "
1189 + choice.getName(), choice.hashCode());
1190 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1191 // TODO catch and handle errors for savestate
1193 new Jalview2XML().SaveState(choice);
1194 } catch (OutOfMemoryError oom)
1196 new OOMWarning("Whilst saving current state to "+choice.getName(), oom);
1198 catch (Exception ex)
1200 Cache.log.error("Problems whilst trying to save to "+choice.getName(),ex);
1201 JOptionPane.showMessageDialog(this, "Error whilst saving current state to "+choice.getName(), "Couldn't save project", JOptionPane.WARNING_MESSAGE);
1203 setProgressBar(null, choice.hashCode());
1214 public void loadState_actionPerformed(ActionEvent e)
1216 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1217 .getProperty("LAST_DIRECTORY"), new String[]
1218 { "jar" }, new String[]
1219 { "Jalview Project" }, "Jalview Project");
1220 chooser.setFileView(new JalviewFileView());
1221 chooser.setDialogTitle("Restore state");
1223 int value = chooser.showOpenDialog(this);
1225 if (value == JalviewFileChooser.APPROVE_OPTION)
1227 final String choice = chooser.getSelectedFile().getAbsolutePath();
1228 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
1229 .getSelectedFile().getParent());
1230 new Thread(new Runnable() {
1232 setProgressBar("loading jalview project "
1233 + choice, choice.hashCode());
1235 new Jalview2XML().LoadJalviewAlign(choice); }
1236 catch (OutOfMemoryError oom)
1238 new OOMWarning("Whilst loading project from "+choice, oom);
1240 catch (Exception ex)
1242 Cache.log.error("Problems whilst loading project from "+choice,ex);
1243 JOptionPane.showMessageDialog(Desktop.desktop, "Error whilst loading project from "+choice, "Couldn't load project", JOptionPane.WARNING_MESSAGE);
1245 setProgressBar(null, choice.hashCode());
1251 public void inputSequence_actionPerformed(ActionEvent e)
1253 new SequenceFetcher(this);
1256 JPanel progressPanel;
1258 public void startLoading(final String fileName)
1260 if (fileLoadingCount == 0)
1262 addProgressPanel("Loading File: " + fileName + " ");
1268 private JProgressBar addProgressPanel(String string)
1270 if (progressPanel == null)
1272 progressPanel = new JPanel(new BorderLayout());
1273 totalProgressCount = 0;
1275 JProgressBar progressBar = new JProgressBar();
1276 progressBar.setIndeterminate(true);
1278 progressPanel.add(new JLabel(string), BorderLayout.WEST);
1280 progressPanel.add(progressBar, BorderLayout.CENTER);
1282 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
1283 totalProgressCount++;
1288 int totalProgressCount = 0;
1290 private void removeProgressPanel(JProgressBar progbar)
1292 if (progressPanel != null)
1294 progressPanel.remove(progbar);
1295 if (--totalProgressCount < 1)
1297 this.getContentPane().remove(progressPanel);
1298 progressPanel = null;
1304 public void stopLoading()
1307 if (fileLoadingCount < 1)
1309 if (progressPanel != null)
1311 this.getContentPane().remove(progressPanel);
1312 progressPanel = null;
1314 fileLoadingCount = 0;
1319 public static int getViewCount(String viewId)
1321 AlignViewport[] aps = getViewports(viewId);
1322 return (aps == null) ? 0 : aps.length;
1328 * @return all AlignmentPanels concerning the viewId sequence set
1330 public static AlignmentPanel[] getAlignmentPanels(String viewId)
1333 if (Desktop.desktop == null)
1335 // no frames created and in headless mode
1336 // TODO: verify that frames are recoverable when in headless mode
1339 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1340 ArrayList aps = new ArrayList();
1341 for (int t = 0; t < frames.length; t++)
1343 if (frames[t] instanceof AlignFrame)
1345 AlignFrame af = (AlignFrame) frames[t];
1346 for (int a = 0; a < af.alignPanels.size(); a++)
1349 .equals(((AlignmentPanel) af.alignPanels.elementAt(a)).av
1350 .getSequenceSetId()))
1352 aps.add(af.alignPanels.elementAt(a));
1357 if (aps.size() == 0)
1361 AlignmentPanel[] vap = new AlignmentPanel[aps.size()];
1362 for (int t = 0; t < vap.length; t++)
1364 vap[t] = (AlignmentPanel) aps.get(t);
1370 * get all the viewports on an alignment.
1372 * @param sequenceSetId
1373 * unique alignment id
1374 * @return all viewports on the alignment bound to sequenceSetId
1376 public static AlignViewport[] getViewports(String sequenceSetId)
1378 Vector viewp = new Vector();
1379 if (desktop != null)
1381 javax.swing.JInternalFrame[] frames = instance.getAllFrames();
1383 for (int t = 0; t < frames.length; t++)
1385 if (frames[t] instanceof AlignFrame)
1387 AlignFrame afr = ((AlignFrame) frames[t]);
1388 if (afr.getViewport().getSequenceSetId().equals(sequenceSetId))
1390 if (afr.alignPanels != null)
1392 for (int a = 0; a < afr.alignPanels.size(); a++)
1394 if (sequenceSetId.equals(((AlignmentPanel) afr.alignPanels
1395 .elementAt(a)).av.getSequenceSetId()))
1397 viewp.addElement(((AlignmentPanel) afr.alignPanels
1404 viewp.addElement(((AlignFrame) frames[t]).getViewport());
1409 if (viewp.size() > 0)
1411 AlignViewport[] vp = new AlignViewport[viewp.size()];
1419 public void explodeViews(AlignFrame af)
1421 int size = af.alignPanels.size();
1427 for (int i = 0; i < size; i++)
1429 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
1430 AlignFrame newaf = new AlignFrame(ap);
1431 if (ap.av.explodedPosition != null
1432 && !ap.av.explodedPosition.equals(af.getBounds()))
1434 newaf.setBounds(ap.av.explodedPosition);
1437 ap.av.gatherViewsHere = false;
1439 addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1440 AlignFrame.DEFAULT_HEIGHT);
1443 af.alignPanels.clear();
1444 af.closeMenuItem_actionPerformed(true);
1448 public void gatherViews(AlignFrame source)
1450 source.viewport.gatherViewsHere = true;
1451 source.viewport.explodedPosition = source.getBounds();
1452 JInternalFrame[] frames = desktop.getAllFrames();
1453 String viewId = source.viewport.sequenceSetID;
1455 for (int t = 0; t < frames.length; t++)
1457 if (frames[t] instanceof AlignFrame && frames[t] != source)
1459 AlignFrame af = (AlignFrame) frames[t];
1460 boolean gatherThis = false;
1461 for (int a = 0; a < af.alignPanels.size(); a++)
1463 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
1464 if (viewId.equals(ap.av.getSequenceSetId()))
1467 ap.av.gatherViewsHere = false;
1468 ap.av.explodedPosition = af.getBounds();
1469 source.addAlignmentPanel(ap, false);
1475 af.alignPanels.clear();
1476 af.closeMenuItem_actionPerformed(true);
1483 jalview.gui.VamsasApplication v_client = null;
1485 public void vamsasImport_actionPerformed(ActionEvent e)
1487 if (v_client == null)
1489 // Load and try to start a session.
1490 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1491 .getProperty("LAST_DIRECTORY"));
1493 chooser.setFileView(new JalviewFileView());
1494 chooser.setDialogTitle("Open a saved VAMSAS session");
1496 .setToolTipText("select a vamsas session to be opened as a new vamsas session.");
1498 int value = chooser.showOpenDialog(this);
1500 if (value == JalviewFileChooser.APPROVE_OPTION)
1502 String fle = chooser.getSelectedFile().toString();
1503 if (!vamsasImport(chooser.getSelectedFile()))
1505 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1506 "Couldn't import '" + fle + "' as a new vamsas session.",
1507 "Vamsas Document Import Failed",
1508 JOptionPane.ERROR_MESSAGE);
1514 jalview.bin.Cache.log
1515 .error("Implementation error - load session from a running session is not supported.");
1520 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1523 * @return true if import was a success and a session was started.
1525 public boolean vamsasImport(URL url)
1527 // TODO: create progress bar
1528 if (v_client != null)
1531 jalview.bin.Cache.log
1532 .error("Implementation error - load session from a running session is not supported.");
1538 // copy the URL content to a temporary local file
1539 // TODO: be a bit cleverer here with nio (?!)
1540 File file = File.createTempFile("vdocfromurl", ".vdj");
1541 FileOutputStream fos = new FileOutputStream(file);
1542 BufferedInputStream bis = new BufferedInputStream(url.openStream());
1543 byte[] buffer = new byte[2048];
1545 while ((ln = bis.read(buffer)) > -1)
1547 fos.write(buffer, 0, ln);
1551 v_client = new jalview.gui.VamsasApplication(this, file, url
1553 } catch (Exception ex)
1555 jalview.bin.Cache.log.error(
1556 "Failed to create new vamsas session from contents of URL "
1560 setupVamsasConnectedGui();
1561 v_client.initial_update(); // TODO: thread ?
1562 return v_client.inSession();
1566 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1569 * @return true if import was a success and a session was started.
1571 public boolean vamsasImport(File file)
1573 if (v_client != null)
1576 jalview.bin.Cache.log
1577 .error("Implementation error - load session from a running session is not supported.");
1581 setProgressBar("Importing VAMSAS session from " + file.getName(), file
1585 v_client = new jalview.gui.VamsasApplication(this, file, null);
1586 } catch (Exception ex)
1588 setProgressBar("Importing VAMSAS session from " + file.getName(),
1590 jalview.bin.Cache.log.error(
1591 "New vamsas session from existing session file failed:", ex);
1594 setupVamsasConnectedGui();
1595 v_client.initial_update(); // TODO: thread ?
1596 setProgressBar("Importing VAMSAS session from " + file.getName(), file
1598 return v_client.inSession();
1601 public boolean joinVamsasSession(String mysesid)
1603 if (v_client != null)
1606 "Trying to join a vamsas session when another is already connected.");
1608 if (mysesid == null)
1610 throw new Error("Invalid vamsas session id.");
1612 v_client = new VamsasApplication(this, mysesid);
1613 setupVamsasConnectedGui();
1614 v_client.initial_update();
1615 return (v_client.inSession());
1618 public void vamsasStart_actionPerformed(ActionEvent e)
1620 if (v_client == null)
1623 // we just start a default session for moment.
1625 * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1626 * getProperty("LAST_DIRECTORY"));
1628 * chooser.setFileView(new JalviewFileView());
1629 * chooser.setDialogTitle("Load Vamsas file");
1630 * chooser.setToolTipText("Import");
1632 * int value = chooser.showOpenDialog(this);
1634 * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
1635 * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
1637 v_client = new VamsasApplication(this);
1638 setupVamsasConnectedGui();
1639 v_client.initial_update(); // TODO: thread ?
1643 // store current data in session.
1644 v_client.push_update(); // TODO: thread
1648 protected void setupVamsasConnectedGui()
1650 vamsasStart.setText("Session Update");
1651 vamsasSave.setVisible(true);
1652 vamsasStop.setVisible(true);
1653 vamsasImport.setVisible(false); // Document import to existing session is
1654 // not possible for vamsas-client-1.0.
1657 protected void setupVamsasDisconnectedGui()
1659 vamsasSave.setVisible(false);
1660 vamsasStop.setVisible(false);
1661 vamsasImport.setVisible(true);
1662 vamsasStart.setText("New Vamsas Session");
1665 public void vamsasStop_actionPerformed(ActionEvent e)
1667 if (v_client != null)
1669 v_client.end_session();
1671 setupVamsasDisconnectedGui();
1675 protected void buildVamsasStMenu()
1677 if (v_client == null)
1679 String[] sess = null;
1682 sess = VamsasApplication.getSessionList();
1683 } catch (Exception e)
1685 jalview.bin.Cache.log.warn(
1686 "Problem getting current sessions list.", e);
1691 jalview.bin.Cache.log.debug("Got current sessions list: "
1692 + sess.length + " entries.");
1693 VamsasStMenu.removeAll();
1694 for (int i = 0; i < sess.length; i++)
1696 JMenuItem sessit = new JMenuItem();
1697 sessit.setText(sess[i]);
1698 sessit.setToolTipText("Connect to session " + sess[i]);
1699 final Desktop dsktp = this;
1700 final String mysesid = sess[i];
1701 sessit.addActionListener(new ActionListener()
1704 public void actionPerformed(ActionEvent e)
1706 if (dsktp.v_client == null)
1708 Thread rthr = new Thread(new Runnable()
1713 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1714 dsktp.setupVamsasConnectedGui();
1715 dsktp.v_client.initial_update();
1723 VamsasStMenu.add(sessit);
1725 // don't show an empty menu.
1726 VamsasStMenu.setVisible(sess.length > 0);
1731 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1732 VamsasStMenu.removeAll();
1733 VamsasStMenu.setVisible(false);
1738 // Not interested in the content. Just hide ourselves.
1739 VamsasStMenu.setVisible(false);
1743 public void vamsasSave_actionPerformed(ActionEvent e)
1745 if (v_client != null)
1747 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1748 .getProperty("LAST_DIRECTORY"), new String[]
1749 { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1751 { "Vamsas Document" }, "Vamsas Document");
1753 chooser.setFileView(new JalviewFileView());
1754 chooser.setDialogTitle("Save Vamsas Document Archive");
1756 int value = chooser.showSaveDialog(this);
1758 if (value == JalviewFileChooser.APPROVE_OPTION)
1760 java.io.File choice = chooser.getSelectedFile();
1761 JProgressBar progpanel = addProgressPanel("Saving VAMSAS Document to "
1762 + choice.getName());
1763 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1764 String warnmsg = null;
1765 String warnttl = null;
1768 v_client.vclient.storeDocument(choice);
1771 warnttl = "Serious Problem saving Vamsas Document";
1772 warnmsg = ex.toString();
1773 jalview.bin.Cache.log.error("Error Whilst saving document to "
1776 } catch (Exception ex)
1778 warnttl = "Problem saving Vamsas Document.";
1779 warnmsg = ex.toString();
1780 jalview.bin.Cache.log.warn("Exception Whilst saving document to "
1784 removeProgressPanel(progpanel);
1785 if (warnmsg != null)
1787 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1789 warnmsg, warnttl, JOptionPane.ERROR_MESSAGE);
1795 JProgressBar vamUpdate = null;
1798 * hide vamsas user gui bits when a vamsas document event is being handled.
1801 * true to hide gui, false to reveal gui
1803 public void setVamsasUpdate(boolean b)
1805 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "
1806 + (b ? "in progress" : "finished"));
1808 if (vamUpdate != null)
1810 this.removeProgressPanel(vamUpdate);
1814 vamUpdate = this.addProgressPanel("Updating vamsas session");
1816 vamsasStart.setVisible(!b);
1817 vamsasStop.setVisible(!b);
1818 vamsasSave.setVisible(!b);
1821 public JInternalFrame[] getAllFrames()
1823 return desktop.getAllFrames();
1827 * Checks the given url to see if it gives a response indicating that the user
1828 * should be informed of a new questionnaire.
1832 public void checkForQuestionnaire(String url)
1834 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1835 // javax.swing.SwingUtilities.invokeLater(jvq);
1836 new Thread(jvq).start();
1840 * Proxy class for JDesktopPane which optionally displays the current memory
1841 * usage and highlights the desktop area with a red bar if free memory runs
1846 public class MyDesktopPane extends JDesktopPane implements Runnable
1849 boolean showMemoryUsage = false;
1853 java.text.NumberFormat df;
1855 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
1858 public MyDesktopPane(boolean showMemoryUsage)
1860 showMemoryUsage(showMemoryUsage);
1863 public void showMemoryUsage(boolean showMemoryUsage)
1865 this.showMemoryUsage = showMemoryUsage;
1866 if (showMemoryUsage)
1868 Thread worker = new Thread(this);
1873 public boolean isShowMemoryUsage()
1875 return showMemoryUsage;
1880 df = java.text.NumberFormat.getNumberInstance();
1881 df.setMaximumFractionDigits(2);
1882 runtime = Runtime.getRuntime();
1884 while (showMemoryUsage)
1888 maxMemory = runtime.maxMemory() / 1048576f;
1889 allocatedMemory = runtime.totalMemory() / 1048576f;
1890 freeMemory = runtime.freeMemory() / 1048576f;
1891 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1893 percentUsage = (totalFreeMemory / maxMemory) * 100;
1895 // if (percentUsage < 20)
1897 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12,
1899 // instance.set.setBorder(border1);
1902 // sleep after showing usage
1904 } catch (Exception ex)
1906 ex.printStackTrace();
1911 public void paintComponent(Graphics g)
1913 if (showMemoryUsage && g != null && df != null)
1915 if (percentUsage < 20)
1916 g.setColor(Color.red);
1917 FontMetrics fm = g.getFontMetrics();
1920 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1921 + "MB; Max Memory: " + df.format(maxMemory) + "MB; "
1922 + df.format(percentUsage) + "%", 10, getHeight()
1930 protected JMenuItem groovyShell;
1932 public void doGroovyCheck()
1934 if (jalview.bin.Cache.groovyJarsPresent())
1936 groovyShell = new JMenuItem();
1937 groovyShell.setText("Groovy Console...");
1938 groovyShell.addActionListener(new ActionListener()
1940 public void actionPerformed(ActionEvent e)
1942 groovyShell_actionPerformed(e);
1945 toolsMenu.add(groovyShell);
1946 groovyShell.setVisible(true);
1951 * Accessor method to quickly get all the AlignmentFrames loaded.
1953 public static AlignFrame[] getAlignframes()
1955 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1961 Vector avp = new Vector();
1965 for (int i = frames.length - 1; i > -1; i--)
1967 if (frames[i] instanceof AlignFrame)
1969 AlignFrame af = (AlignFrame) frames[i];
1973 } catch (Exception ex)
1975 ex.printStackTrace();
1977 if (avp.size() == 0)
1981 AlignFrame afs[] = new AlignFrame[avp.size()];
1982 for (int i = 0, j = avp.size(); i < j; i++)
1984 afs[i] = (AlignFrame) avp.elementAt(i);
1991 * Add Groovy Support to Jalview
1993 public void groovyShell_actionPerformed(ActionEvent e)
1995 // use reflection to avoid creating compilation dependency.
1996 if (!jalview.bin.Cache.groovyJarsPresent())
1999 "Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
2003 Class gcClass = Desktop.class.getClassLoader().loadClass(
2004 "groovy.ui.Console");
2005 Constructor gccons = gcClass.getConstructor(null);
2006 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
2008 { String.class, Object.class });
2009 java.lang.reflect.Method run = gcClass.getMethod("run", null);
2010 Object gc = gccons.newInstance(null);
2011 setvar.invoke(gc, new Object[]
2012 { "Jalview", this });
2013 run.invoke(gc, null);
2014 } catch (Exception ex)
2016 jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
2018 .showInternalMessageDialog(
2021 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.",
2022 "Jalview Groovy Support Failed",
2023 JOptionPane.ERROR_MESSAGE);
2028 * Progress bars managed by the IProgressIndicator method.
2030 private Hashtable progressBars, progressBarHandlers;
2035 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
2037 public void setProgressBar(String message, long id)
2039 if (progressBars == null)
2041 progressBars = new Hashtable();
2042 progressBarHandlers = new Hashtable();
2045 if (progressBars.get(new Long(id)) != null)
2047 JProgressBar progressPanel = (JProgressBar) progressBars
2048 .remove(new Long(id));
2049 if (progressBarHandlers.contains(new Long(id)))
2051 progressBarHandlers.remove(new Long(id));
2053 removeProgressPanel(progressPanel);
2057 progressBars.put(new Long(id), addProgressPanel(message));
2064 * @see jalview.gui.IProgressIndicator#registerHandler(long,
2065 * jalview.gui.IProgressIndicatorHandler)
2067 public void registerHandler(final long id,
2068 final IProgressIndicatorHandler handler)
2070 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
2073 "call setProgressBar before registering the progress bar's handler.");
2075 progressBarHandlers.put(new Long(id), handler);
2076 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
2077 if (handler.canCancel())
2079 JButton cancel = new JButton("Cancel");
2080 final IProgressIndicator us = this;
2081 cancel.addActionListener(new ActionListener()
2084 public void actionPerformed(ActionEvent e)
2086 handler.cancelActivity(id);
2087 us.setProgressBar("Cancelled "
2088 + ((JLabel) progressPanel.getComponent(0)).getText(), id);
2091 progressPanel.add(cancel, BorderLayout.EAST);
2096 * This will return the first AlignFrame viewing AlignViewport av. It will
2097 * break if there are more than one AlignFrames viewing a particular av. This
2100 * @return alignFrame for av
2102 public static AlignFrame getAlignFrameFor(AlignViewport av)
2104 if (desktop != null)
2106 AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId());
2107 for (int panel = 0; aps != null && panel < aps.length; panel++)
2109 if (aps[panel] != null && aps[panel].av == av)
2111 return aps[panel].alignFrame;
2118 public VamsasApplication getVamsasApplication()
2124 * flag set if jalview GUI is being operated programmatically
2126 private boolean inBatchMode=false;
2129 * check if jalview GUI is being operated programmatically
2130 * @return inBatchMode
2132 public boolean isInBatchMode()
2138 * set flag if jalview GUI is being operated programmatically
2139 * @param inBatchMode
2141 public void setInBatchMode(boolean inBatchMode)
2143 this.inBatchMode = inBatchMode;
2147 public void startServiceDiscovery()
2149 startServiceDiscovery(false);
2152 public void startServiceDiscovery(boolean blocking)
2154 boolean alive = true;
2155 Thread t0 = null, t1 = null, t2 = null;
2157 // todo: changesupport handlers need to be transferred
2158 if (discoverer == null)
2160 discoverer = new jalview.ws.jws1.Discoverer();
2161 // register PCS handler for desktop.
2162 discoverer.addPropertyChangeListener(changeSupport);
2164 if (Cache.getDefault("SHOW_JWS1_SERVICES", true))
2166 (t0 = new Thread(discoverer)).start();
2171 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
2173 // EnfinEnvision web service menu entries are rebuild every time the
2174 // menu is shown, so no changeSupport events are needed.
2175 jalview.ws.EnfinEnvision2OneWay.getInstance();
2176 (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
2179 } catch (Exception e)
2183 "Exception when trying to launch Envision2 workflow discovery.",
2185 Cache.log.info(e.getStackTrace());
2187 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
2189 jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
2190 .addPropertyChangeListener(changeSupport);
2191 (t2 = new Thread(jalview.ws.jws2.Jws2Discoverer.getDiscoverer()))
2201 } catch (Exception e)
2204 alive = (t1 != null && t1.isAlive())
2205 || (t2 != null && t2.isAlive())
2206 || (t0 != null && t0.isAlive());
2212 * start a thread to open a URL in the configured browser. Pops up a warning dialog to the user if there is an exception when calling out to the browser to open the URL.
2215 public static void showUrl(final String url)
2217 new Thread(new Runnable() {
2220 jalview.util.BrowserLauncher.openURL(url);
2221 } catch (Exception ex)
2224 .showInternalMessageDialog(
2226 "Unixers: Couldn't find default web browser."
2227 + "\nAdd the full path to your browser in Preferences.",
2228 "Web browser not found", JOptionPane.WARNING_MESSAGE);
2230 ex.printStackTrace();
2236 public static WsParamSetManager wsparamManager = null;
2237 public static ParamManager getUserParameterStore()
2239 if (wsparamManager==null)
2241 wsparamManager = new WsParamSetManager();
2243 return wsparamManager;