2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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.*;
31 import org.vamsas.test.simpleclient.ArchiveClient;
39 public class Desktop extends jalview.jbgui.GDesktop
40 implements DropTargetListener, ClipboardOwner
43 public static Desktop instance;
44 public static JDesktopPane desktop;
45 static int openFrameCount = 0;
46 static final int xOffset = 30;
47 static final int yOffset = 30;
48 public static jalview.ws.Discoverer discoverer;
50 public static Object [] jalviewClipboard;
52 static int fileLoadingCount= 0;
55 * Creates a new Desktop object.
65 java.net.URL url = getClass().getResource("/images/logo.gif");
69 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
71 MediaTracker mt = new MediaTracker(this);
72 mt.addImage(image, 0);
81 setTitle("Jalview "+jalview.bin.Cache.getProperty("VERSION"));
82 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
83 desktop = new JDesktopPane();
84 desktop.setBackground(Color.white);
85 getContentPane().setLayout(new BorderLayout());
86 getContentPane().add(desktop, BorderLayout.CENTER);
87 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
89 // This line prevents Windows Look&Feel resizing all new windows to maximum
90 // if previous window was maximised
91 desktop.setDesktopManager(new DefaultDesktopManager());
93 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
94 String x = jalview.bin.Cache.getProperty("SCREEN_X");
95 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
96 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
97 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
99 if ((x != null) && (y != null) && (width != null) && (height != null))
101 setBounds(Integer.parseInt(x), Integer.parseInt(y),
102 Integer.parseInt(width), Integer.parseInt(height));
106 setBounds((int) (screenSize.width - 900) / 2,
107 (int) (screenSize.height - 650) / 2, 900, 650);
110 this.addWindowListener(new WindowAdapter()
112 public void windowClosing(WindowEvent evt)
118 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
120 /////////Add a splashscreen on startup
121 /////////Add a splashscreen on startup
122 JInternalFrame frame = new JInternalFrame();
124 SplashScreen splash = new SplashScreen(frame, image);
125 frame.setContentPane(splash);
126 frame.setLayer(JLayeredPane.PALETTE_LAYER);
127 frame.setLocation((int) ((getWidth() - 750) / 2),
128 (int) ((getHeight() - 160) / 2));
130 addInternalFrame(frame, "", 750, 160, false);
132 discoverer=new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
139 * @param frame DOCUMENT ME!
140 * @param title DOCUMENT ME!
141 * @param w DOCUMENT ME!
142 * @param h DOCUMENT ME!
144 public static synchronized void addInternalFrame(final JInternalFrame frame,
145 String title, int w, int h)
147 addInternalFrame(frame, title, w, h, true);
153 * @param frame DOCUMENT ME!
154 * @param title DOCUMENT ME!
155 * @param w DOCUMENT ME!
156 * @param h DOCUMENT ME!
157 * @param resizable DOCUMENT ME!
159 public static synchronized void addInternalFrame(final JInternalFrame frame,
160 String title, int w, int h, boolean resizable)
163 frame.setTitle(title);
164 if(frame.getWidth()<1 || frame.getHeight()<1)
168 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
169 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
170 // IF JALVIEW IS RUNNING HEADLESS
171 /////////////////////////////////////////////////
172 if (System.getProperty("java.awt.headless") != null
173 && System.getProperty("java.awt.headless").equals("true"))
181 frame.setVisible(true);
182 frame.setClosable(true);
183 frame.setResizable(resizable);
184 frame.setMaximizable(resizable);
185 frame.setIconifiable(resizable);
186 frame.setFrameIcon(null);
188 if (frame.getX()<1 && frame.getY()<1)
190 frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);
193 final JMenuItem menuItem = new JMenuItem(title);
194 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
196 public void internalFrameActivated(javax.swing.event.
197 InternalFrameEvent evt)
199 JInternalFrame itf = desktop.getSelectedFrame();
205 public void internalFrameClosed(
206 javax.swing.event.InternalFrameEvent evt)
209 windowMenu.remove(menuItem);
210 JInternalFrame itf = desktop.getSelectedFrame();
217 menuItem.addActionListener(new ActionListener()
219 public void actionPerformed(ActionEvent e)
223 frame.setSelected(true);
224 frame.setIcon(false);
226 catch (java.beans.PropertyVetoException ex)
233 windowMenu.add(menuItem);
238 frame.setSelected(true);
239 frame.requestFocus();
240 }catch(java.beans.PropertyVetoException ve)
244 public void lostOwnership(Clipboard clipboard, Transferable contents)
246 Desktop.jalviewClipboard = null;
249 public void dragEnter(DropTargetDragEvent evt)
252 public void dragExit(DropTargetEvent evt)
255 public void dragOver(DropTargetDragEvent evt)
258 public void dropActionChanged(DropTargetDragEvent evt)
264 * @param evt DOCUMENT ME!
266 public void drop(DropTargetDropEvent evt)
268 Transferable t = evt.getTransferable();
269 java.util.List files = null;
273 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
274 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
276 //Works on Windows and MacOSX
277 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
278 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
280 else if (t.isDataFlavorSupported(uriListFlavor))
282 // This is used by Unix drag system
283 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
284 String data = (String) t.getTransferData(uriListFlavor);
285 files = new java.util.ArrayList(1);
286 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
289 st.hasMoreTokens(); )
291 String s = st.nextToken();
292 if (s.startsWith("#"))
294 // the line is a comment (as per the RFC 2483)
298 java.net.URI uri = new java.net.URI(s);
299 java.io.File file = new java.io.File(uri);
313 for (int i = 0; i < files.size(); i++)
315 String file = files.get(i).toString();
316 String protocol = FormatAdapter.FILE;
317 String format = null;
319 if (file.endsWith(".jar"))
326 format = new IdentifyFile().Identify(file,
331 new FileLoader().LoadFile(file, protocol, format);
337 ex.printStackTrace();
345 * @param e DOCUMENT ME!
347 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
349 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
353 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
358 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
359 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
361 chooser.setFileView(new JalviewFileView());
362 chooser.setDialogTitle("Open local file");
363 chooser.setToolTipText("Open");
365 int value = chooser.showOpenDialog(this);
367 if (value == JalviewFileChooser.APPROVE_OPTION)
369 String choice = chooser.getSelectedFile().getPath();
370 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
371 chooser.getSelectedFile().getParent());
373 String format = null;
374 if (chooser.getSelectedFormat().equals("Jalview"))
380 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
383 if (viewport != null)
384 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
386 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
395 * @param e DOCUMENT ME!
397 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
399 // This construct allows us to have a wider textfield
401 JLabel label = new JLabel("Enter URL of Input File");
402 final JComboBox history = new JComboBox();
404 JPanel panel = new JPanel(new GridLayout(2,1));
407 history.setPreferredSize(new Dimension(400,20));
408 history.setEditable(true);
409 history.addItem("http://www.");
411 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
415 if (historyItems != null)
417 st = new StringTokenizer(historyItems, "\t");
419 while (st.hasMoreTokens())
421 history.addItem(st.nextElement());
425 int reply = JOptionPane.showInternalConfirmDialog(desktop,
426 panel, "Input Alignment From URL",
427 JOptionPane.OK_CANCEL_OPTION );
430 if (reply != JOptionPane.OK_OPTION )
435 String url = history.getSelectedItem().toString();
437 if (url.toLowerCase().endsWith(".jar"))
439 if (viewport != null)
440 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
442 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
446 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
448 if (format.equals("URL NOT FOUND"))
450 JOptionPane.showInternalMessageDialog(Desktop.desktop,
451 "Couldn't locate " + url,
453 JOptionPane.WARNING_MESSAGE);
458 if (viewport != null)
459 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
461 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
468 * @param e DOCUMENT ME!
470 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
472 CutAndPasteTransfer cap = new CutAndPasteTransfer();
473 cap.setForInput(viewport);
474 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
482 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
483 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
484 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
485 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
492 * @param e DOCUMENT ME!
494 public void aboutMenuItem_actionPerformed(ActionEvent e)
496 StringBuffer message = new StringBuffer("JalView version " +
497 jalview.bin.Cache.getProperty(
501 Cache.getDefault("BUILD_DATE", "unknown"));
503 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
504 jalview.bin.Cache.getProperty("VERSION")))
506 message.append("\n\n!! Jalview version "
507 + jalview.bin.Cache.getProperty("LATEST_VERSION")
508 + " is available for download from http://www.jalview.org !!\n");
512 message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
513 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
514 "\nFor all issues relating to Jalview, email help@jalview.org" +
515 "\n\nIf you use JalView, please cite:" +
516 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
517 "\nBioinformatics, 2004 20;426-7.");
519 JOptionPane.showInternalMessageDialog(Desktop.desktop,
521 message.toString(), "About Jalview",
522 JOptionPane.INFORMATION_MESSAGE);
528 * @param e DOCUMENT ME!
530 public void documentationMenuItem_actionPerformed(ActionEvent e)
534 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
535 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
536 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
538 javax.help.HelpBroker hb = hs.createHelpBroker();
539 hb.setCurrentID("home");
540 hb.setDisplayed(true);
544 ex.printStackTrace();
551 * @param e DOCUMENT ME!
553 protected void preferences_actionPerformed(ActionEvent e)
561 * @param e DOCUMENT ME!
563 public void saveState_actionPerformed(ActionEvent e)
565 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
566 "LAST_DIRECTORY"), new String[] { "jar" },
567 new String[] { "Jalview Project" }, "Jalview Project");
569 chooser.setFileView(new JalviewFileView());
570 chooser.setDialogTitle("Save State");
572 int value = chooser.showSaveDialog(this);
574 if (value == JalviewFileChooser.APPROVE_OPTION)
576 java.io.File choice = chooser.getSelectedFile();
577 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
578 new Jalview2XML().SaveState(choice);
585 * @param e DOCUMENT ME!
587 public void loadState_actionPerformed(ActionEvent e)
589 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
590 "LAST_DIRECTORY"), new String[] { "jar" },
591 new String[] { "Jalview Project" }, "Jalview Project");
592 chooser.setFileView(new JalviewFileView());
593 chooser.setDialogTitle("Restore state");
595 int value = chooser.showOpenDialog(this);
597 if (value == JalviewFileChooser.APPROVE_OPTION)
599 String choice = chooser.getSelectedFile().getAbsolutePath();
600 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
601 chooser.getSelectedFile().getParent());
602 new Jalview2XML().LoadJalviewAlign(choice);
606 /* public void vamsasLoad_actionPerformed(ActionEvent e)
608 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
609 getProperty("LAST_DIRECTORY"));
611 chooser.setFileView(new JalviewFileView());
612 chooser.setDialogTitle("Load Vamsas file");
613 chooser.setToolTipText("Import");
615 int value = chooser.showOpenDialog(this);
617 if (value == JalviewFileChooser.APPROVE_OPTION)
619 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
621 chooser.getSelectedFile().getAbsolutePath()
628 public void inputSequence_actionPerformed(ActionEvent e)
630 new SequenceFetcher(null);
633 JPanel progressPanel;
635 public void startLoading(final String fileName)
637 if (fileLoadingCount == 0)
639 progressPanel = new JPanel(new BorderLayout());
640 JProgressBar progressBar = new JProgressBar();
641 progressBar.setIndeterminate(true);
643 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
646 progressPanel.add(progressBar, BorderLayout.CENTER);
648 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
654 public void stopLoading()
657 if (fileLoadingCount < 1)
659 if(progressPanel!=null)
661 this.getContentPane().remove(progressPanel);
662 progressPanel = null;
664 fileLoadingCount = 0;
668 jalview.gui.VamsasClient v_client=null;
669 public void vamsasLoad_actionPerformed(ActionEvent e)
671 if (v_client==null) {
673 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
674 getProperty("LAST_DIRECTORY"));
676 chooser.setFileView(new JalviewFileView());
677 chooser.setDialogTitle("Load Vamsas file");
678 chooser.setToolTipText("Import");
680 int value = chooser.showOpenDialog(this);
682 if (value == JalviewFileChooser.APPROVE_OPTION)
684 v_client = new jalview.gui.VamsasClient(this,
685 chooser.getSelectedFile());
686 this.vamsasLoad.setText("Session Update");
687 this.vamsasStop.setVisible(true);
688 v_client.initial_update();
691 // store current data in session.
692 v_client.push_update();
695 public void vamsasStop_actionPerformed(ActionEvent e) {
696 if (v_client!=null) {
697 v_client.end_session();
699 this.vamsasStop.setVisible(false);
700 this.vamsasLoad.setText("Start Vamsas Session...");