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