2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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;
21 import jalview.io.FileLoader;
22 import jalview.io.FormatAdapter;
23 import jalview.io.IdentifyFile;
24 import jalview.io.JalviewFileChooser;
25 import jalview.io.JalviewFileView;
26 import jalview.ws.params.ParamManager;
28 import java.awt.BorderLayout;
29 import java.awt.Color;
30 import java.awt.Dimension;
31 import java.awt.FontMetrics;
32 import java.awt.Graphics;
33 import java.awt.GridLayout;
34 import java.awt.Point;
35 import java.awt.Rectangle;
36 import java.awt.Toolkit;
37 import java.awt.datatransfer.Clipboard;
38 import java.awt.datatransfer.ClipboardOwner;
39 import java.awt.datatransfer.DataFlavor;
40 import java.awt.datatransfer.Transferable;
41 import java.awt.dnd.DnDConstants;
42 import java.awt.dnd.DropTargetDragEvent;
43 import java.awt.dnd.DropTargetDropEvent;
44 import java.awt.dnd.DropTargetEvent;
45 import java.awt.dnd.DropTargetListener;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.ActionListener;
48 import java.awt.event.FocusEvent;
49 import java.awt.event.FocusListener;
50 import java.awt.event.MouseAdapter;
51 import java.awt.event.MouseEvent;
52 import java.awt.event.MouseListener;
53 import java.awt.event.WindowAdapter;
54 import java.awt.event.WindowEvent;
55 import java.beans.PropertyChangeEvent;
56 import java.beans.PropertyChangeListener;
57 import java.beans.PropertyVetoException;
58 import java.io.BufferedInputStream;
60 import java.io.FileOutputStream;
61 import java.lang.reflect.Constructor;
63 import java.util.ArrayList;
64 import java.util.Hashtable;
65 import java.util.StringTokenizer;
66 import java.util.Vector;
68 import javax.swing.DefaultDesktopManager;
69 import javax.swing.DesktopManager;
70 import javax.swing.JButton;
71 import javax.swing.JComboBox;
72 import javax.swing.JComponent;
73 import javax.swing.JDesktopPane;
74 import javax.swing.JFrame;
75 import javax.swing.JInternalFrame;
76 import javax.swing.JLabel;
77 import javax.swing.JMenuItem;
78 import javax.swing.JOptionPane;
79 import javax.swing.JPanel;
80 import javax.swing.JPopupMenu;
81 import javax.swing.JProgressBar;
82 import javax.swing.SwingUtilities;
83 import javax.swing.event.MenuEvent;
84 import javax.swing.event.MenuListener;
91 * @version $Revision: 1.155 $
93 public class Desktop extends jalview.jbgui.GDesktop implements
94 DropTargetListener, ClipboardOwner, IProgressIndicator, jalview.api.StructureSelectionManagerProvider
97 private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
100 * news reader - null if it was never started.
102 private BlogReader jvnews=null;
106 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
108 public void addJalviewPropertyChangeListener(
109 PropertyChangeListener listener)
111 changeSupport.addJalviewPropertyChangeListener(listener);
115 * @param propertyName
117 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
118 * java.beans.PropertyChangeListener)
120 public void addJalviewPropertyChangeListener(String propertyName,
121 PropertyChangeListener listener)
123 changeSupport.addJalviewPropertyChangeListener(propertyName, listener);
127 * @param propertyName
129 * @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
130 * java.beans.PropertyChangeListener)
132 public void removeJalviewPropertyChangeListener(String propertyName,
133 PropertyChangeListener listener)
135 changeSupport.removeJalviewPropertyChangeListener(propertyName,
139 /** Singleton Desktop instance */
140 public static Desktop instance;
142 public static MyDesktopPane desktop;
144 static int openFrameCount = 0;
146 static final int xOffset = 30;
148 static final int yOffset = 30;
150 public static jalview.ws.jws1.Discoverer discoverer;
152 public static Object[] jalviewClipboard;
154 public static boolean internalCopy = false;
156 static int fileLoadingCount = 0;
158 class MyDesktopManager implements DesktopManager
161 private DesktopManager delegate;
163 public MyDesktopManager(DesktopManager delegate)
165 this.delegate = delegate;
168 public void activateFrame(JInternalFrame f)
172 delegate.activateFrame(f);
173 } catch (NullPointerException npe)
175 Point p = getMousePosition();
176 instance.showPasteMenu(p.x, p.y);
180 public void beginDraggingFrame(JComponent f)
182 delegate.beginDraggingFrame(f);
185 public void beginResizingFrame(JComponent f, int direction)
187 delegate.beginResizingFrame(f, direction);
190 public void closeFrame(JInternalFrame f)
192 delegate.closeFrame(f);
195 public void deactivateFrame(JInternalFrame f)
197 delegate.deactivateFrame(f);
200 public void deiconifyFrame(JInternalFrame f)
202 delegate.deiconifyFrame(f);
205 public void dragFrame(JComponent f, int newX, int newY)
211 delegate.dragFrame(f, newX, newY);
214 public void endDraggingFrame(JComponent f)
216 delegate.endDraggingFrame(f);
219 public void endResizingFrame(JComponent f)
221 delegate.endResizingFrame(f);
224 public void iconifyFrame(JInternalFrame f)
226 delegate.iconifyFrame(f);
229 public void maximizeFrame(JInternalFrame f)
231 delegate.maximizeFrame(f);
234 public void minimizeFrame(JInternalFrame f)
236 delegate.minimizeFrame(f);
239 public void openFrame(JInternalFrame f)
241 delegate.openFrame(f);
244 public void resizeFrame(JComponent f, int newX, int newY, int newWidth,
247 Rectangle b=desktop.getBounds();
252 delegate.resizeFrame(f, newX, newY, newWidth, newHeight);
255 public void setBoundsForFrame(JComponent f, int newX, int newY,
256 int newWidth, int newHeight)
258 delegate.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
261 // All other methods, simply delegate
266 * Creates a new Desktop object.
271 * A note to implementors. It is ESSENTIAL that any activities that might
272 * block are spawned off as threads rather than waited for during this
276 doVamsasClientCheck();
279 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
280 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
281 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",
283 boolean showjconsole = jalview.bin.Cache.getDefault(
284 "SHOW_JAVA_CONSOLE", false);
285 desktop = new MyDesktopPane(selmemusage);
286 showMemusage.setSelected(selmemusage);
287 desktop.setBackground(Color.white);
288 getContentPane().setLayout(new BorderLayout());
289 // alternate config - have scrollbars - see notes in JAL-153
290 //JScrollPane sp = new JScrollPane();
291 //sp.getViewport().setView(desktop);
292 //getContentPane().add(sp, BorderLayout.CENTER);
293 getContentPane().add(desktop, BorderLayout.CENTER);
294 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
297 // This line prevents Windows Look&Feel resizing all new windows to maximum
298 // if previous window was maximised
299 desktop.setDesktopManager(new MyDesktopManager(
300 new DefaultDesktopManager()));
302 Rectangle dims = getLastKnownDimensions("");
309 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
310 setBounds((int) (screenSize.width - 900) / 2,
311 (int) (screenSize.height - 650) / 2, 900, 650);
313 jconsole = new Console(this, showjconsole);
314 // add essential build information
315 jconsole.setHeader("Jalview Desktop "
316 + jalview.bin.Cache.getProperty("VERSION") + "\n"
318 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
319 + "Java version: " + System.getProperty("java.version") + "\n"
320 + System.getProperty("os.arch") + " "
321 + System.getProperty("os.name") + " "
322 + System.getProperty("os.version"));
324 showConsole(showjconsole);
326 showNews.setVisible(false);
327 final Desktop me = this;
328 // Thread off the news reader, in case there are connection problems.
329 new Thread( new Runnable() {
333 Cache.log.debug("Starting news thread.");
335 jvnews = new BlogReader(me);
336 showNews.setVisible(true);
337 Cache.log.debug("Completed news thread.");
341 this.addWindowListener(new WindowAdapter()
343 public void windowClosing(WindowEvent evt)
350 this.addMouseListener(ma=new MouseAdapter()
352 public void mousePressed(MouseEvent evt)
354 if (SwingUtilities.isRightMouseButton(evt))
356 showPasteMenu(evt.getX(), evt.getY());
360 desktop.addMouseListener(ma);
362 this.addFocusListener(new FocusListener()
366 public void focusLost(FocusEvent e)
368 // TODO Auto-generated method stub
373 public void focusGained(FocusEvent e)
375 Cache.log.debug("Relaying windows after focus gain");
376 // make sure that we sort windows properly after we gain focus
377 instance.relayerWindows();
380 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
381 // Spawn a thread that shows the splashscreen
382 SwingUtilities.invokeLater(new Runnable()
391 // Thread off a new instance of the file chooser - this reduces the time it
392 // takes to open it later on.
393 new Thread(new Runnable()
397 Cache.log.debug("Filechooser init thread started.");
398 JalviewFileChooser chooser = new JalviewFileChooser(
399 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
400 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
401 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
402 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
403 Cache.log.debug("Filechooser init thread finished.");
406 // Add the service change listener
407 changeSupport.addJalviewPropertyChangeListener("services",
408 new PropertyChangeListener()
412 public void propertyChange(PropertyChangeEvent evt)
414 Cache.log.debug("Firing service changed event for "
415 + evt.getNewValue());
416 JalviewServicesChanged(evt);
422 protected void showNews_actionPerformed(ActionEvent e)
424 showNews(showNews.isSelected());
426 void showNews(boolean visible)
429 Cache.log.debug((visible?"Showing":"Hiding")+" news.");
430 showNews.setSelected(visible);
431 if (visible && !jvnews.isVisible())
433 new Thread(new Runnable() {
437 long instance=System.currentTimeMillis();
438 Desktop.instance.setProgressBar("Refreshing news", instance);
439 jvnews.refreshNews();
440 Desktop.instance.setProgressBar(null, instance);
449 * recover the last known dimensions for a jalview window
452 * - empty string is desktop, all other windows have unique prefix
453 * @return null or last known dimensions scaled to current geometry (if last
454 * window geom was known)
456 Rectangle getLastKnownDimensions(String windowName)
458 // TODO: lock aspect ratio for scaling desktop Bug #0058199
459 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
460 String x = jalview.bin.Cache.getProperty(windowName + "SCREEN_X");
461 String y = jalview.bin.Cache.getProperty(windowName + "SCREEN_Y");
462 String width = jalview.bin.Cache.getProperty(windowName
464 String height = jalview.bin.Cache.getProperty(windowName
466 if ((x != null) && (y != null) && (width != null) && (height != null))
468 int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer
469 .parseInt(width), ih = Integer.parseInt(height);
470 if (jalview.bin.Cache.getProperty("SCREENGEOMETRY_WIDTH") != null)
472 // attempt #1 - try to cope with change in screen geometry - this
473 // version doesn't preserve original jv aspect ratio.
474 // take ratio of current screen size vs original screen size.
475 double sw = ((1f * screenSize.width) / (1f * Integer
476 .parseInt(jalview.bin.Cache
477 .getProperty("SCREENGEOMETRY_WIDTH"))));
478 double sh = ((1f * screenSize.height) / (1f * Integer
479 .parseInt(jalview.bin.Cache
480 .getProperty("SCREENGEOMETRY_HEIGHT"))));
481 // rescale the bounds depending upon the current screen geometry.
482 ix = (int) (ix * sw);
483 iw = (int) (iw * sw);
484 iy = (int) (iy * sh);
485 ih = (int) (ih * sh);
486 while (ix >= screenSize.width)
488 jalview.bin.Cache.log
489 .debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
490 ix -= screenSize.width;
492 while (iy >= screenSize.height)
494 jalview.bin.Cache.log
495 .debug("Window geometry location recall error: shifting vertical to within screenbounds.");
496 iy -= screenSize.height;
498 jalview.bin.Cache.log.debug("Got last known dimensions for "
499 + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
502 // return dimensions for new instance
503 return new Rectangle(ix, iy, iw, ih);
508 private void doVamsasClientCheck()
510 if (jalview.bin.Cache.vamsasJarsPresent())
512 setupVamsasDisconnectedGui();
513 VamsasMenu.setVisible(true);
514 final Desktop us = this;
515 VamsasMenu.addMenuListener(new MenuListener()
517 // this listener remembers when the menu was first selected, and
518 // doesn't rebuild the session list until it has been cleared and
520 boolean refresh = true;
522 public void menuCanceled(MenuEvent e)
527 public void menuDeselected(MenuEvent e)
532 public void menuSelected(MenuEvent e)
536 us.buildVamsasStMenu();
541 vamsasStart.setVisible(true);
545 void showPasteMenu(int x, int y)
547 JPopupMenu popup = new JPopupMenu();
548 JMenuItem item = new JMenuItem("Paste To New Window");
549 item.addActionListener(new ActionListener()
551 public void actionPerformed(ActionEvent evt)
558 popup.show(this, x, y);
565 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
566 Transferable contents = c.getContents(this);
568 if (contents != null)
570 String file = (String) contents
571 .getTransferData(DataFlavor.stringFlavor);
573 String format = new IdentifyFile().Identify(file,
574 FormatAdapter.PASTE);
576 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
579 } catch (Exception ex)
582 .println("Unable to paste alignment from system clipboard:\n"
588 * Adds and opens the given frame to the desktop
599 public static synchronized void addInternalFrame(
600 final JInternalFrame frame, String title, int w, int h)
602 addInternalFrame(frame, title, w, h, true);
619 public static synchronized void addInternalFrame(
620 final JInternalFrame frame, String title, int w, int h,
624 // TODO: allow callers to determine X and Y position of frame (eg. via
626 // TODO: consider fixing method to update entries in the window submenu with
627 // the current window title
629 frame.setTitle(title);
630 if (frame.getWidth() < 1 || frame.getHeight() < 1)
634 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
635 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
636 // IF JALVIEW IS RUNNING HEADLESS
637 // ///////////////////////////////////////////////
638 if (System.getProperty("java.awt.headless") != null
639 && System.getProperty("java.awt.headless").equals("true"))
646 frame.setVisible(true);
647 frame.setClosable(true);
648 frame.setResizable(resizable);
649 frame.setMaximizable(resizable);
650 frame.setIconifiable(resizable);
651 frame.setFrameIcon(null);
653 if (frame.getX() < 1 && frame.getY() < 1)
655 frame.setLocation(xOffset * openFrameCount, yOffset
656 * ((openFrameCount - 1) % 10) + yOffset);
659 final JMenuItem menuItem = new JMenuItem(title);
660 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
662 public void internalFrameActivated(
663 javax.swing.event.InternalFrameEvent evt)
665 JInternalFrame itf = desktop.getSelectedFrame();
673 public void internalFrameClosed(
674 javax.swing.event.InternalFrameEvent evt)
676 PaintRefresher.RemoveComponent(frame);
678 windowMenu.remove(menuItem);
679 JInternalFrame itf = desktop.getSelectedFrame();
688 menuItem.addActionListener(new ActionListener()
690 public void actionPerformed(ActionEvent e)
694 frame.setSelected(true);
695 frame.setIcon(false);
696 } catch (java.beans.PropertyVetoException ex)
702 menuItem.addMouseListener(new MouseListener()
706 public void mouseReleased(MouseEvent e)
711 public void mousePressed(MouseEvent e)
716 public void mouseExited(MouseEvent e)
720 frame.setSelected(false);
721 } catch (PropertyVetoException e1)
727 public void mouseEntered(MouseEvent e)
731 frame.setSelected(true);
732 } catch (PropertyVetoException e1)
738 public void mouseClicked(MouseEvent e)
744 windowMenu.add(menuItem);
750 frame.setSelected(true);
751 frame.requestFocus();
752 } catch (java.beans.PropertyVetoException ve)
755 catch (java.lang.ClassCastException cex)
757 Cache.log.warn("Squashed a possible GUI implementation error. If you can recreate this, please look at http://issues.jalview.org/browse/JAL-869",cex);
761 public void lostOwnership(Clipboard clipboard, Transferable contents)
765 Desktop.jalviewClipboard = null;
768 internalCopy = false;
771 public void dragEnter(DropTargetDragEvent evt)
775 public void dragExit(DropTargetEvent evt)
779 public void dragOver(DropTargetDragEvent evt)
783 public void dropActionChanged(DropTargetDragEvent evt)
793 public void drop(DropTargetDropEvent evt)
795 Transferable t = evt.getTransferable();
796 java.util.List files = null;
797 java.util.List protocols = null;
801 DataFlavor uriListFlavor = new DataFlavor(
802 "text/uri-list;class=java.lang.String");
803 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
805 // Works on Windows and MacOSX
806 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
807 files = (java.util.List) t
808 .getTransferData(DataFlavor.javaFileListFlavor);
810 else if (t.isDataFlavorSupported(uriListFlavor))
812 // This is used by Unix drag system
813 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
814 String data = (String) t.getTransferData(uriListFlavor);
815 files = new java.util.ArrayList(1);
816 protocols = new java.util.ArrayList(1);
817 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
818 data, "\r\n"); st.hasMoreTokens();)
820 String s = st.nextToken();
821 if (s.startsWith("#"))
823 // the line is a comment (as per the RFC 2483)
826 java.net.URI uri = new java.net.URI(s);
827 if (uri.getScheme().toLowerCase().startsWith("http"))
829 protocols.add(FormatAdapter.URL);
830 files.add(uri.toString());
834 // otherwise preserve old behaviour: catch all for file objects
835 java.io.File file = new java.io.File(uri);
836 protocols.add(FormatAdapter.FILE);
837 files.add(file.toString());
841 } catch (Exception e)
849 for (int i = 0; i < files.size(); i++)
851 String file = files.get(i).toString();
852 String protocol = (protocols == null) ? FormatAdapter.FILE
853 : (String) protocols.get(i);
854 String format = null;
856 if (file.endsWith(".jar"))
863 format = new IdentifyFile().Identify(file, protocol);
866 new FileLoader().LoadFile(file, protocol, format);
869 } catch (Exception ex)
881 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
883 JalviewFileChooser chooser = new JalviewFileChooser(
884 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
885 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
886 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
887 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
889 chooser.setFileView(new JalviewFileView());
890 chooser.setDialogTitle("Open local file");
891 chooser.setToolTipText("Open");
893 int value = chooser.showOpenDialog(this);
895 if (value == JalviewFileChooser.APPROVE_OPTION)
897 String choice = chooser.getSelectedFile().getPath();
898 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
899 .getSelectedFile().getParent());
901 String format = null;
902 if (chooser.getSelectedFormat().equals("Jalview"))
908 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
911 if (viewport != null)
913 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
918 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
929 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
931 // This construct allows us to have a wider textfield
933 JLabel label = new JLabel("Enter URL of Input File");
934 final JComboBox history = new JComboBox();
936 JPanel panel = new JPanel(new GridLayout(2, 1));
939 history.setPreferredSize(new Dimension(400, 20));
940 history.setEditable(true);
941 history.addItem("http://www.");
943 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
947 if (historyItems != null)
949 st = new StringTokenizer(historyItems, "\t");
951 while (st.hasMoreTokens())
953 history.addItem(st.nextElement());
957 int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
958 "Input Alignment From URL", JOptionPane.OK_CANCEL_OPTION);
960 if (reply != JOptionPane.OK_OPTION)
965 String url = history.getSelectedItem().toString();
967 if (url.toLowerCase().endsWith(".jar"))
969 if (viewport != null)
971 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
976 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
981 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
983 if (format.equals("URL NOT FOUND"))
985 JOptionPane.showInternalMessageDialog(Desktop.desktop,
986 "Couldn't locate " + url, "URL not found",
987 JOptionPane.WARNING_MESSAGE);
992 if (viewport != null)
994 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
998 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
1009 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
1011 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1012 cap.setForInput(viewport);
1013 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
1021 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
1023 .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
1024 jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
1026 storeLastKnownDimensions("", new Rectangle(getBounds().x,
1027 getBounds().y, getWidth(), getHeight()));
1029 if (jconsole != null)
1031 storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
1032 jconsole.stopConsole();
1036 storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
1043 private void storeLastKnownDimensions(String string, Rectangle jc)
1045 jalview.bin.Cache.log.debug("Storing last known dimensions for "
1046 + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
1047 + " height:" + jc.height);
1049 jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
1050 jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
1051 jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
1052 jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
1061 public void aboutMenuItem_actionPerformed(ActionEvent e)
1063 StringBuffer message = getAboutMessage(false);
1064 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1066 message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
1068 public StringBuffer getAboutMessage(boolean shortv)
1070 StringBuffer message=new StringBuffer();
1071 message.append("<html>");
1074 message.append("<h1><strong>Jalview "
1075 + jalview.bin.Cache.getProperty("VERSION") + "</strong></h1><br>");
1076 message.append("<strong>Last Updated: <em>"+jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")+"</em></strong>");
1080 message.append("<strong>Jalview version "
1081 + jalview.bin.Cache.getProperty("VERSION") + "; last updated: "
1082 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
1085 if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
1088 message.append("<br>...Checking latest version...</br>");
1090 else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
1091 .equals(jalview.bin.Cache.getProperty("VERSION")))
1094 if (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
1095 .indexOf("automated build") == -1)
1098 // Displayed when code version and jnlp version do not match and code
1099 // version is not a development build
1100 message.append("<div style=\"color: #FF0000;font-style: bold;\">");
1103 message.append("<br>!! Jalview version "
1104 + jalview.bin.Cache.getDefault("LATEST_VERSION",
1106 + " is available for download from "+jalview.bin.Cache.getDefault("www.jalview.org","http://www.jalview.org")+" !!");
1108 message.append("</div>");
1111 message.append("<br>Authors: "+jalview.bin.Cache.getDefault("AUTHORNAMES","Jim Procter, Andrew Waterhouse, Jan Engelhardt, Lauren Lui, Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton")
1112 + "<br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
1113 + "<br>For help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list"
1114 + "<br>If you use Jalview, please cite:"
1115 + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
1116 + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
1117 + "<br>Bioinformatics doi: 10.1093/bioinformatics/btp033"
1128 public void documentationMenuItem_actionPerformed(ActionEvent e)
1132 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
1133 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
1134 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
1136 javax.help.HelpBroker hb = hs.createHelpBroker();
1137 hb.setCurrentID("home");
1138 hb.setDisplayed(true);
1139 } catch (Exception ex)
1144 public void closeAll_actionPerformed(ActionEvent e)
1146 JInternalFrame[] frames = desktop.getAllFrames();
1147 for (int i = 0; i < frames.length; i++)
1151 frames[i].setClosed(true);
1152 } catch (java.beans.PropertyVetoException ex)
1156 System.out.println("ALL CLOSED");
1157 if (v_client != null)
1159 // TODO clear binding to vamsas document objects on close_all
1164 public void raiseRelated_actionPerformed(ActionEvent e)
1166 reorderAssociatedWindows(false, false);
1169 public void minimizeAssociated_actionPerformed(ActionEvent e)
1171 reorderAssociatedWindows(true, false);
1174 void closeAssociatedWindows()
1176 reorderAssociatedWindows(false, true);
1182 * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
1185 protected void garbageCollect_actionPerformed(ActionEvent e)
1187 // We simply collect the garbage
1188 jalview.bin.Cache.log.debug("Collecting garbage...");
1190 jalview.bin.Cache.log.debug("Finished garbage collection.");
1197 * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
1200 protected void showMemusage_actionPerformed(ActionEvent e)
1202 desktop.showMemoryUsage(showMemusage.isSelected());
1209 * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
1212 protected void showConsole_actionPerformed(ActionEvent e)
1214 showConsole(showConsole.isSelected());
1217 Console jconsole = null;
1220 * control whether the java console is visible or not
1224 void showConsole(boolean selected)
1226 showConsole.setSelected(selected);
1227 // TODO: decide if we should update properties file
1228 Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected)
1230 jconsole.setVisible(selected);
1233 void reorderAssociatedWindows(boolean minimize, boolean close)
1235 JInternalFrame[] frames = desktop.getAllFrames();
1236 if (frames == null || frames.length < 1)
1241 AlignViewport source = null, target = null;
1242 if (frames[0] instanceof AlignFrame)
1244 source = ((AlignFrame) frames[0]).getCurrentView();
1246 else if (frames[0] instanceof TreePanel)
1248 source = ((TreePanel) frames[0]).getViewPort();
1250 else if (frames[0] instanceof PCAPanel)
1252 source = ((PCAPanel) frames[0]).av;
1254 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
1256 source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
1261 for (int i = 0; i < frames.length; i++)
1264 if (frames[i] == null)
1268 if (frames[i] instanceof AlignFrame)
1270 target = ((AlignFrame) frames[i]).getCurrentView();
1272 else if (frames[i] instanceof TreePanel)
1274 target = ((TreePanel) frames[i]).getViewPort();
1276 else if (frames[i] instanceof PCAPanel)
1278 target = ((PCAPanel) frames[i]).av;
1280 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
1282 target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
1285 if (source == target)
1291 frames[i].setClosed(true);
1295 frames[i].setIcon(minimize);
1298 frames[i].toFront();
1302 } catch (java.beans.PropertyVetoException ex)
1316 protected void preferences_actionPerformed(ActionEvent e)
1327 public void saveState_actionPerformed(ActionEvent e)
1329 JalviewFileChooser chooser = new JalviewFileChooser(
1330 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1331 { "jar" }, new String[]
1332 { "Jalview Project" }, "Jalview Project");
1334 chooser.setFileView(new JalviewFileView());
1335 chooser.setDialogTitle("Save State");
1337 int value = chooser.showSaveDialog(this);
1339 if (value == JalviewFileChooser.APPROVE_OPTION)
1341 final Desktop me = this;
1342 final java.io.File choice = chooser.getSelectedFile();
1343 new Thread(new Runnable()
1348 setProgressBar("Saving jalview project " + choice.getName(),
1350 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1351 // TODO catch and handle errors for savestate
1352 // TODO prevent user from messing with the Desktop whilst we're saving
1355 new Jalview2XML().SaveState(choice);
1356 } catch (OutOfMemoryError oom)
1359 "Whilst saving current state to " + choice.getName(), oom);
1360 } catch (Exception ex)
1363 .error("Problems whilst trying to save to "
1364 + choice.getName(), ex);
1365 JOptionPane.showMessageDialog(me,
1366 "Error whilst saving current state to " + choice.getName(),
1367 "Couldn't save project", JOptionPane.WARNING_MESSAGE);
1369 setProgressBar(null, choice.hashCode());
1381 public void loadState_actionPerformed(ActionEvent e)
1383 JalviewFileChooser chooser = new JalviewFileChooser(
1384 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1385 { "jar" }, new String[]
1386 { "Jalview Project" }, "Jalview Project");
1387 chooser.setFileView(new JalviewFileView());
1388 chooser.setDialogTitle("Restore state");
1390 int value = chooser.showOpenDialog(this);
1392 if (value == JalviewFileChooser.APPROVE_OPTION)
1394 final String choice = chooser.getSelectedFile().getAbsolutePath();
1395 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
1396 .getSelectedFile().getParent());
1397 new Thread(new Runnable()
1401 setProgressBar("loading jalview project " + choice,
1405 new Jalview2XML().LoadJalviewAlign(choice);
1406 } catch (OutOfMemoryError oom)
1408 new OOMWarning("Whilst loading project from " + choice, oom);
1409 } catch (Exception ex)
1411 Cache.log.error("Problems whilst loading project from "
1413 JOptionPane.showMessageDialog(Desktop.desktop,
1414 "Error whilst loading project from " + choice,
1415 "Couldn't load project", JOptionPane.WARNING_MESSAGE);
1417 setProgressBar(null, choice.hashCode());
1423 public void inputSequence_actionPerformed(ActionEvent e)
1425 new SequenceFetcher(this);
1428 JPanel progressPanel;
1429 ArrayList<JPanel> fileLoadingPanels=new ArrayList<JPanel>();
1430 public void startLoading(final String fileName)
1432 if (fileLoadingCount == 0)
1434 fileLoadingPanels.add(addProgressPanel("Loading File: " + fileName + " "));
1439 private JPanel addProgressPanel(String string)
1441 if (progressPanel == null)
1443 progressPanel = new JPanel(new GridLayout(1,1));
1444 totalProgressCount = 0;
1445 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
1447 JPanel thisprogress=new JPanel(new BorderLayout(10,5));
1448 JProgressBar progressBar = new JProgressBar();
1449 progressBar.setIndeterminate(true);
1451 thisprogress.add(new JLabel(string), BorderLayout.WEST);
1453 thisprogress.add(progressBar, BorderLayout.CENTER);
1454 progressPanel.add(thisprogress);
1455 ((GridLayout)progressPanel.getLayout()).setRows(((GridLayout)progressPanel.getLayout()).getRows()+1);
1456 ++totalProgressCount;
1457 instance.validate();
1458 return thisprogress;
1461 int totalProgressCount = 0;
1463 private void removeProgressPanel(JPanel progbar)
1465 if (progressPanel != null)
1467 progressPanel.remove(progbar);
1468 GridLayout gl = (GridLayout) progressPanel.getLayout();
1469 gl.setRows(gl.getRows()-1);
1470 if (--totalProgressCount < 1)
1472 this.getContentPane().remove(progressPanel);
1473 progressPanel = null;
1479 public void stopLoading()
1482 if (fileLoadingCount < 1)
1484 for (JPanel flp : fileLoadingPanels)
1486 removeProgressPanel(flp);
1488 fileLoadingPanels.clear();
1489 fileLoadingCount = 0;
1494 public static int getViewCount(String alignmentId)
1496 AlignViewport[] aps = getViewports(alignmentId);
1497 return (aps == null) ? 0 : aps.length;
1502 * @param alignmentId
1503 * @return all AlignmentPanels concerning the alignmentId sequence set
1505 public static AlignmentPanel[] getAlignmentPanels(String alignmentId)
1508 if (Desktop.desktop == null)
1510 // no frames created and in headless mode
1511 // TODO: verify that frames are recoverable when in headless mode
1514 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1515 ArrayList aps = new ArrayList();
1516 for (int t = 0; t < frames.length; t++)
1518 if (frames[t] instanceof AlignFrame)
1520 AlignFrame af = (AlignFrame) frames[t];
1521 for (int a = 0; a < af.alignPanels.size(); a++)
1524 .equals(((AlignmentPanel) af.alignPanels.elementAt(a)).av
1525 .getSequenceSetId()))
1527 aps.add(af.alignPanels.elementAt(a));
1532 if (aps.size() == 0)
1536 AlignmentPanel[] vap = new AlignmentPanel[aps.size()];
1537 for (int t = 0; t < vap.length; t++)
1539 vap[t] = (AlignmentPanel) aps.get(t);
1545 * get all the viewports on an alignment.
1547 * @param sequenceSetId
1548 * unique alignment id
1549 * @return all viewports on the alignment bound to sequenceSetId
1551 public static AlignViewport[] getViewports(String sequenceSetId)
1553 Vector viewp = new Vector();
1554 if (desktop != null)
1556 javax.swing.JInternalFrame[] frames = instance.getAllFrames();
1558 for (int t = 0; t < frames.length; t++)
1560 if (frames[t] instanceof AlignFrame)
1562 AlignFrame afr = ((AlignFrame) frames[t]);
1563 if (afr.getViewport().getSequenceSetId().equals(sequenceSetId))
1565 if (afr.alignPanels != null)
1567 for (int a = 0; a < afr.alignPanels.size(); a++)
1569 if (sequenceSetId.equals(((AlignmentPanel) afr.alignPanels
1570 .elementAt(a)).av.getSequenceSetId()))
1572 viewp.addElement(((AlignmentPanel) afr.alignPanels
1579 viewp.addElement(((AlignFrame) frames[t]).getViewport());
1584 if (viewp.size() > 0)
1586 AlignViewport[] vp = new AlignViewport[viewp.size()];
1594 public void explodeViews(AlignFrame af)
1596 int size = af.alignPanels.size();
1602 for (int i = 0; i < size; i++)
1604 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
1605 AlignFrame newaf = new AlignFrame(ap);
1606 if (ap.av.explodedPosition != null
1607 && !ap.av.explodedPosition.equals(af.getBounds()))
1609 newaf.setBounds(ap.av.explodedPosition);
1612 ap.av.gatherViewsHere = false;
1614 addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1615 AlignFrame.DEFAULT_HEIGHT);
1618 af.alignPanels.clear();
1619 af.closeMenuItem_actionPerformed(true);
1623 public void gatherViews(AlignFrame source)
1625 source.viewport.gatherViewsHere = true;
1626 source.viewport.explodedPosition = source.getBounds();
1627 JInternalFrame[] frames = desktop.getAllFrames();
1628 String viewId = source.viewport.getSequenceSetId();
1630 for (int t = 0; t < frames.length; t++)
1632 if (frames[t] instanceof AlignFrame && frames[t] != source)
1634 AlignFrame af = (AlignFrame) frames[t];
1635 boolean gatherThis = false;
1636 for (int a = 0; a < af.alignPanels.size(); a++)
1638 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
1639 if (viewId.equals(ap.av.getSequenceSetId()))
1642 ap.av.gatherViewsHere = false;
1643 ap.av.explodedPosition = af.getBounds();
1644 source.addAlignmentPanel(ap, false);
1650 af.alignPanels.clear();
1651 af.closeMenuItem_actionPerformed(true);
1658 jalview.gui.VamsasApplication v_client = null;
1660 public void vamsasImport_actionPerformed(ActionEvent e)
1662 if (v_client == null)
1664 // Load and try to start a session.
1665 JalviewFileChooser chooser = new JalviewFileChooser(
1666 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1668 chooser.setFileView(new JalviewFileView());
1669 chooser.setDialogTitle("Open a saved VAMSAS session");
1670 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
1672 int value = chooser.showOpenDialog(this);
1674 if (value == JalviewFileChooser.APPROVE_OPTION)
1676 String fle = chooser.getSelectedFile().toString();
1677 if (!vamsasImport(chooser.getSelectedFile()))
1679 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1680 "Couldn't import '" + fle + "' as a new vamsas session.",
1681 "Vamsas Document Import Failed",
1682 JOptionPane.ERROR_MESSAGE);
1688 jalview.bin.Cache.log
1689 .error("Implementation error - load session from a running session is not supported.");
1694 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1697 * @return true if import was a success and a session was started.
1699 public boolean vamsasImport(URL url)
1701 // TODO: create progress bar
1702 if (v_client != null)
1705 jalview.bin.Cache.log
1706 .error("Implementation error - load session from a running session is not supported.");
1712 // copy the URL content to a temporary local file
1713 // TODO: be a bit cleverer here with nio (?!)
1714 File file = File.createTempFile("vdocfromurl", ".vdj");
1715 FileOutputStream fos = new FileOutputStream(file);
1716 BufferedInputStream bis = new BufferedInputStream(url.openStream());
1717 byte[] buffer = new byte[2048];
1719 while ((ln = bis.read(buffer)) > -1)
1721 fos.write(buffer, 0, ln);
1725 v_client = new jalview.gui.VamsasApplication(this, file,
1726 url.toExternalForm());
1727 } catch (Exception ex)
1729 jalview.bin.Cache.log.error(
1730 "Failed to create new vamsas session from contents of URL "
1734 setupVamsasConnectedGui();
1735 v_client.initial_update(); // TODO: thread ?
1736 return v_client.inSession();
1740 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1743 * @return true if import was a success and a session was started.
1745 public boolean vamsasImport(File file)
1747 if (v_client != null)
1750 jalview.bin.Cache.log
1751 .error("Implementation error - load session from a running session is not supported.");
1755 setProgressBar("Importing VAMSAS session from " + file.getName(),
1759 v_client = new jalview.gui.VamsasApplication(this, file, null);
1760 } catch (Exception ex)
1762 setProgressBar("Importing VAMSAS session from " + file.getName(),
1764 jalview.bin.Cache.log.error(
1765 "New vamsas session from existing session file failed:", ex);
1768 setupVamsasConnectedGui();
1769 v_client.initial_update(); // TODO: thread ?
1770 setProgressBar("Importing VAMSAS session from " + file.getName(),
1772 return v_client.inSession();
1775 public boolean joinVamsasSession(String mysesid)
1777 if (v_client != null)
1780 "Trying to join a vamsas session when another is already connected.");
1782 if (mysesid == null)
1784 throw new Error("Invalid vamsas session id.");
1786 v_client = new VamsasApplication(this, mysesid);
1787 setupVamsasConnectedGui();
1788 v_client.initial_update();
1789 return (v_client.inSession());
1792 public void vamsasStart_actionPerformed(ActionEvent e)
1794 if (v_client == null)
1797 // we just start a default session for moment.
1799 * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1800 * getProperty("LAST_DIRECTORY"));
1802 * chooser.setFileView(new JalviewFileView());
1803 * chooser.setDialogTitle("Load Vamsas file");
1804 * chooser.setToolTipText("Import");
1806 * int value = chooser.showOpenDialog(this);
1808 * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
1809 * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
1811 v_client = new VamsasApplication(this);
1812 setupVamsasConnectedGui();
1813 v_client.initial_update(); // TODO: thread ?
1817 // store current data in session.
1818 v_client.push_update(); // TODO: thread
1822 protected void setupVamsasConnectedGui()
1824 vamsasStart.setText("Session Update");
1825 vamsasSave.setVisible(true);
1826 vamsasStop.setVisible(true);
1827 vamsasImport.setVisible(false); // Document import to existing session is
1828 // not possible for vamsas-client-1.0.
1831 protected void setupVamsasDisconnectedGui()
1833 vamsasSave.setVisible(false);
1834 vamsasStop.setVisible(false);
1835 vamsasImport.setVisible(true);
1836 vamsasStart.setText("New Vamsas Session");
1839 public void vamsasStop_actionPerformed(ActionEvent e)
1841 if (v_client != null)
1843 v_client.end_session();
1845 setupVamsasDisconnectedGui();
1849 protected void buildVamsasStMenu()
1851 if (v_client == null)
1853 String[] sess = null;
1856 sess = VamsasApplication.getSessionList();
1857 } catch (Exception e)
1859 jalview.bin.Cache.log.warn(
1860 "Problem getting current sessions list.", e);
1865 jalview.bin.Cache.log.debug("Got current sessions list: "
1866 + sess.length + " entries.");
1867 VamsasStMenu.removeAll();
1868 for (int i = 0; i < sess.length; i++)
1870 JMenuItem sessit = new JMenuItem();
1871 sessit.setText(sess[i]);
1872 sessit.setToolTipText("Connect to session " + sess[i]);
1873 final Desktop dsktp = this;
1874 final String mysesid = sess[i];
1875 sessit.addActionListener(new ActionListener()
1878 public void actionPerformed(ActionEvent e)
1880 if (dsktp.v_client == null)
1882 Thread rthr = new Thread(new Runnable()
1887 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1888 dsktp.setupVamsasConnectedGui();
1889 dsktp.v_client.initial_update();
1897 VamsasStMenu.add(sessit);
1899 // don't show an empty menu.
1900 VamsasStMenu.setVisible(sess.length > 0);
1905 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1906 VamsasStMenu.removeAll();
1907 VamsasStMenu.setVisible(false);
1912 // Not interested in the content. Just hide ourselves.
1913 VamsasStMenu.setVisible(false);
1917 public void vamsasSave_actionPerformed(ActionEvent e)
1919 if (v_client != null)
1921 JalviewFileChooser chooser = new JalviewFileChooser(
1922 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
1923 { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1925 { "Vamsas Document" }, "Vamsas Document");
1927 chooser.setFileView(new JalviewFileView());
1928 chooser.setDialogTitle("Save Vamsas Document Archive");
1930 int value = chooser.showSaveDialog(this);
1932 if (value == JalviewFileChooser.APPROVE_OPTION)
1934 java.io.File choice = chooser.getSelectedFile();
1935 JPanel progpanel = addProgressPanel("Saving VAMSAS Document to "
1936 + choice.getName());
1937 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1938 String warnmsg = null;
1939 String warnttl = null;
1942 v_client.vclient.storeDocument(choice);
1945 warnttl = "Serious Problem saving Vamsas Document";
1946 warnmsg = ex.toString();
1947 jalview.bin.Cache.log.error("Error Whilst saving document to "
1950 } catch (Exception ex)
1952 warnttl = "Problem saving Vamsas Document.";
1953 warnmsg = ex.toString();
1954 jalview.bin.Cache.log.warn("Exception Whilst saving document to "
1958 removeProgressPanel(progpanel);
1959 if (warnmsg != null)
1961 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1963 warnmsg, warnttl, JOptionPane.ERROR_MESSAGE);
1969 JPanel vamUpdate = null;
1972 * hide vamsas user gui bits when a vamsas document event is being handled.
1975 * true to hide gui, false to reveal gui
1977 public void setVamsasUpdate(boolean b)
1979 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "
1980 + (b ? "in progress" : "finished"));
1982 if (vamUpdate != null)
1984 this.removeProgressPanel(vamUpdate);
1988 vamUpdate = this.addProgressPanel("Updating vamsas session");
1990 vamsasStart.setVisible(!b);
1991 vamsasStop.setVisible(!b);
1992 vamsasSave.setVisible(!b);
1995 public JInternalFrame[] getAllFrames()
1997 return desktop.getAllFrames();
2001 * Checks the given url to see if it gives a response indicating that the user
2002 * should be informed of a new questionnaire.
2006 public void checkForQuestionnaire(String url)
2008 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
2009 // javax.swing.SwingUtilities.invokeLater(jvq);
2010 new Thread(jvq).start();
2014 * Proxy class for JDesktopPane which optionally displays the current memory
2015 * usage and highlights the desktop area with a red bar if free memory runs
2020 public class MyDesktopPane extends JDesktopPane implements Runnable
2023 boolean showMemoryUsage = false;
2027 java.text.NumberFormat df;
2029 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
2032 public MyDesktopPane(boolean showMemoryUsage)
2034 showMemoryUsage(showMemoryUsage);
2037 public void showMemoryUsage(boolean showMemoryUsage)
2039 this.showMemoryUsage = showMemoryUsage;
2040 if (showMemoryUsage)
2042 Thread worker = new Thread(this);
2047 public boolean isShowMemoryUsage()
2049 return showMemoryUsage;
2054 df = java.text.NumberFormat.getNumberInstance();
2055 df.setMaximumFractionDigits(2);
2056 runtime = Runtime.getRuntime();
2058 while (showMemoryUsage)
2062 maxMemory = runtime.maxMemory() / 1048576f;
2063 allocatedMemory = runtime.totalMemory() / 1048576f;
2064 freeMemory = runtime.freeMemory() / 1048576f;
2065 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
2067 percentUsage = (totalFreeMemory / maxMemory) * 100;
2069 // if (percentUsage < 20)
2071 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12,
2073 // instance.set.setBorder(border1);
2076 // sleep after showing usage
2078 } catch (Exception ex)
2080 ex.printStackTrace();
2085 public void paintComponent(Graphics g)
2087 if (showMemoryUsage && g != null && df != null)
2089 if (percentUsage < 20)
2090 g.setColor(Color.red);
2091 FontMetrics fm = g.getFontMetrics();
2095 "Total Free Memory: " + df.format(totalFreeMemory)
2096 + "MB; Max Memory: " + df.format(maxMemory)
2097 + "MB; " + df.format(percentUsage) + "%", 10,
2098 getHeight() - fm.getHeight());
2105 * fixes stacking order after a modal dialog to ensure windows that should be on top actually are
2107 public void relayerWindows()
2112 protected JMenuItem groovyShell;
2114 public void doGroovyCheck()
2116 if (jalview.bin.Cache.groovyJarsPresent())
2118 groovyShell = new JMenuItem();
2119 groovyShell.setText("Groovy Console...");
2120 groovyShell.addActionListener(new ActionListener()
2122 public void actionPerformed(ActionEvent e)
2124 groovyShell_actionPerformed(e);
2127 toolsMenu.add(groovyShell);
2128 groovyShell.setVisible(true);
2133 * Accessor method to quickly get all the AlignmentFrames loaded.
2135 public static AlignFrame[] getAlignframes()
2137 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
2143 Vector avp = new Vector();
2147 for (int i = frames.length - 1; i > -1; i--)
2149 if (frames[i] instanceof AlignFrame)
2151 AlignFrame af = (AlignFrame) frames[i];
2155 } catch (Exception ex)
2157 ex.printStackTrace();
2159 if (avp.size() == 0)
2163 AlignFrame afs[] = new AlignFrame[avp.size()];
2164 for (int i = 0, j = avp.size(); i < j; i++)
2166 afs[i] = (AlignFrame) avp.elementAt(i);
2171 public AppJmol[] getJmols()
2173 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
2179 Vector avp = new Vector();
2183 for (int i = frames.length - 1; i > -1; i--)
2185 if (frames[i] instanceof AppJmol)
2187 AppJmol af = (AppJmol) frames[i];
2191 } catch (Exception ex)
2193 ex.printStackTrace();
2195 if (avp.size() == 0)
2199 AppJmol afs[] = new AppJmol[avp.size()];
2200 for (int i = 0, j = avp.size(); i < j; i++)
2202 afs[i] = (AppJmol) avp.elementAt(i);
2209 * Add Groovy Support to Jalview
2211 public void groovyShell_actionPerformed(ActionEvent e)
2213 // use reflection to avoid creating compilation dependency.
2214 if (!jalview.bin.Cache.groovyJarsPresent())
2217 "Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
2221 Class gcClass = Desktop.class.getClassLoader().loadClass(
2222 "groovy.ui.Console");
2223 Constructor gccons = gcClass.getConstructor(null);
2224 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
2226 { String.class, Object.class });
2227 java.lang.reflect.Method run = gcClass.getMethod("run", null);
2228 Object gc = gccons.newInstance(null);
2229 setvar.invoke(gc, new Object[]
2230 { "Jalview", this });
2231 run.invoke(gc, null);
2232 } catch (Exception ex)
2234 jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
2236 .showInternalMessageDialog(
2239 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.",
2240 "Jalview Groovy Support Failed",
2241 JOptionPane.ERROR_MESSAGE);
2246 * Progress bars managed by the IProgressIndicator method.
2248 private Hashtable<Long,JPanel> progressBars;
2249 private Hashtable<Long,IProgressIndicatorHandler> progressBarHandlers;
2254 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
2256 public void setProgressBar(String message, long id)
2258 if (progressBars == null)
2260 progressBars = new Hashtable<Long,JPanel>();
2261 progressBarHandlers = new Hashtable<Long,IProgressIndicatorHandler>();
2264 if (progressBars.get(new Long(id)) != null)
2266 JPanel progressPanel = progressBars
2267 .remove(new Long(id));
2268 if (progressBarHandlers.contains(new Long(id)))
2270 progressBarHandlers.remove(new Long(id));
2272 removeProgressPanel(progressPanel);
2276 progressBars.put(new Long(id), addProgressPanel(message));
2283 * @see jalview.gui.IProgressIndicator#registerHandler(long,
2284 * jalview.gui.IProgressIndicatorHandler)
2286 public void registerHandler(final long id,
2287 final IProgressIndicatorHandler handler)
2289 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
2292 "call setProgressBar before registering the progress bar's handler.");
2294 progressBarHandlers.put(new Long(id), handler);
2295 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
2296 if (handler.canCancel())
2298 JButton cancel = new JButton("Cancel");
2299 final IProgressIndicator us = this;
2300 cancel.addActionListener(new ActionListener()
2303 public void actionPerformed(ActionEvent e)
2305 handler.cancelActivity(id);
2308 + ((JLabel) progressPanel.getComponent(0))
2312 progressPanel.add(cancel, BorderLayout.EAST);
2317 * This will return the first AlignFrame viewing AlignViewport av. It will
2318 * break if there are more than one AlignFrames viewing a particular av. This
2321 * @return alignFrame for av
2323 public static AlignFrame getAlignFrameFor(AlignViewport av)
2325 if (desktop != null)
2327 AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId());
2328 for (int panel = 0; aps != null && panel < aps.length; panel++)
2330 if (aps[panel] != null && aps[panel].av == av)
2332 return aps[panel].alignFrame;
2339 public VamsasApplication getVamsasApplication()
2346 * flag set if jalview GUI is being operated programmatically
2348 private boolean inBatchMode = false;
2351 * check if jalview GUI is being operated programmatically
2353 * @return inBatchMode
2355 public boolean isInBatchMode()
2361 * set flag if jalview GUI is being operated programmatically
2363 * @param inBatchMode
2365 public void setInBatchMode(boolean inBatchMode)
2367 this.inBatchMode = inBatchMode;
2370 public void startServiceDiscovery()
2372 startServiceDiscovery(false);
2375 public void startServiceDiscovery(boolean blocking)
2377 boolean alive = true;
2378 Thread t0 = null, t1 = null, t2 = null;
2380 // todo: changesupport handlers need to be transferred
2381 if (discoverer == null)
2383 discoverer = new jalview.ws.jws1.Discoverer();
2384 // register PCS handler for desktop.
2385 discoverer.addPropertyChangeListener(changeSupport);
2387 // JAL-940 - disabled JWS1 service configuration - always start discoverer until we phase out completely
2390 (t0 = new Thread(discoverer)).start();
2395 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
2397 // EnfinEnvision web service menu entries are rebuild every time the
2398 // menu is shown, so no changeSupport events are needed.
2399 jalview.ws.EnfinEnvision2OneWay.getInstance();
2400 (t1 = new Thread(jalview.ws.EnfinEnvision2OneWay.getInstance()))
2403 } catch (Exception e)
2406 .info("Exception when trying to launch Envision2 workflow discovery.",
2408 Cache.log.info(e.getStackTrace());
2410 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
2412 if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning())
2414 jalview.ws.jws2.Jws2Discoverer.getDiscoverer().setAborted(true);
2416 t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(
2422 // TODO: do rest service discovery
2431 } catch (Exception e)
2434 alive = (t1 != null && t1.isAlive())
2435 || (t2 != null && t2.isAlive())
2436 || (t3 != null && t3.isAlive())
2437 || (t0 != null && t0.isAlive());
2443 * called to check if the service discovery process completed successfully.
2447 protected void JalviewServicesChanged(PropertyChangeEvent evt)
2449 if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
2451 final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
2452 .getErrorMessages();
2455 if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
2457 if (serviceChangedDialog == null)
2459 // only run if we aren't already displaying one of these.
2460 javax.swing.SwingUtilities
2461 .invokeLater(serviceChangedDialog = new Runnable()
2467 .showInternalMessageDialog(
2470 + "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",
2471 "Preferences Problem",
2472 JOptionPane.WARNING_MESSAGE);
2473 serviceChangedDialog = null;
2482 .error("Errors reported by JABA discovery service. Check web services preferences.\n"
2489 private Runnable serviceChangedDialog = null;
2492 * start a thread to open a URL in the configured browser. Pops up a warning
2493 * dialog to the user if there is an exception when calling out to the browser
2498 public static void showUrl(final String url)
2500 showUrl(url, Desktop.instance);
2503 * Like showUrl but allows progress handler to be specified
2505 * @param progress (null) or object implementing IProgressIndicator
2507 public static void showUrl(final String url, final IProgressIndicator progress)
2509 new Thread(new Runnable()
2515 if (progress!=null) {
2516 progress.setProgressBar("Opening "+url, this.hashCode());
2518 jalview.util.BrowserLauncher.openURL(url);
2519 } catch (Exception ex)
2522 .showInternalMessageDialog(
2524 "Unixers: Couldn't find default web browser."
2525 + "\nAdd the full path to your browser in Preferences.",
2526 "Web browser not found",
2527 JOptionPane.WARNING_MESSAGE);
2529 ex.printStackTrace();
2531 if (progress!=null) {
2532 progress.setProgressBar(null, this.hashCode());
2538 public static WsParamSetManager wsparamManager = null;
2540 public static ParamManager getUserParameterStore()
2542 if (wsparamManager == null)
2544 wsparamManager = new WsParamSetManager();
2546 return wsparamManager;