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)
215 PaintRefresher.RemoveComponent(frame);
217 windowMenu.remove(menuItem);
218 JInternalFrame itf = desktop.getSelectedFrame();
225 menuItem.addActionListener(new ActionListener()
227 public void actionPerformed(ActionEvent e)
231 frame.setSelected(true);
232 frame.setIcon(false);
234 catch (java.beans.PropertyVetoException ex)
241 windowMenu.add(menuItem);
246 frame.setSelected(true);
247 frame.requestFocus();
248 }catch(java.beans.PropertyVetoException ve)
252 public void lostOwnership(Clipboard clipboard, Transferable contents)
254 Desktop.jalviewClipboard = null;
257 public void dragEnter(DropTargetDragEvent evt)
260 public void dragExit(DropTargetEvent evt)
263 public void dragOver(DropTargetDragEvent evt)
266 public void dropActionChanged(DropTargetDragEvent evt)
272 * @param evt DOCUMENT ME!
274 public void drop(DropTargetDropEvent evt)
276 Transferable t = evt.getTransferable();
277 java.util.List files = null;
281 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
282 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
284 //Works on Windows and MacOSX
285 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
286 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
288 else if (t.isDataFlavorSupported(uriListFlavor))
290 // This is used by Unix drag system
291 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
292 String data = (String) t.getTransferData(uriListFlavor);
293 files = new java.util.ArrayList(1);
294 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
297 st.hasMoreTokens(); )
299 String s = st.nextToken();
300 if (s.startsWith("#"))
302 // the line is a comment (as per the RFC 2483)
306 java.net.URI uri = new java.net.URI(s);
307 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);
349 * @param e DOCUMENT ME!
351 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
353 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
357 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
362 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
363 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
365 chooser.setFileView(new JalviewFileView());
366 chooser.setDialogTitle("Open local file");
367 chooser.setToolTipText("Open");
369 int value = chooser.showOpenDialog(this);
371 if (value == JalviewFileChooser.APPROVE_OPTION)
373 String choice = chooser.getSelectedFile().getPath();
374 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
375 chooser.getSelectedFile().getParent());
377 String format = null;
378 if (chooser.getSelectedFormat().equals("Jalview"))
384 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
387 if (viewport != null)
388 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
390 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
399 * @param e DOCUMENT ME!
401 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
403 // This construct allows us to have a wider textfield
405 JLabel label = new JLabel("Enter URL of Input File");
406 final JComboBox history = new JComboBox();
408 JPanel panel = new JPanel(new GridLayout(2,1));
411 history.setPreferredSize(new Dimension(400,20));
412 history.setEditable(true);
413 history.addItem("http://www.");
415 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
419 if (historyItems != null)
421 st = new StringTokenizer(historyItems, "\t");
423 while (st.hasMoreTokens())
425 history.addItem(st.nextElement());
429 int reply = JOptionPane.showInternalConfirmDialog(desktop,
430 panel, "Input Alignment From URL",
431 JOptionPane.OK_CANCEL_OPTION );
434 if (reply != JOptionPane.OK_OPTION )
439 String url = history.getSelectedItem().toString();
441 if (url.toLowerCase().endsWith(".jar"))
443 if (viewport != null)
444 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
446 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
450 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
452 if (format.equals("URL NOT FOUND"))
454 JOptionPane.showInternalMessageDialog(Desktop.desktop,
455 "Couldn't locate " + url,
457 JOptionPane.WARNING_MESSAGE);
462 if (viewport != null)
463 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
465 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
472 * @param e DOCUMENT ME!
474 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
476 CutAndPasteTransfer cap = new CutAndPasteTransfer();
477 cap.setForInput(viewport);
478 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
486 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
487 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
488 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
489 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
496 * @param e DOCUMENT ME!
498 public void aboutMenuItem_actionPerformed(ActionEvent e)
500 StringBuffer message = new StringBuffer("JalView version " +
501 jalview.bin.Cache.getProperty(
505 Cache.getDefault("BUILD_DATE", "unknown"));
507 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
508 jalview.bin.Cache.getProperty("VERSION")))
510 message.append("\n\n!! Jalview version "
511 + jalview.bin.Cache.getProperty("LATEST_VERSION")
512 + " is available for download from http://www.jalview.org !!\n");
516 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
517 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
518 "\nFor all issues relating to Jalview, email help@jalview.org" +
519 "\n\nIf you use JalView, please cite:" +
520 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
521 "\nBioinformatics, 2004 20;426-7.");
523 JOptionPane.showInternalMessageDialog(Desktop.desktop,
525 message.toString(), "About Jalview",
526 JOptionPane.INFORMATION_MESSAGE);
532 * @param e DOCUMENT ME!
534 public void documentationMenuItem_actionPerformed(ActionEvent e)
538 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
539 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
540 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
542 javax.help.HelpBroker hb = hs.createHelpBroker();
543 hb.setCurrentID("home");
544 hb.setDisplayed(true);
550 public void closeAll_actionPerformed(ActionEvent e)
552 JInternalFrame [] frames = desktop.getAllFrames();
553 for(int i=0; i<frames.length; i++)
556 frames[i].setClosed(true);
557 }catch(java.beans.PropertyVetoException ex){}
561 public void raiseRelated_actionPerformed(ActionEvent e)
563 reorderAssociatedWindows(false, false);
566 public void minimizeAssociated_actionPerformed(ActionEvent e)
568 reorderAssociatedWindows(true, false);
571 void closeAssociatedWindows()
573 reorderAssociatedWindows(false, true);
576 void reorderAssociatedWindows(boolean minimize, boolean close)
578 JInternalFrame[] frames = desktop.getAllFrames();
579 if (frames == null || frames.length<1)
582 AlignViewport source = null, target = null;
583 if (frames[0] instanceof AlignFrame)
584 source = ( (AlignFrame) frames[0]).getCurrentView();
585 else if (frames[0] instanceof TreePanel)
586 source = ( (TreePanel) frames[0]).getViewPort();
587 else if (frames[0] instanceof PCAPanel)
588 source = ( (PCAPanel) frames[0]).av;
589 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
590 source = ((PairwiseAlignPanel)frames[0].getContentPane()).av;
594 for (int i = 0; i < frames.length; i++)
601 if (frames[i] instanceof AlignFrame)
602 target = ( (AlignFrame) frames[i]).getCurrentView();
603 else if (frames[i] instanceof TreePanel)
604 target = ( (TreePanel) frames[i]).getViewPort();
605 else if (frames[i] instanceof PCAPanel)
606 target = ( (PCAPanel) frames[i]).av;
607 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
608 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
610 if (source == target)
615 frames[i].setClosed(true);
618 frames[i].setIcon(minimize);
626 catch (java.beans.PropertyVetoException ex)
637 * @param e DOCUMENT ME!
639 protected void preferences_actionPerformed(ActionEvent e)
647 * @param e DOCUMENT ME!
649 public void saveState_actionPerformed(ActionEvent e)
651 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
652 "LAST_DIRECTORY"), new String[] { "jar" },
653 new String[] { "Jalview Project" }, "Jalview Project");
655 chooser.setFileView(new JalviewFileView());
656 chooser.setDialogTitle("Save State");
658 int value = chooser.showSaveDialog(this);
660 if (value == JalviewFileChooser.APPROVE_OPTION)
662 java.io.File choice = chooser.getSelectedFile();
663 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
664 new Jalview2XML().SaveState(choice);
671 * @param e DOCUMENT ME!
673 public void loadState_actionPerformed(ActionEvent e)
675 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
676 "LAST_DIRECTORY"), new String[] { "jar" },
677 new String[] { "Jalview Project" }, "Jalview Project");
678 chooser.setFileView(new JalviewFileView());
679 chooser.setDialogTitle("Restore state");
681 int value = chooser.showOpenDialog(this);
683 if (value == JalviewFileChooser.APPROVE_OPTION)
685 String choice = chooser.getSelectedFile().getAbsolutePath();
686 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
687 chooser.getSelectedFile().getParent());
688 new Jalview2XML().LoadJalviewAlign(choice);
692 /* public void vamsasLoad_actionPerformed(ActionEvent e)
694 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
695 getProperty("LAST_DIRECTORY"));
697 chooser.setFileView(new JalviewFileView());
698 chooser.setDialogTitle("Load Vamsas file");
699 chooser.setToolTipText("Import");
701 int value = chooser.showOpenDialog(this);
703 if (value == JalviewFileChooser.APPROVE_OPTION)
705 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
707 chooser.getSelectedFile().getAbsolutePath()
714 public void inputSequence_actionPerformed(ActionEvent e)
716 new SequenceFetcher(null);
719 JPanel progressPanel;
721 public void startLoading(final String fileName)
723 if (fileLoadingCount == 0)
725 progressPanel = new JPanel(new BorderLayout());
726 JProgressBar progressBar = new JProgressBar();
727 progressBar.setIndeterminate(true);
729 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
732 progressPanel.add(progressBar, BorderLayout.CENTER);
734 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
740 public void stopLoading()
743 if (fileLoadingCount < 1)
745 if(progressPanel!=null)
747 this.getContentPane().remove(progressPanel);
748 progressPanel = null;
750 fileLoadingCount = 0;
755 public static int getViewCount(String viewId)
758 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
759 for (int t = 0; t < frames.length; t++)
761 if (frames[t] instanceof AlignFrame)
763 AlignFrame af = (AlignFrame) frames[t];
764 for(int a=0; a<af.alignPanels.size(); a++)
767 ((AlignmentPanel)af.alignPanels.elementAt(a)).av.getSequenceSetId() )
777 public void explodeViews(AlignFrame af)
779 int size = af.alignPanels.size();
783 for(int i=0; i<size; i++)
785 AlignmentPanel ap = (AlignmentPanel)af.alignPanels.elementAt(i);
786 AlignFrame newaf = new AlignFrame(ap);
787 if(ap.av.explodedPosition!=null)
788 newaf.setBounds(ap.av.explodedPosition);
790 ap.av.gatherViewsHere = false;
792 addInternalFrame(newaf, af.getTitle(),
793 AlignFrame.DEFAULT_WIDTH,
794 AlignFrame.DEFAULT_HEIGHT);
797 af.alignPanels.clear();
798 af.closeMenuItem_actionPerformed(true);
802 public void gatherViews(AlignFrame source)
804 source.viewport.gatherViewsHere = true;
805 source.viewport.explodedPosition = source.getBounds();
806 JInternalFrame[] frames = desktop.getAllFrames();
807 String viewId = source.viewport.sequenceSetID;
809 for (int t = 0; t < frames.length; t++)
811 if (frames[t] instanceof AlignFrame && frames[t] != source)
813 AlignFrame af = (AlignFrame) frames[t];
814 boolean gatherThis = false;
815 for (int a = 0; a < af.alignPanels.size(); a++)
817 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
818 if (viewId.equals(ap.av.getSequenceSetId()))
821 ap.av.gatherViewsHere = false;
822 ap.av.explodedPosition = af.getBounds();
823 source.addAlignmentPanel(ap, false);
829 af.alignPanels.clear();
830 af.closeMenuItem_actionPerformed(true);
837 jalview.gui.VamsasClient v_client=null;
838 public void vamsasLoad_actionPerformed(ActionEvent e)
840 if (v_client==null) {
842 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
843 getProperty("LAST_DIRECTORY"));
845 chooser.setFileView(new JalviewFileView());
846 chooser.setDialogTitle("Load Vamsas file");
847 chooser.setToolTipText("Import");
849 int value = chooser.showOpenDialog(this);
851 if (value == JalviewFileChooser.APPROVE_OPTION)
853 v_client = new jalview.gui.VamsasClient(this,
854 chooser.getSelectedFile());
855 this.vamsasLoad.setText("Session Update");
856 this.vamsasStop.setVisible(true);
857 v_client.initial_update();
858 v_client.startWatcher();
861 // store current data in session.
862 v_client.push_update();
865 public void vamsasStop_actionPerformed(ActionEvent e) {
866 if (v_client!=null) {
867 v_client.end_session();
869 this.vamsasStop.setVisible(false);
870 this.vamsasLoad.setText("Start Vamsas Session...");
874 * hide vamsas user gui bits when a vamsas document event is being handled.
875 * @param b true to hide gui, false to reveal gui
877 public void setVamsasUpdate(boolean b) {
878 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "+(b ? "in progress" : "finished"));
879 vamsasLoad.setVisible(!b);
880 vamsasStop.setVisible(!b);