X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FCutAndPasteTransfer.java;h=1e806a5cb5afaf535b76206ef2acee4719f1f46f;hb=136c0793b90b72b928c4d77dc109dd5c644e00d3;hp=5b699a6df60f98cfcdf350c6423de3cb4c3fcabb;hpb=ecdc53f0d45b7533878cef236fff851ea64ef9a9;p=jalview.git diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index 5b699a6..1e806a5 100644 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -20,36 +20,41 @@ */ package jalview.appletgui; -import java.awt.BorderLayout; -import java.awt.Button; -import java.awt.Dialog; -import java.awt.Font; -import java.awt.Frame; -import java.awt.Label; -import java.awt.Panel; -import java.awt.TextArea; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - import jalview.analysis.AlignmentUtils; +import jalview.api.ComplexAlignFile; +import jalview.api.FeaturesSourceI; import jalview.bin.JalviewLite; -import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.io.AlignmentFileReaderI; import jalview.io.AnnotationFile; import jalview.io.AppletFormatAdapter; -import jalview.io.FileParse; -import jalview.io.HtmlFile; +import jalview.io.DataSourceType; +import jalview.io.FileFormatI; import jalview.io.IdentifyFile; -import jalview.io.JSONFile; import jalview.io.NewickFile; import jalview.io.TCoffeeScoreFile; +import jalview.json.binding.biojson.v1.ColourSchemeMapper; +import jalview.schemes.ColourSchemeI; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Dialog; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Label; +import java.awt.Panel; +import java.awt.TextArea; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.IOException; + public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener { @@ -63,7 +68,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, AlignFrame alignFrame; - FileParse source = null; + AlignmentFileReaderI source = null; public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame) { @@ -115,6 +120,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, addSequences.setVisible(false); } + @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == accept) @@ -191,7 +197,8 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, { try { - NewickFile fin = new NewickFile(textarea.getText(), "Paste"); + NewickFile fin = new NewickFile(textarea.getText(), + DataSourceType.PASTE); fin.parse(); if (fin.getTree() != null) @@ -204,8 +211,8 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, // TODO: JAL-1102 - should have a warning message in dialog, not simply // overwrite the broken input data with the exception textarea.setText(MessageManager.formatMessage( - "label.could_not_parse_newick_file", new Object[] - { ex.getMessage() })); + "label.could_not_parse_newick_file", + new Object[] { ex.getMessage() })); return false; } return false; @@ -220,19 +227,16 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, protected void loadAlignment(String text, boolean newWindow, AlignViewport viewport) { - Alignment al = null; + AlignmentI al = null; - String format = new IdentifyFile().Identify(text, - AppletFormatAdapter.PASTE); - AppletFormatAdapter afa = new AppletFormatAdapter(viewport); try { - al = afa.readFile(text, AppletFormatAdapter.PASTE, format); + FileFormatI format = new IdentifyFile().identify(text, + DataSourceType.PASTE); + AppletFormatAdapter afa = new AppletFormatAdapter( + alignFrame.alignPanel); + al = afa.readFile(text, DataSourceType.PASTE, format); source = afa.getAlignFile(); - } catch (java.io.IOException ex) - { - ex.printStackTrace(); - } if (al != null) { @@ -249,20 +253,42 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, } if (newWindow) { - AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet, - "Cut & Paste input - " + format, false); - af.statusBar - .setText(MessageManager - .getString("label.successfully_pasted_annotation_to_alignment")); + AlignFrame af; - if (source instanceof HtmlFile) + if (source instanceof ComplexAlignFile) { - ((HtmlFile) source).applySettingsToAlignmentView(af); + HiddenColumns colSel = ((ComplexAlignFile) source) + .getHiddenColumns(); + SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) + .getHiddenSequences(); + boolean showSeqFeatures = ((ComplexAlignFile) source) + .isShowSeqFeatures(); + String colourSchemeName = ((ComplexAlignFile) source) + .getGlobalColourScheme(); + af = new AlignFrame(al, hiddenSeqs, colSel, + alignFrame.viewport.applet, "Cut & Paste input - " + + format, false); + af.getAlignViewport().setShowSequenceFeatures(showSeqFeatures); + ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( + colourSchemeName, al); + if (cs != null) + { + af.changeColour(cs); + } } - else if (source instanceof JSONFile) + else { - ((JSONFile) source).applySettingsToAlignmentView(af); + af = new AlignFrame(al, alignFrame.viewport.applet, + "Cut & Paste input - " + format, false); + if (source instanceof FeaturesSourceI) + { + af.getAlignViewport().setShowSequenceFeatures(true); + } } + + af.statusBar + .setText(MessageManager + .getString("label.successfully_pasted_annotation_to_alignment")); } else { @@ -271,6 +297,10 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, .getString("label.successfully_pasted_alignment_file")); } } + } catch (IOException ex) + { + ex.printStackTrace(); + } } /** @@ -281,9 +311,10 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, * @param al * @return */ - protected boolean openSplitFrame(Alignment al, String format) + protected boolean openSplitFrame(AlignmentI al, FileFormatI format) { - final AlignmentI thisAlignment = this.alignFrame.getAlignViewport().getAlignment(); + final AlignmentI thisAlignment = this.alignFrame.getAlignViewport() + .getAlignment(); if (thisAlignment.isNucleotide() == al.isNucleotide()) { // both nucleotide or both protein @@ -291,7 +322,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, } AlignmentI protein = thisAlignment.isNucleotide() ? al : thisAlignment; AlignmentI dna = thisAlignment.isNucleotide() ? thisAlignment : al; - boolean mapped = AlignmentUtils.mapProteinToCdna(protein, dna); + boolean mapped = AlignmentUtils.mapProteinAlignmentToCdna(protein, dna); if (!mapped) { return false; @@ -312,13 +343,18 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, dialog.setMainPanel(question); dialog.setVisible(true); dialog.toFront(); - + if (!dialog.accept) { return false; } /* + * 'align' the added alignment to match the current one + */ + al.alignAs(thisAlignment); + + /* * Open SplitFrame with DNA above and protein below, including the alignment * from textbox and a copy of the original. */ @@ -329,8 +365,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, AlignFrame newFrame = new AlignFrame(al, alignFrame.viewport.applet, "Cut & Paste input - " + format, false, false); AlignFrame dnaFrame = al.isNucleotide() ? newFrame : copyFrame; - AlignFrame proteinFrame = al.isNucleotide() ? copyFrame - : newFrame; + AlignFrame proteinFrame = al.isNucleotide() ? copyFrame : newFrame; SplitFrame sf = new SplitFrame(dnaFrame, proteinFrame); sf.addToDisplay(false, applet); return true; @@ -346,11 +381,10 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, try { tcf = new TCoffeeScoreFile(textarea.getText(), - jalview.io.AppletFormatAdapter.PASTE); + jalview.io.DataSourceType.PASTE); if (tcf.isValid()) { - if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(), - true)) + if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(), true)) { alignFrame.tcoffeeColour.setEnabled(true); alignFrame.alignPanel.fontChanged(); @@ -365,8 +399,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, // file valid but didn't get added to alignment for some reason alignFrame.statusBar.setText(MessageManager.formatMessage( "label.failed_add_tcoffee_scores", - new Object[] - { (tcf.getWarningMessage() != null ? tcf + new Object[] { (tcf.getWarningMessage() != null ? tcf .getWarningMessage() : "") })); } } @@ -381,8 +414,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, if (tcf == null) { if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport, - textarea.getText(), - jalview.io.AppletFormatAdapter.PASTE)) + textarea.getText(), jalview.io.DataSourceType.PASTE)) { alignFrame.alignPanel.fontChanged(); alignFrame.alignPanel.setScrollValues(0, 0); @@ -394,7 +426,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, else { if (!alignFrame.parseFeaturesFile(textarea.getText(), - jalview.io.AppletFormatAdapter.PASTE)) + jalview.io.DataSourceType.PASTE)) { alignFrame.statusBar .setText(MessageManager @@ -417,13 +449,13 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, if (alignFrame.alignPanel.av.applet.jmolAvailable) { - new jalview.appletgui.AppletJmol(pdb, new SequenceI[] - { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE); + new jalview.appletgui.AppletJmol(pdb, new SequenceI[] { seq }, null, + alignFrame.alignPanel, DataSourceType.PASTE); } else { - new MCview.AppletPDBViewer(pdb, new SequenceI[] - { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE); + new MCview.AppletPDBViewer(pdb, new SequenceI[] { seq }, null, + alignFrame.alignPanel, DataSourceType.PASTE); } } @@ -469,6 +501,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, this.add(textarea, java.awt.BorderLayout.CENTER); } + @Override public void mousePressed(MouseEvent evt) { if (textarea.getText().startsWith( @@ -478,18 +511,22 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, } } + @Override public void mouseReleased(MouseEvent evt) { } + @Override public void mouseClicked(MouseEvent evt) { } + @Override public void mouseEntered(MouseEvent evt) { } + @Override public void mouseExited(MouseEvent evt) { }