1 /********************
\r
2 * 2004 Jalview Reengineered
\r
10 package jalview.gui;
\r
12 import jalview.gui.*;
\r
13 import jalview.io.*;
\r
14 import jalview.datamodel.*;
\r
15 import jalview.schemes.*;
\r
16 import javax.swing.*;
\r
18 import java.awt.event.*;
\r
19 import java.awt.dnd.*;
\r
20 import javax.swing.*;
\r
21 import java.awt.datatransfer.*;
\r
25 public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener
\r
27 public static JDesktopPane desktop;
\r
28 static int openFrameCount = 0;
\r
29 static final int xOffset = 30, yOffset = 30;
\r
35 java.net.URL url = getClass().getResource("/images/logo.gif");
\r
38 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
39 MediaTracker mt = new MediaTracker(this);
\r
40 mt.addImage(image, 0);
\r
42 setIconImage(image);
\r
45 }catch(Exception ex){}
\r
47 setTitle("Jalview 2005");
\r
48 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
49 desktop = new JDesktopPane();
\r
50 // desktop.setBackground(Color.white);
\r
51 setContentPane(desktop);
\r
52 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
\r
55 // This line prevents Windows Look&Feel resizing all new windows to maximum
\r
56 // if previous window was maximised
\r
57 desktop.setDesktopManager( new DefaultDesktopManager() );
\r
60 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
\r
61 String x = jalview.bin.Cache.getProperty("SCREEN_X");
\r
62 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
\r
63 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
\r
64 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
\r
66 if(x!=null && y!=null && width!=null && height!=null)
\r
68 setBounds( Integer.parseInt(x), Integer.parseInt(y),
\r
69 Integer.parseInt(width), Integer.parseInt(height));
\r
72 setBounds( (int)(screenSize.width-900)/2,
\r
73 (int)(screenSize.height-650)/2,
\r
77 this.addWindowListener(new WindowAdapter()
\r
79 public void windowClosing(WindowEvent evt)
\r
81 jalview.bin.Cache.setProperty("SCREEN_X",
\r
82 getBounds().x + "");
\r
83 jalview.bin.Cache.setProperty("SCREEN_Y",
\r
84 getBounds().y + "");
\r
85 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
\r
86 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
\r
91 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
\r
94 /////////Add a splashscreen on startup
\r
95 JInternalFrame frame = new JInternalFrame();
\r
97 SplashScreen splash = new SplashScreen(frame, image);
\r
98 frame.setContentPane(splash);
\r
104 frame.setSelected(true);
\r
106 catch (java.beans.PropertyVetoException e)
\r
108 frame.setResizable(true);
\r
109 frame.setSize(750, 160);
\r
110 frame.setLocation( (int)((getWidth()-750) /2), (int)((getHeight()-160) /2));
\r
111 frame.setClosable(false);
\r
112 frame.setIconifiable(false);
\r
113 frame.setMaximizable(false);
\r
114 frame.setFrameIcon(null);
\r
115 frame.setVisible(true);
\r
118 public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)
\r
120 addInternalFrame(frame, title, w, h, true);
\r
123 public static void addInternalFrame(final JInternalFrame frame, String title,
\r
126 boolean resizable )
\r
128 desktop.add(frame);
\r
131 frame.setSelected(true);
\r
132 } catch (java.beans.PropertyVetoException e) {}
\r
133 frame.setTitle(title);
\r
134 frame.setSize(w,h);
\r
135 frame.setClosable(true);
\r
136 frame.setResizable(resizable);
\r
137 frame.setMaximizable(resizable);
\r
138 frame.setIconifiable(resizable);
\r
139 frame.setFrameIcon(null);
\r
140 frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
\r
142 final JMenuItem menuItem = new JMenuItem(title);
\r
143 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
144 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
\r
147 windowMenu.remove(menuItem);
\r
151 menuItem.addActionListener(new ActionListener()
\r
153 public void actionPerformed(ActionEvent e)
\r
155 try{ frame.setSelected(true); frame.setIcon(false); }
\r
156 catch(java.beans.PropertyVetoException ex){};
\r
160 frame.setVisible(true);
\r
161 windowMenu.add(menuItem);
\r
164 public void dragEnter(DropTargetDragEvent evt){}
\r
165 public void dragExit(DropTargetEvent evt){}
\r
166 public void dragOver(DropTargetDragEvent evt){}
\r
167 public void dropActionChanged(DropTargetDragEvent evt){}
\r
168 public void drop(DropTargetDropEvent evt)
\r
170 Transferable t = evt.getTransferable();
\r
171 if(!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
\r
174 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
176 java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
\r
178 for (int i = 0; i < files.size(); i++)
\r
180 String file = files.get(i).toString();
\r
181 String protocol = "File";
\r
182 String format = jalview.io.IdentifyFile.Identify(file, protocol);
\r
183 LoadFile(file, protocol, format);
\r
186 }catch(Exception ex){ex.printStackTrace();}
\r
189 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
\r
191 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
\r
192 new String[]{"fa", "fasta", "fastq", "blc", "msf", "pfam", "aln", "pir"}, "Alignment files");
\r
193 chooser.setFileView(new JalviewFileView());
\r
194 chooser.setDialogTitle("Open local file");
\r
195 chooser.setToolTipText("Open");
\r
196 int value = chooser.showOpenDialog(this);
\r
197 if(value == JalviewFileChooser.APPROVE_OPTION)
\r
199 String choice = chooser.getSelectedFile().getPath();
\r
200 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
\r
201 String format = IdentifyFile.Identify(choice, "File");
\r
202 LoadFile(choice, "File", format);
\r
206 public void LoadFile(String file, String protocol, String format)
\r
208 SequenceI [] sequences = null;
\r
210 if (FormatProperties.contains(format))
\r
211 sequences = FormatAdapter.read(file, protocol, format);
\r
213 if (sequences != null && sequences.length>0)
\r
215 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
216 addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
217 af.statusBar.setText("Successfully loaded file " + file);
\r
221 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't open file.\n"
\r
222 + "Formats currently supported are\n"
\r
223 + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM" // JBPNote - message should be generated through FormatAdapter!
\r
224 ,"Error loading file",
\r
225 JOptionPane.WARNING_MESSAGE);
\r
229 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
231 String url = JOptionPane.showInternalInputDialog(Desktop.desktop,"Enter url of input file",
\r
232 "Input alignment from URL",
\r
233 JOptionPane.QUESTION_MESSAGE);
\r
237 String format = IdentifyFile.Identify(url, "URL");
\r
239 if (format.equals("URL NOT FOUND"))
\r
241 JOptionPane.showInternalMessageDialog(Desktop.desktop,"Couldn't locate " + url,
\r
243 JOptionPane.WARNING_MESSAGE);
\r
247 LoadFile(url, "URL", format);
\r
250 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\r
252 CutAndPasteTransfer cap = new CutAndPasteTransfer(true);
\r
253 int accept = JOptionPane.showInternalOptionDialog(Desktop.desktop, cap, "Cut & paste Alignment File",
\r
254 JOptionPane.YES_NO_CANCEL_OPTION,
\r
255 JOptionPane.PLAIN_MESSAGE,
\r
257 new Object[]{"Accept", "Cancel", }, null);
\r
260 if(accept == JOptionPane.YES_OPTION)
\r
262 String format = IdentifyFile.Identify(cap.getText(), "Paste");
\r
263 SequenceI [] sequences = null;
\r
265 if (FormatProperties.contains( format ))
\r
266 sequences = FormatAdapter.read(cap.getText(), "Paste", format);
\r
269 if(sequences!=null)
\r
271 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
272 addInternalFrame(af, "Cut & Paste input - "+format,
\r
273 AlignFrame.NEW_WINDOW_WIDTH,
\r
274 AlignFrame.NEW_WINDOW_HEIGHT);
\r
275 af.statusBar.setText("Successfully pasted alignment file");
\r
278 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n"
\r
279 +"Formats currently supported are\n"
\r
280 +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",
\r
281 "Error parsing text", JOptionPane.WARNING_MESSAGE);
\r
289 public void quit_actionPerformed(ActionEvent e)
\r
291 if(jalview.bin.Jalview.applet!=null)
\r
292 jalview.bin.Jalview.applet.destroy();
\r
299 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
301 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
302 "JalView 2005 version " + jalview.bin.Cache.VERSION+"; last updated: "+jalview.bin.Cache.BUILD_DATE
\r
303 +"\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton."
\r
304 +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."
\r
305 +"\nIf you use JalView, please cite: Bioinformatics, 2004 12;426-7."
\r
306 +"\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",
\r
308 JOptionPane.INFORMATION_MESSAGE);
\r
311 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
315 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
\r
316 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,"help/help");
\r
317 javax.help.HelpSet hs = new javax.help.HelpSet(cl,url);
\r
319 javax.help.HelpBroker hb = hs.createHelpBroker();
\r
320 hb.setLocation(new Point(200, 50));
\r
321 hb.setSize(new Dimension(800,700));
\r
322 hb.setCurrentID("home");
\r
323 hb.setDisplayed(true);
\r
325 catch (Exception ex)
\r
327 ex.printStackTrace();
\r