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 frame.setTitle(title);
243 if (frame.getWidth() < 1 || frame.getHeight() < 1)
247 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
248 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
249 // IF JALVIEW IS RUNNING HEADLESS
250 /////////////////////////////////////////////////
251 if (System.getProperty("java.awt.headless") != null
252 && System.getProperty("java.awt.headless").equals("true"))
259 frame.setVisible(true);
260 frame.setClosable(true);
261 frame.setResizable(resizable);
262 frame.setMaximizable(resizable);
263 frame.setIconifiable(resizable);
264 frame.setFrameIcon(null);
266 if (frame.getX() < 1 && frame.getY() < 1)
268 frame.setLocation(xOffset * openFrameCount,
269 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
272 final JMenuItem menuItem = new JMenuItem(title);
273 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
275 public void internalFrameActivated(javax.swing.event.
276 InternalFrameEvent evt)
278 JInternalFrame itf = desktop.getSelectedFrame();
286 public void internalFrameClosed(
287 javax.swing.event.InternalFrameEvent evt)
289 PaintRefresher.RemoveComponent(frame);
291 windowMenu.remove(menuItem);
292 JInternalFrame itf = desktop.getSelectedFrame();
302 menuItem.addActionListener(new ActionListener()
304 public void actionPerformed(ActionEvent e)
308 frame.setSelected(true);
309 frame.setIcon(false);
311 catch (java.beans.PropertyVetoException ex)
318 windowMenu.add(menuItem);
324 frame.setSelected(true);
325 frame.requestFocus();
327 catch (java.beans.PropertyVetoException ve)
331 public void lostOwnership(Clipboard clipboard, Transferable contents)
335 Desktop.jalviewClipboard = null;
338 internalCopy = false;
341 public void dragEnter(DropTargetDragEvent evt)
344 public void dragExit(DropTargetEvent evt)
347 public void dragOver(DropTargetDragEvent evt)
350 public void dropActionChanged(DropTargetDragEvent evt)
356 * @param evt DOCUMENT ME!
358 public void drop(DropTargetDropEvent evt)
360 Transferable t = evt.getTransferable();
361 java.util.List files = null;
365 DataFlavor uriListFlavor = new DataFlavor(
366 "text/uri-list;class=java.lang.String");
367 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
369 //Works on Windows and MacOSX
370 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
371 files = (java.util.List) t.getTransferData(DataFlavor.
374 else if (t.isDataFlavorSupported(uriListFlavor))
376 // This is used by Unix drag system
377 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
378 String data = (String) t.getTransferData(uriListFlavor);
379 files = new java.util.ArrayList(1);
380 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
383 st.hasMoreTokens(); )
385 String s = st.nextToken();
386 if (s.startsWith("#"))
388 // the line is a comment (as per the RFC 2483)
392 java.net.URI uri = new java.net.URI(s);
393 java.io.File file = new java.io.File(uri);
405 for (int i = 0; i < files.size(); i++)
407 String file = files.get(i).toString();
408 String protocol = FormatAdapter.FILE;
409 String format = null;
411 if (file.endsWith(".jar"))
418 format = new IdentifyFile().Identify(file,
422 new FileLoader().LoadFile(file, protocol, format);
434 * @param e DOCUMENT ME!
436 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
438 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
441 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
442 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
443 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
445 chooser.setFileView(new JalviewFileView());
446 chooser.setDialogTitle("Open local file");
447 chooser.setToolTipText("Open");
449 int value = chooser.showOpenDialog(this);
451 if (value == JalviewFileChooser.APPROVE_OPTION)
453 String choice = chooser.getSelectedFile().getPath();
454 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
455 chooser.getSelectedFile().getParent());
457 String format = null;
458 if (chooser.getSelectedFormat().equals("Jalview"))
464 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
467 if (viewport != null)
469 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
473 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
481 * @param e DOCUMENT ME!
483 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
485 // This construct allows us to have a wider textfield
487 JLabel label = new JLabel("Enter URL of Input File");
488 final JComboBox history = new JComboBox();
490 JPanel panel = new JPanel(new GridLayout(2, 1));
493 history.setPreferredSize(new Dimension(400, 20));
494 history.setEditable(true);
495 history.addItem("http://www.");
497 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
501 if (historyItems != null)
503 st = new StringTokenizer(historyItems, "\t");
505 while (st.hasMoreTokens())
507 history.addItem(st.nextElement());
511 int reply = JOptionPane.showInternalConfirmDialog(desktop,
512 panel, "Input Alignment From URL",
513 JOptionPane.OK_CANCEL_OPTION);
515 if (reply != JOptionPane.OK_OPTION)
520 String url = history.getSelectedItem().toString();
522 if (url.toLowerCase().endsWith(".jar"))
524 if (viewport != null)
526 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
530 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
535 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
537 if (format.equals("URL NOT FOUND"))
539 JOptionPane.showInternalMessageDialog(Desktop.desktop,
540 "Couldn't locate " + url,
542 JOptionPane.WARNING_MESSAGE);
547 if (viewport != null)
549 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
553 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
561 * @param e DOCUMENT ME!
563 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
565 CutAndPasteTransfer cap = new CutAndPasteTransfer();
566 cap.setForInput(viewport);
567 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
575 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
576 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
577 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
578 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
585 * @param e DOCUMENT ME!
587 public void aboutMenuItem_actionPerformed(ActionEvent e)
589 StringBuffer message = new StringBuffer("Jalview version " +
590 jalview.bin.Cache.getProperty(
594 Cache.getDefault("BUILD_DATE",
597 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
598 jalview.bin.Cache.getProperty("VERSION")))
600 message.append("\n\n!! Jalview version "
601 + jalview.bin.Cache.getProperty("LATEST_VERSION")
603 " is available for download from http://www.jalview.org !!\n");
607 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
608 "\nDevelopment managed by The Barton Group, University of Dundee.\n"+
609 "\nFor specific issues relating to Jalview, email help@jalview.org\n"+
610 " or join the jalview-discuss@jalview.org mailing list" +
611 "\n\nIf you use Jalview, please cite:" +
612 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
613 "\nBioinformatics, 2004 20;426-7.");
615 JOptionPane.showInternalMessageDialog(Desktop.desktop,
617 message.toString(), "About Jalview",
618 JOptionPane.INFORMATION_MESSAGE);
624 * @param e DOCUMENT ME!
626 public void documentationMenuItem_actionPerformed(ActionEvent e)
630 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
631 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
632 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
634 javax.help.HelpBroker hb = hs.createHelpBroker();
635 hb.setCurrentID("home");
636 hb.setDisplayed(true);
642 public void closeAll_actionPerformed(ActionEvent e)
644 JInternalFrame[] frames = desktop.getAllFrames();
645 for (int i = 0; i < frames.length; i++)
649 frames[i].setClosed(true);
651 catch (java.beans.PropertyVetoException ex)
654 System.out.println("ALL CLOSED");
658 public void raiseRelated_actionPerformed(ActionEvent e)
660 reorderAssociatedWindows(false, false);
663 public void minimizeAssociated_actionPerformed(ActionEvent e)
665 reorderAssociatedWindows(true, false);
668 void closeAssociatedWindows()
670 reorderAssociatedWindows(false, true);
674 * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
676 protected void garbageCollect_actionPerformed(ActionEvent e)
678 // We simply collect the garbage
679 jalview.bin.Cache.log.debug("Collecting garbage...");
681 jalview.bin.Cache.log.debug("Finished garbage collection.");
685 * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
687 protected void showMemusage_actionPerformed(ActionEvent e)
689 desktop.showMemoryUsage(showMemusage.isSelected());
692 void reorderAssociatedWindows(boolean minimize, boolean close)
694 JInternalFrame[] frames = desktop.getAllFrames();
695 if (frames == null || frames.length < 1)
700 AlignViewport source = null, target = null;
701 if (frames[0] instanceof AlignFrame)
703 source = ( (AlignFrame) frames[0]).getCurrentView();
705 else if (frames[0] instanceof TreePanel)
707 source = ( (TreePanel) frames[0]).getViewPort();
709 else if (frames[0] instanceof PCAPanel)
711 source = ( (PCAPanel) frames[0]).av;
713 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
715 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
720 for (int i = 0; i < frames.length; i++)
723 if (frames[i] == null)
727 if (frames[i] instanceof AlignFrame)
729 target = ( (AlignFrame) frames[i]).getCurrentView();
731 else if (frames[i] instanceof TreePanel)
733 target = ( (TreePanel) frames[i]).getViewPort();
735 else if (frames[i] instanceof PCAPanel)
737 target = ( (PCAPanel) frames[i]).av;
739 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
741 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
744 if (source == target)
750 frames[i].setClosed(true);
754 frames[i].setIcon(minimize);
762 catch (java.beans.PropertyVetoException ex)
771 * @param e DOCUMENT ME!
773 protected void preferences_actionPerformed(ActionEvent e)
781 * @param e DOCUMENT ME!
783 public void saveState_actionPerformed(ActionEvent e)
785 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
787 "LAST_DIRECTORY"), new String[]
790 {"Jalview Project"}, "Jalview Project");
792 chooser.setFileView(new JalviewFileView());
793 chooser.setDialogTitle("Save State");
795 int value = chooser.showSaveDialog(this);
797 if (value == JalviewFileChooser.APPROVE_OPTION)
799 java.io.File choice = chooser.getSelectedFile();
800 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
801 new Jalview2XML().SaveState(choice);
808 * @param e DOCUMENT ME!
810 public void loadState_actionPerformed(ActionEvent e)
812 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
814 "LAST_DIRECTORY"), new String[]
817 {"Jalview Project"}, "Jalview Project");
818 chooser.setFileView(new JalviewFileView());
819 chooser.setDialogTitle("Restore state");
821 int value = chooser.showOpenDialog(this);
823 if (value == JalviewFileChooser.APPROVE_OPTION)
825 String choice = chooser.getSelectedFile().getAbsolutePath();
826 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
827 chooser.getSelectedFile().getParent());
828 new Jalview2XML().LoadJalviewAlign(choice);
832 public void inputSequence_actionPerformed(ActionEvent e)
834 new SequenceFetcher(this);
837 JPanel progressPanel;
839 public void startLoading(final String fileName)
841 if (fileLoadingCount == 0)
843 addProgressPanel("Loading File: " + fileName + " ");
848 private JProgressBar addProgressPanel(String string)
850 if (progressPanel==null)
852 progressPanel = new JPanel(new BorderLayout());
853 totalProgressCount=0;
855 JProgressBar progressBar = new JProgressBar();
856 progressBar.setIndeterminate(true);
858 progressPanel.add(new JLabel(string),
861 progressPanel.add(progressBar, BorderLayout.CENTER);
863 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
864 totalProgressCount++;
868 int totalProgressCount=0;
869 private void removeProgressPanel(JProgressBar progbar)
871 if (progressPanel!=null)
873 progressPanel.remove(progbar);
874 if (--totalProgressCount<1)
876 this.getContentPane().remove(progressPanel);
877 progressPanel = null;
882 public void stopLoading()
885 if (fileLoadingCount < 1)
887 if (progressPanel != null)
889 this.getContentPane().remove(progressPanel);
890 progressPanel = null;
892 fileLoadingCount = 0;
896 public static int getViewCount(String viewId)
899 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
900 for (int t = 0; t < frames.length; t++)
902 if (frames[t] instanceof AlignFrame)
904 AlignFrame af = (AlignFrame) frames[t];
905 for (int a = 0; a < af.alignPanels.size(); a++)
908 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
921 public void explodeViews(AlignFrame af)
923 int size = af.alignPanels.size();
929 for (int i = 0; i < size; i++)
931 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
932 AlignFrame newaf = new AlignFrame(ap);
933 if (ap.av.explodedPosition != null &&
934 !ap.av.explodedPosition.equals(af.getBounds()))
936 newaf.setBounds(ap.av.explodedPosition);
939 ap.av.gatherViewsHere = false;
941 addInternalFrame(newaf, af.getTitle(),
942 AlignFrame.DEFAULT_WIDTH,
943 AlignFrame.DEFAULT_HEIGHT);
946 af.alignPanels.clear();
947 af.closeMenuItem_actionPerformed(true);
951 public void gatherViews(AlignFrame source)
953 source.viewport.gatherViewsHere = true;
954 source.viewport.explodedPosition = source.getBounds();
955 JInternalFrame[] frames = desktop.getAllFrames();
956 String viewId = source.viewport.sequenceSetID;
958 for (int t = 0; t < frames.length; t++)
960 if (frames[t] instanceof AlignFrame && frames[t] != source)
962 AlignFrame af = (AlignFrame) frames[t];
963 boolean gatherThis = false;
964 for (int a = 0; a < af.alignPanels.size(); a++)
966 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
967 if (viewId.equals(ap.av.getSequenceSetId()))
970 ap.av.gatherViewsHere = false;
971 ap.av.explodedPosition = af.getBounds();
972 source.addAlignmentPanel(ap, false);
978 af.alignPanels.clear();
979 af.closeMenuItem_actionPerformed(true);
986 jalview.gui.VamsasApplication v_client = null;
987 public void vamsasImport_actionPerformed(ActionEvent e)
991 // Load and try to start a session.
992 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
993 getProperty("LAST_DIRECTORY"));
995 chooser.setFileView(new JalviewFileView());
996 chooser.setDialogTitle("Open a saved VAMSAS session");
997 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
999 int value = chooser.showOpenDialog(this);
1001 if (value == JalviewFileChooser.APPROVE_OPTION)
1004 v_client = new jalview.gui.VamsasApplication(this,
1005 chooser.getSelectedFile());
1006 } catch (Exception ex)
1008 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
1011 setupVamsasConnectedGui();
1012 v_client.initial_update(); // TODO: thread ?
1015 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
1019 public void vamsasStart_actionPerformed(ActionEvent e)
1021 if (v_client == null)
1024 // we just start a default session for moment.
1026 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1027 getProperty("LAST_DIRECTORY"));
1029 chooser.setFileView(new JalviewFileView());
1030 chooser.setDialogTitle("Load Vamsas file");
1031 chooser.setToolTipText("Import");
1033 int value = chooser.showOpenDialog(this);
1035 if (value == JalviewFileChooser.APPROVE_OPTION)
1037 v_client = new jalview.gui.VamsasApplication(this,
1038 chooser.getSelectedFile());
1041 v_client = new VamsasApplication(this);
1042 setupVamsasConnectedGui();
1043 v_client.initial_update(); // TODO: thread ?
1047 // store current data in session.
1048 v_client.push_update(); // TODO: thread
1052 protected void setupVamsasConnectedGui()
1054 vamsasStart.setText("Session Update");
1055 vamsasSave.setVisible(true);
1056 vamsasStop.setVisible(true);
1057 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1059 protected void setupVamsasDisconnectedGui()
1061 vamsasSave.setVisible(false);
1062 vamsasStop.setVisible(false);
1063 vamsasImport.setVisible(true);
1064 vamsasStart.setText("New Vamsas Session");
1067 public void vamsasStop_actionPerformed(ActionEvent e)
1069 if (v_client != null)
1071 v_client.end_session();
1073 setupVamsasDisconnectedGui();
1076 protected void buildVamsasStMenu()
1078 if (v_client == null)
1080 String[] sess = null;
1083 sess = VamsasApplication.getSessionList();
1084 } catch (Exception e)
1086 jalview.bin.Cache.log.warn(
1087 "Problem getting current sessions list.", e);
1092 jalview.bin.Cache.log.debug("Got current sessions list: "
1093 + sess.length + " entries.");
1094 VamsasStMenu.removeAll();
1095 for (int i = 0; i < sess.length; i++)
1097 JMenuItem sessit = new JMenuItem();
1098 sessit.setText(sess[i]);
1099 sessit.setToolTipText("Connect to session " + sess[i]);
1100 final Desktop dsktp = this;
1101 final String mysesid = sess[i];
1102 sessit.addActionListener(new ActionListener()
1105 public void actionPerformed(ActionEvent e)
1107 if (dsktp.v_client == null)
1109 Thread rthr = new Thread(new Runnable() {
1113 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1114 dsktp.setupVamsasConnectedGui();
1115 dsktp.v_client.initial_update();
1123 VamsasStMenu.add(sessit);
1125 // don't show an empty menu.
1126 VamsasStMenu.setVisible(sess.length>0);
1131 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1132 VamsasStMenu.removeAll();
1133 VamsasStMenu.setVisible(false);
1136 // Not interested in the content. Just hide ourselves.
1137 VamsasStMenu.setVisible(false);
1140 public void vamsasSave_actionPerformed(ActionEvent e)
1142 if (v_client != null)
1144 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1146 "LAST_DIRECTORY"), new String[]
1147 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1149 {"Vamsas Document"}, "Vamsas Document");
1151 chooser.setFileView(new JalviewFileView());
1152 chooser.setDialogTitle("Save Vamsas Document Archive");
1154 int value = chooser.showSaveDialog(this);
1156 if (value == JalviewFileChooser.APPROVE_OPTION)
1158 java.io.File choice = chooser.getSelectedFile();
1159 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1160 String warnmsg=null;
1161 String warnttl=null;
1163 v_client.vclient.storeDocument(choice);
1167 warnttl = "Serious Problem saving Vamsas Document";
1168 warnmsg = ex.toString();
1169 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1172 catch (Exception ex)
1174 warnttl = "Problem saving Vamsas Document.";
1175 warnmsg = ex.toString();
1176 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1181 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1184 JOptionPane.ERROR_MESSAGE);
1189 JProgressBar vamUpdate = null;
1191 * hide vamsas user gui bits when a vamsas document event is being handled.
1192 * @param b true to hide gui, false to reveal gui
1194 public void setVamsasUpdate(boolean b)
1196 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1197 (b ? "in progress" : "finished"));
1199 if (vamUpdate!=null)
1201 this.removeProgressPanel(vamUpdate);
1205 vamUpdate = this.addProgressPanel("Updating vamsas session");
1207 vamsasStart.setVisible(!b);
1208 vamsasStop.setVisible(!b);
1209 vamsasSave.setVisible(!b);
1212 public JInternalFrame[] getAllFrames()
1214 return desktop.getAllFrames();
1219 * Checks the given url to see if it gives a response indicating that
1220 * the user should be informed of a new questionnaire.
1223 public void checkForQuestionnaire(String url)
1225 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1226 //javax.swing.SwingUtilities.invokeLater(jvq);
1227 new Thread(jvq).start();
1230 * Proxy class for JDesktopPane which optionally
1231 * displays the current memory usage and highlights
1232 * the desktop area with a red bar if free memory runs low.
1235 public class MyDesktopPane extends JDesktopPane implements Runnable
1238 boolean showMemoryUsage = false;
1240 java.text.NumberFormat df;
1242 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1244 public MyDesktopPane(boolean showMemoryUsage)
1246 showMemoryUsage(showMemoryUsage);
1249 public void showMemoryUsage(boolean showMemoryUsage)
1251 this.showMemoryUsage = showMemoryUsage;
1252 if (showMemoryUsage)
1254 Thread worker = new Thread(this);
1258 public boolean isShowMemoryUsage()
1260 return showMemoryUsage;
1264 df = java.text.NumberFormat.getNumberInstance();
1265 df.setMaximumFractionDigits(2);
1266 runtime = Runtime.getRuntime();
1268 while (showMemoryUsage)
1273 maxMemory = runtime.maxMemory() / 1048576f;
1274 allocatedMemory = runtime.totalMemory() / 1048576f;
1275 freeMemory = runtime.freeMemory() / 1048576f;
1276 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1278 percentUsage = (totalFreeMemory / maxMemory) * 100;
1280 // if (percentUsage < 20)
1282 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1283 // instance.set.setBorder(border1);
1288 catch (Exception ex)
1290 ex.printStackTrace();
1295 public void paintComponent(Graphics g)
1299 if (percentUsage < 20)
1300 g.setColor(Color.red);
1302 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1303 + "MB; Max Memory: " + df.format(maxMemory)
1304 + "MB; " + df.format(percentUsage) + "%", 10,
1305 getHeight() - g.getFontMetrics().getHeight());
1312 protected JMenuItem groovyShell;
1313 public void doGroovyCheck() {
1314 if (jalview.bin.Cache.groovyJarsPresent())
1316 groovyShell = new JMenuItem();
1317 groovyShell.setText("Groovy Console...");
1318 groovyShell.addActionListener(new ActionListener()
1320 public void actionPerformed(ActionEvent e) {
1321 groovyShell_actionPerformed(e);
1324 toolsMenu.add(groovyShell);
1325 groovyShell.setVisible(true);
1329 * Accessor method to quickly get all the AlignmentFrames
1332 public static AlignFrame[] getAlignframes() {
1333 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1339 Vector avp=new Vector();
1343 for (int i = frames.length - 1; i > -1; i--)
1345 if (frames[i] instanceof AlignFrame)
1347 AlignFrame af = (AlignFrame) frames[i];
1352 catch (Exception ex)
1354 ex.printStackTrace();
1360 AlignFrame afs[] = new AlignFrame[avp.size()];
1361 for (int i=0,j=avp.size(); i<j; i++) {
1362 afs[i] = (AlignFrame) avp.elementAt(i);
1369 * Add Groovy Support to Jalview
1371 public void groovyShell_actionPerformed(ActionEvent e) {
1372 // use reflection to avoid creating compilation dependency.
1373 if (!jalview.bin.Cache.groovyJarsPresent())
1375 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1378 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1379 Constructor gccons = gcClass.getConstructor(null);
1380 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1381 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1382 Object gc = gccons.newInstance(null);
1383 setvar.invoke(gc, new Object[] { "Jalview", this});
1384 run.invoke(gc, null);
1386 catch (Exception ex)
1388 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1389 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1391 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1392 JOptionPane.ERROR_MESSAGE);
1397 * Progress bars managed by the IProgressIndicator method.
1399 private Hashtable progressBars;
1401 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1403 public void setProgressBar(String message, long id)
1405 if(progressBars == null)
1407 progressBars = new Hashtable();
1410 if(progressBars.get( new Long(id) )!=null)
1412 JProgressBar progressPanel = (JProgressBar)progressBars.remove( new Long(id) );
1413 removeProgressPanel(progressPanel);
1415 progressBars.put(new Long(id), addProgressPanel(message));