2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.event.*;
22 import java.awt.font.LineMetrics;
23 import java.awt.geom.AffineTransform;
24 import java.awt.image.*;
25 import java.util.Hashtable;
29 import jalview.analysis.AAFrequency;
30 import jalview.datamodel.*;
31 import jalview.schemes.ColourSchemeI;
39 public class AnnotationPanel extends JPanel implements MouseListener,
40 MouseMotionListener, ActionListener, AdjustmentListener
42 final String HELIX = "Helix";
44 final String SHEET = "Sheet";
46 final String LABEL = "Label";
48 final String REMOVE = "Remove Annotation";
50 final String COLOUR = "Colour";
52 final Color HELIX_COLOUR = Color.red.darker();
54 final Color SHEET_COLOUR = Color.green.darker().darker();
65 BufferedImage fadedImage;
73 boolean fastPaint = false;
75 // Used For mouse Dragging and resizing graphs
76 int graphStretch = -1;
78 int graphStretchY = -1;
80 int min; // used by mouseDragged to see if user
82 int max; // used by mouseDragged to see if user
84 boolean mouseDragging = false;
89 * Creates a new AnnotationPanel object.
94 public AnnotationPanel(AlignmentPanel ap)
97 MAC = new jalview.util.Platform().isAMac();
99 ToolTipManager.sharedInstance().registerComponent(this);
100 ToolTipManager.sharedInstance().setInitialDelay(0);
101 ToolTipManager.sharedInstance().setDismissDelay(10000);
104 this.setLayout(null);
105 addMouseListener(this);
106 addMouseMotionListener(this);
107 ap.annotationScroller.getVerticalScrollBar()
108 .addAdjustmentListener(this);
111 public AnnotationPanel(AlignViewport av)
122 public void adjustmentValueChanged(AdjustmentEvent evt)
124 ap.alabels.setScrollOffset(-evt.getValue());
128 * Calculates the height of the annotation displayed in the annotation panel.
129 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
130 * all annotation associated components are updated correctly.
133 public int adjustPanelHeight()
135 int height=calcPanelHeight();
136 this.setPreferredSize(new Dimension(1, height));
139 // revalidate only when the alignment panel is fully constructed
147 * calculate the height for visible annotation, revalidating bounds where necessary
148 * ABSTRACT GUI METHOD
149 * @return total height of annotation
151 public int calcPanelHeight()
153 // setHeight of panels
154 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
159 for (int i = 0; i < aa.length; i++)
163 System.err.println("Null annotation row: ignoring.");
175 aa[i].height += av.charHeight;
185 aa[i].height += aa[i].graphHeight;
188 if (aa[i].height == 0)
193 height += aa[i].height;
210 public void actionPerformed(ActionEvent evt)
212 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
217 Annotation[] anot = aa[activeRow].annotations;
219 if (anot.length < av.getColumnSelection().getMax())
221 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
222 System.arraycopy(anot, 0, temp, 0, anot.length);
224 aa[activeRow].annotations = anot;
227 if (evt.getActionCommand().equals(REMOVE))
229 for (int i = 0; i < av.getColumnSelection().size(); i++)
231 anot[av.getColumnSelection().columnAt(i)] = null;
234 else if (evt.getActionCommand().equals(LABEL))
236 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
237 String label = JOptionPane.showInputDialog(this, "Enter label",
245 if ((label.length() > 0) && !aa[activeRow].hasText)
247 aa[activeRow].hasText = true;
250 for (int i = 0; i < av.getColumnSelection().size(); i++)
252 int index = av.getColumnSelection().columnAt(i);
254 if (!av.colSel.isVisible(index))
257 if (anot[index] == null)
259 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
266 anot[index].displayCharacter = label;
270 else if (evt.getActionCommand().equals(COLOUR))
272 Color col = JColorChooser.showDialog(this,
273 "Choose foreground colour", Color.black);
275 for (int i = 0; i < av.getColumnSelection().size(); i++)
277 int index = av.getColumnSelection().columnAt(i);
279 if (!av.colSel.isVisible(index))
282 if (anot[index] == null)
284 anot[index] = new Annotation("", "", ' ', 0);
287 anot[index].colour = col;
294 String symbol = "\u03B1";
296 if (evt.getActionCommand().equals(HELIX))
300 else if (evt.getActionCommand().equals(SHEET))
306 if (!aa[activeRow].hasIcons)
308 aa[activeRow].hasIcons = true;
311 String label = JOptionPane.showInputDialog(
312 "Enter a label for the structure?", symbol);
319 if ((label.length() > 0) && !aa[activeRow].hasText)
321 aa[activeRow].hasText = true;
324 for (int i = 0; i < av.getColumnSelection().size(); i++)
326 int index = av.getColumnSelection().columnAt(i);
328 if (!av.colSel.isVisible(index))
331 if (anot[index] == null)
333 anot[index] = new Annotation(label, "", type, 0);
336 anot[index].secondaryStructure = type;
337 anot[index].displayCharacter = label;
347 private String collectAnnotVals(Annotation[] anot,
348 ColumnSelection columnSelection, String label2)
350 String collatedInput = "";
352 for (int i = 0; i < columnSelection.size(); i++)
354 int index = columnSelection.columnAt(i);
355 // always check for current display state - just in case
356 if (!av.colSel.isVisible(index))
358 String tlabel = null;
359 if (anot[index] != null)
361 if (label2.equals(HELIX) || label2.equals(SHEET)
362 || label2.equals(LABEL))
364 tlabel = anot[index].description;
365 if (tlabel == null || tlabel.length() < 1)
367 if (label2.equals(HELIX) || label2.equals(SHEET))
369 tlabel = "" + anot[index].secondaryStructure;
373 tlabel = "" + anot[index].displayCharacter;
377 if (tlabel != null && !tlabel.equals(last))
379 if (last.length() > 0)
381 collatedInput += " ";
383 collatedInput += tlabel;
387 return collatedInput;
396 public void mousePressed(MouseEvent evt)
399 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
408 for (int i = 0; i < aa.length; i++)
412 height += aa[i].height;
415 if (evt.getY() < height)
421 else if (aa[i].graph > 0)
425 graphStretchY = evt.getY();
432 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
434 if (av.getColumnSelection() == null)
439 JPopupMenu pop = new JPopupMenu("Structure type");
440 JMenuItem item = new JMenuItem(HELIX);
441 item.addActionListener(this);
443 item = new JMenuItem(SHEET);
444 item.addActionListener(this);
446 item = new JMenuItem(LABEL);
447 item.addActionListener(this);
449 item = new JMenuItem(COLOUR);
450 item.addActionListener(this);
452 item = new JMenuItem(REMOVE);
453 item.addActionListener(this);
455 pop.show(this, evt.getX(), evt.getY());
465 ap.scalePanel.mousePressed(evt);
475 public void mouseReleased(MouseEvent evt)
479 mouseDragging = false;
480 ap.scalePanel.mouseReleased(evt);
489 public void mouseEntered(MouseEvent evt)
491 ap.scalePanel.mouseEntered(evt);
500 public void mouseExited(MouseEvent evt)
502 ap.scalePanel.mouseExited(evt);
511 public void mouseDragged(MouseEvent evt)
513 if (graphStretch > -1)
515 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
517 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
519 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
521 graphStretchY = evt.getY();
523 ap.paintAlignment(true);
527 ap.scalePanel.mouseDragged(evt);
537 public void mouseMoved(MouseEvent evt)
539 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
543 this.setToolTipText(null);
550 for (int i = 0; i < aa.length; i++)
554 height += aa[i].height;
557 if (evt.getY() < height)
567 this.setToolTipText(null);
571 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
573 if (av.hasHiddenColumns)
575 res = av.getColumnSelection().adjustForHiddenColumns(res);
578 if (row > -1 && aa[row].annotations != null
579 && res < (int) aa[row].annotations.length)
581 if (aa[row].graphGroup > -1)
583 StringBuffer tip = new StringBuffer("<html>");
584 for (int gg = 0; gg < aa.length; gg++)
586 if (aa[gg].graphGroup == aa[row].graphGroup
587 && aa[gg].annotations[res] != null)
589 tip.append(aa[gg].label + " "
590 + aa[gg].annotations[res].description + "<br>");
593 if (tip.length() != 6)
595 tip.setLength(tip.length() - 4);
596 this.setToolTipText(tip.toString() + "</html>");
599 else if (aa[row].annotations[res] != null
600 && aa[row].annotations[res].description != null
601 && aa[row].annotations[res].description.length() > 0)
603 this.setToolTipText(aa[row].annotations[res].description);
607 // clear the tooltip.
608 this.setToolTipText(null);
611 if (aa[row].annotations[res] != null)
613 StringBuffer text = new StringBuffer("Sequence position "
616 if (aa[row].annotations[res].description != null)
618 text.append(" " + aa[row].annotations[res].description);
621 ap.alignFrame.statusBar.setText(text.toString());
626 this.setToolTipText(null);
636 public void mouseClicked(MouseEvent evt)
646 public void paintComponent(Graphics g)
648 g.setColor(Color.white);
649 g.fillRect(0, 0, getWidth(), getHeight());
653 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
654 || (getVisibleRect().height != g.getClipBounds().height))
656 g.drawImage(image, 0, 0, this);
661 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
664 if (image == null || imgWidth != image.getWidth()
665 || image.getHeight(this) != getHeight())
667 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
668 BufferedImage.TYPE_INT_RGB);
669 gg = (Graphics2D) image.getGraphics();
673 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
674 RenderingHints.VALUE_ANTIALIAS_ON);
677 gg.setFont(av.getFont());
678 fm = gg.getFontMetrics();
679 gg.setColor(Color.white);
680 gg.fillRect(0, 0, imgWidth, image.getHeight());
683 drawComponent(gg, av.startRes, av.endRes + 1);
684 g.drawImage(image, 0, 0, this);
688 * non-Thread safe repaint
691 * repaint with horizontal shift in alignment
693 public void fastPaint(int horizontal)
696 if ((horizontal == 0) || gg == null
697 || av.alignment.getAlignmentAnnotation() == null
698 || av.alignment.getAlignmentAnnotation().length < 1
699 || av.updatingConsensus || av.updatingConservation)
704 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
706 int sr = av.startRes;
707 int er = av.endRes + 1;
710 if (horizontal > 0) // scrollbar pulled right, image to the left
712 transX = (er - sr - horizontal) * av.charWidth;
713 sr = er - horizontal;
715 else if (horizontal < 0)
717 er = sr - horizontal;
720 gg.translate(transX, 0);
722 drawComponent(gg, sr, er);
724 gg.translate(-transX, 0);
741 public void drawComponent(Graphics g, int startRes, int endRes)
743 if (av.updatingConsensus || av.updatingConservation)
749 // We'll keep a record of the old image,
750 // and draw a faded image until the calculation
752 if (fadedImage == null || fadedImage.getWidth() != imgWidth
753 || fadedImage.getHeight() != image.getHeight())
755 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
756 BufferedImage.TYPE_INT_RGB);
758 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
760 fadedG.setColor(Color.white);
761 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
763 fadedG.setComposite(AlphaComposite.getInstance(
764 AlphaComposite.SRC_OVER, .3f));
765 fadedG.drawImage(image, 0, 0, this);
775 g.setColor(Color.white);
776 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
778 g.setFont(av.getFont());
781 fm = g.getFontMetrics();
784 if ((av.alignment.getAlignmentAnnotation() == null)
785 || (av.alignment.getAlignmentAnnotation().length < 1))
787 g.setColor(Color.white);
788 g.fillRect(0, 0, getWidth(), getHeight());
789 g.setColor(Color.black);
790 if (av.validCharWidth)
792 g.drawString("Alignment has no annotations", 20, 15);
798 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
805 boolean validRes = false;
806 boolean validEnd = false;
807 boolean labelAllCols = false;
808 boolean centreColLabels, centreColLabelsDef = av
809 .getCentreColumnLabels();
810 boolean scaleColLabel = false;
811 boolean[] graphGroupDrawn = new boolean[aa.length];
812 int charOffset = 0; // offset for a label
813 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
815 Font ofont = g.getFont();
817 for (int i = 0; i < aa.length; i++)
819 AlignmentAnnotation row = aa[i];
825 centreColLabels = row.centreColLabels || centreColLabelsDef;
826 labelAllCols = row.showAllColLabels;
827 scaleColLabel = row.scaleColLabel;
833 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
838 // this is so that we draw the characters below the graph
843 iconOffset = av.charHeight - fm.getDescent();
847 else if (row.hasText)
849 iconOffset = av.charHeight - fm.getDescent();
857 if (av.updatingConsensus && aa[i] == av.consensus)
861 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
862 - row.height, imgWidth, y, this);
863 g.setColor(Color.black);
864 // g.drawString("Calculating Consensus....",20, y-row.height/2);
868 else if (av.updatingConservation
869 && aa[i].label.equals("Conservation"))
873 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
874 - row.height, imgWidth, y, this);
876 g.setColor(Color.black);
877 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
881 else if (av.updatingConservation && aa[i].label.equals("Quality"))
885 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
886 - row.height, imgWidth, y, this);
887 g.setColor(Color.black);
888 // / g.drawString("Calculating Quality....",20, y-row.height/2);
894 while (x < endRes - startRes)
896 if (av.hasHiddenColumns)
898 column = av.getColumnSelection().adjustForHiddenColumns(
900 if (column > row.annotations.length - 1)
907 column = startRes + x;
910 if ((row.annotations == null) || (row.annotations.length <= column)
911 || (row.annotations[column] == null))
922 g.setColor(Color.red);
924 if (av.getColumnSelection() != null)
926 for (int n = 0; n < av.getColumnSelection().size(); n++)
928 int v = av.getColumnSelection().columnAt(n);
932 g.fillRect(x * av.charWidth, y, av.charWidth, av.charHeight);
938 if (av.validCharWidth && validRes
939 && row.annotations[column].displayCharacter != null
940 && (row.annotations[column].displayCharacter.length() > 0))
943 if (centreColLabels || scaleColLabel)
945 fmWidth = (float) fm.charsWidth(
946 row.annotations[column].displayCharacter.toCharArray(),
947 0, row.annotations[column].displayCharacter.length());
951 // justify the label and scale to fit in column
952 if (fmWidth > av.charWidth)
954 // scale only if the current font isn't already small enough
955 fmScaling = av.charWidth;
956 fmScaling /= fmWidth;
957 g.setFont(ofont.deriveFont(AffineTransform
958 .getScaleInstance(fmScaling, 1.0)));
959 // and update the label's width to reflect the scaling.
960 fmWidth = av.charWidth;
967 .charWidth(row.annotations[column].displayCharacter
970 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
972 if (row.annotations[column].colour == null)
973 g.setColor(Color.black);
975 g.setColor(row.annotations[column].colour);
977 if (column == 0 || row.graph > 0)
979 g.drawString(row.annotations[column].displayCharacter,
980 (x * av.charWidth) + charOffset, y + iconOffset);
982 else if (row.annotations[column - 1] == null
984 || !row.annotations[column].displayCharacter
985 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
986 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
988 g.drawString(row.annotations[column].displayCharacter, x
989 * av.charWidth + charOffset, y + iconOffset);
997 || (row.annotations[column].secondaryStructure != lastSS))
1002 g.setColor(HELIX_COLOUR);
1005 // Off by 1 offset when drawing rects and ovals
1006 // to offscreen image on the MAC
1007 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
1008 (x * av.charWidth) - lastSSX, 7, 8, 8);
1012 int sCol = (lastSSX / av.charWidth) + startRes;
1014 int x2 = (x * av.charWidth);
1017 || row.annotations[sCol - 1] == null
1018 || row.annotations[sCol - 1].secondaryStructure != 'H')
1020 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
1022 x1 += av.charWidth / 2;
1025 if (!validRes || row.annotations[column] == null
1026 || row.annotations[column].secondaryStructure != 'H')
1028 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1029 + iconOffset, av.charWidth, 8, 270, 180);
1030 x2 -= av.charWidth / 2;
1033 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1037 g.setColor(SHEET_COLOUR);
1038 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1040 g.fillPolygon(new int[]
1041 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1042 (x * av.charWidth) }, new int[]
1043 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1049 g.setColor(Color.gray);
1050 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1058 lastSS = row.annotations[column].secondaryStructure;
1065 lastSSX = (x * av.charWidth);
1073 if (column >= row.annotations.length)
1075 column = row.annotations.length - 1;
1090 g.setColor(HELIX_COLOUR);
1093 // Off by 1 offset when drawing rects and ovals
1094 // to offscreen image on the MAC
1095 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1096 - lastSSX, 7, 8, 8);
1100 int sCol = (lastSSX / av.charWidth) + startRes;
1102 int x2 = (x * av.charWidth);
1104 if (sCol == 0 || row.annotations[sCol - 1] == null
1105 || row.annotations[sCol - 1].secondaryStructure != 'H')
1107 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
1108 x1 += av.charWidth / 2;
1111 if (row.annotations[column] == null
1112 || row.annotations[column].secondaryStructure != 'H')
1114 g.fillArc((x * av.charWidth) - av.charWidth,
1115 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1116 x2 -= av.charWidth / 2;
1119 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1124 g.setColor(SHEET_COLOUR);
1126 if (!validEnd || row.annotations[endRes] == null
1127 || row.annotations[endRes].secondaryStructure != 'E')
1129 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1131 g.fillPolygon(new int[]
1132 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1133 (x * av.charWidth) }, new int[]
1134 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1138 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1144 g.setColor(Color.gray);
1145 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1152 if (row.graph > 0 && row.graphHeight > 0)
1154 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1156 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1158 float groupmax = -999999, groupmin = 9999999;
1159 for (int gg = 0; gg < aa.length; gg++)
1161 if (aa[gg].graphGroup != row.graphGroup)
1168 aa[gg].visible = false;
1171 if (aa[gg].graphMax > groupmax)
1173 groupmax = aa[gg].graphMax;
1175 if (aa[gg].graphMin < groupmin)
1177 groupmin = aa[gg].graphMin;
1181 for (int gg = 0; gg < aa.length; gg++)
1183 if (aa[gg].graphGroup == row.graphGroup)
1185 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1186 groupmax, row.graphHeight);
1190 graphGroupDrawn[row.graphGroup] = true;
1194 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1195 row.graphMax, row.graphHeight);
1198 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1200 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1205 if (row.graph > 0 && row.hasText)
1217 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1218 int eRes, int y, float min, float max, int graphHeight)
1220 if (sRes > aa.annotations.length)
1227 // Adjustment for fastpaint to left
1228 if (eRes < av.endRes)
1233 eRes = Math.min(eRes, aa.annotations.length);
1241 float range = max - min;
1246 y2 = y - (int) ((0 - min / range) * graphHeight);
1249 g.setColor(Color.gray);
1250 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1252 eRes = Math.min(eRes, aa.annotations.length);
1255 int aaMax = aa.annotations.length - 1;
1257 while (x < eRes - sRes)
1260 if (av.hasHiddenColumns)
1262 column = av.getColumnSelection().adjustForHiddenColumns(column);
1270 if (aa.annotations[column] == null
1271 || aa.annotations[column - 1] == null)
1277 if (aa.annotations[column].colour == null)
1278 g.setColor(Color.black);
1280 g.setColor(aa.annotations[column].colour);
1283 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1285 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1287 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1288 + av.charWidth / 2, y2);
1292 if (aa.threshold != null)
1294 g.setColor(aa.threshold.colour);
1295 Graphics2D g2 = (Graphics2D) g;
1296 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1297 BasicStroke.JOIN_ROUND, 3f, new float[]
1300 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1301 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1302 g2.setStroke(new BasicStroke());
1306 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1307 int eRes, float min, float max, int y)
1309 ColourSchemeI profcolour = av.getGlobalColourScheme();
1310 if (profcolour == null)
1312 profcolour = new jalview.schemes.ZappoColourScheme();
1314 if (sRes > aa.annotations.length)
1318 Font ofont = g.getFont();
1319 eRes = Math.min(eRes, aa.annotations.length);
1321 int x = 0, y1 = y, y2 = y;
1323 float range = max - min;
1327 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1330 g.setColor(Color.gray);
1332 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1335 int aaMax = aa.annotations.length - 1;
1336 boolean renderHistogram = true, renderProfile = true;
1337 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1339 // TODO: generalise this to have render styles for consensus/profile data
1340 if (aa.groupRef != null)
1342 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1343 renderProfile = aa.groupRef.isShowSequenceLogo();
1347 renderHistogram = av.isShowConsensusHistogram();
1348 renderProfile = av.isShowSequenceLogo();
1351 while (x < eRes - sRes)
1354 if (av.hasHiddenColumns)
1356 column = av.getColumnSelection().adjustForHiddenColumns(column);
1364 if (aa.annotations[column] == null)
1369 if (aa.annotations[column].colour == null)
1370 g.setColor(Color.black);
1372 g.setColor(aa.annotations[column].colour);
1375 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1377 if (renderHistogram)
1381 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1385 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1388 // draw profile if available
1389 if (renderProfile && aa.annotations[column].value != 0)
1391 int profl[] = getProfileFor(aa, column);
1392 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1395 char[] dc = new char[1];
1397 for (int c = 1; profl != null && c < profl[0];)
1399 dc[0] = (char) profl[c++];
1400 wdth = av.charWidth;
1401 wdth /= (float) fm.charsWidth(dc, 0, 1);
1408 // if (aa.annotations[column].value==0) {
1409 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1410 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1411 // ht = y2-(int)ht2;
1413 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1414 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1416 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1419 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1420 // ? );// try to get a
1421 // colourscheme for the
1422 // group(aa.groupRef.cs==null)
1423 // ? av.textColour2 :
1424 // cs.findColour(dc));
1425 g.drawChars(dc, 0, 1, x * av.charWidth,
1426 (int) (ht + lm.getHeight()));
1427 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1434 if (aa.threshold != null)
1436 g.setColor(aa.threshold.colour);
1437 Graphics2D g2 = (Graphics2D) g;
1438 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1439 BasicStroke.JOIN_ROUND, 3f, new float[]
1442 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1443 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1444 g2.setStroke(new BasicStroke());
1448 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1450 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1452 if (aa.groupRef != null && aa.groupRef.consensusData != null
1453 && aa.groupRef.isShowSequenceLogo())
1455 return AAFrequency.extractProfile(
1456 aa.groupRef.consensusData[column],
1457 aa.groupRef.getIgnoreGapsConsensus());
1459 // TODO extend annotation row to enable dynamic and static profile data to
1461 if (aa.groupRef == null && aa.sequenceRef == null
1462 && av.isShowSequenceLogo())
1464 return AAFrequency.extractProfile(av.hconsensus[column],
1465 av.getIgnoreGapsConsensus());
1471 // used by overview window
1472 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1473 int y, int sRes, int eRes)
1475 eRes = Math.min(eRes, aa.annotations.length);
1476 g.setColor(Color.white);
1477 g.fillRect(0, 0, width, y);
1478 g.setColor(new Color(0, 0, 180));
1482 for (int j = sRes; j < eRes; j++)
1484 if (aa.annotations[j] != null)
1486 if (aa.annotations[j].colour == null)
1487 g.setColor(Color.black);
1489 g.setColor(aa.annotations[j].colour);
1491 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1497 g.fillRect(x, y - height, av.charWidth, height);