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
23 import java.awt.datatransfer.*;
24 import java.awt.dnd.*;
25 import java.awt.event.*;
26 import java.lang.reflect.Constructor;
30 import javax.swing.event.MenuEvent;
31 import javax.swing.event.MenuListener;
40 extends jalview.jbgui.GDesktop implements DropTargetListener,
44 public static Desktop instance;
46 //Need to decide if the Memory Usage is to be included in
47 //Next release or not.
48 public static MyDesktopPane desktop;
49 // public static JDesktopPane desktop;
52 static int openFrameCount = 0;
53 static final int xOffset = 30;
54 static final int yOffset = 30;
55 public static jalview.ws.Discoverer discoverer;
57 public static Object[] jalviewClipboard;
58 public static boolean internalCopy = false;
60 static int fileLoadingCount = 0;
63 * Creates a new Desktop object.
68 doVamsasClientCheck();
72 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
73 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
74 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",false);
75 desktop = new MyDesktopPane(selmemusage);
76 showMemusage.setSelected(selmemusage);
77 desktop.setBackground(Color.white);
78 getContentPane().setLayout(new BorderLayout());
79 getContentPane().add(desktop, BorderLayout.CENTER);
80 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
82 // This line prevents Windows Look&Feel resizing all new windows to maximum
83 // if previous window was maximised
84 desktop.setDesktopManager(new DefaultDesktopManager());
86 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
87 String x = jalview.bin.Cache.getProperty("SCREEN_X");
88 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
89 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
90 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
92 if ( (x != null) && (y != null) && (width != null) && (height != null))
94 setBounds(Integer.parseInt(x), Integer.parseInt(y),
95 Integer.parseInt(width), Integer.parseInt(height));
99 setBounds( (int) (screenSize.width - 900) / 2,
100 (int) (screenSize.height - 650) / 2, 900, 650);
103 this.addWindowListener(new WindowAdapter()
105 public void windowClosing(WindowEvent evt)
111 this.addMouseListener(new MouseAdapter()
113 public void mousePressed(MouseEvent evt)
115 if(SwingUtilities.isRightMouseButton(evt))
117 showPasteMenu(evt.getX(), evt.getY());
123 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
125 /////////Add a splashscreen on startup
126 /////////Add a splashscreen on startup
130 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
133 private void doVamsasClientCheck()
135 if (jalview.bin.Cache.vamsasJarsPresent())
137 setupVamsasDisconnectedGui();
138 VamsasMenu.setVisible(true);
139 final Desktop us = this;
140 VamsasMenu.addMenuListener(new MenuListener() {
141 // this listener remembers when the menu was first selected, and
142 // doesn't rebuild the session list until it has been cleared and
144 boolean refresh=true;
145 public void menuCanceled(MenuEvent e)
150 public void menuDeselected(MenuEvent e)
155 public void menuSelected(MenuEvent e)
159 us.buildVamsasStMenu();
164 vamsasStart.setVisible(true);
168 void showPasteMenu(int x, int y)
170 JPopupMenu popup = new JPopupMenu();
171 JMenuItem item = new JMenuItem("Paste To New Window");
172 item.addActionListener(new ActionListener()
174 public void actionPerformed(ActionEvent evt)
181 popup.show(this, x, y);
188 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
189 Transferable contents = c.getContents(this);
191 if (contents != null)
193 String file = (String) contents
194 .getTransferData(DataFlavor.stringFlavor);
196 String format = new IdentifyFile().Identify(file,
197 FormatAdapter.PASTE);
199 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
205 System.out.println("Unable to paste alignment from system clipboard:\n"
213 * @param frame DOCUMENT ME!
214 * @param title DOCUMENT ME!
215 * @param w DOCUMENT ME!
216 * @param h DOCUMENT ME!
218 public static synchronized void addInternalFrame(final JInternalFrame frame,
219 String title, int w, int h)
221 addInternalFrame(frame, title, w, h, true);
227 * @param frame DOCUMENT ME!
228 * @param title DOCUMENT ME!
229 * @param w DOCUMENT ME!
230 * @param h DOCUMENT ME!
231 * @param resizable DOCUMENT ME!
233 public static synchronized void addInternalFrame(final JInternalFrame frame,
234 String title, int w, int h, boolean resizable)
237 frame.setTitle(title);
238 if (frame.getWidth() < 1 || frame.getHeight() < 1)
242 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
243 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
244 // IF JALVIEW IS RUNNING HEADLESS
245 /////////////////////////////////////////////////
246 if (System.getProperty("java.awt.headless") != null
247 && System.getProperty("java.awt.headless").equals("true"))
254 frame.setVisible(true);
255 frame.setClosable(true);
256 frame.setResizable(resizable);
257 frame.setMaximizable(resizable);
258 frame.setIconifiable(resizable);
259 frame.setFrameIcon(null);
261 if (frame.getX() < 1 && frame.getY() < 1)
263 frame.setLocation(xOffset * openFrameCount,
264 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
267 final JMenuItem menuItem = new JMenuItem(title);
268 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
270 public void internalFrameActivated(javax.swing.event.
271 InternalFrameEvent evt)
273 JInternalFrame itf = desktop.getSelectedFrame();
281 public void internalFrameClosed(
282 javax.swing.event.InternalFrameEvent evt)
284 PaintRefresher.RemoveComponent(frame);
286 windowMenu.remove(menuItem);
287 JInternalFrame itf = desktop.getSelectedFrame();
297 menuItem.addActionListener(new ActionListener()
299 public void actionPerformed(ActionEvent e)
303 frame.setSelected(true);
304 frame.setIcon(false);
306 catch (java.beans.PropertyVetoException ex)
313 windowMenu.add(menuItem);
319 frame.setSelected(true);
320 frame.requestFocus();
322 catch (java.beans.PropertyVetoException ve)
326 public void lostOwnership(Clipboard clipboard, Transferable contents)
330 Desktop.jalviewClipboard = null;
333 internalCopy = false;
336 public void dragEnter(DropTargetDragEvent evt)
339 public void dragExit(DropTargetEvent evt)
342 public void dragOver(DropTargetDragEvent evt)
345 public void dropActionChanged(DropTargetDragEvent evt)
351 * @param evt DOCUMENT ME!
353 public void drop(DropTargetDropEvent evt)
355 Transferable t = evt.getTransferable();
356 java.util.List files = null;
360 DataFlavor uriListFlavor = new DataFlavor(
361 "text/uri-list;class=java.lang.String");
362 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
364 //Works on Windows and MacOSX
365 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
366 files = (java.util.List) t.getTransferData(DataFlavor.
369 else if (t.isDataFlavorSupported(uriListFlavor))
371 // This is used by Unix drag system
372 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
373 String data = (String) t.getTransferData(uriListFlavor);
374 files = new java.util.ArrayList(1);
375 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
378 st.hasMoreTokens(); )
380 String s = st.nextToken();
381 if (s.startsWith("#"))
383 // the line is a comment (as per the RFC 2483)
387 java.net.URI uri = new java.net.URI(s);
388 java.io.File file = new java.io.File(uri);
400 for (int i = 0; i < files.size(); i++)
402 String file = files.get(i).toString();
403 String protocol = FormatAdapter.FILE;
404 String format = null;
406 if (file.endsWith(".jar"))
413 format = new IdentifyFile().Identify(file,
417 new FileLoader().LoadFile(file, protocol, format);
429 * @param e DOCUMENT ME!
431 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
433 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
436 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
437 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
438 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
440 chooser.setFileView(new JalviewFileView());
441 chooser.setDialogTitle("Open local file");
442 chooser.setToolTipText("Open");
444 int value = chooser.showOpenDialog(this);
446 if (value == JalviewFileChooser.APPROVE_OPTION)
448 String choice = chooser.getSelectedFile().getPath();
449 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
450 chooser.getSelectedFile().getParent());
452 String format = null;
453 if (chooser.getSelectedFormat().equals("Jalview"))
459 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
462 if (viewport != null)
464 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
468 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
476 * @param e DOCUMENT ME!
478 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
480 // This construct allows us to have a wider textfield
482 JLabel label = new JLabel("Enter URL of Input File");
483 final JComboBox history = new JComboBox();
485 JPanel panel = new JPanel(new GridLayout(2, 1));
488 history.setPreferredSize(new Dimension(400, 20));
489 history.setEditable(true);
490 history.addItem("http://www.");
492 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
496 if (historyItems != null)
498 st = new StringTokenizer(historyItems, "\t");
500 while (st.hasMoreTokens())
502 history.addItem(st.nextElement());
506 int reply = JOptionPane.showInternalConfirmDialog(desktop,
507 panel, "Input Alignment From URL",
508 JOptionPane.OK_CANCEL_OPTION);
510 if (reply != JOptionPane.OK_OPTION)
515 String url = history.getSelectedItem().toString();
517 if (url.toLowerCase().endsWith(".jar"))
519 if (viewport != null)
521 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
525 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
530 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
532 if (format.equals("URL NOT FOUND"))
534 JOptionPane.showInternalMessageDialog(Desktop.desktop,
535 "Couldn't locate " + url,
537 JOptionPane.WARNING_MESSAGE);
542 if (viewport != null)
544 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
548 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
556 * @param e DOCUMENT ME!
558 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
560 CutAndPasteTransfer cap = new CutAndPasteTransfer();
561 cap.setForInput(viewport);
562 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
570 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
571 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
572 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
573 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
580 * @param e DOCUMENT ME!
582 public void aboutMenuItem_actionPerformed(ActionEvent e)
584 StringBuffer message = new StringBuffer("JalView version " +
585 jalview.bin.Cache.getProperty(
589 Cache.getDefault("BUILD_DATE",
592 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
593 jalview.bin.Cache.getProperty("VERSION")))
595 message.append("\n\n!! Jalview version "
596 + jalview.bin.Cache.getProperty("LATEST_VERSION")
598 " is available for download from http://www.jalview.org !!\n");
602 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
603 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
604 "\nFor all issues relating to Jalview, email help@jalview.org" +
605 "\n\nIf you use JalView, please cite:" +
606 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
607 "\nBioinformatics, 2004 20;426-7.");
609 JOptionPane.showInternalMessageDialog(Desktop.desktop,
611 message.toString(), "About Jalview",
612 JOptionPane.INFORMATION_MESSAGE);
618 * @param e DOCUMENT ME!
620 public void documentationMenuItem_actionPerformed(ActionEvent e)
624 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
625 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
626 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
628 javax.help.HelpBroker hb = hs.createHelpBroker();
629 hb.setCurrentID("home");
630 hb.setDisplayed(true);
636 public void closeAll_actionPerformed(ActionEvent e)
638 JInternalFrame[] frames = desktop.getAllFrames();
639 for (int i = 0; i < frames.length; i++)
643 frames[i].setClosed(true);
645 catch (java.beans.PropertyVetoException ex)
648 System.out.println("ALL CLOSED");
652 public void raiseRelated_actionPerformed(ActionEvent e)
654 reorderAssociatedWindows(false, false);
657 public void minimizeAssociated_actionPerformed(ActionEvent e)
659 reorderAssociatedWindows(true, false);
662 void closeAssociatedWindows()
664 reorderAssociatedWindows(false, true);
668 * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
670 protected void garbageCollect_actionPerformed(ActionEvent e)
672 // We simply collect the garbage
673 jalview.bin.Cache.log.debug("Collecting garbage...");
675 jalview.bin.Cache.log.debug("Finished garbage collection.");
679 * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
681 protected void showMemusage_actionPerformed(ActionEvent e)
683 desktop.showMemoryUsage(showMemusage.isSelected());
686 void reorderAssociatedWindows(boolean minimize, boolean close)
688 JInternalFrame[] frames = desktop.getAllFrames();
689 if (frames == null || frames.length < 1)
694 AlignViewport source = null, target = null;
695 if (frames[0] instanceof AlignFrame)
697 source = ( (AlignFrame) frames[0]).getCurrentView();
699 else if (frames[0] instanceof TreePanel)
701 source = ( (TreePanel) frames[0]).getViewPort();
703 else if (frames[0] instanceof PCAPanel)
705 source = ( (PCAPanel) frames[0]).av;
707 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
709 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
714 for (int i = 0; i < frames.length; i++)
717 if (frames[i] == null)
721 if (frames[i] instanceof AlignFrame)
723 target = ( (AlignFrame) frames[i]).getCurrentView();
725 else if (frames[i] instanceof TreePanel)
727 target = ( (TreePanel) frames[i]).getViewPort();
729 else if (frames[i] instanceof PCAPanel)
731 target = ( (PCAPanel) frames[i]).av;
733 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
735 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
738 if (source == target)
744 frames[i].setClosed(true);
748 frames[i].setIcon(minimize);
756 catch (java.beans.PropertyVetoException ex)
765 * @param e DOCUMENT ME!
767 protected void preferences_actionPerformed(ActionEvent e)
775 * @param e DOCUMENT ME!
777 public void saveState_actionPerformed(ActionEvent e)
779 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
781 "LAST_DIRECTORY"), new String[]
784 {"Jalview Project"}, "Jalview Project");
786 chooser.setFileView(new JalviewFileView());
787 chooser.setDialogTitle("Save State");
789 int value = chooser.showSaveDialog(this);
791 if (value == JalviewFileChooser.APPROVE_OPTION)
793 java.io.File choice = chooser.getSelectedFile();
794 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
795 new Jalview2XML().SaveState(choice);
802 * @param e DOCUMENT ME!
804 public void loadState_actionPerformed(ActionEvent e)
806 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
808 "LAST_DIRECTORY"), new String[]
811 {"Jalview Project"}, "Jalview Project");
812 chooser.setFileView(new JalviewFileView());
813 chooser.setDialogTitle("Restore state");
815 int value = chooser.showOpenDialog(this);
817 if (value == JalviewFileChooser.APPROVE_OPTION)
819 String choice = chooser.getSelectedFile().getAbsolutePath();
820 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
821 chooser.getSelectedFile().getParent());
822 new Jalview2XML().LoadJalviewAlign(choice);
826 public void inputSequence_actionPerformed(ActionEvent e)
828 new SequenceFetcher(null);
831 JPanel progressPanel;
833 public void startLoading(final String fileName)
835 if (fileLoadingCount == 0)
837 addProgressPanel("Loading File: " + fileName + " ");
842 private JProgressBar addProgressPanel(String string)
844 if (progressPanel==null)
846 progressPanel = new JPanel(new BorderLayout());
847 totalProgressCount=0;
849 JProgressBar progressBar = new JProgressBar();
850 progressBar.setIndeterminate(true);
852 progressPanel.add(new JLabel(string),
855 progressPanel.add(progressBar, BorderLayout.CENTER);
857 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
858 totalProgressCount++;
862 int totalProgressCount=0;
863 private void removeProgressPanel(JProgressBar progbar)
865 if (progressPanel!=null)
867 progressPanel.remove(progbar);
868 if (--totalProgressCount<1)
870 this.getContentPane().remove(progressPanel);
871 progressPanel = null;
876 public void stopLoading()
879 if (fileLoadingCount < 1)
881 if (progressPanel != null)
883 this.getContentPane().remove(progressPanel);
884 progressPanel = null;
886 fileLoadingCount = 0;
890 public static int getViewCount(String viewId)
893 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
894 for (int t = 0; t < frames.length; t++)
896 if (frames[t] instanceof AlignFrame)
898 AlignFrame af = (AlignFrame) frames[t];
899 for (int a = 0; a < af.alignPanels.size(); a++)
902 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
915 public void explodeViews(AlignFrame af)
917 int size = af.alignPanels.size();
923 for (int i = 0; i < size; i++)
925 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
926 AlignFrame newaf = new AlignFrame(ap);
927 if (ap.av.explodedPosition != null &&
928 !ap.av.explodedPosition.equals(af.getBounds()))
930 newaf.setBounds(ap.av.explodedPosition);
933 ap.av.gatherViewsHere = false;
935 addInternalFrame(newaf, af.getTitle(),
936 AlignFrame.DEFAULT_WIDTH,
937 AlignFrame.DEFAULT_HEIGHT);
940 af.alignPanels.clear();
941 af.closeMenuItem_actionPerformed(true);
945 public void gatherViews(AlignFrame source)
947 source.viewport.gatherViewsHere = true;
948 source.viewport.explodedPosition = source.getBounds();
949 JInternalFrame[] frames = desktop.getAllFrames();
950 String viewId = source.viewport.sequenceSetID;
952 for (int t = 0; t < frames.length; t++)
954 if (frames[t] instanceof AlignFrame && frames[t] != source)
956 AlignFrame af = (AlignFrame) frames[t];
957 boolean gatherThis = false;
958 for (int a = 0; a < af.alignPanels.size(); a++)
960 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
961 if (viewId.equals(ap.av.getSequenceSetId()))
964 ap.av.gatherViewsHere = false;
965 ap.av.explodedPosition = af.getBounds();
966 source.addAlignmentPanel(ap, false);
972 af.alignPanels.clear();
973 af.closeMenuItem_actionPerformed(true);
980 jalview.gui.VamsasApplication v_client = null;
981 public void vamsasImport_actionPerformed(ActionEvent e)
985 // Load and try to start a session.
986 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
987 getProperty("LAST_DIRECTORY"));
989 chooser.setFileView(new JalviewFileView());
990 chooser.setDialogTitle("Open a saved VAMSAS session");
991 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
993 int value = chooser.showOpenDialog(this);
995 if (value == JalviewFileChooser.APPROVE_OPTION)
998 v_client = new jalview.gui.VamsasApplication(this,
999 chooser.getSelectedFile());
1000 } catch (Exception ex)
1002 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
1005 setupVamsasConnectedGui();
1006 v_client.initial_update(); // TODO: thread ?
1009 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
1013 public void vamsasStart_actionPerformed(ActionEvent e)
1015 if (v_client == null)
1018 // we just start a default session for moment.
1020 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1021 getProperty("LAST_DIRECTORY"));
1023 chooser.setFileView(new JalviewFileView());
1024 chooser.setDialogTitle("Load Vamsas file");
1025 chooser.setToolTipText("Import");
1027 int value = chooser.showOpenDialog(this);
1029 if (value == JalviewFileChooser.APPROVE_OPTION)
1031 v_client = new jalview.gui.VamsasApplication(this,
1032 chooser.getSelectedFile());
1035 v_client = new VamsasApplication(this);
1036 setupVamsasConnectedGui();
1037 v_client.initial_update(); // TODO: thread ?
1041 // store current data in session.
1042 v_client.push_update(); // TODO: thread
1046 protected void setupVamsasConnectedGui()
1048 vamsasStart.setText("Session Update");
1049 vamsasSave.setVisible(true);
1050 vamsasStop.setVisible(true);
1051 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1053 protected void setupVamsasDisconnectedGui()
1055 vamsasSave.setVisible(false);
1056 vamsasStop.setVisible(false);
1057 vamsasImport.setVisible(true);
1058 vamsasStart.setText("New Vamsas Session...");
1061 public void vamsasStop_actionPerformed(ActionEvent e)
1063 if (v_client != null)
1065 v_client.end_session();
1067 setupVamsasDisconnectedGui();
1070 protected void buildVamsasStMenu()
1072 if (v_client == null)
1074 String[] sess = null;
1077 sess = VamsasApplication.getSessionList();
1078 } catch (Exception e)
1080 jalview.bin.Cache.log.warn(
1081 "Problem getting current sessions list.", e);
1086 jalview.bin.Cache.log.debug("Got current sessions list: "
1087 + sess.length + " entries.");
1088 VamsasStMenu.removeAll();
1089 for (int i = 0; i < sess.length; i++)
1091 JMenuItem sessit = new JMenuItem();
1092 sessit.setText(sess[i]);
1093 sessit.setToolTipText("Connect to session " + sess[i]);
1094 final Desktop dsktp = this;
1095 final String mysesid = sess[i];
1096 sessit.addActionListener(new ActionListener()
1099 public void actionPerformed(ActionEvent e)
1101 if (dsktp.v_client == null)
1103 Thread rthr = new Thread(new Runnable() {
1107 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1108 dsktp.setupVamsasConnectedGui();
1109 dsktp.v_client.initial_update();
1117 VamsasStMenu.add(sessit);
1119 // don't show an empty menu.
1120 VamsasStMenu.setVisible(sess.length>0);
1125 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1126 VamsasStMenu.removeAll();
1127 VamsasStMenu.setVisible(false);
1130 // Not interested in the content. Just hide ourselves.
1131 VamsasStMenu.setVisible(false);
1134 public void vamsasSave_actionPerformed(ActionEvent e)
1136 if (v_client != null)
1138 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1140 "LAST_DIRECTORY"), new String[]
1141 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1143 {"Vamsas Document"}, "Vamsas Document");
1145 chooser.setFileView(new JalviewFileView());
1146 chooser.setDialogTitle("Save Vamsas Document Archive");
1148 int value = chooser.showSaveDialog(this);
1150 if (value == JalviewFileChooser.APPROVE_OPTION)
1152 java.io.File choice = chooser.getSelectedFile();
1153 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1154 String warnmsg=null;
1155 String warnttl=null;
1157 v_client.vclient.storeDocument(choice);
1161 warnttl = "Serious Problem saving Vamsas Document";
1162 warnmsg = ex.toString();
1163 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1166 catch (Exception ex)
1168 warnttl = "Problem saving Vamsas Document.";
1169 warnmsg = ex.toString();
1170 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1175 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1178 JOptionPane.ERROR_MESSAGE);
1183 JProgressBar vamUpdate = null;
1185 * hide vamsas user gui bits when a vamsas document event is being handled.
1186 * @param b true to hide gui, false to reveal gui
1188 public void setVamsasUpdate(boolean b)
1190 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1191 (b ? "in progress" : "finished"));
1193 if (vamUpdate!=null)
1195 this.removeProgressPanel(vamUpdate);
1199 vamUpdate = this.addProgressPanel("Updating vamsas session");
1201 vamsasStart.setVisible(!b);
1202 vamsasStop.setVisible(!b);
1203 vamsasSave.setVisible(!b);
1206 public JInternalFrame[] getAllFrames()
1208 return desktop.getAllFrames();
1213 * Checks the given url to see if it gives a response indicating that
1214 * the user should be informed of a new questionnaire.
1217 public void checkForQuestionnaire(String url)
1219 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1220 javax.swing.SwingUtilities.invokeLater(jvq);
1223 * Proxy class for JDesktopPane which optionally
1224 * displays the current memory usage and highlights
1225 * the desktop area with a red bar if free memory runs low.
1228 public class MyDesktopPane extends JDesktopPane implements Runnable
1231 boolean showMemoryUsage = false;
1233 java.text.NumberFormat df;
1235 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1237 public MyDesktopPane(boolean showMemoryUsage)
1239 showMemoryUsage(showMemoryUsage);
1242 public void showMemoryUsage(boolean showMemoryUsage)
1244 this.showMemoryUsage = showMemoryUsage;
1245 if (showMemoryUsage)
1247 Thread worker = new Thread(this);
1251 public boolean isShowMemoryUsage()
1253 return showMemoryUsage;
1257 df = java.text.NumberFormat.getNumberInstance();
1258 df.setMaximumFractionDigits(2);
1259 runtime = Runtime.getRuntime();
1261 while (showMemoryUsage)
1266 maxMemory = runtime.maxMemory() / 1048576f;
1267 allocatedMemory = runtime.totalMemory() / 1048576f;
1268 freeMemory = runtime.freeMemory() / 1048576f;
1269 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1271 percentUsage = (totalFreeMemory / maxMemory) * 100;
1273 // if (percentUsage < 20)
1275 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1276 // instance.set.setBorder(border1);
1281 catch (Exception ex)
1283 ex.printStackTrace();
1288 public void paintComponent(Graphics g)
1292 if (percentUsage < 20)
1293 g.setColor(Color.red);
1295 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1296 + "MB; Max Memory: " + df.format(maxMemory)
1297 + "MB; " + df.format(percentUsage) + "%", 10,
1298 getHeight() - g.getFontMetrics().getHeight());
1305 protected JMenuItem groovyShell;
1306 public void doGroovyCheck() {
1307 if (jalview.bin.Cache.groovyJarsPresent())
1309 groovyShell = new JMenuItem();
1310 groovyShell.setText("Groovy Console...");
1311 groovyShell.addActionListener(new ActionListener()
1313 public void actionPerformed(ActionEvent e) {
1314 groovyShell_actionPerformed(e);
1317 toolsMenu.add(groovyShell);
1318 groovyShell.setVisible(true);
1322 * Accessor method to quickly get all the AlignmentFrames
1325 public static AlignFrame[] getAlignframes() {
1326 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1332 Vector avp=new Vector();
1336 for (int i = frames.length - 1; i > -1; i--)
1338 if (frames[i] instanceof AlignFrame)
1340 AlignFrame af = (AlignFrame) frames[i];
1345 catch (Exception ex)
1347 ex.printStackTrace();
1353 AlignFrame afs[] = new AlignFrame[avp.size()];
1354 for (int i=0,j=avp.size(); i<j; i++) {
1355 afs[i] = (AlignFrame) avp.elementAt(i);
1362 * Add Groovy Support to Jalview
1364 public void groovyShell_actionPerformed(ActionEvent e) {
1365 // use reflection to avoid creating compilation dependency.
1366 if (!jalview.bin.Cache.groovyJarsPresent())
1368 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1371 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1372 Constructor gccons = gcClass.getConstructor(null);
1373 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1374 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1375 Object gc = gccons.newInstance(null);
1376 setvar.invoke(gc, new Object[] { "Jalview", this});
1377 run.invoke(gc, null);
1379 catch (Exception ex)
1381 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1382 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1384 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1385 JOptionPane.ERROR_MESSAGE);