2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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.*;
38 public class Desktop extends jalview.jbgui.GDesktop
39 implements DropTargetListener, ClipboardOwner
42 public static Desktop instance;
43 public static JDesktopPane desktop;
44 static int openFrameCount = 0;
45 static final int xOffset = 30;
46 static final int yOffset = 30;
47 public static jalview.ws.Discoverer discoverer;
49 public static Object [] jalviewClipboard;
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() {
135 if (jalview.bin.Cache.vamsasJarsPresent()) {
136 VamsasMenu.setVisible(true);
137 vamsasLoad.setVisible(true);
145 * @param frame DOCUMENT ME!
146 * @param title DOCUMENT ME!
147 * @param w DOCUMENT ME!
148 * @param h DOCUMENT ME!
150 public static synchronized void addInternalFrame(final JInternalFrame frame,
151 String title, int w, int h)
153 addInternalFrame(frame, title, w, h, true);
159 * @param frame DOCUMENT ME!
160 * @param title DOCUMENT ME!
161 * @param w DOCUMENT ME!
162 * @param h DOCUMENT ME!
163 * @param resizable DOCUMENT ME!
165 public static synchronized void addInternalFrame(final JInternalFrame frame,
166 String title, int w, int h, boolean resizable)
169 frame.setTitle(title);
170 if(frame.getWidth()<1 || frame.getHeight()<1)
174 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
175 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
176 // IF JALVIEW IS RUNNING HEADLESS
177 /////////////////////////////////////////////////
178 if (System.getProperty("java.awt.headless") != null
179 && System.getProperty("java.awt.headless").equals("true"))
187 frame.setVisible(true);
188 frame.setClosable(true);
189 frame.setResizable(resizable);
190 frame.setMaximizable(resizable);
191 frame.setIconifiable(resizable);
192 frame.setFrameIcon(null);
194 if (frame.getX()<1 && frame.getY()<1)
196 frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);
199 final JMenuItem menuItem = new JMenuItem(title);
200 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
202 public void internalFrameActivated(javax.swing.event.
203 InternalFrameEvent evt)
205 JInternalFrame itf = desktop.getSelectedFrame();
212 public void internalFrameClosed(
213 javax.swing.event.InternalFrameEvent evt)
216 windowMenu.remove(menuItem);
217 JInternalFrame itf = desktop.getSelectedFrame();
224 menuItem.addActionListener(new ActionListener()
226 public void actionPerformed(ActionEvent e)
230 frame.setSelected(true);
231 frame.setIcon(false);
233 catch (java.beans.PropertyVetoException ex)
240 windowMenu.add(menuItem);
245 frame.setSelected(true);
246 frame.requestFocus();
247 }catch(java.beans.PropertyVetoException ve)
251 public void lostOwnership(Clipboard clipboard, Transferable contents)
253 Desktop.jalviewClipboard = null;
256 public void dragEnter(DropTargetDragEvent evt)
259 public void dragExit(DropTargetEvent evt)
262 public void dragOver(DropTargetDragEvent evt)
265 public void dropActionChanged(DropTargetDragEvent evt)
271 * @param evt DOCUMENT ME!
273 public void drop(DropTargetDropEvent evt)
275 Transferable t = evt.getTransferable();
276 java.util.List files = null;
280 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
281 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
283 //Works on Windows and MacOSX
284 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
285 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
287 else if (t.isDataFlavorSupported(uriListFlavor))
289 // This is used by Unix drag system
290 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
291 String data = (String) t.getTransferData(uriListFlavor);
292 files = new java.util.ArrayList(1);
293 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
296 st.hasMoreTokens(); )
298 String s = st.nextToken();
299 if (s.startsWith("#"))
301 // the line is a comment (as per the RFC 2483)
305 java.net.URI uri = new java.net.URI(s);
306 java.io.File file = new java.io.File(uri);
318 for (int i = 0; i < files.size(); i++)
320 String file = files.get(i).toString();
321 String protocol = FormatAdapter.FILE;
322 String format = null;
324 if (file.endsWith(".jar"))
331 format = new IdentifyFile().Identify(file,
336 new FileLoader().LoadFile(file, protocol, format);
348 * @param e DOCUMENT ME!
350 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
352 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
356 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
361 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
362 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
364 chooser.setFileView(new JalviewFileView());
365 chooser.setDialogTitle("Open local file");
366 chooser.setToolTipText("Open");
368 int value = chooser.showOpenDialog(this);
370 if (value == JalviewFileChooser.APPROVE_OPTION)
372 String choice = chooser.getSelectedFile().getPath();
373 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
374 chooser.getSelectedFile().getParent());
376 String format = null;
377 if (chooser.getSelectedFormat().equals("Jalview"))
383 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
386 if (viewport != null)
387 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
389 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
398 * @param e DOCUMENT ME!
400 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
402 // This construct allows us to have a wider textfield
404 JLabel label = new JLabel("Enter URL of Input File");
405 final JComboBox history = new JComboBox();
407 JPanel panel = new JPanel(new GridLayout(2,1));
410 history.setPreferredSize(new Dimension(400,20));
411 history.setEditable(true);
412 history.addItem("http://www.");
414 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
418 if (historyItems != null)
420 st = new StringTokenizer(historyItems, "\t");
422 while (st.hasMoreTokens())
424 history.addItem(st.nextElement());
428 int reply = JOptionPane.showInternalConfirmDialog(desktop,
429 panel, "Input Alignment From URL",
430 JOptionPane.OK_CANCEL_OPTION );
433 if (reply != JOptionPane.OK_OPTION )
438 String url = history.getSelectedItem().toString();
440 if (url.toLowerCase().endsWith(".jar"))
442 if (viewport != null)
443 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
445 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
449 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
451 if (format.equals("URL NOT FOUND"))
453 JOptionPane.showInternalMessageDialog(Desktop.desktop,
454 "Couldn't locate " + url,
456 JOptionPane.WARNING_MESSAGE);
461 if (viewport != null)
462 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
464 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
471 * @param e DOCUMENT ME!
473 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
475 CutAndPasteTransfer cap = new CutAndPasteTransfer();
476 cap.setForInput(viewport);
477 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
485 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
486 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
487 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
488 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
495 * @param e DOCUMENT ME!
497 public void aboutMenuItem_actionPerformed(ActionEvent e)
499 StringBuffer message = new StringBuffer("JalView version " +
500 jalview.bin.Cache.getProperty(
504 Cache.getDefault("BUILD_DATE", "unknown"));
506 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
507 jalview.bin.Cache.getProperty("VERSION")))
509 message.append("\n\n!! Jalview version "
510 + jalview.bin.Cache.getProperty("LATEST_VERSION")
511 + " is available for download from http://www.jalview.org !!\n");
515 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
516 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
517 "\nFor all issues relating to Jalview, email help@jalview.org" +
518 "\n\nIf you use JalView, please cite:" +
519 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
520 "\nBioinformatics, 2004 20;426-7.");
522 JOptionPane.showInternalMessageDialog(Desktop.desktop,
524 message.toString(), "About Jalview",
525 JOptionPane.INFORMATION_MESSAGE);
531 * @param e DOCUMENT ME!
533 public void documentationMenuItem_actionPerformed(ActionEvent e)
537 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
538 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
539 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
541 javax.help.HelpBroker hb = hs.createHelpBroker();
542 hb.setCurrentID("home");
543 hb.setDisplayed(true);
549 public void closeAll_actionPerformed(ActionEvent e)
551 JInternalFrame [] frames = desktop.getAllFrames();
552 for(int i=0; i<frames.length; i++)
555 frames[i].setClosed(true);
556 }catch(java.beans.PropertyVetoException ex){}
560 public void raiseRelated_actionPerformed(ActionEvent e)
562 reorderAssociatedWindows(false, false);
565 public void minimizeAssociated_actionPerformed(ActionEvent e)
567 reorderAssociatedWindows(true, false);
570 void closeAssociatedWindows()
572 reorderAssociatedWindows(false, true);
575 void reorderAssociatedWindows(boolean minimize, boolean close)
577 JInternalFrame[] frames = desktop.getAllFrames();
578 if (frames == null || frames.length<1)
581 AlignViewport source = null, target = null;
582 if (frames[0] instanceof AlignFrame)
583 source = ( (AlignFrame) frames[0]).getCurrentView();
584 else if (frames[0] instanceof TreePanel)
585 source = ( (TreePanel) frames[0]).getViewPort();
586 else if (frames[0] instanceof PCAPanel)
587 source = ( (PCAPanel) frames[0]).av;
588 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
589 source = ((PairwiseAlignPanel)frames[0].getContentPane()).av;
593 for (int i = 0; i < frames.length; i++)
600 if (frames[i] instanceof AlignFrame)
601 target = ( (AlignFrame) frames[i]).getCurrentView();
602 else if (frames[i] instanceof TreePanel)
603 target = ( (TreePanel) frames[i]).getViewPort();
604 else if (frames[i] instanceof PCAPanel)
605 target = ( (PCAPanel) frames[i]).av;
606 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
607 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
609 if (source == target)
614 frames[i].setClosed(true);
617 frames[i].setIcon(minimize);
625 catch (java.beans.PropertyVetoException ex)
636 * @param e DOCUMENT ME!
638 protected void preferences_actionPerformed(ActionEvent e)
646 * @param e DOCUMENT ME!
648 public void saveState_actionPerformed(ActionEvent e)
650 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
651 "LAST_DIRECTORY"), new String[] { "jar" },
652 new String[] { "Jalview Project" }, "Jalview Project");
654 chooser.setFileView(new JalviewFileView());
655 chooser.setDialogTitle("Save State");
657 int value = chooser.showSaveDialog(this);
659 if (value == JalviewFileChooser.APPROVE_OPTION)
661 java.io.File choice = chooser.getSelectedFile();
662 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
663 new Jalview2XML().SaveState(choice);
670 * @param e DOCUMENT ME!
672 public void loadState_actionPerformed(ActionEvent e)
674 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
675 "LAST_DIRECTORY"), new String[] { "jar" },
676 new String[] { "Jalview Project" }, "Jalview Project");
677 chooser.setFileView(new JalviewFileView());
678 chooser.setDialogTitle("Restore state");
680 int value = chooser.showOpenDialog(this);
682 if (value == JalviewFileChooser.APPROVE_OPTION)
684 String choice = chooser.getSelectedFile().getAbsolutePath();
685 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
686 chooser.getSelectedFile().getParent());
687 new Jalview2XML().LoadJalviewAlign(choice);
691 /* public void vamsasLoad_actionPerformed(ActionEvent e)
693 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
694 getProperty("LAST_DIRECTORY"));
696 chooser.setFileView(new JalviewFileView());
697 chooser.setDialogTitle("Load Vamsas file");
698 chooser.setToolTipText("Import");
700 int value = chooser.showOpenDialog(this);
702 if (value == JalviewFileChooser.APPROVE_OPTION)
704 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
706 chooser.getSelectedFile().getAbsolutePath()
713 public void inputSequence_actionPerformed(ActionEvent e)
715 new SequenceFetcher(null);
718 JPanel progressPanel;
720 public void startLoading(final String fileName)
722 if (fileLoadingCount == 0)
724 progressPanel = new JPanel(new BorderLayout());
725 JProgressBar progressBar = new JProgressBar();
726 progressBar.setIndeterminate(true);
728 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
731 progressPanel.add(progressBar, BorderLayout.CENTER);
733 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
739 public void stopLoading()
742 if (fileLoadingCount < 1)
744 if(progressPanel!=null)
746 this.getContentPane().remove(progressPanel);
747 progressPanel = null;
749 fileLoadingCount = 0;
754 public static int getViewCount(String viewId)
757 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
758 for (int t = 0; t < frames.length; t++)
760 if (frames[t] instanceof AlignFrame)
762 AlignFrame af = (AlignFrame) frames[t];
763 for(int a=0; a<af.alignPanels.size(); a++)
766 ((AlignmentPanel)af.alignPanels.elementAt(a)).av.getSequenceSetId() )
776 public void explodeViews(AlignFrame af)
778 int size = af.alignPanels.size();
782 for(int i=0; i<size; i++)
784 AlignmentPanel ap = (AlignmentPanel)af.alignPanels.elementAt(i);
785 AlignFrame newaf = new AlignFrame(ap);
786 if(ap.av.explodedPosition!=null)
787 newaf.setBounds(ap.av.explodedPosition);
789 ap.av.gatherViewsHere = false;
791 addInternalFrame(newaf, af.getTitle(),
792 AlignFrame.DEFAULT_WIDTH,
793 AlignFrame.DEFAULT_HEIGHT);
796 af.alignPanels.clear();
797 af.closeMenuItem_actionPerformed(true);
801 public void gatherViews(AlignFrame source)
803 source.viewport.gatherViewsHere = true;
804 source.viewport.explodedPosition = source.getBounds();
805 JInternalFrame[] frames = desktop.getAllFrames();
806 String viewId = source.viewport.sequenceSetID;
808 for (int t = 0; t < frames.length; t++)
810 if (frames[t] instanceof AlignFrame && frames[t] != source)
812 AlignFrame af = (AlignFrame) frames[t];
813 boolean gatherThis = false;
814 for (int a = 0; a < af.alignPanels.size(); a++)
816 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
817 if (viewId.equals(ap.av.getSequenceSetId()))
820 ap.av.gatherViewsHere = false;
821 ap.av.explodedPosition = af.getBounds();
822 source.addAlignmentPanel(ap, false);
828 af.alignPanels.clear();
829 af.closeMenuItem_actionPerformed(true);
836 jalview.gui.VamsasClient v_client=null;
837 public void vamsasLoad_actionPerformed(ActionEvent e)
839 if (v_client==null) {
841 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
842 getProperty("LAST_DIRECTORY"));
844 chooser.setFileView(new JalviewFileView());
845 chooser.setDialogTitle("Load Vamsas file");
846 chooser.setToolTipText("Import");
848 int value = chooser.showOpenDialog(this);
850 if (value == JalviewFileChooser.APPROVE_OPTION)
852 v_client = new jalview.gui.VamsasClient(this,
853 chooser.getSelectedFile());
854 this.vamsasLoad.setText("Session Update");
855 this.vamsasStop.setVisible(true);
856 v_client.initial_update();
857 v_client.startWatcher();
860 // store current data in session.
861 v_client.push_update();
864 public void vamsasStop_actionPerformed(ActionEvent e) {
865 if (v_client!=null) {
866 v_client.end_session();
868 this.vamsasStop.setVisible(false);
869 this.vamsasLoad.setText("Start Vamsas Session...");
873 * hide vamsas user gui bits when a vamsas document event is being handled.
874 * @param b true to hide gui, false to reveal gui
876 public void setVamsasUpdate(boolean b) {
877 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "+(b ? "in progress" : "finished"));
878 vamsasLoad.setVisible(!b);
879 vamsasStop.setVisible(!b);