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 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;
184 this.setPreferredSize(new Dimension(1, height));
187 // revalidate only when the alignment panel is fully constructed
200 public void actionPerformed(ActionEvent evt)
202 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
207 Annotation[] anot = aa[activeRow].annotations;
209 if (anot.length < av.getColumnSelection().getMax())
211 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
212 System.arraycopy(anot, 0, temp, 0, anot.length);
214 aa[activeRow].annotations = anot;
217 if (evt.getActionCommand().equals(REMOVE))
219 for (int i = 0; i < av.getColumnSelection().size(); i++)
221 anot[av.getColumnSelection().columnAt(i)] = null;
224 else if (evt.getActionCommand().equals(LABEL))
226 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
227 String label = JOptionPane.showInputDialog(this, "Enter label",
235 if ((label.length() > 0) && !aa[activeRow].hasText)
237 aa[activeRow].hasText = true;
240 for (int i = 0; i < av.getColumnSelection().size(); i++)
242 int index = av.getColumnSelection().columnAt(i);
244 if (!av.colSel.isVisible(index))
247 if (anot[index] == null)
249 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
256 anot[index].displayCharacter = label;
260 else if (evt.getActionCommand().equals(COLOUR))
262 Color col = JColorChooser.showDialog(this,
263 "Choose foreground colour", Color.black);
265 for (int i = 0; i < av.getColumnSelection().size(); i++)
267 int index = av.getColumnSelection().columnAt(i);
269 if (!av.colSel.isVisible(index))
272 if (anot[index] == null)
274 anot[index] = new Annotation("", "", ' ', 0);
277 anot[index].colour = col;
284 String symbol = "\u03B1";
286 if (evt.getActionCommand().equals(HELIX))
290 else if (evt.getActionCommand().equals(SHEET))
296 if (!aa[activeRow].hasIcons)
298 aa[activeRow].hasIcons = true;
301 String label = JOptionPane.showInputDialog(
302 "Enter a label for the structure?", symbol);
309 if ((label.length() > 0) && !aa[activeRow].hasText)
311 aa[activeRow].hasText = true;
314 for (int i = 0; i < av.getColumnSelection().size(); i++)
316 int index = av.getColumnSelection().columnAt(i);
318 if (!av.colSel.isVisible(index))
321 if (anot[index] == null)
323 anot[index] = new Annotation(label, "", type, 0);
326 anot[index].secondaryStructure = type;
327 anot[index].displayCharacter = label;
337 private String collectAnnotVals(Annotation[] anot,
338 ColumnSelection columnSelection, String label2)
340 String collatedInput = "";
342 for (int i = 0; i < columnSelection.size(); i++)
344 int index = columnSelection.columnAt(i);
345 // always check for current display state - just in case
346 if (!av.colSel.isVisible(index))
348 String tlabel = null;
349 if (anot[index] != null)
351 if (label2.equals(HELIX) || label2.equals(SHEET)
352 || label2.equals(LABEL))
354 tlabel = anot[index].description;
355 if (tlabel == null || tlabel.length() < 1)
357 if (label2.equals(HELIX) || label2.equals(SHEET))
359 tlabel = "" + anot[index].secondaryStructure;
363 tlabel = "" + anot[index].displayCharacter;
367 if (tlabel != null && !tlabel.equals(last))
369 if (last.length() > 0)
371 collatedInput += " ";
373 collatedInput += tlabel;
377 return collatedInput;
386 public void mousePressed(MouseEvent evt)
389 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
398 for (int i = 0; i < aa.length; i++)
402 height += aa[i].height;
405 if (evt.getY() < height)
411 else if (aa[i].graph > 0)
415 graphStretchY = evt.getY();
422 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
424 if (av.getColumnSelection() == null)
429 JPopupMenu pop = new JPopupMenu("Structure type");
430 JMenuItem item = new JMenuItem(HELIX);
431 item.addActionListener(this);
433 item = new JMenuItem(SHEET);
434 item.addActionListener(this);
436 item = new JMenuItem(LABEL);
437 item.addActionListener(this);
439 item = new JMenuItem(COLOUR);
440 item.addActionListener(this);
442 item = new JMenuItem(REMOVE);
443 item.addActionListener(this);
445 pop.show(this, evt.getX(), evt.getY());
455 ap.scalePanel.mousePressed(evt);
465 public void mouseReleased(MouseEvent evt)
469 mouseDragging = false;
470 ap.scalePanel.mouseReleased(evt);
479 public void mouseEntered(MouseEvent evt)
481 ap.scalePanel.mouseEntered(evt);
490 public void mouseExited(MouseEvent evt)
492 ap.scalePanel.mouseExited(evt);
501 public void mouseDragged(MouseEvent evt)
503 if (graphStretch > -1)
505 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
507 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
509 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
511 graphStretchY = evt.getY();
513 ap.paintAlignment(true);
517 ap.scalePanel.mouseDragged(evt);
527 public void mouseMoved(MouseEvent evt)
529 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
533 this.setToolTipText(null);
540 for (int i = 0; i < aa.length; i++)
544 height += aa[i].height;
547 if (evt.getY() < height)
557 this.setToolTipText(null);
561 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
563 if (av.hasHiddenColumns)
565 res = av.getColumnSelection().adjustForHiddenColumns(res);
568 if (row > -1 && aa[row].annotations != null
569 && res < (int) aa[row].annotations.length)
571 if (aa[row].graphGroup > -1)
573 StringBuffer tip = new StringBuffer("<html>");
574 for (int gg = 0; gg < aa.length; gg++)
576 if (aa[gg].graphGroup == aa[row].graphGroup
577 && aa[gg].annotations[res] != null)
579 tip.append(aa[gg].label + " "
580 + aa[gg].annotations[res].description + "<br>");
583 if (tip.length() != 6)
585 tip.setLength(tip.length() - 4);
586 this.setToolTipText(tip.toString() + "</html>");
589 else if (aa[row].annotations[res] != null
590 && aa[row].annotations[res].description != null
591 && aa[row].annotations[res].description.length() > 0)
593 this.setToolTipText(aa[row].annotations[res].description);
597 // clear the tooltip.
598 this.setToolTipText(null);
601 if (aa[row].annotations[res] != null)
603 StringBuffer text = new StringBuffer("Sequence position "
606 if (aa[row].annotations[res].description != null)
608 text.append(" " + aa[row].annotations[res].description);
611 ap.alignFrame.statusBar.setText(text.toString());
616 this.setToolTipText(null);
626 public void mouseClicked(MouseEvent evt)
636 public void paintComponent(Graphics g)
638 g.setColor(Color.white);
639 g.fillRect(0, 0, getWidth(), getHeight());
643 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
644 || (getVisibleRect().height != g.getClipBounds().height))
646 g.drawImage(image, 0, 0, this);
651 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
654 if (image == null || imgWidth != image.getWidth()
655 || image.getHeight(this) != getHeight())
657 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
658 BufferedImage.TYPE_INT_RGB);
659 gg = (Graphics2D) image.getGraphics();
663 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
664 RenderingHints.VALUE_ANTIALIAS_ON);
667 gg.setFont(av.getFont());
668 fm = gg.getFontMetrics();
669 gg.setColor(Color.white);
670 gg.fillRect(0, 0, imgWidth, image.getHeight());
673 drawComponent(gg, av.startRes, av.endRes + 1);
674 g.drawImage(image, 0, 0, this);
678 * non-Thread safe repaint
681 * repaint with horizontal shift in alignment
683 public void fastPaint(int horizontal)
686 if ((horizontal == 0) || gg == null
687 || av.alignment.getAlignmentAnnotation() == null
688 || av.alignment.getAlignmentAnnotation().length < 1
689 || av.updatingConsensus || av.updatingConservation)
694 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
696 int sr = av.startRes;
697 int er = av.endRes + 1;
700 if (horizontal > 0) // scrollbar pulled right, image to the left
702 transX = (er - sr - horizontal) * av.charWidth;
703 sr = er - horizontal;
705 else if (horizontal < 0)
707 er = sr - horizontal;
710 gg.translate(transX, 0);
712 drawComponent(gg, sr, er);
714 gg.translate(-transX, 0);
731 public void drawComponent(Graphics g, int startRes, int endRes)
733 if (av.updatingConsensus || av.updatingConservation)
739 // We'll keep a record of the old image,
740 // and draw a faded image until the calculation
742 if (fadedImage == null || fadedImage.getWidth() != imgWidth
743 || fadedImage.getHeight() != image.getHeight())
745 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
746 BufferedImage.TYPE_INT_RGB);
748 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
750 fadedG.setColor(Color.white);
751 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
753 fadedG.setComposite(AlphaComposite.getInstance(
754 AlphaComposite.SRC_OVER, .3f));
755 fadedG.drawImage(image, 0, 0, this);
765 g.setColor(Color.white);
766 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
768 g.setFont(av.getFont());
771 fm = g.getFontMetrics();
774 if ((av.alignment.getAlignmentAnnotation() == null)
775 || (av.alignment.getAlignmentAnnotation().length < 1))
777 g.setColor(Color.white);
778 g.fillRect(0, 0, getWidth(), getHeight());
779 g.setColor(Color.black);
780 if (av.validCharWidth)
782 g.drawString("Alignment has no annotations", 20, 15);
788 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
795 boolean validRes = false;
796 boolean validEnd = false;
797 boolean labelAllCols = false;
798 boolean centreColLabels, centreColLabelsDef = av
799 .getCentreColumnLabels();
800 boolean scaleColLabel = false;
801 boolean[] graphGroupDrawn = new boolean[aa.length];
802 int charOffset = 0; // offset for a label
803 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
805 Font ofont = g.getFont();
807 for (int i = 0; i < aa.length; i++)
809 AlignmentAnnotation row = aa[i];
815 centreColLabels = row.centreColLabels || centreColLabelsDef;
816 labelAllCols = row.showAllColLabels;
817 scaleColLabel = row.scaleColLabel;
823 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
828 // this is so that we draw the characters below the graph
833 iconOffset = av.charHeight - fm.getDescent();
837 else if (row.hasText)
839 iconOffset = av.charHeight - fm.getDescent();
847 if (av.updatingConsensus && aa[i] == av.consensus)
851 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
852 - row.height, imgWidth, y, this);
853 g.setColor(Color.black);
854 // g.drawString("Calculating Consensus....",20, y-row.height/2);
858 else if (av.updatingConservation
859 && aa[i].label.equals("Conservation"))
863 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
864 - row.height, imgWidth, y, this);
866 g.setColor(Color.black);
867 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
871 else if (av.updatingConservation && aa[i].label.equals("Quality"))
875 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
876 - row.height, imgWidth, y, this);
877 g.setColor(Color.black);
878 // / g.drawString("Calculating Quality....",20, y-row.height/2);
884 while (x < endRes - startRes)
886 if (av.hasHiddenColumns)
888 column = av.getColumnSelection().adjustForHiddenColumns(
890 if (column > row.annotations.length - 1)
897 column = startRes + x;
900 if ((row.annotations == null) || (row.annotations.length <= column)
901 || (row.annotations[column] == null))
912 g.setColor(Color.red);
914 if (av.getColumnSelection() != null)
916 for (int n = 0; n < av.getColumnSelection().size(); n++)
918 int v = av.getColumnSelection().columnAt(n);
922 g.fillRect(x * av.charWidth, y, av.charWidth, av.charHeight);
928 if (av.validCharWidth && validRes
929 && row.annotations[column].displayCharacter != null
930 && (row.annotations[column].displayCharacter.length() > 0))
933 if (centreColLabels || scaleColLabel)
935 fmWidth = (float) fm.charsWidth(
936 row.annotations[column].displayCharacter.toCharArray(),
937 0, row.annotations[column].displayCharacter.length());
941 // justify the label and scale to fit in column
942 if (fmWidth > av.charWidth)
944 // scale only if the current font isn't already small enough
945 fmScaling = av.charWidth;
946 fmScaling /= fmWidth;
947 g.setFont(ofont.deriveFont(AffineTransform
948 .getScaleInstance(fmScaling, 1.0)));
949 // and update the label's width to reflect the scaling.
950 fmWidth = av.charWidth;
957 .charWidth(row.annotations[column].displayCharacter
960 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
962 if (row.annotations[column].colour == null)
963 g.setColor(Color.black);
965 g.setColor(row.annotations[column].colour);
967 if (column == 0 || row.graph > 0)
969 g.drawString(row.annotations[column].displayCharacter,
970 (x * av.charWidth) + charOffset, y + iconOffset);
972 else if (row.annotations[column - 1] == null
974 || !row.annotations[column].displayCharacter
975 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
976 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
978 g.drawString(row.annotations[column].displayCharacter, x
979 * av.charWidth + charOffset, y + iconOffset);
987 || (row.annotations[column].secondaryStructure != lastSS))
992 g.setColor(HELIX_COLOUR);
995 // Off by 1 offset when drawing rects and ovals
996 // to offscreen image on the MAC
997 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
998 (x * av.charWidth) - lastSSX, 7, 8, 8);
1002 int sCol = (lastSSX / av.charWidth) + startRes;
1004 int x2 = (x * av.charWidth);
1007 || row.annotations[sCol - 1] == null
1008 || row.annotations[sCol - 1].secondaryStructure != 'H')
1010 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
1012 x1 += av.charWidth / 2;
1015 if (!validRes || row.annotations[column] == null
1016 || row.annotations[column].secondaryStructure != 'H')
1018 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1019 + iconOffset, av.charWidth, 8, 270, 180);
1020 x2 -= av.charWidth / 2;
1023 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1027 g.setColor(SHEET_COLOUR);
1028 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1030 g.fillPolygon(new int[]
1031 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1032 (x * av.charWidth) }, new int[]
1033 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1039 g.setColor(Color.gray);
1040 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1048 lastSS = row.annotations[column].secondaryStructure;
1055 lastSSX = (x * av.charWidth);
1063 if (column >= row.annotations.length)
1065 column = row.annotations.length - 1;
1080 g.setColor(HELIX_COLOUR);
1083 // Off by 1 offset when drawing rects and ovals
1084 // to offscreen image on the MAC
1085 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1086 - lastSSX, 7, 8, 8);
1090 int sCol = (lastSSX / av.charWidth) + startRes;
1092 int x2 = (x * av.charWidth);
1094 if (sCol == 0 || row.annotations[sCol - 1] == null
1095 || row.annotations[sCol - 1].secondaryStructure != 'H')
1097 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
1098 x1 += av.charWidth / 2;
1101 if (row.annotations[column] == null
1102 || row.annotations[column].secondaryStructure != 'H')
1104 g.fillArc((x * av.charWidth) - av.charWidth,
1105 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1106 x2 -= av.charWidth / 2;
1109 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1114 g.setColor(SHEET_COLOUR);
1116 if (!validEnd || row.annotations[endRes] == null
1117 || row.annotations[endRes].secondaryStructure != 'E')
1119 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1121 g.fillPolygon(new int[]
1122 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1123 (x * av.charWidth) }, new int[]
1124 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1128 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1134 g.setColor(Color.gray);
1135 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1142 if (row.graph > 0 && row.graphHeight > 0)
1144 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1146 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1148 float groupmax = -999999, groupmin = 9999999;
1149 for (int gg = 0; gg < aa.length; gg++)
1151 if (aa[gg].graphGroup != row.graphGroup)
1158 aa[gg].visible = false;
1161 if (aa[gg].graphMax > groupmax)
1163 groupmax = aa[gg].graphMax;
1165 if (aa[gg].graphMin < groupmin)
1167 groupmin = aa[gg].graphMin;
1171 for (int gg = 0; gg < aa.length; gg++)
1173 if (aa[gg].graphGroup == row.graphGroup)
1175 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1176 groupmax, row.graphHeight);
1180 graphGroupDrawn[row.graphGroup] = true;
1184 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1185 row.graphMax, row.graphHeight);
1188 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1190 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1195 if (row.graph > 0 && row.hasText)
1207 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1208 int eRes, int y, float min, float max, int graphHeight)
1210 if (sRes > aa.annotations.length)
1217 // Adjustment for fastpaint to left
1218 if (eRes < av.endRes)
1223 eRes = Math.min(eRes, aa.annotations.length);
1231 float range = max - min;
1236 y2 = y - (int) ((0 - min / range) * graphHeight);
1239 g.setColor(Color.gray);
1240 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1242 eRes = Math.min(eRes, aa.annotations.length);
1245 int aaMax = aa.annotations.length - 1;
1247 while (x < eRes - sRes)
1250 if (av.hasHiddenColumns)
1252 column = av.getColumnSelection().adjustForHiddenColumns(column);
1260 if (aa.annotations[column] == null
1261 || aa.annotations[column - 1] == null)
1267 if (aa.annotations[column].colour == null)
1268 g.setColor(Color.black);
1270 g.setColor(aa.annotations[column].colour);
1273 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1275 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1277 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1278 + av.charWidth / 2, y2);
1282 if (aa.threshold != null)
1284 g.setColor(aa.threshold.colour);
1285 Graphics2D g2 = (Graphics2D) g;
1286 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1287 BasicStroke.JOIN_ROUND, 3f, new float[]
1290 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1291 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1292 g2.setStroke(new BasicStroke());
1296 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1297 int eRes, float min, float max, int y)
1299 ColourSchemeI profcolour = av.getGlobalColourScheme();
1300 if (profcolour == null)
1302 profcolour = new jalview.schemes.ZappoColourScheme();
1304 if (sRes > aa.annotations.length)
1308 Font ofont = g.getFont();
1309 eRes = Math.min(eRes, aa.annotations.length);
1311 int x = 0, y1 = y, y2 = y;
1313 float range = max - min;
1317 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1320 g.setColor(Color.gray);
1322 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1325 int aaMax = aa.annotations.length - 1;
1326 boolean renderHistogram = true, renderProfile = true;
1327 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1329 // TODO: generalise this to have render styles for consensus/profile data
1330 if (aa.groupRef != null)
1332 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1333 renderProfile = aa.groupRef.isShowSequenceLogo();
1337 renderHistogram = av.isShowConsensusHistogram();
1338 renderProfile = av.isShowSequenceLogo();
1341 while (x < eRes - sRes)
1344 if (av.hasHiddenColumns)
1346 column = av.getColumnSelection().adjustForHiddenColumns(column);
1354 if (aa.annotations[column] == null)
1359 if (aa.annotations[column].colour == null)
1360 g.setColor(Color.black);
1362 g.setColor(aa.annotations[column].colour);
1365 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1367 if (renderHistogram)
1371 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1375 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1378 // draw profile if available
1379 if (aa.annotations[column].value != 0 && renderProfile)
1381 int profl[] = getProfileFor(aa, column);
1382 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1385 char[] dc = new char[1];
1387 for (int c = 1; profl != null && c < profl[0];)
1389 dc[0] = (char) profl[c++];
1390 wdth = av.charWidth;
1391 wdth /= (float) fm.charsWidth(dc, 0, 1);
1398 // if (aa.annotations[column].value==0) {
1399 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1400 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1401 // ht = y2-(int)ht2;
1403 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1404 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1406 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1409 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1410 // ? );// try to get a
1411 // colourscheme for the
1412 // group(aa.groupRef.cs==null)
1413 // ? av.textColour2 :
1414 // cs.findColour(dc));
1415 g.drawChars(dc, 0, 1, x * av.charWidth,
1416 (int) (ht + lm.getHeight()));
1417 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1424 if (aa.threshold != null)
1426 g.setColor(aa.threshold.colour);
1427 Graphics2D g2 = (Graphics2D) g;
1428 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1429 BasicStroke.JOIN_ROUND, 3f, new float[]
1432 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1433 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1434 g2.setStroke(new BasicStroke());
1438 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1440 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1442 if (aa.groupRef != null && aa.groupRef.consensusData != null
1443 && aa.groupRef.isShowSequenceLogo())
1445 return AAFrequency.extractProfile(
1446 aa.groupRef.consensusData[column],
1447 aa.groupRef.getIgnoreGapsConsensus());
1449 // TODO extend annotation row to enable dynamic and static profile data to
1451 if (aa.groupRef == null && aa.sequenceRef == null
1452 && av.isShowSequenceLogo())
1454 return AAFrequency.extractProfile(av.hconsensus[column],
1455 av.getIgnoreGapsConsensus());
1461 // used by overview window
1462 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1463 int y, int sRes, int eRes)
1465 eRes = Math.min(eRes, aa.annotations.length);
1466 g.setColor(Color.white);
1467 g.fillRect(0, 0, width, y);
1468 g.setColor(new Color(0, 0, 180));
1472 for (int j = sRes; j < eRes; j++)
1474 if (aa.annotations[j] != null)
1476 if (aa.annotations[j].colour == null)
1477 g.setColor(Color.black);
1479 g.setColor(aa.annotations[j].colour);
1481 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1487 g.fillRect(x, y - height, av.charWidth, height);