2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.event.*;
22 import java.awt.font.LineMetrics;
23 import java.awt.geom.AffineTransform;
24 import java.awt.image.*;
25 import java.util.Hashtable;
29 import com.stevesoft.pat.Regex;
31 import jalview.analysis.AAFrequency;
32 import jalview.datamodel.*;
33 import jalview.schemes.ColourSchemeI;
41 public class AnnotationPanel extends JPanel implements MouseListener,
42 MouseMotionListener, ActionListener, AdjustmentListener
44 final String HELIX = "Helix";
46 final String SHEET = "Sheet";
49 * For RNA secondary structure "stems" aka helices
51 final String STEM = "RNA Helix";
53 final String LABEL = "Label";
55 final String REMOVE = "Remove Annotation";
57 final String COLOUR = "Colour";
59 final Color HELIX_COLOUR = Color.red.darker();
61 final Color SHEET_COLOUR = Color.green.darker().darker();
63 final Color STEM_COLOUR = Color.blue.darker();
74 BufferedImage fadedImage;
82 boolean fastPaint = false;
84 // Used For mouse Dragging and resizing graphs
85 int graphStretch = -1;
87 int graphStretchY = -1;
89 int min; // used by mouseDragged to see if user
91 int max; // used by mouseDragged to see if user
93 boolean mouseDragging = false;
98 * Creates a new AnnotationPanel object.
103 public AnnotationPanel(AlignmentPanel ap)
106 MAC = new jalview.util.Platform().isAMac();
108 ToolTipManager.sharedInstance().registerComponent(this);
109 ToolTipManager.sharedInstance().setInitialDelay(0);
110 ToolTipManager.sharedInstance().setDismissDelay(10000);
113 this.setLayout(null);
114 addMouseListener(this);
115 addMouseMotionListener(this);
116 ap.annotationScroller.getVerticalScrollBar()
117 .addAdjustmentListener(this);
120 public AnnotationPanel(AlignViewport av)
131 public void adjustmentValueChanged(AdjustmentEvent evt)
133 ap.alabels.setScrollOffset(-evt.getValue());
137 * Calculates the height of the annotation displayed in the annotation panel.
138 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
139 * all annotation associated components are updated correctly.
142 public int adjustPanelHeight()
144 int height=calcPanelHeight();
145 this.setPreferredSize(new Dimension(1, height));
148 // revalidate only when the alignment panel is fully constructed
156 * calculate the height for visible annotation, revalidating bounds where necessary
157 * ABSTRACT GUI METHOD
158 * @return total height of annotation
160 public int calcPanelHeight()
162 // setHeight of panels
163 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
168 for (int i = 0; i < aa.length; i++)
172 System.err.println("Null annotation row: ignoring.");
184 aa[i].height += av.charHeight;
194 aa[i].height += aa[i].graphHeight;
197 if (aa[i].height == 0)
202 height += aa[i].height;
219 public void actionPerformed(ActionEvent evt)
221 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
226 Annotation[] anot = aa[activeRow].annotations;
228 if (anot.length < av.getColumnSelection().getMax())
230 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
231 System.arraycopy(anot, 0, temp, 0, anot.length);
233 aa[activeRow].annotations = anot;
236 if (evt.getActionCommand().equals(REMOVE))
238 for (int i = 0; i < av.getColumnSelection().size(); i++)
240 anot[av.getColumnSelection().columnAt(i)] = null;
243 else if (evt.getActionCommand().equals(LABEL))
245 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
246 String label = JOptionPane.showInputDialog(this, "Enter label",
254 if ((label.length() > 0) && !aa[activeRow].hasText)
256 aa[activeRow].hasText = true;
259 for (int i = 0; i < av.getColumnSelection().size(); i++)
261 int index = av.getColumnSelection().columnAt(i);
263 if (!av.colSel.isVisible(index))
266 if (anot[index] == null)
268 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
275 anot[index].displayCharacter = label;
279 else if (evt.getActionCommand().equals(COLOUR))
281 Color col = JColorChooser.showDialog(this,
282 "Choose foreground colour", Color.black);
284 for (int i = 0; i < av.getColumnSelection().size(); i++)
286 int index = av.getColumnSelection().columnAt(i);
288 if (!av.colSel.isVisible(index))
291 if (anot[index] == null)
293 anot[index] = new Annotation("", "", ' ', 0);
296 anot[index].colour = col;
303 String symbol = "\u03B1";
305 if (evt.getActionCommand().equals(HELIX))
309 else if (evt.getActionCommand().equals(SHEET))
315 // Added by LML to color stems
316 else if (evt.getActionCommand().equals(STEM))
322 if (!aa[activeRow].hasIcons)
324 aa[activeRow].hasIcons = true;
327 String label = JOptionPane.showInputDialog(
328 "Enter a label for the structure?", symbol);
335 if ((label.length() > 0) && !aa[activeRow].hasText)
337 aa[activeRow].hasText = true;
340 for (int i = 0; i < av.getColumnSelection().size(); i++)
342 int index = av.getColumnSelection().columnAt(i);
344 if (!av.colSel.isVisible(index))
347 if (anot[index] == null)
349 anot[index] = new Annotation(label, "", type, 0);
352 anot[index].secondaryStructure = type;
353 anot[index].displayCharacter = label;
363 private String collectAnnotVals(Annotation[] anot,
364 ColumnSelection columnSelection, String label2)
366 String collatedInput = "";
368 for (int i = 0; i < columnSelection.size(); i++)
370 int index = columnSelection.columnAt(i);
371 // always check for current display state - just in case
372 if (!av.colSel.isVisible(index))
374 String tlabel = null;
375 if (anot[index] != null)
376 { // LML added stem code
377 if (label2.equals(HELIX) || label2.equals(SHEET)
378 || label2.equals(STEM) || label2.equals(LABEL))
380 tlabel = anot[index].description;
381 if (tlabel == null || tlabel.length() < 1)
383 if (label2.equals(HELIX) || label2.equals(SHEET)
384 || label2.equals(STEM))
386 tlabel = "" + anot[index].secondaryStructure;
390 tlabel = "" + anot[index].displayCharacter;
394 if (tlabel != null && !tlabel.equals(last))
396 if (last.length() > 0)
398 collatedInput += " ";
400 collatedInput += tlabel;
404 return collatedInput;
413 public void mousePressed(MouseEvent evt)
416 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
425 for (int i = 0; i < aa.length; i++)
429 height += aa[i].height;
432 if (evt.getY() < height)
438 else if (aa[i].graph > 0)
442 graphStretchY = evt.getY();
449 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
451 if (av.getColumnSelection() == null)
456 JPopupMenu pop = new JPopupMenu("Structure type");
457 JMenuItem item = new JMenuItem(HELIX);
458 item.addActionListener(this);
460 item = new JMenuItem(SHEET);
461 item.addActionListener(this);
463 item = new JMenuItem(STEM);
464 item.addActionListener(this);
466 item = new JMenuItem(LABEL);
467 item.addActionListener(this);
469 item = new JMenuItem(COLOUR);
470 item.addActionListener(this);
472 item = new JMenuItem(REMOVE);
473 item.addActionListener(this);
475 pop.show(this, evt.getX(), evt.getY());
485 ap.scalePanel.mousePressed(evt);
495 public void mouseReleased(MouseEvent evt)
499 mouseDragging = false;
500 ap.scalePanel.mouseReleased(evt);
509 public void mouseEntered(MouseEvent evt)
511 ap.scalePanel.mouseEntered(evt);
520 public void mouseExited(MouseEvent evt)
522 ap.scalePanel.mouseExited(evt);
531 public void mouseDragged(MouseEvent evt)
533 if (graphStretch > -1)
535 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
537 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
539 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
541 graphStretchY = evt.getY();
543 ap.paintAlignment(true);
547 ap.scalePanel.mouseDragged(evt);
557 public void mouseMoved(MouseEvent evt)
559 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
563 this.setToolTipText(null);
570 for (int i = 0; i < aa.length; i++)
574 height += aa[i].height;
577 if (evt.getY() < height)
587 this.setToolTipText(null);
591 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
593 if (av.hasHiddenColumns)
595 res = av.getColumnSelection().adjustForHiddenColumns(res);
598 if (row > -1 && aa[row].annotations != null
599 && res < (int) aa[row].annotations.length)
601 if (aa[row].graphGroup > -1)
603 StringBuffer tip = new StringBuffer("<html>");
604 for (int gg = 0; gg < aa.length; gg++)
606 if (aa[gg].graphGroup == aa[row].graphGroup
607 && aa[gg].annotations[res] != null)
609 tip.append(aa[gg].label + " "
610 + aa[gg].annotations[res].description + "<br>");
613 if (tip.length() != 6)
615 tip.setLength(tip.length() - 4);
616 this.setToolTipText(tip.toString() + "</html>");
619 else if (aa[row].annotations[res] != null
620 && aa[row].annotations[res].description != null
621 && aa[row].annotations[res].description.length() > 0)
623 this.setToolTipText(aa[row].annotations[res].description);
627 // clear the tooltip.
628 this.setToolTipText(null);
631 if (aa[row].annotations[res] != null)
633 StringBuffer text = new StringBuffer("Sequence position "
636 if (aa[row].annotations[res].description != null)
638 text.append(" " + aa[row].annotations[res].description);
641 ap.alignFrame.statusBar.setText(text.toString());
646 this.setToolTipText(null);
656 public void mouseClicked(MouseEvent evt)
666 public void paintComponent(Graphics g)
668 g.setColor(Color.white);
669 g.fillRect(0, 0, getWidth(), getHeight());
673 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
674 || (getVisibleRect().height != g.getClipBounds().height))
676 g.drawImage(image, 0, 0, this);
681 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
684 if (image == null || imgWidth != image.getWidth()
685 || image.getHeight(this) != getHeight())
687 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
688 BufferedImage.TYPE_INT_RGB);
689 gg = (Graphics2D) image.getGraphics();
693 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
694 RenderingHints.VALUE_ANTIALIAS_ON);
697 gg.setFont(av.getFont());
698 fm = gg.getFontMetrics();
699 gg.setColor(Color.white);
700 gg.fillRect(0, 0, imgWidth, image.getHeight());
703 drawComponent(gg, av.startRes, av.endRes + 1);
704 g.drawImage(image, 0, 0, this);
708 * non-Thread safe repaint
711 * repaint with horizontal shift in alignment
713 public void fastPaint(int horizontal)
716 if ((horizontal == 0) || gg == null
717 || av.alignment.getAlignmentAnnotation() == null
718 || av.alignment.getAlignmentAnnotation().length < 1
719 || av.updatingConsensus || av.updatingConservation)
724 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
726 int sr = av.startRes;
727 int er = av.endRes + 1;
730 if (horizontal > 0) // scrollbar pulled right, image to the left
732 transX = (er - sr - horizontal) * av.charWidth;
733 sr = er - horizontal;
735 else if (horizontal < 0)
737 er = sr - horizontal;
740 gg.translate(transX, 0);
742 drawComponent(gg, sr, er);
744 gg.translate(-transX, 0);
761 public void drawComponent(Graphics g, int startRes, int endRes)
763 if (av.updatingConsensus || av.updatingConservation)
769 // We'll keep a record of the old image,
770 // and draw a faded image until the calculation
772 if (fadedImage == null || fadedImage.getWidth() != imgWidth
773 || fadedImage.getHeight() != image.getHeight())
775 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
776 BufferedImage.TYPE_INT_RGB);
778 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
780 fadedG.setColor(Color.white);
781 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
783 fadedG.setComposite(AlphaComposite.getInstance(
784 AlphaComposite.SRC_OVER, .3f));
785 fadedG.drawImage(image, 0, 0, this);
795 g.setColor(Color.white);
796 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
798 g.setFont(av.getFont());
801 fm = g.getFontMetrics();
804 if ((av.alignment.getAlignmentAnnotation() == null)
805 || (av.alignment.getAlignmentAnnotation().length < 1))
807 g.setColor(Color.white);
808 g.fillRect(0, 0, getWidth(), getHeight());
809 g.setColor(Color.black);
810 if (av.validCharWidth)
812 g.drawString("Alignment has no annotations", 20, 15);
818 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
825 boolean validRes = false;
826 boolean validEnd = false;
827 boolean labelAllCols = false;
828 boolean centreColLabels, centreColLabelsDef = av
829 .getCentreColumnLabels();
830 boolean scaleColLabel = false;
831 boolean[] graphGroupDrawn = new boolean[aa.length];
832 int charOffset = 0; // offset for a label
833 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
835 Font ofont = g.getFont();
837 for (int i = 0; i < aa.length; i++)
839 AlignmentAnnotation row = aa[i];
845 centreColLabels = row.centreColLabels || centreColLabelsDef;
846 labelAllCols = row.showAllColLabels;
847 scaleColLabel = row.scaleColLabel;
853 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
858 // this is so that we draw the characters below the graph
863 iconOffset = av.charHeight - fm.getDescent();
867 else if (row.hasText)
869 iconOffset = av.charHeight - fm.getDescent();
877 if (av.updatingConsensus && aa[i] == av.consensus)
881 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
882 - row.height, imgWidth, y, this);
883 g.setColor(Color.black);
884 // g.drawString("Calculating Consensus....",20, y-row.height/2);
888 else if (av.updatingConservation
889 && aa[i].label.equals("Conservation"))
893 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
894 - row.height, imgWidth, y, this);
896 g.setColor(Color.black);
897 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
901 else if (av.updatingConservation && aa[i].label.equals("Quality"))
905 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
906 - row.height, imgWidth, y, this);
907 g.setColor(Color.black);
908 // / g.drawString("Calculating Quality....",20, y-row.height/2);
914 while (x < endRes - startRes)
916 if (av.hasHiddenColumns)
918 column = av.getColumnSelection().adjustForHiddenColumns(
920 if (column > row.annotations.length - 1)
927 column = startRes + x;
930 if ((row.annotations == null) || (row.annotations.length <= column)
931 || (row.annotations[column] == null))
942 g.setColor(Color.red);
944 if (av.getColumnSelection() != null)
946 for (int n = 0; n < av.getColumnSelection().size(); n++)
948 int v = av.getColumnSelection().columnAt(n);
952 g.fillRect(x * av.charWidth, y, av.charWidth, av.charHeight);
958 if (av.validCharWidth && validRes
959 && row.annotations[column].displayCharacter != null
960 && (row.annotations[column].displayCharacter.length() > 0))
963 if (centreColLabels || scaleColLabel)
965 fmWidth = (float) fm.charsWidth(
966 row.annotations[column].displayCharacter.toCharArray(),
967 0, row.annotations[column].displayCharacter.length());
971 // justify the label and scale to fit in column
972 if (fmWidth > av.charWidth)
974 // scale only if the current font isn't already small enough
975 fmScaling = av.charWidth;
976 fmScaling /= fmWidth;
977 g.setFont(ofont.deriveFont(AffineTransform
978 .getScaleInstance(fmScaling, 1.0)));
979 // and update the label's width to reflect the scaling.
980 fmWidth = av.charWidth;
987 .charWidth(row.annotations[column].displayCharacter
990 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
992 if (row.annotations[column].colour == null)
993 g.setColor(Color.black);
995 g.setColor(row.annotations[column].colour);
997 if (column == 0 || row.graph > 0)
999 g.drawString(row.annotations[column].displayCharacter,
1000 (x * av.charWidth) + charOffset, y + iconOffset);
1002 else if (row.annotations[column - 1] == null
1004 || !row.annotations[column].displayCharacter
1005 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
1006 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
1008 g.drawString(row.annotations[column].displayCharacter, x
1009 * av.charWidth + charOffset, y + iconOffset);
1017 || (row.annotations[column].secondaryStructure != lastSS))
1022 g.setColor(HELIX_COLOUR);
1025 // Off by 1 offset when drawing rects and ovals
1026 // to offscreen image on the MAC
1027 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
1028 (x * av.charWidth) - lastSSX, 7, 8, 8);
1032 int sCol = (lastSSX / av.charWidth) + startRes;
1034 int x2 = (x * av.charWidth);
1037 || row.annotations[sCol - 1] == null
1038 || row.annotations[sCol - 1].secondaryStructure != 'H')
1040 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
1042 x1 += av.charWidth / 2;
1045 if (!validRes || row.annotations[column] == null
1046 || row.annotations[column].secondaryStructure != 'H')
1048 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1049 + iconOffset, av.charWidth, 8, 270, 180);
1050 x2 -= av.charWidth / 2;
1053 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1057 g.setColor(SHEET_COLOUR);
1058 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1060 g.fillPolygon(new int[]
1061 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1062 (x * av.charWidth) }, new int[]
1063 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1068 case 'S': // Stem case for RNA secondary structure
1069 g.setColor(STEM_COLOUR); // row.annotations[column].colour for By
1070 // RNA Helices colouring
1071 // System.out.println("last SSX displayx" +
1072 // row.annotations[column-1].displayCharacter +"x");
1073 Regex closeparen = new Regex("(\\))");
1075 //If a closing base pair half of the stem, display a backward arrow
1077 .search(row.annotations[column - 1].displayCharacter))// row.annotations[column-1].displayCharacter))
1079 g.fillPolygon(new int[]
1080 { lastSSX + 5, lastSSX + 5, lastSSX },
1082 { y + iconOffset, y + 14 + iconOffset,
1083 y + 8 + iconOffset }, 3);
1084 g.fillRect(lastSSX + 2, y + 4 + iconOffset,
1085 (x * av.charWidth) - lastSSX - 2, 7);
1087 else //display a forward arrow
1089 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1091 g.fillPolygon(new int[]
1092 { (x * av.charWidth) - 5, (x * av.charWidth) - 5,
1093 (x * av.charWidth) },
1095 { y + iconOffset, y + 14 + iconOffset,
1096 y + 8 + iconOffset }, 3);
1101 g.setColor(Color.gray);
1102 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1110 lastSS = row.annotations[column].secondaryStructure;
1117 lastSSX = (x * av.charWidth);
1125 if (column >= row.annotations.length)
1127 column = row.annotations.length - 1;
1142 g.setColor(HELIX_COLOUR);
1145 // Off by 1 offset when drawing rects and ovals
1146 // to offscreen image on the MAC
1147 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1148 - lastSSX, 7, 8, 8);
1152 int sCol = (lastSSX / av.charWidth) + startRes;
1154 int x2 = (x * av.charWidth);
1156 if (sCol == 0 || row.annotations[sCol - 1] == null
1157 || row.annotations[sCol - 1].secondaryStructure != 'H')
1159 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
1160 x1 += av.charWidth / 2;
1163 if (row.annotations[column] == null
1164 || row.annotations[column].secondaryStructure != 'H')
1166 g.fillArc((x * av.charWidth) - av.charWidth,
1167 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1168 x2 -= av.charWidth / 2;
1171 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1176 g.setColor(SHEET_COLOUR);
1178 if (!validEnd || row.annotations[endRes] == null
1179 || row.annotations[endRes].secondaryStructure != 'E')
1181 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1183 g.fillPolygon(new int[]
1184 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1185 (x * av.charWidth) }, new int[]
1186 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1190 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1196 g.setColor(Color.gray);
1197 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1204 if (row.graph > 0 && row.graphHeight > 0)
1206 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1208 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1210 float groupmax = -999999, groupmin = 9999999;
1211 for (int gg = 0; gg < aa.length; gg++)
1213 if (aa[gg].graphGroup != row.graphGroup)
1220 aa[gg].visible = false;
1223 if (aa[gg].graphMax > groupmax)
1225 groupmax = aa[gg].graphMax;
1227 if (aa[gg].graphMin < groupmin)
1229 groupmin = aa[gg].graphMin;
1233 for (int gg = 0; gg < aa.length; gg++)
1235 if (aa[gg].graphGroup == row.graphGroup)
1237 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1238 groupmax, row.graphHeight);
1242 graphGroupDrawn[row.graphGroup] = true;
1246 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1247 row.graphMax, row.graphHeight);
1250 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1252 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1257 if (row.graph > 0 && row.hasText)
1269 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1270 int eRes, int y, float min, float max, int graphHeight)
1272 if (sRes > aa.annotations.length)
1279 // Adjustment for fastpaint to left
1280 if (eRes < av.endRes)
1285 eRes = Math.min(eRes, aa.annotations.length);
1293 float range = max - min;
1298 y2 = y - (int) ((0 - min / range) * graphHeight);
1301 g.setColor(Color.gray);
1302 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1304 eRes = Math.min(eRes, aa.annotations.length);
1307 int aaMax = aa.annotations.length - 1;
1309 while (x < eRes - sRes)
1312 if (av.hasHiddenColumns)
1314 column = av.getColumnSelection().adjustForHiddenColumns(column);
1322 if (aa.annotations[column] == null
1323 || aa.annotations[column - 1] == null)
1329 if (aa.annotations[column].colour == null)
1330 g.setColor(Color.black);
1332 g.setColor(aa.annotations[column].colour);
1335 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1337 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1339 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1340 + av.charWidth / 2, y2);
1344 if (aa.threshold != null)
1346 g.setColor(aa.threshold.colour);
1347 Graphics2D g2 = (Graphics2D) g;
1348 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1349 BasicStroke.JOIN_ROUND, 3f, new float[]
1352 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1353 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1354 g2.setStroke(new BasicStroke());
1358 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1359 int eRes, float min, float max, int y)
1361 ColourSchemeI profcolour = av.getGlobalColourScheme();
1362 if (profcolour == null)
1364 profcolour = new jalview.schemes.ZappoColourScheme();
1366 if (sRes > aa.annotations.length)
1370 Font ofont = g.getFont();
1371 eRes = Math.min(eRes, aa.annotations.length);
1373 int x = 0, y1 = y, y2 = y;
1375 float range = max - min;
1379 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1382 g.setColor(Color.gray);
1384 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1387 int aaMax = aa.annotations.length - 1;
1388 boolean renderHistogram = true, renderProfile = true;
1389 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1391 // TODO: generalise this to have render styles for consensus/profile data
1392 if (aa.groupRef != null)
1394 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1395 renderProfile = aa.groupRef.isShowSequenceLogo();
1399 renderHistogram = av.isShowConsensusHistogram();
1400 renderProfile = av.isShowSequenceLogo();
1403 while (x < eRes - sRes)
1406 if (av.hasHiddenColumns)
1408 column = av.getColumnSelection().adjustForHiddenColumns(column);
1416 if (aa.annotations[column] == null)
1421 if (aa.annotations[column].colour == null)
1422 g.setColor(Color.black);
1424 g.setColor(aa.annotations[column].colour);
1427 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1429 if (renderHistogram)
1433 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1437 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1440 // draw profile if available
1441 if (renderProfile && aa.annotations[column].value != 0)
1443 int profl[] = getProfileFor(aa, column);
1444 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1447 char[] dc = new char[1];
1449 for (int c = 1; profl != null && c < profl[0];)
1451 dc[0] = (char) profl[c++];
1452 wdth = av.charWidth;
1453 wdth /= (float) fm.charsWidth(dc, 0, 1);
1460 // if (aa.annotations[column].value==0) {
1461 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1462 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1463 // ht = y2-(int)ht2;
1465 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1466 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1468 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1471 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1472 // ? );// try to get a
1473 // colourscheme for the
1474 // group(aa.groupRef.cs==null)
1475 // ? av.textColour2 :
1476 // cs.findColour(dc));
1477 g.drawChars(dc, 0, 1, x * av.charWidth,
1478 (int) (ht + lm.getHeight()));
1479 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1486 if (aa.threshold != null)
1488 g.setColor(aa.threshold.colour);
1489 Graphics2D g2 = (Graphics2D) g;
1490 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1491 BasicStroke.JOIN_ROUND, 3f, new float[]
1494 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1495 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1496 g2.setStroke(new BasicStroke());
1500 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1502 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1504 if (aa.groupRef != null && aa.groupRef.consensusData != null
1505 && aa.groupRef.isShowSequenceLogo())
1507 return AAFrequency.extractProfile(
1508 aa.groupRef.consensusData[column],
1509 aa.groupRef.getIgnoreGapsConsensus());
1511 // TODO extend annotation row to enable dynamic and static profile data to
1513 if (aa.groupRef == null && aa.sequenceRef == null
1514 && av.isShowSequenceLogo())
1516 return AAFrequency.extractProfile(av.hconsensus[column],
1517 av.getIgnoreGapsConsensus());
1523 // used by overview window
1524 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1525 int y, int sRes, int eRes)
1527 eRes = Math.min(eRes, aa.annotations.length);
1528 g.setColor(Color.white);
1529 g.fillRect(0, 0, width, y);
1530 g.setColor(new Color(0, 0, 180));
1534 for (int j = sRes; j < eRes; j++)
1536 if (aa.annotations[j] != null)
1538 if (aa.annotations[j].colour == null)
1539 g.setColor(Color.black);
1541 g.setColor(aa.annotations[j].colour);
1543 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1549 g.fillRect(x, y - height, av.charWidth, height);