import javax.swing.*;\r
import java.awt.*;\r
import java.awt.event.*;\r
+import java.awt.dnd.*;\r
+import javax.swing.*;\r
+import java.awt.datatransfer.*;\r
+import jalview.bin.Cache;\r
\r
\r
-public class Desktop extends jalview.jbgui.GDesktop\r
+public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener\r
{\r
public static JDesktopPane desktop;\r
static int openFrameCount = 0;\r
{\r
Image image =null;\r
try{\r
- java.net.URL url = getClass().getResource("/BartonGroupBanner.gif");\r
+ java.net.URL url = getClass().getResource("/images/logo.gif");\r
if(url!=null)\r
{\r
image = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
\r
setTitle("Jalview 2005");\r
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
- setVisible(true);\r
desktop = new JDesktopPane();\r
+ desktop.setBackground(Color.white);\r
setContentPane(desktop);\r
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);\r
\r
+\r
+ // This line prevents Windows Look&Feel resizing all new windows to maximum\r
+ // if previous window was maximised\r
+ desktop.setDesktopManager( new DefaultDesktopManager() );\r
+\r
+\r
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();\r
- int width = 1200, height = 800;\r
- if(screenSize.getWidth()<width)\r
- width = screenSize.width;\r
- if(screenSize.getHeight()<height)\r
- height = screenSize.height;\r
+ String x = jalview.bin.Cache.getProperty("SCREEN_X");\r
+ String y = jalview.bin.Cache.getProperty("SCREEN_Y");\r
+ String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");\r
+ String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");\r
+\r
+ if(x!=null && y!=null && width!=null && height!=null)\r
+ {\r
+ setBounds( Integer.parseInt(x), Integer.parseInt(y),\r
+ Integer.parseInt(width), Integer.parseInt(height));\r
+ }\r
+ else\r
+ setBounds( (int)(screenSize.width-900)/2,\r
+ (int)(screenSize.height-650)/2,\r
+ 900 ,\r
+ 650);\r
\r
- setBounds( (int)(screenSize.width-width)/2,\r
- (int)(screenSize.height-height)/2,\r
- width ,\r
- height);\r
+this.addWindowListener(new WindowAdapter()\r
+{\r
+public void windowClosing(WindowEvent evt)\r
+{\r
+ jalview.bin.Cache.setProperty("SCREEN_X",\r
+ getBounds().x + "");\r
+ jalview.bin.Cache.setProperty("SCREEN_Y",\r
+ getBounds().y + "");\r
+ jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");\r
+ jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");\r
+}\r
+});\r
+setVisible(true);\r
\r
+this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));\r
\r
+/////////Add a splashscreen on startup\r
/////////Add a splashscreen on startup\r
JInternalFrame frame = new JInternalFrame();\r
\r
SplashScreen splash = new SplashScreen(frame, image);\r
frame.setContentPane(splash);\r
- desktop.add(frame);\r
- frame.setVisible(true);\r
- openFrameCount++;\r
- try\r
- {\r
- frame.setSelected(true);\r
- }\r
- catch (java.beans.PropertyVetoException e)\r
- {}\r
- frame.setResizable(true);\r
- frame.setSize(845, 200);\r
- frame.setLocation( (int)((getWidth()-845) /2), (int)((getHeight()-240) /2));\r
- frame.setClosable(false);\r
- frame.setIconifiable(false);\r
- frame.setMaximizable(false);\r
- frame.setFrameIcon(null);\r
-\r
+ frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
+ addInternalFrame(frame, "", 750,160, false);\r
+ frame.setLocation( (int)((getWidth()-750) /2), (int)((getHeight()-160) /2));\r
}\r
-\r
public static void addInternalFrame(final JInternalFrame frame, String title, int w, int h)\r
{\r
+ addInternalFrame(frame, title, w, h, true);\r
+ }\r
+\r
+ public static void addInternalFrame(final JInternalFrame frame, String title,\r
+ int w,\r
+ int h,\r
+ boolean resizable )\r
+ {\r
desktop.add(frame);\r
- frame.setVisible(true);\r
openFrameCount++;\r
try {\r
frame.setSelected(true);\r
} catch (java.beans.PropertyVetoException e) {}\r
frame.setTitle(title);\r
- frame.setResizable(true);\r
frame.setSize(w,h);\r
frame.setClosable(true);\r
- frame.setMaximizable(true);\r
- frame.setIconifiable(true);\r
+ frame.setResizable(resizable);\r
+ frame.setMaximizable(resizable);\r
+ frame.setIconifiable(resizable);\r
+ frame.setFrameIcon(null);\r
frame.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);\r
frame.toFront();\r
final JMenuItem menuItem = new JMenuItem(title);\r
frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
- { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)\r
- {\r
- openFrameCount--;\r
- windowMenu.remove(menuItem);\r
- };\r
- });\r
+ {\r
+ public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)\r
+ {\r
+ openFrameCount--;\r
+ windowMenu.remove(menuItem);\r
+ };\r
+ });\r
\r
menuItem.addActionListener(new ActionListener()\r
{\r
}\r
});\r
\r
+ frame.setVisible(true);\r
windowMenu.add(menuItem);\r
}\r
\r
+ public void dragEnter(DropTargetDragEvent evt){}\r
+ public void dragExit(DropTargetEvent evt){}\r
+ public void dragOver(DropTargetDragEvent evt){}\r
+ public void dropActionChanged(DropTargetDragEvent evt){}\r
+ public void drop(DropTargetDropEvent evt)\r
+{\r
+ Transferable t = evt.getTransferable();\r
+ if(!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))\r
+ return;\r
+\r
+ evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);\r
+ try{\r
+ java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);\r
+\r
+ for (int i = 0; i < files.size(); i++)\r
+ {\r
+ String file = files.get(i).toString();\r
+ String protocol = "File";\r
+ if(file.endsWith(".jar"))\r
+ Jalview2XML.LoadJalviewAlign(file);\r
+ else\r
+ {\r
+ String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
+ LoadFile(file, protocol, format);\r
+ }\r
+ }\r
+\r
+ }catch(Exception ex){ex.printStackTrace();}\r
+ }\r
\r
\r
public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)\r
{\r
- JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY);\r
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),\r
+ new String[]{"fa, fasta, fastq", "aln", "pfam", "msf", "pir","blc","jar"},\r
+ new String[]{"Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"}\r
+ ,null);\r
+\r
+ chooser.setFileView(new JalviewFileView());\r
chooser.setDialogTitle("Open local file");\r
chooser.setToolTipText("Open");\r
int value = chooser.showOpenDialog(this);\r
- if(value == JFileChooser.APPROVE_OPTION)\r
+ if(value == JalviewFileChooser.APPROVE_OPTION)\r
{\r
String choice = chooser.getSelectedFile().getPath();\r
- jalview.bin.Cache.LAST_DIRECTORY = choice;\r
- String format = IdentifyFile.Identify(choice, "File");\r
- LoadFile(choice, "File", format);\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser.getSelectedFile().getParent());\r
+ if(chooser.getSelectedFormat().equals("Jalview"))\r
+ {\r
+ Jalview2XML.LoadJalviewAlign(choice);\r
+ }\r
+ else\r
+ {\r
+ String format = IdentifyFile.Identify(choice, "File");\r
+ LoadFile(choice, "File", format);\r
+ }\r
}\r
}\r
\r
public void LoadFile(String file, String protocol, String format)\r
{\r
- SequenceI [] sequences = null;\r
+ LoadingThread loader = new LoadingThread(file, protocol, format);\r
+ loader.start();\r
+ }\r
\r
- if (FormatProperties.contains(format))\r
- sequences = FormatAdapter.read(file, protocol, format);\r
+ class LoadingThread extends Thread\r
+ {\r
+ String file, protocol, format;\r
\r
- if (sequences != null)\r
+ public LoadingThread(String file, String protocol, String format)\r
{\r
- AlignFrame af = new AlignFrame(new Alignment(sequences));\r
- addInternalFrame(af, file, 700, 500);\r
- af.statusBar.setText("Successfully loaded file " + file);\r
-\r
-\r
+ this.file = file;\r
+ this.protocol = protocol;\r
+ this.format = format;\r
}\r
- else\r
- JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't open file.\n"\r
- + "Formats currently supported are\n"\r
- + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM"\r
- ,"Error loading file",\r
- JOptionPane.WARNING_MESSAGE);\r
+ public void run()\r
+ {\r
+ SequenceI [] sequences = null;\r
+\r
+ if (FormatAdapter.formats.contains(format))\r
+ sequences = FormatAdapter.readFile(file, protocol, format);\r
+\r
+ if (sequences != null && sequences.length>0)\r
+ {\r
+ AlignFrame af = new AlignFrame(new Alignment(sequences));\r
+ addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);\r
+ af.currentFileFormat = format;\r
+ af.statusBar.setText("Successfully loaded file " + file);\r
+ try{\r
+ af.setMaximum(Preferences.showFullscreen);\r
+ }catch(Exception ex){}\r
+\r
+ }\r
+ else\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't open file.\n"\r
+ + "Formats currently supported are\n"\r
+ + "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter!\r
+ ,"Error loading file",\r
+ JOptionPane.WARNING_MESSAGE);\r
\r
+ }\r
}\r
\r
+\r
public void inputURLMenuItem_actionPerformed(ActionEvent e)\r
{\r
String url = JOptionPane.showInternalInputDialog(Desktop.desktop,"Enter url of input file",\r
"Input alignment from URL",\r
- JOptionPane.QUESTION_MESSAGE);\r
+ JOptionPane.QUESTION_MESSAGE,\r
+ null, null,\r
+ "http://www.").toString();\r
if (url == null)\r
return;\r
\r
String format = IdentifyFile.Identify(url, "URL");\r
\r
- System.out.println(format +" format");\r
if (format.equals("URL NOT FOUND"))\r
{\r
JOptionPane.showInternalMessageDialog(Desktop.desktop,"Couldn't locate " + url,\r
String format = IdentifyFile.Identify(cap.getText(), "Paste");\r
SequenceI [] sequences = null;\r
\r
- if (FormatProperties.contains( format ))\r
- sequences = FormatAdapter.read(cap.getText(), "Paste", format);\r
+ if (FormatAdapter.formats.contains( format ))\r
+ sequences = FormatAdapter.readFile(cap.getText(), "Paste", format);\r
\r
\r
if(sequences!=null)\r
{\r
AlignFrame af = new AlignFrame(new Alignment(sequences));\r
- addInternalFrame(af, "Cut & Paste input - "+format, 700, 500);\r
+ af.currentFileFormat = format;\r
+ addInternalFrame(af, "Cut & Paste input - "+format,\r
+ AlignFrame.NEW_WINDOW_WIDTH,\r
+ AlignFrame.NEW_WINDOW_HEIGHT);\r
af.statusBar.setText("Successfully pasted alignment file");\r
}\r
else\r
JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n"\r
+"Formats currently supported are\n"\r
- +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM",\r
+ +"Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM",\r
"Error parsing text", JOptionPane.WARNING_MESSAGE);\r
\r
-\r
}\r
}\r
\r
}\r
\r
\r
- protected void colourIndexMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- ColourKey colourKey = new ColourKey(null);\r
- addInternalFrame(colourKey, "Colour scheme key", 400, 320);\r
- }\r
-\r
\r
public void aboutMenuItem_actionPerformed(ActionEvent e)\r
{\r
JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "JalView 2005"\r
+ "JalView 2005 version " + jalview.bin.Cache.VERSION+"; last updated: "+jalview.bin.Cache.BUILD_DATE\r
+"\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton."\r
+"\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee."\r
- +"\nIf you use JalView, please cite: \"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",\r
+ +"\nIf you use JalView, please cite:"\r
+ +"\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\""\r
+ +"\nBioinformatics, 2004 12;426-7.",\r
"About Jalview",\r
JOptionPane.INFORMATION_MESSAGE);\r
}\r
\r
public void documentationMenuItem_actionPerformed(ActionEvent e)\r
{\r
- try{\r
- jalview.util.BrowserLauncher.openURL("http://www.jalview.org/documentation.html");\r
- }catch(Exception ex){}\r
+ try\r
+ {\r
+ ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();\r
+ java.net.URL url = javax.help.HelpSet.findHelpSet(cl,"help/help");\r
+ javax.help.HelpSet hs = new javax.help.HelpSet(cl,url);\r
+\r
+ javax.help.HelpBroker hb = hs.createHelpBroker();\r
+ hb.setLocation(new Point(200, 50));\r
+ hb.setSize(new Dimension(800,700));\r
+ hb.setCurrentID("home");\r
+ hb.setDisplayed(true);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
}\r
\r
+ protected void preferences_actionPerformed(ActionEvent e)\r
+ {\r
+ Preferences pref = new Preferences();\r
+ }\r
+\r
+ public void saveState_actionPerformed(ActionEvent e)\r
+ {\r
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
+ getProperty("LAST_DIRECTORY"),\r
+ new String[]\r
+ {"xml"}, new String[]{"Jalview Project"}, "Jalview Project");\r
+\r
+ chooser.setFileView(new JalviewFileView());\r
+ chooser.setDialogTitle("Save State");\r
+ int value = chooser.showSaveDialog(this);\r
+ if (value == JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ java.io.File choice = chooser.getSelectedFile();\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());\r
+ Jalview2XML.SaveState(choice);\r
+ }\r
+\r
+ }\r
\r
+\r
+ public void loadState_actionPerformed(ActionEvent e)\r
+ {\r
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),\r
+ new String[]{"xml"}, new String[]{"Jalview Project"}, "Jalview Project");\r
+ chooser.setFileView(new JalviewFileView());\r
+ chooser.setDialogTitle("Restore state");\r
+ int value = chooser.showOpenDialog(this);\r
+ if(value == JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ String choice = chooser.getSelectedFile().getAbsolutePath();\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser.getSelectedFile().getParent());\r
+ Jalview2XML.LoadState(choice);\r
+ }\r
+ }\r
}\r
+\r
+\r