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 int width = 1200, height = 800;
\r
52 if(screenSize.getWidth()<width)
\r
53 width = screenSize.width;
\r
54 if(screenSize.getHeight()<height)
\r
55 height = screenSize.height;
\r
57 setBounds( (int)(screenSize.width-width)/2,
\r
58 (int)(screenSize.height-height)/2,
\r
63 /////////Add a splashscreen on startup
\r
64 JInternalFrame frame = new JInternalFrame();
\r
66 SplashScreen splash = new SplashScreen(frame, image);
\r
67 frame.setContentPane(splash);
\r
68 addInternalFrame(frame, "",845,200);
\r
69 splashScreenVisible = true;
\r
71 frame.setLocation( (int)((getWidth()-845) /2), (int)((getHeight()-240) /2));
\r
72 frame.setClosable(false);
\r
73 frame.setIconifiable(false);
\r
74 frame.setMaximizable(false);
\r
75 frame.setFrameIcon(null);
\r
76 splashScreenVisible = false;
\r
80 public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)
\r
82 if(!splashScreenVisible)
\r
83 frame.setVisible(true); //necessary as of 1.3
\r
87 frame.setSelected(true);
\r
88 } catch (java.beans.PropertyVetoException e) {}
\r
89 frame.setTitle(title);
\r
90 frame.setResizable(true);
\r
92 frame.setClosable(true);
\r
93 frame.setMaximizable(true);
\r
94 frame.setIconifiable(true);
\r
95 frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
\r
97 final JMenuItem menuItem = new JMenuItem(title);
\r
98 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
99 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
\r
102 windowMenu.remove(menuItem);
\r
106 menuItem.addActionListener(new ActionListener()
\r
108 public void actionPerformed(ActionEvent e)
\r
110 try{ frame.setSelected(true); frame.setIcon(false); }
\r
111 catch(java.beans.PropertyVetoException ex){};
\r
115 windowMenu.add(menuItem);
\r
120 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
\r
122 JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY);
\r
123 chooser.setDialogTitle("Open local file");
\r
124 chooser.setToolTipText("Open");
\r
125 int value = chooser.showOpenDialog(this);
\r
126 if(value == JFileChooser.APPROVE_OPTION)
\r
128 String choice = chooser.getSelectedFile().getPath();
\r
129 jalview.bin.Cache.LAST_DIRECTORY = choice;
\r
130 String format = IdentifyFile.Identify(choice, "File");
\r
131 LoadFile(choice, "File", format);
\r
135 public void LoadFile(String file, String protocol, String format)
\r
137 SequenceI [] sequences = null;
\r
139 if (FormatProperties.contains(format))
\r
140 sequences = FormatAdapter.read(file, protocol, format);
\r
142 if (sequences != null)
\r
144 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
145 addInternalFrame(af, file, 700, 500);
\r
146 af.statusBar.setText("Successfully loaded file " + file);
\r
151 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't open file.\n"
\r
152 + "Formats currently supported are\n"
\r
153 + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM"
\r
154 ,"Error loading file",
\r
155 JOptionPane.WARNING_MESSAGE);
\r
159 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
161 String url = JOptionPane.showInternalInputDialog(Desktop.desktop,"Enter url of input file",
\r
162 "Input alignment from URL",
\r
163 JOptionPane.QUESTION_MESSAGE);
\r
167 String format = IdentifyFile.Identify(url, "URL");
\r
169 System.out.println(format +" format");
\r
170 if (format.equals("URL NOT FOUND"))
\r
172 JOptionPane.showInternalMessageDialog(Desktop.desktop,"Couldn't locate " + url,
\r
174 JOptionPane.WARNING_MESSAGE);
\r
178 LoadFile(url, "URL", format);
\r
181 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\r
183 CutAndPasteTransfer cap = new CutAndPasteTransfer(true);
\r
184 int accept = JOptionPane.showInternalOptionDialog(Desktop.desktop, cap, "Cut & paste Alignment File",
\r
185 JOptionPane.YES_NO_CANCEL_OPTION,
\r
186 JOptionPane.PLAIN_MESSAGE,
\r
188 new Object[]{"Accept", "Cancel", }, null);
\r
191 if(accept == JOptionPane.YES_OPTION)
\r
193 String format = IdentifyFile.Identify(cap.getText(), "Paste");
\r
194 SequenceI [] sequences = null;
\r
196 if (FormatProperties.contains( format ))
\r
197 sequences = FormatAdapter.read(cap.getText(), "Paste", format);
\r
200 if(sequences!=null)
\r
202 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
203 addInternalFrame(af, "Cut & Paste input - "+format, 700, 500);
\r
204 af.statusBar.setText("Successfully pasted alignment file");
\r
207 JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n"
\r
208 +"Formats currently supported are\n"
\r
209 +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",
\r
210 "Error parsing text", JOptionPane.WARNING_MESSAGE);
\r
219 public void quit_actionPerformed(ActionEvent e)
\r
221 this.setVisible(false);
\r
226 protected void colourIndexMenuItem_actionPerformed(ActionEvent e)
\r
228 ColourKey colourKey = new ColourKey(null);
\r
229 addInternalFrame(colourKey, "Colour scheme key", 400, 320);
\r
233 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
235 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
237 +"\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton."
\r
238 +"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."
\r
239 +"\nIf you use JalView, please cite: \"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",
\r
241 JOptionPane.INFORMATION_MESSAGE);
\r
244 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
247 jalview.util.BrowserLauncher.openURL("http://www.jalview.org/documentation.html");
\r
248 }catch(Exception ex){}
\r