From: kiramt Date: Wed, 1 Mar 2017 08:46:10 +0000 (+0000) Subject: JAL-2388 Preliminary refactor check-in, does not compile X-Git-Tag: Release_2_10_2~3^2~92^2~58 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=79631ef84a124bfefa84c24b85dc77883366ad4a;hp=d862ec6b58b37b80416c7a65d7069f6e785276c1;p=jalview.git JAL-2388 Preliminary refactor check-in, does not compile --- diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 7bebfa9..f1bb8de 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -150,10 +150,11 @@ public class AlignViewport extends AlignmentViewport implements public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) { setAlignment(al); - if (hiddenColumns != null) + posProps.setHiddenColumns(hiddenColumns); + /*if (hiddenColumns != null) { colSel = hiddenColumns; - } + }*/ init(); } @@ -197,10 +198,11 @@ public class AlignViewport extends AlignmentViewport implements Cache.log.debug("Setting viewport's view id : " + viewId); } setAlignment(al); - if (hiddenColumns != null) + posProps.setHiddenColumns(hiddenColumns); + /*if (hiddenColumns != null) { colSel = hiddenColumns; - } + }*/ init(); } @@ -533,7 +535,9 @@ public class AlignViewport extends AlignmentViewport implements { end = alignment.getWidth(); } - viscontigs = colSel.getVisibleContigs(start, end); + viscontigs = posProps.getColumnSelection() + .getVisibleContigs(start, end); + // viscontigs = colSel.getVisibleContigs(start, end); return viscontigs; } diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 41248b1..b62c61c 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -589,9 +589,9 @@ public abstract class AlignmentViewport implements AlignViewportI, return isDataset; } - private Map hiddenRepSequences; - protected ColumnSelection colSel = new ColumnSelection(); + + // protected ColumnSelection colSel = new ColumnSelection(); public boolean autoCalculateConsensus = true; @@ -632,7 +632,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { residueShading.setConservation(hconservation); } - residueShading.alignmentChanged(alignment, hiddenRepSequences); + residueShading.alignmentChanged(alignment, getHiddenRepSequences()); } /* @@ -651,7 +651,8 @@ public abstract class AlignmentViewport implements AlignViewportI, if (cs != null) { sg.getGroupColourScheme() - .alignmentChanged(sg, hiddenRepSequences); +.alignmentChanged(sg, + getHiddenRepSequences()); } } } @@ -1094,24 +1095,27 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setHiddenColumns(ColumnSelection colsel) { - this.colSel = colsel; + posProps.setHiddenColumns(colsel); + // this.colSel = colsel; } @Override public ColumnSelection getColumnSelection() { - return colSel; + return posProps.getColumnSelection(); + // return colSel; } @Override public void setColumnSelection(ColumnSelection colSel) { - this.colSel = colSel; + posProps.setColumnSelection(colSel); + /*this.colSel = colSel; if (colSel != null) { updateHiddenColumns(); } - isColSelChanged(true); + isColSelChanged(true);*/ } /** @@ -1121,14 +1125,14 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public Map getHiddenRepSequences() { - return hiddenRepSequences; + return posProps.getHiddenRepSequences(); } @Override public void setHiddenRepSequences( Map hiddenRepSequences) { - this.hiddenRepSequences = hiddenRepSequences; + posProps.getHiddenRepSequences(); } @Override @@ -1141,7 +1145,8 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public boolean hasHiddenColumns() { - return colSel != null && colSel.hasHiddenColumns(); + return posProps.hasHiddenColumns(); + // return colSel != null && colSel.hasHiddenColumns(); } public void updateHiddenColumns() @@ -1211,7 +1216,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } - private long sgrouphash = -1, colselhash = -1; + private long sgrouphash = -1; /** * checks current SelectionGroup against record of last hash value, and @@ -1247,7 +1252,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public boolean isColSelChanged(boolean b) { - int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); + return posProps.isColSelChanged(b); + /*int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); if (hc != -1 && hc != colselhash) { if (b) @@ -1256,7 +1262,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } return true; } - return false; + return false;*/ } @Override @@ -1337,6 +1343,21 @@ public abstract class AlignmentViewport implements AlignViewportI, // common hide/show column stuff + public void hideColumns(int start, int end) + { + posProps.hideColumns(start, end); + } + + public void showColumn(int col) + { + posProps.showColumn(col); + } + + public void showAllHiddenColumns() + { + posProps.showAllHiddenColumns(); + } + public void hideSelectedColumns() { if (colSel.isEmpty()) @@ -1349,61 +1370,41 @@ public abstract class AlignmentViewport implements AlignViewportI, isColSelChanged(true); } - public void hideColumns(int start, int end) - { - if (start == end) - { - colSel.hideColumns(start); - } - else - { - colSel.hideColumns(start, end); - } - isColSelChanged(true); - } - - public void showColumn(int col) - { - colSel.revealHiddenColumns(col); - isColSelChanged(true); - } - public void showAllHiddenColumns() - { - colSel.revealAllHiddenColumns(); - isColSelChanged(true); - } // common hide/show seq stuff public void showAllHiddenSeqs() { - if (alignment.getHiddenSequences().getSize() > 0) - { - if (selectionGroup == null) - { - selectionGroup = new SequenceGroup(); - selectionGroup.setEndRes(alignment.getWidth() - 1); - } - List tmp = alignment.getHiddenSequences().showAll( - hiddenRepSequences); - for (SequenceI seq : tmp) - { - selectionGroup.addSequence(seq, false); - setSequenceAnnotationsVisible(seq, true); - } + selectionGroup = posProps.showAllHiddenSeqs(selectionGroup); - hiddenRepSequences = null; + /* if (alignment.getHiddenSequences().getSize() > 0) + { + if (selectionGroup == null) + { + selectionGroup = new SequenceGroup(); + selectionGroup.setEndRes(alignment.getWidth() - 1); + } + List tmp = alignment.getHiddenSequences().showAll( + hiddenRepSequences); + for (SequenceI seq : tmp) + { + selectionGroup.addSequence(seq, false); + setSequenceAnnotationsVisible(seq, true); + } - firePropertyChange("alignment", null, alignment.getSequences()); - // used to set hasHiddenRows/hiddenRepSequences here, after the property - // changed event - sendSelection(); - } + hiddenRepSequences = null; + + firePropertyChange("alignment", null, alignment.getSequences()); + // used to set hasHiddenRows/hiddenRepSequences here, after the property + // changed event + sendSelection(); + }*/ } public void showSequence(int index) { - List tmp = alignment.getHiddenSequences().showSequence( + posProps.showSequence(index, selectionGroup); + /*List tmp = alignment.getHiddenSequences().showSequence( index, hiddenRepSequences); if (tmp.size() > 0) { @@ -1420,12 +1421,13 @@ public abstract class AlignmentViewport implements AlignViewportI, } firePropertyChange("alignment", null, alignment.getSequences()); sendSelection(); - } + }*/ } public void hideAllSelectedSeqs() { - if (selectionGroup == null || selectionGroup.getSize() < 1) + posProps.hideAllSelectedSeqs(selectionGroup); + /*if (selectionGroup == null || selectionGroup.getSize() < 1) { return; } @@ -1434,12 +1436,13 @@ public abstract class AlignmentViewport implements AlignViewportI, hideSequence(seqs); - setSelectionGroup(null); + setSelectionGroup(null);*/ } public void hideSequence(SequenceI[] seq) { - if (seq != null) + posProps.hideSequence(seq); + /*if (seq != null) { for (int i = 0; i < seq.length; i++) { @@ -1447,7 +1450,7 @@ public abstract class AlignmentViewport implements AlignViewportI, setSequenceAnnotationsVisible(seq[i], false); } firePropertyChange("alignment", null, alignment.getSequences()); - } + }*/ } /** @@ -1461,7 +1464,8 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public void hideSequences(SequenceI sequence, boolean representGroup) { - if (selectionGroup == null || selectionGroup.getSize() < 1) + posProps.hideSequences(sequence, representGroup, selectionGroup); + /*if (selectionGroup == null || selectionGroup.getSize() < 1) { hideSequence(new SequenceI[] { sequence }); return; @@ -1480,33 +1484,14 @@ public abstract class AlignmentViewport implements AlignViewportI, hideSequence(hseqs); setSelectionGroup(null); - sendSelection(); + sendSelection();*/ } - /** - * Set visibility for any annotations for the given sequence. - * - * @param sequenceI - */ - protected void setSequenceAnnotationsVisible(SequenceI sequenceI, - boolean visible) - { - AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation(); - if (anns != null) - { - for (AlignmentAnnotation ann : anns) - { - if (ann.sequenceRef == sequenceI) - { - ann.visible = visible; - } - } - } - } public void hideRepSequences(SequenceI repSequence, SequenceGroup sg) { - int sSize = sg.getSize(); + posProps.hideRepSequences(repSequence, sg); + /*int sSize = sg.getSize(); if (sSize < 2) { return; @@ -1536,7 +1521,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } sg.setSeqrep(repSequence); // note: not done in 2.7applet sg.setHidereps(true); // note: not done in 2.7applet - hideSequence(seqs); + hideSequence(seqs);*/ } @@ -1566,8 +1551,9 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public boolean isHiddenRepSequence(SequenceI seq) { - return (hiddenRepSequences != null && hiddenRepSequences - .containsKey(seq)); + return posProps.isHiddenRepSequence(seq); + // return (hiddenRepSequences != null && hiddenRepSequences + // .containsKey(seq)); } /** @@ -1578,21 +1564,24 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public SequenceGroup getRepresentedSequences(SequenceI seq) { - return (SequenceGroup) (hiddenRepSequences == null ? null - : hiddenRepSequences.get(seq)); + return posProps.getRepresentedSequences(seq); + // return (SequenceGroup) (hiddenRepSequences == null ? null + // : hiddenRepSequences.get(seq)); } @Override public int adjustForHiddenSeqs(int alignmentIndex) { - return alignment.getHiddenSequences().adjustForHiddenSeqs( - alignmentIndex); + return posProps.adjustForHiddenSeqs(alignmentIndex); + // return alignment.getHiddenSequences().adjustForHiddenSeqs( + // alignmentIndex); } @Override public void invertColumnSelection() { - colSel.invertColumnSelection(0, alignment.getWidth()); + posProps.invertColumnSelection(); + // colSel.invertColumnSelection(0, alignment.getWidth()); } @Override @@ -1640,7 +1629,7 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public CigarArray getViewAsCigars(boolean selectedRegionOnly) { - return new CigarArray(alignment, colSel, + return new CigarArray(alignment, posProps.getColumnSelection(), (selectedRegionOnly ? selectionGroup : null)); } @@ -1655,8 +1644,8 @@ public abstract class AlignmentViewport implements AlignViewportI, public jalview.datamodel.AlignmentView getAlignmentView( boolean selectedOnly, boolean markGroups) { - return new AlignmentView(alignment, colSel, selectionGroup, - colSel != null && colSel.hasHiddenColumns(), selectedOnly, + return new AlignmentView(alignment, posProps.getColumnSelection(), + selectionGroup, posProps.hasHiddenColumns(), selectedOnly, markGroups); } @@ -1700,9 +1689,9 @@ public abstract class AlignmentViewport implements AlignViewportI, } selection = new String[iSize]; - if (colSel != null && colSel.hasHiddenColumns()) + if (posProps.hasHiddenColumns()) { - selection = colSel.getVisibleSequenceStrings(start, end, seqs); + selection = posProps.getVisibleSequenceStrings(start, end, seqs); } else { @@ -1718,49 +1707,52 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public List getVisibleRegionBoundaries(int min, int max) { - ArrayList regions = new ArrayList(); - int start = min; - int end = max; + return posProps.getVisibleRegionBoundaries(min, max); + /* ArrayList regions = new ArrayList(); + int start = min; + int end = max; - do - { - if (colSel != null && colSel.hasHiddenColumns()) - { - if (start == 0) + do { - start = colSel.adjustForHiddenColumns(start); - } - - end = colSel.getHiddenBoundaryRight(start); - if (start == end) - { - end = max; - } - if (end > max) - { - end = max; - } - } + if (colSel != null && colSel.hasHiddenColumns()) + { + if (start == 0) + { + start = colSel.adjustForHiddenColumns(start); + } + + end = colSel.getHiddenBoundaryRight(start); + if (start == end) + { + end = max; + } + if (end > max) + { + end = max; + } + } - regions.add(new int[] { start, end }); + regions.add(new int[] { start, end }); - if (colSel != null && colSel.hasHiddenColumns()) - { - start = colSel.adjustForHiddenColumns(end); - start = colSel.getHiddenBoundaryLeft(start) + 1; - } - } while (end < max); + if (posProps.hasHiddenColumns()) + { + start = colSel.adjustForHiddenColumns(end); + start = colSel.getHiddenBoundaryLeft(start) + 1; + } + } while (end < max); - int[][] startEnd = new int[regions.size()][2]; + int[][] startEnd = new int[regions.size()][2]; - return regions; + return regions;*/ } @Override public List getVisibleAlignmentAnnotation( boolean selectedOnly) { - ArrayList ala = new ArrayList(); + return posProps.getVisibleAlignmentAnnotation(selectedOnly, + selectionGroup); + /*ArrayList ala = new ArrayList(); AlignmentAnnotation[] aa; if ((aa = alignment.getAlignmentAnnotation()) != null) { @@ -1779,7 +1771,7 @@ public abstract class AlignmentViewport implements AlignViewportI, ala.add(clone); } } - return ala; + return ala;*/ } @Override @@ -1852,7 +1844,7 @@ public abstract class AlignmentViewport implements AlignViewportI, ResidueShaderI rs = residueShading; if (rs != null) { - rs.alignmentChanged(alignment, hiddenRepSequences); + rs.alignmentChanged(alignment, posProps.getHiddenRepSequences()); rs.setConsensus(hconsensus); if (rs.conservationApplied()) @@ -1867,7 +1859,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (sg.cs != null) { - sg.cs.alignmentChanged(sg, hiddenRepSequences); + sg.cs.alignmentChanged(sg, posProps.getHiddenRepSequences()); } sg.recalcConservation(); } @@ -2808,7 +2800,11 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public void expandColSelection(SequenceGroup sg, boolean wholewidth) { - int sgs, sge; + if (!this.hasSelectedColumns()) + { + posProps.expandColSelection(sg, wholewidth); + } + /*int sgs, sge; if (sg != null && (sgs = sg.getStartRes()) >= 0 && sg.getStartRes() <= (sge = sg.getEndRes()) && !this.hasSelectedColumns()) @@ -2826,7 +2822,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { colSel.addElement(cspos); } - } + }*/ } /** diff --git a/src/jalview/viewmodel/ViewportPositionProps.java b/src/jalview/viewmodel/ViewportPositionProps.java index 1bb49af..4f67cc6 100644 --- a/src/jalview/viewmodel/ViewportPositionProps.java +++ b/src/jalview/viewmodel/ViewportPositionProps.java @@ -21,7 +21,17 @@ package jalview.viewmodel; import jalview.api.ViewStyleI; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SequenceCollectionI; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; /** * Supplies and updates viewport properties relating to position such as: start @@ -54,6 +64,14 @@ public class ViewportPositionProps extends ViewportProperties // viewstyle private ViewStyleI viewstyle; + // hidden column data + protected ColumnSelection colSel = new ColumnSelection(); + + private long colselhash = -1; + + // hidden sequence data + private Map hiddenRepSequences; + /** * Constructor * @param alignment TODO @@ -209,7 +227,6 @@ public class ViewportPositionProps extends ViewportProperties public int convertPixelsToResidues(int x) { return Math.round((float) x / viewstyle.getCharWidth()); - // return (int) ((float) x / viewstyle.getCharWidth()); } /** @@ -222,7 +239,6 @@ public class ViewportPositionProps extends ViewportProperties public int convertPixelsToSequences(int y) { return Math.round((float) y / viewstyle.getCharHeight()); - // return (int) ((float) y / viewstyle.getCharHeight()); } /** @@ -248,4 +264,389 @@ public class ViewportPositionProps extends ViewportProperties { return (r * viewstyle.getCharWidth()); } + + public void setHiddenColumns(ColumnSelection colsel) + { + this.colSel = colsel; + } + + public ColumnSelection getColumnSelection() + { + return colSel; + } + + public void setColumnSelection(ColumnSelection colSel) + { + this.colSel = colSel; + if (colSel != null) + { + // updateHiddenColumns(); - does nothing + } + isColSelChanged(true); + } + + public boolean hasHiddenColumns() + { + return colSel != null && colSel.hasHiddenColumns(); + } + + /** + * checks current colsel against record of last hash value, and optionally + * updates record. + * + * @param b + * update the record of last hash value + * @return true if colsel changed since last call (when b is true) + */ + public boolean isColSelChanged(boolean b) + { + int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); + if (hc != -1 && hc != colselhash) + { + if (b) + { + colselhash = hc; + } + return true; + } + return false; + } + + public void hideColumns(int start, int end) + { + if (start == end) + { + colSel.hideColumns(start); + } + else + { + colSel.hideColumns(start, end); + } + isColSelChanged(true); + } + + public void showColumn(int col) + { + colSel.revealHiddenColumns(col); + isColSelChanged(true); + } + + public void showAllHiddenColumns() + { + colSel.revealAllHiddenColumns(); + isColSelChanged(true); + } + + public void invertColumnSelection() + { + colSel.invertColumnSelection(0, al.getWidth()); + } + + public List getVisibleRegionBoundaries(int min, int max) + { + ArrayList regions = new ArrayList(); + int start = min; + int end = max; + + do + { + if (hasHiddenColumns()) + { + if (start == 0) + { + start = colSel.adjustForHiddenColumns(start); + } + + end = colSel.getHiddenBoundaryRight(start); + if (start == end) + { + end = max; + } + if (end > max) + { + end = max; + } + } + + regions.add(new int[] { start, end }); + + if (hasHiddenColumns()) + { + start = colSel.adjustForHiddenColumns(end); + start = colSel.getHiddenBoundaryLeft(start) + 1; + } + } while (end < max); + + int[][] startEnd = new int[regions.size()][2]; + + return regions; + } + + /** + * synthesize a column selection if none exists so it covers the given + * selection group. if wholewidth is false, no column selection is made if the + * selection group covers the whole alignment width. + * + * @param sg + * @param wholewidth + */ + public void expandColSelection(SequenceGroup sg, boolean wholewidth) + { + int sgs, sge; + if (sg != null && (sgs = sg.getStartRes()) >= 0 + && sg.getStartRes() <= (sge = sg.getEndRes())) + { + if (!wholewidth && al.getWidth() == (1 + sge - sgs)) + { + // do nothing + return; + } + if (colSel == null) + { + colSel = new ColumnSelection(); + } + for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++) + { + colSel.addElement(cspos); + } + } + } + + public List getVisibleAlignmentAnnotation( + boolean selectedOnly, SequenceGroup selectionGroup) + { + ArrayList ala = new ArrayList(); + AlignmentAnnotation[] aa; + if ((aa = al.getAlignmentAnnotation()) != null) + { + for (AlignmentAnnotation annot : aa) + { + AlignmentAnnotation clone = new AlignmentAnnotation(annot); + if (selectedOnly && selectionGroup != null) + { + colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), + selectionGroup.getEndRes(), clone); + } + else + { + colSel.makeVisibleAnnotation(clone); + } + ala.add(clone); + } + } + return ala; + } + + public String[] getVisibleSequenceStrings(int start, int end, + SequenceI[] seqs) + { + return colSel.getVisibleSequenceStrings(start, end, seqs); + } + + /** + * Set visibility for any annotations for the given sequence. + * + * @param sequenceI + */ + protected void setSequenceAnnotationsVisible(SequenceI sequenceI, + boolean visible) + { + AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); + if (anns != null) + { + for (AlignmentAnnotation ann : anns) + { + if (ann.sequenceRef == sequenceI) + { + ann.visible = visible; + } + } + } + } + + public void setHiddenRepSequences( + Map hiddenRepSequences) + { + this.hiddenRepSequences = hiddenRepSequences; + } + + public Map getHiddenRepSequences() + { + return hiddenRepSequences; + } + + // common hide/show seq stuff + public SequenceGroup showAllHiddenSeqs(SequenceGroup selectionGroup) + { + if (al.getHiddenSequences().getSize() > 0) + { + if (selectionGroup == null) + { + selectionGroup = new SequenceGroup(); + selectionGroup.setEndRes(al.getWidth() - 1); + } + List tmp = al.getHiddenSequences().showAll( + hiddenRepSequences); + for (SequenceI seq : tmp) + { + selectionGroup.addSequence(seq, false); + setSequenceAnnotationsVisible(seq, true); + } + + hiddenRepSequences = null; + + firePropertyChange("alignment", null, al.getSequences()); + // used to set hasHiddenRows/hiddenRepSequences here, after the property + // changed event + sendSelection(); + } + } + + public void showSequence(int index, SequenceGroup selectionGroup) + { + List tmp = al.getHiddenSequences().showSequence(index, + hiddenRepSequences); + if (tmp.size() > 0) + { + if (selectionGroup == null) + { + selectionGroup = new SequenceGroup(); + selectionGroup.setEndRes(al.getWidth() - 1); + } + + for (SequenceI seq : tmp) + { + selectionGroup.addSequence(seq, false); + setSequenceAnnotationsVisible(seq, true); + } + firePropertyChange("alignment", null, al.getSequences()); + sendSelection(); + } + } + + public void hideAllSelectedSeqs(SequenceGroup selectionGroup) + { + if (selectionGroup == null || selectionGroup.getSize() < 1) + { + return; + } + + SequenceI[] seqs = selectionGroup.getSequencesInOrder(al); + + hideSequence(seqs); + + setSelectionGroup(null); + } + + public void hideSequence(SequenceI[] seq) + { + if (seq != null) + { + for (int i = 0; i < seq.length; i++) + { + al.getHiddenSequences().hideSequence(seq[i]); + setSequenceAnnotationsVisible(seq[i], false); + } + firePropertyChange("alignment", null, al.getSequences()); + } + } + + /** + * Hides the specified sequence, or the sequences it represents + * + * @param sequence + * the sequence to hide, or keep as representative + * @param representGroup + * if true, hide the current selection group except for the + * representative sequence + */ + public void hideSequences(SequenceI sequence, boolean representGroup, + SequenceGroup selectionGroup) + { + if (selectionGroup == null || selectionGroup.getSize() < 1) + { + hideSequence(new SequenceI[] { sequence }); + return; + } + + if (representGroup) + { + hideRepSequences(sequence, selectionGroup); + setSelectionGroup(null); + return; + } + + int gsize = selectionGroup.getSize(); + SequenceI[] hseqs = selectionGroup.getSequences().toArray( + new SequenceI[gsize]); + + hideSequence(hseqs); + setSelectionGroup(null); + sendSelection(); + } + + public void hideRepSequences(SequenceI repSequence, SequenceGroup sg) + { + int sSize = sg.getSize(); + if (sSize < 2) + { + return; + } + + if (hiddenRepSequences == null) + { + hiddenRepSequences = new Hashtable(); + } + + hiddenRepSequences.put(repSequence, sg); + + // Hide all sequences except the repSequence + SequenceI[] seqs = new SequenceI[sSize - 1]; + int index = 0; + for (int i = 0; i < sSize; i++) + { + if (sg.getSequenceAt(i) != repSequence) + { + if (index == sSize - 1) + { + return; + } + + seqs[index++] = sg.getSequenceAt(i); + } + } + sg.setSeqrep(repSequence); // note: not done in 2.7applet + sg.setHidereps(true); // note: not done in 2.7applet + hideSequence(seqs); + + } + + /** + * + * @param seq + * @return true if there are sequences represented by this sequence that are + * currently hidden + */ + public boolean isHiddenRepSequence(SequenceI seq) + { + return (hiddenRepSequences != null && hiddenRepSequences + .containsKey(seq)); + } + + /** + * + * @param seq + * @return null or a sequence group containing the sequences that seq + * represents + */ + public SequenceGroup getRepresentedSequences(SequenceI seq) + { + return (SequenceGroup) (hiddenRepSequences == null ? null + : hiddenRepSequences.get(seq)); + } + + public int adjustForHiddenSeqs(int alignmentIndex) + { + return al.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex); + } }