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.io.*;
\r
24 import java.awt.datatransfer.*;
\r
25 import java.awt.dnd.*;
\r
26 import java.awt.event.*;
\r
29 import javax.swing.*;
\r
36 * @version $Revision$
\r
38 public class Desktop extends jalview.jbgui.GDesktop
\r
39 implements DropTargetListener, ClipboardOwner
\r
41 /** DOCUMENT ME!! */
\r
42 public static Desktop instance;
\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
47 public static jalview.ws.Discoverer discoverer;
\r
49 public static Object [] jalviewClipboard;
\r
51 static int fileLoadingCount= 0;
\r
54 * Creates a new Desktop object.
\r
64 java.net.URL url = getClass().getResource("/images/logo.gif");
\r
68 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
70 MediaTracker mt = new MediaTracker(this);
\r
71 mt.addImage(image, 0);
\r
73 setIconImage(image);
\r
76 catch (Exception ex)
\r
80 setTitle("Jalview "+jalview.bin.Cache.getProperty("VERSION"));
\r
81 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
82 desktop = new JDesktopPane();
\r
83 desktop.setBackground(Color.white);
\r
84 getContentPane().setLayout(new BorderLayout());
\r
85 getContentPane().add(desktop, BorderLayout.CENTER);
\r
86 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
\r
88 // This line prevents Windows Look&Feel resizing all new windows to maximum
\r
89 // if previous window was maximised
\r
90 desktop.setDesktopManager(new DefaultDesktopManager());
\r
92 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
\r
93 String x = jalview.bin.Cache.getProperty("SCREEN_X");
\r
94 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
\r
95 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
\r
96 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
\r
98 if ((x != null) && (y != null) && (width != null) && (height != null))
\r
100 setBounds(Integer.parseInt(x), Integer.parseInt(y),
\r
101 Integer.parseInt(width), Integer.parseInt(height));
\r
105 setBounds((int) (screenSize.width - 900) / 2,
\r
106 (int) (screenSize.height - 650) / 2, 900, 650);
\r
109 this.addWindowListener(new WindowAdapter()
\r
111 public void windowClosing(WindowEvent evt)
\r
117 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
\r
119 /////////Add a splashscreen on startup
\r
120 /////////Add a splashscreen on startup
\r
121 JInternalFrame frame = new JInternalFrame();
\r
123 SplashScreen splash = new SplashScreen(frame, image);
\r
124 frame.setContentPane(splash);
\r
125 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
126 frame.setLocation((int) ((getWidth() - 750) / 2),
\r
127 (int) ((getHeight() - 160) / 2));
\r
129 addInternalFrame(frame, "", 750, 160, false);
\r
131 discoverer=new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
\r
138 * @param frame DOCUMENT ME!
\r
139 * @param title DOCUMENT ME!
\r
140 * @param w DOCUMENT ME!
\r
141 * @param h DOCUMENT ME!
\r
143 public static synchronized void addInternalFrame(final JInternalFrame frame,
\r
144 String title, int w, int h)
\r
146 addInternalFrame(frame, title, w, h, true);
\r
152 * @param frame DOCUMENT ME!
\r
153 * @param title DOCUMENT ME!
\r
154 * @param w DOCUMENT ME!
\r
155 * @param h DOCUMENT ME!
\r
156 * @param resizable DOCUMENT ME!
\r
158 public static synchronized void addInternalFrame(final JInternalFrame frame,
\r
159 String title, int w, int h, boolean resizable)
\r
162 frame.setTitle(title);
\r
163 if(frame.getWidth()<1 || frame.getHeight()<1)
\r
165 frame.setSize(w, h);
\r
167 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
\r
168 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
\r
169 // IF JALVIEW IS RUNNING HEADLESS
\r
170 /////////////////////////////////////////////////
\r
171 if (System.getProperty("java.awt.headless") != null
\r
172 && System.getProperty("java.awt.headless").equals("true"))
\r
180 frame.setVisible(true);
\r
181 frame.setClosable(true);
\r
182 frame.setResizable(resizable);
\r
183 frame.setMaximizable(resizable);
\r
184 frame.setIconifiable(resizable);
\r
185 frame.setFrameIcon(null);
\r
187 if (frame.getX()<1 && frame.getY()<1)
\r
189 frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);
\r
192 final JMenuItem menuItem = new JMenuItem(title);
\r
193 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
195 public void internalFrameActivated(javax.swing.event.
\r
196 InternalFrameEvent evt)
\r
198 JInternalFrame itf = desktop.getSelectedFrame();
\r
200 itf.requestFocus();
\r
204 public void internalFrameClosed(
\r
205 javax.swing.event.InternalFrameEvent evt)
\r
208 windowMenu.remove(menuItem);
\r
209 JInternalFrame itf = desktop.getSelectedFrame();
\r
211 itf.requestFocus();
\r
216 menuItem.addActionListener(new ActionListener()
\r
218 public void actionPerformed(ActionEvent e)
\r
222 frame.setSelected(true);
\r
223 frame.setIcon(false);
\r
225 catch (java.beans.PropertyVetoException ex)
\r
232 windowMenu.add(menuItem);
\r
234 desktop.add(frame);
\r
237 frame.setSelected(true);
\r
238 frame.requestFocus();
\r
239 }catch(java.beans.PropertyVetoException ve)
\r
243 public void lostOwnership(Clipboard clipboard, Transferable contents)
\r
245 Desktop.jalviewClipboard = null;
\r
248 public void dragEnter(DropTargetDragEvent evt)
\r
251 public void dragExit(DropTargetEvent evt)
\r
254 public void dragOver(DropTargetDragEvent evt)
\r
257 public void dropActionChanged(DropTargetDragEvent evt)
\r
263 * @param evt DOCUMENT ME!
\r
265 public void drop(DropTargetDropEvent evt)
\r
267 Transferable t = evt.getTransferable();
\r
268 java.util.List files = null;
\r
272 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
\r
273 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
\r
275 //Works on Windows and MacOSX
\r
276 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
277 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
\r
279 else if (t.isDataFlavorSupported(uriListFlavor))
\r
281 // This is used by Unix drag system
\r
282 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
283 String data = (String) t.getTransferData(uriListFlavor);
\r
284 files = new java.util.ArrayList(1);
\r
285 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
\r
288 st.hasMoreTokens(); )
\r
290 String s = st.nextToken();
\r
291 if (s.startsWith("#"))
\r
293 // the line is a comment (as per the RFC 2483)
\r
297 java.net.URI uri = new java.net.URI(s);
\r
298 java.io.File file = new java.io.File(uri);
\r
303 catch (Exception e)
\r
305 e.printStackTrace();
\r
312 for (int i = 0; i < files.size(); i++)
\r
314 String file = files.get(i).toString();
\r
315 String protocol = FormatAdapter.FILE;
\r
316 String format = null;
\r
318 if (file.endsWith(".jar"))
\r
320 format = "Jalview";
\r
325 format = new IdentifyFile().Identify(file,
\r
330 new FileLoader().LoadFile(file, protocol, format);
\r
334 catch (Exception ex)
\r
336 ex.printStackTrace();
\r
344 * @param e DOCUMENT ME!
\r
346 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
\r
348 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
352 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
\r
357 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
\r
358 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
\r
360 chooser.setFileView(new JalviewFileView());
\r
361 chooser.setDialogTitle("Open local file");
\r
362 chooser.setToolTipText("Open");
\r
364 int value = chooser.showOpenDialog(this);
\r
366 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
368 String choice = chooser.getSelectedFile().getPath();
\r
369 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
370 chooser.getSelectedFile().getParent());
\r
372 String format = null;
\r
373 if (chooser.getSelectedFormat().equals("Jalview"))
\r
375 format = "Jalview";
\r
379 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
\r
382 if (viewport != null)
\r
383 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
\r
385 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
\r
394 * @param e DOCUMENT ME!
\r
396 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
\r
398 // This construct allows us to have a wider textfield
\r
400 JLabel label = new JLabel("Enter URL of Input File");
\r
401 final JComboBox history = new JComboBox();
\r
403 JPanel panel = new JPanel(new GridLayout(2,1));
\r
405 panel.add(history);
\r
406 history.setPreferredSize(new Dimension(400,20));
\r
407 history.setEditable(true);
\r
408 history.addItem("http://www.");
\r
410 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
\r
412 StringTokenizer st;
\r
414 if (historyItems != null)
\r
416 st = new StringTokenizer(historyItems, "\t");
\r
418 while (st.hasMoreTokens())
\r
420 history.addItem(st.nextElement());
\r
424 int reply = JOptionPane.showInternalConfirmDialog(desktop,
\r
425 panel, "Input Alignment From URL",
\r
426 JOptionPane.OK_CANCEL_OPTION );
\r
429 if (reply != JOptionPane.OK_OPTION )
\r
434 String url = history.getSelectedItem().toString();
\r
436 if (url.toLowerCase().endsWith(".jar"))
\r
438 if (viewport != null)
\r
439 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
\r
441 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
\r
445 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
\r
447 if (format.equals("URL NOT FOUND"))
\r
449 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
450 "Couldn't locate " + url,
\r
452 JOptionPane.WARNING_MESSAGE);
\r
457 if (viewport != null)
\r
458 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
\r
460 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
\r
467 * @param e DOCUMENT ME!
\r
469 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
\r
471 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
472 cap.setForInput(viewport);
\r
473 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
\r
481 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
\r
482 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
\r
483 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
\r
484 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
\r
491 * @param e DOCUMENT ME!
\r
493 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
495 StringBuffer message = new StringBuffer("JalView version " +
\r
496 jalview.bin.Cache.getProperty(
\r
498 "; last updated: " +
\r
500 Cache.getDefault("BUILD_DATE", "unknown"));
\r
502 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
\r
503 jalview.bin.Cache.getProperty("VERSION")))
\r
505 message.append("\n\n!! Jalview version "
\r
506 + jalview.bin.Cache.getProperty("LATEST_VERSION")
\r
507 + " is available for download from http://www.jalview.org !!\n");
\r
511 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
\r
512 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
\r
513 "\nFor all issues relating to Jalview, email help@jalview.org" +
\r
514 "\n\nIf you use JalView, please cite:" +
\r
515 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
\r
516 "\nBioinformatics, 2004 20;426-7.");
\r
518 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
520 message.toString(), "About Jalview",
\r
521 JOptionPane.INFORMATION_MESSAGE);
\r
527 * @param e DOCUMENT ME!
\r
529 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
533 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
\r
534 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
\r
535 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
\r
537 javax.help.HelpBroker hb = hs.createHelpBroker();
\r
538 hb.setCurrentID("home");
\r
539 hb.setDisplayed(true);
\r
541 catch (Exception ex)
\r
543 ex.printStackTrace();
\r
550 * @param e DOCUMENT ME!
\r
552 protected void preferences_actionPerformed(ActionEvent e)
\r
560 * @param e DOCUMENT ME!
\r
562 public void saveState_actionPerformed(ActionEvent e)
\r
564 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
565 "LAST_DIRECTORY"), new String[] { "jar" },
\r
566 new String[] { "Jalview Project" }, "Jalview Project");
\r
568 chooser.setFileView(new JalviewFileView());
\r
569 chooser.setDialogTitle("Save State");
\r
571 int value = chooser.showSaveDialog(this);
\r
573 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
575 java.io.File choice = chooser.getSelectedFile();
\r
576 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
\r
577 new Jalview2XML().SaveState(choice);
\r
584 * @param e DOCUMENT ME!
\r
586 public void loadState_actionPerformed(ActionEvent e)
\r
588 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
589 "LAST_DIRECTORY"), new String[] { "jar" },
\r
590 new String[] { "Jalview Project" }, "Jalview Project");
\r
591 chooser.setFileView(new JalviewFileView());
\r
592 chooser.setDialogTitle("Restore state");
\r
594 int value = chooser.showOpenDialog(this);
\r
596 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
598 String choice = chooser.getSelectedFile().getAbsolutePath();
\r
599 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
600 chooser.getSelectedFile().getParent());
\r
601 new Jalview2XML().LoadJalviewAlign(choice);
\r
605 /* public void vamsasLoad_actionPerformed(ActionEvent e)
\r
607 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
\r
608 getProperty("LAST_DIRECTORY"));
\r
610 chooser.setFileView(new JalviewFileView());
\r
611 chooser.setDialogTitle("Load Vamsas file");
\r
612 chooser.setToolTipText("Import");
\r
614 int value = chooser.showOpenDialog(this);
\r
616 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
618 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
\r
620 chooser.getSelectedFile().getAbsolutePath()
\r
627 public void inputSequence_actionPerformed(ActionEvent e)
\r
629 new SequenceFetcher(null);
\r
632 JPanel progressPanel;
\r
634 public void startLoading(final String fileName)
\r
636 if (fileLoadingCount == 0)
\r
638 progressPanel = new JPanel(new BorderLayout());
\r
639 JProgressBar progressBar = new JProgressBar();
\r
640 progressBar.setIndeterminate(true);
\r
642 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
\r
643 BorderLayout.WEST);
\r
645 progressPanel.add(progressBar, BorderLayout.CENTER);
\r
647 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
\r
649 fileLoadingCount++;
\r
653 public void stopLoading()
\r
655 fileLoadingCount--;
\r
656 if (fileLoadingCount < 1)
\r
658 if(progressPanel!=null)
\r
660 this.getContentPane().remove(progressPanel);
\r
661 progressPanel = null;
\r
663 fileLoadingCount = 0;
\r