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();
211 public void internalFrameClosed(
212 javax.swing.event.InternalFrameEvent evt)
215 windowMenu.remove(menuItem);
216 JInternalFrame itf = desktop.getSelectedFrame();
223 menuItem.addActionListener(new ActionListener()
225 public void actionPerformed(ActionEvent e)
229 frame.setSelected(true);
230 frame.setIcon(false);
232 catch (java.beans.PropertyVetoException ex)
239 windowMenu.add(menuItem);
244 frame.setSelected(true);
245 frame.requestFocus();
246 }catch(java.beans.PropertyVetoException ve)
250 public void lostOwnership(Clipboard clipboard, Transferable contents)
252 Desktop.jalviewClipboard = null;
255 public void dragEnter(DropTargetDragEvent evt)
258 public void dragExit(DropTargetEvent evt)
261 public void dragOver(DropTargetDragEvent evt)
264 public void dropActionChanged(DropTargetDragEvent evt)
270 * @param evt DOCUMENT ME!
272 public void drop(DropTargetDropEvent evt)
274 Transferable t = evt.getTransferable();
275 java.util.List files = null;
279 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
280 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
282 //Works on Windows and MacOSX
283 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
284 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
286 else if (t.isDataFlavorSupported(uriListFlavor))
288 // This is used by Unix drag system
289 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
290 String data = (String) t.getTransferData(uriListFlavor);
291 files = new java.util.ArrayList(1);
292 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
295 st.hasMoreTokens(); )
297 String s = st.nextToken();
298 if (s.startsWith("#"))
300 // the line is a comment (as per the RFC 2483)
304 java.net.URI uri = new java.net.URI(s);
305 java.io.File file = new java.io.File(uri);
319 for (int i = 0; i < files.size(); i++)
321 String file = files.get(i).toString();
322 String protocol = FormatAdapter.FILE;
323 String format = null;
325 if (file.endsWith(".jar"))
332 format = new IdentifyFile().Identify(file,
337 new FileLoader().LoadFile(file, protocol, format);
343 ex.printStackTrace();
351 * @param e DOCUMENT ME!
353 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
355 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
359 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
364 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
365 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
367 chooser.setFileView(new JalviewFileView());
368 chooser.setDialogTitle("Open local file");
369 chooser.setToolTipText("Open");
371 int value = chooser.showOpenDialog(this);
373 if (value == JalviewFileChooser.APPROVE_OPTION)
375 String choice = chooser.getSelectedFile().getPath();
376 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
377 chooser.getSelectedFile().getParent());
379 String format = null;
380 if (chooser.getSelectedFormat().equals("Jalview"))
386 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
389 if (viewport != null)
390 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
392 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
401 * @param e DOCUMENT ME!
403 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
405 // This construct allows us to have a wider textfield
407 JLabel label = new JLabel("Enter URL of Input File");
408 final JComboBox history = new JComboBox();
410 JPanel panel = new JPanel(new GridLayout(2,1));
413 history.setPreferredSize(new Dimension(400,20));
414 history.setEditable(true);
415 history.addItem("http://www.");
417 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
421 if (historyItems != null)
423 st = new StringTokenizer(historyItems, "\t");
425 while (st.hasMoreTokens())
427 history.addItem(st.nextElement());
431 int reply = JOptionPane.showInternalConfirmDialog(desktop,
432 panel, "Input Alignment From URL",
433 JOptionPane.OK_CANCEL_OPTION );
436 if (reply != JOptionPane.OK_OPTION )
441 String url = history.getSelectedItem().toString();
443 if (url.toLowerCase().endsWith(".jar"))
445 if (viewport != null)
446 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
448 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
452 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
454 if (format.equals("URL NOT FOUND"))
456 JOptionPane.showInternalMessageDialog(Desktop.desktop,
457 "Couldn't locate " + url,
459 JOptionPane.WARNING_MESSAGE);
464 if (viewport != null)
465 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
467 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
474 * @param e DOCUMENT ME!
476 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
478 CutAndPasteTransfer cap = new CutAndPasteTransfer();
479 cap.setForInput(viewport);
480 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
488 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
489 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
490 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
491 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
498 * @param e DOCUMENT ME!
500 public void aboutMenuItem_actionPerformed(ActionEvent e)
502 StringBuffer message = new StringBuffer("JalView version " +
503 jalview.bin.Cache.getProperty(
507 Cache.getDefault("BUILD_DATE", "unknown"));
509 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
510 jalview.bin.Cache.getProperty("VERSION")))
512 message.append("\n\n!! Jalview version "
513 + jalview.bin.Cache.getProperty("LATEST_VERSION")
514 + " is available for download from http://www.jalview.org !!\n");
518 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
519 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
520 "\nFor all issues relating to Jalview, email help@jalview.org" +
521 "\n\nIf you use JalView, please cite:" +
522 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
523 "\nBioinformatics, 2004 20;426-7.");
525 JOptionPane.showInternalMessageDialog(Desktop.desktop,
527 message.toString(), "About Jalview",
528 JOptionPane.INFORMATION_MESSAGE);
534 * @param e DOCUMENT ME!
536 public void documentationMenuItem_actionPerformed(ActionEvent e)
540 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
541 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
542 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
544 javax.help.HelpBroker hb = hs.createHelpBroker();
545 hb.setCurrentID("home");
546 hb.setDisplayed(true);
550 ex.printStackTrace();
554 public void closeAll_actionPerformed(ActionEvent e)
556 JInternalFrame [] frames = desktop.getAllFrames();
557 for(int i=0; i<frames.length; i++)
560 frames[i].setClosed(true);
561 }catch(java.beans.PropertyVetoException ex){}
565 public void raiseRelated_actionPerformed(ActionEvent e)
567 reorderAssociatedWindows(false);
570 public void minimizeAssociated_actionPerformed(ActionEvent e)
572 reorderAssociatedWindows(true);
575 void reorderAssociatedWindows(boolean minimize)
577 JInternalFrame[] frames = desktop.getAllFrames();
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;
590 for (int i = 0; i < frames.length; i++)
593 if (frames[i] instanceof AlignFrame)
594 target = ( (AlignFrame) frames[i]).getCurrentView();
595 else if (frames[i] instanceof TreePanel)
596 target = ( (TreePanel) frames[i]).getViewPort();
597 else if (frames[i] instanceof PCAPanel)
598 target = ( (PCAPanel) frames[i]).av;
600 if (source == target)
606 frames[i].setIcon(minimize);
608 catch (java.beans.PropertyVetoException ex)
619 * @param e DOCUMENT ME!
621 protected void preferences_actionPerformed(ActionEvent e)
629 * @param e DOCUMENT ME!
631 public void saveState_actionPerformed(ActionEvent e)
633 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
634 "LAST_DIRECTORY"), new String[] { "jar" },
635 new String[] { "Jalview Project" }, "Jalview Project");
637 chooser.setFileView(new JalviewFileView());
638 chooser.setDialogTitle("Save State");
640 int value = chooser.showSaveDialog(this);
642 if (value == JalviewFileChooser.APPROVE_OPTION)
644 java.io.File choice = chooser.getSelectedFile();
645 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
646 new Jalview2XML().SaveState(choice);
653 * @param e DOCUMENT ME!
655 public void loadState_actionPerformed(ActionEvent e)
657 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
658 "LAST_DIRECTORY"), new String[] { "jar" },
659 new String[] { "Jalview Project" }, "Jalview Project");
660 chooser.setFileView(new JalviewFileView());
661 chooser.setDialogTitle("Restore state");
663 int value = chooser.showOpenDialog(this);
665 if (value == JalviewFileChooser.APPROVE_OPTION)
667 String choice = chooser.getSelectedFile().getAbsolutePath();
668 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
669 chooser.getSelectedFile().getParent());
670 new Jalview2XML().LoadJalviewAlign(choice);
674 /* public void vamsasLoad_actionPerformed(ActionEvent e)
676 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
677 getProperty("LAST_DIRECTORY"));
679 chooser.setFileView(new JalviewFileView());
680 chooser.setDialogTitle("Load Vamsas file");
681 chooser.setToolTipText("Import");
683 int value = chooser.showOpenDialog(this);
685 if (value == JalviewFileChooser.APPROVE_OPTION)
687 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
689 chooser.getSelectedFile().getAbsolutePath()
696 public void inputSequence_actionPerformed(ActionEvent e)
698 new SequenceFetcher(null);
701 JPanel progressPanel;
703 public void startLoading(final String fileName)
705 if (fileLoadingCount == 0)
707 progressPanel = new JPanel(new BorderLayout());
708 JProgressBar progressBar = new JProgressBar();
709 progressBar.setIndeterminate(true);
711 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
714 progressPanel.add(progressBar, BorderLayout.CENTER);
716 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
722 public void stopLoading()
725 if (fileLoadingCount < 1)
727 if(progressPanel!=null)
729 this.getContentPane().remove(progressPanel);
730 progressPanel = null;
732 fileLoadingCount = 0;
737 public static int getViewCount(String viewId)
740 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
741 for (int t = 0; t < frames.length; t++)
743 if (frames[t] instanceof AlignFrame)
745 AlignFrame af = (AlignFrame) frames[t];
746 for(int a=0; a<af.alignPanels.size(); a++)
749 ((AlignmentPanel)af.alignPanels.elementAt(a)).av.getSequenceSetId() )
759 public void explodeViews(AlignFrame af)
761 int size = af.alignPanels.size();
765 for(int i=0; i<size; i++)
767 AlignmentPanel ap = (AlignmentPanel)af.alignPanels.elementAt(i);
768 AlignFrame newaf = new AlignFrame(ap);
769 if(ap.av.explodedPosition!=null)
770 newaf.setBounds(ap.av.explodedPosition);
772 ap.av.gatherViewsHere = false;
774 addInternalFrame(newaf, af.getTitle(),
775 AlignFrame.DEFAULT_WIDTH,
776 AlignFrame.DEFAULT_HEIGHT);
779 af.alignPanels.clear();
780 af.closeMenuItem_actionPerformed(true);
784 public void gatherViews(AlignFrame source)
786 source.viewport.gatherViewsHere = true;
787 source.viewport.explodedPosition = source.getBounds();
788 JInternalFrame[] frames = desktop.getAllFrames();
789 String viewId = source.viewport.sequenceSetID;
791 for (int t = 0; t < frames.length; t++)
793 if (frames[t] instanceof AlignFrame && frames[t] != source)
795 AlignFrame af = (AlignFrame) frames[t];
796 boolean gatherThis = false;
797 for (int a = 0; a < af.alignPanels.size(); a++)
799 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
800 if (viewId.equals(ap.av.getSequenceSetId()))
803 ap.av.gatherViewsHere = false;
804 ap.av.explodedPosition = af.getBounds();
805 source.addAlignmentPanel(ap, false);
811 af.alignPanels.clear();
812 af.closeMenuItem_actionPerformed(true);
819 jalview.gui.VamsasClient v_client=null;
820 public void vamsasLoad_actionPerformed(ActionEvent e)
822 if (v_client==null) {
824 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
825 getProperty("LAST_DIRECTORY"));
827 chooser.setFileView(new JalviewFileView());
828 chooser.setDialogTitle("Load Vamsas file");
829 chooser.setToolTipText("Import");
831 int value = chooser.showOpenDialog(this);
833 if (value == JalviewFileChooser.APPROVE_OPTION)
835 v_client = new jalview.gui.VamsasClient(this,
836 chooser.getSelectedFile());
837 this.vamsasLoad.setText("Session Update");
838 this.vamsasStop.setVisible(true);
839 v_client.initial_update();
840 v_client.startWatcher();
843 // store current data in session.
844 v_client.push_update();
847 public void vamsasStop_actionPerformed(ActionEvent e) {
848 if (v_client!=null) {
849 v_client.end_session();
851 this.vamsasStop.setVisible(false);
852 this.vamsasLoad.setText("Start Vamsas Session...");
856 * hide vamsas user gui bits when a vamsas document event is being handled.
857 * @param b true to hide gui, false to reveal gui
859 public void setVamsasUpdate(boolean b) {
860 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "+(b ? "in progress" : "finished"));
861 vamsasLoad.setVisible(!b);
862 vamsasStop.setVisible(!b);