X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationExporter.java;h=e50859d56d51341ec2905e58dcd152dd0729b8f5;hb=8a1017e676ae8a3ae7f0900a7023c4ad598a0ad5;hp=ab3f0d1006903cc74bc1024c64ff6e2bf55970cf;hpb=990fd5f012601024aaeeb09e2901791d242636c4;p=jalview.git diff --git a/src/jalview/gui/AnnotationExporter.java b/src/jalview/gui/AnnotationExporter.java index ab3f0d1..e50859d 100755 --- a/src/jalview/gui/AnnotationExporter.java +++ b/src/jalview/gui/AnnotationExporter.java @@ -1,22 +1,20 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ - package jalview.gui; import java.util.*; @@ -30,19 +28,24 @@ import jalview.io.*; /** * - * GUI dialog for exporting features or alignment annotations depending upon which method is called. + * GUI dialog for exporting features or alignment annotations depending upon + * which method is called. * * @author AMW - * + * */ -public class AnnotationExporter - extends JPanel +public class AnnotationExporter extends JPanel { JInternalFrame frame; + AlignmentPanel ap; + boolean features = true; + AlignmentAnnotation[] annotations; + Vector sequenceGroups; + Hashtable alignmentProperties; public AnnotationExporter() @@ -50,8 +53,7 @@ public class AnnotationExporter try { jbInit(); - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); } @@ -59,9 +61,7 @@ public class AnnotationExporter frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); - Desktop.addInternalFrame(frame, - "", - 260, 125); + Desktop.addInternalFrame(frame, "", 260, 125); } public void exportFeatures(AlignmentPanel ap) @@ -73,9 +73,8 @@ public class AnnotationExporter } public void exportAnnotations(AlignmentPanel ap, - AlignmentAnnotation[] annotations, - Vector sequenceGroups, - Hashtable alProperties) + AlignmentAnnotation[] annotations, Vector sequenceGroups, + Hashtable alProperties) { this.ap = ap; features = false; @@ -90,11 +89,11 @@ public class AnnotationExporter public void toFile_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY")); + jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle( - features ? "Save Features to File" : "Save Annotation to File"); + chooser.setDialogTitle(features ? "Save Features to File" + : "Save Annotation to File"); chooser.setToolTipText("Save"); int value = chooser.showSaveDialog(this); @@ -106,15 +105,15 @@ public class AnnotationExporter { if (GFFFormat.isSelected()) { - text = new FeaturesFile().printGFFFormat( - ap.av.alignment.getDataset().getSequencesArray(), - ap.av.featuresDisplayed); + text = new FeaturesFile().printGFFFormat(ap.av.alignment + .getDataset().getSequencesArray(), + getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());// ap.av.featuresDisplayed//); } else { - text = new FeaturesFile().printJalviewFormat( - ap.av.alignment.getDataset().getSequencesArray(), - ap.av.featuresDisplayed); + text = new FeaturesFile().printJalviewFormat(ap.av.alignment + .getDataset().getSequencesArray(), + getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); // ap.av.featuresDisplayed); } } else @@ -122,23 +121,22 @@ public class AnnotationExporter if (CSVFormat.isSelected()) { text = new AnnotationFile().printCSVAnnotations(annotations); - } else { - text = new AnnotationFile().printAnnotations( - annotations, - sequenceGroups, - alignmentProperties); + } + else + { + text = new AnnotationFile().printAnnotations(annotations, + sequenceGroups, alignmentProperties); } } try { java.io.PrintWriter out = new java.io.PrintWriter( - new java.io.FileWriter(chooser.getSelectedFile())); + new java.io.FileWriter(chooser.getSelectedFile())); out.print(text); out.close(); - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); } @@ -154,15 +152,15 @@ public class AnnotationExporter { if (GFFFormat.isSelected()) { - text = new FeaturesFile().printGFFFormat( - ap.av.alignment.getDataset().getSequencesArray(), - ap.av.featuresDisplayed); + text = new FeaturesFile().printGFFFormat(ap.av.alignment + .getDataset().getSequencesArray(), + getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); } else { - text = new FeaturesFile().printJalviewFormat( - ap.av.alignment.getDataset().getSequencesArray(), - ap.av.featuresDisplayed); + text = new FeaturesFile().printJalviewFormat(ap.av.alignment + .getDataset().getSequencesArray(), + getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); } } else if (!features) @@ -170,38 +168,62 @@ public class AnnotationExporter if (CSVFormat.isSelected()) { text = new AnnotationFile().printCSVAnnotations(annotations); - } else { - text = new AnnotationFile().printAnnotations( - annotations, - sequenceGroups, - alignmentProperties); + } + else + { + text = new AnnotationFile().printAnnotations(annotations, + sequenceGroups, alignmentProperties); } } CutAndPasteTransfer cap = new CutAndPasteTransfer(); - cap.setText(text); - Desktop.addInternalFrame(cap, - (features ? "Features for - " : - "Annotations for - ") - + ap.alignFrame.getTitle(), - 600, - 500); + try + { + cap.setText(text); + Desktop.addInternalFrame(cap, (features ? "Features for - " + : "Annotations for - ") + ap.alignFrame.getTitle(), 600, 500); + } catch (OutOfMemoryError oom) + { + new OOMWarning("generating " + + (features ? "Features for - " : "Annotations for - ") + + ap.alignFrame.getTitle(), oom); + cap.dispose(); + } close_actionPerformed(null); } + private Hashtable getDisplayedFeatureCols() + { + Hashtable fcols = new Hashtable(); + if (ap.av.featuresDisplayed == null) + { + return fcols; + } + Enumeration en = ap.av.featuresDisplayed.keys(); + FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider + // higher + // level + // method ? + while (en.hasMoreElements()) + { + Object col = en.nextElement(); + fcols.put(col, fr.featureColours.get(col)); + } + return fcols; + } + public void close_actionPerformed(ActionEvent e) { try { frame.setClosed(true); + } catch (java.beans.PropertyVetoException ex) + { } - catch (java.beans.PropertyVetoException ex) - {} } - private void jbInit() - throws Exception + private void jbInit() throws Exception { this.setLayout(flowLayout1); toFile.setText("to File"); @@ -256,15 +278,25 @@ public class AnnotationExporter } JPanel jPanel1 = new JPanel(); + JButton toFile = new JButton(); + JButton toTextbox = new JButton(); + JButton close = new JButton(); + ButtonGroup buttonGroup = new ButtonGroup(); + JRadioButton jalviewFormat = new JRadioButton(); + JRadioButton GFFFormat = new JRadioButton(); + JRadioButton CSVFormat = new JRadioButton(); + JLabel jLabel1 = new JLabel(); + JPanel jPanel3 = new JPanel(); + FlowLayout flowLayout1 = new FlowLayout(); }