2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import java.awt.event.*;
23 import java.awt.font.LineMetrics;
24 import java.awt.geom.AffineTransform;
25 import java.awt.image.*;
26 import java.util.Hashtable;
30 import jalview.analysis.AAFrequency;
31 import jalview.datamodel.*;
32 import jalview.schemes.ColourSchemeI;
40 public class AnnotationPanel extends JPanel implements MouseListener,
41 MouseMotionListener, ActionListener, AdjustmentListener
43 final String HELIX = "Helix";
45 final String SHEET = "Sheet";
47 final String LABEL = "Label";
49 final String REMOVE = "Remove Annotation";
51 final String COLOUR = "Colour";
53 final Color HELIX_COLOUR = Color.red.darker();
55 final Color SHEET_COLOUR = Color.green.darker().darker();
66 BufferedImage fadedImage;
74 boolean fastPaint = false;
76 // Used For mouse Dragging and resizing graphs
77 int graphStretch = -1;
79 int graphStretchY = -1;
81 int min; // used by mouseDragged to see if user
83 int max; // used by mouseDragged to see if user
85 boolean mouseDragging = false;
90 * Creates a new AnnotationPanel object.
95 public AnnotationPanel(AlignmentPanel ap)
98 MAC = new jalview.util.Platform().isAMac();
100 ToolTipManager.sharedInstance().registerComponent(this);
101 ToolTipManager.sharedInstance().setInitialDelay(0);
102 ToolTipManager.sharedInstance().setDismissDelay(10000);
105 this.setLayout(null);
106 addMouseListener(this);
107 addMouseMotionListener(this);
108 ap.annotationScroller.getVerticalScrollBar()
109 .addAdjustmentListener(this);
112 public AnnotationPanel(AlignViewport av)
123 public void adjustmentValueChanged(AdjustmentEvent evt)
125 ap.alabels.setScrollOffset(-evt.getValue());
129 * Calculates the height of the annotation displayed in the annotation panel.
130 * Callers should normally call the ap.adjustAnnotationHeight method to ensure all
131 * annotation associated components are updated correctly.
134 public int adjustPanelHeight()
136 // setHeight of panels
137 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
142 for (int i = 0; i < aa.length; i++)
153 aa[i].height += av.charHeight;
163 aa[i].height += aa[i].graphHeight;
166 if (aa[i].height == 0)
171 height += aa[i].height;
179 this.setPreferredSize(new Dimension(1, height));
180 ap.alabels.validate();
191 public void actionPerformed(ActionEvent evt)
193 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
194 Annotation[] anot = aa[activeRow].annotations;
196 if (anot.length < av.getColumnSelection().getMax())
198 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
199 System.arraycopy(anot, 0, temp, 0, anot.length);
201 aa[activeRow].annotations = anot;
204 if (evt.getActionCommand().equals(REMOVE))
206 for (int i = 0; i < av.getColumnSelection().size(); i++)
208 anot[av.getColumnSelection().columnAt(i)] = null;
211 else if (evt.getActionCommand().equals(LABEL))
213 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
214 String label = JOptionPane.showInputDialog(this, "Enter label",
222 if ((label.length() > 0) && !aa[activeRow].hasText)
224 aa[activeRow].hasText = true;
227 for (int i = 0; i < av.getColumnSelection().size(); i++)
229 int index = av.getColumnSelection().columnAt(i);
231 if (!av.colSel.isVisible(index))
234 if (anot[index] == null)
236 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
243 anot[index].displayCharacter = label;
247 else if (evt.getActionCommand().equals(COLOUR))
249 Color col = JColorChooser.showDialog(this,
250 "Choose foreground colour", Color.black);
252 for (int i = 0; i < av.getColumnSelection().size(); i++)
254 int index = av.getColumnSelection().columnAt(i);
256 if (!av.colSel.isVisible(index))
259 if (anot[index] == null)
261 anot[index] = new Annotation("", "", ' ', 0);
264 anot[index].colour = col;
271 String symbol = "\u03B1";
273 if (evt.getActionCommand().equals(HELIX))
277 else if (evt.getActionCommand().equals(SHEET))
283 if (!aa[activeRow].hasIcons)
285 aa[activeRow].hasIcons = true;
288 String label = JOptionPane.showInputDialog(
289 "Enter a label for the structure?", symbol);
296 if ((label.length() > 0) && !aa[activeRow].hasText)
298 aa[activeRow].hasText = true;
301 for (int i = 0; i < av.getColumnSelection().size(); i++)
303 int index = av.getColumnSelection().columnAt(i);
305 if (!av.colSel.isVisible(index))
308 if (anot[index] == null)
310 anot[index] = new Annotation(label, "", type, 0);
313 anot[index].secondaryStructure = type;
314 anot[index].displayCharacter = label;
324 private String collectAnnotVals(Annotation[] anot,
325 ColumnSelection columnSelection, String label2)
327 String collatedInput = "";
329 for (int i = 0; i < columnSelection.size(); i++)
331 int index = columnSelection.columnAt(i);
332 // always check for current display state - just in case
333 if (!av.colSel.isVisible(index))
335 String tlabel = null;
336 if (anot[index] != null)
338 if (label2.equals(HELIX) || label2.equals(SHEET)
339 || label2.equals(LABEL))
341 tlabel = anot[index].description;
342 if (tlabel == null || tlabel.length()<1)
344 if (label2.equals(HELIX) || label2.equals(SHEET))
346 tlabel = "" + anot[index].secondaryStructure;
350 tlabel = "" + anot[index].displayCharacter;
354 if (tlabel != null && !tlabel.equals(last))
356 if (last.length() > 0)
358 collatedInput += " ";
360 collatedInput += tlabel;
364 return collatedInput;
373 public void mousePressed(MouseEvent evt)
376 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
385 for (int i = 0; i < aa.length; i++)
389 height += aa[i].height;
392 if (evt.getY() < height)
398 else if (aa[i].graph > 0)
402 graphStretchY = evt.getY();
409 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
411 if (av.getColumnSelection() == null)
416 JPopupMenu pop = new JPopupMenu("Structure type");
417 JMenuItem item = new JMenuItem(HELIX);
418 item.addActionListener(this);
420 item = new JMenuItem(SHEET);
421 item.addActionListener(this);
423 item = new JMenuItem(LABEL);
424 item.addActionListener(this);
426 item = new JMenuItem(COLOUR);
427 item.addActionListener(this);
429 item = new JMenuItem(REMOVE);
430 item.addActionListener(this);
432 pop.show(this, evt.getX(), evt.getY());
442 ap.scalePanel.mousePressed(evt);
452 public void mouseReleased(MouseEvent evt)
456 mouseDragging = false;
457 ap.scalePanel.mouseReleased(evt);
466 public void mouseEntered(MouseEvent evt)
468 ap.scalePanel.mouseEntered(evt);
477 public void mouseExited(MouseEvent evt)
479 ap.scalePanel.mouseExited(evt);
488 public void mouseDragged(MouseEvent evt)
490 if (graphStretch > -1)
492 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
494 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
496 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
498 graphStretchY = evt.getY();
500 ap.paintAlignment(true);
504 ap.scalePanel.mouseDragged(evt);
514 public void mouseMoved(MouseEvent evt)
516 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
520 this.setToolTipText(null);
527 for (int i = 0; i < aa.length; i++)
531 height += aa[i].height;
534 if (evt.getY() < height)
544 this.setToolTipText(null);
548 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
550 if (av.hasHiddenColumns)
552 res = av.getColumnSelection().adjustForHiddenColumns(res);
555 if (aa[row].annotations != null && row > -1
556 && res < (int) aa[row].annotations.length)
558 if (aa[row].graphGroup > -1)
560 StringBuffer tip = new StringBuffer("<html>");
561 for (int gg = 0; gg < aa.length; gg++)
563 if (aa[gg].graphGroup == aa[row].graphGroup
564 && aa[gg].annotations[res] != null)
566 tip.append(aa[gg].label + " "
567 + aa[gg].annotations[res].description + "<br>");
570 if (tip.length() != 6)
572 tip.setLength(tip.length() - 4);
573 this.setToolTipText(tip.toString() + "</html>");
576 else if (aa[row].annotations[res] != null
577 && aa[row].annotations[res].description != null)
579 this.setToolTipText(aa[row].annotations[res].description);
582 if (aa[row].annotations[res] != null)
584 StringBuffer text = new StringBuffer("Sequence position "
587 if (aa[row].annotations[res].description != null)
589 text.append(" " + aa[row].annotations[res].description);
592 ap.alignFrame.statusBar.setText(text.toString());
597 this.setToolTipText(null);
607 public void mouseClicked(MouseEvent evt)
617 public void paintComponent(Graphics g)
619 g.setColor(Color.white);
620 g.fillRect(0, 0, getWidth(), getHeight());
624 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
625 || (getVisibleRect().height != g.getClipBounds().height))
627 g.drawImage(image, 0, 0, this);
632 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
635 if (image == null || imgWidth != image.getWidth()
636 || image.getHeight(this) != getHeight())
638 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
639 BufferedImage.TYPE_INT_RGB);
640 gg = (Graphics2D) image.getGraphics();
644 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
645 RenderingHints.VALUE_ANTIALIAS_ON);
648 gg.setFont(av.getFont());
649 fm = gg.getFontMetrics();
650 gg.setColor(Color.white);
651 gg.fillRect(0, 0, imgWidth, image.getHeight());
654 drawComponent(gg, av.startRes, av.endRes + 1);
655 g.drawImage(image, 0, 0, this);
659 * non-Thread safe repaint
662 * repaint with horizontal shift in alignment
664 public void fastPaint(int horizontal)
667 if ((horizontal == 0) || gg == null
668 || av.alignment.getAlignmentAnnotation() == null
669 || av.alignment.getAlignmentAnnotation().length < 1
670 || av.updatingConsensus || av.updatingConservation)
675 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
677 int sr = av.startRes;
678 int er = av.endRes + 1;
681 if (horizontal > 0) // scrollbar pulled right, image to the left
683 transX = (er - sr - horizontal) * av.charWidth;
684 sr = er - horizontal;
686 else if (horizontal < 0)
688 er = sr - horizontal;
691 gg.translate(transX, 0);
693 drawComponent(gg, sr, er);
695 gg.translate(-transX, 0);
712 public void drawComponent(Graphics g, int startRes, int endRes)
714 if (av.updatingConsensus || av.updatingConservation)
720 // We'll keep a record of the old image,
721 // and draw a faded image until the calculation
723 if (fadedImage == null || fadedImage.getWidth() != imgWidth
724 || fadedImage.getHeight() != image.getHeight())
726 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
727 BufferedImage.TYPE_INT_RGB);
729 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
731 fadedG.setColor(Color.white);
732 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
734 fadedG.setComposite(AlphaComposite.getInstance(
735 AlphaComposite.SRC_OVER, .3f));
736 fadedG.drawImage(image, 0, 0, this);
746 g.setColor(Color.white);
747 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
749 g.setFont(av.getFont());
752 fm = g.getFontMetrics();
755 if ((av.alignment.getAlignmentAnnotation() == null)
756 || (av.alignment.getAlignmentAnnotation().length < 1))
758 g.setColor(Color.white);
759 g.fillRect(0, 0, getWidth(), getHeight());
760 g.setColor(Color.black);
761 if (av.validCharWidth)
763 g.drawString("Alignment has no annotations", 20, 15);
769 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
776 boolean validRes = false;
777 boolean validEnd = false;
778 boolean labelAllCols = false;
779 boolean centreColLabels,centreColLabelsDef = av.getCentreColumnLabels();
780 boolean scaleColLabel=false;
781 boolean[] graphGroupDrawn = new boolean[aa.length];
782 int charOffset = 0; // offset for a label
783 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a column.
784 Font ofont = g.getFont();
786 for (int i = 0; i < aa.length; i++)
788 AlignmentAnnotation row = aa[i];
794 centreColLabels = row.centreColLabels || centreColLabelsDef;
795 labelAllCols = row.showAllColLabels;
796 scaleColLabel = row.scaleColLabel;
802 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
807 // this is so that we draw the characters below the graph
812 iconOffset = av.charHeight - fm.getDescent();
816 else if (row.hasText)
818 iconOffset = av.charHeight - fm.getDescent();
826 if (av.updatingConsensus && aa[i] == av.consensus)
830 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
831 - row.height, imgWidth, y, this);
832 g.setColor(Color.black);
833 // g.drawString("Calculating Consensus....",20, y-row.height/2);
837 else if (av.updatingConservation
838 && aa[i].label.equals("Conservation"))
842 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
843 - row.height, imgWidth, y, this);
845 g.setColor(Color.black);
846 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
850 else if (av.updatingConservation && aa[i].label.equals("Quality"))
854 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
855 - row.height, imgWidth, y, this);
856 g.setColor(Color.black);
857 // / g.drawString("Calculating Quality....",20, y-row.height/2);
863 while (x < endRes - startRes)
865 if (av.hasHiddenColumns)
867 column = av.getColumnSelection().adjustForHiddenColumns(
869 if (column > row.annotations.length - 1)
876 column = startRes + x;
879 if ((row.annotations == null) || (row.annotations.length <= column)
880 || (row.annotations[column] == null))
891 g.setColor(Color.red);
893 if (av.getColumnSelection() != null)
895 for (int n = 0; n < av.getColumnSelection().size(); n++)
897 int v = av.getColumnSelection().columnAt(n);
902 .fillRect(x * av.charWidth, y, av.charWidth,
909 if (av.validCharWidth && validRes
910 && row.annotations[column].displayCharacter != null
911 && (row.annotations[column].displayCharacter.length() > 0))
914 if (centreColLabels || scaleColLabel)
917 .charsWidth(row.annotations[column].displayCharacter
919 row.annotations[column].displayCharacter.length());
921 if ( scaleColLabel ) {
922 // justify the label and scale to fit in column
923 if (fmWidth > av.charWidth) {
924 // scale only if the current font isn't already small enough
925 fmScaling = av.charWidth;
926 fmScaling /= fmWidth;
927 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(fmScaling, 1.0)));
928 // and update the label's width to reflect the scaling.
929 fmWidth = av.charWidth;
934 .charWidth(row.annotations[column].displayCharacter.charAt(0));
936 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
938 if (row.annotations[column].colour == null)
939 g.setColor(Color.black);
941 g.setColor(row.annotations[column].colour);
943 if (column == 0 || row.graph > 0)
945 g.drawString(row.annotations[column].displayCharacter,
946 (x * av.charWidth) + charOffset, y + iconOffset);
948 else if (row.annotations[column - 1] == null
949 || (labelAllCols||!row.annotations[column].displayCharacter
950 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
951 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
953 g.drawString(row.annotations[column].displayCharacter, x
954 * av.charWidth + charOffset, y + iconOffset);
962 || (row.annotations[column].secondaryStructure != lastSS))
967 g.setColor(HELIX_COLOUR);
970 // Off by 1 offset when drawing rects and ovals
971 // to offscreen image on the MAC
972 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
973 (x * av.charWidth) - lastSSX, 7, 8, 8);
977 int sCol = (lastSSX / av.charWidth) + startRes;
979 int x2 = (x * av.charWidth);
982 || row.annotations[sCol - 1] == null
983 || row.annotations[sCol - 1].secondaryStructure != 'H')
985 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
987 x1 += av.charWidth / 2;
990 if (!validRes || row.annotations[column] == null
991 || row.annotations[column].secondaryStructure != 'H')
993 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
994 + iconOffset, av.charWidth, 8, 270, 180);
995 x2 -= av.charWidth / 2;
998 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1002 g.setColor(SHEET_COLOUR);
1003 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1005 g.fillPolygon(new int[]
1006 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1007 (x * av.charWidth) }, new int[]
1008 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1014 g.setColor(Color.gray);
1015 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1023 lastSS = row.annotations[column].secondaryStructure;
1030 lastSSX = (x * av.charWidth);
1038 if (column >= row.annotations.length)
1040 column = row.annotations.length - 1;
1055 g.setColor(HELIX_COLOUR);
1058 // Off by 1 offset when drawing rects and ovals
1059 // to offscreen image on the MAC
1060 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1061 - lastSSX, 7, 8, 8);
1065 int sCol = (lastSSX / av.charWidth) + startRes;
1067 int x2 = (x * av.charWidth);
1069 if (sCol == 0 || row.annotations[sCol - 1] == null
1070 || row.annotations[sCol - 1].secondaryStructure != 'H')
1073 .fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8,
1075 x1 += av.charWidth / 2;
1078 if (row.annotations[column] == null
1079 || row.annotations[column].secondaryStructure != 'H')
1081 g.fillArc((x * av.charWidth) - av.charWidth,
1082 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1083 x2 -= av.charWidth / 2;
1086 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1091 g.setColor(SHEET_COLOUR);
1093 if (!validEnd || row.annotations[endRes] == null
1094 || row.annotations[endRes].secondaryStructure != 'E')
1096 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1098 g.fillPolygon(new int[]
1099 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1100 (x * av.charWidth) }, new int[]
1101 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1105 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1111 g.setColor(Color.gray);
1112 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1119 if (row.graph > 0 && row.graphHeight > 0)
1121 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1123 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1125 float groupmax = -999999, groupmin = 9999999;
1126 for (int gg = 0; gg < aa.length; gg++)
1128 if (aa[gg].graphGroup != row.graphGroup)
1135 aa[gg].visible = false;
1138 if (aa[gg].graphMax > groupmax)
1140 groupmax = aa[gg].graphMax;
1142 if (aa[gg].graphMin < groupmin)
1144 groupmin = aa[gg].graphMin;
1148 for (int gg = 0; gg < aa.length; gg++)
1150 if (aa[gg].graphGroup == row.graphGroup)
1152 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1153 groupmax, row.graphHeight);
1157 graphGroupDrawn[row.graphGroup] = true;
1161 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1162 row.graphMax, row.graphHeight);
1165 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1167 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1172 if (row.graph > 0 && row.hasText)
1184 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1185 int eRes, int y, float min, float max, int graphHeight)
1187 if (sRes > aa.annotations.length)
1194 // Adjustment for fastpaint to left
1195 if (eRes < av.endRes)
1200 eRes = Math.min(eRes, aa.annotations.length);
1208 float range = max - min;
1213 y2 = y - (int) ((0 - min / range) * graphHeight);
1216 g.setColor(Color.gray);
1217 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1219 eRes = Math.min(eRes, aa.annotations.length);
1222 int aaMax = aa.annotations.length - 1;
1224 while (x < eRes - sRes)
1227 if (av.hasHiddenColumns)
1229 column = av.getColumnSelection().adjustForHiddenColumns(column);
1237 if (aa.annotations[column] == null
1238 || aa.annotations[column - 1] == null)
1244 if (aa.annotations[column].colour == null)
1245 g.setColor(Color.black);
1247 g.setColor(aa.annotations[column].colour);
1250 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1252 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1254 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1255 + av.charWidth / 2, y2);
1259 if (aa.threshold != null)
1261 g.setColor(aa.threshold.colour);
1262 Graphics2D g2 = (Graphics2D) g;
1263 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1264 BasicStroke.JOIN_ROUND, 3f, new float[]
1267 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1268 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1269 g2.setStroke(new BasicStroke());
1273 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1274 int eRes, float min, float max, int y)
1276 ColourSchemeI profcolour = av.getGlobalColourScheme();
1277 if (profcolour==null)
1279 profcolour = new jalview.schemes.ZappoColourScheme();
1281 if (sRes > aa.annotations.length)
1285 Font ofont = g.getFont();
1286 eRes = Math.min(eRes, aa.annotations.length);
1288 int x = 0, y1 = y, y2 = y;
1290 float range = max - min;
1294 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1297 g.setColor(Color.gray);
1299 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1302 int aaMax = aa.annotations.length - 1;
1304 while (x < eRes - sRes)
1307 if (av.hasHiddenColumns)
1309 column = av.getColumnSelection().adjustForHiddenColumns(column);
1317 if (aa.annotations[column] == null)
1323 if (aa.annotations[column].colour == null)
1324 g.setColor(Color.black);
1326 g.setColor(aa.annotations[column].colour);
1329 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1333 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1337 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1339 // draw profile if available
1340 if (aa.annotations[column].value!=0)
1342 int profl[] = getProfileFor(aa,column);
1343 int ht = y1,htn=y2-y1;//aa.graphHeight;
1346 char[] dc = new char[1];
1348 for (int c=1;profl!=null && c<profl[0];)
1350 dc[0] = (char) profl[c++];
1351 wdth = av.charWidth;
1353 .charsWidth(dc,0,1);
1360 //if (aa.annotations[column].value==0) {
1361 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1362 // ht = y2-(int)ht2;
1364 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(htn*((double)profl[c++])/100.0))/av.charHeight)));
1365 lm = g.getFontMetrics().getLineMetrics(dc,0,1, g);
1368 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null) ? );// try to get a colourscheme for the group(aa.groupRef.cs==null) ? av.textColour2 : cs.findColour(dc));
1369 g.drawChars(dc,0,1,x*av.charWidth, (int) (ht+lm.getHeight()));
1370 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1377 if (aa.threshold != null)
1379 g.setColor(aa.threshold.colour);
1380 Graphics2D g2 = (Graphics2D) g;
1381 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1382 BasicStroke.JOIN_ROUND, 3f, new float[]
1385 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1386 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1387 g2.setStroke(new BasicStroke());
1391 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1393 if (aa.groupRef!=null && aa.groupRef.consensusData!=null) {
1394 return AAFrequency.extractProfile(aa.groupRef.consensusData[column],aa.groupRef.getIgnoreGapsConsensus());
1396 // TODO extend annotation row to enable dynamic and static profile data to be stored
1397 if (aa.autoCalculated && aa.groupRef==null && aa.sequenceRef==null && aa.label.equals("Consensus"))
1399 return AAFrequency.extractProfile(av.hconsensus[column],av.getIgnoreGapsConsensus());
1404 // used by overview window
1405 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1406 int y, int sRes, int eRes)
1408 eRes = Math.min(eRes, aa.annotations.length);
1409 g.setColor(Color.white);
1410 g.fillRect(0, 0, width, y);
1411 g.setColor(new Color(0, 0, 180));
1415 for (int j = sRes; j < eRes; j++)
1417 if (aa.annotations[j] != null)
1419 if (aa.annotations[j].colour == null)
1420 g.setColor(Color.black);
1422 g.setColor(aa.annotations[j].colour);
1424 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1430 g.fillRect(x, y - height, av.charWidth, height);