2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
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 // setHeight of panels
136 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
141 for (int i = 0; i < aa.length; i++)
145 System.err.println("Null annotation row: ignoring.");
157 aa[i].height += av.charHeight;
167 aa[i].height += aa[i].graphHeight;
170 if (aa[i].height == 0)
175 height += aa[i].height;
183 this.setPreferredSize(new Dimension(1, height));
186 // revalidate only when the alignment panel is fully constructed
199 public void actionPerformed(ActionEvent evt)
201 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
202 Annotation[] anot = aa[activeRow].annotations;
204 if (anot.length < av.getColumnSelection().getMax())
206 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
207 System.arraycopy(anot, 0, temp, 0, anot.length);
209 aa[activeRow].annotations = anot;
212 if (evt.getActionCommand().equals(REMOVE))
214 for (int i = 0; i < av.getColumnSelection().size(); i++)
216 anot[av.getColumnSelection().columnAt(i)] = null;
219 else if (evt.getActionCommand().equals(LABEL))
221 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
222 String label = JOptionPane.showInputDialog(this, "Enter label",
230 if ((label.length() > 0) && !aa[activeRow].hasText)
232 aa[activeRow].hasText = true;
235 for (int i = 0; i < av.getColumnSelection().size(); i++)
237 int index = av.getColumnSelection().columnAt(i);
239 if (!av.colSel.isVisible(index))
242 if (anot[index] == null)
244 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
251 anot[index].displayCharacter = label;
255 else if (evt.getActionCommand().equals(COLOUR))
257 Color col = JColorChooser.showDialog(this,
258 "Choose foreground colour", Color.black);
260 for (int i = 0; i < av.getColumnSelection().size(); i++)
262 int index = av.getColumnSelection().columnAt(i);
264 if (!av.colSel.isVisible(index))
267 if (anot[index] == null)
269 anot[index] = new Annotation("", "", ' ', 0);
272 anot[index].colour = col;
279 String symbol = "\u03B1";
281 if (evt.getActionCommand().equals(HELIX))
285 else if (evt.getActionCommand().equals(SHEET))
291 if (!aa[activeRow].hasIcons)
293 aa[activeRow].hasIcons = true;
296 String label = JOptionPane.showInputDialog(
297 "Enter a label for the structure?", symbol);
304 if ((label.length() > 0) && !aa[activeRow].hasText)
306 aa[activeRow].hasText = true;
309 for (int i = 0; i < av.getColumnSelection().size(); i++)
311 int index = av.getColumnSelection().columnAt(i);
313 if (!av.colSel.isVisible(index))
316 if (anot[index] == null)
318 anot[index] = new Annotation(label, "", type, 0);
321 anot[index].secondaryStructure = type;
322 anot[index].displayCharacter = label;
332 private String collectAnnotVals(Annotation[] anot,
333 ColumnSelection columnSelection, String label2)
335 String collatedInput = "";
337 for (int i = 0; i < columnSelection.size(); i++)
339 int index = columnSelection.columnAt(i);
340 // always check for current display state - just in case
341 if (!av.colSel.isVisible(index))
343 String tlabel = null;
344 if (anot[index] != null)
346 if (label2.equals(HELIX) || label2.equals(SHEET)
347 || label2.equals(LABEL))
349 tlabel = anot[index].description;
350 if (tlabel == null || tlabel.length() < 1)
352 if (label2.equals(HELIX) || label2.equals(SHEET))
354 tlabel = "" + anot[index].secondaryStructure;
358 tlabel = "" + anot[index].displayCharacter;
362 if (tlabel != null && !tlabel.equals(last))
364 if (last.length() > 0)
366 collatedInput += " ";
368 collatedInput += tlabel;
372 return collatedInput;
381 public void mousePressed(MouseEvent evt)
384 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
393 for (int i = 0; i < aa.length; i++)
397 height += aa[i].height;
400 if (evt.getY() < height)
406 else if (aa[i].graph > 0)
410 graphStretchY = evt.getY();
417 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
419 if (av.getColumnSelection() == null)
424 JPopupMenu pop = new JPopupMenu("Structure type");
425 JMenuItem item = new JMenuItem(HELIX);
426 item.addActionListener(this);
428 item = new JMenuItem(SHEET);
429 item.addActionListener(this);
431 item = new JMenuItem(LABEL);
432 item.addActionListener(this);
434 item = new JMenuItem(COLOUR);
435 item.addActionListener(this);
437 item = new JMenuItem(REMOVE);
438 item.addActionListener(this);
440 pop.show(this, evt.getX(), evt.getY());
450 ap.scalePanel.mousePressed(evt);
460 public void mouseReleased(MouseEvent evt)
464 mouseDragging = false;
465 ap.scalePanel.mouseReleased(evt);
474 public void mouseEntered(MouseEvent evt)
476 ap.scalePanel.mouseEntered(evt);
485 public void mouseExited(MouseEvent evt)
487 ap.scalePanel.mouseExited(evt);
496 public void mouseDragged(MouseEvent evt)
498 if (graphStretch > -1)
500 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
502 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
504 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
506 graphStretchY = evt.getY();
508 ap.paintAlignment(true);
512 ap.scalePanel.mouseDragged(evt);
522 public void mouseMoved(MouseEvent evt)
524 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
528 this.setToolTipText(null);
535 for (int i = 0; i < aa.length; i++)
539 height += aa[i].height;
542 if (evt.getY() < height)
552 this.setToolTipText(null);
556 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
558 if (av.hasHiddenColumns)
560 res = av.getColumnSelection().adjustForHiddenColumns(res);
563 if (row > -1 && aa[row].annotations != null
564 && res < (int) aa[row].annotations.length)
566 if (aa[row].graphGroup > -1)
568 StringBuffer tip = new StringBuffer("<html>");
569 for (int gg = 0; gg < aa.length; gg++)
571 if (aa[gg].graphGroup == aa[row].graphGroup
572 && aa[gg].annotations[res] != null)
574 tip.append(aa[gg].label + " "
575 + aa[gg].annotations[res].description + "<br>");
578 if (tip.length() != 6)
580 tip.setLength(tip.length() - 4);
581 this.setToolTipText(tip.toString() + "</html>");
584 else if (aa[row].annotations[res] != null
585 && aa[row].annotations[res].description != null
586 && aa[row].annotations[res].description.length() > 0)
588 this.setToolTipText(aa[row].annotations[res].description);
592 // clear the tooltip.
593 this.setToolTipText(null);
596 if (aa[row].annotations[res] != null)
598 StringBuffer text = new StringBuffer("Sequence position "
601 if (aa[row].annotations[res].description != null)
603 text.append(" " + aa[row].annotations[res].description);
606 ap.alignFrame.statusBar.setText(text.toString());
611 this.setToolTipText(null);
621 public void mouseClicked(MouseEvent evt)
631 public void paintComponent(Graphics g)
633 g.setColor(Color.white);
634 g.fillRect(0, 0, getWidth(), getHeight());
638 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
639 || (getVisibleRect().height != g.getClipBounds().height))
641 g.drawImage(image, 0, 0, this);
646 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
649 if (image == null || imgWidth != image.getWidth()
650 || image.getHeight(this) != getHeight())
652 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
653 BufferedImage.TYPE_INT_RGB);
654 gg = (Graphics2D) image.getGraphics();
658 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
659 RenderingHints.VALUE_ANTIALIAS_ON);
662 gg.setFont(av.getFont());
663 fm = gg.getFontMetrics();
664 gg.setColor(Color.white);
665 gg.fillRect(0, 0, imgWidth, image.getHeight());
668 drawComponent(gg, av.startRes, av.endRes + 1);
669 g.drawImage(image, 0, 0, this);
673 * non-Thread safe repaint
676 * repaint with horizontal shift in alignment
678 public void fastPaint(int horizontal)
681 if ((horizontal == 0) || gg == null
682 || av.alignment.getAlignmentAnnotation() == null
683 || av.alignment.getAlignmentAnnotation().length < 1
684 || av.updatingConsensus || av.updatingConservation)
689 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
691 int sr = av.startRes;
692 int er = av.endRes + 1;
695 if (horizontal > 0) // scrollbar pulled right, image to the left
697 transX = (er - sr - horizontal) * av.charWidth;
698 sr = er - horizontal;
700 else if (horizontal < 0)
702 er = sr - horizontal;
705 gg.translate(transX, 0);
707 drawComponent(gg, sr, er);
709 gg.translate(-transX, 0);
726 public void drawComponent(Graphics g, int startRes, int endRes)
728 if (av.updatingConsensus || av.updatingConservation)
734 // We'll keep a record of the old image,
735 // and draw a faded image until the calculation
737 if (fadedImage == null || fadedImage.getWidth() != imgWidth
738 || fadedImage.getHeight() != image.getHeight())
740 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
741 BufferedImage.TYPE_INT_RGB);
743 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
745 fadedG.setColor(Color.white);
746 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
748 fadedG.setComposite(AlphaComposite.getInstance(
749 AlphaComposite.SRC_OVER, .3f));
750 fadedG.drawImage(image, 0, 0, this);
760 g.setColor(Color.white);
761 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
763 g.setFont(av.getFont());
766 fm = g.getFontMetrics();
769 if ((av.alignment.getAlignmentAnnotation() == null)
770 || (av.alignment.getAlignmentAnnotation().length < 1))
772 g.setColor(Color.white);
773 g.fillRect(0, 0, getWidth(), getHeight());
774 g.setColor(Color.black);
775 if (av.validCharWidth)
777 g.drawString("Alignment has no annotations", 20, 15);
783 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
790 boolean validRes = false;
791 boolean validEnd = false;
792 boolean labelAllCols = false;
793 boolean centreColLabels, centreColLabelsDef = av
794 .getCentreColumnLabels();
795 boolean scaleColLabel = false;
796 boolean[] graphGroupDrawn = new boolean[aa.length];
797 int charOffset = 0; // offset for a label
798 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
800 Font ofont = g.getFont();
802 for (int i = 0; i < aa.length; i++)
804 AlignmentAnnotation row = aa[i];
810 centreColLabels = row.centreColLabels || centreColLabelsDef;
811 labelAllCols = row.showAllColLabels;
812 scaleColLabel = row.scaleColLabel;
818 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
823 // this is so that we draw the characters below the graph
828 iconOffset = av.charHeight - fm.getDescent();
832 else if (row.hasText)
834 iconOffset = av.charHeight - fm.getDescent();
842 if (av.updatingConsensus && aa[i] == av.consensus)
846 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
847 - row.height, imgWidth, y, this);
848 g.setColor(Color.black);
849 // g.drawString("Calculating Consensus....",20, y-row.height/2);
853 else if (av.updatingConservation
854 && aa[i].label.equals("Conservation"))
858 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
859 - row.height, imgWidth, y, this);
861 g.setColor(Color.black);
862 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
866 else if (av.updatingConservation && aa[i].label.equals("Quality"))
870 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
871 - row.height, imgWidth, y, this);
872 g.setColor(Color.black);
873 // / g.drawString("Calculating Quality....",20, y-row.height/2);
879 while (x < endRes - startRes)
881 if (av.hasHiddenColumns)
883 column = av.getColumnSelection().adjustForHiddenColumns(
885 if (column > row.annotations.length - 1)
892 column = startRes + x;
895 if ((row.annotations == null) || (row.annotations.length <= column)
896 || (row.annotations[column] == null))
907 g.setColor(Color.red);
909 if (av.getColumnSelection() != null)
911 for (int n = 0; n < av.getColumnSelection().size(); n++)
913 int v = av.getColumnSelection().columnAt(n);
918 .fillRect(x * av.charWidth, y, av.charWidth,
925 if (av.validCharWidth && validRes
926 && row.annotations[column].displayCharacter != null
927 && (row.annotations[column].displayCharacter.length() > 0))
930 if (centreColLabels || scaleColLabel)
932 fmWidth = (float) fm.charsWidth(
933 row.annotations[column].displayCharacter.toCharArray(),
934 0, row.annotations[column].displayCharacter.length());
938 // justify the label and scale to fit in column
939 if (fmWidth > av.charWidth)
941 // scale only if the current font isn't already small enough
942 fmScaling = av.charWidth;
943 fmScaling /= fmWidth;
944 g.setFont(ofont.deriveFont(AffineTransform
945 .getScaleInstance(fmScaling, 1.0)));
946 // and update the label's width to reflect the scaling.
947 fmWidth = av.charWidth;
954 .charWidth(row.annotations[column].displayCharacter
957 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
959 if (row.annotations[column].colour == null)
960 g.setColor(Color.black);
962 g.setColor(row.annotations[column].colour);
964 if (column == 0 || row.graph > 0)
966 g.drawString(row.annotations[column].displayCharacter,
967 (x * av.charWidth) + charOffset, y + iconOffset);
969 else if (row.annotations[column - 1] == null
971 || !row.annotations[column].displayCharacter
972 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
973 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
975 g.drawString(row.annotations[column].displayCharacter, x
976 * av.charWidth + charOffset, y + iconOffset);
984 || (row.annotations[column].secondaryStructure != lastSS))
989 g.setColor(HELIX_COLOUR);
992 // Off by 1 offset when drawing rects and ovals
993 // to offscreen image on the MAC
994 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
995 (x * av.charWidth) - lastSSX, 7, 8, 8);
999 int sCol = (lastSSX / av.charWidth) + startRes;
1001 int x2 = (x * av.charWidth);
1004 || row.annotations[sCol - 1] == null
1005 || row.annotations[sCol - 1].secondaryStructure != 'H')
1007 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
1009 x1 += av.charWidth / 2;
1012 if (!validRes || row.annotations[column] == null
1013 || row.annotations[column].secondaryStructure != 'H')
1015 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1016 + iconOffset, av.charWidth, 8, 270, 180);
1017 x2 -= av.charWidth / 2;
1020 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1024 g.setColor(SHEET_COLOUR);
1025 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1027 g.fillPolygon(new int[]
1028 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1029 (x * av.charWidth) }, new int[]
1030 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1036 g.setColor(Color.gray);
1037 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1045 lastSS = row.annotations[column].secondaryStructure;
1052 lastSSX = (x * av.charWidth);
1060 if (column >= row.annotations.length)
1062 column = row.annotations.length - 1;
1077 g.setColor(HELIX_COLOUR);
1080 // Off by 1 offset when drawing rects and ovals
1081 // to offscreen image on the MAC
1082 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1083 - lastSSX, 7, 8, 8);
1087 int sCol = (lastSSX / av.charWidth) + startRes;
1089 int x2 = (x * av.charWidth);
1091 if (sCol == 0 || row.annotations[sCol - 1] == null
1092 || row.annotations[sCol - 1].secondaryStructure != 'H')
1095 .fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8,
1097 x1 += av.charWidth / 2;
1100 if (row.annotations[column] == null
1101 || row.annotations[column].secondaryStructure != 'H')
1103 g.fillArc((x * av.charWidth) - av.charWidth,
1104 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1105 x2 -= av.charWidth / 2;
1108 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1113 g.setColor(SHEET_COLOUR);
1115 if (!validEnd || row.annotations[endRes] == null
1116 || row.annotations[endRes].secondaryStructure != 'E')
1118 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1120 g.fillPolygon(new int[]
1121 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1122 (x * av.charWidth) }, new int[]
1123 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1127 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1133 g.setColor(Color.gray);
1134 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1141 if (row.graph > 0 && row.graphHeight > 0)
1143 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1145 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1147 float groupmax = -999999, groupmin = 9999999;
1148 for (int gg = 0; gg < aa.length; gg++)
1150 if (aa[gg].graphGroup != row.graphGroup)
1157 aa[gg].visible = false;
1160 if (aa[gg].graphMax > groupmax)
1162 groupmax = aa[gg].graphMax;
1164 if (aa[gg].graphMin < groupmin)
1166 groupmin = aa[gg].graphMin;
1170 for (int gg = 0; gg < aa.length; gg++)
1172 if (aa[gg].graphGroup == row.graphGroup)
1174 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1175 groupmax, row.graphHeight);
1179 graphGroupDrawn[row.graphGroup] = true;
1183 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1184 row.graphMax, row.graphHeight);
1187 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1189 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1194 if (row.graph > 0 && row.hasText)
1206 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1207 int eRes, int y, float min, float max, int graphHeight)
1209 if (sRes > aa.annotations.length)
1216 // Adjustment for fastpaint to left
1217 if (eRes < av.endRes)
1222 eRes = Math.min(eRes, aa.annotations.length);
1230 float range = max - min;
1235 y2 = y - (int) ((0 - min / range) * graphHeight);
1238 g.setColor(Color.gray);
1239 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1241 eRes = Math.min(eRes, aa.annotations.length);
1244 int aaMax = aa.annotations.length - 1;
1246 while (x < eRes - sRes)
1249 if (av.hasHiddenColumns)
1251 column = av.getColumnSelection().adjustForHiddenColumns(column);
1259 if (aa.annotations[column] == null
1260 || aa.annotations[column - 1] == null)
1266 if (aa.annotations[column].colour == null)
1267 g.setColor(Color.black);
1269 g.setColor(aa.annotations[column].colour);
1272 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1274 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1276 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1277 + av.charWidth / 2, y2);
1281 if (aa.threshold != null)
1283 g.setColor(aa.threshold.colour);
1284 Graphics2D g2 = (Graphics2D) g;
1285 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1286 BasicStroke.JOIN_ROUND, 3f, new float[]
1289 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1290 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1291 g2.setStroke(new BasicStroke());
1295 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1296 int eRes, float min, float max, int y)
1298 ColourSchemeI profcolour = av.getGlobalColourScheme();
1299 if (profcolour == null)
1301 profcolour = new jalview.schemes.ZappoColourScheme();
1303 if (sRes > aa.annotations.length)
1307 Font ofont = g.getFont();
1308 eRes = Math.min(eRes, aa.annotations.length);
1310 int x = 0, y1 = y, y2 = y;
1312 float range = max - min;
1316 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1319 g.setColor(Color.gray);
1321 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1324 int aaMax = aa.annotations.length - 1;
1325 boolean renderHistogram = true, renderProfile = true;
1326 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1328 // TODO: generalise this to have render styles for consensus/profile data
1329 if (aa.groupRef != null)
1331 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1332 renderProfile = aa.groupRef.isShowSequenceLogo();
1336 renderHistogram = av.isShowConsensusHistogram();
1337 renderProfile = av.isShowSequenceLogo();
1340 while (x < eRes - sRes)
1343 if (av.hasHiddenColumns)
1345 column = av.getColumnSelection().adjustForHiddenColumns(column);
1353 if (aa.annotations[column] == null)
1358 if (aa.annotations[column].colour == null)
1359 g.setColor(Color.black);
1361 g.setColor(aa.annotations[column].colour);
1364 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1366 if (renderHistogram)
1370 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1374 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1377 // draw profile if available
1378 if (aa.annotations[column].value != 0 && renderProfile)
1380 int profl[] = getProfileFor(aa, column);
1381 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1384 char[] dc = new char[1];
1386 for (int c = 1; profl != null && c < profl[0];)
1388 dc[0] = (char) profl[c++];
1389 wdth = av.charWidth;
1390 wdth /= (float) fm.charsWidth(dc, 0, 1);
1397 // if (aa.annotations[column].value==0) {
1398 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1399 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1400 // ht = y2-(int)ht2;
1402 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1403 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1405 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1408 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1409 // ? );// try to get a
1410 // colourscheme for the
1411 // group(aa.groupRef.cs==null)
1412 // ? av.textColour2 :
1413 // cs.findColour(dc));
1414 g.drawChars(dc, 0, 1, x * av.charWidth, (int) (ht + lm
1416 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1423 if (aa.threshold != null)
1425 g.setColor(aa.threshold.colour);
1426 Graphics2D g2 = (Graphics2D) g;
1427 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1428 BasicStroke.JOIN_ROUND, 3f, new float[]
1431 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1432 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1433 g2.setStroke(new BasicStroke());
1437 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1439 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1441 if (aa.groupRef != null && aa.groupRef.consensusData != null
1442 && aa.groupRef.isShowSequenceLogo())
1444 return AAFrequency.extractProfile(
1445 aa.groupRef.consensusData[column], aa.groupRef
1446 .getIgnoreGapsConsensus());
1448 // TODO extend annotation row to enable dynamic and static profile data to
1450 if (aa.groupRef == null && aa.sequenceRef == null
1451 && av.isShowSequenceLogo())
1453 return AAFrequency.extractProfile(av.hconsensus[column], av
1454 .getIgnoreGapsConsensus());
1460 // used by overview window
1461 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1462 int y, int sRes, int eRes)
1464 eRes = Math.min(eRes, aa.annotations.length);
1465 g.setColor(Color.white);
1466 g.fillRect(0, 0, width, y);
1467 g.setColor(new Color(0, 0, 180));
1471 for (int j = sRes; j < eRes; j++)
1473 if (aa.annotations[j] != null)
1475 if (aa.annotations[j].colour == null)
1476 g.setColor(Color.black);
1478 g.setColor(aa.annotations[j].colour);
1480 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1486 g.fillRect(x, y - height, av.charWidth, height);