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 javax.swing.*;
\r
17 import java.awt.event.*;
\r
18 import java.awt.dnd.*;
\r
19 import javax.swing.*;
\r
20 import java.awt.datatransfer.*;
\r
21 import jalview.bin.Cache;
\r
24 public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener
\r
26 public static JDesktopPane desktop;
\r
27 static int openFrameCount = 0;
\r
28 static final int xOffset = 30, yOffset = 30;
\r
34 java.net.URL url = getClass().getResource("/images/logo.gif");
\r
37 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
38 MediaTracker mt = new MediaTracker(this);
\r
39 mt.addImage(image, 0);
\r
41 setIconImage(image);
\r
44 }catch(Exception ex){}
\r
46 setTitle("Jalview 2005");
\r
47 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
48 desktop = new JDesktopPane();
\r
49 // desktop.setBackground(Color.white);
\r
50 setContentPane(desktop);
\r
51 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
\r
54 // This line prevents Windows Look&Feel resizing all new windows to maximum
\r
55 // if previous window was maximised
\r
56 desktop.setDesktopManager( new DefaultDesktopManager() );
\r
59 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
\r
60 String x = jalview.bin.Cache.getProperty("SCREEN_X");
\r
61 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
\r
62 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
\r
63 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
\r
65 if(x!=null && y!=null && width!=null && height!=null)
\r
67 setBounds( Integer.parseInt(x), Integer.parseInt(y),
\r
68 Integer.parseInt(width), Integer.parseInt(height));
\r
71 setBounds( (int)(screenSize.width-900)/2,
\r
72 (int)(screenSize.height-650)/2,
\r
76 this.addWindowListener(new WindowAdapter()
\r
78 public void windowClosing(WindowEvent evt)
\r
80 jalview.bin.Cache.setProperty("SCREEN_X",
\r
81 getBounds().x + "");
\r
82 jalview.bin.Cache.setProperty("SCREEN_Y",
\r
83 getBounds().y + "");
\r
84 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
\r
85 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
\r
90 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
\r
92 /////////Add a splashscreen on startup
\r
93 /////////Add a splashscreen on startup
\r
94 JInternalFrame frame = new JInternalFrame();
\r
96 SplashScreen splash = new SplashScreen(frame, image);
\r
97 frame.setContentPane(splash);
\r
98 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
99 addInternalFrame(frame, "", 750,160, false);
\r
100 frame.setLocation( (int)((getWidth()-750) /2), (int)((getHeight()-160) /2));
\r
102 public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)
\r
104 addInternalFrame(frame, title, w, h, true);
\r
107 public static void addInternalFrame(final JInternalFrame frame, String title,
\r
110 boolean resizable )
\r
112 desktop.add(frame);
\r
115 frame.setSelected(true);
\r
116 } catch (java.beans.PropertyVetoException e) {}
\r
117 frame.setTitle(title);
\r
118 frame.setSize(w,h);
\r
119 frame.setClosable(true);
\r
120 frame.setResizable(resizable);
\r
121 frame.setMaximizable(resizable);
\r
122 frame.setIconifiable(resizable);
\r
123 frame.setFrameIcon(null);
\r
124 frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
\r
126 final JMenuItem menuItem = new JMenuItem(title);
\r
127 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
128 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
\r
131 windowMenu.remove(menuItem);
\r
135 menuItem.addActionListener(new ActionListener()
\r
137 public void actionPerformed(ActionEvent e)
\r
139 try{ frame.setSelected(true); frame.setIcon(false); }
\r
140 catch(java.beans.PropertyVetoException ex){};
\r
144 frame.setVisible(true);
\r
145 windowMenu.add(menuItem);
\r
148 public void dragEnter(DropTargetDragEvent evt){}
\r
149 public void dragExit(DropTargetEvent evt){}
\r
150 public void dragOver(DropTargetDragEvent evt){}
\r
151 public void dropActionChanged(DropTargetDragEvent evt){}
\r
152 public void drop(DropTargetDropEvent evt)
\r
154 Transferable t = evt.getTransferable();
\r
155 if(!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
\r
158 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
160 java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
\r
162 for (int i = 0; i < files.size(); i++)
\r
164 String file = files.get(i).toString();
\r
165 String protocol = "File";
\r
166 String format = jalview.io.IdentifyFile.Identify(file, protocol);
\r
167 LoadFile(file, protocol, format);
\r
170 }catch(Exception ex){ex.printStackTrace();}
\r
174 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
\r
176 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
\r
177 new String[]{"fa", "fasta", "fastq", "blc", "msf", "pfam", "aln", "pir"}, "Alignment files");
\r
178 chooser.setFileView(new JalviewFileView());
\r
179 chooser.setDialogTitle("Open local file");
\r
180 chooser.setToolTipText("Open");
\r
181 int value = chooser.showOpenDialog(this);
\r
182 if(value == JalviewFileChooser.APPROVE_OPTION)
\r
184 String choice = chooser.getSelectedFile().getPath();
\r
185 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
\r
186 String format = IdentifyFile.Identify(choice, "File");
\r
187 LoadFile(choice, "File", format);
\r
191 public void LoadFile(String file, String protocol, String format)
\r
193 LoadingThread loader = new LoadingThread(file, protocol, format);
\r
197 class LoadingThread extends Thread
\r
199 String file, protocol, format;
\r
201 public LoadingThread(String file, String protocol, String format)
\r
204 this.protocol = protocol;
\r
205 this.format = format;
\r
209 SequenceI [] sequences = null;
\r
211 if (FormatAdapter.formats.contains(format))
\r
212 sequences = FormatAdapter.readFile(file, protocol, format);
\r
214 if (sequences != null && sequences.length>0)
\r
216 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
217 addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
218 af.statusBar.setText("Successfully loaded file " + file);
\r
220 af.setMaximum(Preferences.showFullscreen);
\r
221 }catch(Exception ex){}
\r
225 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't open file.\n"
\r
226 + "Formats currently supported are\n"
\r
227 + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM" // JBPNote - message should be generated through FormatAdapter!
\r
228 ,"Error loading file",
\r
229 JOptionPane.WARNING_MESSAGE);
\r
235 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
237 JOptionPane op = new JOptionPane();
\r
239 String url = JOptionPane.showInternalInputDialog(Desktop.desktop,"Enter url of input file",
\r
240 "Input alignment from URL",
\r
241 JOptionPane.QUESTION_MESSAGE,
\r
243 "http://www.").toString();
\r
247 String format = IdentifyFile.Identify(url, "URL");
\r
249 if (format.equals("URL NOT FOUND"))
\r
251 JOptionPane.showInternalMessageDialog(Desktop.desktop,"Couldn't locate " + url,
\r
253 JOptionPane.WARNING_MESSAGE);
\r
257 LoadFile(url, "URL", format);
\r
260 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\r
262 CutAndPasteTransfer cap = new CutAndPasteTransfer(true);
\r
263 int accept = JOptionPane.showInternalOptionDialog(Desktop.desktop, cap, "Cut & paste Alignment File",
\r
264 JOptionPane.YES_NO_CANCEL_OPTION,
\r
265 JOptionPane.PLAIN_MESSAGE,
\r
267 new Object[]{"Accept", "Cancel", }, null);
\r
270 if(accept == JOptionPane.YES_OPTION)
\r
272 String format = IdentifyFile.Identify(cap.getText(), "Paste");
\r
273 SequenceI [] sequences = null;
\r
275 if (FormatAdapter.formats.contains( format ))
\r
276 sequences = FormatAdapter.readFile(cap.getText(), "Paste", format);
\r
279 if(sequences!=null)
\r
281 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
282 addInternalFrame(af, "Cut & Paste input - "+format,
\r
283 AlignFrame.NEW_WINDOW_WIDTH,
\r
284 AlignFrame.NEW_WINDOW_HEIGHT);
\r
285 af.statusBar.setText("Successfully pasted alignment file");
\r
288 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n"
\r
289 +"Formats currently supported are\n"
\r
290 +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",
\r
291 "Error parsing text", JOptionPane.WARNING_MESSAGE);
\r
299 public void quit_actionPerformed(ActionEvent e)
\r
301 if(jalview.bin.Jalview.applet!=null)
\r
302 jalview.bin.Jalview.applet.destroy();
\r
309 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
311 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
312 "JalView 2005 version " + jalview.bin.Cache.VERSION+"; last updated: "+jalview.bin.Cache.BUILD_DATE
\r
313 +"\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton."
\r
314 +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."
\r
315 +"\nIf you use JalView, please cite:"
\r
316 +"\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\""
\r
317 +"\nBioinformatics, 2004 12;426-7.",
\r
319 JOptionPane.INFORMATION_MESSAGE);
\r
322 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
326 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
\r
327 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,"help/help");
\r
328 javax.help.HelpSet hs = new javax.help.HelpSet(cl,url);
\r
330 javax.help.HelpBroker hb = hs.createHelpBroker();
\r
331 hb.setLocation(new Point(200, 50));
\r
332 hb.setSize(new Dimension(800,700));
\r
333 hb.setCurrentID("home");
\r
334 hb.setDisplayed(true);
\r
336 catch (Exception ex)
\r
338 ex.printStackTrace();
\r
342 protected void preferences_actionPerformed(ActionEvent e)
\r
344 Preferences pref = new Preferences();
\r