Dont use addToDesktop for splashscreen
[jalview.git] / src / jalview / gui / Desktop.java
1 /********************\r
2  * 2004 Jalview Reengineered\r
3  * Barton Group\r
4  * Dundee University\r
5  *\r
6  * AM Waterhouse\r
7  *******************/\r
8 \r
9 \r
10 package jalview.gui;\r
11 \r
12 import jalview.gui.*;\r
13 import jalview.io.*;\r
14 import jalview.datamodel.*;\r
15 import javax.swing.*;\r
16 import java.awt.*;\r
17 import java.awt.event.*;\r
18 \r
19 \r
20 public class Desktop extends jalview.jbgui.GDesktop\r
21 {\r
22   public static JDesktopPane desktop;\r
23   static int openFrameCount = 0;\r
24   static final int xOffset = 30, yOffset = 30;\r
25 \r
26   public Desktop()\r
27   {\r
28     Image image =null;\r
29     try{\r
30       java.net.URL url = getClass().getResource("/BartonGroupBanner.gif");\r
31       if(url!=null)\r
32       {\r
33         image = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
34         MediaTracker mt = new MediaTracker(this);\r
35         mt.addImage(image, 0);\r
36         mt.waitForID(0);\r
37         setIconImage(image);\r
38       }\r
39 \r
40     }catch(Exception ex){}\r
41 \r
42     setTitle("Jalview 2005");\r
43     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
44     setVisible(true);\r
45     desktop = new JDesktopPane();\r
46     setContentPane(desktop);\r
47     desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);\r
48 \r
49     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();\r
50     int width = 1200, height = 800;\r
51     if(screenSize.getWidth()<width)\r
52       width = screenSize.width;\r
53     if(screenSize.getHeight()<height)\r
54       height = screenSize.height;\r
55 \r
56     setBounds( (int)(screenSize.width-width)/2,\r
57                (int)(screenSize.height-height)/2,\r
58               width ,\r
59               height);\r
60 \r
61 \r
62    /////////Add a splashscreen on startup\r
63     JInternalFrame frame = new JInternalFrame();\r
64 \r
65     SplashScreen splash = new SplashScreen(frame, image);\r
66     frame.setContentPane(splash);\r
67     desktop.add(frame);\r
68     frame.setVisible(true);\r
69     openFrameCount++;\r
70     try\r
71     {\r
72       frame.setSelected(true);\r
73     }\r
74     catch (java.beans.PropertyVetoException e)\r
75     {}\r
76     frame.setResizable(true);\r
77     frame.setSize(845, 200);\r
78     frame.setLocation( (int)((getWidth()-845) /2), (int)((getHeight()-240) /2));\r
79     frame.setClosable(false);\r
80     frame.setIconifiable(false);\r
81     frame.setMaximizable(false);\r
82     frame.setFrameIcon(null);\r
83 \r
84   }\r
85 \r
86   public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)\r
87   {\r
88    desktop.add(frame);\r
89    frame.setVisible(true);\r
90    openFrameCount++;\r
91    try {\r
92        frame.setSelected(true);\r
93    } catch (java.beans.PropertyVetoException e) {}\r
94    frame.setTitle(title);\r
95    frame.setResizable(true);\r
96    frame.setSize(w,h);\r
97    frame.setClosable(true);\r
98    frame.setMaximizable(true);\r
99    frame.setIconifiable(true);\r
100    frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);\r
101    frame.toFront();\r
102    final JMenuItem menuItem = new JMenuItem(title);\r
103    frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
104                                    { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)\r
105                                      {\r
106                                        openFrameCount--;\r
107                                        windowMenu.remove(menuItem);\r
108                                        System.out.println(openFrameCount);\r
109                                      };\r
110                                    });\r
111 \r
112    menuItem.addActionListener(new ActionListener()\r
113     {\r
114       public void actionPerformed(ActionEvent e)\r
115       {\r
116         try{  frame.setSelected(true);   frame.setIcon(false); }\r
117         catch(java.beans.PropertyVetoException ex){};\r
118       }\r
119     });\r
120 \r
121    windowMenu.add(menuItem);\r
122  }\r
123 \r
124 \r
125 \r
126  public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)\r
127  {\r
128    JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY);\r
129    chooser.setDialogTitle("Open local file");\r
130    chooser.setToolTipText("Open");\r
131    int value = chooser.showOpenDialog(this);\r
132    if(value == JFileChooser.APPROVE_OPTION)\r
133    {\r
134      String choice =  chooser.getSelectedFile().getPath();\r
135      jalview.bin.Cache.LAST_DIRECTORY = choice;\r
136      String format = IdentifyFile.Identify(choice, "File");\r
137      LoadFile(choice, "File", format);\r
138    }\r
139  }\r
140 \r
141  public void LoadFile(String file, String protocol,  String format)\r
142  {\r
143    SequenceI [] sequences = null;\r
144 \r
145    if (FormatProperties.contains(format))\r
146        sequences = FormatAdapter.read(file, protocol, format);\r
147 \r
148    if (sequences != null)\r
149    {\r
150      AlignFrame af = new AlignFrame(new Alignment(sequences));\r
151      addInternalFrame(af, file, 700, 500);\r
152      af.statusBar.setText("Successfully loaded file " + file);\r
153 \r
154 \r
155    }\r
156    else\r
157      JOptionPane.showInternalMessageDialog(Desktop.desktop,  "Couldn't open file.\n"\r
158                           + "Formats currently supported are\n"\r
159                           + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM"\r
160                           ,"Error loading file",\r
161                                    JOptionPane.WARNING_MESSAGE);\r
162 \r
163  }\r
164 \r
165  public void inputURLMenuItem_actionPerformed(ActionEvent e)\r
166  {\r
167    String url = JOptionPane.showInternalInputDialog(Desktop.desktop,"Enter url of input file",\r
168                                             "Input alignment from URL",\r
169                                             JOptionPane.QUESTION_MESSAGE);\r
170    if (url == null)\r
171      return;\r
172 \r
173    String format = IdentifyFile.Identify(url, "URL");\r
174 \r
175    System.out.println(format +" format");\r
176    if (format.equals("URL NOT FOUND"))\r
177    {\r
178      JOptionPane.showInternalMessageDialog(Desktop.desktop,"Couldn't locate " + url,\r
179                                    "URL not found",\r
180                                    JOptionPane.WARNING_MESSAGE);\r
181      return;\r
182    }\r
183 \r
184     LoadFile(url, "URL", format);\r
185  }\r
186 \r
187  public void inputTextboxMenuItem_actionPerformed(ActionEvent e)\r
188  {\r
189    CutAndPasteTransfer cap = new CutAndPasteTransfer(true);\r
190    int accept =  JOptionPane.showInternalOptionDialog(Desktop.desktop, cap, "Cut & paste Alignment File",\r
191                                        JOptionPane.YES_NO_CANCEL_OPTION,\r
192                                        JOptionPane.PLAIN_MESSAGE,\r
193                                        null,\r
194                                        new Object[]{"Accept", "Cancel", }, null);\r
195 \r
196 \r
197   if(accept == JOptionPane.YES_OPTION)\r
198   {\r
199     String format = IdentifyFile.Identify(cap.getText(), "Paste");\r
200     SequenceI [] sequences = null;\r
201 \r
202     if (FormatProperties.contains( format ))\r
203       sequences = FormatAdapter.read(cap.getText(), "Paste", format);\r
204 \r
205 \r
206       if(sequences!=null)\r
207       {\r
208         AlignFrame af = new AlignFrame(new Alignment(sequences));\r
209         addInternalFrame(af, "Cut & Paste input - "+format, 700, 500);\r
210         af.statusBar.setText("Successfully pasted alignment file");\r
211       }\r
212       else\r
213         JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n"\r
214                                       +"Formats currently supported are\n"\r
215                                       +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",\r
216                                       "Error parsing text", JOptionPane.WARNING_MESSAGE);\r
217 \r
218 \r
219    }\r
220  }\r
221 \r
222 /*\r
223 * Exit the program\r
224 */\r
225  public void quit_actionPerformed(ActionEvent e)\r
226  {\r
227    this.setVisible(false);\r
228    System.exit(0);\r
229  }\r
230 \r
231 \r
232  protected void colourIndexMenuItem_actionPerformed(ActionEvent e)\r
233  {\r
234    ColourKey colourKey = new ColourKey(null);\r
235    addInternalFrame(colourKey, "Colour scheme key", 400, 320);\r
236  }\r
237 \r
238 \r
239  public void aboutMenuItem_actionPerformed(ActionEvent e)\r
240  {\r
241    JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
242                                          "JalView 2005"\r
243                                        +"\nAuthors:  Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton."\r
244                                        +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."\r
245                                        +"\nIf  you use JalView, please cite:  \"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",\r
246                                          "About Jalview",\r
247                                          JOptionPane.INFORMATION_MESSAGE);\r
248  }\r
249 \r
250  public void documentationMenuItem_actionPerformed(ActionEvent e)\r
251  {\r
252    try{\r
253      jalview.util.BrowserLauncher.openURL("http://www.jalview.org/documentation.html");\r
254    }catch(Exception ex){}\r
255  }\r
256 \r
257 \r
258 }\r