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 * A note to implementors. It is ESSENTIAL that any
69 * activities that might block are spawned off as threads rather
70 * than waited for during this constructor.
73 doVamsasClientCheck();
77 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
78 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
79 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",false);
80 desktop = new MyDesktopPane(selmemusage);
81 showMemusage.setSelected(selmemusage);
82 desktop.setBackground(Color.white);
83 getContentPane().setLayout(new BorderLayout());
84 getContentPane().add(desktop, BorderLayout.CENTER);
85 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
87 // This line prevents Windows Look&Feel resizing all new windows to maximum
88 // if previous window was maximised
89 desktop.setDesktopManager(new DefaultDesktopManager());
91 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
92 String x = jalview.bin.Cache.getProperty("SCREEN_X");
93 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
94 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
95 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
97 if ( (x != null) && (y != null) && (width != null) && (height != null))
99 setBounds(Integer.parseInt(x), Integer.parseInt(y),
100 Integer.parseInt(width), Integer.parseInt(height));
104 setBounds( (int) (screenSize.width - 900) / 2,
105 (int) (screenSize.height - 650) / 2, 900, 650);
108 this.addWindowListener(new WindowAdapter()
110 public void windowClosing(WindowEvent evt)
116 this.addMouseListener(new MouseAdapter()
118 public void mousePressed(MouseEvent evt)
120 if(SwingUtilities.isRightMouseButton(evt))
122 showPasteMenu(evt.getX(), evt.getY());
128 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
129 // Spawn a thread that shows the splashscreen
134 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
137 private void doVamsasClientCheck()
139 if (jalview.bin.Cache.vamsasJarsPresent())
141 setupVamsasDisconnectedGui();
142 VamsasMenu.setVisible(true);
143 final Desktop us = this;
144 VamsasMenu.addMenuListener(new MenuListener() {
145 // this listener remembers when the menu was first selected, and
146 // doesn't rebuild the session list until it has been cleared and
148 boolean refresh=true;
149 public void menuCanceled(MenuEvent e)
154 public void menuDeselected(MenuEvent e)
159 public void menuSelected(MenuEvent e)
163 us.buildVamsasStMenu();
168 vamsasStart.setVisible(true);
172 void showPasteMenu(int x, int y)
174 JPopupMenu popup = new JPopupMenu();
175 JMenuItem item = new JMenuItem("Paste To New Window");
176 item.addActionListener(new ActionListener()
178 public void actionPerformed(ActionEvent evt)
185 popup.show(this, x, y);
192 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
193 Transferable contents = c.getContents(this);
195 if (contents != null)
197 String file = (String) contents
198 .getTransferData(DataFlavor.stringFlavor);
200 String format = new IdentifyFile().Identify(file,
201 FormatAdapter.PASTE);
203 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
209 System.out.println("Unable to paste alignment from system clipboard:\n"
217 * @param frame DOCUMENT ME!
218 * @param title DOCUMENT ME!
219 * @param w DOCUMENT ME!
220 * @param h DOCUMENT ME!
222 public static synchronized void addInternalFrame(final JInternalFrame frame,
223 String title, int w, int h)
225 addInternalFrame(frame, title, w, h, true);
231 * @param frame DOCUMENT ME!
232 * @param title DOCUMENT ME!
233 * @param w DOCUMENT ME!
234 * @param h DOCUMENT ME!
235 * @param resizable DOCUMENT ME!
237 public static synchronized void addInternalFrame(final JInternalFrame frame,
238 String title, int w, int h, boolean resizable)
241 frame.setTitle(title);
242 if (frame.getWidth() < 1 || frame.getHeight() < 1)
246 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
247 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
248 // IF JALVIEW IS RUNNING HEADLESS
249 /////////////////////////////////////////////////
250 if (System.getProperty("java.awt.headless") != null
251 && System.getProperty("java.awt.headless").equals("true"))
258 frame.setVisible(true);
259 frame.setClosable(true);
260 frame.setResizable(resizable);
261 frame.setMaximizable(resizable);
262 frame.setIconifiable(resizable);
263 frame.setFrameIcon(null);
265 if (frame.getX() < 1 && frame.getY() < 1)
267 frame.setLocation(xOffset * openFrameCount,
268 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
271 final JMenuItem menuItem = new JMenuItem(title);
272 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
274 public void internalFrameActivated(javax.swing.event.
275 InternalFrameEvent evt)
277 JInternalFrame itf = desktop.getSelectedFrame();
285 public void internalFrameClosed(
286 javax.swing.event.InternalFrameEvent evt)
288 PaintRefresher.RemoveComponent(frame);
290 windowMenu.remove(menuItem);
291 JInternalFrame itf = desktop.getSelectedFrame();
301 menuItem.addActionListener(new ActionListener()
303 public void actionPerformed(ActionEvent e)
307 frame.setSelected(true);
308 frame.setIcon(false);
310 catch (java.beans.PropertyVetoException ex)
317 windowMenu.add(menuItem);
323 frame.setSelected(true);
324 frame.requestFocus();
326 catch (java.beans.PropertyVetoException ve)
330 public void lostOwnership(Clipboard clipboard, Transferable contents)
334 Desktop.jalviewClipboard = null;
337 internalCopy = false;
340 public void dragEnter(DropTargetDragEvent evt)
343 public void dragExit(DropTargetEvent evt)
346 public void dragOver(DropTargetDragEvent evt)
349 public void dropActionChanged(DropTargetDragEvent evt)
355 * @param evt DOCUMENT ME!
357 public void drop(DropTargetDropEvent evt)
359 Transferable t = evt.getTransferable();
360 java.util.List files = null;
364 DataFlavor uriListFlavor = new DataFlavor(
365 "text/uri-list;class=java.lang.String");
366 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
368 //Works on Windows and MacOSX
369 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
370 files = (java.util.List) t.getTransferData(DataFlavor.
373 else if (t.isDataFlavorSupported(uriListFlavor))
375 // This is used by Unix drag system
376 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
377 String data = (String) t.getTransferData(uriListFlavor);
378 files = new java.util.ArrayList(1);
379 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
382 st.hasMoreTokens(); )
384 String s = st.nextToken();
385 if (s.startsWith("#"))
387 // the line is a comment (as per the RFC 2483)
391 java.net.URI uri = new java.net.URI(s);
392 java.io.File file = new java.io.File(uri);
404 for (int i = 0; i < files.size(); i++)
406 String file = files.get(i).toString();
407 String protocol = FormatAdapter.FILE;
408 String format = null;
410 if (file.endsWith(".jar"))
417 format = new IdentifyFile().Identify(file,
421 new FileLoader().LoadFile(file, protocol, format);
433 * @param e DOCUMENT ME!
435 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
437 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
440 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
441 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
442 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
444 chooser.setFileView(new JalviewFileView());
445 chooser.setDialogTitle("Open local file");
446 chooser.setToolTipText("Open");
448 int value = chooser.showOpenDialog(this);
450 if (value == JalviewFileChooser.APPROVE_OPTION)
452 String choice = chooser.getSelectedFile().getPath();
453 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
454 chooser.getSelectedFile().getParent());
456 String format = null;
457 if (chooser.getSelectedFormat().equals("Jalview"))
463 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
466 if (viewport != null)
468 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
472 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
480 * @param e DOCUMENT ME!
482 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
484 // This construct allows us to have a wider textfield
486 JLabel label = new JLabel("Enter URL of Input File");
487 final JComboBox history = new JComboBox();
489 JPanel panel = new JPanel(new GridLayout(2, 1));
492 history.setPreferredSize(new Dimension(400, 20));
493 history.setEditable(true);
494 history.addItem("http://www.");
496 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
500 if (historyItems != null)
502 st = new StringTokenizer(historyItems, "\t");
504 while (st.hasMoreTokens())
506 history.addItem(st.nextElement());
510 int reply = JOptionPane.showInternalConfirmDialog(desktop,
511 panel, "Input Alignment From URL",
512 JOptionPane.OK_CANCEL_OPTION);
514 if (reply != JOptionPane.OK_OPTION)
519 String url = history.getSelectedItem().toString();
521 if (url.toLowerCase().endsWith(".jar"))
523 if (viewport != null)
525 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
529 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
534 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
536 if (format.equals("URL NOT FOUND"))
538 JOptionPane.showInternalMessageDialog(Desktop.desktop,
539 "Couldn't locate " + url,
541 JOptionPane.WARNING_MESSAGE);
546 if (viewport != null)
548 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
552 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
560 * @param e DOCUMENT ME!
562 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
564 CutAndPasteTransfer cap = new CutAndPasteTransfer();
565 cap.setForInput(viewport);
566 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
574 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
575 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
576 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
577 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
584 * @param e DOCUMENT ME!
586 public void aboutMenuItem_actionPerformed(ActionEvent e)
588 StringBuffer message = new StringBuffer("JalView version " +
589 jalview.bin.Cache.getProperty(
593 Cache.getDefault("BUILD_DATE",
596 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
597 jalview.bin.Cache.getProperty("VERSION")))
599 message.append("\n\n!! Jalview version "
600 + jalview.bin.Cache.getProperty("LATEST_VERSION")
602 " is available for download from http://www.jalview.org !!\n");
606 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
607 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
608 "\nFor all issues relating to Jalview, email help@jalview.org" +
609 "\n\nIf you use JalView, please cite:" +
610 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
611 "\nBioinformatics, 2004 20;426-7.");
613 JOptionPane.showInternalMessageDialog(Desktop.desktop,
615 message.toString(), "About Jalview",
616 JOptionPane.INFORMATION_MESSAGE);
622 * @param e DOCUMENT ME!
624 public void documentationMenuItem_actionPerformed(ActionEvent e)
628 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
629 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
630 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
632 javax.help.HelpBroker hb = hs.createHelpBroker();
633 hb.setCurrentID("home");
634 hb.setDisplayed(true);
640 public void closeAll_actionPerformed(ActionEvent e)
642 JInternalFrame[] frames = desktop.getAllFrames();
643 for (int i = 0; i < frames.length; i++)
647 frames[i].setClosed(true);
649 catch (java.beans.PropertyVetoException ex)
652 System.out.println("ALL CLOSED");
656 public void raiseRelated_actionPerformed(ActionEvent e)
658 reorderAssociatedWindows(false, false);
661 public void minimizeAssociated_actionPerformed(ActionEvent e)
663 reorderAssociatedWindows(true, false);
666 void closeAssociatedWindows()
668 reorderAssociatedWindows(false, true);
672 * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
674 protected void garbageCollect_actionPerformed(ActionEvent e)
676 // We simply collect the garbage
677 jalview.bin.Cache.log.debug("Collecting garbage...");
679 jalview.bin.Cache.log.debug("Finished garbage collection.");
683 * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
685 protected void showMemusage_actionPerformed(ActionEvent e)
687 desktop.showMemoryUsage(showMemusage.isSelected());
690 void reorderAssociatedWindows(boolean minimize, boolean close)
692 JInternalFrame[] frames = desktop.getAllFrames();
693 if (frames == null || frames.length < 1)
698 AlignViewport source = null, target = null;
699 if (frames[0] instanceof AlignFrame)
701 source = ( (AlignFrame) frames[0]).getCurrentView();
703 else if (frames[0] instanceof TreePanel)
705 source = ( (TreePanel) frames[0]).getViewPort();
707 else if (frames[0] instanceof PCAPanel)
709 source = ( (PCAPanel) frames[0]).av;
711 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
713 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
718 for (int i = 0; i < frames.length; i++)
721 if (frames[i] == null)
725 if (frames[i] instanceof AlignFrame)
727 target = ( (AlignFrame) frames[i]).getCurrentView();
729 else if (frames[i] instanceof TreePanel)
731 target = ( (TreePanel) frames[i]).getViewPort();
733 else if (frames[i] instanceof PCAPanel)
735 target = ( (PCAPanel) frames[i]).av;
737 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
739 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
742 if (source == target)
748 frames[i].setClosed(true);
752 frames[i].setIcon(minimize);
760 catch (java.beans.PropertyVetoException ex)
769 * @param e DOCUMENT ME!
771 protected void preferences_actionPerformed(ActionEvent e)
779 * @param e DOCUMENT ME!
781 public void saveState_actionPerformed(ActionEvent e)
783 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
785 "LAST_DIRECTORY"), new String[]
788 {"Jalview Project"}, "Jalview Project");
790 chooser.setFileView(new JalviewFileView());
791 chooser.setDialogTitle("Save State");
793 int value = chooser.showSaveDialog(this);
795 if (value == JalviewFileChooser.APPROVE_OPTION)
797 java.io.File choice = chooser.getSelectedFile();
798 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
799 new Jalview2XML().SaveState(choice);
806 * @param e DOCUMENT ME!
808 public void loadState_actionPerformed(ActionEvent e)
810 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
812 "LAST_DIRECTORY"), new String[]
815 {"Jalview Project"}, "Jalview Project");
816 chooser.setFileView(new JalviewFileView());
817 chooser.setDialogTitle("Restore state");
819 int value = chooser.showOpenDialog(this);
821 if (value == JalviewFileChooser.APPROVE_OPTION)
823 String choice = chooser.getSelectedFile().getAbsolutePath();
824 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
825 chooser.getSelectedFile().getParent());
826 new Jalview2XML().LoadJalviewAlign(choice);
830 public void inputSequence_actionPerformed(ActionEvent e)
832 new SequenceFetcher(null);
835 JPanel progressPanel;
837 public void startLoading(final String fileName)
839 if (fileLoadingCount == 0)
841 addProgressPanel("Loading File: " + fileName + " ");
846 private JProgressBar addProgressPanel(String string)
848 if (progressPanel==null)
850 progressPanel = new JPanel(new BorderLayout());
851 totalProgressCount=0;
853 JProgressBar progressBar = new JProgressBar();
854 progressBar.setIndeterminate(true);
856 progressPanel.add(new JLabel(string),
859 progressPanel.add(progressBar, BorderLayout.CENTER);
861 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
862 totalProgressCount++;
866 int totalProgressCount=0;
867 private void removeProgressPanel(JProgressBar progbar)
869 if (progressPanel!=null)
871 progressPanel.remove(progbar);
872 if (--totalProgressCount<1)
874 this.getContentPane().remove(progressPanel);
875 progressPanel = null;
880 public void stopLoading()
883 if (fileLoadingCount < 1)
885 if (progressPanel != null)
887 this.getContentPane().remove(progressPanel);
888 progressPanel = null;
890 fileLoadingCount = 0;
894 public static int getViewCount(String viewId)
897 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
898 for (int t = 0; t < frames.length; t++)
900 if (frames[t] instanceof AlignFrame)
902 AlignFrame af = (AlignFrame) frames[t];
903 for (int a = 0; a < af.alignPanels.size(); a++)
906 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
919 public void explodeViews(AlignFrame af)
921 int size = af.alignPanels.size();
927 for (int i = 0; i < size; i++)
929 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
930 AlignFrame newaf = new AlignFrame(ap);
931 if (ap.av.explodedPosition != null &&
932 !ap.av.explodedPosition.equals(af.getBounds()))
934 newaf.setBounds(ap.av.explodedPosition);
937 ap.av.gatherViewsHere = false;
939 addInternalFrame(newaf, af.getTitle(),
940 AlignFrame.DEFAULT_WIDTH,
941 AlignFrame.DEFAULT_HEIGHT);
944 af.alignPanels.clear();
945 af.closeMenuItem_actionPerformed(true);
949 public void gatherViews(AlignFrame source)
951 source.viewport.gatherViewsHere = true;
952 source.viewport.explodedPosition = source.getBounds();
953 JInternalFrame[] frames = desktop.getAllFrames();
954 String viewId = source.viewport.sequenceSetID;
956 for (int t = 0; t < frames.length; t++)
958 if (frames[t] instanceof AlignFrame && frames[t] != source)
960 AlignFrame af = (AlignFrame) frames[t];
961 boolean gatherThis = false;
962 for (int a = 0; a < af.alignPanels.size(); a++)
964 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
965 if (viewId.equals(ap.av.getSequenceSetId()))
968 ap.av.gatherViewsHere = false;
969 ap.av.explodedPosition = af.getBounds();
970 source.addAlignmentPanel(ap, false);
976 af.alignPanels.clear();
977 af.closeMenuItem_actionPerformed(true);
984 jalview.gui.VamsasApplication v_client = null;
985 public void vamsasImport_actionPerformed(ActionEvent e)
989 // Load and try to start a session.
990 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
991 getProperty("LAST_DIRECTORY"));
993 chooser.setFileView(new JalviewFileView());
994 chooser.setDialogTitle("Open a saved VAMSAS session");
995 chooser.setToolTipText("select a vamsas session to be opened as a new vamsas session.");
997 int value = chooser.showOpenDialog(this);
999 if (value == JalviewFileChooser.APPROVE_OPTION)
1002 v_client = new jalview.gui.VamsasApplication(this,
1003 chooser.getSelectedFile());
1004 } catch (Exception ex)
1006 jalview.bin.Cache.log.error("New vamsas session from existing session file failed:",ex);
1009 setupVamsasConnectedGui();
1010 v_client.initial_update(); // TODO: thread ?
1013 jalview.bin.Cache.log.error("Implementation error - load session from a running session is not supported.");
1017 public void vamsasStart_actionPerformed(ActionEvent e)
1019 if (v_client == null)
1022 // we just start a default session for moment.
1024 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1025 getProperty("LAST_DIRECTORY"));
1027 chooser.setFileView(new JalviewFileView());
1028 chooser.setDialogTitle("Load Vamsas file");
1029 chooser.setToolTipText("Import");
1031 int value = chooser.showOpenDialog(this);
1033 if (value == JalviewFileChooser.APPROVE_OPTION)
1035 v_client = new jalview.gui.VamsasApplication(this,
1036 chooser.getSelectedFile());
1039 v_client = new VamsasApplication(this);
1040 setupVamsasConnectedGui();
1041 v_client.initial_update(); // TODO: thread ?
1045 // store current data in session.
1046 v_client.push_update(); // TODO: thread
1050 protected void setupVamsasConnectedGui()
1052 vamsasStart.setText("Session Update");
1053 vamsasSave.setVisible(true);
1054 vamsasStop.setVisible(true);
1055 vamsasImport.setVisible(false); // Document import to existing session is not possible for vamsas-client-1.0.
1057 protected void setupVamsasDisconnectedGui()
1059 vamsasSave.setVisible(false);
1060 vamsasStop.setVisible(false);
1061 vamsasImport.setVisible(true);
1062 vamsasStart.setText("New Vamsas Session...");
1065 public void vamsasStop_actionPerformed(ActionEvent e)
1067 if (v_client != null)
1069 v_client.end_session();
1071 setupVamsasDisconnectedGui();
1074 protected void buildVamsasStMenu()
1076 if (v_client == null)
1078 String[] sess = null;
1081 sess = VamsasApplication.getSessionList();
1082 } catch (Exception e)
1084 jalview.bin.Cache.log.warn(
1085 "Problem getting current sessions list.", e);
1090 jalview.bin.Cache.log.debug("Got current sessions list: "
1091 + sess.length + " entries.");
1092 VamsasStMenu.removeAll();
1093 for (int i = 0; i < sess.length; i++)
1095 JMenuItem sessit = new JMenuItem();
1096 sessit.setText(sess[i]);
1097 sessit.setToolTipText("Connect to session " + sess[i]);
1098 final Desktop dsktp = this;
1099 final String mysesid = sess[i];
1100 sessit.addActionListener(new ActionListener()
1103 public void actionPerformed(ActionEvent e)
1105 if (dsktp.v_client == null)
1107 Thread rthr = new Thread(new Runnable() {
1111 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
1112 dsktp.setupVamsasConnectedGui();
1113 dsktp.v_client.initial_update();
1121 VamsasStMenu.add(sessit);
1123 // don't show an empty menu.
1124 VamsasStMenu.setVisible(sess.length>0);
1129 jalview.bin.Cache.log.debug("No current vamsas sessions.");
1130 VamsasStMenu.removeAll();
1131 VamsasStMenu.setVisible(false);
1134 // Not interested in the content. Just hide ourselves.
1135 VamsasStMenu.setVisible(false);
1138 public void vamsasSave_actionPerformed(ActionEvent e)
1140 if (v_client != null)
1142 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1144 "LAST_DIRECTORY"), new String[]
1145 {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
1147 {"Vamsas Document"}, "Vamsas Document");
1149 chooser.setFileView(new JalviewFileView());
1150 chooser.setDialogTitle("Save Vamsas Document Archive");
1152 int value = chooser.showSaveDialog(this);
1154 if (value == JalviewFileChooser.APPROVE_OPTION)
1156 java.io.File choice = chooser.getSelectedFile();
1157 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
1158 String warnmsg=null;
1159 String warnttl=null;
1161 v_client.vclient.storeDocument(choice);
1165 warnttl = "Serious Problem saving Vamsas Document";
1166 warnmsg = ex.toString();
1167 jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex);
1170 catch (Exception ex)
1172 warnttl = "Problem saving Vamsas Document.";
1173 warnmsg = ex.toString();
1174 jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex);
1179 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1182 JOptionPane.ERROR_MESSAGE);
1187 JProgressBar vamUpdate = null;
1189 * hide vamsas user gui bits when a vamsas document event is being handled.
1190 * @param b true to hide gui, false to reveal gui
1192 public void setVamsasUpdate(boolean b)
1194 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1195 (b ? "in progress" : "finished"));
1197 if (vamUpdate!=null)
1199 this.removeProgressPanel(vamUpdate);
1203 vamUpdate = this.addProgressPanel("Updating vamsas session");
1205 vamsasStart.setVisible(!b);
1206 vamsasStop.setVisible(!b);
1207 vamsasSave.setVisible(!b);
1210 public JInternalFrame[] getAllFrames()
1212 return desktop.getAllFrames();
1217 * Checks the given url to see if it gives a response indicating that
1218 * the user should be informed of a new questionnaire.
1221 public void checkForQuestionnaire(String url)
1223 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1224 //javax.swing.SwingUtilities.invokeLater(jvq);
1225 new Thread(jvq).start();
1228 * Proxy class for JDesktopPane which optionally
1229 * displays the current memory usage and highlights
1230 * the desktop area with a red bar if free memory runs low.
1233 public class MyDesktopPane extends JDesktopPane implements Runnable
1236 boolean showMemoryUsage = false;
1238 java.text.NumberFormat df;
1240 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1242 public MyDesktopPane(boolean showMemoryUsage)
1244 showMemoryUsage(showMemoryUsage);
1247 public void showMemoryUsage(boolean showMemoryUsage)
1249 this.showMemoryUsage = showMemoryUsage;
1250 if (showMemoryUsage)
1252 Thread worker = new Thread(this);
1256 public boolean isShowMemoryUsage()
1258 return showMemoryUsage;
1262 df = java.text.NumberFormat.getNumberInstance();
1263 df.setMaximumFractionDigits(2);
1264 runtime = Runtime.getRuntime();
1266 while (showMemoryUsage)
1271 maxMemory = runtime.maxMemory() / 1048576f;
1272 allocatedMemory = runtime.totalMemory() / 1048576f;
1273 freeMemory = runtime.freeMemory() / 1048576f;
1274 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1276 percentUsage = (totalFreeMemory / maxMemory) * 100;
1278 // if (percentUsage < 20)
1280 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1281 // instance.set.setBorder(border1);
1286 catch (Exception ex)
1288 ex.printStackTrace();
1293 public void paintComponent(Graphics g)
1297 if (percentUsage < 20)
1298 g.setColor(Color.red);
1300 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1301 + "MB; Max Memory: " + df.format(maxMemory)
1302 + "MB; " + df.format(percentUsage) + "%", 10,
1303 getHeight() - g.getFontMetrics().getHeight());
1310 protected JMenuItem groovyShell;
1311 public void doGroovyCheck() {
1312 if (jalview.bin.Cache.groovyJarsPresent())
1314 groovyShell = new JMenuItem();
1315 groovyShell.setText("Groovy Console...");
1316 groovyShell.addActionListener(new ActionListener()
1318 public void actionPerformed(ActionEvent e) {
1319 groovyShell_actionPerformed(e);
1322 toolsMenu.add(groovyShell);
1323 groovyShell.setVisible(true);
1327 * Accessor method to quickly get all the AlignmentFrames
1330 public static AlignFrame[] getAlignframes() {
1331 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1337 Vector avp=new Vector();
1341 for (int i = frames.length - 1; i > -1; i--)
1343 if (frames[i] instanceof AlignFrame)
1345 AlignFrame af = (AlignFrame) frames[i];
1350 catch (Exception ex)
1352 ex.printStackTrace();
1358 AlignFrame afs[] = new AlignFrame[avp.size()];
1359 for (int i=0,j=avp.size(); i<j; i++) {
1360 afs[i] = (AlignFrame) avp.elementAt(i);
1367 * Add Groovy Support to Jalview
1369 public void groovyShell_actionPerformed(ActionEvent e) {
1370 // use reflection to avoid creating compilation dependency.
1371 if (!jalview.bin.Cache.groovyJarsPresent())
1373 throw new Error("Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
1376 Class gcClass = Desktop.class.getClassLoader().loadClass("groovy.ui.Console");
1377 Constructor gccons = gcClass.getConstructor(null);
1378 java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", new Class[] { String.class, Object.class} );
1379 java.lang.reflect.Method run = gcClass.getMethod("run", null);
1380 Object gc = gccons.newInstance(null);
1381 setvar.invoke(gc, new Object[] { "Jalview", this});
1382 run.invoke(gc, null);
1384 catch (Exception ex)
1386 jalview.bin.Cache.log.error("Groovy Shell Creation failed.",ex);
1387 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1389 "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.", "Jalview Groovy Support Failed",
1390 JOptionPane.ERROR_MESSAGE);