2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import java.awt.event.*;
23 import java.awt.font.LineMetrics;
24 import java.awt.geom.AffineTransform;
25 import java.awt.image.*;
26 import java.util.Hashtable;
30 import jalview.analysis.AAFrequency;
31 import jalview.datamodel.*;
32 import jalview.schemes.ColourSchemeI;
40 public class AnnotationPanel extends JPanel implements MouseListener,
41 MouseMotionListener, ActionListener, AdjustmentListener
43 final String HELIX = "Helix";
45 final String SHEET = "Sheet";
47 final String LABEL = "Label";
49 final String REMOVE = "Remove Annotation";
51 final String COLOUR = "Colour";
53 final Color HELIX_COLOUR = Color.red.darker();
55 final Color SHEET_COLOUR = Color.green.darker().darker();
66 BufferedImage fadedImage;
74 boolean fastPaint = false;
76 // Used For mouse Dragging and resizing graphs
77 int graphStretch = -1;
79 int graphStretchY = -1;
81 int min; // used by mouseDragged to see if user
83 int max; // used by mouseDragged to see if user
85 boolean mouseDragging = false;
90 * Creates a new AnnotationPanel object.
95 public AnnotationPanel(AlignmentPanel ap)
98 MAC = new jalview.util.Platform().isAMac();
100 ToolTipManager.sharedInstance().registerComponent(this);
101 ToolTipManager.sharedInstance().setInitialDelay(0);
102 ToolTipManager.sharedInstance().setDismissDelay(10000);
105 this.setLayout(null);
106 addMouseListener(this);
107 addMouseMotionListener(this);
108 ap.annotationScroller.getVerticalScrollBar()
109 .addAdjustmentListener(this);
112 public AnnotationPanel(AlignViewport av)
123 public void adjustmentValueChanged(AdjustmentEvent evt)
125 ap.alabels.setScrollOffset(-evt.getValue());
129 * Calculates the height of the annotation displayed in the annotation panel.
130 * Callers should normally call the ap.adjustAnnotationHeight method to ensure all
131 * annotation associated components are updated correctly.
134 public int adjustPanelHeight()
136 // setHeight of panels
137 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
142 for (int i = 0; i < aa.length; i++)
146 System.err.println("Null annotation row: ignoring.");
158 aa[i].height += av.charHeight;
168 aa[i].height += aa[i].graphHeight;
171 if (aa[i].height == 0)
176 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();
203 Annotation[] anot = aa[activeRow].annotations;
205 if (anot.length < av.getColumnSelection().getMax())
207 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
208 System.arraycopy(anot, 0, temp, 0, anot.length);
210 aa[activeRow].annotations = anot;
213 if (evt.getActionCommand().equals(REMOVE))
215 for (int i = 0; i < av.getColumnSelection().size(); i++)
217 anot[av.getColumnSelection().columnAt(i)] = null;
220 else if (evt.getActionCommand().equals(LABEL))
222 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
223 String label = JOptionPane.showInputDialog(this, "Enter label",
231 if ((label.length() > 0) && !aa[activeRow].hasText)
233 aa[activeRow].hasText = true;
236 for (int i = 0; i < av.getColumnSelection().size(); i++)
238 int index = av.getColumnSelection().columnAt(i);
240 if (!av.colSel.isVisible(index))
243 if (anot[index] == null)
245 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
252 anot[index].displayCharacter = label;
256 else if (evt.getActionCommand().equals(COLOUR))
258 Color col = JColorChooser.showDialog(this,
259 "Choose foreground colour", Color.black);
261 for (int i = 0; i < av.getColumnSelection().size(); i++)
263 int index = av.getColumnSelection().columnAt(i);
265 if (!av.colSel.isVisible(index))
268 if (anot[index] == null)
270 anot[index] = new Annotation("", "", ' ', 0);
273 anot[index].colour = col;
280 String symbol = "\u03B1";
282 if (evt.getActionCommand().equals(HELIX))
286 else if (evt.getActionCommand().equals(SHEET))
292 if (!aa[activeRow].hasIcons)
294 aa[activeRow].hasIcons = true;
297 String label = JOptionPane.showInputDialog(
298 "Enter a label for the structure?", symbol);
305 if ((label.length() > 0) && !aa[activeRow].hasText)
307 aa[activeRow].hasText = true;
310 for (int i = 0; i < av.getColumnSelection().size(); i++)
312 int index = av.getColumnSelection().columnAt(i);
314 if (!av.colSel.isVisible(index))
317 if (anot[index] == null)
319 anot[index] = new Annotation(label, "", type, 0);
322 anot[index].secondaryStructure = type;
323 anot[index].displayCharacter = label;
333 private String collectAnnotVals(Annotation[] anot,
334 ColumnSelection columnSelection, String label2)
336 String collatedInput = "";
338 for (int i = 0; i < columnSelection.size(); i++)
340 int index = columnSelection.columnAt(i);
341 // always check for current display state - just in case
342 if (!av.colSel.isVisible(index))
344 String tlabel = null;
345 if (anot[index] != null)
347 if (label2.equals(HELIX) || label2.equals(SHEET)
348 || label2.equals(LABEL))
350 tlabel = anot[index].description;
351 if (tlabel == null || tlabel.length()<1)
353 if (label2.equals(HELIX) || label2.equals(SHEET))
355 tlabel = "" + anot[index].secondaryStructure;
359 tlabel = "" + anot[index].displayCharacter;
363 if (tlabel != null && !tlabel.equals(last))
365 if (last.length() > 0)
367 collatedInput += " ";
369 collatedInput += tlabel;
373 return collatedInput;
382 public void mousePressed(MouseEvent evt)
385 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
394 for (int i = 0; i < aa.length; i++)
398 height += aa[i].height;
401 if (evt.getY() < height)
407 else if (aa[i].graph > 0)
411 graphStretchY = evt.getY();
418 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
420 if (av.getColumnSelection() == null)
425 JPopupMenu pop = new JPopupMenu("Structure type");
426 JMenuItem item = new JMenuItem(HELIX);
427 item.addActionListener(this);
429 item = new JMenuItem(SHEET);
430 item.addActionListener(this);
432 item = new JMenuItem(LABEL);
433 item.addActionListener(this);
435 item = new JMenuItem(COLOUR);
436 item.addActionListener(this);
438 item = new JMenuItem(REMOVE);
439 item.addActionListener(this);
441 pop.show(this, evt.getX(), evt.getY());
451 ap.scalePanel.mousePressed(evt);
461 public void mouseReleased(MouseEvent evt)
465 mouseDragging = false;
466 ap.scalePanel.mouseReleased(evt);
475 public void mouseEntered(MouseEvent evt)
477 ap.scalePanel.mouseEntered(evt);
486 public void mouseExited(MouseEvent evt)
488 ap.scalePanel.mouseExited(evt);
497 public void mouseDragged(MouseEvent evt)
499 if (graphStretch > -1)
501 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
503 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
505 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
507 graphStretchY = evt.getY();
509 ap.paintAlignment(true);
513 ap.scalePanel.mouseDragged(evt);
523 public void mouseMoved(MouseEvent evt)
525 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
529 this.setToolTipText(null);
536 for (int i = 0; i < aa.length; i++)
540 height += aa[i].height;
543 if (evt.getY() < height)
553 this.setToolTipText(null);
557 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
559 if (av.hasHiddenColumns)
561 res = av.getColumnSelection().adjustForHiddenColumns(res);
564 if (row > -1 && aa[row].annotations != null
565 && res < (int) aa[row].annotations.length)
567 if (aa[row].graphGroup > -1)
569 StringBuffer tip = new StringBuffer("<html>");
570 for (int gg = 0; gg < aa.length; gg++)
572 if (aa[gg].graphGroup == aa[row].graphGroup
573 && aa[gg].annotations[res] != null)
575 tip.append(aa[gg].label + " "
576 + aa[gg].annotations[res].description + "<br>");
579 if (tip.length() != 6)
581 tip.setLength(tip.length() - 4);
582 this.setToolTipText(tip.toString() + "</html>");
585 else if (aa[row].annotations[res] != null
586 && aa[row].annotations[res].description != null && aa[row].annotations[res].description.length()>0)
588 this.setToolTipText(aa[row].annotations[res].description);
592 // clear the tooltip.
593 this.setToolTipText(null);
596 if (aa[row].annotations[res] != null)
598 StringBuffer text = new StringBuffer("Sequence position "
601 if (aa[row].annotations[res].description != null)
603 text.append(" " + aa[row].annotations[res].description);
606 ap.alignFrame.statusBar.setText(text.toString());
611 this.setToolTipText(null);
621 public void mouseClicked(MouseEvent evt)
631 public void paintComponent(Graphics g)
633 g.setColor(Color.white);
634 g.fillRect(0, 0, getWidth(), getHeight());
638 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
639 || (getVisibleRect().height != g.getClipBounds().height))
641 g.drawImage(image, 0, 0, this);
646 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
649 if (image == null || imgWidth != image.getWidth()
650 || image.getHeight(this) != getHeight())
652 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
653 BufferedImage.TYPE_INT_RGB);
654 gg = (Graphics2D) image.getGraphics();
658 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
659 RenderingHints.VALUE_ANTIALIAS_ON);
662 gg.setFont(av.getFont());
663 fm = gg.getFontMetrics();
664 gg.setColor(Color.white);
665 gg.fillRect(0, 0, imgWidth, image.getHeight());
668 drawComponent(gg, av.startRes, av.endRes + 1);
669 g.drawImage(image, 0, 0, this);
673 * non-Thread safe repaint
676 * repaint with horizontal shift in alignment
678 public void fastPaint(int horizontal)
681 if ((horizontal == 0) || gg == null
682 || av.alignment.getAlignmentAnnotation() == null
683 || av.alignment.getAlignmentAnnotation().length < 1
684 || av.updatingConsensus || av.updatingConservation)
689 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
691 int sr = av.startRes;
692 int er = av.endRes + 1;
695 if (horizontal > 0) // scrollbar pulled right, image to the left
697 transX = (er - sr - horizontal) * av.charWidth;
698 sr = er - horizontal;
700 else if (horizontal < 0)
702 er = sr - horizontal;
705 gg.translate(transX, 0);
707 drawComponent(gg, sr, er);
709 gg.translate(-transX, 0);
726 public void drawComponent(Graphics g, int startRes, int endRes)
728 if (av.updatingConsensus || av.updatingConservation)
734 // We'll keep a record of the old image,
735 // and draw a faded image until the calculation
737 if (fadedImage == null || fadedImage.getWidth() != imgWidth
738 || fadedImage.getHeight() != image.getHeight())
740 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
741 BufferedImage.TYPE_INT_RGB);
743 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
745 fadedG.setColor(Color.white);
746 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
748 fadedG.setComposite(AlphaComposite.getInstance(
749 AlphaComposite.SRC_OVER, .3f));
750 fadedG.drawImage(image, 0, 0, this);
760 g.setColor(Color.white);
761 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
763 g.setFont(av.getFont());
766 fm = g.getFontMetrics();
769 if ((av.alignment.getAlignmentAnnotation() == null)
770 || (av.alignment.getAlignmentAnnotation().length < 1))
772 g.setColor(Color.white);
773 g.fillRect(0, 0, getWidth(), getHeight());
774 g.setColor(Color.black);
775 if (av.validCharWidth)
777 g.drawString("Alignment has no annotations", 20, 15);
783 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
790 boolean validRes = false;
791 boolean validEnd = false;
792 boolean labelAllCols = false;
793 boolean centreColLabels,centreColLabelsDef = av.getCentreColumnLabels();
794 boolean scaleColLabel=false;
795 boolean[] graphGroupDrawn = new boolean[aa.length];
796 int charOffset = 0; // offset for a label
797 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a column.
798 Font ofont = g.getFont();
800 for (int i = 0; i < aa.length; i++)
802 AlignmentAnnotation row = aa[i];
808 centreColLabels = row.centreColLabels || centreColLabelsDef;
809 labelAllCols = row.showAllColLabels;
810 scaleColLabel = row.scaleColLabel;
816 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
821 // this is so that we draw the characters below the graph
826 iconOffset = av.charHeight - fm.getDescent();
830 else if (row.hasText)
832 iconOffset = av.charHeight - fm.getDescent();
840 if (av.updatingConsensus && aa[i] == av.consensus)
844 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
845 - row.height, imgWidth, y, this);
846 g.setColor(Color.black);
847 // g.drawString("Calculating Consensus....",20, y-row.height/2);
851 else if (av.updatingConservation
852 && aa[i].label.equals("Conservation"))
856 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
857 - row.height, imgWidth, y, this);
859 g.setColor(Color.black);
860 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
864 else if (av.updatingConservation && aa[i].label.equals("Quality"))
868 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
869 - row.height, imgWidth, y, this);
870 g.setColor(Color.black);
871 // / g.drawString("Calculating Quality....",20, y-row.height/2);
877 while (x < endRes - startRes)
879 if (av.hasHiddenColumns)
881 column = av.getColumnSelection().adjustForHiddenColumns(
883 if (column > row.annotations.length - 1)
890 column = startRes + x;
893 if ((row.annotations == null) || (row.annotations.length <= column)
894 || (row.annotations[column] == null))
905 g.setColor(Color.red);
907 if (av.getColumnSelection() != null)
909 for (int n = 0; n < av.getColumnSelection().size(); n++)
911 int v = av.getColumnSelection().columnAt(n);
916 .fillRect(x * av.charWidth, y, av.charWidth,
923 if (av.validCharWidth && validRes
924 && row.annotations[column].displayCharacter != null
925 && (row.annotations[column].displayCharacter.length() > 0))
928 if (centreColLabels || scaleColLabel)
931 .charsWidth(row.annotations[column].displayCharacter
933 row.annotations[column].displayCharacter.length());
935 if ( scaleColLabel ) {
936 // justify the label and scale to fit in column
937 if (fmWidth > av.charWidth) {
938 // scale only if the current font isn't already small enough
939 fmScaling = av.charWidth;
940 fmScaling /= fmWidth;
941 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(fmScaling, 1.0)));
942 // and update the label's width to reflect the scaling.
943 fmWidth = av.charWidth;
948 .charWidth(row.annotations[column].displayCharacter.charAt(0));
950 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
952 if (row.annotations[column].colour == null)
953 g.setColor(Color.black);
955 g.setColor(row.annotations[column].colour);
957 if (column == 0 || row.graph > 0)
959 g.drawString(row.annotations[column].displayCharacter,
960 (x * av.charWidth) + charOffset, y + iconOffset);
962 else if (row.annotations[column - 1] == null
963 || (labelAllCols||!row.annotations[column].displayCharacter
964 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
965 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
967 g.drawString(row.annotations[column].displayCharacter, x
968 * av.charWidth + charOffset, y + iconOffset);
976 || (row.annotations[column].secondaryStructure != lastSS))
981 g.setColor(HELIX_COLOUR);
984 // Off by 1 offset when drawing rects and ovals
985 // to offscreen image on the MAC
986 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
987 (x * av.charWidth) - lastSSX, 7, 8, 8);
991 int sCol = (lastSSX / av.charWidth) + startRes;
993 int x2 = (x * av.charWidth);
996 || row.annotations[sCol - 1] == null
997 || row.annotations[sCol - 1].secondaryStructure != 'H')
999 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
1001 x1 += av.charWidth / 2;
1004 if (!validRes || row.annotations[column] == null
1005 || row.annotations[column].secondaryStructure != 'H')
1007 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1008 + iconOffset, av.charWidth, 8, 270, 180);
1009 x2 -= av.charWidth / 2;
1012 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1016 g.setColor(SHEET_COLOUR);
1017 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1019 g.fillPolygon(new int[]
1020 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1021 (x * av.charWidth) }, new int[]
1022 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1028 g.setColor(Color.gray);
1029 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1037 lastSS = row.annotations[column].secondaryStructure;
1044 lastSSX = (x * av.charWidth);
1052 if (column >= row.annotations.length)
1054 column = row.annotations.length - 1;
1069 g.setColor(HELIX_COLOUR);
1072 // Off by 1 offset when drawing rects and ovals
1073 // to offscreen image on the MAC
1074 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1075 - lastSSX, 7, 8, 8);
1079 int sCol = (lastSSX / av.charWidth) + startRes;
1081 int x2 = (x * av.charWidth);
1083 if (sCol == 0 || row.annotations[sCol - 1] == null
1084 || row.annotations[sCol - 1].secondaryStructure != 'H')
1087 .fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8,
1089 x1 += av.charWidth / 2;
1092 if (row.annotations[column] == null
1093 || row.annotations[column].secondaryStructure != 'H')
1095 g.fillArc((x * av.charWidth) - av.charWidth,
1096 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1097 x2 -= av.charWidth / 2;
1100 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1105 g.setColor(SHEET_COLOUR);
1107 if (!validEnd || row.annotations[endRes] == null
1108 || row.annotations[endRes].secondaryStructure != 'E')
1110 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1112 g.fillPolygon(new int[]
1113 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1114 (x * av.charWidth) }, new int[]
1115 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1119 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1125 g.setColor(Color.gray);
1126 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1133 if (row.graph > 0 && row.graphHeight > 0)
1135 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1137 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1139 float groupmax = -999999, groupmin = 9999999;
1140 for (int gg = 0; gg < aa.length; gg++)
1142 if (aa[gg].graphGroup != row.graphGroup)
1149 aa[gg].visible = false;
1152 if (aa[gg].graphMax > groupmax)
1154 groupmax = aa[gg].graphMax;
1156 if (aa[gg].graphMin < groupmin)
1158 groupmin = aa[gg].graphMin;
1162 for (int gg = 0; gg < aa.length; gg++)
1164 if (aa[gg].graphGroup == row.graphGroup)
1166 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1167 groupmax, row.graphHeight);
1171 graphGroupDrawn[row.graphGroup] = true;
1175 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1176 row.graphMax, row.graphHeight);
1179 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1181 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1186 if (row.graph > 0 && row.hasText)
1198 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1199 int eRes, int y, float min, float max, int graphHeight)
1201 if (sRes > aa.annotations.length)
1208 // Adjustment for fastpaint to left
1209 if (eRes < av.endRes)
1214 eRes = Math.min(eRes, aa.annotations.length);
1222 float range = max - min;
1227 y2 = y - (int) ((0 - min / range) * graphHeight);
1230 g.setColor(Color.gray);
1231 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1233 eRes = Math.min(eRes, aa.annotations.length);
1236 int aaMax = aa.annotations.length - 1;
1238 while (x < eRes - sRes)
1241 if (av.hasHiddenColumns)
1243 column = av.getColumnSelection().adjustForHiddenColumns(column);
1251 if (aa.annotations[column] == null
1252 || aa.annotations[column - 1] == null)
1258 if (aa.annotations[column].colour == null)
1259 g.setColor(Color.black);
1261 g.setColor(aa.annotations[column].colour);
1264 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1266 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1268 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1269 + av.charWidth / 2, y2);
1273 if (aa.threshold != null)
1275 g.setColor(aa.threshold.colour);
1276 Graphics2D g2 = (Graphics2D) g;
1277 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1278 BasicStroke.JOIN_ROUND, 3f, new float[]
1281 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1282 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1283 g2.setStroke(new BasicStroke());
1287 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1288 int eRes, float min, float max, int y)
1290 ColourSchemeI profcolour = av.getGlobalColourScheme();
1291 if (profcolour==null)
1293 profcolour = new jalview.schemes.ZappoColourScheme();
1295 if (sRes > aa.annotations.length)
1299 Font ofont = g.getFont();
1300 eRes = Math.min(eRes, aa.annotations.length);
1302 int x = 0, y1 = y, y2 = y;
1304 float range = max - min;
1308 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1311 g.setColor(Color.gray);
1313 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1316 int aaMax = aa.annotations.length - 1;
1317 boolean renderHistogram = true, renderProfile = true;
1318 if (aa.autoCalculated && aa.label.startsWith("Consensus")) {
1319 // TODO: generalise this to have render styles for consensus/profile data
1320 if (aa.groupRef!=null)
1322 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1323 renderProfile = aa.groupRef.isShowSequenceLogo();
1325 renderHistogram = av.isShowConsensusHistogram();
1326 renderProfile = av.isShowSequenceLogo();
1329 while (x < eRes - sRes)
1332 if (av.hasHiddenColumns)
1334 column = av.getColumnSelection().adjustForHiddenColumns(column);
1342 if (aa.annotations[column] == null)
1347 if (aa.annotations[column].colour == null)
1348 g.setColor(Color.black);
1350 g.setColor(aa.annotations[column].colour);
1353 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1355 if (renderHistogram)
1359 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1363 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1366 // draw profile if available
1367 if (aa.annotations[column].value!=0 && renderProfile)
1369 int profl[] = getProfileFor(aa,column);
1370 int ht = y1,htn=y2-y1;//aa.graphHeight;
1373 char[] dc = new char[1];
1375 for (int c=1;profl!=null && c<profl[0];)
1377 dc[0] = (char) profl[c++];
1378 wdth = av.charWidth;
1380 .charsWidth(dc,0,1);
1387 //if (aa.annotations[column].value==0) {
1388 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1389 // ht = y2-(int)ht2;
1391 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(htn*((double)profl[c++])/100.0))/av.charHeight)));
1392 lm = g.getFontMetrics().getLineMetrics(dc,0,1, g);
1395 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));
1396 g.drawChars(dc,0,1,x*av.charWidth, (int) (ht+lm.getHeight()));
1397 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1404 if (aa.threshold != null)
1406 g.setColor(aa.threshold.colour);
1407 Graphics2D g2 = (Graphics2D) g;
1408 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1409 BasicStroke.JOIN_ROUND, 3f, new float[]
1412 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1413 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1414 g2.setStroke(new BasicStroke());
1418 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1420 if (aa.autoCalculated && aa.label.startsWith("Consensus")) {
1421 if (aa.groupRef!=null && aa.groupRef.consensusData!=null && aa.groupRef.isShowSequenceLogo()) {
1422 return AAFrequency.extractProfile(aa.groupRef.consensusData[column],aa.groupRef.getIgnoreGapsConsensus());
1424 // TODO extend annotation row to enable dynamic and static profile data to be stored
1425 if (aa.groupRef==null && aa.sequenceRef==null && av.isShowSequenceLogo())
1427 return AAFrequency.extractProfile(av.hconsensus[column],av.getIgnoreGapsConsensus());
1433 // used by overview window
1434 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1435 int y, int sRes, int eRes)
1437 eRes = Math.min(eRes, aa.annotations.length);
1438 g.setColor(Color.white);
1439 g.fillRect(0, 0, width, y);
1440 g.setColor(new Color(0, 0, 180));
1444 for (int j = sRes; j < eRes; j++)
1446 if (aa.annotations[j] != null)
1448 if (aa.annotations[j].colour == null)
1449 g.setColor(Color.black);
1451 g.setColor(aa.annotations[j].colour);
1453 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1459 g.fillRect(x, y - height, av.charWidth, height);