From 3a45e0d68dde73c005832b7b3924194b214e00ff Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Mon, 30 Jan 2006 14:55:17 +0000 Subject: [PATCH] GraphGroups added --- src/jalview/gui/AnnotationLabels.java | 79 +++++++-- src/jalview/gui/AnnotationPanel.java | 307 ++++++++++++++++++++++++++------- 2 files changed, 311 insertions(+), 75 deletions(-) diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 560c983..7418e48 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -182,15 +182,8 @@ public class AnnotationLabels extends JPanel implements MouseListener, ap.annotationPanel.adjustPanelHeight(); - - Dimension d = ap.annotationScroller.getPreferredSize(); - ap.annotationScroller.setPreferredSize(new Dimension(d.width, - d.height + dif)); - d = ap.annotationSpaceFillerHolder.getPreferredSize(); - ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(d.width, - d.height + dif)); - - ap.addNotify(); + ap.annotationScroller.validate(); + ap.repaint(); } /** @@ -363,6 +356,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, width = ap.calculateIdWidth().width + 4; Graphics2D g2 = (Graphics2D) g; + if(av.antiAlias) g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -390,8 +384,11 @@ public class AnnotationLabels extends JPanel implements MouseListener, g.setColor(Color.black); AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - int y = g.getFont().getSize(); + int fontHeight = g.getFont().getSize(); + int y = fontHeight; int x = 0; + int graphExtras = 0; + if (aa != null) @@ -407,13 +404,71 @@ public class AnnotationLabels extends JPanel implements MouseListener, if (aa[i].graph>0) { + graphExtras = y; + y += (aa[i].height / 3); + + if(aa[i].graphGroup<0) + graphExtras = y + fontHeight; } - g.drawString(aa[i].label, x, y); + if(aa[i].graphGroup>-1) + { + int groupSize = 0; + for (int gg = 0; gg < aa.length; gg++) + { + if (aa[gg].graphGroup == aa[i].graphGroup) + groupSize++; + } + + if(groupSize * (fontHeight+8) < aa[i].height) + graphExtras += (aa[i].height -( groupSize * (fontHeight+8)) )/2; + + for(int gg=0; gg0) { + if (aa[i].graphLines != null) + { + for (int gl = 0; gl < aa[i].graphLines.size(); gl++) + { + x = width - fm.stringWidth(aa[i].getGraphLine(gl).label) - 3; + g.drawString(aa[i].getGraphLine(gl).label, x, graphExtras); + g.setColor(aa[i].getGraphLine(gl).colour); + Graphics2D g2 = (Graphics2D) g; + g2.setStroke(new BasicStroke(1, + BasicStroke.CAP_SQUARE, + BasicStroke.JOIN_ROUND, 3f, + new float[] + {5f, 3f}, 0f)); + + graphExtras += 3; + + g.drawLine(x, graphExtras, + x+fm.stringWidth(aa[i].label), + graphExtras); + g2.setStroke(new BasicStroke()); + } + } y += ((2 * aa[i].height) / 3); } else @@ -427,7 +482,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, { if (image != null) { - g.drawImage(image, 2, 0, this); + g.drawImage(image, 2, 0 - scrollOffset, this); } } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 8f72f71..3a4a197 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. * @@ -125,7 +128,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, 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,23 @@ public class AnnotationPanel extends JPanel implements MouseListener, { activeRow = i; } + else if(aa[i].graph>0) + { + if(SwingUtilities.isRightMouseButton(evt) + && aa[i].graphLines!=null + && aa[i].graphLines.size()>0) + { + SliderPanel sp = new SliderPanel(aa[i], ap); + return; + } + else + { + //Stretch Graph + graphStretch = i; + graphStretchY = evt.getY(); + activeRes = null; + } + } else { activeRes = null; @@ -434,8 +456,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, activeRes = new Vector(); activeRes.addElement(String.valueOf(res)); } - - repaint(); } /** @@ -445,6 +465,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void mouseReleased(MouseEvent evt) { + graphStretch = -1; + graphStretchY = -1; } /** @@ -472,6 +494,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(); + } } /** @@ -511,7 +542,21 @@ public class AnnotationPanel extends JPanel implements MouseListener, if ((row > -1) && (res < aa[row].annotations.length) && (aa[row].annotations[res] != null)) { - this.setToolTipText(aa[row].annotations[res].description); + + + if(aa[row].graphGroup>-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+"
" ); + } + tip.setLength(tip.length()-4); + this.setToolTipText(tip.toString()+""); + } + else + this.setToolTipText(aa[row].annotations[res].description); StringBuffer text = new StringBuffer("Sequence position " + (res + 1) + " " + aa[row].annotations[res].description); @@ -538,20 +583,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 +610,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, fm = gg.getFontMetrics(); } + drawComponent(gg, av.startRes, av.endRes + 1); g.drawImage(image, 0, 0, this); } @@ -575,7 +627,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, (av.alignment.getAlignmentAnnotation().length < 1)) { repaint(); - return; } @@ -646,6 +697,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++) { @@ -659,6 +713,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, 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; @@ -760,8 +817,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, break; - case 'C': - break; default: g.setColor(Color.gray); @@ -783,21 +838,6 @@ public class AnnotationPanel extends JPanel implements MouseListener, lastSSX[i] = x; } } - - if (validRes && row.graph>0) - { - ///g.setColor(new Color(0, 0, 180)); - - if(row.graph== AlignmentAnnotation.LINE_GRAPH ) - drawLineGraph(g, row, j, j+1, x, y); - else if(row.graph == AlignmentAnnotation.BAR_GRAPH ) - drawBarGraph(g, row, j, j+1, x, y); - - //int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); - - // g.setColor(row.annotations[j].colour); - // g.fillRect(x, y - height, av.charWidth, height); - } } x += av.charWidth; @@ -815,14 +855,22 @@ 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].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; @@ -837,6 +885,48 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } + 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; @@ -849,39 +939,130 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes, int eRes, int x, int y) + public void drawLineGraph(Graphics g, AlignmentAnnotation aa, + int sRes, int eRes, + int y, + float min, float max, + int graphHeight) { - g.setColor(new Color(0, 0, 0)); + if(sRes>aa.annotations.length) + return; + + int x = 0; + + //Adjustment for fastpaint to left + if(eResaa.annotations.length) + return; + + int x=0, y1, y2; + + float range = max - min; + + if(aa.graphLines!=null) { - g.setColor(aa.annotations[j].colour); - height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); + for(int l=0; l0) + g.fillRect(x, y2, av.charWidth, y1-y2 ); + else + g.fillRect(x, y1, av.charWidth, y2-y1 ); + + x += av.charWidth; + } + } // used by overview window @@ -895,7 +1076,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, for (int j = sRes; j < eRes; j++) { - g.setColor(new Color(0, 0, 180)); + g.setColor(aa.annotations[j].colour); height = (int) ((aa.annotations[j].value / aa.graphMax) * y); if(height>y) -- 1.7.10.2