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
23 import jalview.bin.Cache;
\r
26 public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener
\r
28 public static JDesktopPane desktop;
\r
29 static int openFrameCount = 0;
\r
30 static final int xOffset = 30, yOffset = 30;
\r
36 java.net.URL url = getClass().getResource("/images/logo.gif");
\r
39 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
40 MediaTracker mt = new MediaTracker(this);
\r
41 mt.addImage(image, 0);
\r
43 setIconImage(image);
\r
46 }catch(Exception ex){}
\r
48 setTitle("Jalview 2005");
\r
49 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
50 desktop = new JDesktopPane();
\r
51 // desktop.setBackground(Color.white);
\r
52 setContentPane(desktop);
\r
53 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
\r
56 // This line prevents Windows Look&Feel resizing all new windows to maximum
\r
57 // if previous window was maximised
\r
58 desktop.setDesktopManager( new DefaultDesktopManager() );
\r
61 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
\r
62 String x = jalview.bin.Cache.getProperty("SCREEN_X");
\r
63 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
\r
64 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
\r
65 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
\r
67 if(x!=null && y!=null && width!=null && height!=null)
\r
69 setBounds( Integer.parseInt(x), Integer.parseInt(y),
\r
70 Integer.parseInt(width), Integer.parseInt(height));
\r
73 setBounds( (int)(screenSize.width-900)/2,
\r
74 (int)(screenSize.height-650)/2,
\r
78 this.addWindowListener(new WindowAdapter()
\r
80 public void windowClosing(WindowEvent evt)
\r
82 jalview.bin.Cache.setProperty("SCREEN_X",
\r
83 getBounds().x + "");
\r
84 jalview.bin.Cache.setProperty("SCREEN_Y",
\r
85 getBounds().y + "");
\r
86 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
\r
87 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
\r
92 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
\r
94 /////////Add a splashscreen on startup
\r
95 /////////Add a splashscreen on startup
\r
96 JInternalFrame frame = new JInternalFrame();
\r
98 SplashScreen splash = new SplashScreen(frame, image);
\r
99 frame.setContentPane(splash);
\r
100 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
101 addInternalFrame(frame, "", 750,160, false);
\r
102 frame.setLocation( (int)((getWidth()-750) /2), (int)((getHeight()-160) /2));
\r
104 public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)
\r
106 addInternalFrame(frame, title, w, h, true);
\r
109 public static void addInternalFrame(final JInternalFrame frame, String title,
\r
112 boolean resizable )
\r
114 desktop.add(frame);
\r
117 frame.setSelected(true);
\r
118 } catch (java.beans.PropertyVetoException e) {}
\r
119 frame.setTitle(title);
\r
120 frame.setSize(w,h);
\r
121 frame.setClosable(true);
\r
122 frame.setResizable(resizable);
\r
123 frame.setMaximizable(resizable);
\r
124 frame.setIconifiable(resizable);
\r
125 frame.setFrameIcon(null);
\r
126 frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
\r
128 final JMenuItem menuItem = new JMenuItem(title);
\r
129 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
130 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
\r
133 windowMenu.remove(menuItem);
\r
137 menuItem.addActionListener(new ActionListener()
\r
139 public void actionPerformed(ActionEvent e)
\r
141 try{ frame.setSelected(true); frame.setIcon(false); }
\r
142 catch(java.beans.PropertyVetoException ex){};
\r
146 frame.setVisible(true);
\r
147 windowMenu.add(menuItem);
\r
150 public void dragEnter(DropTargetDragEvent evt){}
\r
151 public void dragExit(DropTargetEvent evt){}
\r
152 public void dragOver(DropTargetDragEvent evt){}
\r
153 public void dropActionChanged(DropTargetDragEvent evt){}
\r
154 public void drop(DropTargetDropEvent evt)
\r
156 Transferable t = evt.getTransferable();
\r
157 if(!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
\r
160 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
162 java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
\r
164 for (int i = 0; i < files.size(); i++)
\r
166 String file = files.get(i).toString();
\r
167 String protocol = "File";
\r
168 String format = jalview.io.IdentifyFile.Identify(file, protocol);
\r
169 LoadFile(file, protocol, format);
\r
172 }catch(Exception ex){ex.printStackTrace();}
\r
176 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
\r
178 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
\r
179 new String[]{"fa", "fasta", "fastq", "blc", "msf", "pfam", "aln", "pir"}, "Alignment files");
\r
180 chooser.setFileView(new JalviewFileView());
\r
181 chooser.setDialogTitle("Open local file");
\r
182 chooser.setToolTipText("Open");
\r
183 int value = chooser.showOpenDialog(this);
\r
184 if(value == JalviewFileChooser.APPROVE_OPTION)
\r
186 String choice = chooser.getSelectedFile().getPath();
\r
187 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
\r
188 String format = IdentifyFile.Identify(choice, "File");
\r
189 LoadFile(choice, "File", format);
\r
193 public void LoadFile(String file, String protocol, String format)
\r
195 LoadingThread loader = new LoadingThread(file, protocol, format);
\r
199 class LoadingThread extends Thread
\r
201 String file, protocol, format;
\r
203 public LoadingThread(String file, String protocol, String format)
\r
206 this.protocol = protocol;
\r
207 this.format = format;
\r
211 SequenceI [] sequences = null;
\r
213 if (FormatProperties.contains(format))
\r
214 sequences = FormatAdapter.read(file, protocol, format);
\r
216 if (sequences != null && sequences.length>0)
\r
218 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
219 addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
220 af.statusBar.setText("Successfully loaded file " + file);
\r
221 String string = Cache.getProperty("SHOW_FULLSCREEN");
\r
223 if (string != null)
\r
224 af.setMaximum(Boolean.valueOf(string).booleanValue());
\r
225 }catch(Exception ex){}
\r
229 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't open file.\n"
\r
230 + "Formats currently supported are\n"
\r
231 + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM" // JBPNote - message should be generated through FormatAdapter!
\r
232 ,"Error loading file",
\r
233 JOptionPane.WARNING_MESSAGE);
\r
239 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
241 JOptionPane op = new JOptionPane();
\r
243 String url = JOptionPane.showInternalInputDialog(Desktop.desktop,"Enter url of input file",
\r
244 "Input alignment from URL",
\r
245 JOptionPane.QUESTION_MESSAGE,
\r
247 "http://www.").toString();
\r
251 String format = IdentifyFile.Identify(url, "URL");
\r
253 if (format.equals("URL NOT FOUND"))
\r
255 JOptionPane.showInternalMessageDialog(Desktop.desktop,"Couldn't locate " + url,
\r
257 JOptionPane.WARNING_MESSAGE);
\r
261 LoadFile(url, "URL", format);
\r
264 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\r
266 CutAndPasteTransfer cap = new CutAndPasteTransfer(true);
\r
267 int accept = JOptionPane.showInternalOptionDialog(Desktop.desktop, cap, "Cut & paste Alignment File",
\r
268 JOptionPane.YES_NO_CANCEL_OPTION,
\r
269 JOptionPane.PLAIN_MESSAGE,
\r
271 new Object[]{"Accept", "Cancel", }, null);
\r
274 if(accept == JOptionPane.YES_OPTION)
\r
276 String format = IdentifyFile.Identify(cap.getText(), "Paste");
\r
277 SequenceI [] sequences = null;
\r
279 if (FormatProperties.contains( format ))
\r
280 sequences = FormatAdapter.read(cap.getText(), "Paste", format);
\r
283 if(sequences!=null)
\r
285 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
286 addInternalFrame(af, "Cut & Paste input - "+format,
\r
287 AlignFrame.NEW_WINDOW_WIDTH,
\r
288 AlignFrame.NEW_WINDOW_HEIGHT);
\r
289 af.statusBar.setText("Successfully pasted alignment file");
\r
292 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n"
\r
293 +"Formats currently supported are\n"
\r
294 +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",
\r
295 "Error parsing text", JOptionPane.WARNING_MESSAGE);
\r
303 public void quit_actionPerformed(ActionEvent e)
\r
305 if(jalview.bin.Jalview.applet!=null)
\r
306 jalview.bin.Jalview.applet.destroy();
\r
313 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
315 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
316 "JalView 2005 version " + jalview.bin.Cache.VERSION+"; last updated: "+jalview.bin.Cache.BUILD_DATE
\r
317 +"\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton."
\r
318 +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."
\r
319 +"\nIf you use JalView, please cite:"
\r
320 +"\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\""
\r
321 +"\nBioinformatics, 2004 12;426-7.",
\r
323 JOptionPane.INFORMATION_MESSAGE);
\r
326 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
330 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
\r
331 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,"help/help");
\r
332 javax.help.HelpSet hs = new javax.help.HelpSet(cl,url);
\r
334 javax.help.HelpBroker hb = hs.createHelpBroker();
\r
335 hb.setLocation(new Point(200, 50));
\r
336 hb.setSize(new Dimension(800,700));
\r
337 hb.setCurrentID("home");
\r
338 hb.setDisplayed(true);
\r
340 catch (Exception ex)
\r
342 ex.printStackTrace();
\r