2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 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.*;
37 public class Desktop extends jalview.jbgui.GDesktop
38 implements DropTargetListener
41 public static JDesktopPane desktop;
42 static int openFrameCount = 0;
43 static final int xOffset = 30;
44 static final int yOffset = 30;
45 public static jalview.ws.Discoverer discoverer;
47 public static Object [] jalviewClipboard;
51 * Creates a new Desktop object.
60 java.net.URL url = getClass().getResource("/images/logo.gif");
64 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
66 MediaTracker mt = new MediaTracker(this);
67 mt.addImage(image, 0);
76 setTitle("Jalview "+jalview.bin.Cache.getProperty("VERSION"));
77 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
78 desktop = new JDesktopPane();
79 desktop.setBackground(Color.white);
80 setContentPane(desktop);
81 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
83 // This line prevents Windows Look&Feel resizing all new windows to maximum
84 // if previous window was maximised
85 desktop.setDesktopManager(new DefaultDesktopManager());
87 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
88 String x = jalview.bin.Cache.getProperty("SCREEN_X");
89 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
90 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
91 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
93 if ((x != null) && (y != null) && (width != null) && (height != null))
95 setBounds(Integer.parseInt(x), Integer.parseInt(y),
96 Integer.parseInt(width), Integer.parseInt(height));
100 setBounds((int) (screenSize.width - 900) / 2,
101 (int) (screenSize.height - 650) / 2, 900, 650);
104 this.addWindowListener(new WindowAdapter()
106 public void windowClosing(WindowEvent evt)
112 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
114 /////////Add a splashscreen on startup
115 /////////Add a splashscreen on startup
116 JInternalFrame frame = new JInternalFrame();
118 SplashScreen splash = new SplashScreen(frame, image);
119 frame.setContentPane(splash);
120 frame.setLayer(JLayeredPane.PALETTE_LAYER);
121 frame.setLocation((int) ((getWidth() - 750) / 2),
122 (int) ((getHeight() - 160) / 2));
124 addInternalFrame(frame, "", 750, 160, false);
126 discoverer=new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
133 * @param frame DOCUMENT ME!
134 * @param title DOCUMENT ME!
135 * @param w DOCUMENT ME!
136 * @param h DOCUMENT ME!
138 public static synchronized void addInternalFrame(final JInternalFrame frame,
139 String title, int w, int h)
141 addInternalFrame(frame, title, w, h, true);
147 * @param frame DOCUMENT ME!
148 * @param title DOCUMENT ME!
149 * @param w DOCUMENT ME!
150 * @param h DOCUMENT ME!
151 * @param resizable DOCUMENT ME!
153 public static synchronized void addInternalFrame(final JInternalFrame frame,
154 String title, int w, int h, boolean resizable)
157 frame.setTitle(title);
158 if(frame.getWidth()<1 || frame.getHeight()<1)
162 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
163 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
164 // IF JALVIEW IS RUNNING HEADLESS
165 /////////////////////////////////////////////////
166 if (System.getProperty("java.awt.headless") != null
167 && System.getProperty("java.awt.headless").equals("true"))
175 frame.setVisible(true);
176 frame.setClosable(true);
177 frame.setResizable(resizable);
178 frame.setMaximizable(resizable);
179 frame.setIconifiable(resizable);
180 frame.setFrameIcon(null);
182 if (frame.getX()<1 && frame.getY()<1)
184 frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);
187 final JMenuItem menuItem = new JMenuItem(title);
188 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
190 public void internalFrameClosed(
191 javax.swing.event.InternalFrameEvent evt)
194 windowMenu.remove(menuItem);
195 JInternalFrame itf = desktop.getSelectedFrame();
202 menuItem.addActionListener(new ActionListener()
204 public void actionPerformed(ActionEvent e)
208 frame.setSelected(true);
209 frame.setIcon(false);
211 catch (java.beans.PropertyVetoException ex)
218 windowMenu.add(menuItem);
223 frame.setSelected(true);
224 frame.requestFocus();
225 }catch(java.beans.PropertyVetoException ve)
233 * @param evt DOCUMENT ME!
235 public void dragEnter(DropTargetDragEvent evt)
242 * @param evt DOCUMENT ME!
244 public void dragExit(DropTargetEvent evt)
251 * @param evt DOCUMENT ME!
253 public void dragOver(DropTargetDragEvent evt)
260 * @param evt DOCUMENT ME!
262 public void dropActionChanged(DropTargetDragEvent evt)
269 * @param evt DOCUMENT ME!
271 public void drop(DropTargetDropEvent evt)
273 Transferable t = evt.getTransferable();
275 if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
280 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
284 java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
286 for (int i = 0; i < files.size(); i++)
288 String file = files.get(i).toString();
289 String protocol = "File";
290 String format = null;
292 if (file.endsWith(".jar"))
299 format = jalview.io.IdentifyFile.Identify(file,
302 LoadFile(file, protocol, format);
307 ex.printStackTrace();
314 * @param e DOCUMENT ME!
316 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
318 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
322 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
327 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
328 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
330 chooser.setFileView(new JalviewFileView());
331 chooser.setDialogTitle("Open local file");
332 chooser.setToolTipText("Open");
334 int value = chooser.showOpenDialog(this);
336 if (value == JalviewFileChooser.APPROVE_OPTION)
338 String choice = chooser.getSelectedFile().getPath();
339 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
340 chooser.getSelectedFile().getParent());
342 String format = null;
343 if (chooser.getSelectedFormat().equals("Jalview"))
349 format = IdentifyFile.Identify(choice, "File");
352 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
353 LoadFile(choice, "File", format);
360 * @param file DOCUMENT ME!
361 * @param protocol DOCUMENT ME!
362 * @param format DOCUMENT ME!
364 public void LoadFile(String file, String protocol, String format)
366 FileLoader fileLoader = new FileLoader();
367 fileLoader.LoadFile(file, protocol, format);
373 * @param e DOCUMENT ME!
375 public void inputURLMenuItem_actionPerformed(ActionEvent e)
377 Object reply = JOptionPane.showInternalInputDialog(Desktop.desktop,
378 "Enter url of input file", "Input alignment from URL",
379 JOptionPane.QUESTION_MESSAGE, null, null, "http://www.");
386 String url = reply.toString().trim();
388 if (url.toLowerCase().endsWith(".jar"))
390 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", "Jalview");
391 Jalview2XML.LoadJalviewAlign(url);
396 String format = IdentifyFile.Identify(url, "URL");
398 if (format.equals("URL NOT FOUND"))
400 JOptionPane.showInternalMessageDialog(Desktop.desktop,
401 "Couldn't locate " + url,
403 JOptionPane.WARNING_MESSAGE);
408 LoadFile(url, "URL", format);
415 * @param e DOCUMENT ME!
417 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
419 CutAndPasteTransfer cap = new CutAndPasteTransfer();
421 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
429 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
430 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
431 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
432 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
439 * @param e DOCUMENT ME!
441 public void aboutMenuItem_actionPerformed(ActionEvent e)
443 StringBuffer message = new StringBuffer("JalView 2005 version " +
444 jalview.bin.Cache.getProperty(
448 Cache.getDefault("BUILD_DATE", "unknown"));
450 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
451 jalview.bin.Cache.getProperty("VERSION")))
453 message.append("\n\n!! Jalview version "
454 + jalview.bin.Cache.getProperty("LATEST_VERSION")
455 + " is available for download from http://www.jalview.org !!\n");
459 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
460 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
461 "\nFor all issues relating to Jalview, email help@jalview.org" +
462 "\n\nIf you use JalView, please cite:" +
463 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
464 "\nBioinformatics, 2004 12;426-7.");
466 JOptionPane.showInternalMessageDialog(Desktop.desktop,
468 message.toString(), "About Jalview",
469 JOptionPane.INFORMATION_MESSAGE);
475 * @param e DOCUMENT ME!
477 public void documentationMenuItem_actionPerformed(ActionEvent e)
481 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
482 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
483 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
485 javax.help.HelpBroker hb = hs.createHelpBroker();
486 hb.setCurrentID("home");
487 hb.setDisplayed(true);
491 ex.printStackTrace();
498 * @param e DOCUMENT ME!
500 protected void preferences_actionPerformed(ActionEvent e)
508 * @param e DOCUMENT ME!
510 public void saveState_actionPerformed(ActionEvent e)
512 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
513 "LAST_DIRECTORY"), new String[] { "jar" },
514 new String[] { "Jalview Project" }, "Jalview Project");
516 chooser.setFileView(new JalviewFileView());
517 chooser.setDialogTitle("Save State");
519 int value = chooser.showSaveDialog(this);
521 if (value == JalviewFileChooser.APPROVE_OPTION)
523 java.io.File choice = chooser.getSelectedFile();
524 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
525 Jalview2XML.SaveState(choice);
532 * @param e DOCUMENT ME!
534 public void loadState_actionPerformed(ActionEvent e)
536 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
537 "LAST_DIRECTORY"), new String[] { "jar" },
538 new String[] { "Jalview Project" }, "Jalview Project");
539 chooser.setFileView(new JalviewFileView());
540 chooser.setDialogTitle("Restore state");
542 int value = chooser.showOpenDialog(this);
544 if (value == JalviewFileChooser.APPROVE_OPTION)
546 String choice = chooser.getSelectedFile().getAbsolutePath();
547 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
548 chooser.getSelectedFile().getParent());
549 Jalview2XML.LoadJalviewAlign(choice);
553 /* public void vamsasLoad_actionPerformed(ActionEvent e)
555 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
556 getProperty("LAST_DIRECTORY"));
558 chooser.setFileView(new JalviewFileView());
559 chooser.setDialogTitle("Load Vamsas file");
560 chooser.setToolTipText("Import");
562 int value = chooser.showOpenDialog(this);
564 if (value == JalviewFileChooser.APPROVE_OPTION)
566 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
568 chooser.getSelectedFile().getAbsolutePath()
575 public void inputSequence_actionPerformed(ActionEvent e)
577 SequenceFetcher sf = new SequenceFetcher(null);