From: amwaterhouse Date: Fri, 24 Feb 2006 11:44:36 +0000 (+0000) Subject: First attempt at hidden regions X-Git-Tag: Root_VamJalview_2_07b+~94 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3098f4ad5ced6a2dce2327dfa8547c6c0b129e13;p=jalview.git First attempt at hidden regions --- diff --git a/src/jalview/gui/ColumnSelection.java b/src/jalview/gui/ColumnSelection.java index a7fd83a..02810a4 100755 --- a/src/jalview/gui/ColumnSelection.java +++ b/src/jalview/gui/ColumnSelection.java @@ -28,6 +28,9 @@ public class ColumnSelection { Vector selected = new Vector(); + //Vector of int [] {startCol, endCol} + Vector hiddenColumns; + /** * DOCUMENT ME! * @@ -151,15 +154,6 @@ public class ColumnSelection return min; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector asVector() - { - return selected; - } /** * DOCUMENT ME! @@ -179,4 +173,147 @@ public class ColumnSelection } } } + + /** + * This Method is used to return all the HiddenColumn regions + * less than the given index. + * @param end int + * @return Vector + */ + public Vector getHiddenColumns() + { + return hiddenColumns; + } + + public int adjustForHiddenColumns(int column) + { + int result = column; + if (hiddenColumns != null) + { + for (int i = 0; i < hiddenColumns.size(); i++) + { + int[] region = (int[]) hiddenColumns.elementAt(i); + if (result >= region[0]) + { + result += region[1] - region[0] + 1; + } + } + } + return result; + } + + /** + * Use this method to find out where a visible column is in the alignment + * when hidden columns exist + * @param hiddenColumn int + * @return int + */ + public int findColumnPosition(int hiddenColumn) + { + int result = hiddenColumn; + if (hiddenColumns != null) + { + int index = 0; + int gaps = 0; + do + { + int[] region = (int[]) hiddenColumns.elementAt(index); + if (hiddenColumn > region[1]) + { + result -= region[1]+1-region[0]; + } + index++; + } + while (index < hiddenColumns.size()); + + result -= gaps; + } + + return result; + } + + /** + * Use this method to determine where the next hiddenRegion starts + */ + public int findHiddenRegionPosition(int hiddenRegion) + { + int result = 0; + if (hiddenColumns != null) + { + int index = 0; + int gaps = 0; + do + { + int[] region = (int[]) hiddenColumns.elementAt(index); + if(hiddenRegion==0) + { + return region[0]; + } + + gaps += region[1] +1 - region[0]; + result = region[1] +1; + index++; + } + while(index < hiddenRegion+1); + + result -= gaps; + } + + return result; + } + + + + public void hideColumns(int res, AlignViewport av) + { + if(hiddenColumns==null) + hiddenColumns = new Vector(); + + // First find out range of columns to hide + int min = res, max = res+1; + while( contains(min) ) + { removeElement(min); min --; } + + while( contains(max) ) + { removeElement(max); max ++; } + + min++; max--; + + boolean added = false; + for(int i=0; i= startx) && (sel <= endx)) { @@ -264,7 +312,7 @@ public class ScalePanel extends JPanel { if ((i % 10) == 0) { - gg.drawString(String.valueOf(i), + gg.drawString(String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i)), (i - startx - 1) * av.charWidth, y); gg.drawLine((int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)), y + 2, @@ -279,5 +327,32 @@ public class ScalePanel extends JPanel (av.charWidth / 2)), y + (fm.getDescent() * 2)); } } + + if (av.hasHiddenColumns) + { + gg.setColor(Color.blue); + int res; + for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++) + { + res = av.getColumnSelection().findHiddenRegionPosition( i )-startx; + + gg.fillPolygon(new int[] { res*av.charWidth - 4, + res*av.charWidth + 4, + res*av.charWidth }, + new int[] + { + y-av.charHeight/2 , y-av.charHeight/2 , + y + 8 + }, 3); + + } + + if (reveal != null && reveal[0] > startx && reveal[0] < endx) + { + gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0); + } + } + + } }