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 2005");
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.
123 this.addKeyListener(new KeyAdapter()
125 public void keyPressed(KeyEvent k)
127 System.out.println(k);
135 * @param frame DOCUMENT ME!
136 * @param title DOCUMENT ME!
137 * @param w DOCUMENT ME!
138 * @param h DOCUMENT ME!
140 public static synchronized void addInternalFrame(final JInternalFrame frame,
141 String title, int w, int h)
143 addInternalFrame(frame, title, w, h, true);
149 * @param frame DOCUMENT ME!
150 * @param title DOCUMENT ME!
151 * @param w DOCUMENT ME!
152 * @param h DOCUMENT ME!
153 * @param resizable DOCUMENT ME!
155 public static synchronized void addInternalFrame(final JInternalFrame frame,
156 String title, int w, int h, boolean resizable)
159 frame.setTitle(title);
160 if(frame.getWidth()<1 || frame.getHeight()<1)
164 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
165 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
166 // IF JALVIEW IS RUNNING HEADLESS
167 /////////////////////////////////////////////////
168 if (System.getProperty("java.awt.headless") != null
169 && System.getProperty("java.awt.headless").equals("true"))
177 frame.setVisible(true);
178 frame.setClosable(true);
179 frame.setResizable(resizable);
180 frame.setMaximizable(resizable);
181 frame.setIconifiable(resizable);
182 frame.setFrameIcon(null);
184 if (frame.getX()<1 && frame.getY()<1)
186 frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);
189 final JMenuItem menuItem = new JMenuItem(title);
190 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
192 public void internalFrameClosed(
193 javax.swing.event.InternalFrameEvent evt)
196 windowMenu.remove(menuItem);
201 menuItem.addActionListener(new ActionListener()
203 public void actionPerformed(ActionEvent e)
207 frame.setSelected(true);
208 frame.setIcon(false);
210 catch (java.beans.PropertyVetoException ex)
217 windowMenu.add(menuItem);
222 frame.setSelected(true);
223 }catch(java.beans.PropertyVetoException ve)
230 * @param evt DOCUMENT ME!
232 public void dragEnter(DropTargetDragEvent evt)
239 * @param evt DOCUMENT ME!
241 public void dragExit(DropTargetEvent evt)
248 * @param evt DOCUMENT ME!
250 public void dragOver(DropTargetDragEvent evt)
257 * @param evt DOCUMENT ME!
259 public void dropActionChanged(DropTargetDragEvent evt)
266 * @param evt DOCUMENT ME!
268 public void drop(DropTargetDropEvent evt)
270 Transferable t = evt.getTransferable();
272 if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
277 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
281 java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
283 for (int i = 0; i < files.size(); i++)
285 String file = files.get(i).toString();
286 String protocol = "File";
287 String format = null;
289 if (file.endsWith(".jar"))
296 format = jalview.io.IdentifyFile.Identify(file,
299 LoadFile(file, protocol, format);
304 ex.printStackTrace();
311 * @param e DOCUMENT ME!
313 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
315 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
319 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
324 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
325 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
327 chooser.setFileView(new JalviewFileView());
328 chooser.setDialogTitle("Open local file");
329 chooser.setToolTipText("Open");
331 int value = chooser.showOpenDialog(this);
333 if (value == JalviewFileChooser.APPROVE_OPTION)
335 String choice = chooser.getSelectedFile().getPath();
336 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
337 chooser.getSelectedFile().getParent());
339 String format = null;
340 if (chooser.getSelectedFormat().equals("Jalview"))
346 format = IdentifyFile.Identify(choice, "File");
349 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
350 LoadFile(choice, "File", format);
357 * @param file DOCUMENT ME!
358 * @param protocol DOCUMENT ME!
359 * @param format DOCUMENT ME!
361 public void LoadFile(String file, String protocol, String format)
363 FileLoader fileLoader = new FileLoader();
364 fileLoader.LoadFile(file, protocol, format);
370 * @param e DOCUMENT ME!
372 public void inputURLMenuItem_actionPerformed(ActionEvent e)
374 String url = JOptionPane.showInternalInputDialog(Desktop.desktop,
375 "Enter url of input file", "Input alignment from URL",
376 JOptionPane.QUESTION_MESSAGE, null, null, "http://www.")
384 if (url.trim().toLowerCase().endsWith(".jar"))
386 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", "Jalview");
387 Jalview2XML.LoadJalviewAlign(url);
392 String format = IdentifyFile.Identify(url, "URL");
394 if (format.equals("URL NOT FOUND"))
396 JOptionPane.showInternalMessageDialog(Desktop.desktop,
397 "Couldn't locate " + url,
399 JOptionPane.WARNING_MESSAGE);
404 LoadFile(url, "URL", format);
411 * @param e DOCUMENT ME!
413 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
415 CutAndPasteTransfer cap = new CutAndPasteTransfer();
417 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
425 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
426 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
427 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
428 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
435 * @param e DOCUMENT ME!
437 public void aboutMenuItem_actionPerformed(ActionEvent e)
439 StringBuffer message = new StringBuffer("JalView 2005 version " +
440 jalview.bin.Cache.getProperty(
444 Cache.getDefault("BUILD_DATE", "unknown"));
446 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
447 jalview.bin.Cache.getProperty("VERSION")))
449 message.append("\n\n!! Jalview version "
450 + jalview.bin.Cache.getProperty("LATEST_VERSION")
451 + " is available for download from http://www.jalview.org !!\n");
455 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
456 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
457 "\nFor all issues relating to Jalview, email help@jalview.org" +
458 "\n\nIf you use JalView, please cite:" +
459 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
460 "\nBioinformatics, 2004 12;426-7.");
462 JOptionPane.showInternalMessageDialog(Desktop.desktop,
464 message.toString(), "About Jalview",
465 JOptionPane.INFORMATION_MESSAGE);
471 * @param e DOCUMENT ME!
473 public void documentationMenuItem_actionPerformed(ActionEvent e)
477 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
478 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
479 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
481 javax.help.HelpBroker hb = hs.createHelpBroker();
482 hb.setLocation(new Point(200, 50));
483 hb.setSize(new Dimension(800, 700));
484 hb.setCurrentID("home");
485 hb.setDisplayed(true);
489 ex.printStackTrace();
496 * @param e DOCUMENT ME!
498 protected void preferences_actionPerformed(ActionEvent e)
506 * @param e DOCUMENT ME!
508 public void saveState_actionPerformed(ActionEvent e)
510 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
511 "LAST_DIRECTORY"), new String[] { "jar" },
512 new String[] { "Jalview Project" }, "Jalview Project");
514 chooser.setFileView(new JalviewFileView());
515 chooser.setDialogTitle("Save State");
517 int value = chooser.showSaveDialog(this);
519 if (value == JalviewFileChooser.APPROVE_OPTION)
521 java.io.File choice = chooser.getSelectedFile();
522 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
523 Jalview2XML.SaveState(choice);
530 * @param e DOCUMENT ME!
532 public void loadState_actionPerformed(ActionEvent e)
534 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
535 "LAST_DIRECTORY"), new String[] { "jar" },
536 new String[] { "Jalview Project" }, "Jalview Project");
537 chooser.setFileView(new JalviewFileView());
538 chooser.setDialogTitle("Restore state");
540 int value = chooser.showOpenDialog(this);
542 if (value == JalviewFileChooser.APPROVE_OPTION)
544 String choice = chooser.getSelectedFile().getAbsolutePath();
545 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
546 chooser.getSelectedFile().getParent());
547 Jalview2XML.LoadJalviewAlign(choice);