2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.datatransfer.*;
25 import java.awt.dnd.*;
26 import java.awt.event.*;
27 import java.lang.reflect.Constructor;
31 import javax.swing.event.MenuEvent;
32 import javax.swing.event.MenuListener;
41 extends jalview.jbgui.GDesktop implements DropTargetListener,
42 ClipboardOwner, IProgressIndicator
45 public static Desktop instance;
47 //Need to decide if the Memory Usage is to be included in
48 //Next release or not.
49 public static MyDesktopPane desktop;
50 // public static JDesktopPane desktop;
53 static int openFrameCount = 0;
54 static final int xOffset = 30;
55 static final int yOffset = 30;
56 public static jalview.ws.Discoverer discoverer;
58 public static Object[] jalviewClipboard;
59 public static boolean internalCopy = false;
61 static int fileLoadingCount = 0;
64 * Creates a new Desktop object.
69 * A note to implementors. It is ESSENTIAL that any
70 * activities that might block are spawned off as threads rather
71 * than waited for during this constructor.
74 doVamsasClientCheck();
78 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
79 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
80 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",false);
81 desktop = new MyDesktopPane(selmemusage);
82 showMemusage.setSelected(selmemusage);
83 desktop.setBackground(Color.white);
84 getContentPane().setLayout(new BorderLayout());
85 getContentPane().add(desktop, BorderLayout.CENTER);
86 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
88 // This line prevents Windows Look&Feel resizing all new windows to maximum
89 // if previous window was maximised
90 desktop.setDesktopManager(new DefaultDesktopManager());
92 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
93 String x = jalview.bin.Cache.getProperty("SCREEN_X");
94 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
95 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
96 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
98 if ( (x != null) && (y != null) && (width != null) && (height != null))
100 setBounds(Integer.parseInt(x), Integer.parseInt(y),
101 Integer.parseInt(width), Integer.parseInt(height));
105 setBounds( (int) (screenSize.width - 900) / 2,
106 (int) (screenSize.height - 650) / 2, 900, 650);
109 this.addWindowListener(new WindowAdapter()
111 public void windowClosing(WindowEvent evt)
117 this.addMouseListener(new MouseAdapter()
119 public void mousePressed(MouseEvent evt)
121 if(SwingUtilities.isRightMouseButton(evt))
123 showPasteMenu(evt.getX(), evt.getY());
129 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
130 // Spawn a thread that shows the splashscreen
135 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
138 private void doVamsasClientCheck()
140 if (jalview.bin.Cache.vamsasJarsPresent())
142 setupVamsasDisconnectedGui();
143 VamsasMenu.setVisible(true);
144 final Desktop us = this;
145 VamsasMenu.addMenuListener(new MenuListener() {
146 // this listener remembers when the menu was first selected, and
147 // doesn't rebuild the session list until it has been cleared and
149 boolean refresh=true;
150 public void menuCanceled(MenuEvent e)
155 public void menuDeselected(MenuEvent e)
160 public void menuSelected(MenuEvent e)
164 us.buildVamsasStMenu();
169 vamsasStart.setVisible(true);
173 void showPasteMenu(int x, int y)
175 JPopupMenu popup = new JPopupMenu();
176 JMenuItem item = new JMenuItem("Paste To New Window");
177 item.addActionListener(new ActionListener()
179 public void actionPerformed(ActionEvent evt)
186 popup.show(this, x, y);
193 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
194 Transferable contents = c.getContents(this);
196 if (contents != null)
198 String file = (String) contents
199 .getTransferData(DataFlavor.stringFlavor);
201 String format = new IdentifyFile().Identify(file,
202 FormatAdapter.PASTE);
204 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
210 System.out.println("Unable to paste alignment from system clipboard:\n"
218 * @param frame DOCUMENT ME!
219 * @param title DOCUMENT ME!
220 * @param w DOCUMENT ME!
221 * @param h DOCUMENT ME!
223 public static synchronized void addInternalFrame(final JInternalFrame frame,
224 String title, int w, int h)
226 addInternalFrame(frame, title, w, h, true);
232 * @param frame DOCUMENT ME!
233 * @param title DOCUMENT ME!
234 * @param w DOCUMENT ME!
235 * @param h DOCUMENT ME!
236 * @param resizable DOCUMENT ME!
238 public static synchronized void addInternalFrame(final JInternalFrame frame,
239 String title, int w, int h, boolean resizable)
242 // TODO: consider fixing method to update entries in the window submenu with the current window title
244 frame.setTitle(title);
245 if (frame.getWidth() < 1 || frame.getHeight() < 1)
249 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
250 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
251 // IF JALVIEW IS RUNNING HEADLESS
252 /////////////////////////////////////////////////
253 if (System.getProperty("java.awt.headless") != null
254 && System.getProperty("java.awt.headless").equals("true"))
261 frame.setVisible(true);
262 frame.setClosable(true);
263 frame.setResizable(resizable);
264 frame.setMaximizable(resizable);
265 frame.setIconifiable(resizable);
266 frame.setFrameIcon(null);
268 if (frame.getX() < 1 && frame.getY() < 1)
270 frame.setLocation(xOffset * openFrameCount,
271 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
274 final JMenuItem menuItem = new JMenuItem(title);
275 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
277 public void internalFrameActivated(javax.swing.event.
278 InternalFrameEvent evt)
280 JInternalFrame itf = desktop.getSelectedFrame();
288 public void internalFrameClosed(
289 javax.swing.event.InternalFrameEvent evt)
291 PaintRefresher.RemoveComponent(frame);
293 windowMenu.remove(menuItem);
294 JInternalFrame itf = desktop.getSelectedFrame();
304 menuItem.addActionListener(new ActionListener()
306 public void actionPerformed(ActionEvent e)
310 frame.setSelected(true);
311 frame.setIcon(false);
313 catch (java.beans.PropertyVetoException ex)
320 windowMenu.add(menuItem);
326 frame.setSelected(true);
327 frame.requestFocus();
329 catch (java.beans.PropertyVetoException ve)
333 public void lostOwnership(Clipboard clipboard, Transferable contents)
337 Desktop.jalviewClipboard = null;
340 internalCopy = false;
343 public void dragEnter(DropTargetDragEvent evt)
346 public void dragExit(DropTargetEvent evt)
349 public void dragOver(DropTargetDragEvent evt)
352 public void dropActionChanged(DropTargetDragEvent evt)
358 * @param evt DOCUMENT ME!
360 public void drop(DropTargetDropEvent evt)
362 Transferable t = evt.getTransferable();
363 java.util.List files = null;
367 DataFlavor uriListFlavor = new DataFlavor(
368 "text/uri-list;class=java.lang.String");
369 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
371 //Works on Windows and MacOSX
372 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
373 files = (java.util.List) t.getTransferData(DataFlavor.
376 else if (t.isDataFlavorSupported(uriListFlavor))
378 // This is used by Unix drag system
379 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
380 String data = (String) t.getTransferData(uriListFlavor);
381 files = new java.util.ArrayList(1);
382 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
385 st.hasMoreTokens(); )
387 String s = st.nextToken();
388 if (s.startsWith("#"))
390 // the line is a comment (as per the RFC 2483)
394 java.net.URI uri = new java.net.URI(s);
395 java.io.File file = new java.io.File(uri);
407 for (int i = 0; i < files.size(); i++)
409 String file = files.get(i).toString();
410 String protocol = FormatAdapter.FILE;
411 String format = null;
413 if (file.endsWith(".jar"))
420 format = new IdentifyFile().Identify(file,
424 new FileLoader().LoadFile(file, protocol, format);
436 * @param e DOCUMENT ME!
438 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
440 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
443 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
444 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
445 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
447 chooser.setFileView(new JalviewFileView());
448 chooser.setDialogTitle("Open local file");
449 chooser.setToolTipText("Open");
451 int value = chooser.showOpenDialog(this);
453 if (value == JalviewFileChooser.APPROVE_OPTION)
455 String choice = chooser.getSelectedFile().getPath();
456 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
457 chooser.getSelectedFile().getParent());
459 String format = null;
460 if (chooser.getSelectedFormat().equals("Jalview"))
466 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
469 if (viewport != null)
471 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
475 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
483 * @param e DOCUMENT ME!
485 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
487 // This construct allows us to have a wider textfield
489 JLabel label = new JLabel("Enter URL of Input File");
490 final JComboBox history = new JComboBox();
492 JPanel panel = new JPanel(new GridLayout(2, 1));
495 history.setPreferredSize(new Dimension(400, 20));
496 history.setEditable(true);
497 history.addItem("http://www.");
499 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
503 if (historyItems != null)
505 st = new StringTokenizer(historyItems, "\t");
507 while (st.hasMoreTokens())
509 history.addItem(st.nextElement());
513 int reply = JOptionPane.showInternalConfirmDialog(desktop,
514 panel, "Input Alignment From URL",
515 JOptionPane.OK_CANCEL_OPTION);
517 if (reply != JOptionPane.OK_OPTION)
522 String url = history.getSelectedItem().toString();
524 if (url.toLowerCase().endsWith(".jar"))
526 if (viewport != null)
528 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
532 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
537 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
539 if (format.equals("URL NOT FOUND"))
541 JOptionPane.showInternalMessageDialog(Desktop.desktop,
542 "Couldn't locate " + url,
544 JOptionPane.WARNING_MESSAGE);
549 if (viewport != null)
551 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
555 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
563 * @param e DOCUMENT ME!
565 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
567 CutAndPasteTransfer cap = new CutAndPasteTransfer();
568 cap.setForInput(viewport);
569 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
577 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
578 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
579 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
580 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
587 * @param e DOCUMENT ME!
589 public void aboutMenuItem_actionPerformed(ActionEvent e)
591 StringBuffer message = new StringBuffer("Jalview version " +
592 jalview.bin.Cache.getProperty(
596 Cache.getDefault("BUILD_DATE",
599 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
600 jalview.bin.Cache.getProperty("VERSION")))
602 message.append("\n\n!! Jalview version "
603 + jalview.bin.Cache.getProperty("LATEST_VERSION")
605 " is available for download from http://www.jalview.org !!\n");
609 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
610 "\nDevelopment managed by The Barton Group, University of Dundee.\n"+
611 "\nFor specific issues relating to Jalview, email help@jalview.org\n"+
612 " or join the jalview-discuss@jalview.org mailing list" +
613 "\n\nIf you use Jalview, please cite:" +
614 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
615 "\nBioinformatics, 2004 20;426-7.");
617 JOptionPane.showInternalMessageDialog(Desktop.desktop,
619 message.toString(), "About Jalview",
620 JOptionPane.INFORMATION_MESSAGE);
626 * @param e DOCUMENT ME!
628 public void documentationMenuItem_actionPerformed(ActionEvent e)
632 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
633 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
634 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
636 javax.help.HelpBroker hb = hs.createHelpBroker();
637 hb.setCurrentID("home");
638 hb.setDisplayed(true);
644 public void closeAll_actionPerformed(ActionEvent e)
646 JInternalFrame[] frames = desktop.getAllFrames();
647 for (int i = 0; i < frames.length; i++)
651 frames[i].setClosed(true);
653 catch (java.beans.PropertyVetoException ex)
656 System.out.println("ALL CLOSED");
660 public void raiseRelated_actionPerformed(ActionEvent e)
662 reorderAssociatedWindows(false, false);
665 public void minimizeAssociated_actionPerformed(ActionEvent e)
667 reorderAssociatedWindows(true, false);
670 void closeAssociatedWindows()
672 reorderAssociatedWindows(false, true);
676 * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
678 protected void garbageCollect_actionPerformed(ActionEvent e)
680 // We simply collect the garbage
681 jalview.bin.Cache.log.debug("Collecting garbage...");
683 jalview.bin.Cache.log.debug("Finished garbage collection.");
687 * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
689 protected void showMemusage_actionPerformed(ActionEvent e)
691 desktop.showMemoryUsage(showMemusage.isSelected());
694 void reorderAssociatedWindows(boolean minimize, boolean close)
696 JInternalFrame[] frames = desktop.getAllFrames();
697 if (frames == null || frames.length < 1)
702 AlignViewport source = null, target = null;
703 if (frames[0] instanceof AlignFrame)
705 source = ( (AlignFrame) frames[0]).getCurrentView();
707 else if (frames[0] instanceof TreePanel)
709 source = ( (TreePanel) frames[0]).getViewPort();
711 else if (frames[0] instanceof PCAPanel)
713 source = ( (PCAPanel) frames[0]).av;
715 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
717 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
722 for (int i = 0; i < frames.length; i++)
725 if (frames[i] == null)
729 if (frames[i] instanceof AlignFrame)
731 target = ( (AlignFrame) frames[i]).getCurrentView();
733 else if (frames[i] instanceof TreePanel)
735 target = ( (TreePanel) frames[i]).getViewPort();
737 else if (frames[i] instanceof PCAPanel)
739 target = ( (PCAPanel) frames[i]).av;
741 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
743 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
746 if (source == target)
752 frames[i].setClosed(true);
756 frames[i].setIcon(minimize);
764 catch (java.beans.PropertyVetoException ex)
773 * @param e DOCUMENT ME!
775 protected void preferences_actionPerformed(ActionEvent e)
783 * @param e DOCUMENT ME!
785 public void saveState_actionPerformed(ActionEvent e)
787 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
789 "LAST_DIRECTORY"), new String[]
792 {"Jalview Project"}, "Jalview Project");
794 chooser.setFileView(new JalviewFileView());
795 chooser.setDialogTitle("Save State");
797 int value = chooser.showSaveDialog(this);
799 if (value == JalviewFileChooser.APPROVE_OPTION)
801 java.io.File choice = chooser.getSelectedFile();
802 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
803 new Jalview2XML().SaveState(choice);
810 * @param e DOCUMENT ME!
812 public void loadState_actionPerformed(ActionEvent e)
814 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
816 "LAST_DIRECTORY"), new String[]
819 {"Jalview Project"}, "Jalview Project");
820 chooser.setFileView(new JalviewFileView());
821 chooser.setDialogTitle("Restore state");
823 int value = chooser.showOpenDialog(this);
825 if (value == JalviewFileChooser.APPROVE_OPTION)
827 String choice = chooser.getSelectedFile().getAbsolutePath();
828 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
829 chooser.getSelectedFile().getParent());
830 new Jalview2XML().LoadJalviewAlign(choice);
834 public void inputSequence_actionPerformed(ActionEvent e)
836 new SequenceFetcher(this);
839 JPanel progressPanel;
841 public void startLoading(final String fileName)
843 if (fileLoadingCount == 0)
845 addProgressPanel("Loading File: " + fileName + " ");
850 private JProgressBar addProgressPanel(String string)
852 if (progressPanel==null)
854 progressPanel = new JPanel(new BorderLayout());
855 totalProgressCount=0;
857 JProgressBar progressBar = new JProgressBar();
858 progressBar.setIndeterminate(true);
860 progressPanel.add(new JLabel(string),
863 progressPanel.add(progressBar, BorderLayout.CENTER);
865 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
866 totalProgressCount++;
870 int totalProgressCount=0;
871 private void removeProgressPanel(JProgressBar progbar)
873 if (progressPanel!=null)
875 progressPanel.remove(progbar);
876 if (--totalProgressCount<1)
878 this.getContentPane().remove(progressPanel);
879 progressPanel = null;
884 public void stopLoading()
887 if (fileLoadingCount < 1)
889 if (progressPanel != null)
891 this.getContentPane().remove(progressPanel);
892 progressPanel = null;
894 fileLoadingCount = 0;
898 public static int getViewCount(String viewId)
901 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
902 for (int t = 0; t < frames.length; t++)
904 if (frames[t] instanceof AlignFrame)
906 AlignFrame af = (AlignFrame) frames[t];
907 for (int a = 0; a < af.alignPanels.size(); a++)
910 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
923 public void explodeViews(AlignFrame af)
925 int size = af.alignPanels.size();
931 for (int i = 0; i < size; i++)
933 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
934 AlignFrame newaf = new AlignFrame(ap);
935 if (ap.av.explodedPosition != null &&
936 !ap.av.explodedPosition.equals(af.getBounds()))
938 newaf.setBounds(ap.av.explodedPosition);
941 ap.av.gatherViewsHere = false;
943 addInternalFrame(newaf, af.getTitle(),
944 AlignFrame.DEFAULT_WIDTH,
945 AlignFrame.DEFAULT_HEIGHT);
948 af.alignPanels.clear();
949 af.closeMenuItem_actionPerformed(true);
953 public void gatherViews(AlignFrame source)
955 source.viewport.gatherViewsHere = true;
956 source.viewport.explodedPosition = source.getBounds();
957 JInternalFrame[] frames = desktop.getAllFrames();
958 String viewId = source.viewport.sequenceSetID;
960 for (int t = 0; t < frames.length; t++)
962 if (frames[t] instanceof AlignFrame && frames[t] != source)
964 AlignFrame af = (AlignFrame) frames[t];
965 boolean gatherThis = false;
966 for (int a = 0; a < af.alignPanels.size(); a++)
968 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
969 if (viewId.equals(ap.av.getSequenceSetId()))
972 ap.av.gatherViewsHere = false;
973 ap.av.explodedPosition = af.getBounds();
974 source.addAlignmentPanel(ap, false);
980 af.alignPanels.clear();
981 af.closeMenuItem_actionPerformed(true);
988 jalview.gui.VamsasApplication v_client = null;
989 public void vamsasImport_actionPerformed(ActionEvent e)
993 // Load and try to start a session.
994 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
995 getProperty("LAST_DIRECTORY"));
997 chooser.setFileView(new JalviewFileView());
998 chooser.setDialogTitle("Open a saved VAMSAS session");
999 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
1001 int value = chooser.showOpenDialog(this);
1003 if (value == JalviewFileChooser.APPROVE_OPTION)
1006 v_client = new jalview.gui.VamsasApplication(this,
1007 chooser.getSelectedFile());
1008 } catch (Exception ex)
1010 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
1013 setupVamsasConnectedGui();
1014 v_client.initial_update(); // TODO: thread ?
1017 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
1021 public void vamsasStart_actionPerformed(ActionEvent e)
1023 if (v_client == null)
1026 // we just start a default session for moment.
1028 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1029 getProperty("LAST_DIRECTORY"));
1031 chooser.setFileView(new JalviewFileView());
1032 chooser.setDialogTitle("Load Vamsas file");
1033 chooser.setToolTipText("Import");
1035 int value = chooser.showOpenDialog(this);
1037 if (value == JalviewFileChooser.APPROVE_OPTION)
1039 v_client = new jalview.gui.VamsasApplication(this,
1040 chooser.getSelectedFile());
1043 v_client = new VamsasApplication(this);
1044 setupVamsasConnectedGui();
1045 v_client.initial_update(); // TODO: thread ?
1049 // store current data in session.
1050 v_client.push_update(); // TODO: thread
1054 protected void setupVamsasConnectedGui()
1056 vamsasStart.setText("Session Update");
1057 vamsasSave.setVisible(true);
1058 vamsasStop.setVisible(true);
1059 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1061 protected void setupVamsasDisconnectedGui()
1063 vamsasSave.setVisible(false);
1064 vamsasStop.setVisible(false);
1065 vamsasImport.setVisible(true);
1066 vamsasStart.setText("New Vamsas Session");
1069 public void vamsasStop_actionPerformed(ActionEvent e)
1071 if (v_client != null)
1073 v_client.end_session();
1075 setupVamsasDisconnectedGui();
1078 protected void buildVamsasStMenu()
1080 if (v_client == null)
1082 String[] sess = null;
1085 sess = VamsasApplication.getSessionList();
1086 } catch (Exception e)
1088 jalview.bin.Cache.log.warn(
1089 "Problem getting current sessions list.", e);
1094 jalview.bin.Cache.log.debug("Got current sessions list: "
1095 + sess.length + " entries.");
1096 VamsasStMenu.removeAll();
1097 for (int i = 0; i < sess.length; i++)
1099 JMenuItem sessit = new JMenuItem();
1100 sessit.setText(sess[i]);
1101 sessit.setToolTipText("Connect to session " + sess[i]);
1102 final Desktop dsktp = this;
1103 final String mysesid = sess[i];
1104 sessit.addActionListener(new ActionListener()
1107 public void actionPerformed(ActionEvent e)
1109 if (dsktp.v_client == null)
1111 Thread rthr = new Thread(new Runnable() {
1115 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1116 dsktp.setupVamsasConnectedGui();
1117 dsktp.v_client.initial_update();
1125 VamsasStMenu.add(sessit);
1127 // don't show an empty menu.
1128 VamsasStMenu.setVisible(sess.length>0);
1133 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1134 VamsasStMenu.removeAll();
1135 VamsasStMenu.setVisible(false);
1138 // Not interested in the content. Just hide ourselves.
1139 VamsasStMenu.setVisible(false);
1142 public void vamsasSave_actionPerformed(ActionEvent e)
1144 if (v_client != null)
1146 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1148 "LAST_DIRECTORY"), new String[]
1149 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1151 {"Vamsas Document"}, "Vamsas Document");
1153 chooser.setFileView(new JalviewFileView());
1154 chooser.setDialogTitle("Save Vamsas Document Archive");
1156 int value = chooser.showSaveDialog(this);
1158 if (value == JalviewFileChooser.APPROVE_OPTION)
1160 java.io.File choice = chooser.getSelectedFile();
1161 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1162 String warnmsg=null;
1163 String warnttl=null;
1165 v_client.vclient.storeDocument(choice);
1169 warnttl = "Serious Problem saving Vamsas Document";
1170 warnmsg = ex.toString();
1171 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1174 catch (Exception ex)
1176 warnttl = "Problem saving Vamsas Document.";
1177 warnmsg = ex.toString();
1178 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1183 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1186 JOptionPane.ERROR_MESSAGE);
1191 JProgressBar vamUpdate = null;
1193 * hide vamsas user gui bits when a vamsas document event is being handled.
1194 * @param b true to hide gui, false to reveal gui
1196 public void setVamsasUpdate(boolean b)
1198 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1199 (b ? "in progress" : "finished"));
1201 if (vamUpdate!=null)
1203 this.removeProgressPanel(vamUpdate);
1207 vamUpdate = this.addProgressPanel("Updating vamsas session");
1209 vamsasStart.setVisible(!b);
1210 vamsasStop.setVisible(!b);
1211 vamsasSave.setVisible(!b);
1214 public JInternalFrame[] getAllFrames()
1216 return desktop.getAllFrames();
1221 * Checks the given url to see if it gives a response indicating that
1222 * the user should be informed of a new questionnaire.
1225 public void checkForQuestionnaire(String url)
1227 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1228 //javax.swing.SwingUtilities.invokeLater(jvq);
1229 new Thread(jvq).start();
1232 * Proxy class for JDesktopPane which optionally
1233 * displays the current memory usage and highlights
1234 * the desktop area with a red bar if free memory runs low.
1237 public class MyDesktopPane extends JDesktopPane implements Runnable
1240 boolean showMemoryUsage = false;
1242 java.text.NumberFormat df;
1244 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1246 public MyDesktopPane(boolean showMemoryUsage)
1248 showMemoryUsage(showMemoryUsage);
1251 public void showMemoryUsage(boolean showMemoryUsage)
1253 this.showMemoryUsage = showMemoryUsage;
1254 if (showMemoryUsage)
1256 Thread worker = new Thread(this);
1260 public boolean isShowMemoryUsage()
1262 return showMemoryUsage;
1266 df = java.text.NumberFormat.getNumberInstance();
1267 df.setMaximumFractionDigits(2);
1268 runtime = Runtime.getRuntime();
1270 while (showMemoryUsage)
1275 maxMemory = runtime.maxMemory() / 1048576f;
1276 allocatedMemory = runtime.totalMemory() / 1048576f;
1277 freeMemory = runtime.freeMemory() / 1048576f;
1278 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1280 percentUsage = (totalFreeMemory / maxMemory) * 100;
1282 // if (percentUsage < 20)
1284 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1285 // instance.set.setBorder(border1);
1290 catch (Exception ex)
1292 ex.printStackTrace();
1297 public void paintComponent(Graphics g)
1301 if (percentUsage < 20)
1302 g.setColor(Color.red);
1304 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1305 + "MB; Max Memory: " + df.format(maxMemory)
1306 + "MB; " + df.format(percentUsage) + "%", 10,
1307 getHeight() - g.getFontMetrics().getHeight());
1314 protected JMenuItem groovyShell;
1315 public void doGroovyCheck() {
1316 if (jalview.bin.Cache.groovyJarsPresent())
1318 groovyShell = new JMenuItem();
1319 groovyShell.setText("Groovy Console...");
1320 groovyShell.addActionListener(new ActionListener()
1322 public void actionPerformed(ActionEvent e) {
1323 groovyShell_actionPerformed(e);
1326 toolsMenu.add(groovyShell);
1327 groovyShell.setVisible(true);
1331 * Accessor method to quickly get all the AlignmentFrames
1334 public static AlignFrame[] getAlignframes() {
1335 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1341 Vector avp=new Vector();
1345 for (int i = frames.length - 1; i > -1; i--)
1347 if (frames[i] instanceof AlignFrame)
1349 AlignFrame af = (AlignFrame) frames[i];
1354 catch (Exception ex)
1356 ex.printStackTrace();
1362 AlignFrame afs[] = new AlignFrame[avp.size()];
1363 for (int i=0,j=avp.size(); i<j; i++) {
1364 afs[i] = (AlignFrame) avp.elementAt(i);
1371 * Add Groovy Support to Jalview
1373 public void groovyShell_actionPerformed(ActionEvent e) {
1374 // use reflection to avoid creating compilation dependency.
1375 if (!jalview.bin.Cache.groovyJarsPresent())
1377 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1380 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1381 Constructor gccons = gcClass.getConstructor(null);
1382 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1383 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1384 Object gc = gccons.newInstance(null);
1385 setvar.invoke(gc, new Object[] { "Jalview", this});
1386 run.invoke(gc, null);
1388 catch (Exception ex)
1390 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1391 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1393 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1394 JOptionPane.ERROR_MESSAGE);
1399 * Progress bars managed by the IProgressIndicator method.
1401 private Hashtable progressBars;
1403 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1405 public void setProgressBar(String message, long id)
1407 if(progressBars == null)
1409 progressBars = new Hashtable();
1412 if(progressBars.get( new Long(id) )!=null)
1414 JProgressBar progressPanel = (JProgressBar)progressBars.remove( new Long(id) );
1415 removeProgressPanel(progressPanel);
1417 progressBars.put(new Long(id), addProgressPanel(message));