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
20 public class Desktop extends jalview.jbgui.GDesktop
\r
22 public static JDesktopPane desktop;
\r
23 static int openFrameCount = 0;
\r
24 static final int xOffset = 30, yOffset = 30;
\r
25 static boolean splashScreenVisible = false;
\r
31 java.net.URL url = getClass().getResource("/BartonGroupBanner.gif");
\r
34 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
35 MediaTracker mt = new MediaTracker(this);
\r
36 mt.addImage(image, 0);
\r
38 setIconImage(image);
\r
41 }catch(Exception ex){}
\r
43 setTitle("Jalview 2005");
\r
44 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
46 desktop = new JDesktopPane();
\r
47 setContentPane(desktop);
\r
48 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
\r
50 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
\r
51 setBounds( (int)(screenSize.getWidth()-1200)/2,
\r
52 (int)(screenSize.getHeight()-800)/2,
\r
57 /////////Add a splashscreen on startup
\r
58 JInternalFrame frame = new JInternalFrame();
\r
60 SplashScreen splash = new SplashScreen(frame, image);
\r
61 frame.setContentPane(splash);
\r
62 addInternalFrame(frame, "",845,200);
\r
63 splashScreenVisible = true;
\r
65 frame.setLocation( (int)((getWidth()-845) /2), (int)((getHeight()-240) /2));
\r
66 frame.setClosable(false);
\r
67 frame.setIconifiable(false);
\r
68 frame.setMaximizable(false);
\r
69 frame.setFrameIcon(null);
\r
70 splashScreenVisible = false;
\r
74 public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)
\r
76 if(!splashScreenVisible)
\r
77 frame.setVisible(true); //necessary as of 1.3
\r
81 frame.setSelected(true);
\r
82 } catch (java.beans.PropertyVetoException e) {}
\r
83 frame.setTitle(title);
\r
84 frame.setResizable(true);
\r
86 frame.setClosable(true);
\r
87 frame.setMaximizable(true);
\r
88 frame.setIconifiable(true);
\r
89 frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
\r
91 final JMenuItem menuItem = new JMenuItem(title);
\r
92 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
93 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
\r
96 windowMenu.remove(menuItem);
\r
100 menuItem.addActionListener(new ActionListener()
\r
102 public void actionPerformed(ActionEvent e)
\r
104 try{ frame.setSelected(true); frame.setIcon(false); }
\r
105 catch(java.beans.PropertyVetoException ex){};
\r
109 windowMenu.add(menuItem);
\r
114 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
\r
116 JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY);
\r
117 chooser.setDialogTitle("Open local file");
\r
118 chooser.setToolTipText("Open");
\r
119 int value = chooser.showOpenDialog(this);
\r
120 if(value == JFileChooser.APPROVE_OPTION)
\r
122 String choice = chooser.getSelectedFile().getPath();
\r
123 jalview.bin.Cache.LAST_DIRECTORY = choice;
\r
124 String format = IdentifyFile.Identify(choice, "File");
\r
125 LoadFile(choice, "File", format);
\r
129 public void LoadFile(String file, String protocol, String format)
\r
131 SequenceI [] sequences = null;
\r
133 if (FormatProperties.contains(format))
\r
134 sequences = FormatAdapter.read(file, protocol, format);
\r
136 if (sequences != null)
\r
138 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
139 addInternalFrame(af, file, 700, 500);
\r
140 af.statusBar.setText("Successfully loaded file " + file);
\r
145 JOptionPane.showInternalMessageDialog(this, "Couldn't open file.\n"
\r
146 + "Formats currently supported are\n"
\r
147 + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM"
\r
148 ,"Error loading file",
\r
149 JOptionPane.WARNING_MESSAGE);
\r
153 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
155 String url = JOptionPane.showInternalInputDialog(this,"Enter url of input file",
\r
156 "Input alignment from URL",
\r
157 JOptionPane.QUESTION_MESSAGE);
\r
161 String format = IdentifyFile.Identify(url, "URL");
\r
163 System.out.println(format +" format");
\r
164 if (format.equals("URL NOT FOUND"))
\r
166 JOptionPane.showInternalMessageDialog(this,"Couldn't locate " + url,
\r
168 JOptionPane.WARNING_MESSAGE);
\r
172 LoadFile(url, "URL", format);
\r
175 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\r
177 CutAndPasteTransfer cap = new CutAndPasteTransfer(true);
\r
178 int accept = JOptionPane.showInternalOptionDialog(desktop, cap, "Cut & paste Alignment File",
\r
179 JOptionPane.YES_NO_CANCEL_OPTION,
\r
180 JOptionPane.PLAIN_MESSAGE,
\r
182 new Object[]{"Accept", "Cancel", }, null);
\r
185 if(accept == JOptionPane.YES_OPTION)
\r
187 String format = IdentifyFile.Identify(cap.getText(), "Paste");
\r
188 SequenceI [] sequences = null;
\r
190 if (FormatProperties.contains( format ))
\r
191 sequences = FormatAdapter.read(cap.getText(), "Paste", format);
\r
194 if(sequences!=null)
\r
196 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
197 addInternalFrame(af, "Cut & Paste input - "+format, 700, 500);
\r
198 af.statusBar.setText("Successfully pasted alignment file");
\r
201 JOptionPane.showInternalMessageDialog(this, "Couldn't read the pasted text.\n"
\r
202 +"Formats currently supported are\n"
\r
203 +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",
\r
204 "Error parsing text", JOptionPane.WARNING_MESSAGE);
\r
213 public void quit_actionPerformed(ActionEvent e)
\r
215 this.setVisible(false);
\r
220 protected void colourIndexMenuItem_actionPerformed(ActionEvent e)
\r
222 ColourKey colourKey = new ColourKey(null);
\r
223 addInternalFrame(colourKey, "Colour scheme key", 400, 320);
\r
227 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
229 JOptionPane.showInternalMessageDialog(desktop,
\r
231 +"\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse and Geoff Barton."
\r
232 +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."
\r
233 +"\nIf you use JalView, please cite: \"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",
\r
235 JOptionPane.INFORMATION_MESSAGE);
\r
238 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
241 jalview.util.BrowserLauncher.openURL("http://jalview.org/documentation.html");
\r
242 }catch(Exception ex){}
\r