2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.event.*;
22 import java.awt.font.LineMetrics;
23 import java.awt.geom.AffineTransform;
24 import java.awt.image.*;
25 import java.util.Hashtable;
29 import jalview.analysis.AAFrequency;
30 import jalview.datamodel.*;
31 import jalview.schemes.ColourSchemeI;
39 public class AnnotationPanel extends JPanel implements MouseListener,
40 MouseMotionListener, ActionListener, AdjustmentListener
42 final String HELIX = "Helix";
44 final String SHEET = "Sheet";
46 final String LABEL = "Label";
48 final String REMOVE = "Remove Annotation";
50 final String COLOUR = "Colour";
52 final Color HELIX_COLOUR = Color.red.darker();
54 final Color SHEET_COLOUR = Color.green.darker().darker();
65 BufferedImage fadedImage;
73 boolean fastPaint = false;
75 // Used For mouse Dragging and resizing graphs
76 int graphStretch = -1;
78 int graphStretchY = -1;
80 int min; // used by mouseDragged to see if user
82 int max; // used by mouseDragged to see if user
84 boolean mouseDragging = false;
89 * Creates a new AnnotationPanel object.
94 public AnnotationPanel(AlignmentPanel ap)
97 MAC = new jalview.util.Platform().isAMac();
99 ToolTipManager.sharedInstance().registerComponent(this);
100 ToolTipManager.sharedInstance().setInitialDelay(0);
101 ToolTipManager.sharedInstance().setDismissDelay(10000);
104 this.setLayout(null);
105 addMouseListener(this);
106 addMouseMotionListener(this);
107 ap.annotationScroller.getVerticalScrollBar()
108 .addAdjustmentListener(this);
111 public AnnotationPanel(AlignViewport av)
122 public void adjustmentValueChanged(AdjustmentEvent evt)
124 ap.alabels.setScrollOffset(-evt.getValue());
128 * Calculates the height of the annotation displayed in the annotation panel.
129 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
130 * all annotation associated components are updated correctly.
133 public int adjustPanelHeight()
135 // setHeight of panels
136 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
141 for (int i = 0; i < aa.length; i++)
145 System.err.println("Null annotation row: ignoring.");
157 aa[i].height += av.charHeight;
167 aa[i].height += aa[i].graphHeight;
170 if (aa[i].height == 0)
175 height += aa[i].height;
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);
923 .fillRect(x * av.charWidth, y, av.charWidth,
930 if (av.validCharWidth && validRes
931 && row.annotations[column].displayCharacter != null
932 && (row.annotations[column].displayCharacter.length() > 0))
935 if (centreColLabels || scaleColLabel)
937 fmWidth = (float) fm.charsWidth(
938 row.annotations[column].displayCharacter.toCharArray(),
939 0, row.annotations[column].displayCharacter.length());
943 // justify the label and scale to fit in column
944 if (fmWidth > av.charWidth)
946 // scale only if the current font isn't already small enough
947 fmScaling = av.charWidth;
948 fmScaling /= fmWidth;
949 g.setFont(ofont.deriveFont(AffineTransform
950 .getScaleInstance(fmScaling, 1.0)));
951 // and update the label's width to reflect the scaling.
952 fmWidth = av.charWidth;
959 .charWidth(row.annotations[column].displayCharacter
962 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
964 if (row.annotations[column].colour == null)
965 g.setColor(Color.black);
967 g.setColor(row.annotations[column].colour);
969 if (column == 0 || row.graph > 0)
971 g.drawString(row.annotations[column].displayCharacter,
972 (x * av.charWidth) + charOffset, y + iconOffset);
974 else if (row.annotations[column - 1] == null
976 || !row.annotations[column].displayCharacter
977 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
978 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
980 g.drawString(row.annotations[column].displayCharacter, x
981 * av.charWidth + charOffset, y + iconOffset);
989 || (row.annotations[column].secondaryStructure != lastSS))
994 g.setColor(HELIX_COLOUR);
997 // Off by 1 offset when drawing rects and ovals
998 // to offscreen image on the MAC
999 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
1000 (x * av.charWidth) - lastSSX, 7, 8, 8);
1004 int sCol = (lastSSX / av.charWidth) + startRes;
1006 int x2 = (x * av.charWidth);
1009 || row.annotations[sCol - 1] == null
1010 || row.annotations[sCol - 1].secondaryStructure != 'H')
1012 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
1014 x1 += av.charWidth / 2;
1017 if (!validRes || row.annotations[column] == null
1018 || row.annotations[column].secondaryStructure != 'H')
1020 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1021 + iconOffset, av.charWidth, 8, 270, 180);
1022 x2 -= av.charWidth / 2;
1025 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1029 g.setColor(SHEET_COLOUR);
1030 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1032 g.fillPolygon(new int[]
1033 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1034 (x * av.charWidth) }, new int[]
1035 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1041 g.setColor(Color.gray);
1042 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1050 lastSS = row.annotations[column].secondaryStructure;
1057 lastSSX = (x * av.charWidth);
1065 if (column >= row.annotations.length)
1067 column = row.annotations.length - 1;
1082 g.setColor(HELIX_COLOUR);
1085 // Off by 1 offset when drawing rects and ovals
1086 // to offscreen image on the MAC
1087 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1088 - lastSSX, 7, 8, 8);
1092 int sCol = (lastSSX / av.charWidth) + startRes;
1094 int x2 = (x * av.charWidth);
1096 if (sCol == 0 || row.annotations[sCol - 1] == null
1097 || row.annotations[sCol - 1].secondaryStructure != 'H')
1100 .fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8,
1102 x1 += av.charWidth / 2;
1105 if (row.annotations[column] == null
1106 || row.annotations[column].secondaryStructure != 'H')
1108 g.fillArc((x * av.charWidth) - av.charWidth,
1109 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1110 x2 -= av.charWidth / 2;
1113 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1118 g.setColor(SHEET_COLOUR);
1120 if (!validEnd || row.annotations[endRes] == null
1121 || row.annotations[endRes].secondaryStructure != 'E')
1123 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1125 g.fillPolygon(new int[]
1126 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1127 (x * av.charWidth) }, new int[]
1128 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1132 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1138 g.setColor(Color.gray);
1139 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1146 if (row.graph > 0 && row.graphHeight > 0)
1148 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1150 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1152 float groupmax = -999999, groupmin = 9999999;
1153 for (int gg = 0; gg < aa.length; gg++)
1155 if (aa[gg].graphGroup != row.graphGroup)
1162 aa[gg].visible = false;
1165 if (aa[gg].graphMax > groupmax)
1167 groupmax = aa[gg].graphMax;
1169 if (aa[gg].graphMin < groupmin)
1171 groupmin = aa[gg].graphMin;
1175 for (int gg = 0; gg < aa.length; gg++)
1177 if (aa[gg].graphGroup == row.graphGroup)
1179 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1180 groupmax, row.graphHeight);
1184 graphGroupDrawn[row.graphGroup] = true;
1188 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1189 row.graphMax, row.graphHeight);
1192 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1194 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1199 if (row.graph > 0 && row.hasText)
1211 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1212 int eRes, int y, float min, float max, int graphHeight)
1214 if (sRes > aa.annotations.length)
1221 // Adjustment for fastpaint to left
1222 if (eRes < av.endRes)
1227 eRes = Math.min(eRes, aa.annotations.length);
1235 float range = max - min;
1240 y2 = y - (int) ((0 - min / range) * graphHeight);
1243 g.setColor(Color.gray);
1244 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1246 eRes = Math.min(eRes, aa.annotations.length);
1249 int aaMax = aa.annotations.length - 1;
1251 while (x < eRes - sRes)
1254 if (av.hasHiddenColumns)
1256 column = av.getColumnSelection().adjustForHiddenColumns(column);
1264 if (aa.annotations[column] == null
1265 || aa.annotations[column - 1] == null)
1271 if (aa.annotations[column].colour == null)
1272 g.setColor(Color.black);
1274 g.setColor(aa.annotations[column].colour);
1277 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1279 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1281 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1282 + av.charWidth / 2, y2);
1286 if (aa.threshold != null)
1288 g.setColor(aa.threshold.colour);
1289 Graphics2D g2 = (Graphics2D) g;
1290 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1291 BasicStroke.JOIN_ROUND, 3f, new float[]
1294 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1295 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1296 g2.setStroke(new BasicStroke());
1300 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1301 int eRes, float min, float max, int y)
1303 ColourSchemeI profcolour = av.getGlobalColourScheme();
1304 if (profcolour == null)
1306 profcolour = new jalview.schemes.ZappoColourScheme();
1308 if (sRes > aa.annotations.length)
1312 Font ofont = g.getFont();
1313 eRes = Math.min(eRes, aa.annotations.length);
1315 int x = 0, y1 = y, y2 = y;
1317 float range = max - min;
1321 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1324 g.setColor(Color.gray);
1326 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1329 int aaMax = aa.annotations.length - 1;
1330 boolean renderHistogram = true, renderProfile = true;
1331 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1333 // TODO: generalise this to have render styles for consensus/profile data
1334 if (aa.groupRef != null)
1336 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1337 renderProfile = aa.groupRef.isShowSequenceLogo();
1341 renderHistogram = av.isShowConsensusHistogram();
1342 renderProfile = av.isShowSequenceLogo();
1345 while (x < eRes - sRes)
1348 if (av.hasHiddenColumns)
1350 column = av.getColumnSelection().adjustForHiddenColumns(column);
1358 if (aa.annotations[column] == null)
1363 if (aa.annotations[column].colour == null)
1364 g.setColor(Color.black);
1366 g.setColor(aa.annotations[column].colour);
1369 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1371 if (renderHistogram)
1375 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1379 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1382 // draw profile if available
1383 if (aa.annotations[column].value != 0 && renderProfile)
1385 int profl[] = getProfileFor(aa, column);
1386 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1389 char[] dc = new char[1];
1391 for (int c = 1; profl != null && c < profl[0];)
1393 dc[0] = (char) profl[c++];
1394 wdth = av.charWidth;
1395 wdth /= (float) fm.charsWidth(dc, 0, 1);
1402 // if (aa.annotations[column].value==0) {
1403 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1404 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1405 // ht = y2-(int)ht2;
1407 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1408 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1410 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1413 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1414 // ? );// try to get a
1415 // colourscheme for the
1416 // group(aa.groupRef.cs==null)
1417 // ? av.textColour2 :
1418 // cs.findColour(dc));
1419 g.drawChars(dc, 0, 1, x * av.charWidth, (int) (ht + lm
1421 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1428 if (aa.threshold != null)
1430 g.setColor(aa.threshold.colour);
1431 Graphics2D g2 = (Graphics2D) g;
1432 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1433 BasicStroke.JOIN_ROUND, 3f, new float[]
1436 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1437 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1438 g2.setStroke(new BasicStroke());
1442 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1444 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1446 if (aa.groupRef != null && aa.groupRef.consensusData != null
1447 && aa.groupRef.isShowSequenceLogo())
1449 return AAFrequency.extractProfile(
1450 aa.groupRef.consensusData[column], aa.groupRef
1451 .getIgnoreGapsConsensus());
1453 // TODO extend annotation row to enable dynamic and static profile data to
1455 if (aa.groupRef == null && aa.sequenceRef == null
1456 && av.isShowSequenceLogo())
1458 return AAFrequency.extractProfile(av.hconsensus[column], av
1459 .getIgnoreGapsConsensus());
1465 // used by overview window
1466 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1467 int y, int sRes, int eRes)
1469 eRes = Math.min(eRes, aa.annotations.length);
1470 g.setColor(Color.white);
1471 g.fillRect(0, 0, width, y);
1472 g.setColor(new Color(0, 0, 180));
1476 for (int j = sRes; j < eRes; j++)
1478 if (aa.annotations[j] != null)
1480 if (aa.annotations[j].colour == null)
1481 g.setColor(Color.black);
1483 g.setColor(aa.annotations[j].colour);
1485 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1491 g.fillRect(x, y - height, av.charWidth, height);