2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
23 import jalview.io.*;
\r
26 import java.awt.datatransfer.*;
\r
27 import java.awt.dnd.*;
\r
28 import java.awt.event.*;
\r
30 import javax.swing.*;
\r
37 * @version $Revision$
\r
39 public class Desktop extends jalview.jbgui.GDesktop
\r
40 implements DropTargetListener
\r
42 /** DOCUMENT ME!! */
\r
43 public static JDesktopPane desktop;
\r
44 static int openFrameCount = 0;
\r
45 static final int xOffset = 30;
\r
46 static final int yOffset = 30;
\r
49 * Creates a new Desktop object.
\r
57 java.net.URL url = getClass().getResource("/images/logo.gif");
\r
61 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
63 MediaTracker mt = new MediaTracker(this);
\r
64 mt.addImage(image, 0);
\r
66 // setIconImage(image);
\r
69 catch (Exception ex)
\r
73 setTitle("Jalview 2005");
\r
74 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
75 desktop = new JDesktopPane();
\r
76 desktop.setBackground(Color.white);
\r
77 setContentPane(desktop);
\r
78 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
\r
80 // This line prevents Windows Look&Feel resizing all new windows to maximum
\r
81 // if previous window was maximised
\r
82 desktop.setDesktopManager(new DefaultDesktopManager());
\r
84 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
\r
85 String x = jalview.bin.Cache.getProperty("SCREEN_X");
\r
86 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
\r
87 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
\r
88 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
\r
90 if ((x != null) && (y != null) && (width != null) && (height != null))
\r
92 setBounds(Integer.parseInt(x), Integer.parseInt(y),
\r
93 Integer.parseInt(width), Integer.parseInt(height));
\r
97 setBounds((int) (screenSize.width - 900) / 2,
\r
98 (int) (screenSize.height - 650) / 2, 900, 650);
\r
101 this.addWindowListener(new WindowAdapter()
\r
103 public void windowClosing(WindowEvent evt)
\r
109 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
\r
111 /////////Add a splashscreen on startup
\r
112 /////////Add a splashscreen on startup
\r
113 JInternalFrame frame = new JInternalFrame();
\r
115 SplashScreen splash = new SplashScreen(frame, image);
\r
116 frame.setContentPane(splash);
\r
117 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
118 addInternalFrame(frame, "", 750, 160, false);
\r
119 frame.setLocation((int) ((getWidth() - 750) / 2),
\r
120 (int) ((getHeight() - 160) / 2));
\r
126 * @param frame DOCUMENT ME!
\r
127 * @param title DOCUMENT ME!
\r
128 * @param w DOCUMENT ME!
\r
129 * @param h DOCUMENT ME!
\r
131 public static void addInternalFrame(final JInternalFrame frame,
\r
132 String title, int w, int h)
\r
134 addInternalFrame(frame, title, w, h, true);
\r
140 * @param frame DOCUMENT ME!
\r
141 * @param title DOCUMENT ME!
\r
142 * @param w DOCUMENT ME!
\r
143 * @param h DOCUMENT ME!
\r
144 * @param resizable DOCUMENT ME!
\r
146 public static void addInternalFrame(final JInternalFrame frame,
\r
147 String title, int w, int h, boolean resizable)
\r
149 desktop.add(frame);
\r
154 frame.setSelected(true);
\r
156 catch (java.beans.PropertyVetoException e)
\r
160 frame.setTitle(title);
\r
161 frame.setSize(w, h);
\r
162 frame.setClosable(true);
\r
163 frame.setResizable(resizable);
\r
164 frame.setMaximizable(resizable);
\r
165 frame.setIconifiable(resizable);
\r
166 frame.setFrameIcon(null);
\r
167 frame.setLocation(xOffset * openFrameCount, yOffset * openFrameCount);
\r
170 final JMenuItem menuItem = new JMenuItem(title);
\r
171 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
173 public void internalFrameClosed(
\r
174 javax.swing.event.InternalFrameEvent evt)
\r
177 windowMenu.remove(menuItem);
\r
182 menuItem.addActionListener(new ActionListener()
\r
184 public void actionPerformed(ActionEvent e)
\r
188 frame.setSelected(true);
\r
189 frame.setIcon(false);
\r
191 catch (java.beans.PropertyVetoException ex)
\r
199 frame.setVisible(true);
\r
200 windowMenu.add(menuItem);
\r
206 * @param evt DOCUMENT ME!
\r
208 public void dragEnter(DropTargetDragEvent evt)
\r
215 * @param evt DOCUMENT ME!
\r
217 public void dragExit(DropTargetEvent evt)
\r
224 * @param evt DOCUMENT ME!
\r
226 public void dragOver(DropTargetDragEvent evt)
\r
233 * @param evt DOCUMENT ME!
\r
235 public void dropActionChanged(DropTargetDragEvent evt)
\r
242 * @param evt DOCUMENT ME!
\r
244 public void drop(DropTargetDropEvent evt)
\r
246 Transferable t = evt.getTransferable();
\r
248 if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
\r
253 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
257 java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
\r
259 for (int i = 0; i < files.size(); i++)
\r
261 String file = files.get(i).toString();
\r
262 String protocol = "File";
\r
263 String format = null;
\r
265 if (file.endsWith(".jar"))
\r
267 format = "Jalview";
\r
272 format = jalview.io.IdentifyFile.Identify(file,
\r
275 LoadFile(file, protocol, format);
\r
278 catch (Exception ex)
\r
280 ex.printStackTrace();
\r
287 * @param e DOCUMENT ME!
\r
289 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
\r
291 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
295 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
\r
300 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
\r
301 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
\r
303 chooser.setFileView(new JalviewFileView());
\r
304 chooser.setDialogTitle("Open local file");
\r
305 chooser.setToolTipText("Open");
\r
307 int value = chooser.showOpenDialog(this);
\r
309 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
311 String choice = chooser.getSelectedFile().getPath();
\r
312 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
313 chooser.getSelectedFile().getParent());
\r
315 String format = null;
\r
316 if (chooser.getSelectedFormat().equals("Jalview"))
\r
318 format = "Jalview";
\r
322 format = IdentifyFile.Identify(choice, "File");
\r
325 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
\r
326 LoadFile(choice, "File", format);
\r
333 * @param file DOCUMENT ME!
\r
334 * @param protocol DOCUMENT ME!
\r
335 * @param format DOCUMENT ME!
\r
337 public void LoadFile(String file, String protocol, String format)
\r
339 LoadingThread loader = new LoadingThread(file, protocol, format);
\r
345 * @param file DOCUMENT ME!
\r
346 * @param protocol DOCUMENT ME!
\r
347 * @param format DOCUMENT ME!
\r
349 public AlignFrame LoadFileWaitTillLoaded(String file, String protocol, String format)
\r
351 LoadingThread loader = new LoadingThread(file, protocol, format);
\r
354 while (loader.isAlive())
\r
360 catch (Exception ex)
\r
370 * @param e DOCUMENT ME!
\r
372 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
374 String url = JOptionPane.showInternalInputDialog(Desktop.desktop,
\r
375 "Enter url of input file", "Input alignment from URL",
\r
376 JOptionPane.QUESTION_MESSAGE, null, null, "http://www.")
\r
384 if (url.trim().toLowerCase().endsWith(".jar"))
\r
386 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", "Jalview");
\r
387 Jalview2XML.LoadJalviewAlign(url);
\r
392 String format = IdentifyFile.Identify(url, "URL");
\r
394 if (format.equals("URL NOT FOUND"))
\r
396 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
397 "Couldn't locate " + url,
\r
399 JOptionPane.WARNING_MESSAGE);
\r
404 LoadFile(url, "URL", format);
\r
411 * @param e DOCUMENT ME!
\r
413 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\r
415 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
417 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
\r
425 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
\r
426 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
\r
427 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
\r
428 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
\r
435 * @param e DOCUMENT ME!
\r
437 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
439 StringBuffer message = new StringBuffer("JalView 2005 version " +
\r
440 jalview.bin.Cache.getProperty(
\r
442 "; last updated: " +
\r
444 Cache.getProperty("BUILD_DATE"));
\r
446 if (!jalview.bin.Cache.getProperty("jalview.version").equals(
\r
447 jalview.bin.Cache.getProperty("VERSION")))
\r
449 message.append("\n\n!! Jalview version "
\r
450 + jalview.bin.Cache.getProperty("jalview.version")
\r
451 + " is available for download from http://www.jalview.org !!\n");
\r
455 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
\r
456 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
\r
457 "\nFor all issues relating to Jalview, email help@jalview.org" +
\r
458 "\n\nIf you use JalView, please cite:" +
\r
459 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
\r
460 "\nBioinformatics, 2004 12;426-7.");
\r
462 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
464 message.toString(), "About Jalview",
\r
465 JOptionPane.INFORMATION_MESSAGE);
\r
471 * @param e DOCUMENT ME!
\r
473 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
477 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
\r
478 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
\r
479 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
\r
481 javax.help.HelpBroker hb = hs.createHelpBroker();
\r
482 hb.setLocation(new Point(200, 50));
\r
483 hb.setSize(new Dimension(800, 700));
\r
484 hb.setCurrentID("home");
\r
485 hb.setDisplayed(true);
\r
487 catch (Exception ex)
\r
489 ex.printStackTrace();
\r
496 * @param e DOCUMENT ME!
\r
498 protected void preferences_actionPerformed(ActionEvent e)
\r
506 * @param e DOCUMENT ME!
\r
508 public void saveState_actionPerformed(ActionEvent e)
\r
510 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
511 "LAST_DIRECTORY"), new String[] { "jar" },
\r
512 new String[] { "Jalview Project" }, "Jalview Project");
\r
514 chooser.setFileView(new JalviewFileView());
\r
515 chooser.setDialogTitle("Save State");
\r
517 int value = chooser.showSaveDialog(this);
\r
519 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
521 java.io.File choice = chooser.getSelectedFile();
\r
522 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
\r
523 Jalview2XML.SaveState(choice);
\r
530 * @param e DOCUMENT ME!
\r
532 public void loadState_actionPerformed(ActionEvent e)
\r
534 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
535 "LAST_DIRECTORY"), new String[] { "jar" },
\r
536 new String[] { "Jalview Project" }, "Jalview Project");
\r
537 chooser.setFileView(new JalviewFileView());
\r
538 chooser.setDialogTitle("Restore state");
\r
540 int value = chooser.showOpenDialog(this);
\r
542 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
544 String choice = chooser.getSelectedFile().getAbsolutePath();
\r
545 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
546 chooser.getSelectedFile().getParent());
\r
547 Jalview2XML.LoadJalviewAlign(choice);
\r
551 class LoadingThread extends Thread
\r
558 public LoadingThread(String file, String protocol, String format)
\r
561 this.protocol = protocol;
\r
562 this.format = format;
\r
567 SequenceI[] sequences = null;
\r
569 if(format.equalsIgnoreCase("Jalview"))
\r
571 Jalview2XML.LoadJalviewAlign(file);
\r
575 if (FormatAdapter.formats.contains(format))
\r
577 sequences = FormatAdapter.readFile(file, protocol, format);
\r
580 if ( (sequences != null) && (sequences.length > 0))
\r
582 af = new AlignFrame(new Alignment(sequences));
\r
583 addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH,
\r
584 AlignFrame.NEW_WINDOW_HEIGHT);
\r
585 af.currentFileFormat = format;
\r
586 af.statusBar.setText("Successfully loaded file " + file);
\r
590 af.setMaximum(Preferences.showFullscreen);
\r
592 catch (Exception ex)
\r
598 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
599 "Couldn't open file.\n" +
\r
600 "Formats currently supported are\n" +
\r
601 "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter!
\r
602 , "Error loading file", JOptionPane.WARNING_MESSAGE);
\r