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 * Creates a new Desktop object.
55 java.net.URL url = getClass().getResource("/images/logo.gif");
59 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
61 MediaTracker mt = new MediaTracker(this);
62 mt.addImage(image, 0);
71 setTitle("Jalview "+jalview.bin.Cache.getProperty("VERSION"));
72 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
73 desktop = new JDesktopPane();
74 desktop.setBackground(Color.white);
75 setContentPane(desktop);
76 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
78 // This line prevents Windows Look&Feel resizing all new windows to maximum
79 // if previous window was maximised
80 desktop.setDesktopManager(new DefaultDesktopManager());
82 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
83 String x = jalview.bin.Cache.getProperty("SCREEN_X");
84 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
85 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
86 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
88 if ((x != null) && (y != null) && (width != null) && (height != null))
90 setBounds(Integer.parseInt(x), Integer.parseInt(y),
91 Integer.parseInt(width), Integer.parseInt(height));
95 setBounds((int) (screenSize.width - 900) / 2,
96 (int) (screenSize.height - 650) / 2, 900, 650);
99 this.addWindowListener(new WindowAdapter()
101 public void windowClosing(WindowEvent evt)
107 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
109 /////////Add a splashscreen on startup
110 /////////Add a splashscreen on startup
111 JInternalFrame frame = new JInternalFrame();
113 SplashScreen splash = new SplashScreen(frame, image);
114 frame.setContentPane(splash);
115 frame.setLayer(JLayeredPane.PALETTE_LAYER);
116 frame.setLocation((int) ((getWidth() - 750) / 2),
117 (int) ((getHeight() - 160) / 2));
119 addInternalFrame(frame, "", 750, 160, false);
121 discoverer=new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
128 * @param frame DOCUMENT ME!
129 * @param title DOCUMENT ME!
130 * @param w DOCUMENT ME!
131 * @param h DOCUMENT ME!
133 public static synchronized void addInternalFrame(final JInternalFrame frame,
134 String title, int w, int h)
136 addInternalFrame(frame, title, w, h, true);
142 * @param frame DOCUMENT ME!
143 * @param title DOCUMENT ME!
144 * @param w DOCUMENT ME!
145 * @param h DOCUMENT ME!
146 * @param resizable DOCUMENT ME!
148 public static synchronized void addInternalFrame(final JInternalFrame frame,
149 String title, int w, int h, boolean resizable)
152 frame.setTitle(title);
153 if(frame.getWidth()<1 || frame.getHeight()<1)
157 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
158 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
159 // IF JALVIEW IS RUNNING HEADLESS
160 /////////////////////////////////////////////////
161 if (System.getProperty("java.awt.headless") != null
162 && System.getProperty("java.awt.headless").equals("true"))
170 frame.setVisible(true);
171 frame.setClosable(true);
172 frame.setResizable(resizable);
173 frame.setMaximizable(resizable);
174 frame.setIconifiable(resizable);
175 frame.setFrameIcon(null);
177 if (frame.getX()<1 && frame.getY()<1)
179 frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);
182 final JMenuItem menuItem = new JMenuItem(title);
183 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
185 public void internalFrameClosed(
186 javax.swing.event.InternalFrameEvent evt)
189 windowMenu.remove(menuItem);
190 JInternalFrame itf = desktop.getSelectedFrame();
197 menuItem.addActionListener(new ActionListener()
199 public void actionPerformed(ActionEvent e)
203 frame.setSelected(true);
204 frame.setIcon(false);
206 catch (java.beans.PropertyVetoException ex)
213 windowMenu.add(menuItem);
218 frame.setSelected(true);
219 frame.requestFocus();
220 }catch(java.beans.PropertyVetoException ve)
227 * @param evt DOCUMENT ME!
229 public void dragEnter(DropTargetDragEvent evt)
236 * @param evt DOCUMENT ME!
238 public void dragExit(DropTargetEvent evt)
245 * @param evt DOCUMENT ME!
247 public void dragOver(DropTargetDragEvent evt)
254 * @param evt DOCUMENT ME!
256 public void dropActionChanged(DropTargetDragEvent evt)
263 * @param evt DOCUMENT ME!
265 public void drop(DropTargetDropEvent evt)
267 Transferable t = evt.getTransferable();
269 if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
274 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
278 java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
280 for (int i = 0; i < files.size(); i++)
282 String file = files.get(i).toString();
283 String protocol = "File";
284 String format = null;
286 if (file.endsWith(".jar"))
293 format = jalview.io.IdentifyFile.Identify(file,
296 LoadFile(file, protocol, format);
301 ex.printStackTrace();
308 * @param e DOCUMENT ME!
310 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
312 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
316 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
321 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
322 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
324 chooser.setFileView(new JalviewFileView());
325 chooser.setDialogTitle("Open local file");
326 chooser.setToolTipText("Open");
328 int value = chooser.showOpenDialog(this);
330 if (value == JalviewFileChooser.APPROVE_OPTION)
332 String choice = chooser.getSelectedFile().getPath();
333 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
334 chooser.getSelectedFile().getParent());
336 String format = null;
337 if (chooser.getSelectedFormat().equals("Jalview"))
343 format = IdentifyFile.Identify(choice, "File");
346 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
347 LoadFile(choice, "File", format);
354 * @param file DOCUMENT ME!
355 * @param protocol DOCUMENT ME!
356 * @param format DOCUMENT ME!
358 public void LoadFile(String file, String protocol, String format)
360 FileLoader fileLoader = new FileLoader();
361 fileLoader.LoadFile(file, protocol, format);
367 * @param e DOCUMENT ME!
369 public void inputURLMenuItem_actionPerformed(ActionEvent e)
371 Object reply = JOptionPane.showInternalInputDialog(Desktop.desktop,
372 "Enter url of input file", "Input alignment from URL",
373 JOptionPane.QUESTION_MESSAGE, null, null, "http://www.");
380 String url = reply.toString().trim();
382 if (url.toLowerCase().endsWith(".jar"))
384 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", "Jalview");
385 Jalview2XML.LoadJalviewAlign(url);
390 String format = IdentifyFile.Identify(url, "URL");
392 if (format.equals("URL NOT FOUND"))
394 JOptionPane.showInternalMessageDialog(Desktop.desktop,
395 "Couldn't locate " + url,
397 JOptionPane.WARNING_MESSAGE);
402 LoadFile(url, "URL", format);
409 * @param e DOCUMENT ME!
411 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
413 CutAndPasteTransfer cap = new CutAndPasteTransfer();
415 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
423 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
424 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
425 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
426 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
433 * @param e DOCUMENT ME!
435 public void aboutMenuItem_actionPerformed(ActionEvent e)
437 StringBuffer message = new StringBuffer("JalView 2005 version " +
438 jalview.bin.Cache.getProperty(
442 Cache.getDefault("BUILD_DATE", "unknown"));
444 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
445 jalview.bin.Cache.getProperty("VERSION")))
447 message.append("\n\n!! Jalview version "
448 + jalview.bin.Cache.getProperty("LATEST_VERSION")
449 + " is available for download from http://www.jalview.org !!\n");
453 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
454 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
455 "\nFor all issues relating to Jalview, email help@jalview.org" +
456 "\n\nIf you use JalView, please cite:" +
457 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
458 "\nBioinformatics, 2004 12;426-7.");
460 JOptionPane.showInternalMessageDialog(Desktop.desktop,
462 message.toString(), "About Jalview",
463 JOptionPane.INFORMATION_MESSAGE);
469 * @param e DOCUMENT ME!
471 public void documentationMenuItem_actionPerformed(ActionEvent e)
475 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
476 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
477 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
479 javax.help.HelpBroker hb = hs.createHelpBroker();
480 hb.setCurrentID("home");
481 hb.setDisplayed(true);
485 ex.printStackTrace();
492 * @param e DOCUMENT ME!
494 protected void preferences_actionPerformed(ActionEvent e)
502 * @param e DOCUMENT ME!
504 public void saveState_actionPerformed(ActionEvent e)
506 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
507 "LAST_DIRECTORY"), new String[] { "jar" },
508 new String[] { "Jalview Project" }, "Jalview Project");
510 chooser.setFileView(new JalviewFileView());
511 chooser.setDialogTitle("Save State");
513 int value = chooser.showSaveDialog(this);
515 if (value == JalviewFileChooser.APPROVE_OPTION)
517 java.io.File choice = chooser.getSelectedFile();
518 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
519 Jalview2XML.SaveState(choice);
526 * @param e DOCUMENT ME!
528 public void loadState_actionPerformed(ActionEvent e)
530 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
531 "LAST_DIRECTORY"), new String[] { "jar" },
532 new String[] { "Jalview Project" }, "Jalview Project");
533 chooser.setFileView(new JalviewFileView());
534 chooser.setDialogTitle("Restore state");
536 int value = chooser.showOpenDialog(this);
538 if (value == JalviewFileChooser.APPROVE_OPTION)
540 String choice = chooser.getSelectedFile().getAbsolutePath();
541 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
542 chooser.getSelectedFile().getParent());
543 Jalview2XML.LoadJalviewAlign(choice);
547 public void vamsasLoad_actionPerformed(ActionEvent e)
549 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
550 getProperty("LAST_DIRECTORY"));
552 chooser.setFileView(new JalviewFileView());
553 chooser.setDialogTitle("Load Vamsas file");
554 chooser.setToolTipText("Import");
556 int value = chooser.showOpenDialog(this);
558 if (value == JalviewFileChooser.APPROVE_OPTION)
560 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
562 chooser.getSelectedFile().getAbsolutePath()