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.*;
37 extends jalview.jbgui.GDesktop implements DropTargetListener,
41 public static Desktop instance;
42 public static JDesktopPane desktop;
43 static int openFrameCount = 0;
44 static final int xOffset = 30;
45 static final int yOffset = 30;
46 public static jalview.ws.Discoverer discoverer;
48 public static Object[] jalviewClipboard;
49 public static boolean internalCopy = false;
51 static int fileLoadingCount = 0;
54 * Creates a new Desktop object.
59 doVamsasClientCheck();
64 java.net.URL url = getClass().getResource("/images/logo.gif");
68 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
70 MediaTracker mt = new MediaTracker(this);
71 mt.addImage(image, 0);
80 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
81 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
82 desktop = new JDesktopPane();
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.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
119 /////////Add a splashscreen on startup
120 /////////Add a splashscreen on startup
121 JInternalFrame frame = new JInternalFrame();
123 SplashScreen splash = new SplashScreen(frame, image);
124 frame.setContentPane(splash);
125 frame.setLayer(JLayeredPane.PALETTE_LAYER);
126 frame.setLocation( (int) ( (getWidth() - 750) / 2),
127 (int) ( (getHeight() - 160) / 2));
129 addInternalFrame(frame, "", 750, 160, false);
131 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
134 private void doVamsasClientCheck()
136 if (jalview.bin.Cache.vamsasJarsPresent())
138 VamsasMenu.setVisible(true);
139 vamsasLoad.setVisible(true);
147 * @param frame DOCUMENT ME!
148 * @param title DOCUMENT ME!
149 * @param w DOCUMENT ME!
150 * @param h DOCUMENT ME!
152 public static synchronized void addInternalFrame(final JInternalFrame frame,
153 String title, int w, int h)
155 addInternalFrame(frame, title, w, h, true);
161 * @param frame DOCUMENT ME!
162 * @param title DOCUMENT ME!
163 * @param w DOCUMENT ME!
164 * @param h DOCUMENT ME!
165 * @param resizable DOCUMENT ME!
167 public static synchronized void addInternalFrame(final JInternalFrame frame,
168 String title, int w, int h, boolean resizable)
171 frame.setTitle(title);
172 if (frame.getWidth() < 1 || frame.getHeight() < 1)
176 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
177 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
178 // IF JALVIEW IS RUNNING HEADLESS
179 /////////////////////////////////////////////////
180 if (System.getProperty("java.awt.headless") != null
181 && System.getProperty("java.awt.headless").equals("true"))
188 frame.setVisible(true);
189 frame.setClosable(true);
190 frame.setResizable(resizable);
191 frame.setMaximizable(resizable);
192 frame.setIconifiable(resizable);
193 frame.setFrameIcon(null);
195 if (frame.getX() < 1 && frame.getY() < 1)
197 frame.setLocation(xOffset * openFrameCount,
198 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
201 final JMenuItem menuItem = new JMenuItem(title);
202 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
204 public void internalFrameActivated(javax.swing.event.
205 InternalFrameEvent evt)
207 JInternalFrame itf = desktop.getSelectedFrame();
215 public void internalFrameClosed(
216 javax.swing.event.InternalFrameEvent evt)
218 PaintRefresher.RemoveComponent(frame);
220 windowMenu.remove(menuItem);
221 JInternalFrame itf = desktop.getSelectedFrame();
230 menuItem.addActionListener(new ActionListener()
232 public void actionPerformed(ActionEvent e)
236 frame.setSelected(true);
237 frame.setIcon(false);
239 catch (java.beans.PropertyVetoException ex)
246 windowMenu.add(menuItem);
252 frame.setSelected(true);
253 frame.requestFocus();
255 catch (java.beans.PropertyVetoException ve)
259 public void lostOwnership(Clipboard clipboard, Transferable contents)
263 Desktop.jalviewClipboard = null;
266 internalCopy = false;
269 public void dragEnter(DropTargetDragEvent evt)
272 public void dragExit(DropTargetEvent evt)
275 public void dragOver(DropTargetDragEvent evt)
278 public void dropActionChanged(DropTargetDragEvent evt)
284 * @param evt DOCUMENT ME!
286 public void drop(DropTargetDropEvent evt)
288 Transferable t = evt.getTransferable();
289 java.util.List files = null;
293 DataFlavor uriListFlavor = new DataFlavor(
294 "text/uri-list;class=java.lang.String");
295 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
297 //Works on Windows and MacOSX
298 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
299 files = (java.util.List) t.getTransferData(DataFlavor.
302 else if (t.isDataFlavorSupported(uriListFlavor))
304 // This is used by Unix drag system
305 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
306 String data = (String) t.getTransferData(uriListFlavor);
307 files = new java.util.ArrayList(1);
308 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
311 st.hasMoreTokens(); )
313 String s = st.nextToken();
314 if (s.startsWith("#"))
316 // the line is a comment (as per the RFC 2483)
320 java.net.URI uri = new java.net.URI(s);
321 java.io.File file = new java.io.File(uri);
333 for (int i = 0; i < files.size(); i++)
335 String file = files.get(i).toString();
336 String protocol = FormatAdapter.FILE;
337 String format = null;
339 if (file.endsWith(".jar"))
346 format = new IdentifyFile().Identify(file,
350 new FileLoader().LoadFile(file, protocol, format);
362 * @param e DOCUMENT ME!
364 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
366 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
371 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
376 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
377 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
379 chooser.setFileView(new JalviewFileView());
380 chooser.setDialogTitle("Open local file");
381 chooser.setToolTipText("Open");
383 int value = chooser.showOpenDialog(this);
385 if (value == JalviewFileChooser.APPROVE_OPTION)
387 String choice = chooser.getSelectedFile().getPath();
388 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
389 chooser.getSelectedFile().getParent());
391 String format = null;
392 if (chooser.getSelectedFormat().equals("Jalview"))
398 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
401 if (viewport != null)
403 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
407 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
415 * @param e DOCUMENT ME!
417 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
419 // This construct allows us to have a wider textfield
421 JLabel label = new JLabel("Enter URL of Input File");
422 final JComboBox history = new JComboBox();
424 JPanel panel = new JPanel(new GridLayout(2, 1));
427 history.setPreferredSize(new Dimension(400, 20));
428 history.setEditable(true);
429 history.addItem("http://www.");
431 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
435 if (historyItems != null)
437 st = new StringTokenizer(historyItems, "\t");
439 while (st.hasMoreTokens())
441 history.addItem(st.nextElement());
445 int reply = JOptionPane.showInternalConfirmDialog(desktop,
446 panel, "Input Alignment From URL",
447 JOptionPane.OK_CANCEL_OPTION);
449 if (reply != JOptionPane.OK_OPTION)
454 String url = history.getSelectedItem().toString();
456 if (url.toLowerCase().endsWith(".jar"))
458 if (viewport != null)
460 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
464 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
469 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
471 if (format.equals("URL NOT FOUND"))
473 JOptionPane.showInternalMessageDialog(Desktop.desktop,
474 "Couldn't locate " + url,
476 JOptionPane.WARNING_MESSAGE);
481 if (viewport != null)
483 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
487 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
495 * @param e DOCUMENT ME!
497 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
499 CutAndPasteTransfer cap = new CutAndPasteTransfer();
500 cap.setForInput(viewport);
501 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
509 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
510 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
511 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
512 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
519 * @param e DOCUMENT ME!
521 public void aboutMenuItem_actionPerformed(ActionEvent e)
523 StringBuffer message = new StringBuffer("JalView version " +
524 jalview.bin.Cache.getProperty(
528 Cache.getDefault("BUILD_DATE",
531 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
532 jalview.bin.Cache.getProperty("VERSION")))
534 message.append("\n\n!! Jalview version "
535 + jalview.bin.Cache.getProperty("LATEST_VERSION")
537 " is available for download from http://www.jalview.org !!\n");
541 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
542 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
543 "\nFor all issues relating to Jalview, email help@jalview.org" +
544 "\n\nIf you use JalView, please cite:" +
545 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
546 "\nBioinformatics, 2004 20;426-7.");
548 JOptionPane.showInternalMessageDialog(Desktop.desktop,
550 message.toString(), "About Jalview",
551 JOptionPane.INFORMATION_MESSAGE);
557 * @param e DOCUMENT ME!
559 public void documentationMenuItem_actionPerformed(ActionEvent e)
563 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
564 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
565 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
567 javax.help.HelpBroker hb = hs.createHelpBroker();
568 hb.setCurrentID("home");
569 hb.setDisplayed(true);
575 public void closeAll_actionPerformed(ActionEvent e)
577 JInternalFrame[] frames = desktop.getAllFrames();
578 for (int i = 0; i < frames.length; i++)
582 frames[i].setClosed(true);
584 catch (java.beans.PropertyVetoException ex)
589 public void raiseRelated_actionPerformed(ActionEvent e)
591 reorderAssociatedWindows(false, false);
594 public void minimizeAssociated_actionPerformed(ActionEvent e)
596 reorderAssociatedWindows(true, false);
599 void closeAssociatedWindows()
601 reorderAssociatedWindows(false, true);
604 void reorderAssociatedWindows(boolean minimize, boolean close)
606 JInternalFrame[] frames = desktop.getAllFrames();
607 if (frames == null || frames.length < 1)
612 AlignViewport source = null, target = null;
613 if (frames[0] instanceof AlignFrame)
615 source = ( (AlignFrame) frames[0]).getCurrentView();
617 else if (frames[0] instanceof TreePanel)
619 source = ( (TreePanel) frames[0]).getViewPort();
621 else if (frames[0] instanceof PCAPanel)
623 source = ( (PCAPanel) frames[0]).av;
625 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
627 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
632 for (int i = 0; i < frames.length; i++)
635 if (frames[i] == null)
639 if (frames[i] instanceof AlignFrame)
641 target = ( (AlignFrame) frames[i]).getCurrentView();
643 else if (frames[i] instanceof TreePanel)
645 target = ( (TreePanel) frames[i]).getViewPort();
647 else if (frames[i] instanceof PCAPanel)
649 target = ( (PCAPanel) frames[i]).av;
651 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
653 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
656 if (source == target)
662 frames[i].setClosed(true);
666 frames[i].setIcon(minimize);
674 catch (java.beans.PropertyVetoException ex)
684 * @param e DOCUMENT ME!
686 protected void preferences_actionPerformed(ActionEvent e)
694 * @param e DOCUMENT ME!
696 public void saveState_actionPerformed(ActionEvent e)
698 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
700 "LAST_DIRECTORY"), new String[]
703 {"Jalview Project"}, "Jalview Project");
705 chooser.setFileView(new JalviewFileView());
706 chooser.setDialogTitle("Save State");
708 int value = chooser.showSaveDialog(this);
710 if (value == JalviewFileChooser.APPROVE_OPTION)
712 java.io.File choice = chooser.getSelectedFile();
713 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
714 new Jalview2XML().SaveState(choice);
721 * @param e DOCUMENT ME!
723 public void loadState_actionPerformed(ActionEvent e)
725 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
727 "LAST_DIRECTORY"), new String[]
730 {"Jalview Project"}, "Jalview Project");
731 chooser.setFileView(new JalviewFileView());
732 chooser.setDialogTitle("Restore state");
734 int value = chooser.showOpenDialog(this);
736 if (value == JalviewFileChooser.APPROVE_OPTION)
738 String choice = chooser.getSelectedFile().getAbsolutePath();
739 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
740 chooser.getSelectedFile().getParent());
741 new Jalview2XML().LoadJalviewAlign(choice);
745 /* public void vamsasLoad_actionPerformed(ActionEvent e)
747 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
748 getProperty("LAST_DIRECTORY"));
750 chooser.setFileView(new JalviewFileView());
751 chooser.setDialogTitle("Load Vamsas file");
752 chooser.setToolTipText("Import");
754 int value = chooser.showOpenDialog(this);
756 if (value == JalviewFileChooser.APPROVE_OPTION)
758 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
760 chooser.getSelectedFile().getAbsolutePath()
767 public void inputSequence_actionPerformed(ActionEvent e)
769 new SequenceFetcher(null);
772 JPanel progressPanel;
774 public void startLoading(final String fileName)
776 if (fileLoadingCount == 0)
778 progressPanel = new JPanel(new BorderLayout());
779 JProgressBar progressBar = new JProgressBar();
780 progressBar.setIndeterminate(true);
782 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
785 progressPanel.add(progressBar, BorderLayout.CENTER);
787 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
793 public void stopLoading()
796 if (fileLoadingCount < 1)
798 if (progressPanel != null)
800 this.getContentPane().remove(progressPanel);
801 progressPanel = null;
803 fileLoadingCount = 0;
808 public static int getViewCount(String viewId)
811 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
812 for (int t = 0; t < frames.length; t++)
814 if (frames[t] instanceof AlignFrame)
816 AlignFrame af = (AlignFrame) frames[t];
817 for (int a = 0; a < af.alignPanels.size(); a++)
820 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
833 public void explodeViews(AlignFrame af)
835 int size = af.alignPanels.size();
841 for (int i = 0; i < size; i++)
843 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
844 AlignFrame newaf = new AlignFrame(ap);
845 if (ap.av.explodedPosition != null &&
846 !ap.av.explodedPosition.equals(af.getBounds()))
848 newaf.setBounds(ap.av.explodedPosition);
851 ap.av.gatherViewsHere = false;
853 addInternalFrame(newaf, af.getTitle(),
854 AlignFrame.DEFAULT_WIDTH,
855 AlignFrame.DEFAULT_HEIGHT);
858 af.alignPanels.clear();
859 af.closeMenuItem_actionPerformed(true);
863 public void gatherViews(AlignFrame source)
865 source.viewport.gatherViewsHere = true;
866 source.viewport.explodedPosition = source.getBounds();
867 JInternalFrame[] frames = desktop.getAllFrames();
868 String viewId = source.viewport.sequenceSetID;
870 for (int t = 0; t < frames.length; t++)
872 if (frames[t] instanceof AlignFrame && frames[t] != source)
874 AlignFrame af = (AlignFrame) frames[t];
875 boolean gatherThis = false;
876 for (int a = 0; a < af.alignPanels.size(); a++)
878 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
879 if (viewId.equals(ap.av.getSequenceSetId()))
882 ap.av.gatherViewsHere = false;
883 ap.av.explodedPosition = af.getBounds();
884 source.addAlignmentPanel(ap, false);
890 af.alignPanels.clear();
891 af.closeMenuItem_actionPerformed(true);
898 jalview.gui.VamsasClient v_client = null;
899 public void vamsasLoad_actionPerformed(ActionEvent e)
901 if (v_client == null)
904 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
905 getProperty("LAST_DIRECTORY"));
907 chooser.setFileView(new JalviewFileView());
908 chooser.setDialogTitle("Load Vamsas file");
909 chooser.setToolTipText("Import");
911 int value = chooser.showOpenDialog(this);
913 if (value == JalviewFileChooser.APPROVE_OPTION)
915 v_client = new jalview.gui.VamsasClient(this,
916 chooser.getSelectedFile());
917 this.vamsasLoad.setText("Session Update");
918 this.vamsasStop.setVisible(true);
919 v_client.initial_update();
920 v_client.startWatcher();
925 // store current data in session.
926 v_client.push_update();
930 public void vamsasStop_actionPerformed(ActionEvent e)
932 if (v_client != null)
934 v_client.end_session();
936 this.vamsasStop.setVisible(false);
937 this.vamsasLoad.setText("Start Vamsas Session...");
942 * hide vamsas user gui bits when a vamsas document event is being handled.
943 * @param b true to hide gui, false to reveal gui
945 public void setVamsasUpdate(boolean b)
947 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
948 (b ? "in progress" : "finished"));
949 vamsasLoad.setVisible(!b);
950 vamsasStop.setVisible(!b);
955 * Checks the given url to see if it gives a response indicating that
956 * the user should be informed of a new questionnaire.
959 public void checkForQuestionnaire(String url)
961 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
962 javax.swing.SwingUtilities.invokeLater(jvq);