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 JalviewChangeSupport changeSupport = new JalviewChangeSupport();
60 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
62 public void addJalviewPropertyChangeListener(
63 PropertyChangeListener listener)
65 changeSupport.addJalviewPropertyChangeListener(listener);
71 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
72 * java.beans.PropertyChangeListener)
74 public void addJalviewPropertyChangeListener(String propertyName,
75 PropertyChangeListener listener)
77 changeSupport.addJalviewPropertyChangeListener(propertyName, listener);
83 * @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
84 * java.beans.PropertyChangeListener)
86 public void removeJalviewPropertyChangeListener(String propertyName,
87 PropertyChangeListener listener)
89 changeSupport.removeJalviewPropertyChangeListener(propertyName,
93 /** Singleton Desktop instance */
94 public static Desktop instance;
96 public static MyDesktopPane desktop;
98 static int openFrameCount = 0;
100 static final int xOffset = 30;
102 static final int yOffset = 30;
104 public static jalview.ws.jws1.Discoverer discoverer;
106 public static Object[] jalviewClipboard;
108 public static boolean internalCopy = false;
110 static int fileLoadingCount = 0;
112 class MyDesktopManager implements DesktopManager
115 private DesktopManager delegate;
117 public MyDesktopManager(DesktopManager delegate)
119 this.delegate = delegate;
122 public void activateFrame(JInternalFrame f)
126 delegate.activateFrame(f);
127 } catch (NullPointerException npe)
129 Point p = getMousePosition();
130 instance.showPasteMenu(p.x, p.y);
134 public void beginDraggingFrame(JComponent f)
136 delegate.beginDraggingFrame(f);
139 public void beginResizingFrame(JComponent f, int direction)
141 delegate.beginResizingFrame(f, direction);
144 public void closeFrame(JInternalFrame f)
146 delegate.closeFrame(f);
149 public void deactivateFrame(JInternalFrame f)
151 delegate.deactivateFrame(f);
154 public void deiconifyFrame(JInternalFrame f)
156 delegate.deiconifyFrame(f);
159 public void dragFrame(JComponent f, int newX, int newY)
161 delegate.dragFrame(f, newX, newY);
164 public void endDraggingFrame(JComponent f)
166 delegate.endDraggingFrame(f);
169 public void endResizingFrame(JComponent f)
171 delegate.endResizingFrame(f);
174 public void iconifyFrame(JInternalFrame f)
176 delegate.iconifyFrame(f);
179 public void maximizeFrame(JInternalFrame f)
181 delegate.maximizeFrame(f);
184 public void minimizeFrame(JInternalFrame f)
186 delegate.minimizeFrame(f);
189 public void openFrame(JInternalFrame f)
191 delegate.openFrame(f);
194 public void resizeFrame(JComponent f, int newX, int newY, int newWidth,
197 delegate.resizeFrame(f, newX, newY, newWidth, newHeight);
200 public void setBoundsForFrame(JComponent f, int newX, int newY,
201 int newWidth, int newHeight)
203 delegate.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
206 // All other methods, simply delegate
211 * Creates a new Desktop object.
216 * A note to implementors. It is ESSENTIAL that any activities that might
217 * block are spawned off as threads rather than waited for during this
221 doVamsasClientCheck();
224 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
225 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
226 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",
228 boolean showjconsole = jalview.bin.Cache.getDefault(
229 "SHOW_JAVA_CONSOLE", false);
230 desktop = new MyDesktopPane(selmemusage);
231 showMemusage.setSelected(selmemusage);
232 desktop.setBackground(Color.white);
233 getContentPane().setLayout(new BorderLayout());
234 getContentPane().add(desktop, BorderLayout.CENTER);
235 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
237 // This line prevents Windows Look&Feel resizing all new windows to maximum
238 // if previous window was maximised
239 desktop.setDesktopManager(new MyDesktopManager(
240 new DefaultDesktopManager()));
241 Rectangle dims = getLastKnownDimensions("");
248 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
249 setBounds((int) (screenSize.width - 900) / 2,
250 (int) (screenSize.height - 650) / 2, 900, 650);
252 jconsole = new Console(this, showjconsole);
253 // add essential build information
254 jconsole.setHeader("Jalview Desktop "
255 + jalview.bin.Cache.getProperty("VERSION") + "\n"
257 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
258 + "Java version: " + System.getProperty("java.version") + "\n"
259 + System.getProperty("os.arch") + " "
260 + System.getProperty("os.name") + " "
261 + System.getProperty("os.version"));
263 showConsole(showjconsole);
265 this.addWindowListener(new WindowAdapter()
267 public void windowClosing(WindowEvent evt)
273 this.addMouseListener(new MouseAdapter()
275 public void mousePressed(MouseEvent evt)
277 if (SwingUtilities.isRightMouseButton(evt))
279 showPasteMenu(evt.getX(), evt.getY());
284 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
285 // Spawn a thread that shows the splashscreen
286 SwingUtilities.invokeLater(new Runnable()
295 // Thread off a new instance of the file chooser - this reduces the time it
296 // takes to open it later on.
297 new Thread(new Runnable()
301 Cache.log.debug("Filechooser init thread started.");
302 JalviewFileChooser chooser = new JalviewFileChooser(
303 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
304 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
305 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
306 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
307 Cache.log.debug("Filechooser init thread finished.");
310 // Add the service change listener
311 changeSupport.addJalviewPropertyChangeListener("services",
312 new PropertyChangeListener()
316 public void propertyChange(PropertyChangeEvent evt)
318 Cache.log.debug("Firing service changed event for "
319 + evt.getNewValue());
320 JalviewServicesChanged(evt);
327 * recover the last known dimensions for a jalview window
330 * - empty string is desktop, all other windows have unique prefix
331 * @return null or last known dimensions scaled to current geometry (if last
332 * window geom was known)
334 Rectangle getLastKnownDimensions(String windowName)
336 // TODO: lock aspect ratio for scaling desktop Bug #0058199
337 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
338 String x = jalview.bin.Cache.getProperty(windowName + "SCREEN_X");
339 String y = jalview.bin.Cache.getProperty(windowName + "SCREEN_Y");
340 String width = jalview.bin.Cache.getProperty(windowName
342 String height = jalview.bin.Cache.getProperty(windowName
344 if ((x != null) && (y != null) && (width != null) && (height != null))
346 int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer
347 .parseInt(width), ih = Integer.parseInt(height);
348 if (jalview.bin.Cache.getProperty("SCREENGEOMETRY_WIDTH") != null)
350 // attempt #1 - try to cope with change in screen geometry - this
351 // version doesn't preserve original jv aspect ratio.
352 // take ratio of current screen size vs original screen size.
353 double sw = ((1f * screenSize.width) / (1f * Integer
354 .parseInt(jalview.bin.Cache
355 .getProperty("SCREENGEOMETRY_WIDTH"))));
356 double sh = ((1f * screenSize.height) / (1f * Integer
357 .parseInt(jalview.bin.Cache
358 .getProperty("SCREENGEOMETRY_HEIGHT"))));
359 // rescale the bounds depending upon the current screen geometry.
360 ix = (int) (ix * sw);
361 iw = (int) (iw * sw);
362 iy = (int) (iy * sh);
363 ih = (int) (ih * sh);
364 while (ix >= screenSize.width)
366 jalview.bin.Cache.log
367 .debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
368 ix -= screenSize.width;
370 while (iy >= screenSize.height)
372 jalview.bin.Cache.log
373 .debug("Window geometry location recall error: shifting vertical to within screenbounds.");
374 iy -= screenSize.height;
376 jalview.bin.Cache.log.debug("Got last known dimensions for "
377 + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
380 // return dimensions for new instance
381 return new Rectangle(ix, iy, iw, ih);
386 private void doVamsasClientCheck()
388 if (jalview.bin.Cache.vamsasJarsPresent())
390 setupVamsasDisconnectedGui();
391 VamsasMenu.setVisible(true);
392 final Desktop us = this;
393 VamsasMenu.addMenuListener(new MenuListener()
395 // this listener remembers when the menu was first selected, and
396 // doesn't rebuild the session list until it has been cleared and
398 boolean refresh = true;
400 public void menuCanceled(MenuEvent e)
405 public void menuDeselected(MenuEvent e)
410 public void menuSelected(MenuEvent e)
414 us.buildVamsasStMenu();
419 vamsasStart.setVisible(true);
423 void showPasteMenu(int x, int y)
425 JPopupMenu popup = new JPopupMenu();
426 JMenuItem item = new JMenuItem("Paste To New Window");
427 item.addActionListener(new ActionListener()
429 public void actionPerformed(ActionEvent evt)
436 popup.show(this, x, y);
443 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
444 Transferable contents = c.getContents(this);
446 if (contents != null)
448 String file = (String) contents
449 .getTransferData(DataFlavor.stringFlavor);
451 String format = new IdentifyFile().Identify(file,
452 FormatAdapter.PASTE);
454 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
457 } catch (Exception ex)
460 .println("Unable to paste alignment from system clipboard:\n"
466 * Adds and opens the given frame to the desktop
477 public static synchronized void addInternalFrame(
478 final JInternalFrame frame, String title, int w, int h)
480 addInternalFrame(frame, title, w, h, true);
497 public static synchronized void addInternalFrame(
498 final JInternalFrame frame, String title, int w, int h,
502 // TODO: allow callers to determine X and Y position of frame (eg. via
504 // TODO: consider fixing method to update entries in the window submenu with
505 // the current window title
507 frame.setTitle(title);
508 if (frame.getWidth() < 1 || frame.getHeight() < 1)
512 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
513 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
514 // IF JALVIEW IS RUNNING HEADLESS
515 // ///////////////////////////////////////////////
516 if (System.getProperty("java.awt.headless") != null
517 && System.getProperty("java.awt.headless").equals("true"))
524 frame.setVisible(true);
525 frame.setClosable(true);
526 frame.setResizable(resizable);
527 frame.setMaximizable(resizable);
528 frame.setIconifiable(resizable);
529 frame.setFrameIcon(null);
531 if (frame.getX() < 1 && frame.getY() < 1)
533 frame.setLocation(xOffset * openFrameCount, yOffset
534 * ((openFrameCount - 1) % 10) + yOffset);
537 final JMenuItem menuItem = new JMenuItem(title);
538 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
540 public void internalFrameActivated(
541 javax.swing.event.InternalFrameEvent evt)
543 JInternalFrame itf = desktop.getSelectedFrame();
551 public void internalFrameClosed(
552 javax.swing.event.InternalFrameEvent evt)
554 PaintRefresher.RemoveComponent(frame);
556 windowMenu.remove(menuItem);
557 JInternalFrame itf = desktop.getSelectedFrame();
566 menuItem.addActionListener(new ActionListener()
568 public void actionPerformed(ActionEvent e)
572 frame.setSelected(true);
573 frame.setIcon(false);
574 } catch (java.beans.PropertyVetoException ex)
581 windowMenu.add(menuItem);
587 frame.setSelected(true);
588 frame.requestFocus();
589 } catch (java.beans.PropertyVetoException ve)
594 public void lostOwnership(Clipboard clipboard, Transferable contents)
598 Desktop.jalviewClipboard = null;
601 internalCopy = false;
604 public void dragEnter(DropTargetDragEvent evt)
608 public void dragExit(DropTargetEvent evt)
612 public void dragOver(DropTargetDragEvent evt)
616 public void dropActionChanged(DropTargetDragEvent evt)
626 public void drop(DropTargetDropEvent evt)
628 Transferable t = evt.getTransferable();
629 java.util.List files = null;
630 java.util.List protocols = null;
634 DataFlavor uriListFlavor = new DataFlavor(
635 "text/uri-list;class=java.lang.String");
636 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
638 // Works on Windows and MacOSX
639 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
640 files = (java.util.List) t
641 .getTransferData(DataFlavor.javaFileListFlavor);
643 else if (t.isDataFlavorSupported(uriListFlavor))
645 // This is used by Unix drag system
646 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
647 String data = (String) t.getTransferData(uriListFlavor);
648 files = new java.util.ArrayList(1);
649 protocols = new java.util.ArrayList(1);
650 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
651 data, "\r\n"); st.hasMoreTokens();)
653 String s = st.nextToken();
654 if (s.startsWith("#"))
656 // the line is a comment (as per the RFC 2483)
659 java.net.URI uri = new java.net.URI(s);
660 if (uri.getScheme().toLowerCase().startsWith("http"))
662 protocols.add(FormatAdapter.URL);
663 files.add(uri.toString());
667 // otherwise preserve old behaviour: catch all for file objects
668 java.io.File file = new java.io.File(uri);
669 protocols.add(FormatAdapter.FILE);
670 files.add(file.toString());
674 } catch (Exception e)
682 for (int i = 0; i < files.size(); i++)
684 String file = files.get(i).toString();
685 String protocol = (protocols == null) ? FormatAdapter.FILE
686 : (String) protocols.get(i);
687 String format = null;
689 if (file.endsWith(".jar"))
696 format = new IdentifyFile().Identify(file, protocol);
699 new FileLoader().LoadFile(file, protocol, format);
702 } catch (Exception ex)
714 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
716 JalviewFileChooser chooser = new JalviewFileChooser(
717 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
718 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
719 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
720 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
722 chooser.setFileView(new JalviewFileView());
723 chooser.setDialogTitle("Open local file");
724 chooser.setToolTipText("Open");
726 int value = chooser.showOpenDialog(this);
728 if (value == JalviewFileChooser.APPROVE_OPTION)
730 String choice = chooser.getSelectedFile().getPath();
731 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
732 .getSelectedFile().getParent());
734 String format = null;
735 if (chooser.getSelectedFormat().equals("Jalview"))
741 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
744 if (viewport != null)
746 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
751 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
762 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
764 // This construct allows us to have a wider textfield
766 JLabel label = new JLabel("Enter URL of Input File");
767 final JComboBox history = new JComboBox();
769 JPanel panel = new JPanel(new GridLayout(2, 1));
772 history.setPreferredSize(new Dimension(400, 20));
773 history.setEditable(true);
774 history.addItem("http://www.");
776 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
780 if (historyItems != null)
782 st = new StringTokenizer(historyItems, "\t");
784 while (st.hasMoreTokens())
786 history.addItem(st.nextElement());
790 int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
791 "Input Alignment From URL", JOptionPane.OK_CANCEL_OPTION);
793 if (reply != JOptionPane.OK_OPTION)
798 String url = history.getSelectedItem().toString();
800 if (url.toLowerCase().endsWith(".jar"))
802 if (viewport != null)
804 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
809 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
814 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
816 if (format.equals("URL NOT FOUND"))
818 JOptionPane.showInternalMessageDialog(Desktop.desktop,
819 "Couldn't locate " + url, "URL not found",
820 JOptionPane.WARNING_MESSAGE);
825 if (viewport != null)
827 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
831 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
842 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
844 CutAndPasteTransfer cap = new CutAndPasteTransfer();
845 cap.setForInput(viewport);
846 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
854 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
856 .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
857 jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
859 storeLastKnownDimensions("", new Rectangle(getBounds().x,
860 getBounds().y, getWidth(), getHeight()));
862 if (jconsole != null)
864 storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
865 jconsole.stopConsole();
870 private void storeLastKnownDimensions(String string, Rectangle jc)
872 jalview.bin.Cache.log.debug("Storing last known dimensions for "
873 + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
874 + " height:" + jc.height);
876 jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
877 jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
878 jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
879 jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
888 public void aboutMenuItem_actionPerformed(ActionEvent e)
890 StringBuffer message = new StringBuffer("Jalview version "
891 + jalview.bin.Cache.getProperty("VERSION") + "; last updated: "
892 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
894 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
895 jalview.bin.Cache.getProperty("VERSION")))
897 message.append("\n\n!! Jalview version "
898 + jalview.bin.Cache.getProperty("LATEST_VERSION")
899 + " is available for download from http://www.jalview.org !!\n");
902 // TODO: update this text for each release or centrally store it for lite
904 message.append("\nAuthors: Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,\n David Martin & Geoff Barton."
905 + "\nDevelopment managed by The Barton Group, University of Dundee, Scotland, UK.\n"
906 + "\nFor help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list\n"
907 + "\nIf you use Jalview, please cite:"
908 + "\nWaterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
909 + "\nJalview Version 2 - a multiple sequence alignment editor and analysis workbench"
910 + "\nBioinformatics doi: 10.1093/bioinformatics/btp033");
911 JOptionPane.showInternalMessageDialog(Desktop.desktop,
913 message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
922 public void documentationMenuItem_actionPerformed(ActionEvent e)
926 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
927 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
928 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
930 javax.help.HelpBroker hb = hs.createHelpBroker();
931 hb.setCurrentID("home");
932 hb.setDisplayed(true);
933 } catch (Exception ex)
938 public void closeAll_actionPerformed(ActionEvent e)
940 JInternalFrame[] frames = desktop.getAllFrames();
941 for (int i = 0; i < frames.length; i++)
945 frames[i].setClosed(true);
946 } catch (java.beans.PropertyVetoException ex)
950 System.out.println("ALL CLOSED");
951 if (v_client != null)
953 // TODO clear binding to vamsas document objects on close_all
958 public void raiseRelated_actionPerformed(ActionEvent e)
960 reorderAssociatedWindows(false, false);
963 public void minimizeAssociated_actionPerformed(ActionEvent e)
965 reorderAssociatedWindows(true, false);
968 void closeAssociatedWindows()
970 reorderAssociatedWindows(false, true);
976 * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
979 protected void garbageCollect_actionPerformed(ActionEvent e)
981 // We simply collect the garbage
982 jalview.bin.Cache.log.debug("Collecting garbage...");
984 jalview.bin.Cache.log.debug("Finished garbage collection.");
991 * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
994 protected void showMemusage_actionPerformed(ActionEvent e)
996 desktop.showMemoryUsage(showMemusage.isSelected());
1003 * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
1006 protected void showConsole_actionPerformed(ActionEvent e)
1008 showConsole(showConsole.isSelected());
1011 Console jconsole = null;
1014 * control whether the java console is visible or not
1018 void showConsole(boolean selected)
1020 showConsole.setSelected(selected);
1021 // TODO: decide if we should update properties file
1022 Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected)
1024 jconsole.setVisible(selected);
1027 void reorderAssociatedWindows(boolean minimize, boolean close)
1029 JInternalFrame[] frames = desktop.getAllFrames();
1030 if (frames == null || frames.length < 1)
1035 AlignViewport source = null, target = null;
1036 if (frames[0] instanceof AlignFrame)
1038 source = ((AlignFrame) frames[0]).getCurrentView();
1040 else if (frames[0] instanceof TreePanel)
1042 source = ((TreePanel) frames[0]).getViewPort();
1044 else if (frames[0] instanceof PCAPanel)
1046 source = ((PCAPanel) frames[0]).av;
1048 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
1050 source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
1055 for (int i = 0; i < frames.length; i++)
1058 if (frames[i] == null)
1062 if (frames[i] instanceof AlignFrame)
1064 target = ((AlignFrame) frames[i]).getCurrentView();
1066 else if (frames[i] instanceof TreePanel)
1068 target = ((TreePanel) frames[i]).getViewPort();
1070 else if (frames[i] instanceof PCAPanel)
1072 target = ((PCAPanel) frames[i]).av;
1074 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
1076 target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
1079 if (source == target)
1085 frames[i].setClosed(true);
1089 frames[i].setIcon(minimize);
1092 frames[i].toFront();
1096 } catch (java.beans.PropertyVetoException ex)
1110 protected void preferences_actionPerformed(ActionEvent e)
1121 public void saveState_actionPerformed(ActionEvent e)
1123 JalviewFileChooser chooser = new JalviewFileChooser(
1124 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1125 { "jar" }, new String[]
1126 { "Jalview Project" }, "Jalview Project");
1128 chooser.setFileView(new JalviewFileView());
1129 chooser.setDialogTitle("Save State");
1131 int value = chooser.showSaveDialog(this);
1133 if (value == JalviewFileChooser.APPROVE_OPTION)
1135 java.io.File choice = chooser.getSelectedFile();
1136 setProgressBar("Saving jalview project " + choice.getName(),
1138 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1139 // TODO catch and handle errors for savestate
1142 new Jalview2XML().SaveState(choice);
1143 } catch (OutOfMemoryError oom)
1146 "Whilst saving current state to " + choice.getName(), oom);
1147 } catch (Exception ex)
1150 .error("Problems whilst trying to save to "
1151 + choice.getName(), ex);
1152 JOptionPane.showMessageDialog(this,
1153 "Error whilst saving current state to " + choice.getName(),
1154 "Couldn't save project", JOptionPane.WARNING_MESSAGE);
1156 setProgressBar(null, choice.hashCode());
1167 public void loadState_actionPerformed(ActionEvent e)
1169 JalviewFileChooser chooser = new JalviewFileChooser(
1170 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1171 { "jar" }, new String[]
1172 { "Jalview Project" }, "Jalview Project");
1173 chooser.setFileView(new JalviewFileView());
1174 chooser.setDialogTitle("Restore state");
1176 int value = chooser.showOpenDialog(this);
1178 if (value == JalviewFileChooser.APPROVE_OPTION)
1180 final String choice = chooser.getSelectedFile().getAbsolutePath();
1181 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
1182 .getSelectedFile().getParent());
1183 new Thread(new Runnable()
1187 setProgressBar("loading jalview project " + choice,
1191 new Jalview2XML().LoadJalviewAlign(choice);
1192 } catch (OutOfMemoryError oom)
1194 new OOMWarning("Whilst loading project from " + choice, oom);
1195 } catch (Exception ex)
1197 Cache.log.error("Problems whilst loading project from "
1199 JOptionPane.showMessageDialog(Desktop.desktop,
1200 "Error whilst loading project from " + choice,
1201 "Couldn't load project", JOptionPane.WARNING_MESSAGE);
1203 setProgressBar(null, choice.hashCode());
1209 public void inputSequence_actionPerformed(ActionEvent e)
1211 new SequenceFetcher(this);
1214 JPanel progressPanel;
1216 public void startLoading(final String fileName)
1218 if (fileLoadingCount == 0)
1220 addProgressPanel("Loading File: " + fileName + " ");
1226 private JProgressBar addProgressPanel(String string)
1228 if (progressPanel == null)
1230 progressPanel = new JPanel(new BorderLayout());
1231 totalProgressCount = 0;
1233 JProgressBar progressBar = new JProgressBar();
1234 progressBar.setIndeterminate(true);
1236 progressPanel.add(new JLabel(string), BorderLayout.WEST);
1238 progressPanel.add(progressBar, BorderLayout.CENTER);
1240 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
1241 totalProgressCount++;
1246 int totalProgressCount = 0;
1248 private void removeProgressPanel(JProgressBar progbar)
1250 if (progressPanel != null)
1252 progressPanel.remove(progbar);
1253 if (--totalProgressCount < 1)
1255 this.getContentPane().remove(progressPanel);
1256 progressPanel = null;
1262 public void stopLoading()
1265 if (fileLoadingCount < 1)
1267 if (progressPanel != null)
1269 this.getContentPane().remove(progressPanel);
1270 progressPanel = null;
1272 fileLoadingCount = 0;
1277 public static int getViewCount(String viewId)
1279 AlignViewport[] aps = getViewports(viewId);
1280 return (aps == null) ? 0 : aps.length;
1286 * @return all AlignmentPanels concerning the viewId sequence set
1288 public static AlignmentPanel[] getAlignmentPanels(String viewId)
1291 if (Desktop.desktop == null)
1293 // no frames created and in headless mode
1294 // TODO: verify that frames are recoverable when in headless mode
1297 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1298 ArrayList aps = new ArrayList();
1299 for (int t = 0; t < frames.length; t++)
1301 if (frames[t] instanceof AlignFrame)
1303 AlignFrame af = (AlignFrame) frames[t];
1304 for (int a = 0; a < af.alignPanels.size(); a++)
1307 .equals(((AlignmentPanel) af.alignPanels.elementAt(a)).av
1308 .getSequenceSetId()))
1310 aps.add(af.alignPanels.elementAt(a));
1315 if (aps.size() == 0)
1319 AlignmentPanel[] vap = new AlignmentPanel[aps.size()];
1320 for (int t = 0; t < vap.length; t++)
1322 vap[t] = (AlignmentPanel) aps.get(t);
1328 * get all the viewports on an alignment.
1330 * @param sequenceSetId
1331 * unique alignment id
1332 * @return all viewports on the alignment bound to sequenceSetId
1334 public static AlignViewport[] getViewports(String sequenceSetId)
1336 Vector viewp = new Vector();
1337 if (desktop != null)
1339 javax.swing.JInternalFrame[] frames = instance.getAllFrames();
1341 for (int t = 0; t < frames.length; t++)
1343 if (frames[t] instanceof AlignFrame)
1345 AlignFrame afr = ((AlignFrame) frames[t]);
1346 if (afr.getViewport().getSequenceSetId().equals(sequenceSetId))
1348 if (afr.alignPanels != null)
1350 for (int a = 0; a < afr.alignPanels.size(); a++)
1352 if (sequenceSetId.equals(((AlignmentPanel) afr.alignPanels
1353 .elementAt(a)).av.getSequenceSetId()))
1355 viewp.addElement(((AlignmentPanel) afr.alignPanels
1362 viewp.addElement(((AlignFrame) frames[t]).getViewport());
1367 if (viewp.size() > 0)
1369 AlignViewport[] vp = new AlignViewport[viewp.size()];
1377 public void explodeViews(AlignFrame af)
1379 int size = af.alignPanels.size();
1385 for (int i = 0; i < size; i++)
1387 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
1388 AlignFrame newaf = new AlignFrame(ap);
1389 if (ap.av.explodedPosition != null
1390 && !ap.av.explodedPosition.equals(af.getBounds()))
1392 newaf.setBounds(ap.av.explodedPosition);
1395 ap.av.gatherViewsHere = false;
1397 addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1398 AlignFrame.DEFAULT_HEIGHT);
1401 af.alignPanels.clear();
1402 af.closeMenuItem_actionPerformed(true);
1406 public void gatherViews(AlignFrame source)
1408 source.viewport.gatherViewsHere = true;
1409 source.viewport.explodedPosition = source.getBounds();
1410 JInternalFrame[] frames = desktop.getAllFrames();
1411 String viewId = source.viewport.sequenceSetID;
1413 for (int t = 0; t < frames.length; t++)
1415 if (frames[t] instanceof AlignFrame && frames[t] != source)
1417 AlignFrame af = (AlignFrame) frames[t];
1418 boolean gatherThis = false;
1419 for (int a = 0; a < af.alignPanels.size(); a++)
1421 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
1422 if (viewId.equals(ap.av.getSequenceSetId()))
1425 ap.av.gatherViewsHere = false;
1426 ap.av.explodedPosition = af.getBounds();
1427 source.addAlignmentPanel(ap, false);
1433 af.alignPanels.clear();
1434 af.closeMenuItem_actionPerformed(true);
1441 jalview.gui.VamsasApplication v_client = null;
1443 public void vamsasImport_actionPerformed(ActionEvent e)
1445 if (v_client == null)
1447 // Load and try to start a session.
1448 JalviewFileChooser chooser = new JalviewFileChooser(
1449 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1451 chooser.setFileView(new JalviewFileView());
1452 chooser.setDialogTitle("Open a saved VAMSAS session");
1453 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
1455 int value = chooser.showOpenDialog(this);
1457 if (value == JalviewFileChooser.APPROVE_OPTION)
1459 String fle = chooser.getSelectedFile().toString();
1460 if (!vamsasImport(chooser.getSelectedFile()))
1462 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1463 "Couldn't import '" + fle + "' as a new vamsas session.",
1464 "Vamsas Document Import Failed",
1465 JOptionPane.ERROR_MESSAGE);
1471 jalview.bin.Cache.log
1472 .error("Implementation error - load session from a running session is not supported.");
1477 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1480 * @return true if import was a success and a session was started.
1482 public boolean vamsasImport(URL url)
1484 // TODO: create progress bar
1485 if (v_client != null)
1488 jalview.bin.Cache.log
1489 .error("Implementation error - load session from a running session is not supported.");
1495 // copy the URL content to a temporary local file
1496 // TODO: be a bit cleverer here with nio (?!)
1497 File file = File.createTempFile("vdocfromurl", ".vdj");
1498 FileOutputStream fos = new FileOutputStream(file);
1499 BufferedInputStream bis = new BufferedInputStream(url.openStream());
1500 byte[] buffer = new byte[2048];
1502 while ((ln = bis.read(buffer)) > -1)
1504 fos.write(buffer, 0, ln);
1508 v_client = new jalview.gui.VamsasApplication(this, file,
1509 url.toExternalForm());
1510 } catch (Exception ex)
1512 jalview.bin.Cache.log.error(
1513 "Failed to create new vamsas session from contents of URL "
1517 setupVamsasConnectedGui();
1518 v_client.initial_update(); // TODO: thread ?
1519 return v_client.inSession();
1523 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1526 * @return true if import was a success and a session was started.
1528 public boolean vamsasImport(File file)
1530 if (v_client != null)
1533 jalview.bin.Cache.log
1534 .error("Implementation error - load session from a running session is not supported.");
1538 setProgressBar("Importing VAMSAS session from " + file.getName(),
1542 v_client = new jalview.gui.VamsasApplication(this, file, null);
1543 } catch (Exception ex)
1545 setProgressBar("Importing VAMSAS session from " + file.getName(),
1547 jalview.bin.Cache.log.error(
1548 "New vamsas session from existing session file failed:", ex);
1551 setupVamsasConnectedGui();
1552 v_client.initial_update(); // TODO: thread ?
1553 setProgressBar("Importing VAMSAS session from " + file.getName(),
1555 return v_client.inSession();
1558 public boolean joinVamsasSession(String mysesid)
1560 if (v_client != null)
1563 "Trying to join a vamsas session when another is already connected.");
1565 if (mysesid == null)
1567 throw new Error("Invalid vamsas session id.");
1569 v_client = new VamsasApplication(this, mysesid);
1570 setupVamsasConnectedGui();
1571 v_client.initial_update();
1572 return (v_client.inSession());
1575 public void vamsasStart_actionPerformed(ActionEvent e)
1577 if (v_client == null)
1580 // we just start a default session for moment.
1582 * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1583 * getProperty("LAST_DIRECTORY"));
1585 * chooser.setFileView(new JalviewFileView());
1586 * chooser.setDialogTitle("Load Vamsas file");
1587 * chooser.setToolTipText("Import");
1589 * int value = chooser.showOpenDialog(this);
1591 * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
1592 * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
1594 v_client = new VamsasApplication(this);
1595 setupVamsasConnectedGui();
1596 v_client.initial_update(); // TODO: thread ?
1600 // store current data in session.
1601 v_client.push_update(); // TODO: thread
1605 protected void setupVamsasConnectedGui()
1607 vamsasStart.setText("Session Update");
1608 vamsasSave.setVisible(true);
1609 vamsasStop.setVisible(true);
1610 vamsasImport.setVisible(false); // Document import to existing session is
1611 // not possible for vamsas-client-1.0.
1614 protected void setupVamsasDisconnectedGui()
1616 vamsasSave.setVisible(false);
1617 vamsasStop.setVisible(false);
1618 vamsasImport.setVisible(true);
1619 vamsasStart.setText("New Vamsas Session");
1622 public void vamsasStop_actionPerformed(ActionEvent e)
1624 if (v_client != null)
1626 v_client.end_session();
1628 setupVamsasDisconnectedGui();
1632 protected void buildVamsasStMenu()
1634 if (v_client == null)
1636 String[] sess = null;
1639 sess = VamsasApplication.getSessionList();
1640 } catch (Exception e)
1642 jalview.bin.Cache.log.warn(
1643 "Problem getting current sessions list.", e);
1648 jalview.bin.Cache.log.debug("Got current sessions list: "
1649 + sess.length + " entries.");
1650 VamsasStMenu.removeAll();
1651 for (int i = 0; i < sess.length; i++)
1653 JMenuItem sessit = new JMenuItem();
1654 sessit.setText(sess[i]);
1655 sessit.setToolTipText("Connect to session " + sess[i]);
1656 final Desktop dsktp = this;
1657 final String mysesid = sess[i];
1658 sessit.addActionListener(new ActionListener()
1661 public void actionPerformed(ActionEvent e)
1663 if (dsktp.v_client == null)
1665 Thread rthr = new Thread(new Runnable()
1670 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1671 dsktp.setupVamsasConnectedGui();
1672 dsktp.v_client.initial_update();
1680 VamsasStMenu.add(sessit);
1682 // don't show an empty menu.
1683 VamsasStMenu.setVisible(sess.length > 0);
1688 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1689 VamsasStMenu.removeAll();
1690 VamsasStMenu.setVisible(false);
1695 // Not interested in the content. Just hide ourselves.
1696 VamsasStMenu.setVisible(false);
1700 public void vamsasSave_actionPerformed(ActionEvent e)
1702 if (v_client != null)
1704 JalviewFileChooser chooser = new JalviewFileChooser(
1705 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1706 { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1708 { "Vamsas Document" }, "Vamsas Document");
1710 chooser.setFileView(new JalviewFileView());
1711 chooser.setDialogTitle("Save Vamsas Document Archive");
1713 int value = chooser.showSaveDialog(this);
1715 if (value == JalviewFileChooser.APPROVE_OPTION)
1717 java.io.File choice = chooser.getSelectedFile();
1718 JProgressBar progpanel = addProgressPanel("Saving VAMSAS Document to "
1719 + choice.getName());
1720 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1721 String warnmsg = null;
1722 String warnttl = null;
1725 v_client.vclient.storeDocument(choice);
1728 warnttl = "Serious Problem saving Vamsas Document";
1729 warnmsg = ex.toString();
1730 jalview.bin.Cache.log.error("Error Whilst saving document to "
1733 } catch (Exception ex)
1735 warnttl = "Problem saving Vamsas Document.";
1736 warnmsg = ex.toString();
1737 jalview.bin.Cache.log.warn("Exception Whilst saving document to "
1741 removeProgressPanel(progpanel);
1742 if (warnmsg != null)
1744 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1746 warnmsg, warnttl, JOptionPane.ERROR_MESSAGE);
1752 JProgressBar vamUpdate = null;
1755 * hide vamsas user gui bits when a vamsas document event is being handled.
1758 * true to hide gui, false to reveal gui
1760 public void setVamsasUpdate(boolean b)
1762 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "
1763 + (b ? "in progress" : "finished"));
1765 if (vamUpdate != null)
1767 this.removeProgressPanel(vamUpdate);
1771 vamUpdate = this.addProgressPanel("Updating vamsas session");
1773 vamsasStart.setVisible(!b);
1774 vamsasStop.setVisible(!b);
1775 vamsasSave.setVisible(!b);
1778 public JInternalFrame[] getAllFrames()
1780 return desktop.getAllFrames();
1784 * Checks the given url to see if it gives a response indicating that the user
1785 * should be informed of a new questionnaire.
1789 public void checkForQuestionnaire(String url)
1791 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1792 // javax.swing.SwingUtilities.invokeLater(jvq);
1793 new Thread(jvq).start();
1797 * Proxy class for JDesktopPane which optionally displays the current memory
1798 * usage and highlights the desktop area with a red bar if free memory runs
1803 public class MyDesktopPane extends JDesktopPane implements Runnable
1806 boolean showMemoryUsage = false;
1810 java.text.NumberFormat df;
1812 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
1815 public MyDesktopPane(boolean showMemoryUsage)
1817 showMemoryUsage(showMemoryUsage);
1820 public void showMemoryUsage(boolean showMemoryUsage)
1822 this.showMemoryUsage = showMemoryUsage;
1823 if (showMemoryUsage)
1825 Thread worker = new Thread(this);
1830 public boolean isShowMemoryUsage()
1832 return showMemoryUsage;
1837 df = java.text.NumberFormat.getNumberInstance();
1838 df.setMaximumFractionDigits(2);
1839 runtime = Runtime.getRuntime();
1841 while (showMemoryUsage)
1845 maxMemory = runtime.maxMemory() / 1048576f;
1846 allocatedMemory = runtime.totalMemory() / 1048576f;
1847 freeMemory = runtime.freeMemory() / 1048576f;
1848 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1850 percentUsage = (totalFreeMemory / maxMemory) * 100;
1852 // if (percentUsage < 20)
1854 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12,
1856 // instance.set.setBorder(border1);
1859 // sleep after showing usage
1861 } catch (Exception ex)
1863 ex.printStackTrace();
1868 public void paintComponent(Graphics g)
1870 if (showMemoryUsage && g != null && df != null)
1872 if (percentUsage < 20)
1873 g.setColor(Color.red);
1874 FontMetrics fm = g.getFontMetrics();
1878 "Total Free Memory: " + df.format(totalFreeMemory)
1879 + "MB; Max Memory: " + df.format(maxMemory)
1880 + "MB; " + df.format(percentUsage) + "%", 10,
1881 getHeight() - fm.getHeight());
1888 protected JMenuItem groovyShell;
1890 public void doGroovyCheck()
1892 if (jalview.bin.Cache.groovyJarsPresent())
1894 groovyShell = new JMenuItem();
1895 groovyShell.setText("Groovy Console...");
1896 groovyShell.addActionListener(new ActionListener()
1898 public void actionPerformed(ActionEvent e)
1900 groovyShell_actionPerformed(e);
1903 toolsMenu.add(groovyShell);
1904 groovyShell.setVisible(true);
1909 * Accessor method to quickly get all the AlignmentFrames loaded.
1911 public static AlignFrame[] getAlignframes()
1913 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1919 Vector avp = new Vector();
1923 for (int i = frames.length - 1; i > -1; i--)
1925 if (frames[i] instanceof AlignFrame)
1927 AlignFrame af = (AlignFrame) frames[i];
1931 } catch (Exception ex)
1933 ex.printStackTrace();
1935 if (avp.size() == 0)
1939 AlignFrame afs[] = new AlignFrame[avp.size()];
1940 for (int i = 0, j = avp.size(); i < j; i++)
1942 afs[i] = (AlignFrame) avp.elementAt(i);
1949 * Add Groovy Support to Jalview
1951 public void groovyShell_actionPerformed(ActionEvent e)
1953 // use reflection to avoid creating compilation dependency.
1954 if (!jalview.bin.Cache.groovyJarsPresent())
1957 "Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1961 Class gcClass = Desktop.class.getClassLoader().loadClass(
1962 "groovy.ui.Console");
1963 Constructor gccons = gcClass.getConstructor(null);
1964 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
1966 { String.class, Object.class });
1967 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1968 Object gc = gccons.newInstance(null);
1969 setvar.invoke(gc, new Object[]
1970 { "Jalview", this });
1971 run.invoke(gc, null);
1972 } catch (Exception ex)
1974 jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
1976 .showInternalMessageDialog(
1979 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.",
1980 "Jalview Groovy Support Failed",
1981 JOptionPane.ERROR_MESSAGE);
1986 * Progress bars managed by the IProgressIndicator method.
1988 private Hashtable progressBars, progressBarHandlers;
1993 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1995 public void setProgressBar(String message, long id)
1997 if (progressBars == null)
1999 progressBars = new Hashtable();
2000 progressBarHandlers = new Hashtable();
2003 if (progressBars.get(new Long(id)) != null)
2005 JProgressBar progressPanel = (JProgressBar) progressBars
2006 .remove(new Long(id));
2007 if (progressBarHandlers.contains(new Long(id)))
2009 progressBarHandlers.remove(new Long(id));
2011 removeProgressPanel(progressPanel);
2015 progressBars.put(new Long(id), addProgressPanel(message));
2022 * @see jalview.gui.IProgressIndicator#registerHandler(long,
2023 * jalview.gui.IProgressIndicatorHandler)
2025 public void registerHandler(final long id,
2026 final IProgressIndicatorHandler handler)
2028 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
2031 "call setProgressBar before registering the progress bar's handler.");
2033 progressBarHandlers.put(new Long(id), handler);
2034 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
2035 if (handler.canCancel())
2037 JButton cancel = new JButton("Cancel");
2038 final IProgressIndicator us = this;
2039 cancel.addActionListener(new ActionListener()
2042 public void actionPerformed(ActionEvent e)
2044 handler.cancelActivity(id);
2047 + ((JLabel) progressPanel.getComponent(0))
2051 progressPanel.add(cancel, BorderLayout.EAST);
2056 * This will return the first AlignFrame viewing AlignViewport av. It will
2057 * break if there are more than one AlignFrames viewing a particular av. This
2060 * @return alignFrame for av
2062 public static AlignFrame getAlignFrameFor(AlignViewport av)
2064 if (desktop != null)
2066 AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId());
2067 for (int panel = 0; aps != null && panel < aps.length; panel++)
2069 if (aps[panel] != null && aps[panel].av == av)
2071 return aps[panel].alignFrame;
2078 public VamsasApplication getVamsasApplication()
2085 * flag set if jalview GUI is being operated programmatically
2087 private boolean inBatchMode = false;
2090 * check if jalview GUI is being operated programmatically
2092 * @return inBatchMode
2094 public boolean isInBatchMode()
2100 * set flag if jalview GUI is being operated programmatically
2102 * @param inBatchMode
2104 public void setInBatchMode(boolean inBatchMode)
2106 this.inBatchMode = inBatchMode;
2109 public void startServiceDiscovery()
2111 startServiceDiscovery(false);
2114 public void startServiceDiscovery(boolean blocking)
2116 boolean alive = true;
2117 Thread t0 = null, t1 = null, t2 = null;
2119 // todo: changesupport handlers need to be transferred
2120 if (discoverer == null)
2122 discoverer = new jalview.ws.jws1.Discoverer();
2123 // register PCS handler for desktop.
2124 discoverer.addPropertyChangeListener(changeSupport);
2126 if (Cache.getDefault("SHOW_JWS1_SERVICES", true))
2128 (t0 = new Thread(discoverer)).start();
2133 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
2135 // EnfinEnvision web service menu entries are rebuild every time the
2136 // menu is shown, so no changeSupport events are needed.
2137 jalview.ws.EnfinEnvision2OneWay.getInstance();
2138 (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
2141 } catch (Exception e)
2144 .info("Exception when trying to launch Envision2 workflow discovery.",
2146 Cache.log.info(e.getStackTrace());
2148 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
2150 if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning())
2152 jalview.ws.jws2.Jws2Discoverer.getDiscoverer().setAborted(true);
2154 t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(
2165 } catch (Exception e)
2168 alive = (t1 != null && t1.isAlive())
2169 || (t2 != null && t2.isAlive())
2170 || (t0 != null && t0.isAlive());
2176 * called to check if the service discovery process completed successfully.
2180 protected void JalviewServicesChanged(PropertyChangeEvent evt)
2182 if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
2184 final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
2185 .getErrorMessages();
2188 if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
2190 if (serviceChangedDialog == null)
2193 // only run if we aren't already displaying one of these.
2194 javax.swing.SwingUtilities
2195 .invokeLater(serviceChangedDialog = new Runnable()
2201 .showInternalMessageDialog(
2204 + "It may be that you have invalid JABA URLs\nin your web service preferences.\n\nGo to the Web services tab of the\nTools->Preferences dialog box to change them.\n",
2205 "Preferences Problem",
2206 JOptionPane.WARNING_MESSAGE);
2207 serviceChangedDialog = null;
2216 .error("Errors reported by JABA discovery service. Check web services preferences.\n"
2223 private Runnable serviceChangedDialog = null;
2226 * start a thread to open a URL in the configured browser. Pops up a warning
2227 * dialog to the user if there is an exception when calling out to the browser
2232 public static void showUrl(final String url)
2234 new Thread(new Runnable()
2240 jalview.util.BrowserLauncher.openURL(url);
2241 } catch (Exception ex)
2244 .showInternalMessageDialog(
2246 "Unixers: Couldn't find default web browser."
2247 + "\nAdd the full path to your browser in Preferences.",
2248 "Web browser not found",
2249 JOptionPane.WARNING_MESSAGE);
2251 ex.printStackTrace();
2257 public static WsParamSetManager wsparamManager = null;
2259 public static ParamManager getUserParameterStore()
2261 if (wsparamManager == null)
2263 wsparamManager = new WsParamSetManager();
2265 return wsparamManager;