X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAnnotationPanel.java;h=69ae398c406fd127a84ca284ecbf4c82fc7ffbd0;hb=9a4258bfc6277f67d677ce0e62f6ffd6bcc3d436;hp=9bbcc244a670fafb2158d0e714db08ef4e0e0917;hpb=ce728f87f1f43be3041ef02f7f2cc2e39314711a;p=jalview.git diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 9bbcc24..69ae398 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -38,16 +38,15 @@ import javax.swing.*; public class AnnotationPanel extends JPanel implements MouseListener, MouseMotionListener, ActionListener, AdjustmentListener { - static String HELIX = "Helix"; - static String SHEET = "Sheet"; - static String LABEL = "Label"; - static String REMOVE = "Remove Annotation"; - static String COLOUR = "Colour"; - static Color HELIX_COLOUR = Color.red.darker(); - static Color SHEET_COLOUR = Color.green.darker().darker(); + final String HELIX = "Helix"; + final String SHEET = "Sheet"; + final String LABEL = "Label"; + final String REMOVE = "Remove Annotation"; + final String COLOUR = "Colour"; + final Color HELIX_COLOUR = Color.red.darker(); + final Color SHEET_COLOUR = Color.green.darker().darker(); /** DOCUMENT ME!! */ - public static int GRAPH_HEIGHT = 40; AlignViewport av; AlignmentPanel ap; int activeRow = -1; @@ -58,6 +57,10 @@ public class AnnotationPanel extends JPanel implements MouseListener, int imgWidth = 0; boolean fastPaint = false; + //Used For mouse Dragging and resizing graphs + int graphStretch = -1; + int graphStretchY = -1; + /** * Creates a new AnnotationPanel object. * @@ -123,9 +126,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, aa[i].height += 16; } - if (aa[i].isGraph) + if (aa[i].graph>0) { - aa[i].height += GRAPH_HEIGHT; + aa[i].height += aa[i].graphHeight; } if (aa[i].height == 0) @@ -342,6 +345,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, activeRow = -1; AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if(aa==null) + return; for (int i = 0; i < aa.length; i++) { @@ -356,6 +361,13 @@ public class AnnotationPanel extends JPanel implements MouseListener, { activeRow = i; } + else if(aa[i].graph>0) + { + //Stretch Graph + graphStretch = i; + graphStretchY = evt.getY(); + activeRes = null; + } else { activeRes = null; @@ -434,8 +446,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, activeRes = new Vector(); activeRes.addElement(String.valueOf(res)); } - - repaint(); } /** @@ -445,6 +455,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void mouseReleased(MouseEvent evt) { + graphStretch = -1; + graphStretchY = -1; } /** @@ -472,6 +484,15 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void mouseDragged(MouseEvent evt) { + if(graphStretch>-1) + { + av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY - evt.getY(); + if(av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight <10) + av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 10; + graphStretchY = evt.getY(); + adjustPanelHeight(); + ap.repaint(); + } } /** @@ -508,14 +529,33 @@ public class AnnotationPanel extends JPanel implements MouseListener, int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - if ((row > -1) && (res < aa[row].annotations.length) && - (aa[row].annotations[res] != null)) + if (row > -1 && res-1) + { + StringBuffer tip = new StringBuffer(""); + for (int gg = 0; gg < aa.length; gg++) + { + if (aa[gg].graphGroup == aa[row].graphGroup && aa[gg].annotations[res]!=null) + tip.append(aa[gg].label+" "+aa[gg].annotations[res].description+"
" ); + } + if(tip.length()!=6) + { + tip.setLength(tip.length() - 4); + this.setToolTipText(tip.toString() + ""); + } + } + else if(aa[row].annotations[res] != null) + this.setToolTipText(aa[row].annotations[res].description); - StringBuffer text = new StringBuffer("Sequence position " + - (res + 1) + " " + aa[row].annotations[res].description); - ap.alignFrame.statusBar.setText(text.toString()); + if(aa[row].annotations[res]!=null) + { + StringBuffer text = new StringBuffer("Sequence position " + + (res + 1) + " " + + aa[row].annotations[res].description); + + ap.alignFrame.statusBar.setText(text.toString()); + } } } @@ -538,20 +578,26 @@ public class AnnotationPanel extends JPanel implements MouseListener, g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); - if (fastPaint && image!=null) - { - g.drawImage(image, 0, 0, this); - fastPaint = false; - return; + if(image!=null) + {if (fastPaint + || (getVisibleRect().width != g.getClipBounds().width) + || (getVisibleRect().height != g.getClipBounds().height)) + { + g.drawImage(image, 0, 0, this); + fastPaint = false; + return; + } } - imgWidth = (av.endRes - av.startRes + 1) * av.charWidth; - if (image == null || imgWidth != image.getWidth()) + if (image == null || imgWidth != image.getWidth() + || image.getHeight(this) != getHeight()) { image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(), BufferedImage.TYPE_INT_RGB); gg = (Graphics2D) image.getGraphics(); + + if(av.antiAlias) gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -559,6 +605,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, fm = gg.getFontMetrics(); } + drawComponent(gg, av.startRes, av.endRes + 1); g.drawImage(image, 0, 0, this); } @@ -570,12 +617,11 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void fastPaint(int horizontal) { - if ((horizontal == 0) || + if ((horizontal == 0) || gg==null || (av.alignment.getAlignmentAnnotation() == null) || (av.alignment.getAlignmentAnnotation().length < 1)) { repaint(); - return; } @@ -614,13 +660,13 @@ public class AnnotationPanel extends JPanel implements MouseListener, * @param startRes DOCUMENT ME! * @param endRes DOCUMENT ME! */ - public void drawComponent(Graphics2D g, int startRes, int endRes) + public void drawComponent(Graphics g, int startRes, int endRes) { + g.setFont(av.getFont()); + if (fm == null) fm = g.getFontMetrics(); - if(fm==null) - fm = g.getFontMetrics(); g.setColor(Color.white); g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); @@ -646,6 +692,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, int iconOffset = av.charHeight / 2; boolean validRes = false; + boolean [] graphGroupDrawn = new boolean[aa.length]; + + //\u03B2 \u03B1 for (int i = 0; i < aa.length; i++) { @@ -657,8 +706,12 @@ public class AnnotationPanel extends JPanel implements MouseListener, } - if (row.isGraph) + + if (row.graph>0) { + if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] ) + continue; + // this is so that we draw the characters below the graph y += row.height; @@ -719,7 +772,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, 0))) / 2; g.setColor(row.annotations[j].colour); - if (j == 0 || row.isGraph) + if (j == 0 || row.graph>0) { g.drawString(row.annotations[j].displayCharacter, x+charOffset, y + iconOffset + 3); @@ -760,8 +813,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, break; - case 'C': - break; default: g.setColor(Color.gray); @@ -783,35 +834,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, lastSSX[i] = x; } } - - if (validRes && row.isGraph) - { - g.setColor(new Color(0, 0, 180)); - - int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); - - if (row.windowLength > 1) - { - int total = 0; - - for (int i2 = j - (row.windowLength / 2); - i2 < (j + (row.windowLength / 2)); i2++) - { - if ((i2 < 0) || (i2 >= av.alignment.getWidth())) - { - continue; - } - - total += row.annotations[i2].value; - } - - total /= row.windowLength; - height = (int) ((total / row.graphMax) * GRAPH_HEIGHT); - } - - g.setColor(row.annotations[j].colour); - g.fillRect(x, y - height, av.charWidth, height); - } } x += av.charWidth; @@ -829,14 +851,23 @@ public class AnnotationPanel extends JPanel implements MouseListener, case 'E': g.setColor(SHEET_COLOUR); - g.fillRect(lastSSX[i], y + 4 + iconOffset, - x - lastSSX[i] - 4, 7); - g.fillPolygon(new int[] { x - 4, x - 4, x }, - new int[] - { - y + iconOffset, y + 14 + iconOffset, - y + 7 + iconOffset - }, 3); + + if (row.annotations[endRes] !=null + && row.annotations[endRes].secondaryStructure != 'E') + { + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] + {x - 4, x - 4, x}, + new int[] + { + y + iconOffset, y + 14 + iconOffset, + y + 7 + iconOffset + }, 3); + } + else + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7); break; @@ -851,38 +882,202 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - if (row.isGraph && row.hasText) + if (row.graph>0) + { + if(row.graph == AlignmentAnnotation.LINE_GRAPH ) + { + if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup]) + { + float groupmax=-999999, groupmin=9999999; + for(int gg=0; gggroupmax) + groupmax = aa[gg].graphMax; + if(aa[gg].graphMin0 && row.hasText) { y += av.charHeight; } - if (!row.isGraph) + if (row.graph==0) { y += aa[i].height; } } } - // used by overview window - public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes) + public void drawLineGraph(Graphics g, AlignmentAnnotation aa, + int sRes, int eRes, + int y, + float min, float max, + int graphHeight) { - g.setColor(Color.white); - g.fillRect(0, 0, width, y); - g.setColor(new Color(0, 0, 180)); + if(sRes>aa.annotations.length) + return; + + int x = 0; + + //Adjustment for fastpaint to left + if(eResy) - height = y; + public void drawBarGraph(Graphics g, AlignmentAnnotation aa, + int sRes, int eRes, + float min, float max, + int y) + { + if(sRes>aa.annotations.length) + return; - g.fillRect(x, y - height, av.charWidth, height); - x += av.charWidth; + int x=0, y1, y2; + + float range = max - min; + + if(aa.threshold!=null) + { + g.setColor(aa.threshold.colour); + Graphics2D g2 = (Graphics2D)g; + g2.setStroke(new BasicStroke(1, + BasicStroke.CAP_SQUARE, + BasicStroke.JOIN_ROUND, 3f, + new float[] { 5f, 3f }, 0f)); + + y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight); + g.drawLine(x-av.charWidth,y2,(eRes-sRes+1)*av.charWidth,y2); + g2.setStroke(new BasicStroke()); + } + + y1 = y2 = y; + + if(min<0) + y2 = (int)(y - (0-min / (range))*aa.graphHeight); + + g.setColor(Color.gray); + + g.drawLine(x,y2,(eRes-sRes+1)*av.charWidth,y2); + + eRes = Math.min(eRes, aa.annotations.length-1); + + + for (int j = sRes; j < eRes; j++) + { + + if (aa.annotations[j] == null) + { + x += av.charWidth; + continue; } + + g.setColor(aa.annotations[j].colour); + y1 = y - (int) (((aa.annotations[j].value-min) / (range)) * aa.graphHeight); + + if(y1-y2>0) + g.fillRect(x, y2, av.charWidth, y1-y2 ); + else + g.fillRect(x, y1, av.charWidth, y2-y1 ); + + x += av.charWidth; + } + } + + // used by overview window + public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes) + { + g.setColor(Color.white); + g.fillRect(0, 0, width, y); + g.setColor(new Color(0, 0, 180)); + + int x = 0, height; + + for (int j = sRes; j < eRes; j++) + { + g.setColor(aa.annotations[j].colour); + + height = (int) ((aa.annotations[j].value / aa.graphMax) * y); + if(height>y) + height = y; + + g.fillRect(x, y - height, av.charWidth, height); + x += av.charWidth; + } + } + }