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 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
609 "\nFor all issues relating to Jalview, email help@jalview.org" +
610 "\n\nIf you use JalView, please cite:" +
611 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
612 "\nBioinformatics, 2004 20;426-7.");
614 JOptionPane.showInternalMessageDialog(Desktop.desktop,
616 message.toString(), "About Jalview",
617 JOptionPane.INFORMATION_MESSAGE);
623 * @param e DOCUMENT ME!
625 public void documentationMenuItem_actionPerformed(ActionEvent e)
629 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
630 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
631 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
633 javax.help.HelpBroker hb = hs.createHelpBroker();
634 hb.setCurrentID("home");
635 hb.setDisplayed(true);
641 public void closeAll_actionPerformed(ActionEvent e)
643 JInternalFrame[] frames = desktop.getAllFrames();
644 for (int i = 0; i < frames.length; i++)
648 frames[i].setClosed(true);
650 catch (java.beans.PropertyVetoException ex)
653 System.out.println("ALL CLOSED");
657 public void raiseRelated_actionPerformed(ActionEvent e)
659 reorderAssociatedWindows(false, false);
662 public void minimizeAssociated_actionPerformed(ActionEvent e)
664 reorderAssociatedWindows(true, false);
667 void closeAssociatedWindows()
669 reorderAssociatedWindows(false, true);
673 * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
675 protected void garbageCollect_actionPerformed(ActionEvent e)
677 // We simply collect the garbage
678 jalview.bin.Cache.log.debug("Collecting garbage...");
680 jalview.bin.Cache.log.debug("Finished garbage collection.");
684 * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
686 protected void showMemusage_actionPerformed(ActionEvent e)
688 desktop.showMemoryUsage(showMemusage.isSelected());
691 void reorderAssociatedWindows(boolean minimize, boolean close)
693 JInternalFrame[] frames = desktop.getAllFrames();
694 if (frames == null || frames.length < 1)
699 AlignViewport source = null, target = null;
700 if (frames[0] instanceof AlignFrame)
702 source = ( (AlignFrame) frames[0]).getCurrentView();
704 else if (frames[0] instanceof TreePanel)
706 source = ( (TreePanel) frames[0]).getViewPort();
708 else if (frames[0] instanceof PCAPanel)
710 source = ( (PCAPanel) frames[0]).av;
712 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
714 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
719 for (int i = 0; i < frames.length; i++)
722 if (frames[i] == null)
726 if (frames[i] instanceof AlignFrame)
728 target = ( (AlignFrame) frames[i]).getCurrentView();
730 else if (frames[i] instanceof TreePanel)
732 target = ( (TreePanel) frames[i]).getViewPort();
734 else if (frames[i] instanceof PCAPanel)
736 target = ( (PCAPanel) frames[i]).av;
738 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
740 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
743 if (source == target)
749 frames[i].setClosed(true);
753 frames[i].setIcon(minimize);
761 catch (java.beans.PropertyVetoException ex)
770 * @param e DOCUMENT ME!
772 protected void preferences_actionPerformed(ActionEvent e)
780 * @param e DOCUMENT ME!
782 public void saveState_actionPerformed(ActionEvent e)
784 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
786 "LAST_DIRECTORY"), new String[]
789 {"Jalview Project"}, "Jalview Project");
791 chooser.setFileView(new JalviewFileView());
792 chooser.setDialogTitle("Save State");
794 int value = chooser.showSaveDialog(this);
796 if (value == JalviewFileChooser.APPROVE_OPTION)
798 java.io.File choice = chooser.getSelectedFile();
799 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
800 new Jalview2XML().SaveState(choice);
807 * @param e DOCUMENT ME!
809 public void loadState_actionPerformed(ActionEvent e)
811 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
813 "LAST_DIRECTORY"), new String[]
816 {"Jalview Project"}, "Jalview Project");
817 chooser.setFileView(new JalviewFileView());
818 chooser.setDialogTitle("Restore state");
820 int value = chooser.showOpenDialog(this);
822 if (value == JalviewFileChooser.APPROVE_OPTION)
824 String choice = chooser.getSelectedFile().getAbsolutePath();
825 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
826 chooser.getSelectedFile().getParent());
827 new Jalview2XML().LoadJalviewAlign(choice);
831 public void inputSequence_actionPerformed(ActionEvent e)
833 new SequenceFetcher(this);
836 JPanel progressPanel;
838 public void startLoading(final String fileName)
840 if (fileLoadingCount == 0)
842 addProgressPanel("Loading File: " + fileName + " ");
847 private JProgressBar addProgressPanel(String string)
849 if (progressPanel==null)
851 progressPanel = new JPanel(new BorderLayout());
852 totalProgressCount=0;
854 JProgressBar progressBar = new JProgressBar();
855 progressBar.setIndeterminate(true);
857 progressPanel.add(new JLabel(string),
860 progressPanel.add(progressBar, BorderLayout.CENTER);
862 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
863 totalProgressCount++;
867 int totalProgressCount=0;
868 private void removeProgressPanel(JProgressBar progbar)
870 if (progressPanel!=null)
872 progressPanel.remove(progbar);
873 if (--totalProgressCount<1)
875 this.getContentPane().remove(progressPanel);
876 progressPanel = null;
881 public void stopLoading()
884 if (fileLoadingCount < 1)
886 if (progressPanel != null)
888 this.getContentPane().remove(progressPanel);
889 progressPanel = null;
891 fileLoadingCount = 0;
895 public static int getViewCount(String viewId)
898 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
899 for (int t = 0; t < frames.length; t++)
901 if (frames[t] instanceof AlignFrame)
903 AlignFrame af = (AlignFrame) frames[t];
904 for (int a = 0; a < af.alignPanels.size(); a++)
907 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
920 public void explodeViews(AlignFrame af)
922 int size = af.alignPanels.size();
928 for (int i = 0; i < size; i++)
930 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
931 AlignFrame newaf = new AlignFrame(ap);
932 if (ap.av.explodedPosition != null &&
933 !ap.av.explodedPosition.equals(af.getBounds()))
935 newaf.setBounds(ap.av.explodedPosition);
938 ap.av.gatherViewsHere = false;
940 addInternalFrame(newaf, af.getTitle(),
941 AlignFrame.DEFAULT_WIDTH,
942 AlignFrame.DEFAULT_HEIGHT);
945 af.alignPanels.clear();
946 af.closeMenuItem_actionPerformed(true);
950 public void gatherViews(AlignFrame source)
952 source.viewport.gatherViewsHere = true;
953 source.viewport.explodedPosition = source.getBounds();
954 JInternalFrame[] frames = desktop.getAllFrames();
955 String viewId = source.viewport.sequenceSetID;
957 for (int t = 0; t < frames.length; t++)
959 if (frames[t] instanceof AlignFrame && frames[t] != source)
961 AlignFrame af = (AlignFrame) frames[t];
962 boolean gatherThis = false;
963 for (int a = 0; a < af.alignPanels.size(); a++)
965 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
966 if (viewId.equals(ap.av.getSequenceSetId()))
969 ap.av.gatherViewsHere = false;
970 ap.av.explodedPosition = af.getBounds();
971 source.addAlignmentPanel(ap, false);
977 af.alignPanels.clear();
978 af.closeMenuItem_actionPerformed(true);
985 jalview.gui.VamsasApplication v_client = null;
986 public void vamsasImport_actionPerformed(ActionEvent e)
990 // Load and try to start a session.
991 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
992 getProperty("LAST_DIRECTORY"));
994 chooser.setFileView(new JalviewFileView());
995 chooser.setDialogTitle("Open a saved VAMSAS session");
996 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
998 int value = chooser.showOpenDialog(this);
1000 if (value == JalviewFileChooser.APPROVE_OPTION)
1003 v_client = new jalview.gui.VamsasApplication(this,
1004 chooser.getSelectedFile());
1005 } catch (Exception ex)
1007 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
1010 setupVamsasConnectedGui();
1011 v_client.initial_update(); // TODO: thread ?
1014 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
1018 public void vamsasStart_actionPerformed(ActionEvent e)
1020 if (v_client == null)
1023 // we just start a default session for moment.
1025 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1026 getProperty("LAST_DIRECTORY"));
1028 chooser.setFileView(new JalviewFileView());
1029 chooser.setDialogTitle("Load Vamsas file");
1030 chooser.setToolTipText("Import");
1032 int value = chooser.showOpenDialog(this);
1034 if (value == JalviewFileChooser.APPROVE_OPTION)
1036 v_client = new jalview.gui.VamsasApplication(this,
1037 chooser.getSelectedFile());
1040 v_client = new VamsasApplication(this);
1041 setupVamsasConnectedGui();
1042 v_client.initial_update(); // TODO: thread ?
1046 // store current data in session.
1047 v_client.push_update(); // TODO: thread
1051 protected void setupVamsasConnectedGui()
1053 vamsasStart.setText("Session Update");
1054 vamsasSave.setVisible(true);
1055 vamsasStop.setVisible(true);
1056 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1058 protected void setupVamsasDisconnectedGui()
1060 vamsasSave.setVisible(false);
1061 vamsasStop.setVisible(false);
1062 vamsasImport.setVisible(true);
1063 vamsasStart.setText("New Vamsas Session...");
1066 public void vamsasStop_actionPerformed(ActionEvent e)
1068 if (v_client != null)
1070 v_client.end_session();
1072 setupVamsasDisconnectedGui();
1075 protected void buildVamsasStMenu()
1077 if (v_client == null)
1079 String[] sess = null;
1082 sess = VamsasApplication.getSessionList();
1083 } catch (Exception e)
1085 jalview.bin.Cache.log.warn(
1086 "Problem getting current sessions list.", e);
1091 jalview.bin.Cache.log.debug("Got current sessions list: "
1092 + sess.length + " entries.");
1093 VamsasStMenu.removeAll();
1094 for (int i = 0; i < sess.length; i++)
1096 JMenuItem sessit = new JMenuItem();
1097 sessit.setText(sess[i]);
1098 sessit.setToolTipText("Connect to session " + sess[i]);
1099 final Desktop dsktp = this;
1100 final String mysesid = sess[i];
1101 sessit.addActionListener(new ActionListener()
1104 public void actionPerformed(ActionEvent e)
1106 if (dsktp.v_client == null)
1108 Thread rthr = new Thread(new Runnable() {
1112 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1113 dsktp.setupVamsasConnectedGui();
1114 dsktp.v_client.initial_update();
1122 VamsasStMenu.add(sessit);
1124 // don't show an empty menu.
1125 VamsasStMenu.setVisible(sess.length>0);
1130 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1131 VamsasStMenu.removeAll();
1132 VamsasStMenu.setVisible(false);
1135 // Not interested in the content. Just hide ourselves.
1136 VamsasStMenu.setVisible(false);
1139 public void vamsasSave_actionPerformed(ActionEvent e)
1141 if (v_client != null)
1143 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1145 "LAST_DIRECTORY"), new String[]
1146 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1148 {"Vamsas Document"}, "Vamsas Document");
1150 chooser.setFileView(new JalviewFileView());
1151 chooser.setDialogTitle("Save Vamsas Document Archive");
1153 int value = chooser.showSaveDialog(this);
1155 if (value == JalviewFileChooser.APPROVE_OPTION)
1157 java.io.File choice = chooser.getSelectedFile();
1158 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1159 String warnmsg=null;
1160 String warnttl=null;
1162 v_client.vclient.storeDocument(choice);
1166 warnttl = "Serious Problem saving Vamsas Document";
1167 warnmsg = ex.toString();
1168 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1171 catch (Exception ex)
1173 warnttl = "Problem saving Vamsas Document.";
1174 warnmsg = ex.toString();
1175 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1180 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1183 JOptionPane.ERROR_MESSAGE);
1188 JProgressBar vamUpdate = null;
1190 * hide vamsas user gui bits when a vamsas document event is being handled.
1191 * @param b true to hide gui, false to reveal gui
1193 public void setVamsasUpdate(boolean b)
1195 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1196 (b ? "in progress" : "finished"));
1198 if (vamUpdate!=null)
1200 this.removeProgressPanel(vamUpdate);
1204 vamUpdate = this.addProgressPanel("Updating vamsas session");
1206 vamsasStart.setVisible(!b);
1207 vamsasStop.setVisible(!b);
1208 vamsasSave.setVisible(!b);
1211 public JInternalFrame[] getAllFrames()
1213 return desktop.getAllFrames();
1218 * Checks the given url to see if it gives a response indicating that
1219 * the user should be informed of a new questionnaire.
1222 public void checkForQuestionnaire(String url)
1224 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1225 //javax.swing.SwingUtilities.invokeLater(jvq);
1226 new Thread(jvq).start();
1229 * Proxy class for JDesktopPane which optionally
1230 * displays the current memory usage and highlights
1231 * the desktop area with a red bar if free memory runs low.
1234 public class MyDesktopPane extends JDesktopPane implements Runnable
1237 boolean showMemoryUsage = false;
1239 java.text.NumberFormat df;
1241 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1243 public MyDesktopPane(boolean showMemoryUsage)
1245 showMemoryUsage(showMemoryUsage);
1248 public void showMemoryUsage(boolean showMemoryUsage)
1250 this.showMemoryUsage = showMemoryUsage;
1251 if (showMemoryUsage)
1253 Thread worker = new Thread(this);
1257 public boolean isShowMemoryUsage()
1259 return showMemoryUsage;
1263 df = java.text.NumberFormat.getNumberInstance();
1264 df.setMaximumFractionDigits(2);
1265 runtime = Runtime.getRuntime();
1267 while (showMemoryUsage)
1272 maxMemory = runtime.maxMemory() / 1048576f;
1273 allocatedMemory = runtime.totalMemory() / 1048576f;
1274 freeMemory = runtime.freeMemory() / 1048576f;
1275 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1277 percentUsage = (totalFreeMemory / maxMemory) * 100;
1279 // if (percentUsage < 20)
1281 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1282 // instance.set.setBorder(border1);
1287 catch (Exception ex)
1289 ex.printStackTrace();
1294 public void paintComponent(Graphics g)
1298 if (percentUsage < 20)
1299 g.setColor(Color.red);
1301 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1302 + "MB; Max Memory: " + df.format(maxMemory)
1303 + "MB; " + df.format(percentUsage) + "%", 10,
1304 getHeight() - g.getFontMetrics().getHeight());
1311 protected JMenuItem groovyShell;
1312 public void doGroovyCheck() {
1313 if (jalview.bin.Cache.groovyJarsPresent())
1315 groovyShell = new JMenuItem();
1316 groovyShell.setText("Groovy Console...");
1317 groovyShell.addActionListener(new ActionListener()
1319 public void actionPerformed(ActionEvent e) {
1320 groovyShell_actionPerformed(e);
1323 toolsMenu.add(groovyShell);
1324 groovyShell.setVisible(true);
1328 * Accessor method to quickly get all the AlignmentFrames
1331 public static AlignFrame[] getAlignframes() {
1332 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1338 Vector avp=new Vector();
1342 for (int i = frames.length - 1; i > -1; i--)
1344 if (frames[i] instanceof AlignFrame)
1346 AlignFrame af = (AlignFrame) frames[i];
1351 catch (Exception ex)
1353 ex.printStackTrace();
1359 AlignFrame afs[] = new AlignFrame[avp.size()];
1360 for (int i=0,j=avp.size(); i<j; i++) {
1361 afs[i] = (AlignFrame) avp.elementAt(i);
1368 * Add Groovy Support to Jalview
1370 public void groovyShell_actionPerformed(ActionEvent e) {
1371 // use reflection to avoid creating compilation dependency.
1372 if (!jalview.bin.Cache.groovyJarsPresent())
1374 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1377 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1378 Constructor gccons = gcClass.getConstructor(null);
1379 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1380 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1381 Object gc = gccons.newInstance(null);
1382 setvar.invoke(gc, new Object[] { "Jalview", this});
1383 run.invoke(gc, null);
1385 catch (Exception ex)
1387 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1388 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1390 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1391 JOptionPane.ERROR_MESSAGE);
1396 * Progress bars managed by the IProgressIndicator method.
1398 private Hashtable progressBars;
1400 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1402 public void setProgressBar(String message, long id)
1404 if(progressBars == null)
1406 progressBars = new Hashtable();
1409 if(progressBars.get( new Long(id) )!=null)
1411 JProgressBar progressPanel = (JProgressBar)progressBars.remove( new Long(id) );
1412 removeProgressPanel(progressPanel);
1414 progressBars.put(new Long(id), addProgressPanel(message));