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());
131 public int adjustPanelHeight()
133 // setHeight of panels
134 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
139 for (int i = 0; i < aa.length; i++)
150 aa[i].height += av.charHeight;
160 aa[i].height += aa[i].graphHeight;
163 if (aa[i].height == 0)
168 height += aa[i].height;
176 this.setPreferredSize(new Dimension(1, height));
187 public void actionPerformed(ActionEvent evt)
189 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
190 Annotation[] anot = aa[activeRow].annotations;
192 if (anot.length < av.getColumnSelection().getMax())
194 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
195 System.arraycopy(anot, 0, temp, 0, anot.length);
197 aa[activeRow].annotations = anot;
200 if (evt.getActionCommand().equals(REMOVE))
202 for (int i = 0; i < av.getColumnSelection().size(); i++)
204 anot[av.getColumnSelection().columnAt(i)] = null;
207 else if (evt.getActionCommand().equals(LABEL))
209 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
210 String label = JOptionPane.showInputDialog(this, "Enter label",
218 if ((label.length() > 0) && !aa[activeRow].hasText)
220 aa[activeRow].hasText = true;
223 for (int i = 0; i < av.getColumnSelection().size(); i++)
225 int index = av.getColumnSelection().columnAt(i);
227 if (!av.colSel.isVisible(index))
230 if (anot[index] == null)
232 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
239 anot[index].displayCharacter = label;
243 else if (evt.getActionCommand().equals(COLOUR))
245 Color col = JColorChooser.showDialog(this,
246 "Choose foreground colour", Color.black);
248 for (int i = 0; i < av.getColumnSelection().size(); i++)
250 int index = av.getColumnSelection().columnAt(i);
252 if (!av.colSel.isVisible(index))
255 if (anot[index] == null)
257 anot[index] = new Annotation("", "", ' ', 0);
260 anot[index].colour = col;
267 String symbol = "\u03B1";
269 if (evt.getActionCommand().equals(HELIX))
273 else if (evt.getActionCommand().equals(SHEET))
279 if (!aa[activeRow].hasIcons)
281 aa[activeRow].hasIcons = true;
284 String label = JOptionPane.showInputDialog(
285 "Enter a label for the structure?", symbol);
292 if ((label.length() > 0) && !aa[activeRow].hasText)
294 aa[activeRow].hasText = true;
297 for (int i = 0; i < av.getColumnSelection().size(); i++)
299 int index = av.getColumnSelection().columnAt(i);
301 if (!av.colSel.isVisible(index))
304 if (anot[index] == null)
306 anot[index] = new Annotation(label, "", type, 0);
309 anot[index].secondaryStructure = type;
310 anot[index].displayCharacter = label;
320 private String collectAnnotVals(Annotation[] anot,
321 ColumnSelection columnSelection, String label2)
323 String collatedInput = "";
325 for (int i = 0; i < columnSelection.size(); i++)
327 int index = columnSelection.columnAt(i);
328 // always check for current display state - just in case
329 if (!av.colSel.isVisible(index))
331 String tlabel = null;
332 if (anot[index] != null)
334 if (label2.equals(HELIX) || label2.equals(SHEET)
335 || label2.equals(LABEL))
337 tlabel = anot[index].description;
340 if (label2.equals(HELIX) || label2.equals(SHEET))
342 tlabel = "" + anot[index].secondaryStructure;
346 tlabel = "" + anot[index].displayCharacter;
350 if (tlabel != null && !tlabel.equals(last))
352 if (last.length() > 0)
354 collatedInput += " ";
356 collatedInput += tlabel;
360 return collatedInput;
369 public void mousePressed(MouseEvent evt)
372 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
381 for (int i = 0; i < aa.length; i++)
385 height += aa[i].height;
388 if (evt.getY() < height)
394 else if (aa[i].graph > 0)
398 graphStretchY = evt.getY();
405 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
407 if (av.getColumnSelection() == null)
412 JPopupMenu pop = new JPopupMenu("Structure type");
413 JMenuItem item = new JMenuItem(HELIX);
414 item.addActionListener(this);
416 item = new JMenuItem(SHEET);
417 item.addActionListener(this);
419 item = new JMenuItem(LABEL);
420 item.addActionListener(this);
422 item = new JMenuItem(COLOUR);
423 item.addActionListener(this);
425 item = new JMenuItem(REMOVE);
426 item.addActionListener(this);
428 pop.show(this, evt.getX(), evt.getY());
438 ap.scalePanel.mousePressed(evt);
448 public void mouseReleased(MouseEvent evt)
452 mouseDragging = false;
453 ap.scalePanel.mouseReleased(evt);
462 public void mouseEntered(MouseEvent evt)
464 ap.scalePanel.mouseEntered(evt);
473 public void mouseExited(MouseEvent evt)
475 ap.scalePanel.mouseExited(evt);
484 public void mouseDragged(MouseEvent evt)
486 if (graphStretch > -1)
488 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
490 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
492 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
494 graphStretchY = evt.getY();
496 ap.paintAlignment(true);
500 ap.scalePanel.mouseDragged(evt);
510 public void mouseMoved(MouseEvent evt)
512 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
516 this.setToolTipText(null);
523 for (int i = 0; i < aa.length; i++)
527 height += aa[i].height;
530 if (evt.getY() < height)
540 this.setToolTipText(null);
544 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
546 if (av.hasHiddenColumns)
548 res = av.getColumnSelection().adjustForHiddenColumns(res);
551 if (aa[row].annotations != null && row > -1
552 && res < (int) aa[row].annotations.length)
554 if (aa[row].graphGroup > -1)
556 StringBuffer tip = new StringBuffer("<html>");
557 for (int gg = 0; gg < aa.length; gg++)
559 if (aa[gg].graphGroup == aa[row].graphGroup
560 && aa[gg].annotations[res] != null)
562 tip.append(aa[gg].label + " "
563 + aa[gg].annotations[res].description + "<br>");
566 if (tip.length() != 6)
568 tip.setLength(tip.length() - 4);
569 this.setToolTipText(tip.toString() + "</html>");
572 else if (aa[row].annotations[res] != null
573 && aa[row].annotations[res].description != null)
575 this.setToolTipText(aa[row].annotations[res].description);
578 if (aa[row].annotations[res] != null)
580 StringBuffer text = new StringBuffer("Sequence position "
583 if (aa[row].annotations[res].description != null)
585 text.append(" " + aa[row].annotations[res].description);
588 ap.alignFrame.statusBar.setText(text.toString());
593 this.setToolTipText(null);
603 public void mouseClicked(MouseEvent evt)
613 public void paintComponent(Graphics g)
615 g.setColor(Color.white);
616 g.fillRect(0, 0, getWidth(), getHeight());
620 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
621 || (getVisibleRect().height != g.getClipBounds().height))
623 g.drawImage(image, 0, 0, this);
628 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
631 if (image == null || imgWidth != image.getWidth()
632 || image.getHeight(this) != getHeight())
634 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
635 BufferedImage.TYPE_INT_RGB);
636 gg = (Graphics2D) image.getGraphics();
640 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
641 RenderingHints.VALUE_ANTIALIAS_ON);
644 gg.setFont(av.getFont());
645 fm = gg.getFontMetrics();
646 gg.setColor(Color.white);
647 gg.fillRect(0, 0, imgWidth, image.getHeight());
650 drawComponent(gg, av.startRes, av.endRes + 1);
651 g.drawImage(image, 0, 0, this);
655 * non-Thread safe repaint
658 * repaint with horizontal shift in alignment
660 public void fastPaint(int horizontal)
663 if ((horizontal == 0) || gg == null
664 || av.alignment.getAlignmentAnnotation() == null
665 || av.alignment.getAlignmentAnnotation().length < 1
666 || av.updatingConsensus || av.updatingConservation)
671 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
673 int sr = av.startRes;
674 int er = av.endRes + 1;
677 if (horizontal > 0) // scrollbar pulled right, image to the left
679 transX = (er - sr - horizontal) * av.charWidth;
680 sr = er - horizontal;
682 else if (horizontal < 0)
684 er = sr - horizontal;
687 gg.translate(transX, 0);
689 drawComponent(gg, sr, er);
691 gg.translate(-transX, 0);
708 public void drawComponent(Graphics g, int startRes, int endRes)
710 if (av.updatingConsensus || av.updatingConservation)
716 // We'll keep a record of the old image,
717 // and draw a faded image until the calculation
719 if (fadedImage == null || fadedImage.getWidth() != imgWidth
720 || fadedImage.getHeight() != image.getHeight())
722 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
723 BufferedImage.TYPE_INT_RGB);
725 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
727 fadedG.setColor(Color.white);
728 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
730 fadedG.setComposite(AlphaComposite.getInstance(
731 AlphaComposite.SRC_OVER, .3f));
732 fadedG.drawImage(image, 0, 0, this);
742 g.setColor(Color.white);
743 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
745 g.setFont(av.getFont());
748 fm = g.getFontMetrics();
751 if ((av.alignment.getAlignmentAnnotation() == null)
752 || (av.alignment.getAlignmentAnnotation().length < 1))
754 g.setColor(Color.white);
755 g.fillRect(0, 0, getWidth(), getHeight());
756 g.setColor(Color.black);
757 if (av.validCharWidth)
759 g.drawString("Alignment has no annotations", 20, 15);
765 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
772 boolean validRes = false;
773 boolean validEnd = false;
774 boolean[] graphGroupDrawn = new boolean[aa.length];
777 for (int i = 0; i < aa.length; i++)
779 AlignmentAnnotation row = aa[i];
791 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
796 // this is so that we draw the characters below the graph
801 iconOffset = av.charHeight - fm.getDescent();
805 else if (row.hasText)
807 iconOffset = av.charHeight - fm.getDescent();
815 if (av.updatingConsensus && aa[i] == av.consensus)
819 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
820 - row.height, imgWidth, y, this);
821 g.setColor(Color.black);
822 // g.drawString("Calculating Consensus....",20, y-row.height/2);
826 else if (av.updatingConservation
827 && aa[i].label.equals("Conservation"))
831 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
832 - row.height, imgWidth, y, this);
834 g.setColor(Color.black);
835 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
839 else if (av.updatingConservation && aa[i].label.equals("Quality"))
843 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
844 - row.height, imgWidth, y, this);
845 g.setColor(Color.black);
846 // / g.drawString("Calculating Quality....",20, y-row.height/2);
852 while (x < endRes - startRes)
854 if (av.hasHiddenColumns)
856 column = av.getColumnSelection().adjustForHiddenColumns(
858 if (column > row.annotations.length - 1)
865 column = startRes + x;
868 if ((row.annotations == null) || (row.annotations.length <= column)
869 || (row.annotations[column] == null))
880 g.setColor(Color.red);
882 if (av.getColumnSelection() != null)
884 for (int n = 0; n < av.getColumnSelection().size(); n++)
886 int v = av.getColumnSelection().columnAt(n);
891 .fillRect(x * av.charWidth, y, av.charWidth,
898 if (av.validCharWidth && validRes
899 && row.annotations[column].displayCharacter != null
900 && (row.annotations[column].displayCharacter.length() > 0))
903 int charOffset = (av.getCentreColumnLabels()) ? ((av.charWidth - fm
904 .charsWidth(row.annotations[column].displayCharacter
906 row.annotations[column].displayCharacter.length())) / 2)
908 .charWidth(row.annotations[column].displayCharacter
911 if (row.annotations[column].colour == null)
912 g.setColor(Color.black);
914 g.setColor(row.annotations[column].colour);
916 if (column == 0 || row.graph > 0)
918 g.drawString(row.annotations[column].displayCharacter,
919 (x * av.charWidth) + charOffset, y + iconOffset);
921 else if (row.annotations[column - 1] == null
922 || (!row.annotations[column].displayCharacter
923 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
924 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
926 g.drawString(row.annotations[column].displayCharacter, x
927 * av.charWidth + charOffset, y + iconOffset);
934 || (row.annotations[column].secondaryStructure != lastSS))
939 g.setColor(HELIX_COLOUR);
942 // Off by 1 offset when drawing rects and ovals
943 // to offscreen image on the MAC
944 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
945 (x * av.charWidth) - lastSSX, 7, 8, 8);
949 int sCol = (lastSSX / av.charWidth) + startRes;
951 int x2 = (x * av.charWidth);
954 || row.annotations[sCol - 1] == null
955 || row.annotations[sCol - 1].secondaryStructure != 'H')
957 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
959 x1 += av.charWidth / 2;
962 if (!validRes || row.annotations[column] == null
963 || row.annotations[column].secondaryStructure != 'H')
965 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
966 + iconOffset, av.charWidth, 8, 270, 180);
967 x2 -= av.charWidth / 2;
970 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
974 g.setColor(SHEET_COLOUR);
975 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
977 g.fillPolygon(new int[]
978 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
979 (x * av.charWidth) }, new int[]
980 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
986 g.setColor(Color.gray);
987 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
995 lastSS = row.annotations[column].secondaryStructure;
1002 lastSSX = (x * av.charWidth);
1010 if (column >= row.annotations.length)
1012 column = row.annotations.length - 1;
1027 g.setColor(HELIX_COLOUR);
1030 // Off by 1 offset when drawing rects and ovals
1031 // to offscreen image on the MAC
1032 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1033 - lastSSX, 7, 8, 8);
1037 int sCol = (lastSSX / av.charWidth) + startRes;
1039 int x2 = (x * av.charWidth);
1041 if (sCol == 0 || row.annotations[sCol - 1] == null
1042 || row.annotations[sCol - 1].secondaryStructure != 'H')
1045 .fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8,
1047 x1 += av.charWidth / 2;
1050 if (row.annotations[column] == null
1051 || row.annotations[column].secondaryStructure != 'H')
1053 g.fillArc((x * av.charWidth) - av.charWidth,
1054 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1055 x2 -= av.charWidth / 2;
1058 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1063 g.setColor(SHEET_COLOUR);
1065 if (!validEnd || row.annotations[endRes] == null
1066 || row.annotations[endRes].secondaryStructure != 'E')
1068 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1070 g.fillPolygon(new int[]
1071 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1072 (x * av.charWidth) }, new int[]
1073 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1077 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1083 g.setColor(Color.gray);
1084 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1091 if (row.graph > 0 && row.graphHeight > 0)
1093 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1095 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1097 float groupmax = -999999, groupmin = 9999999;
1098 for (int gg = 0; gg < aa.length; gg++)
1100 if (aa[gg].graphGroup != row.graphGroup)
1107 aa[gg].visible = false;
1110 if (aa[gg].graphMax > groupmax)
1112 groupmax = aa[gg].graphMax;
1114 if (aa[gg].graphMin < groupmin)
1116 groupmin = aa[gg].graphMin;
1120 for (int gg = 0; gg < aa.length; gg++)
1122 if (aa[gg].graphGroup == row.graphGroup)
1124 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1125 groupmax, row.graphHeight);
1129 graphGroupDrawn[row.graphGroup] = true;
1133 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1134 row.graphMax, row.graphHeight);
1137 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1139 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1144 if (row.graph > 0 && row.hasText)
1156 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1157 int eRes, int y, float min, float max, int graphHeight)
1159 if (sRes > aa.annotations.length)
1166 // Adjustment for fastpaint to left
1167 if (eRes < av.endRes)
1172 eRes = Math.min(eRes, aa.annotations.length);
1180 float range = max - min;
1185 y2 = y - (int) ((0 - min / range) * graphHeight);
1188 g.setColor(Color.gray);
1189 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1191 eRes = Math.min(eRes, aa.annotations.length);
1194 int aaMax = aa.annotations.length - 1;
1196 while (x < eRes - sRes)
1199 if (av.hasHiddenColumns)
1201 column = av.getColumnSelection().adjustForHiddenColumns(column);
1209 if (aa.annotations[column] == null
1210 || aa.annotations[column - 1] == null)
1216 if (aa.annotations[column].colour == null)
1217 g.setColor(Color.black);
1219 g.setColor(aa.annotations[column].colour);
1222 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1224 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1226 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1227 + av.charWidth / 2, y2);
1231 if (aa.threshold != null)
1233 g.setColor(aa.threshold.colour);
1234 Graphics2D g2 = (Graphics2D) g;
1235 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1236 BasicStroke.JOIN_ROUND, 3f, new float[]
1239 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1240 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1241 g2.setStroke(new BasicStroke());
1245 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1246 int eRes, float min, float max, int y)
1248 ColourSchemeI profcolour = av.getGlobalColourScheme();
1249 if (profcolour==null)
1251 profcolour = new jalview.schemes.ZappoColourScheme();
1253 if (sRes > aa.annotations.length)
1257 Font ofont = g.getFont();
1258 eRes = Math.min(eRes, aa.annotations.length);
1260 int x = 0, y1 = y, y2 = y;
1262 float range = max - min;
1266 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1269 g.setColor(Color.gray);
1271 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1274 int aaMax = aa.annotations.length - 1;
1276 while (x < eRes - sRes)
1279 if (av.hasHiddenColumns)
1281 column = av.getColumnSelection().adjustForHiddenColumns(column);
1289 if (aa.annotations[column] == null)
1295 if (aa.annotations[column].colour == null)
1296 g.setColor(Color.black);
1298 g.setColor(aa.annotations[column].colour);
1301 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1305 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1309 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1311 // draw profile if available
1312 if (aa.annotations[column].value!=0)
1314 int profl[] = getProfileFor(aa,column);
1315 int ht = y1,htn=y2-y1;//aa.graphHeight;
1318 char[] dc = new char[1];
1320 for (int c=1;profl!=null && c<profl[0];)
1322 dc[0] = (char) profl[c++];
1323 wdth = av.charWidth;
1325 .charsWidth(dc,0,1);
1332 //if (aa.annotations[column].value==0) {
1333 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1334 // ht = y2-(int)ht2;
1336 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(htn*((double)profl[c++])/100.0))/av.charHeight)));
1337 lm = g.getFontMetrics().getLineMetrics(dc,0,1, g);
1340 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));
1341 g.drawChars(dc,0,1,x*av.charWidth, (int) (ht+lm.getHeight()));
1342 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1349 if (aa.threshold != null)
1351 g.setColor(aa.threshold.colour);
1352 Graphics2D g2 = (Graphics2D) g;
1353 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1354 BasicStroke.JOIN_ROUND, 3f, new float[]
1357 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1358 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1359 g2.setStroke(new BasicStroke());
1363 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1365 if (aa.groupRef!=null && aa.groupRef.consensusData!=null) {
1366 return AAFrequency.extractProfile(aa.groupRef.consensusData[column],aa.groupRef.getIgnoreGapsConsensus());
1368 // TODO extend annotation row to enable dynamic and static profile data to be stored
1369 if (aa.autoCalculated && aa.groupRef==null && aa.sequenceRef==null && aa.label.equals("Consensus"))
1371 return AAFrequency.extractProfile(av.hconsensus[column],av.getIgnoreGapsConsensus());
1376 // used by overview window
1377 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1378 int y, int sRes, int eRes)
1380 eRes = Math.min(eRes, aa.annotations.length);
1381 g.setColor(Color.white);
1382 g.fillRect(0, 0, width, y);
1383 g.setColor(new Color(0, 0, 180));
1387 for (int j = sRes; j < eRes; j++)
1389 if (aa.annotations[j] != null)
1391 if (aa.annotations[j].colour == null)
1392 g.setColor(Color.black);
1394 g.setColor(aa.annotations[j].colour);
1396 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1402 g.fillRect(x, y - height, av.charWidth, height);