From 08c8b9d76f478017bdb4fbd5bc1b4d0e16421de6 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 17 Aug 2016 12:30:57 +0100 Subject: [PATCH] JAL-2173 don't remove annotation from hidden columns --- src/jalview/appletgui/AnnotationPanel.java | 10 +++---- src/jalview/gui/AnnotationPanel.java | 45 ++++++++++++++++++---------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index dd652b1..1a5dc05 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -160,12 +160,12 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, if (evt.getActionCommand().equals(REMOVE)) { - for (int sel : av.getColumnSelection().getSelected()) + for (int index : av.getColumnSelection().getSelected()) { - // TODO: JAL-2001 check if applet has faulty 'REMOVE' selected columns - // of - // annotation if selection includes hidden columns - anot[sel] = null; + if (av.getColumnSelection().isVisible(index)) + { + anot[index] = null; + } } } else if (evt.getActionCommand().equals(LABEL)) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 398f57d..eec1881 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -289,9 +289,12 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (evt.getActionCommand().equals(REMOVE)) { - for (int sel : av.getColumnSelection().getSelected()) + for (int index : av.getColumnSelection().getSelected()) { - anot[sel] = null; + if (av.getColumnSelection().isVisible(index)) + { + anot[index] = null; + } } } else if (evt.getActionCommand().equals(LABEL)) @@ -423,9 +426,21 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return; } - private String collectAnnotVals(Annotation[] anot, String label2) + /** + * Returns any existing annotation concatenated as a string. For each + * annotation, takes the description, if any, else the secondary structure + * character (if type is HELIX, SHEET or STEM), else the display character (if + * type is LABEL). + * + * @param anots + * @param type + * @return + */ + private String collectAnnotVals(Annotation[] anots, String type) { - String collatedInput = ""; + // TODO is this method wanted? why? 'last' is not used + + StringBuilder collatedInput = new StringBuilder(64); String last = ""; ColumnSelection viscols = av.getColumnSelection(); // TODO: refactor and save av.getColumnSelection for efficiency @@ -437,22 +452,22 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, continue; } String tlabel = null; - if (anot[index] != null) + if (anots[index] != null) { // LML added stem code - if (label2.equals(HELIX) || label2.equals(SHEET) - || label2.equals(STEM) || label2.equals(LABEL)) + if (type.equals(HELIX) || type.equals(SHEET) + || type.equals(STEM) || type.equals(LABEL)) { - tlabel = anot[index].description; + tlabel = anots[index].description; if (tlabel == null || tlabel.length() < 1) { - if (label2.equals(HELIX) || label2.equals(SHEET) - || label2.equals(STEM)) + if (type.equals(HELIX) || type.equals(SHEET) + || type.equals(STEM)) { - tlabel = "" + anot[index].secondaryStructure; + tlabel = "" + anots[index].secondaryStructure; } else { - tlabel = "" + anot[index].displayCharacter; + tlabel = "" + anots[index].displayCharacter; } } } @@ -460,13 +475,13 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { if (last.length() > 0) { - collatedInput += " "; + collatedInput.append(" "); } - collatedInput += tlabel; + collatedInput.append(tlabel); } } } - return collatedInput; + return collatedInput.toString(); } /** -- 1.7.10.2