2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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");
608 // TODO: update this text for each release or centrally store it for lite and application
609 message.append("\nAuthors: Andrew Waterhouse, Jim Procter, Michele Clamp, James Cuff, Steve Searle,\n David Martin & Geoff Barton." +
610 "\nDevelopment managed by The Barton Group, University of Dundee, Scotland, UK.\n"+
611 "\nFor help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list\n"+
612 "\nIf you use Jalview, please cite:" +
613 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
614 "\nBioinformatics, 2004 20;426-7.");
616 JOptionPane.showInternalMessageDialog(Desktop.desktop,
618 message.toString(), "About Jalview",
619 JOptionPane.INFORMATION_MESSAGE);
625 * @param e DOCUMENT ME!
627 public void documentationMenuItem_actionPerformed(ActionEvent e)
631 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
632 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
633 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
635 javax.help.HelpBroker hb = hs.createHelpBroker();
636 hb.setCurrentID("home");
637 hb.setDisplayed(true);
643 public void closeAll_actionPerformed(ActionEvent e)
645 JInternalFrame[] frames = desktop.getAllFrames();
646 for (int i = 0; i < frames.length; i++)
650 frames[i].setClosed(true);
652 catch (java.beans.PropertyVetoException ex)
655 System.out.println("ALL CLOSED");
659 public void raiseRelated_actionPerformed(ActionEvent e)
661 reorderAssociatedWindows(false, false);
664 public void minimizeAssociated_actionPerformed(ActionEvent e)
666 reorderAssociatedWindows(true, false);
669 void closeAssociatedWindows()
671 reorderAssociatedWindows(false, true);
675 * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
677 protected void garbageCollect_actionPerformed(ActionEvent e)
679 // We simply collect the garbage
680 jalview.bin.Cache.log.debug("Collecting garbage...");
682 jalview.bin.Cache.log.debug("Finished garbage collection.");
686 * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
688 protected void showMemusage_actionPerformed(ActionEvent e)
690 desktop.showMemoryUsage(showMemusage.isSelected());
693 void reorderAssociatedWindows(boolean minimize, boolean close)
695 JInternalFrame[] frames = desktop.getAllFrames();
696 if (frames == null || frames.length < 1)
701 AlignViewport source = null, target = null;
702 if (frames[0] instanceof AlignFrame)
704 source = ( (AlignFrame) frames[0]).getCurrentView();
706 else if (frames[0] instanceof TreePanel)
708 source = ( (TreePanel) frames[0]).getViewPort();
710 else if (frames[0] instanceof PCAPanel)
712 source = ( (PCAPanel) frames[0]).av;
714 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
716 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
721 for (int i = 0; i < frames.length; i++)
724 if (frames[i] == null)
728 if (frames[i] instanceof AlignFrame)
730 target = ( (AlignFrame) frames[i]).getCurrentView();
732 else if (frames[i] instanceof TreePanel)
734 target = ( (TreePanel) frames[i]).getViewPort();
736 else if (frames[i] instanceof PCAPanel)
738 target = ( (PCAPanel) frames[i]).av;
740 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
742 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
745 if (source == target)
751 frames[i].setClosed(true);
755 frames[i].setIcon(minimize);
763 catch (java.beans.PropertyVetoException ex)
772 * @param e DOCUMENT ME!
774 protected void preferences_actionPerformed(ActionEvent e)
782 * @param e DOCUMENT ME!
784 public void saveState_actionPerformed(ActionEvent e)
786 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
788 "LAST_DIRECTORY"), new String[]
791 {"Jalview Project"}, "Jalview Project");
793 chooser.setFileView(new JalviewFileView());
794 chooser.setDialogTitle("Save State");
796 int value = chooser.showSaveDialog(this);
798 if (value == JalviewFileChooser.APPROVE_OPTION)
800 java.io.File choice = chooser.getSelectedFile();
801 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
802 new Jalview2XML().SaveState(choice);
809 * @param e DOCUMENT ME!
811 public void loadState_actionPerformed(ActionEvent e)
813 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
815 "LAST_DIRECTORY"), new String[]
818 {"Jalview Project"}, "Jalview Project");
819 chooser.setFileView(new JalviewFileView());
820 chooser.setDialogTitle("Restore state");
822 int value = chooser.showOpenDialog(this);
824 if (value == JalviewFileChooser.APPROVE_OPTION)
826 String choice = chooser.getSelectedFile().getAbsolutePath();
827 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
828 chooser.getSelectedFile().getParent());
829 new Jalview2XML().LoadJalviewAlign(choice);
833 public void inputSequence_actionPerformed(ActionEvent e)
835 new SequenceFetcher(this);
838 JPanel progressPanel;
840 public void startLoading(final String fileName)
842 if (fileLoadingCount == 0)
844 addProgressPanel("Loading File: " + fileName + " ");
849 private JProgressBar addProgressPanel(String string)
851 if (progressPanel==null)
853 progressPanel = new JPanel(new BorderLayout());
854 totalProgressCount=0;
856 JProgressBar progressBar = new JProgressBar();
857 progressBar.setIndeterminate(true);
859 progressPanel.add(new JLabel(string),
862 progressPanel.add(progressBar, BorderLayout.CENTER);
864 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
865 totalProgressCount++;
869 int totalProgressCount=0;
870 private void removeProgressPanel(JProgressBar progbar)
872 if (progressPanel!=null)
874 progressPanel.remove(progbar);
875 if (--totalProgressCount<1)
877 this.getContentPane().remove(progressPanel);
878 progressPanel = null;
883 public void stopLoading()
886 if (fileLoadingCount < 1)
888 if (progressPanel != null)
890 this.getContentPane().remove(progressPanel);
891 progressPanel = null;
893 fileLoadingCount = 0;
897 public static int getViewCount(String viewId)
900 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
901 for (int t = 0; t < frames.length; t++)
903 if (frames[t] instanceof AlignFrame)
905 AlignFrame af = (AlignFrame) frames[t];
906 for (int a = 0; a < af.alignPanels.size(); a++)
909 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
922 public void explodeViews(AlignFrame af)
924 int size = af.alignPanels.size();
930 for (int i = 0; i < size; i++)
932 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
933 AlignFrame newaf = new AlignFrame(ap);
934 if (ap.av.explodedPosition != null &&
935 !ap.av.explodedPosition.equals(af.getBounds()))
937 newaf.setBounds(ap.av.explodedPosition);
940 ap.av.gatherViewsHere = false;
942 addInternalFrame(newaf, af.getTitle(),
943 AlignFrame.DEFAULT_WIDTH,
944 AlignFrame.DEFAULT_HEIGHT);
947 af.alignPanels.clear();
948 af.closeMenuItem_actionPerformed(true);
952 public void gatherViews(AlignFrame source)
954 source.viewport.gatherViewsHere = true;
955 source.viewport.explodedPosition = source.getBounds();
956 JInternalFrame[] frames = desktop.getAllFrames();
957 String viewId = source.viewport.sequenceSetID;
959 for (int t = 0; t < frames.length; t++)
961 if (frames[t] instanceof AlignFrame && frames[t] != source)
963 AlignFrame af = (AlignFrame) frames[t];
964 boolean gatherThis = false;
965 for (int a = 0; a < af.alignPanels.size(); a++)
967 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
968 if (viewId.equals(ap.av.getSequenceSetId()))
971 ap.av.gatherViewsHere = false;
972 ap.av.explodedPosition = af.getBounds();
973 source.addAlignmentPanel(ap, false);
979 af.alignPanels.clear();
980 af.closeMenuItem_actionPerformed(true);
987 jalview.gui.VamsasApplication v_client = null;
988 public void vamsasImport_actionPerformed(ActionEvent e)
992 // Load and try to start a session.
993 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
994 getProperty("LAST_DIRECTORY"));
996 chooser.setFileView(new JalviewFileView());
997 chooser.setDialogTitle("Open a saved VAMSAS session");
998 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
1000 int value = chooser.showOpenDialog(this);
1002 if (value == JalviewFileChooser.APPROVE_OPTION)
1005 v_client = new jalview.gui.VamsasApplication(this,
1006 chooser.getSelectedFile());
1007 } catch (Exception ex)
1009 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
1012 setupVamsasConnectedGui();
1013 v_client.initial_update(); // TODO: thread ?
1016 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
1020 public void vamsasStart_actionPerformed(ActionEvent e)
1022 if (v_client == null)
1025 // we just start a default session for moment.
1027 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1028 getProperty("LAST_DIRECTORY"));
1030 chooser.setFileView(new JalviewFileView());
1031 chooser.setDialogTitle("Load Vamsas file");
1032 chooser.setToolTipText("Import");
1034 int value = chooser.showOpenDialog(this);
1036 if (value == JalviewFileChooser.APPROVE_OPTION)
1038 v_client = new jalview.gui.VamsasApplication(this,
1039 chooser.getSelectedFile());
1042 v_client = new VamsasApplication(this);
1043 setupVamsasConnectedGui();
1044 v_client.initial_update(); // TODO: thread ?
1048 // store current data in session.
1049 v_client.push_update(); // TODO: thread
1053 protected void setupVamsasConnectedGui()
1055 vamsasStart.setText("Session Update");
1056 vamsasSave.setVisible(true);
1057 vamsasStop.setVisible(true);
1058 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1060 protected void setupVamsasDisconnectedGui()
1062 vamsasSave.setVisible(false);
1063 vamsasStop.setVisible(false);
1064 vamsasImport.setVisible(true);
1065 vamsasStart.setText("New Vamsas Session");
1068 public void vamsasStop_actionPerformed(ActionEvent e)
1070 if (v_client != null)
1072 v_client.end_session();
1074 setupVamsasDisconnectedGui();
1077 protected void buildVamsasStMenu()
1079 if (v_client == null)
1081 String[] sess = null;
1084 sess = VamsasApplication.getSessionList();
1085 } catch (Exception e)
1087 jalview.bin.Cache.log.warn(
1088 "Problem getting current sessions list.", e);
1093 jalview.bin.Cache.log.debug("Got current sessions list: "
1094 + sess.length + " entries.");
1095 VamsasStMenu.removeAll();
1096 for (int i = 0; i < sess.length; i++)
1098 JMenuItem sessit = new JMenuItem();
1099 sessit.setText(sess[i]);
1100 sessit.setToolTipText("Connect to session " + sess[i]);
1101 final Desktop dsktp = this;
1102 final String mysesid = sess[i];
1103 sessit.addActionListener(new ActionListener()
1106 public void actionPerformed(ActionEvent e)
1108 if (dsktp.v_client == null)
1110 Thread rthr = new Thread(new Runnable() {
1114 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1115 dsktp.setupVamsasConnectedGui();
1116 dsktp.v_client.initial_update();
1124 VamsasStMenu.add(sessit);
1126 // don't show an empty menu.
1127 VamsasStMenu.setVisible(sess.length>0);
1132 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1133 VamsasStMenu.removeAll();
1134 VamsasStMenu.setVisible(false);
1137 // Not interested in the content. Just hide ourselves.
1138 VamsasStMenu.setVisible(false);
1141 public void vamsasSave_actionPerformed(ActionEvent e)
1143 if (v_client != null)
1145 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1147 "LAST_DIRECTORY"), new String[]
1148 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1150 {"Vamsas Document"}, "Vamsas Document");
1152 chooser.setFileView(new JalviewFileView());
1153 chooser.setDialogTitle("Save Vamsas Document Archive");
1155 int value = chooser.showSaveDialog(this);
1157 if (value == JalviewFileChooser.APPROVE_OPTION)
1159 java.io.File choice = chooser.getSelectedFile();
1160 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1161 String warnmsg=null;
1162 String warnttl=null;
1164 v_client.vclient.storeDocument(choice);
1168 warnttl = "Serious Problem saving Vamsas Document";
1169 warnmsg = ex.toString();
1170 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1173 catch (Exception ex)
1175 warnttl = "Problem saving Vamsas Document.";
1176 warnmsg = ex.toString();
1177 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1182 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1185 JOptionPane.ERROR_MESSAGE);
1190 JProgressBar vamUpdate = null;
1192 * hide vamsas user gui bits when a vamsas document event is being handled.
1193 * @param b true to hide gui, false to reveal gui
1195 public void setVamsasUpdate(boolean b)
1197 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1198 (b ? "in progress" : "finished"));
1200 if (vamUpdate!=null)
1202 this.removeProgressPanel(vamUpdate);
1206 vamUpdate = this.addProgressPanel("Updating vamsas session");
1208 vamsasStart.setVisible(!b);
1209 vamsasStop.setVisible(!b);
1210 vamsasSave.setVisible(!b);
1213 public JInternalFrame[] getAllFrames()
1215 return desktop.getAllFrames();
1220 * Checks the given url to see if it gives a response indicating that
1221 * the user should be informed of a new questionnaire.
1224 public void checkForQuestionnaire(String url)
1226 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1227 //javax.swing.SwingUtilities.invokeLater(jvq);
1228 new Thread(jvq).start();
1231 * Proxy class for JDesktopPane which optionally
1232 * displays the current memory usage and highlights
1233 * the desktop area with a red bar if free memory runs low.
1236 public class MyDesktopPane extends JDesktopPane implements Runnable
1239 boolean showMemoryUsage = false;
1241 java.text.NumberFormat df;
1243 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1245 public MyDesktopPane(boolean showMemoryUsage)
1247 showMemoryUsage(showMemoryUsage);
1250 public void showMemoryUsage(boolean showMemoryUsage)
1252 this.showMemoryUsage = showMemoryUsage;
1253 if (showMemoryUsage)
1255 Thread worker = new Thread(this);
1259 public boolean isShowMemoryUsage()
1261 return showMemoryUsage;
1265 df = java.text.NumberFormat.getNumberInstance();
1266 df.setMaximumFractionDigits(2);
1267 runtime = Runtime.getRuntime();
1269 while (showMemoryUsage)
1274 maxMemory = runtime.maxMemory() / 1048576f;
1275 allocatedMemory = runtime.totalMemory() / 1048576f;
1276 freeMemory = runtime.freeMemory() / 1048576f;
1277 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1279 percentUsage = (totalFreeMemory / maxMemory) * 100;
1281 // if (percentUsage < 20)
1283 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1284 // instance.set.setBorder(border1);
1289 catch (Exception ex)
1291 ex.printStackTrace();
1296 public void paintComponent(Graphics g)
1300 if (percentUsage < 20)
1301 g.setColor(Color.red);
1303 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1304 + "MB; Max Memory: " + df.format(maxMemory)
1305 + "MB; " + df.format(percentUsage) + "%", 10,
1306 getHeight() - g.getFontMetrics().getHeight());
1313 protected JMenuItem groovyShell;
1314 public void doGroovyCheck() {
1315 if (jalview.bin.Cache.groovyJarsPresent())
1317 groovyShell = new JMenuItem();
1318 groovyShell.setText("Groovy Console...");
1319 groovyShell.addActionListener(new ActionListener()
1321 public void actionPerformed(ActionEvent e) {
1322 groovyShell_actionPerformed(e);
1325 toolsMenu.add(groovyShell);
1326 groovyShell.setVisible(true);
1330 * Accessor method to quickly get all the AlignmentFrames
1333 public static AlignFrame[] getAlignframes() {
1334 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1340 Vector avp=new Vector();
1344 for (int i = frames.length - 1; i > -1; i--)
1346 if (frames[i] instanceof AlignFrame)
1348 AlignFrame af = (AlignFrame) frames[i];
1353 catch (Exception ex)
1355 ex.printStackTrace();
1361 AlignFrame afs[] = new AlignFrame[avp.size()];
1362 for (int i=0,j=avp.size(); i<j; i++) {
1363 afs[i] = (AlignFrame) avp.elementAt(i);
1370 * Add Groovy Support to Jalview
1372 public void groovyShell_actionPerformed(ActionEvent e) {
1373 // use reflection to avoid creating compilation dependency.
1374 if (!jalview.bin.Cache.groovyJarsPresent())
1376 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1379 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1380 Constructor gccons = gcClass.getConstructor(null);
1381 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1382 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1383 Object gc = gccons.newInstance(null);
1384 setvar.invoke(gc, new Object[] { "Jalview", this});
1385 run.invoke(gc, null);
1387 catch (Exception ex)
1389 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1390 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1392 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1393 JOptionPane.ERROR_MESSAGE);
1398 * Progress bars managed by the IProgressIndicator method.
1400 private Hashtable progressBars;
1402 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1404 public void setProgressBar(String message, long id)
1406 if(progressBars == null)
1408 progressBars = new Hashtable();
1411 if(progressBars.get( new Long(id) )!=null)
1413 JProgressBar progressPanel = (JProgressBar)progressBars.remove( new Long(id) );
1414 removeProgressPanel(progressPanel);
1416 progressBars.put(new Long(id), addProgressPanel(message));