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(java.beans.PropertyChangeListener)
88 public void addJalviewPropertyChangeListener(
89 PropertyChangeListener listener)
91 changeSupport.addPropertyChangeListener(listener);
102 * java.beans.PropertyChangeSupport#firePropertyChange(java.lang.String,
103 * java.lang.Object, java.lang.Object) public void firePropertyChange(String
104 * propertyName, Object oldValue, Object newValue) {
105 * changeSupport.firePropertyChange(propertyName, oldValue, newValue); }
109 * @param propertyName
111 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.lang.String,
112 * java.beans.PropertyChangeListener)
114 public void removeJalviewPropertyChangeListener(String propertyName,
115 PropertyChangeListener listener)
117 changeSupport.removePropertyChangeListener(propertyName, listener);
122 private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
126 * @see jalview.gui.Desktop.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
128 public void addJalviewPropertyChangeListener(
129 PropertyChangeListener listener)
131 changeSupport.addJalviewPropertyChangeListener(listener);
135 * @param propertyName
137 * @see jalview.gui.Desktop.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
138 * java.beans.PropertyChangeListener)
140 public void addJalviewPropertyChangeListener(String propertyName,
141 PropertyChangeListener listener)
143 changeSupport.addJalviewPropertyChangeListener(propertyName, listener);
147 * @param propertyName
149 * @see jalview.gui.Desktop.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
150 * java.beans.PropertyChangeListener)
152 public void removeJalviewPropertyChangeListener(String propertyName,
153 PropertyChangeListener listener)
155 changeSupport.removeJalviewPropertyChangeListener(propertyName,
159 /** Singleton Desktop instance */
160 public static Desktop instance;
162 public static MyDesktopPane desktop;
164 static int openFrameCount = 0;
166 static final int xOffset = 30;
168 static final int yOffset = 30;
170 public static jalview.ws.jws1.Discoverer discoverer;
172 public static Object[] jalviewClipboard;
174 public static boolean internalCopy = false;
176 static int fileLoadingCount = 0;
178 class MyDesktopManager implements DesktopManager
181 private DesktopManager delegate;
183 public MyDesktopManager(DesktopManager delegate)
185 this.delegate = delegate;
188 public void activateFrame(JInternalFrame f)
192 delegate.activateFrame(f);
193 } catch (NullPointerException npe)
195 Point p = getMousePosition();
196 instance.showPasteMenu(p.x, p.y);
200 public void beginDraggingFrame(JComponent f)
202 delegate.beginDraggingFrame(f);
205 public void beginResizingFrame(JComponent f, int direction)
207 delegate.beginResizingFrame(f, direction);
210 public void closeFrame(JInternalFrame f)
212 delegate.closeFrame(f);
215 public void deactivateFrame(JInternalFrame f)
217 delegate.deactivateFrame(f);
220 public void deiconifyFrame(JInternalFrame f)
222 delegate.deiconifyFrame(f);
225 public void dragFrame(JComponent f, int newX, int newY)
227 delegate.dragFrame(f, newX, newY);
230 public void endDraggingFrame(JComponent f)
232 delegate.endDraggingFrame(f);
235 public void endResizingFrame(JComponent f)
237 delegate.endResizingFrame(f);
240 public void iconifyFrame(JInternalFrame f)
242 delegate.iconifyFrame(f);
245 public void maximizeFrame(JInternalFrame f)
247 delegate.maximizeFrame(f);
250 public void minimizeFrame(JInternalFrame f)
252 delegate.minimizeFrame(f);
255 public void openFrame(JInternalFrame f)
257 delegate.openFrame(f);
260 public void resizeFrame(JComponent f, int newX, int newY, int newWidth,
263 delegate.resizeFrame(f, newX, newY, newWidth, newHeight);
266 public void setBoundsForFrame(JComponent f, int newX, int newY,
267 int newWidth, int newHeight)
269 delegate.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
272 // All other methods, simply delegate
277 * Creates a new Desktop object.
282 * A note to implementors. It is ESSENTIAL that any activities that might
283 * block are spawned off as threads rather than waited for during this
287 doVamsasClientCheck();
290 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
291 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
292 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",
294 boolean showjconsole = jalview.bin.Cache.getDefault(
295 "SHOW_JAVA_CONSOLE", false);
296 desktop = new MyDesktopPane(selmemusage);
297 showMemusage.setSelected(selmemusage);
298 desktop.setBackground(Color.white);
299 getContentPane().setLayout(new BorderLayout());
300 getContentPane().add(desktop, BorderLayout.CENTER);
301 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
303 // This line prevents Windows Look&Feel resizing all new windows to maximum
304 // if previous window was maximised
305 desktop.setDesktopManager(new MyDesktopManager(
306 new DefaultDesktopManager()));
307 Rectangle dims = getLastKnownDimensions("");
314 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
315 setBounds((int) (screenSize.width - 900) / 2,
316 (int) (screenSize.height - 650) / 2, 900, 650);
318 jconsole = new Console(this, showjconsole);
319 // add essential build information
320 jconsole.setHeader("Jalview Desktop "
321 + jalview.bin.Cache.getProperty("VERSION") + "\n"
323 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
324 + "Java version: " + System.getProperty("java.version") + "\n"
325 + System.getProperty("os.arch") + " "
326 + System.getProperty("os.name") + " "
327 + System.getProperty("os.version"));
329 showConsole(showjconsole);
331 this.addWindowListener(new WindowAdapter()
333 public void windowClosing(WindowEvent evt)
339 this.addMouseListener(new MouseAdapter()
341 public void mousePressed(MouseEvent evt)
343 if (SwingUtilities.isRightMouseButton(evt))
345 showPasteMenu(evt.getX(), evt.getY());
350 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
351 // Spawn a thread that shows the splashscreen
352 SwingUtilities.invokeLater(new Runnable()
361 // Thread off a new instance of the file chooser - this reduces the time it
362 // takes to open it later on.
363 new Thread(new Runnable()
367 Cache.log.debug("Filechooser init thread started.");
368 JalviewFileChooser chooser = new JalviewFileChooser(
369 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
370 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
371 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
372 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
373 Cache.log.debug("Filechooser init thread finished.");
379 * recover the last known dimensions for a jalview window
382 * - empty string is desktop, all other windows have unique prefix
383 * @return null or last known dimensions scaled to current geometry (if last
384 * window geom was known)
386 Rectangle getLastKnownDimensions(String windowName)
388 // TODO: lock aspect ratio for scaling desktop Bug #0058199
389 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
390 String x = jalview.bin.Cache.getProperty(windowName + "SCREEN_X");
391 String y = jalview.bin.Cache.getProperty(windowName + "SCREEN_Y");
392 String width = jalview.bin.Cache.getProperty(windowName
394 String height = jalview.bin.Cache.getProperty(windowName
396 if ((x != null) && (y != null) && (width != null) && (height != null))
398 int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer
399 .parseInt(width), ih = Integer.parseInt(height);
400 if (jalview.bin.Cache.getProperty("SCREENGEOMETRY_WIDTH") != null)
402 // attempt #1 - try to cope with change in screen geometry - this
403 // version doesn't preserve original jv aspect ratio.
404 // take ratio of current screen size vs original screen size.
405 double sw = ((1f * screenSize.width) / (1f * Integer
406 .parseInt(jalview.bin.Cache
407 .getProperty("SCREENGEOMETRY_WIDTH"))));
408 double sh = ((1f * screenSize.height) / (1f * Integer
409 .parseInt(jalview.bin.Cache
410 .getProperty("SCREENGEOMETRY_HEIGHT"))));
411 // rescale the bounds depending upon the current screen geometry.
412 ix = (int) (ix * sw);
413 iw = (int) (iw * sw);
414 iy = (int) (iy * sh);
415 ih = (int) (ih * sh);
416 while (ix >= screenSize.width)
418 jalview.bin.Cache.log
419 .debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
420 ix -= screenSize.width;
422 while (iy >= screenSize.height)
424 jalview.bin.Cache.log
425 .debug("Window geometry location recall error: shifting vertical to within screenbounds.");
426 iy -= screenSize.height;
428 jalview.bin.Cache.log.debug("Got last known dimensions for "
429 + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
432 // return dimensions for new instance
433 return new Rectangle(ix, iy, iw, ih);
438 private void doVamsasClientCheck()
440 if (jalview.bin.Cache.vamsasJarsPresent())
442 setupVamsasDisconnectedGui();
443 VamsasMenu.setVisible(true);
444 final Desktop us = this;
445 VamsasMenu.addMenuListener(new MenuListener()
447 // this listener remembers when the menu was first selected, and
448 // doesn't rebuild the session list until it has been cleared and
450 boolean refresh = true;
452 public void menuCanceled(MenuEvent e)
457 public void menuDeselected(MenuEvent e)
462 public void menuSelected(MenuEvent e)
466 us.buildVamsasStMenu();
471 vamsasStart.setVisible(true);
475 void showPasteMenu(int x, int y)
477 JPopupMenu popup = new JPopupMenu();
478 JMenuItem item = new JMenuItem("Paste To New Window");
479 item.addActionListener(new ActionListener()
481 public void actionPerformed(ActionEvent evt)
488 popup.show(this, x, y);
495 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
496 Transferable contents = c.getContents(this);
498 if (contents != null)
500 String file = (String) contents
501 .getTransferData(DataFlavor.stringFlavor);
503 String format = new IdentifyFile().Identify(file,
504 FormatAdapter.PASTE);
506 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
509 } catch (Exception ex)
512 .println("Unable to paste alignment from system clipboard:\n"
518 * Adds and opens the given frame to the desktop
529 public static synchronized void addInternalFrame(
530 final JInternalFrame frame, String title, int w, int h)
532 addInternalFrame(frame, title, w, h, true);
549 public static synchronized void addInternalFrame(
550 final JInternalFrame frame, String title, int w, int h,
554 // TODO: allow callers to determine X and Y position of frame (eg. via
556 // TODO: consider fixing method to update entries in the window submenu with
557 // the current window title
559 frame.setTitle(title);
560 if (frame.getWidth() < 1 || frame.getHeight() < 1)
564 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
565 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
566 // IF JALVIEW IS RUNNING HEADLESS
567 // ///////////////////////////////////////////////
568 if (System.getProperty("java.awt.headless") != null
569 && System.getProperty("java.awt.headless").equals("true"))
576 frame.setVisible(true);
577 frame.setClosable(true);
578 frame.setResizable(resizable);
579 frame.setMaximizable(resizable);
580 frame.setIconifiable(resizable);
581 frame.setFrameIcon(null);
583 if (frame.getX() < 1 && frame.getY() < 1)
585 frame.setLocation(xOffset * openFrameCount, yOffset
586 * ((openFrameCount - 1) % 10) + yOffset);
589 final JMenuItem menuItem = new JMenuItem(title);
590 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
592 public void internalFrameActivated(
593 javax.swing.event.InternalFrameEvent evt)
595 JInternalFrame itf = desktop.getSelectedFrame();
603 public void internalFrameClosed(
604 javax.swing.event.InternalFrameEvent evt)
606 PaintRefresher.RemoveComponent(frame);
608 windowMenu.remove(menuItem);
609 JInternalFrame itf = desktop.getSelectedFrame();
618 menuItem.addActionListener(new ActionListener()
620 public void actionPerformed(ActionEvent e)
624 frame.setSelected(true);
625 frame.setIcon(false);
626 } catch (java.beans.PropertyVetoException ex)
633 windowMenu.add(menuItem);
639 frame.setSelected(true);
640 frame.requestFocus();
641 } catch (java.beans.PropertyVetoException ve)
646 public void lostOwnership(Clipboard clipboard, Transferable contents)
650 Desktop.jalviewClipboard = null;
653 internalCopy = false;
656 public void dragEnter(DropTargetDragEvent evt)
660 public void dragExit(DropTargetEvent evt)
664 public void dragOver(DropTargetDragEvent evt)
668 public void dropActionChanged(DropTargetDragEvent evt)
678 public void drop(DropTargetDropEvent evt)
680 Transferable t = evt.getTransferable();
681 java.util.List files = null;
682 java.util.List protocols = null;
686 DataFlavor uriListFlavor = new DataFlavor(
687 "text/uri-list;class=java.lang.String");
688 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
690 // Works on Windows and MacOSX
691 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
692 files = (java.util.List) t
693 .getTransferData(DataFlavor.javaFileListFlavor);
695 else if (t.isDataFlavorSupported(uriListFlavor))
697 // This is used by Unix drag system
698 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
699 String data = (String) t.getTransferData(uriListFlavor);
700 files = new java.util.ArrayList(1);
701 protocols = new java.util.ArrayList(1);
702 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
703 data, "\r\n"); st.hasMoreTokens();)
705 String s = st.nextToken();
706 if (s.startsWith("#"))
708 // the line is a comment (as per the RFC 2483)
711 java.net.URI uri = new java.net.URI(s);
712 if (uri.getScheme().toLowerCase().startsWith("http"))
714 protocols.add(FormatAdapter.URL);
715 files.add(uri.toString());
719 // otherwise preserve old behaviour: catch all for file objects
720 java.io.File file = new java.io.File(uri);
721 protocols.add(FormatAdapter.FILE);
722 files.add(file.toString());
726 } catch (Exception e)
734 for (int i = 0; i < files.size(); i++)
736 String file = files.get(i).toString();
737 String protocol = (protocols == null) ? FormatAdapter.FILE
738 : (String) protocols.get(i);
739 String format = null;
741 if (file.endsWith(".jar"))
748 format = new IdentifyFile().Identify(file, protocol);
751 new FileLoader().LoadFile(file, protocol, format);
754 } catch (Exception ex)
766 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
768 JalviewFileChooser chooser = new JalviewFileChooser(
769 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
770 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
771 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
772 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
774 chooser.setFileView(new JalviewFileView());
775 chooser.setDialogTitle("Open local file");
776 chooser.setToolTipText("Open");
778 int value = chooser.showOpenDialog(this);
780 if (value == JalviewFileChooser.APPROVE_OPTION)
782 String choice = chooser.getSelectedFile().getPath();
783 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
784 .getSelectedFile().getParent());
786 String format = null;
787 if (chooser.getSelectedFormat().equals("Jalview"))
793 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
796 if (viewport != null)
798 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
803 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
814 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
816 // This construct allows us to have a wider textfield
818 JLabel label = new JLabel("Enter URL of Input File");
819 final JComboBox history = new JComboBox();
821 JPanel panel = new JPanel(new GridLayout(2, 1));
824 history.setPreferredSize(new Dimension(400, 20));
825 history.setEditable(true);
826 history.addItem("http://www.");
828 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
832 if (historyItems != null)
834 st = new StringTokenizer(historyItems, "\t");
836 while (st.hasMoreTokens())
838 history.addItem(st.nextElement());
842 int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
843 "Input Alignment From URL", JOptionPane.OK_CANCEL_OPTION);
845 if (reply != JOptionPane.OK_OPTION)
850 String url = history.getSelectedItem().toString();
852 if (url.toLowerCase().endsWith(".jar"))
854 if (viewport != null)
856 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
861 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
866 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
868 if (format.equals("URL NOT FOUND"))
870 JOptionPane.showInternalMessageDialog(Desktop.desktop,
871 "Couldn't locate " + url, "URL not found",
872 JOptionPane.WARNING_MESSAGE);
877 if (viewport != null)
879 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
883 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
894 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
896 CutAndPasteTransfer cap = new CutAndPasteTransfer();
897 cap.setForInput(viewport);
898 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
906 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
908 .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
909 jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
911 storeLastKnownDimensions("", new Rectangle(getBounds().x,
912 getBounds().y, getWidth(), getHeight()));
914 if (jconsole != null)
916 storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
917 jconsole.stopConsole();
922 private void storeLastKnownDimensions(String string, Rectangle jc)
924 jalview.bin.Cache.log.debug("Storing last known dimensions for "
925 + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
926 + " height:" + jc.height);
928 jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
929 jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
930 jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
931 jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
940 public void aboutMenuItem_actionPerformed(ActionEvent e)
942 StringBuffer message = new StringBuffer("Jalview version "
943 + jalview.bin.Cache.getProperty("VERSION") + "; last updated: "
944 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
946 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
947 jalview.bin.Cache.getProperty("VERSION")))
949 message.append("\n\n!! Jalview version "
950 + jalview.bin.Cache.getProperty("LATEST_VERSION")
951 + " is available for download from http://www.jalview.org !!\n");
954 // TODO: update this text for each release or centrally store it for lite
956 message.append("\nAuthors: Jim Procter, Andrew Waterhouse, 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(
1176 jalview.bin.Cache.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 " + choice.getName(),
1190 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1191 // TODO catch and handle errors for savestate
1194 new Jalview2XML().SaveState(choice);
1195 } catch (OutOfMemoryError oom)
1198 "Whilst saving current state to " + choice.getName(), oom);
1199 } catch (Exception ex)
1202 .error("Problems whilst trying to save to "
1203 + choice.getName(), ex);
1204 JOptionPane.showMessageDialog(this,
1205 "Error whilst saving current state to " + choice.getName(),
1206 "Couldn't save project", JOptionPane.WARNING_MESSAGE);
1208 setProgressBar(null, choice.hashCode());
1219 public void loadState_actionPerformed(ActionEvent e)
1221 JalviewFileChooser chooser = new JalviewFileChooser(
1222 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1223 { "jar" }, new String[]
1224 { "Jalview Project" }, "Jalview Project");
1225 chooser.setFileView(new JalviewFileView());
1226 chooser.setDialogTitle("Restore state");
1228 int value = chooser.showOpenDialog(this);
1230 if (value == JalviewFileChooser.APPROVE_OPTION)
1232 final String choice = chooser.getSelectedFile().getAbsolutePath();
1233 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
1234 .getSelectedFile().getParent());
1235 new Thread(new Runnable()
1239 setProgressBar("loading jalview project " + choice,
1243 new Jalview2XML().LoadJalviewAlign(choice);
1244 } catch (OutOfMemoryError oom)
1246 new OOMWarning("Whilst loading project from " + choice, oom);
1247 } catch (Exception ex)
1249 Cache.log.error("Problems whilst loading project from "
1251 JOptionPane.showMessageDialog(Desktop.desktop,
1252 "Error whilst loading project from " + choice,
1253 "Couldn't load project", JOptionPane.WARNING_MESSAGE);
1255 setProgressBar(null, choice.hashCode());
1261 public void inputSequence_actionPerformed(ActionEvent e)
1263 new SequenceFetcher(this);
1266 JPanel progressPanel;
1268 public void startLoading(final String fileName)
1270 if (fileLoadingCount == 0)
1272 addProgressPanel("Loading File: " + fileName + " ");
1278 private JProgressBar addProgressPanel(String string)
1280 if (progressPanel == null)
1282 progressPanel = new JPanel(new BorderLayout());
1283 totalProgressCount = 0;
1285 JProgressBar progressBar = new JProgressBar();
1286 progressBar.setIndeterminate(true);
1288 progressPanel.add(new JLabel(string), BorderLayout.WEST);
1290 progressPanel.add(progressBar, BorderLayout.CENTER);
1292 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
1293 totalProgressCount++;
1298 int totalProgressCount = 0;
1300 private void removeProgressPanel(JProgressBar progbar)
1302 if (progressPanel != null)
1304 progressPanel.remove(progbar);
1305 if (--totalProgressCount < 1)
1307 this.getContentPane().remove(progressPanel);
1308 progressPanel = null;
1314 public void stopLoading()
1317 if (fileLoadingCount < 1)
1319 if (progressPanel != null)
1321 this.getContentPane().remove(progressPanel);
1322 progressPanel = null;
1324 fileLoadingCount = 0;
1329 public static int getViewCount(String viewId)
1331 AlignViewport[] aps = getViewports(viewId);
1332 return (aps == null) ? 0 : aps.length;
1338 * @return all AlignmentPanels concerning the viewId sequence set
1340 public static AlignmentPanel[] getAlignmentPanels(String viewId)
1343 if (Desktop.desktop == null)
1345 // no frames created and in headless mode
1346 // TODO: verify that frames are recoverable when in headless mode
1349 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1350 ArrayList aps = new ArrayList();
1351 for (int t = 0; t < frames.length; t++)
1353 if (frames[t] instanceof AlignFrame)
1355 AlignFrame af = (AlignFrame) frames[t];
1356 for (int a = 0; a < af.alignPanels.size(); a++)
1359 .equals(((AlignmentPanel) af.alignPanels.elementAt(a)).av
1360 .getSequenceSetId()))
1362 aps.add(af.alignPanels.elementAt(a));
1367 if (aps.size() == 0)
1371 AlignmentPanel[] vap = new AlignmentPanel[aps.size()];
1372 for (int t = 0; t < vap.length; t++)
1374 vap[t] = (AlignmentPanel) aps.get(t);
1380 * get all the viewports on an alignment.
1382 * @param sequenceSetId
1383 * unique alignment id
1384 * @return all viewports on the alignment bound to sequenceSetId
1386 public static AlignViewport[] getViewports(String sequenceSetId)
1388 Vector viewp = new Vector();
1389 if (desktop != null)
1391 javax.swing.JInternalFrame[] frames = instance.getAllFrames();
1393 for (int t = 0; t < frames.length; t++)
1395 if (frames[t] instanceof AlignFrame)
1397 AlignFrame afr = ((AlignFrame) frames[t]);
1398 if (afr.getViewport().getSequenceSetId().equals(sequenceSetId))
1400 if (afr.alignPanels != null)
1402 for (int a = 0; a < afr.alignPanels.size(); a++)
1404 if (sequenceSetId.equals(((AlignmentPanel) afr.alignPanels
1405 .elementAt(a)).av.getSequenceSetId()))
1407 viewp.addElement(((AlignmentPanel) afr.alignPanels
1414 viewp.addElement(((AlignFrame) frames[t]).getViewport());
1419 if (viewp.size() > 0)
1421 AlignViewport[] vp = new AlignViewport[viewp.size()];
1429 public void explodeViews(AlignFrame af)
1431 int size = af.alignPanels.size();
1437 for (int i = 0; i < size; i++)
1439 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
1440 AlignFrame newaf = new AlignFrame(ap);
1441 if (ap.av.explodedPosition != null
1442 && !ap.av.explodedPosition.equals(af.getBounds()))
1444 newaf.setBounds(ap.av.explodedPosition);
1447 ap.av.gatherViewsHere = false;
1449 addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1450 AlignFrame.DEFAULT_HEIGHT);
1453 af.alignPanels.clear();
1454 af.closeMenuItem_actionPerformed(true);
1458 public void gatherViews(AlignFrame source)
1460 source.viewport.gatherViewsHere = true;
1461 source.viewport.explodedPosition = source.getBounds();
1462 JInternalFrame[] frames = desktop.getAllFrames();
1463 String viewId = source.viewport.sequenceSetID;
1465 for (int t = 0; t < frames.length; t++)
1467 if (frames[t] instanceof AlignFrame && frames[t] != source)
1469 AlignFrame af = (AlignFrame) frames[t];
1470 boolean gatherThis = false;
1471 for (int a = 0; a < af.alignPanels.size(); a++)
1473 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
1474 if (viewId.equals(ap.av.getSequenceSetId()))
1477 ap.av.gatherViewsHere = false;
1478 ap.av.explodedPosition = af.getBounds();
1479 source.addAlignmentPanel(ap, false);
1485 af.alignPanels.clear();
1486 af.closeMenuItem_actionPerformed(true);
1493 jalview.gui.VamsasApplication v_client = null;
1495 public void vamsasImport_actionPerformed(ActionEvent e)
1497 if (v_client == null)
1499 // Load and try to start a session.
1500 JalviewFileChooser chooser = new JalviewFileChooser(
1501 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1503 chooser.setFileView(new JalviewFileView());
1504 chooser.setDialogTitle("Open a saved VAMSAS session");
1505 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
1507 int value = chooser.showOpenDialog(this);
1509 if (value == JalviewFileChooser.APPROVE_OPTION)
1511 String fle = chooser.getSelectedFile().toString();
1512 if (!vamsasImport(chooser.getSelectedFile()))
1514 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1515 "Couldn't import '" + fle + "' as a new vamsas session.",
1516 "Vamsas Document Import Failed",
1517 JOptionPane.ERROR_MESSAGE);
1523 jalview.bin.Cache.log
1524 .error("Implementation error - load session from a running session is not supported.");
1529 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1532 * @return true if import was a success and a session was started.
1534 public boolean vamsasImport(URL url)
1536 // TODO: create progress bar
1537 if (v_client != null)
1540 jalview.bin.Cache.log
1541 .error("Implementation error - load session from a running session is not supported.");
1547 // copy the URL content to a temporary local file
1548 // TODO: be a bit cleverer here with nio (?!)
1549 File file = File.createTempFile("vdocfromurl", ".vdj");
1550 FileOutputStream fos = new FileOutputStream(file);
1551 BufferedInputStream bis = new BufferedInputStream(url.openStream());
1552 byte[] buffer = new byte[2048];
1554 while ((ln = bis.read(buffer)) > -1)
1556 fos.write(buffer, 0, ln);
1560 v_client = new jalview.gui.VamsasApplication(this, file,
1561 url.toExternalForm());
1562 } catch (Exception ex)
1564 jalview.bin.Cache.log.error(
1565 "Failed to create new vamsas session from contents of URL "
1569 setupVamsasConnectedGui();
1570 v_client.initial_update(); // TODO: thread ?
1571 return v_client.inSession();
1575 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1578 * @return true if import was a success and a session was started.
1580 public boolean vamsasImport(File file)
1582 if (v_client != null)
1585 jalview.bin.Cache.log
1586 .error("Implementation error - load session from a running session is not supported.");
1590 setProgressBar("Importing VAMSAS session from " + file.getName(),
1594 v_client = new jalview.gui.VamsasApplication(this, file, null);
1595 } catch (Exception ex)
1597 setProgressBar("Importing VAMSAS session from " + file.getName(),
1599 jalview.bin.Cache.log.error(
1600 "New vamsas session from existing session file failed:", ex);
1603 setupVamsasConnectedGui();
1604 v_client.initial_update(); // TODO: thread ?
1605 setProgressBar("Importing VAMSAS session from " + file.getName(),
1607 return v_client.inSession();
1610 public boolean joinVamsasSession(String mysesid)
1612 if (v_client != null)
1615 "Trying to join a vamsas session when another is already connected.");
1617 if (mysesid == null)
1619 throw new Error("Invalid vamsas session id.");
1621 v_client = new VamsasApplication(this, mysesid);
1622 setupVamsasConnectedGui();
1623 v_client.initial_update();
1624 return (v_client.inSession());
1627 public void vamsasStart_actionPerformed(ActionEvent e)
1629 if (v_client == null)
1632 // we just start a default session for moment.
1634 * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1635 * getProperty("LAST_DIRECTORY"));
1637 * chooser.setFileView(new JalviewFileView());
1638 * chooser.setDialogTitle("Load Vamsas file");
1639 * chooser.setToolTipText("Import");
1641 * int value = chooser.showOpenDialog(this);
1643 * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
1644 * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
1646 v_client = new VamsasApplication(this);
1647 setupVamsasConnectedGui();
1648 v_client.initial_update(); // TODO: thread ?
1652 // store current data in session.
1653 v_client.push_update(); // TODO: thread
1657 protected void setupVamsasConnectedGui()
1659 vamsasStart.setText("Session Update");
1660 vamsasSave.setVisible(true);
1661 vamsasStop.setVisible(true);
1662 vamsasImport.setVisible(false); // Document import to existing session is
1663 // not possible for vamsas-client-1.0.
1666 protected void setupVamsasDisconnectedGui()
1668 vamsasSave.setVisible(false);
1669 vamsasStop.setVisible(false);
1670 vamsasImport.setVisible(true);
1671 vamsasStart.setText("New Vamsas Session");
1674 public void vamsasStop_actionPerformed(ActionEvent e)
1676 if (v_client != null)
1678 v_client.end_session();
1680 setupVamsasDisconnectedGui();
1684 protected void buildVamsasStMenu()
1686 if (v_client == null)
1688 String[] sess = null;
1691 sess = VamsasApplication.getSessionList();
1692 } catch (Exception e)
1694 jalview.bin.Cache.log.warn(
1695 "Problem getting current sessions list.", e);
1700 jalview.bin.Cache.log.debug("Got current sessions list: "
1701 + sess.length + " entries.");
1702 VamsasStMenu.removeAll();
1703 for (int i = 0; i < sess.length; i++)
1705 JMenuItem sessit = new JMenuItem();
1706 sessit.setText(sess[i]);
1707 sessit.setToolTipText("Connect to session " + sess[i]);
1708 final Desktop dsktp = this;
1709 final String mysesid = sess[i];
1710 sessit.addActionListener(new ActionListener()
1713 public void actionPerformed(ActionEvent e)
1715 if (dsktp.v_client == null)
1717 Thread rthr = new Thread(new Runnable()
1722 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1723 dsktp.setupVamsasConnectedGui();
1724 dsktp.v_client.initial_update();
1732 VamsasStMenu.add(sessit);
1734 // don't show an empty menu.
1735 VamsasStMenu.setVisible(sess.length > 0);
1740 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1741 VamsasStMenu.removeAll();
1742 VamsasStMenu.setVisible(false);
1747 // Not interested in the content. Just hide ourselves.
1748 VamsasStMenu.setVisible(false);
1752 public void vamsasSave_actionPerformed(ActionEvent e)
1754 if (v_client != null)
1756 JalviewFileChooser chooser = new JalviewFileChooser(
1757 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1758 { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1760 { "Vamsas Document" }, "Vamsas Document");
1762 chooser.setFileView(new JalviewFileView());
1763 chooser.setDialogTitle("Save Vamsas Document Archive");
1765 int value = chooser.showSaveDialog(this);
1767 if (value == JalviewFileChooser.APPROVE_OPTION)
1769 java.io.File choice = chooser.getSelectedFile();
1770 JProgressBar progpanel = addProgressPanel("Saving VAMSAS Document to "
1771 + choice.getName());
1772 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1773 String warnmsg = null;
1774 String warnttl = null;
1777 v_client.vclient.storeDocument(choice);
1780 warnttl = "Serious Problem saving Vamsas Document";
1781 warnmsg = ex.toString();
1782 jalview.bin.Cache.log.error("Error Whilst saving document to "
1785 } catch (Exception ex)
1787 warnttl = "Problem saving Vamsas Document.";
1788 warnmsg = ex.toString();
1789 jalview.bin.Cache.log.warn("Exception Whilst saving document to "
1793 removeProgressPanel(progpanel);
1794 if (warnmsg != null)
1796 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1798 warnmsg, warnttl, JOptionPane.ERROR_MESSAGE);
1804 JProgressBar vamUpdate = null;
1807 * hide vamsas user gui bits when a vamsas document event is being handled.
1810 * true to hide gui, false to reveal gui
1812 public void setVamsasUpdate(boolean b)
1814 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "
1815 + (b ? "in progress" : "finished"));
1817 if (vamUpdate != null)
1819 this.removeProgressPanel(vamUpdate);
1823 vamUpdate = this.addProgressPanel("Updating vamsas session");
1825 vamsasStart.setVisible(!b);
1826 vamsasStop.setVisible(!b);
1827 vamsasSave.setVisible(!b);
1830 public JInternalFrame[] getAllFrames()
1832 return desktop.getAllFrames();
1836 * Checks the given url to see if it gives a response indicating that the user
1837 * should be informed of a new questionnaire.
1841 public void checkForQuestionnaire(String url)
1843 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1844 // javax.swing.SwingUtilities.invokeLater(jvq);
1845 new Thread(jvq).start();
1849 * Proxy class for JDesktopPane which optionally displays the current memory
1850 * usage and highlights the desktop area with a red bar if free memory runs
1855 public class MyDesktopPane extends JDesktopPane implements Runnable
1858 boolean showMemoryUsage = false;
1862 java.text.NumberFormat df;
1864 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
1867 public MyDesktopPane(boolean showMemoryUsage)
1869 showMemoryUsage(showMemoryUsage);
1872 public void showMemoryUsage(boolean showMemoryUsage)
1874 this.showMemoryUsage = showMemoryUsage;
1875 if (showMemoryUsage)
1877 Thread worker = new Thread(this);
1882 public boolean isShowMemoryUsage()
1884 return showMemoryUsage;
1889 df = java.text.NumberFormat.getNumberInstance();
1890 df.setMaximumFractionDigits(2);
1891 runtime = Runtime.getRuntime();
1893 while (showMemoryUsage)
1897 maxMemory = runtime.maxMemory() / 1048576f;
1898 allocatedMemory = runtime.totalMemory() / 1048576f;
1899 freeMemory = runtime.freeMemory() / 1048576f;
1900 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1902 percentUsage = (totalFreeMemory / maxMemory) * 100;
1904 // if (percentUsage < 20)
1906 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12,
1908 // instance.set.setBorder(border1);
1911 // sleep after showing usage
1913 } catch (Exception ex)
1915 ex.printStackTrace();
1920 public void paintComponent(Graphics g)
1922 if (showMemoryUsage && g != null && df != null)
1924 if (percentUsage < 20)
1925 g.setColor(Color.red);
1926 FontMetrics fm = g.getFontMetrics();
1930 "Total Free Memory: " + df.format(totalFreeMemory)
1931 + "MB; Max Memory: " + df.format(maxMemory)
1932 + "MB; " + df.format(percentUsage) + "%", 10,
1933 getHeight() - fm.getHeight());
1940 protected JMenuItem groovyShell;
1942 public void doGroovyCheck()
1944 if (jalview.bin.Cache.groovyJarsPresent())
1946 groovyShell = new JMenuItem();
1947 groovyShell.setText("Groovy Console...");
1948 groovyShell.addActionListener(new ActionListener()
1950 public void actionPerformed(ActionEvent e)
1952 groovyShell_actionPerformed(e);
1955 toolsMenu.add(groovyShell);
1956 groovyShell.setVisible(true);
1961 * Accessor method to quickly get all the AlignmentFrames loaded.
1963 public static AlignFrame[] getAlignframes()
1965 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1971 Vector avp = new Vector();
1975 for (int i = frames.length - 1; i > -1; i--)
1977 if (frames[i] instanceof AlignFrame)
1979 AlignFrame af = (AlignFrame) frames[i];
1983 } catch (Exception ex)
1985 ex.printStackTrace();
1987 if (avp.size() == 0)
1991 AlignFrame afs[] = new AlignFrame[avp.size()];
1992 for (int i = 0, j = avp.size(); i < j; i++)
1994 afs[i] = (AlignFrame) avp.elementAt(i);
2001 * Add Groovy Support to Jalview
2003 public void groovyShell_actionPerformed(ActionEvent e)
2005 // use reflection to avoid creating compilation dependency.
2006 if (!jalview.bin.Cache.groovyJarsPresent())
2009 "Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
2013 Class gcClass = Desktop.class.getClassLoader().loadClass(
2014 "groovy.ui.Console");
2015 Constructor gccons = gcClass.getConstructor(null);
2016 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
2018 { String.class, Object.class });
2019 java.lang.reflect.Method run = gcClass.getMethod("run", null);
2020 Object gc = gccons.newInstance(null);
2021 setvar.invoke(gc, new Object[]
2022 { "Jalview", this });
2023 run.invoke(gc, null);
2024 } catch (Exception ex)
2026 jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
2028 .showInternalMessageDialog(
2031 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.",
2032 "Jalview Groovy Support Failed",
2033 JOptionPane.ERROR_MESSAGE);
2038 * Progress bars managed by the IProgressIndicator method.
2040 private Hashtable progressBars, progressBarHandlers;
2045 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
2047 public void setProgressBar(String message, long id)
2049 if (progressBars == null)
2051 progressBars = new Hashtable();
2052 progressBarHandlers = new Hashtable();
2055 if (progressBars.get(new Long(id)) != null)
2057 JProgressBar progressPanel = (JProgressBar) progressBars
2058 .remove(new Long(id));
2059 if (progressBarHandlers.contains(new Long(id)))
2061 progressBarHandlers.remove(new Long(id));
2063 removeProgressPanel(progressPanel);
2067 progressBars.put(new Long(id), addProgressPanel(message));
2074 * @see jalview.gui.IProgressIndicator#registerHandler(long,
2075 * jalview.gui.IProgressIndicatorHandler)
2077 public void registerHandler(final long id,
2078 final IProgressIndicatorHandler handler)
2080 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
2083 "call setProgressBar before registering the progress bar's handler.");
2085 progressBarHandlers.put(new Long(id), handler);
2086 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
2087 if (handler.canCancel())
2089 JButton cancel = new JButton("Cancel");
2090 final IProgressIndicator us = this;
2091 cancel.addActionListener(new ActionListener()
2094 public void actionPerformed(ActionEvent e)
2096 handler.cancelActivity(id);
2099 + ((JLabel) progressPanel.getComponent(0))
2103 progressPanel.add(cancel, BorderLayout.EAST);
2108 * This will return the first AlignFrame viewing AlignViewport av. It will
2109 * break if there are more than one AlignFrames viewing a particular av. This
2112 * @return alignFrame for av
2114 public static AlignFrame getAlignFrameFor(AlignViewport av)
2116 if (desktop != null)
2118 AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId());
2119 for (int panel = 0; aps != null && panel < aps.length; panel++)
2121 if (aps[panel] != null && aps[panel].av == av)
2123 return aps[panel].alignFrame;
2130 public VamsasApplication getVamsasApplication()
2137 * flag set if jalview GUI is being operated programmatically
2139 private boolean inBatchMode = false;
2142 * check if jalview GUI is being operated programmatically
2144 * @return inBatchMode
2146 public boolean isInBatchMode()
2152 * set flag if jalview GUI is being operated programmatically
2154 * @param inBatchMode
2156 public void setInBatchMode(boolean inBatchMode)
2158 this.inBatchMode = inBatchMode;
2161 public void startServiceDiscovery()
2163 startServiceDiscovery(false);
2166 public void startServiceDiscovery(boolean blocking)
2168 boolean alive = true;
2169 Thread t0 = null, t1 = null, t2 = null;
2171 // todo: changesupport handlers need to be transferred
2172 if (discoverer == null)
2174 discoverer = new jalview.ws.jws1.Discoverer();
2175 // register PCS handler for desktop.
2176 discoverer.addPropertyChangeListener(changeSupport);
2178 if (Cache.getDefault("SHOW_JWS1_SERVICES", true))
2180 (t0 = new Thread(discoverer)).start();
2185 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
2187 // EnfinEnvision web service menu entries are rebuild every time the
2188 // menu is shown, so no changeSupport events are needed.
2189 jalview.ws.EnfinEnvision2OneWay.getInstance();
2190 (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
2193 } catch (Exception e)
2196 .info("Exception when trying to launch Envision2 workflow discovery.",
2198 Cache.log.info(e.getStackTrace());
2200 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
2202 jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
2203 .addPropertyChangeListener(changeSupport);
2204 (t2 = new Thread(jalview.ws.jws2.Jws2Discoverer.getDiscoverer()))
2214 } catch (Exception e)
2217 alive = (t1 != null && t1.isAlive())
2218 || (t2 != null && t2.isAlive())
2219 || (t0 != null && t0.isAlive());
2225 * start a thread to open a URL in the configured browser. Pops up a warning
2226 * dialog to the user if there is an exception when calling out to the browser
2231 public static void showUrl(final String url)
2233 new Thread(new Runnable()
2239 jalview.util.BrowserLauncher.openURL(url);
2240 } catch (Exception ex)
2243 .showInternalMessageDialog(
2245 "Unixers: Couldn't find default web browser."
2246 + "\nAdd the full path to your browser in Preferences.",
2247 "Web browser not found",
2248 JOptionPane.WARNING_MESSAGE);
2250 ex.printStackTrace();
2256 public static WsParamSetManager wsparamManager = null;
2258 public static ParamManager getUserParameterStore()
2260 if (wsparamManager == null)
2262 wsparamManager = new WsParamSetManager();
2264 return wsparamManager;