From: gmungoc Date: Mon, 23 Feb 2015 12:15:30 +0000 (+0000) Subject: JAL-1619 split frame now offered in applet 'input from textbox' X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=839db4a2e67d4b250e079511d51444d64237d3f4;p=jalview.git JAL-1619 split frame now offered in applet 'input from textbox' --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 3499fdd..6f47422 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1196,11 +1196,12 @@ label.show_logo = Show Logo label.normalise_logo = Normalise Logo label.no_colour_selection_in_scheme = Please, make a colour selection before to apply colour scheme label.no_colour_selection_warn = Error saving colour scheme -label.open_linked_alignment? = Would you like to open as a separate alignment, with cDNA and protein linked? -label.open_linked_alignment = Open linked alignment +label.open_split_window? = Would you like to open as a split window, with cDNA and protein linked? +label.open_split_window = Open split window label.no_mappings = No mappings found label.mapping_failed = No sequence mapping could be made between the alignments.
A mapping requires sequence names to match, and equivalent sequence lengths. action.no = No +action.yes = Yes label.for = for label.select_by_annotation = Select By Annotation action.select_by_annotation = Select by Annotation... diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index cd6c9e5..dc4539e 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1217,7 +1217,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, Frame frame = new Frame(); frame.add(cap); jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage( - "label.alignment_output_command", new String[] + "label.alignment_output_command", new Object[] { e.getActionCommand() }), 600, 500); cap.setText(new AppletFormatAdapter().formatSequences( e.getActionCommand(), viewport.getAlignment(), diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index 0c717b2..248153f 100644 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -20,7 +20,11 @@ */ package jalview.appletgui; +import jalview.analysis.AlignmentUtils; +import jalview.analysis.AlignmentUtils.MappingResult; +import jalview.bin.JalviewLite; import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.io.AnnotationFile; @@ -36,6 +40,7 @@ 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; @@ -225,7 +230,11 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, if (al != null) { - al.setDataset(null); + al.setDataset(null); // set dataset on alignment/sequences + if (openSplitFrame(al, format)) + { + return; + } if (newWindow) { AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet, @@ -244,6 +253,69 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, } /** + * Check whether the new alignment could be mapped to the current one as + * cDNA/protein, if so offer the option to open as split frame view. Returns + * true if a split frame view is opened, false if not. + * + * @param al + * @return + */ + protected boolean openSplitFrame(Alignment al, String format) + { + final AlignmentI thisAlignment = this.alignFrame.getAlignViewport().getAlignment(); + if (thisAlignment.isNucleotide() == al.isNucleotide()) + { + // both nucleotide or both protein + return false; + } + AlignmentI protein = thisAlignment.isNucleotide() ? al : thisAlignment; + AlignmentI dna = thisAlignment.isNucleotide() ? thisAlignment : al; + MappingResult mapped = AlignmentUtils.mapProteinToCdna(protein, dna); + if (mapped == MappingResult.NotMapped) + { + return false; + } + + /* + * A mapping is possible; ask user if they want a split frame. + */ + String title = MessageManager.getString("label.open_split_window"); + final JVDialog dialog = new JVDialog((Frame) this.getParent(), title, + true, 100, 400); + dialog.ok.setLabel(MessageManager.getString("action.yes")); + dialog.cancel.setLabel(MessageManager.getString("action.no")); + Panel question = new Panel(new BorderLayout()); + final String text = MessageManager + .getString("label.open_split_window?"); + question.add(new Label(text, Label.CENTER), BorderLayout.CENTER); + dialog.setMainPanel(question); + dialog.setVisible(true); + dialog.toFront(); + + if (!dialog.accept) + { + return false; + } + + /* + * Open SplitFrame with DNA above and protein below, including the alignment + * from textbox and a copy of the original. + */ + final JalviewLite applet = this.alignFrame.viewport.applet; + AlignFrame copyFrame = new AlignFrame( + this.alignFrame.viewport.getAlignment(), applet, + alignFrame.getTitle(), false, false); + 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; + SplitFrame sf = new SplitFrame(dnaFrame, proteinFrame); + sf.addToDisplay(false, applet); + return true; + } + + /** * Parse the text as a TCoffee score file, if successful add scores as * alignment annotations. */ diff --git a/src/jalview/appletgui/SplitFrame.java b/src/jalview/appletgui/SplitFrame.java index a012092..4f61f4a 100644 --- a/src/jalview/appletgui/SplitFrame.java +++ b/src/jalview/appletgui/SplitFrame.java @@ -40,8 +40,7 @@ public class SplitFrame extends EmbmenuFrame public void init() { setMenuBar(null); - outermost = new Panel(); - outermost.setLayout(new GridLayout(2, 1)); + outermost = new Panel(new GridLayout(2, 1)); Panel topPanel = new Panel(); Panel bottomPanel = new Panel(); @@ -58,12 +57,11 @@ public class SplitFrame extends EmbmenuFrame final AlignViewport bottomViewport = bottomFrame.viewport; final AlignmentI topAlignment = topViewport.getAlignment(); final AlignmentI bottomAlignment = bottomViewport.getAlignment(); - // topAlignment.setDataset(null); - // bottomAlignment.setDataset(null); AlignViewport cdna = topAlignment.isNucleotide() ? topViewport : (bottomAlignment.isNucleotide() ? bottomViewport : null); AlignViewport protein = !topAlignment.isNucleotide() ? topViewport : (!bottomAlignment.isNucleotide() ? bottomViewport : null); + MappingResult mapped = AlignmentUtils.mapProteinToCdna( protein.getAlignment(), cdna.getAlignment()); if (mapped != MappingResult.NotMapped) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 8fc10d7..2129db1 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -977,9 +977,9 @@ public class AlignViewport extends AlignmentViewport implements MessageManager.getString("label.split_window"), MessageManager.getString("label.new_window"), }; final String question = JvSwingUtils.wrapTooltip(true, - MessageManager.getString("label.open_linked_alignment?")); + MessageManager.getString("label.open_split_window?")); int response = JOptionPane.showOptionDialog(Desktop.desktop, question, - MessageManager.getString("label.open_linked_alignment"), + MessageManager.getString("label.open_split_window"), JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);