From: amwaterhouse Date: Thu, 19 May 2005 17:55:04 +0000 (+0000) Subject: Load and Save State added X-Git-Tag: Release_2_0~282 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=04ddbd9a05445eff7618dbc30f30ffbc66d3a947;p=jalview.git Load and Save State added --- diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 95c08a1..29eea5f 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -46,7 +46,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListene setTitle("Jalview 2005"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); desktop = new JDesktopPane(); - // desktop.setBackground(Color.white); + desktop.setBackground(Color.white); setContentPane(desktop); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); @@ -125,12 +125,13 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); frame.toFront(); final JMenuItem menuItem = new JMenuItem(title); frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() - { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) - { - openFrameCount--; - windowMenu.remove(menuItem); - }; - }); + { + public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) + { + openFrameCount--; + windowMenu.remove(menuItem); + }; + }); menuItem.addActionListener(new ActionListener() { @@ -163,8 +164,13 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); { String file = files.get(i).toString(); String protocol = "File"; - String format = jalview.io.IdentifyFile.Identify(file, protocol); - LoadFile(file, protocol, format); + if(file.endsWith(".jar")) + Jalview2XML.LoadJalviewAlign(file); + else + { + String format = jalview.io.IdentifyFile.Identify(file, protocol); + LoadFile(file, protocol, format); + } } }catch(Exception ex){ex.printStackTrace();} @@ -174,7 +180,10 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); public void inputLocalFileMenuItem_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[]{"fa", "fasta", "fastq", "blc", "msf", "pfam", "aln", "pir"}, "Alignment files"); + new String[]{"fa, fasta, fastq", "aln", "pfam", "msf", "pir","blc","jar"}, + new String[]{"Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview Archive"} + ,null); + chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Open local file"); chooser.setToolTipText("Open"); @@ -182,9 +191,16 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); if(value == JalviewFileChooser.APPROVE_OPTION) { String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - String format = IdentifyFile.Identify(choice, "File"); - LoadFile(choice, "File", format); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser.getSelectedFile().getParent()); + if(chooser.getSelectedFormat().equals("Jalview")) + { + Jalview2XML.LoadJalviewAlign(choice); + } + else + { + String format = IdentifyFile.Identify(choice, "File"); + LoadFile(choice, "File", format); + } } } @@ -215,6 +231,7 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); { AlignFrame af = new AlignFrame(new Alignment(sequences)); addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT); + af.currentFileFormat = format; af.statusBar.setText("Successfully loaded file " + file); try{ af.setMaximum(Preferences.showFullscreen); @@ -224,7 +241,7 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); else JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't open file.\n" + "Formats currently supported are\n" - + "Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM" // JBPNote - message should be generated through FormatAdapter! + + "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM" // JBPNote - message should be generated through FormatAdapter! ,"Error loading file", JOptionPane.WARNING_MESSAGE); @@ -234,8 +251,6 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); public void inputURLMenuItem_actionPerformed(ActionEvent e) { - JOptionPane op = new JOptionPane(); - String url = JOptionPane.showInternalInputDialog(Desktop.desktop,"Enter url of input file", "Input alignment from URL", JOptionPane.QUESTION_MESSAGE, @@ -279,6 +294,7 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); if(sequences!=null) { AlignFrame af = new AlignFrame(new Alignment(sequences)); + af.currentFileFormat = format; addInternalFrame(af, "Cut & Paste input - "+format, AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT); @@ -287,7 +303,7 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); else JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n" +"Formats currently supported are\n" - +"Fasta, MSF, Clustal, BLC, PIR, MSP or PFAM", + +"Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM", "Error parsing text", JOptionPane.WARNING_MESSAGE); } @@ -344,6 +360,40 @@ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); Preferences pref = new Preferences(); } + public void saveState_actionPerformed(ActionEvent e) + { + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty("LAST_DIRECTORY"), + new String[] + {"xml"}, new String[]{"Jalview Project"}, "Jalview Project"); + + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Save State"); + int value = chooser.showSaveDialog(this); + if (value == JalviewFileChooser.APPROVE_OPTION) + { + java.io.File choice = chooser.getSelectedFile(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); + Jalview2XML.SaveState(choice); + } + + } + + + public void loadState_actionPerformed(ActionEvent e) + { + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"), + new String[]{"xml"}, new String[]{"Jalview Project"}, "Jalview Project"); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Restore state"); + int value = chooser.showOpenDialog(this); + if(value == JalviewFileChooser.APPROVE_OPTION) + { + String choice = chooser.getSelectedFile().getAbsolutePath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser.getSelectedFile().getParent()); + Jalview2XML.LoadState(choice); + } + } }