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
123 JOptionPane.showMessageDialog(this, "Couldn't open file.\n"
\r
124 + "Formats currently supported are\n"
\r
125 + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM"
\r
126 ,"Error loading file",
\r
127 JOptionPane.WARNING_MESSAGE);
\r
131 public void inputURLMenuItem_actionPerformed(ActionEvent e)
\r
133 String url = JOptionPane.showInputDialog(this,"Enter url of input file",
\r
134 "Input alignment from URL",
\r
135 JOptionPane.QUESTION_MESSAGE);
\r
139 String format = IdentifyFile.Identify(url, "URL");
\r
141 System.out.println(format +" format");
\r
142 if (format.equals("URL NOT FOUND"))
\r
144 JOptionPane.showMessageDialog(this,"Couldn't locate " + url,
\r
146 JOptionPane.WARNING_MESSAGE);
\r
150 LoadFile(url, "URL", format);
\r
153 public void inputTextboxMenuItem_actionPerformed(ActionEvent e)
\r
155 CutAndPasteTransfer cap = new CutAndPasteTransfer(true);
\r
156 int accept = JOptionPane.showInternalOptionDialog(desktop, cap, "Cut & paste Alignment File",
\r
157 JOptionPane.YES_NO_CANCEL_OPTION,
\r
158 JOptionPane.PLAIN_MESSAGE,
\r
160 new Object[]{"Accept", "Cancel", }, null);
\r
163 if(accept == JOptionPane.YES_OPTION)
\r
165 String format = IdentifyFile.Identify(cap.getText(), "Paste");
\r
166 SequenceI [] sequences = null;
\r
168 if (FormatProperties.contains( format ))
\r
169 sequences = FormatAdapter.read(cap.getText(), "Paste", format);
\r
172 if(sequences!=null)
\r
174 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
175 addInternalFrame(af, "Cut & Paste input - "+format, 700, 500);
\r
176 af.statusBar.setText("Successfully pasted alignment file");
\r
179 JOptionPane.showMessageDialog(this, "Couldn't read the pasted text.\n"
\r
180 +"Formats currently supported are\n"
\r
181 +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",
\r
182 "Error parsing text", JOptionPane.WARNING_MESSAGE);
\r
191 public void quit_actionPerformed(ActionEvent e)
\r
193 this.setVisible(false);
\r
198 protected void colourIndexMenuItem_actionPerformed(ActionEvent e)
\r
200 ColourKey colourKey = new ColourKey(null);
\r
201 addInternalFrame(colourKey, "Colour scheme key", 400, 320);
\r
205 public void aboutMenuItem_actionPerformed(ActionEvent e)
\r
207 JOptionPane.showInternalMessageDialog(desktop,
\r
208 "Jalview 1998-2005\n"
\r
209 +"Sequence Alignment viewer & editor",
\r
211 JOptionPane.INFORMATION_MESSAGE);
\r
214 public void documentationMenuItem_actionPerformed(ActionEvent e)
\r
217 jalview.util.BrowserLauncher.openURL("http://jalview.org/documentation.html");
\r
218 }catch(Exception ex){}
\r