From: amwaterhouse Date: Wed, 8 Mar 2006 16:52:59 +0000 (+0000) Subject: Allow for hidden columns X-Git-Tag: Root_VamJalview_2_07b+~81 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=6cbc1c23947d6812cf5efa36998f237f60f4cc74;p=jalview.git Allow for hidden columns --- diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 69ae398..0213565 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -50,7 +50,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, AlignViewport av; AlignmentPanel ap; int activeRow = -1; - Vector activeRes; BufferedImage image; Graphics2D gg; FontMetrics fm; @@ -149,74 +148,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, return height; } - /** - * DOCUMENT ME! - * - * @param col DOCUMENT ME! - */ - public void removeEditableColumn(int col) - { - if (activeRow == -1) - { - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - if(aa==null) - return; - - for (int j = 0; j < aa.length; j++) - { - if (aa[j].editable) - { - activeRow = j; - - break; - } - } - } - - if ((activeRes != null) && activeRes.contains(String.valueOf(col))) - { - activeRes.removeElement(String.valueOf(col)); - } - - repaint(); - } - - /** - * DOCUMENT ME! - * - * @param col DOCUMENT ME! - */ - public void addEditableColumn(int col) - { - if (activeRow == -1) - { - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - if(aa==null) - return; - - for (int j = 0; j < aa.length; j++) - { - if (aa[j].editable) - { - activeRow = j; - - break; - } - } - } - - if (activeRes == null) - { - activeRes = new Vector(); - } - - if (!activeRes.contains(String.valueOf(col))) - { - activeRes.addElement(String.valueOf(col)); - } - repaint(); - } /** * DOCUMENT ME! @@ -230,10 +162,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (evt.getActionCommand().equals(REMOVE)) { - for (int i = 0; i < activeRes.size(); i++) + for (int i = 0; i < av.getColumnSelection().size(); i++) { - anot[Integer.parseInt(activeRes.get(i).toString())] = null; - anot[Integer.parseInt(activeRes.get(i).toString())] = null; + anot[av.getColumnSelection().columnAt(i)] = null; } } else if (evt.getActionCommand().equals(LABEL)) @@ -251,9 +182,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, aa[activeRow].hasText = true; } - for (int i = 0; i < activeRes.size(); i++) + for (int i = 0; i < av.getColumnSelection().size(); i++) { - int index = Integer.parseInt(activeRes.get(i).toString()); + int index = av.getColumnSelection().columnAt(i); if (anot[index] == null) { @@ -268,9 +199,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, Color col = JColorChooser.showDialog(this, "Choose foreground colour", Color.black); - for (int i = 0; i < activeRes.size(); i++) + for (int i = 0; i < av.getColumnSelection().size(); i++) { - int index = Integer.parseInt(activeRes.get(i).toString()); + int index = av.getColumnSelection().columnAt(i); if (anot[index] == null) { @@ -313,9 +244,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, aa[activeRow].hasText = true; } - for (int i = 0; i < activeRes.size(); i++) + for (int i = 0; i < av.getColumnSelection().size(); i++) { - int index = Integer.parseInt(activeRes.get(i).toString()); + int index = av.getColumnSelection().columnAt(i); if (anot[index] == null) { @@ -328,7 +259,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, } adjustPanelHeight(); - activeRes = null; repaint(); return; @@ -366,11 +296,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, //Stretch Graph graphStretch = i; graphStretchY = evt.getY(); - activeRes = null; - } - else - { - activeRes = null; } break; @@ -379,7 +304,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (SwingUtilities.isRightMouseButton(evt)) { - if (activeRes == null) + if (av.getColumnSelection() == null) { return; } @@ -412,19 +337,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - if (evt.isControlDown() || evt.isAltDown()) + if (evt.isShiftDown()) { - addEditableColumn(res); - } - else if (evt.isShiftDown()) - { - if (activeRes == null) - { - activeRes = new Vector(); - } - else - { - int start = Integer.parseInt(activeRes.get(activeRes.size() - + /*int start = Integer.parseInt(activeRes.get(activeRes.size() - 1).toString()); int end = res; @@ -437,14 +352,18 @@ public class AnnotationPanel extends JPanel implements MouseListener, for (int n = start; n <= end; n++) { - addEditableColumn(n); - } - } + addEditableColumn(n); + } */ } else { - activeRes = new Vector(); - activeRes.addElement(String.valueOf(res)); + if (av.getColumnSelection().contains(res)) + av.getColumnSelection().removeElement(res); + else + av.getColumnSelection().addElement(res); + + ap.repaint(); + } } @@ -529,6 +448,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + if(av.hasHiddenColumns) + res = av.getColumnSelection().adjustForHiddenColumns(res); + if (row > -1 && res-1) @@ -684,7 +606,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - int j; int x = 0; int y = 0; char[] lastSS = new char[aa.length]; @@ -730,10 +651,25 @@ public class AnnotationPanel extends JPanel implements MouseListener, iconOffset = 0; } - for (j = startRes; j < endRes; j++) + int column = startRes; + int yPos = startRes; + int aaMax = row.annotations.length-1; + + while (yPos < endRes) { - if ((row.annotations.length <= j) || - (row.annotations[j] == null)) + if (av.hasHiddenColumns) + { + column = av.getColumnSelection().adjustForHiddenColumns(yPos); + if (column > aaMax) + { + break; + } + } + else + column = yPos; + + if ((row.annotations.length <= column) || + (row.annotations[column] == null)) { validRes = false; } @@ -742,21 +678,21 @@ public class AnnotationPanel extends JPanel implements MouseListener, validRes = true; } - x = (j - startRes) * av.charWidth; + x = (yPos - startRes) * av.charWidth; if (activeRow == i) { g.setColor(Color.red); - if (activeRes != null) + if (av.getColumnSelection() != null) { - for (int n = 0; n < activeRes.size(); n++) + for (int n = 0; n < av.getColumnSelection().size(); n++) { - int v = Integer.parseInt(activeRes.get(n).toString()); + int v = av.getColumnSelection().columnAt(n); - if (v == j) + if (v == column) { - g.fillRect((j - startRes) * av.charWidth, y, + g.fillRect((column - startRes) * av.charWidth, y, av.charWidth, row.height); } } @@ -764,24 +700,24 @@ public class AnnotationPanel extends JPanel implements MouseListener, } if (validRes && - (row.annotations[j].displayCharacter.length() > 0)) + (row.annotations[column].displayCharacter.length() > 0)) { int charOffset = (av.charWidth - - fm.charWidth(row.annotations[j].displayCharacter.charAt( + fm.charWidth(row.annotations[column].displayCharacter.charAt( 0))) / 2; - g.setColor(row.annotations[j].colour); + g.setColor(row.annotations[column].colour); - if (j == 0 || row.graph>0) + if (column == 0 || row.graph>0) { - g.drawString(row.annotations[j].displayCharacter, x+charOffset, + g.drawString(row.annotations[column].displayCharacter, x+charOffset, y + iconOffset + 3); } - else if (((row.annotations[j - 1] == null) || - (row.annotations[j].displayCharacter != row.annotations[j - + else if (((row.annotations[column - 1] == null) || + (row.annotations[column].displayCharacter != row.annotations[column - 1].displayCharacter))) { - g.drawString(row.annotations[j].displayCharacter, x+charOffset, + g.drawString(row.annotations[column].displayCharacter, x+charOffset, y + iconOffset + 3); } } @@ -789,7 +725,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (row.hasIcons) { if (!validRes || - (row.annotations[j].secondaryStructure != lastSS[i])) + (row.annotations[column].secondaryStructure != lastSS[i])) { switch (lastSS[i]) { @@ -824,7 +760,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, if (validRes) { - lastSS[i] = row.annotations[j].secondaryStructure; + lastSS[i] = row.annotations[column].secondaryStructure; } else { @@ -834,6 +770,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, lastSSX[i] = x; } } + + yPos++; } x += av.charWidth; @@ -983,16 +921,35 @@ public class AnnotationPanel extends JPanel implements MouseListener, } eRes = Math.min(eRes, aa.annotations.length); - for (int j = sRes; j < eRes; j++) + + int column = sRes; + int yPos = sRes; + int aaMax = aa.annotations.length-1; + + while( yPos < eRes ) { - if(aa.annotations[j]==null || aa.annotations[j-1]==null) + if(av.hasHiddenColumns) + { + column = av.getColumnSelection().adjustForHiddenColumns(yPos); + if(column > aaMax) + { + break; + } + } + else + column = yPos; + + yPos ++; + + if(aa.annotations[column]==null || aa.annotations[column-1]==null) { x+=av.charWidth; continue; } - g.setColor(aa.annotations[j].colour); - y1 = y - (int) (((aa.annotations[j-1].value-min) / range) * graphHeight); - y2 = y - (int) (((aa.annotations[j].value-min) / range) * graphHeight); + + g.setColor(aa.annotations[column].colour); + y1 = y - (int) (((aa.annotations[column-1].value-min) / range) * graphHeight); + y2 = y - (int) (((aa.annotations[column].value-min) / range) * graphHeight); g.drawLine(x-av.charWidth/2, y1, x+av.charWidth/2, y2); x += av.charWidth; } @@ -1033,20 +990,35 @@ public class AnnotationPanel extends JPanel implements MouseListener, g.drawLine(x,y2,(eRes-sRes+1)*av.charWidth,y2); - eRes = Math.min(eRes, aa.annotations.length-1); + int column = sRes; + int yPos = sRes; + int aaMax = aa.annotations.length-1; - for (int j = sRes; j < eRes; j++) + while( yPos < eRes ) { + if(av.hasHiddenColumns) + { + column = av.getColumnSelection().adjustForHiddenColumns(yPos); + if(column > aaMax) + { + break; + } + } + else + column = yPos; + + yPos ++; - if (aa.annotations[j] == null) + if (aa.annotations[column] == null) { x += av.charWidth; continue; } - g.setColor(aa.annotations[j].colour); - y1 = y - (int) (((aa.annotations[j].value-min) / (range)) * aa.graphHeight); + + g.setColor(aa.annotations[column].colour); + y1 = y - (int) (((aa.annotations[column].value-min) / (range)) * aa.graphHeight); if(y1-y2>0) g.fillRect(x, y2, av.charWidth, y1-y2 );