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 (aa[row].annotations != null && row > -1
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)
588 this.setToolTipText(aa[row].annotations[res].description);
591 if (aa[row].annotations[res] != null)
593 StringBuffer text = new StringBuffer("Sequence position "
596 if (aa[row].annotations[res].description != null)
598 text.append(" " + aa[row].annotations[res].description);
601 ap.alignFrame.statusBar.setText(text.toString());
606 this.setToolTipText(null);
616 public void mouseClicked(MouseEvent evt)
626 public void paintComponent(Graphics g)
628 g.setColor(Color.white);
629 g.fillRect(0, 0, getWidth(), getHeight());
633 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
634 || (getVisibleRect().height != g.getClipBounds().height))
636 g.drawImage(image, 0, 0, this);
641 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
644 if (image == null || imgWidth != image.getWidth()
645 || image.getHeight(this) != getHeight())
647 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
648 BufferedImage.TYPE_INT_RGB);
649 gg = (Graphics2D) image.getGraphics();
653 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
654 RenderingHints.VALUE_ANTIALIAS_ON);
657 gg.setFont(av.getFont());
658 fm = gg.getFontMetrics();
659 gg.setColor(Color.white);
660 gg.fillRect(0, 0, imgWidth, image.getHeight());
663 drawComponent(gg, av.startRes, av.endRes + 1);
664 g.drawImage(image, 0, 0, this);
668 * non-Thread safe repaint
671 * repaint with horizontal shift in alignment
673 public void fastPaint(int horizontal)
676 if ((horizontal == 0) || gg == null
677 || av.alignment.getAlignmentAnnotation() == null
678 || av.alignment.getAlignmentAnnotation().length < 1
679 || av.updatingConsensus || av.updatingConservation)
684 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
686 int sr = av.startRes;
687 int er = av.endRes + 1;
690 if (horizontal > 0) // scrollbar pulled right, image to the left
692 transX = (er - sr - horizontal) * av.charWidth;
693 sr = er - horizontal;
695 else if (horizontal < 0)
697 er = sr - horizontal;
700 gg.translate(transX, 0);
702 drawComponent(gg, sr, er);
704 gg.translate(-transX, 0);
721 public void drawComponent(Graphics g, int startRes, int endRes)
723 if (av.updatingConsensus || av.updatingConservation)
729 // We'll keep a record of the old image,
730 // and draw a faded image until the calculation
732 if (fadedImage == null || fadedImage.getWidth() != imgWidth
733 || fadedImage.getHeight() != image.getHeight())
735 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
736 BufferedImage.TYPE_INT_RGB);
738 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
740 fadedG.setColor(Color.white);
741 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
743 fadedG.setComposite(AlphaComposite.getInstance(
744 AlphaComposite.SRC_OVER, .3f));
745 fadedG.drawImage(image, 0, 0, this);
755 g.setColor(Color.white);
756 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
758 g.setFont(av.getFont());
761 fm = g.getFontMetrics();
764 if ((av.alignment.getAlignmentAnnotation() == null)
765 || (av.alignment.getAlignmentAnnotation().length < 1))
767 g.setColor(Color.white);
768 g.fillRect(0, 0, getWidth(), getHeight());
769 g.setColor(Color.black);
770 if (av.validCharWidth)
772 g.drawString("Alignment has no annotations", 20, 15);
778 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
785 boolean validRes = false;
786 boolean validEnd = false;
787 boolean labelAllCols = false;
788 boolean centreColLabels,centreColLabelsDef = av.getCentreColumnLabels();
789 boolean scaleColLabel=false;
790 boolean[] graphGroupDrawn = new boolean[aa.length];
791 int charOffset = 0; // offset for a label
792 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a column.
793 Font ofont = g.getFont();
795 for (int i = 0; i < aa.length; i++)
797 AlignmentAnnotation row = aa[i];
803 centreColLabels = row.centreColLabels || centreColLabelsDef;
804 labelAllCols = row.showAllColLabels;
805 scaleColLabel = row.scaleColLabel;
811 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
816 // this is so that we draw the characters below the graph
821 iconOffset = av.charHeight - fm.getDescent();
825 else if (row.hasText)
827 iconOffset = av.charHeight - fm.getDescent();
835 if (av.updatingConsensus && aa[i] == av.consensus)
839 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
840 - row.height, imgWidth, y, this);
841 g.setColor(Color.black);
842 // g.drawString("Calculating Consensus....",20, y-row.height/2);
846 else if (av.updatingConservation
847 && aa[i].label.equals("Conservation"))
851 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
852 - row.height, imgWidth, y, this);
854 g.setColor(Color.black);
855 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
859 else if (av.updatingConservation && aa[i].label.equals("Quality"))
863 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
864 - row.height, imgWidth, y, this);
865 g.setColor(Color.black);
866 // / g.drawString("Calculating Quality....",20, y-row.height/2);
872 while (x < endRes - startRes)
874 if (av.hasHiddenColumns)
876 column = av.getColumnSelection().adjustForHiddenColumns(
878 if (column > row.annotations.length - 1)
885 column = startRes + x;
888 if ((row.annotations == null) || (row.annotations.length <= column)
889 || (row.annotations[column] == null))
900 g.setColor(Color.red);
902 if (av.getColumnSelection() != null)
904 for (int n = 0; n < av.getColumnSelection().size(); n++)
906 int v = av.getColumnSelection().columnAt(n);
911 .fillRect(x * av.charWidth, y, av.charWidth,
918 if (av.validCharWidth && validRes
919 && row.annotations[column].displayCharacter != null
920 && (row.annotations[column].displayCharacter.length() > 0))
923 if (centreColLabels || scaleColLabel)
926 .charsWidth(row.annotations[column].displayCharacter
928 row.annotations[column].displayCharacter.length());
930 if ( scaleColLabel ) {
931 // justify the label and scale to fit in column
932 if (fmWidth > av.charWidth) {
933 // scale only if the current font isn't already small enough
934 fmScaling = av.charWidth;
935 fmScaling /= fmWidth;
936 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(fmScaling, 1.0)));
937 // and update the label's width to reflect the scaling.
938 fmWidth = av.charWidth;
943 .charWidth(row.annotations[column].displayCharacter.charAt(0));
945 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
947 if (row.annotations[column].colour == null)
948 g.setColor(Color.black);
950 g.setColor(row.annotations[column].colour);
952 if (column == 0 || row.graph > 0)
954 g.drawString(row.annotations[column].displayCharacter,
955 (x * av.charWidth) + charOffset, y + iconOffset);
957 else if (row.annotations[column - 1] == null
958 || (labelAllCols||!row.annotations[column].displayCharacter
959 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
960 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
962 g.drawString(row.annotations[column].displayCharacter, x
963 * av.charWidth + charOffset, y + iconOffset);
971 || (row.annotations[column].secondaryStructure != lastSS))
976 g.setColor(HELIX_COLOUR);
979 // Off by 1 offset when drawing rects and ovals
980 // to offscreen image on the MAC
981 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
982 (x * av.charWidth) - lastSSX, 7, 8, 8);
986 int sCol = (lastSSX / av.charWidth) + startRes;
988 int x2 = (x * av.charWidth);
991 || row.annotations[sCol - 1] == null
992 || row.annotations[sCol - 1].secondaryStructure != 'H')
994 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
996 x1 += av.charWidth / 2;
999 if (!validRes || row.annotations[column] == null
1000 || row.annotations[column].secondaryStructure != 'H')
1002 g.fillArc((x * av.charWidth) - av.charWidth, y + 4
1003 + iconOffset, av.charWidth, 8, 270, 180);
1004 x2 -= av.charWidth / 2;
1007 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1011 g.setColor(SHEET_COLOUR);
1012 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1014 g.fillPolygon(new int[]
1015 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1016 (x * av.charWidth) }, new int[]
1017 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1023 g.setColor(Color.gray);
1024 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1032 lastSS = row.annotations[column].secondaryStructure;
1039 lastSSX = (x * av.charWidth);
1047 if (column >= row.annotations.length)
1049 column = row.annotations.length - 1;
1064 g.setColor(HELIX_COLOUR);
1067 // Off by 1 offset when drawing rects and ovals
1068 // to offscreen image on the MAC
1069 g.fillRoundRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1070 - lastSSX, 7, 8, 8);
1074 int sCol = (lastSSX / av.charWidth) + startRes;
1076 int x2 = (x * av.charWidth);
1078 if (sCol == 0 || row.annotations[sCol - 1] == null
1079 || row.annotations[sCol - 1].secondaryStructure != 'H')
1082 .fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8,
1084 x1 += av.charWidth / 2;
1087 if (row.annotations[column] == null
1088 || row.annotations[column].secondaryStructure != 'H')
1090 g.fillArc((x * av.charWidth) - av.charWidth,
1091 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
1092 x2 -= av.charWidth / 2;
1095 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1100 g.setColor(SHEET_COLOUR);
1102 if (!validEnd || row.annotations[endRes] == null
1103 || row.annotations[endRes].secondaryStructure != 'E')
1105 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
1107 g.fillPolygon(new int[]
1108 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1109 (x * av.charWidth) }, new int[]
1110 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1114 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1120 g.setColor(Color.gray);
1121 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1128 if (row.graph > 0 && row.graphHeight > 0)
1130 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1132 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1134 float groupmax = -999999, groupmin = 9999999;
1135 for (int gg = 0; gg < aa.length; gg++)
1137 if (aa[gg].graphGroup != row.graphGroup)
1144 aa[gg].visible = false;
1147 if (aa[gg].graphMax > groupmax)
1149 groupmax = aa[gg].graphMax;
1151 if (aa[gg].graphMin < groupmin)
1153 groupmin = aa[gg].graphMin;
1157 for (int gg = 0; gg < aa.length; gg++)
1159 if (aa[gg].graphGroup == row.graphGroup)
1161 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1162 groupmax, row.graphHeight);
1166 graphGroupDrawn[row.graphGroup] = true;
1170 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1171 row.graphMax, row.graphHeight);
1174 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1176 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1181 if (row.graph > 0 && row.hasText)
1193 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1194 int eRes, int y, float min, float max, int graphHeight)
1196 if (sRes > aa.annotations.length)
1203 // Adjustment for fastpaint to left
1204 if (eRes < av.endRes)
1209 eRes = Math.min(eRes, aa.annotations.length);
1217 float range = max - min;
1222 y2 = y - (int) ((0 - min / range) * graphHeight);
1225 g.setColor(Color.gray);
1226 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1228 eRes = Math.min(eRes, aa.annotations.length);
1231 int aaMax = aa.annotations.length - 1;
1233 while (x < eRes - sRes)
1236 if (av.hasHiddenColumns)
1238 column = av.getColumnSelection().adjustForHiddenColumns(column);
1246 if (aa.annotations[column] == null
1247 || aa.annotations[column - 1] == null)
1253 if (aa.annotations[column].colour == null)
1254 g.setColor(Color.black);
1256 g.setColor(aa.annotations[column].colour);
1259 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1261 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1263 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1264 + av.charWidth / 2, y2);
1268 if (aa.threshold != null)
1270 g.setColor(aa.threshold.colour);
1271 Graphics2D g2 = (Graphics2D) g;
1272 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1273 BasicStroke.JOIN_ROUND, 3f, new float[]
1276 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1277 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1278 g2.setStroke(new BasicStroke());
1282 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1283 int eRes, float min, float max, int y)
1285 ColourSchemeI profcolour = av.getGlobalColourScheme();
1286 if (profcolour==null)
1288 profcolour = new jalview.schemes.ZappoColourScheme();
1290 if (sRes > aa.annotations.length)
1294 Font ofont = g.getFont();
1295 eRes = Math.min(eRes, aa.annotations.length);
1297 int x = 0, y1 = y, y2 = y;
1299 float range = max - min;
1303 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1306 g.setColor(Color.gray);
1308 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1311 int aaMax = aa.annotations.length - 1;
1312 boolean renderHistogram = true, renderProfile = true;
1313 if (aa.autoCalculated && aa.label.startsWith("Consensus")) {
1314 // TODO: generalise this to have render styles for consensus/profile data
1315 if (aa.groupRef!=null)
1317 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1318 renderProfile = aa.groupRef.isIncludeAllConsSymbols();
1320 renderHistogram = av.isShowConsensusHistogram();
1321 renderProfile = av.isShowConsensusProfile();
1324 while (x < eRes - sRes)
1327 if (av.hasHiddenColumns)
1329 column = av.getColumnSelection().adjustForHiddenColumns(column);
1337 if (aa.annotations[column] == null)
1342 if (aa.annotations[column].colour == null)
1343 g.setColor(Color.black);
1345 g.setColor(aa.annotations[column].colour);
1348 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1350 if (renderHistogram)
1354 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1358 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1361 // draw profile if available
1362 if (aa.annotations[column].value!=0 && renderProfile)
1364 int profl[] = getProfileFor(aa,column);
1365 int ht = y1,htn=y2-y1;//aa.graphHeight;
1368 char[] dc = new char[1];
1370 for (int c=1;profl!=null && c<profl[0];)
1372 dc[0] = (char) profl[c++];
1373 wdth = av.charWidth;
1375 .charsWidth(dc,0,1);
1382 //if (aa.annotations[column].value==0) {
1383 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1384 // ht = y2-(int)ht2;
1386 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth, (ht2=(htn*((double)profl[c++])/100.0))/av.charHeight)));
1387 lm = g.getFontMetrics().getLineMetrics(dc,0,1, g);
1390 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));
1391 g.drawChars(dc,0,1,x*av.charWidth, (int) (ht+lm.getHeight()));
1392 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1399 if (aa.threshold != null)
1401 g.setColor(aa.threshold.colour);
1402 Graphics2D g2 = (Graphics2D) g;
1403 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1404 BasicStroke.JOIN_ROUND, 3f, new float[]
1407 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1408 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1409 g2.setStroke(new BasicStroke());
1413 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1415 if (aa.autoCalculated && aa.label.startsWith("Consensus")) {
1416 if (aa.groupRef!=null && aa.groupRef.consensusData!=null && aa.groupRef.isIncludeAllConsSymbols()) {
1417 return AAFrequency.extractProfile(aa.groupRef.consensusData[column],aa.groupRef.getIgnoreGapsConsensus());
1419 // TODO extend annotation row to enable dynamic and static profile data to be stored
1420 if (aa.groupRef==null && aa.sequenceRef==null && av.isShowConsensusProfile())
1422 return AAFrequency.extractProfile(av.hconsensus[column],av.getIgnoreGapsConsensus());
1428 // used by overview window
1429 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1430 int y, int sRes, int eRes)
1432 eRes = Math.min(eRes, aa.annotations.length);
1433 g.setColor(Color.white);
1434 g.fillRect(0, 0, width, y);
1435 g.setColor(new Color(0, 0, 180));
1439 for (int j = sRes; j < eRes; j++)
1441 if (aa.annotations[j] != null)
1443 if (aa.annotations[j].colour == null)
1444 g.setColor(Color.black);
1446 g.setColor(aa.annotations[j].colour);
1448 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1454 g.fillRect(x, y - height, av.charWidth, height);