From: gmungoc Date: Mon, 22 Jun 2015 13:05:12 +0000 (+0100) Subject: JAL-892 tidy Varna panel names; JAL-1789 simplified mouseover X-Git-Tag: Release_2_10_0~596 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=21fccb30635d61dbf7ad0f266a88f07fb87358f7;p=jalview.git JAL-892 tidy Varna panel names; JAL-1789 simplified mouseover --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 1f5d4cb..b2bf58b 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -662,7 +662,7 @@ label.cancel_job_close_dialog = Close this dialog and cancel job label.input_output = Input/Output label.cut_paste = Cut'n'Paste label.adjusting_parameters_for_calculation = Adjusting parameters for existing Calculation -label.2d_rna_structure_line = 2D RNA {0} +label.2d_rna_structure_line = 2D RNA {0} (alignment) label.2d_rna_sequence_name = 2D RNA - {0} label.edit_name_and_description_current_group = Edit name and description of current group. label.view_structure_for = View structure for {0} diff --git a/src/jalview/gui/AppVarna.java b/src/jalview/gui/AppVarna.java index 9316b05..beb4980 100644 --- a/src/jalview/gui/AppVarna.java +++ b/src/jalview/gui/AppVarna.java @@ -22,6 +22,7 @@ package jalview.gui; import java.awt.BorderLayout; import java.awt.Color; +import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.Hashtable; import java.util.LinkedHashMap; @@ -167,8 +168,6 @@ public class AppVarna extends JInternalFrame implements SelectionListener, /** * Constructor * - * @param sname - * a descriptive name * @param seq * the RNA sequence * @param aa @@ -176,41 +175,18 @@ public class AppVarna extends JInternalFrame implements SelectionListener, * @param ap * the AlignmentPanel creating this object */ - public AppVarna(String sname, SequenceI seq, AlignmentAnnotation aa, - AlignmentPanel ap) + public AppVarna(SequenceI seq, AlignmentAnnotation aa, AlignmentPanel ap) { this(ap); - String name = sname + " trimmed to " + seq.getName(); - String fullName = MessageManager.formatMessage("label.varna_params", + String sname = aa.sequenceRef == null ? "secondary structure (alignment)" + : seq.getName() + " structure"; + String theTitle = sname + + (aa.sequenceRef == null ? " trimmed to " + seq.getName() : ""); + theTitle = MessageManager.formatMessage("label.varna_params", new String[] - { name }); - setTitle(fullName); - - /* - * if (!aa.isValidStruc()) { throw new - * IllegalArgumentException("Invalid RNA structure annotation"); } final - * String struc = aa.getRNAStruc(); - * - * String strucseq = seq.getSequenceAsString(); - * - * String gappedTitle = sname + " (with gaps)"; String rnaTitle = - * gappedTitle; RNA gapped = new RNA(rnaTitle); try { - * gapped.setRNA(strucseq, replaceOddGaps(struc)); } catch - * (ExceptionUnmatchedClosingParentheses e2) { e2.printStackTrace(); } catch - * (ExceptionFileFormatOrSyntax e3) { e3.printStackTrace(); } - * models.put(gapped, new RnaModel(rnaTitle, aa, seq, gapped, true, null)); - * - * String trimmedTitle = "trimmed " + sname; rnaTitle = trimmedTitle; RNA - * trimmed = trimRNA(gapped, rnaTitle); models.put(trimmed, new - * RnaModel(rnaTitle, aa, seq, trimmed, false, null)); - */ - // vab = new AppVarnaBinding(Arrays.asList(new RNA[] - // { trimmed, gapped })); - // vab = new AppVarnaBinding(); - // // String seqName = seq.getName(); - // // String name = sname + " trimmed to " + seqName; - // initVarna(name); + { theTitle }); + setTitle(theTitle); String gappedTitle = sname + " (with gaps)"; RnaModel gappedModel = new RnaModel(gappedTitle, aa, seq, null, true, @@ -409,25 +385,35 @@ public class AppVarna extends JInternalFrame implements SelectionListener, * selected RNA in the VARNA window is highlighted at the specific position. * To be able to remove it before the next highlight it is saved in * _lastHighlight + * + * @param sequence + * @param index + * the aligned sequence position (base 0) + * @param position + * the dataset sequence position (base 1) */ @Override - public void mouseOverSequence(SequenceI sequence, int index) + public void mouseOverSequence(SequenceI sequence, final int index, + final int position) { RNA rna = vab.getSelectedRNA(); if (rna == null) { return; } - if (models.get(rna).seq == sequence) - { - ShiftList shift = offsets.get(rna); - if (shift != null) - { - // System.err.print("Orig pos:"+index); - index = shift.shift(index); - // System.err.println("\nFinal pos:"+index); - } - mouseOverHighlighter.highlightRegion(rna, index, index); + RnaModel rnaModel = models.get(rna); + if (rnaModel.seq == sequence) + { + int highlightPos = rnaModel.gapped ? index : position - 1; + // int highlightPos = index; + // ShiftList shift = offsets.get(rna); + // if (shift != null) + // { + // System.err.print("Orig pos:" + index); + // highlightPos = shift.shift(index); + // System.err.println("\nFinal pos:" + index); + // } + mouseOverHighlighter.highlightRegion(rna, highlightPos, highlightPos); vab.updateSelectedRNA(rna); } } @@ -630,7 +616,6 @@ public class AppVarna extends JInternalFrame implements SelectionListener, { registerOffset(rna, buildOffset(model.seq)); } - // TODO and add mapping (offsets) models.put(rna, newModel); // capture rna selection state when saved selectionHighlighter = new VarnaHighlighter(rna); @@ -680,6 +665,7 @@ public class AppVarna extends JInternalFrame implements SelectionListener, protected ShiftList buildOffset(SequenceI seq) { // TODO refactor to avoid duplication with trimRNA() + // TODO JAL-1789 bugs in use of ShiftList here ShiftList offset = new ShiftList(); int ofstart = -1; int sleng = seq.getLength(); @@ -715,10 +701,10 @@ public class AppVarna extends JInternalFrame implements SelectionListener, /** * Set the selected index in the model selection list * - * @param selectedRna + * @param selectedR */ - public void setSelectedIndex(int selectedRna) + public void setInitialSelection(final int selectedIndex) { - vab.setSelectedIndex(selectedRna); + vab.setSelectedIndex(selectedIndex); } } diff --git a/src/jalview/gui/AppVarnaBinding.java b/src/jalview/gui/AppVarnaBinding.java index 3ea8e4d..956c2e1 100644 --- a/src/jalview/gui/AppVarnaBinding.java +++ b/src/jalview/gui/AppVarnaBinding.java @@ -24,7 +24,6 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; -import java.awt.Font; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.dnd.DnDConstants; @@ -54,6 +53,7 @@ import javax.swing.event.ListSelectionListener; import fr.orsay.lri.varna.VARNAPanel; import fr.orsay.lri.varna.components.ReorderableJList; import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed; +import fr.orsay.lri.varna.exceptions.ExceptionNAViewAlgorithm; import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength; import fr.orsay.lri.varna.models.FullBackup; import fr.orsay.lri.varna.models.VARNAConfig; @@ -165,9 +165,9 @@ public class AppVarnaBinding extends JalviewVarnaBinding vp.setBackground(_backgroundColor); - Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12"); - // MC commented out stuff not added to panel - remove? + // Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12"); + // // _seq.setFont(textFieldsFont); // if (!rnaList.isEmpty()) // { @@ -531,12 +531,9 @@ public class AppVarnaBinding extends JalviewVarnaBinding } /* - * switch display if not already shown + * switch display */ - if (sel.rna != rna) - { - vp.showRNA(model.rna, model.config); - } + vp.showRNA(model.rna, model.config); try { @@ -547,12 +544,9 @@ public class AppVarnaBinding extends JalviewVarnaBinding vp.toXML(filePath); /* - * restore the previous display if needed + * restore the previous display */ - if (sel.rna != rna) - { - vp.showRNA(sel.rna, sel.config); - } + vp.showRNA(sel.rna, sel.config); return filePath; } catch (IOException e) @@ -596,7 +590,7 @@ public class AppVarnaBinding extends JalviewVarnaBinding * * @param selectedRna */ - public void setSelectedIndex(int selectedRna) + public void setSelectedIndex(final int selectedRna) { /* * note this does nothing if, say, selecting item 3 when only 1 has been @@ -604,7 +598,6 @@ public class AppVarnaBinding extends JalviewVarnaBinding */ _sideList.setSelectedIndex(selectedRna); // TODO ? need a worker thread to get this to happen properly - showSelectedStructure(); } /** @@ -622,9 +615,25 @@ public class AppVarnaBinding extends JalviewVarnaBinding * @param rna * @param config */ - protected void addStructure(RNA rna, VARNAConfig config) + protected void addStructure(final RNA rna, final VARNAConfig config) { - rna.drawRNARadiate(config); + drawRna(rna, config); _rnaList.add(config, rna, rna.getName()); } + + /** + * @param rna + * @param config + */ + protected void drawRna(final RNA rna, final VARNAConfig config) + { + try + { + rna.drawRNA(rna.getDrawMode(), config); + } catch (ExceptionNAViewAlgorithm e) + { + // only throwable for draw mode = 3 NAView + System.err.println("Error drawing RNA: " + e.getMessage()); + } + } } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 0ebc804..62c9cad 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -2172,7 +2172,7 @@ public class Jalview2XML }); } catch (Exception x) { - + System.err.println("Error loading alignment: " + x.getMessage()); } } return af; @@ -3348,7 +3348,7 @@ public class Jalview2XML tempStateFile); appVarna.addModel(rna, rnaTitle); } - appVarna.setSelectedIndex(viewer.getSelectedRna()); + appVarna.setInitialSelection(viewer.getSelectedRna()); } } } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 2ba4427..0095bc9 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -343,17 +343,16 @@ public class PopupMenu extends JPopupMenu /* * valid alignment RNA secondary structure annotation */ - final String structureLine = aa.label + " (alignment)"; menuItem = new JMenuItem(); menuItem.setText(MessageManager.formatMessage( "label.2d_rna_structure_line", new Object[] - { structureLine })); + { aa.label })); menuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { - new AppVarna(structureLine, seq, aa, ap); + new AppVarna(seq, aa, ap); } }); rnaStructureMenu.add(menuItem); @@ -361,7 +360,6 @@ public class PopupMenu extends JPopupMenu } } - if (seq.getAnnotation() != null) { AlignmentAnnotation seqAnns[] = seq.getAnnotation(); @@ -383,9 +381,7 @@ public class PopupMenu extends JPopupMenu public void actionPerformed(ActionEvent e) { // TODO: VARNA does'nt print gaps in the sequence - - new AppVarna(seq.getName() + " structure", seq, aa, - ap); + new AppVarna(seq, aa, ap); } }); rnaStructureMenu.add(menuItem); diff --git a/src/jalview/structure/SecondaryStructureListener.java b/src/jalview/structure/SecondaryStructureListener.java index 5d5d880..a7384f8 100644 --- a/src/jalview/structure/SecondaryStructureListener.java +++ b/src/jalview/structure/SecondaryStructureListener.java @@ -20,11 +20,20 @@ */ package jalview.structure; -import jalview.datamodel.*; +import jalview.datamodel.SequenceI; public interface SecondaryStructureListener { // TODO - redefine to allow RNA mouseovers to be passed back correctly to // listeners - public void mouseOverSequence(SequenceI sequence, int index); + /** + * act on a mouseover event + * + * @param sequence + * @param index + * the aligned sequence position (base 0) + * @param position + * the dataset sequence position (base 1) + */ + public void mouseOverSequence(SequenceI sequence, int index, int position); } diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 0253a7e..ac14b52 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -739,7 +739,7 @@ public class StructureSelectionManager else if (listener instanceof SecondaryStructureListener) { ((SecondaryStructureListener) listener).mouseOverSequence(seq, - indexpos); + indexpos, index); } } }