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
29 java.net.URL url = getClass().getResource("/BartonGroupBanner.gif");
\r
32 Image image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
33 MediaTracker mt = new MediaTracker(this);
\r
34 mt.addImage(image, 0);
\r
36 setIconImage(image);
\r
39 }catch(Exception ex){}
\r
41 setTitle("Jalview 2005");
\r
42 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
44 desktop = new JDesktopPane();
\r
45 setContentPane(desktop);
\r
46 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
\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
54 public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)
\r
56 frame.setVisible(true); //necessary as of 1.3
\r
60 frame.setSelected(true);
\r
61 } catch (java.beans.PropertyVetoException e) {}
\r
62 frame.setTitle(title);
\r
63 frame.setResizable(true);
\r
65 frame.setClosable(true);
\r
66 frame.setMaximizable(true);
\r
67 frame.setIconifiable(true);
\r
68 frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
\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
75 windowMenu.remove(menuItem);
\r
79 menuItem.addActionListener(new ActionListener()
\r
81 public void actionPerformed(ActionEvent e)
\r
83 try{ frame.setSelected(true); frame.setIcon(false); }
\r
84 catch(java.beans.PropertyVetoException ex){};
\r
88 windowMenu.add(menuItem);
\r
93 public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)
\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
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
108 public void LoadFile(String file, String protocol, String format)
\r
110 SequenceI [] sequences = null;
\r
113 if (FormatProperties.contains(format))
\r
114 sequences = FormatAdapter.read(file, protocol, format);
\r
116 if (sequences != null)
\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
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
133 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
135 String url = JOptionPane.showInputDialog(this,"Enter url of input file",
\r
136 "Input alignment from URL",
\r
137 JOptionPane.QUESTION_MESSAGE);
\r
141 String format = IdentifyFile.Identify(url, "URL");
\r
143 System.out.println(format +" format");
\r
144 if (format.equals("URL NOT FOUND"))
\r
146 JOptionPane.showMessageDialog(this,"Couldn't locate " + url,
\r
148 JOptionPane.WARNING_MESSAGE);
\r
152 LoadFile(url, "URL", format);
\r
155 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\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
162 new Object[]{"Accept", "Cancel", }, null);
\r
165 if(accept == JOptionPane.YES_OPTION)
\r
167 String format = IdentifyFile.Identify(cap.getText(), "Paste");
\r
168 SequenceI [] sequences = null;
\r
170 if (FormatProperties.contains( format ))
\r
171 sequences = FormatAdapter.read(cap.getText(), "Paste", format);
\r
174 if(sequences!=null)
\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
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
193 public void quit_actionPerformed(ActionEvent e)
\r
195 this.setVisible(false);
\r
200 protected void colourIndexMenuItem_actionPerformed(ActionEvent e)
\r
202 ColourKey colourKey = new ColourKey(null);
\r
203 addInternalFrame(colourKey, "Colour scheme key", 400, 320);
\r
207 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
209 JOptionPane.showInternalMessageDialog(desktop,
\r
210 "Jalview 1998-2005\n"
\r
211 +"Sequence Alignment viewer & editor",
\r
213 JOptionPane.INFORMATION_MESSAGE);
\r
216 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
219 jalview.util.BrowserLauncher.openURL("http://jalview.org/documentation.html");
\r
220 }catch(Exception ex){}
\r