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();
206 Annotation[] anot = aa[activeRow].annotations;
208 if (anot.length < av.getColumnSelection().getMax())
210 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
211 System.arraycopy(anot, 0, temp, 0, anot.length);
213 aa[activeRow].annotations = anot;
216 if (evt.getActionCommand().equals(REMOVE))
218 for (int i = 0; i < av.getColumnSelection().size(); i++)
220 anot[av.getColumnSelection().columnAt(i)] = null;
223 else if (evt.getActionCommand().equals(LABEL))
225 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
226 String label = JOptionPane.showInputDialog(this, "Enter label",
234 if ((label.length() > 0) && !aa[activeRow].hasText)
236 aa[activeRow].hasText = true;
239 for (int i = 0; i < av.getColumnSelection().size(); i++)
241 int index = av.getColumnSelection().columnAt(i);
243 if (!av.colSel.isVisible(index))
246 if (anot[index] == null)
248 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
255 anot[index].displayCharacter = label;
259 else if (evt.getActionCommand().equals(COLOUR))
261 Color col = JColorChooser.showDialog(this,
262 "Choose foreground colour", Color.black);
264 for (int i = 0; i < av.getColumnSelection().size(); i++)
266 int index = av.getColumnSelection().columnAt(i);
268 if (!av.colSel.isVisible(index))
271 if (anot[index] == null)
273 anot[index] = new Annotation("", "", ' ', 0);
276 anot[index].colour = col;
283 String symbol = "\u03B1";
285 if (evt.getActionCommand().equals(HELIX))
289 else if (evt.getActionCommand().equals(SHEET))
295 if (!aa[activeRow].hasIcons)
297 aa[activeRow].hasIcons = true;
300 String label = JOptionPane.showInputDialog(
301 "Enter a label for the structure?", symbol);
308 if ((label.length() > 0) && !aa[activeRow].hasText)
310 aa[activeRow].hasText = true;
313 for (int i = 0; i < av.getColumnSelection().size(); i++)
315 int index = av.getColumnSelection().columnAt(i);
317 if (!av.colSel.isVisible(index))
320 if (anot[index] == null)
322 anot[index] = new Annotation(label, "", type, 0);
325 anot[index].secondaryStructure = type;
326 anot[index].displayCharacter = label;
336 private String collectAnnotVals(Annotation[] anot,
337 ColumnSelection columnSelection, String label2)
339 String collatedInput = "";
341 for (int i = 0; i < columnSelection.size(); i++)
343 int index = columnSelection.columnAt(i);
344 // always check for current display state - just in case
345 if (!av.colSel.isVisible(index))
347 String tlabel = null;
348 if (anot[index] != null)
350 if (label2.equals(HELIX) || label2.equals(SHEET)
351 || label2.equals(LABEL))
353 tlabel = anot[index].description;
354 if (tlabel == null || tlabel.length() < 1)
356 if (label2.equals(HELIX) || label2.equals(SHEET))
358 tlabel = "" + anot[index].secondaryStructure;
362 tlabel = "" + anot[index].displayCharacter;
366 if (tlabel != null && !tlabel.equals(last))
368 if (last.length() > 0)
370 collatedInput += " ";
372 collatedInput += tlabel;
376 return collatedInput;
385 public void mousePressed(MouseEvent evt)
388 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
397 for (int i = 0; i < aa.length; i++)
401 height += aa[i].height;
404 if (evt.getY() < height)
410 else if (aa[i].graph > 0)
414 graphStretchY = evt.getY();
421 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
423 if (av.getColumnSelection() == null)
428 JPopupMenu pop = new JPopupMenu("Structure type");
429 JMenuItem item = new JMenuItem(HELIX);
430 item.addActionListener(this);
432 item = new JMenuItem(SHEET);
433 item.addActionListener(this);
435 item = new JMenuItem(LABEL);
436 item.addActionListener(this);
438 item = new JMenuItem(COLOUR);
439 item.addActionListener(this);
441 item = new JMenuItem(REMOVE);
442 item.addActionListener(this);
444 pop.show(this, evt.getX(), evt.getY());
454 ap.scalePanel.mousePressed(evt);
464 public void mouseReleased(MouseEvent evt)
468 mouseDragging = false;
469 ap.scalePanel.mouseReleased(evt);
478 public void mouseEntered(MouseEvent evt)
480 ap.scalePanel.mouseEntered(evt);
489 public void mouseExited(MouseEvent evt)
491 ap.scalePanel.mouseExited(evt);
500 public void mouseDragged(MouseEvent evt)
502 if (graphStretch > -1)
504 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
506 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
508 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
510 graphStretchY = evt.getY();
512 ap.paintAlignment(true);
516 ap.scalePanel.mouseDragged(evt);
526 public void mouseMoved(MouseEvent evt)
528 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
532 this.setToolTipText(null);
539 for (int i = 0; i < aa.length; i++)
543 height += aa[i].height;
546 if (evt.getY() < height)
556 this.setToolTipText(null);
560 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
562 if (av.hasHiddenColumns)
564 res = av.getColumnSelection().adjustForHiddenColumns(res);
567 if (row > -1 && aa[row].annotations != null
568 && res < (int) aa[row].annotations.length)
570 if (aa[row].graphGroup > -1)
572 StringBuffer tip = new StringBuffer("<html>");
573 for (int gg = 0; gg < aa.length; gg++)
575 if (aa[gg].graphGroup == aa[row].graphGroup
576 && aa[gg].annotations[res] != null)
578 tip.append(aa[gg].label + " "
579 + aa[gg].annotations[res].description + "<br>");
582 if (tip.length() != 6)
584 tip.setLength(tip.length() - 4);
585 this.setToolTipText(tip.toString() + "</html>");
588 else if (aa[row].annotations[res] != null
589 && aa[row].annotations[res].description != null
590 && aa[row].annotations[res].description.length() > 0)
592 this.setToolTipText(aa[row].annotations[res].description);
596 // clear the tooltip.
597 this.setToolTipText(null);
600 if (aa[row].annotations[res] != null)
602 StringBuffer text = new StringBuffer("Sequence position "
605 if (aa[row].annotations[res].description != null)
607 text.append(" " + aa[row].annotations[res].description);
610 ap.alignFrame.statusBar.setText(text.toString());
615 this.setToolTipText(null);
625 public void mouseClicked(MouseEvent evt)
635 public void paintComponent(Graphics g)
637 g.setColor(Color.white);
638 g.fillRect(0, 0, getWidth(), getHeight());
642 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
643 || (getVisibleRect().height != g.getClipBounds().height))
645 g.drawImage(image, 0, 0, this);
650 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
653 if (image == null || imgWidth != image.getWidth()
654 || image.getHeight(this) != getHeight())
656 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
657 BufferedImage.TYPE_INT_RGB);
658 gg = (Graphics2D) image.getGraphics();
662 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
663 RenderingHints.VALUE_ANTIALIAS_ON);
666 gg.setFont(av.getFont());
667 fm = gg.getFontMetrics();
668 gg.setColor(Color.white);
669 gg.fillRect(0, 0, imgWidth, image.getHeight());
672 drawComponent(gg, av.startRes, av.endRes + 1);
673 g.drawImage(image, 0, 0, this);
677 * non-Thread safe repaint
680 * repaint with horizontal shift in alignment
682 public void fastPaint(int horizontal)
685 if ((horizontal == 0) || gg == null
686 || av.alignment.getAlignmentAnnotation() == null
687 || av.alignment.getAlignmentAnnotation().length < 1
688 || av.updatingConsensus || av.updatingConservation)
693 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
695 int sr = av.startRes;
696 int er = av.endRes + 1;
699 if (horizontal > 0) // scrollbar pulled right, image to the left
701 transX = (er - sr - horizontal) * av.charWidth;
702 sr = er - horizontal;
704 else if (horizontal < 0)
706 er = sr - horizontal;
709 gg.translate(transX, 0);
711 drawComponent(gg, sr, er);
713 gg.translate(-transX, 0);
730 public void drawComponent(Graphics g, int startRes, int endRes)
732 if (av.updatingConsensus || av.updatingConservation)
738 // We'll keep a record of the old image,
739 // and draw a faded image until the calculation
741 if (fadedImage == null || fadedImage.getWidth() != imgWidth
742 || fadedImage.getHeight() != image.getHeight())
744 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
745 BufferedImage.TYPE_INT_RGB);
747 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
749 fadedG.setColor(Color.white);
750 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
752 fadedG.setComposite(AlphaComposite.getInstance(
753 AlphaComposite.SRC_OVER, .3f));
754 fadedG.drawImage(image, 0, 0, this);
764 g.setColor(Color.white);
765 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
767 g.setFont(av.getFont());
770 fm = g.getFontMetrics();
773 if ((av.alignment.getAlignmentAnnotation() == null)
774 || (av.alignment.getAlignmentAnnotation().length < 1))
776 g.setColor(Color.white);
777 g.fillRect(0, 0, getWidth(), getHeight());
778 g.setColor(Color.black);
779 if (av.validCharWidth)
781 g.drawString("Alignment has no annotations", 20, 15);
787 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
794 boolean validRes = false;
795 boolean validEnd = false;
796 boolean labelAllCols = false;
797 boolean centreColLabels, centreColLabelsDef = av
798 .getCentreColumnLabels();
799 boolean scaleColLabel = false;
800 boolean[] graphGroupDrawn = new boolean[aa.length];
801 int charOffset = 0; // offset for a label
802 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
804 Font ofont = g.getFont();
806 for (int i = 0; i < aa.length; i++)
808 AlignmentAnnotation row = aa[i];
814 centreColLabels = row.centreColLabels || centreColLabelsDef;
815 labelAllCols = row.showAllColLabels;
816 scaleColLabel = row.scaleColLabel;
822 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
827 // this is so that we draw the characters below the graph
832 iconOffset = av.charHeight - fm.getDescent();
836 else if (row.hasText)
838 iconOffset = av.charHeight - fm.getDescent();
846 if (av.updatingConsensus && aa[i] == av.consensus)
850 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
851 - row.height, imgWidth, y, this);
852 g.setColor(Color.black);
853 // g.drawString("Calculating Consensus....",20, y-row.height/2);
857 else if (av.updatingConservation
858 && aa[i].label.equals("Conservation"))
862 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
863 - row.height, imgWidth, y, this);
865 g.setColor(Color.black);
866 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
870 else if (av.updatingConservation && aa[i].label.equals("Quality"))
874 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
875 - row.height, imgWidth, y, this);
876 g.setColor(Color.black);
877 // / g.drawString("Calculating Quality....",20, y-row.height/2);
883 while (x < endRes - startRes)
885 if (av.hasHiddenColumns)
887 column = av.getColumnSelection().adjustForHiddenColumns(
889 if (column > row.annotations.length - 1)
896 column = startRes + x;
899 if ((row.annotations == null) || (row.annotations.length <= column)
900 || (row.annotations[column] == null))
911 g.setColor(Color.red);
913 if (av.getColumnSelection() != null)
915 for (int n = 0; n < av.getColumnSelection().size(); n++)
917 int v = av.getColumnSelection().columnAt(n);
922 .fillRect(x * av.charWidth, y, av.charWidth,
929 if (av.validCharWidth && validRes
930 && row.annotations[column].displayCharacter != null
931 && (row.annotations[column].displayCharacter.length() > 0))
934 if (centreColLabels || scaleColLabel)
936 fmWidth = (float) fm.charsWidth(
937 row.annotations[column].displayCharacter.toCharArray(),
938 0, row.annotations[column].displayCharacter.length());
942 // justify the label and scale to fit in column
943 if (fmWidth > av.charWidth)
945 // scale only if the current font isn't already small enough
946 fmScaling = av.charWidth;
947 fmScaling /= fmWidth;
948 g.setFont(ofont.deriveFont(AffineTransform
949 .getScaleInstance(fmScaling, 1.0)));
950 // and update the label's width to reflect the scaling.
951 fmWidth = av.charWidth;
958 .charWidth(row.annotations[column].displayCharacter
961 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
963 if (row.annotations[column].colour == null)
964 g.setColor(Color.black);
966 g.setColor(row.annotations[column].colour);
968 if (column == 0 || row.graph > 0)
970 g.drawString(row.annotations[column].displayCharacter,
971 (x * av.charWidth) + charOffset, y + iconOffset);
973 else if (row.annotations[column - 1] == null
975 || !row.annotations[column].displayCharacter
976 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
977 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
979 g.drawString(row.annotations[column].displayCharacter, x
980 * av.charWidth + charOffset, y + iconOffset);
988 || (row.annotations[column].secondaryStructure != lastSS))
993 g.setColor(HELIX_COLOUR);
996 // Off by 1 offset when drawing rects and ovals
997 // to offscreen image on the MAC
998 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
999 (x * av.charWidth) - lastSSX, 7, 8, 8);
1003 int sCol = (lastSSX / av.charWidth) + startRes;
1005 int x2 = (x * av.charWidth);
1008 || row.annotations[sCol - 1] == null
1009 || row.annotations[sCol - 1].secondaryStructure != 'H')
1011 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
1013 x1 += av.charWidth / 2;
1016 if (!validRes || row.annotations[column] == null
1017 || row.annotations[column].secondaryStructure != 'H')
1019 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1020 + iconOffset, av.charWidth, 8, 270, 180);
1021 x2 -= av.charWidth / 2;
1024 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1028 g.setColor(SHEET_COLOUR);
1029 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1031 g.fillPolygon(new int[]
1032 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1033 (x * av.charWidth) }, new int[]
1034 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1040 g.setColor(Color.gray);
1041 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1049 lastSS = row.annotations[column].secondaryStructure;
1056 lastSSX = (x * av.charWidth);
1064 if (column >= row.annotations.length)
1066 column = row.annotations.length - 1;
1081 g.setColor(HELIX_COLOUR);
1084 // Off by 1 offset when drawing rects and ovals
1085 // to offscreen image on the MAC
1086 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1087 - lastSSX, 7, 8, 8);
1091 int sCol = (lastSSX / av.charWidth) + startRes;
1093 int x2 = (x * av.charWidth);
1095 if (sCol == 0 || row.annotations[sCol - 1] == null
1096 || row.annotations[sCol - 1].secondaryStructure != 'H')
1099 .fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8,
1101 x1 += av.charWidth / 2;
1104 if (row.annotations[column] == null
1105 || row.annotations[column].secondaryStructure != 'H')
1107 g.fillArc((x * av.charWidth) - av.charWidth,
1108 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1109 x2 -= av.charWidth / 2;
1112 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1117 g.setColor(SHEET_COLOUR);
1119 if (!validEnd || row.annotations[endRes] == null
1120 || row.annotations[endRes].secondaryStructure != 'E')
1122 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1124 g.fillPolygon(new int[]
1125 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1126 (x * av.charWidth) }, new int[]
1127 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1131 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1137 g.setColor(Color.gray);
1138 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1145 if (row.graph > 0 && row.graphHeight > 0)
1147 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1149 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1151 float groupmax = -999999, groupmin = 9999999;
1152 for (int gg = 0; gg < aa.length; gg++)
1154 if (aa[gg].graphGroup != row.graphGroup)
1161 aa[gg].visible = false;
1164 if (aa[gg].graphMax > groupmax)
1166 groupmax = aa[gg].graphMax;
1168 if (aa[gg].graphMin < groupmin)
1170 groupmin = aa[gg].graphMin;
1174 for (int gg = 0; gg < aa.length; gg++)
1176 if (aa[gg].graphGroup == row.graphGroup)
1178 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1179 groupmax, row.graphHeight);
1183 graphGroupDrawn[row.graphGroup] = true;
1187 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1188 row.graphMax, row.graphHeight);
1191 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1193 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1198 if (row.graph > 0 && row.hasText)
1210 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1211 int eRes, int y, float min, float max, int graphHeight)
1213 if (sRes > aa.annotations.length)
1220 // Adjustment for fastpaint to left
1221 if (eRes < av.endRes)
1226 eRes = Math.min(eRes, aa.annotations.length);
1234 float range = max - min;
1239 y2 = y - (int) ((0 - min / range) * graphHeight);
1242 g.setColor(Color.gray);
1243 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1245 eRes = Math.min(eRes, aa.annotations.length);
1248 int aaMax = aa.annotations.length - 1;
1250 while (x < eRes - sRes)
1253 if (av.hasHiddenColumns)
1255 column = av.getColumnSelection().adjustForHiddenColumns(column);
1263 if (aa.annotations[column] == null
1264 || aa.annotations[column - 1] == null)
1270 if (aa.annotations[column].colour == null)
1271 g.setColor(Color.black);
1273 g.setColor(aa.annotations[column].colour);
1276 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1278 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1280 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1281 + av.charWidth / 2, y2);
1285 if (aa.threshold != null)
1287 g.setColor(aa.threshold.colour);
1288 Graphics2D g2 = (Graphics2D) g;
1289 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1290 BasicStroke.JOIN_ROUND, 3f, new float[]
1293 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1294 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1295 g2.setStroke(new BasicStroke());
1299 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1300 int eRes, float min, float max, int y)
1302 ColourSchemeI profcolour = av.getGlobalColourScheme();
1303 if (profcolour == null)
1305 profcolour = new jalview.schemes.ZappoColourScheme();
1307 if (sRes > aa.annotations.length)
1311 Font ofont = g.getFont();
1312 eRes = Math.min(eRes, aa.annotations.length);
1314 int x = 0, y1 = y, y2 = y;
1316 float range = max - min;
1320 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1323 g.setColor(Color.gray);
1325 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1328 int aaMax = aa.annotations.length - 1;
1329 boolean renderHistogram = true, renderProfile = true;
1330 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1332 // TODO: generalise this to have render styles for consensus/profile data
1333 if (aa.groupRef != null)
1335 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1336 renderProfile = aa.groupRef.isShowSequenceLogo();
1340 renderHistogram = av.isShowConsensusHistogram();
1341 renderProfile = av.isShowSequenceLogo();
1344 while (x < eRes - sRes)
1347 if (av.hasHiddenColumns)
1349 column = av.getColumnSelection().adjustForHiddenColumns(column);
1357 if (aa.annotations[column] == null)
1362 if (aa.annotations[column].colour == null)
1363 g.setColor(Color.black);
1365 g.setColor(aa.annotations[column].colour);
1368 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1370 if (renderHistogram)
1374 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1378 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1381 // draw profile if available
1382 if (aa.annotations[column].value != 0 && renderProfile)
1384 int profl[] = getProfileFor(aa, column);
1385 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1388 char[] dc = new char[1];
1390 for (int c = 1; profl != null && c < profl[0];)
1392 dc[0] = (char) profl[c++];
1393 wdth = av.charWidth;
1394 wdth /= (float) fm.charsWidth(dc, 0, 1);
1401 // if (aa.annotations[column].value==0) {
1402 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1403 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1404 // ht = y2-(int)ht2;
1406 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1407 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1409 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1412 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1413 // ? );// try to get a
1414 // colourscheme for the
1415 // group(aa.groupRef.cs==null)
1416 // ? av.textColour2 :
1417 // cs.findColour(dc));
1418 g.drawChars(dc, 0, 1, x * av.charWidth, (int) (ht + lm
1420 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1427 if (aa.threshold != null)
1429 g.setColor(aa.threshold.colour);
1430 Graphics2D g2 = (Graphics2D) g;
1431 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1432 BasicStroke.JOIN_ROUND, 3f, new float[]
1435 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1436 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1437 g2.setStroke(new BasicStroke());
1441 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1443 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1445 if (aa.groupRef != null && aa.groupRef.consensusData != null
1446 && aa.groupRef.isShowSequenceLogo())
1448 return AAFrequency.extractProfile(
1449 aa.groupRef.consensusData[column], aa.groupRef
1450 .getIgnoreGapsConsensus());
1452 // TODO extend annotation row to enable dynamic and static profile data to
1454 if (aa.groupRef == null && aa.sequenceRef == null
1455 && av.isShowSequenceLogo())
1457 return AAFrequency.extractProfile(av.hconsensus[column], av
1458 .getIgnoreGapsConsensus());
1464 // used by overview window
1465 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1466 int y, int sRes, int eRes)
1468 eRes = Math.min(eRes, aa.annotations.length);
1469 g.setColor(Color.white);
1470 g.fillRect(0, 0, width, y);
1471 g.setColor(new Color(0, 0, 180));
1475 for (int j = sRes; j < eRes; j++)
1477 if (aa.annotations[j] != null)
1479 if (aa.annotations[j].colour == null)
1480 g.setColor(Color.black);
1482 g.setColor(aa.annotations[j].colour);
1484 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1490 g.fillRect(x, y - height, av.charWidth, height);