2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.event.*;
22 import java.awt.font.LineMetrics;
23 import java.awt.geom.AffineTransform;
24 import java.awt.image.*;
25 import java.util.Hashtable;
29 import com.stevesoft.pat.Regex;
31 import jalview.analysis.AAFrequency;
32 import jalview.datamodel.*;
33 import jalview.schemes.ColourSchemeI;
41 public class AnnotationPanel extends JPanel implements MouseListener,
42 MouseMotionListener, ActionListener, AdjustmentListener
44 final String HELIX = "Helix";
46 final String SHEET = "Sheet";
49 * For RNA secondary structure "stems" aka helices
51 final String STEM = "RNA Helix";
53 final String LABEL = "Label";
55 final String REMOVE = "Remove Annotation";
57 final String COLOUR = "Colour";
59 final Color HELIX_COLOUR = Color.red.darker();
61 final Color SHEET_COLOUR = Color.green.darker().darker();
63 final Color STEM_COLOUR = Color.blue.darker();
74 BufferedImage fadedImage;
82 boolean fastPaint = false;
84 // Used For mouse Dragging and resizing graphs
85 int graphStretch = -1;
87 int graphStretchY = -1;
89 int min; // used by mouseDragged to see if user
91 int max; // used by mouseDragged to see if user
93 boolean mouseDragging = false;
102 * Creates a new AnnotationPanel object.
107 public AnnotationPanel(AlignmentPanel ap)
110 MAC = new jalview.util.Platform().isAMac();
112 ToolTipManager.sharedInstance().registerComponent(this);
113 ToolTipManager.sharedInstance().setInitialDelay(0);
114 ToolTipManager.sharedInstance().setDismissDelay(10000);
117 this.setLayout(null);
118 addMouseListener(this);
119 addMouseMotionListener(this);
120 ap.annotationScroller.getVerticalScrollBar()
121 .addAdjustmentListener(this);
124 public AnnotationPanel(AlignViewport av)
135 public void adjustmentValueChanged(AdjustmentEvent evt)
137 ap.alabels.setScrollOffset(-evt.getValue());
141 * Calculates the height of the annotation displayed in the annotation panel.
142 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
143 * all annotation associated components are updated correctly.
146 public int adjustPanelHeight()
148 int height=calcPanelHeight();
149 this.setPreferredSize(new Dimension(1, height));
152 // revalidate only when the alignment panel is fully constructed
160 * calculate the height for visible annotation, revalidating bounds where necessary
161 * ABSTRACT GUI METHOD
162 * @return total height of annotation
164 public int calcPanelHeight()
166 // setHeight of panels
167 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
172 for (int i = 0; i < aa.length; i++)
176 System.err.println("Null annotation row: ignoring.");
188 aa[i].height += av.charHeight;
198 aa[i].height += aa[i].graphHeight;
201 if (aa[i].height == 0)
206 height += aa[i].height;
223 public void actionPerformed(ActionEvent evt)
225 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
230 Annotation[] anot = aa[activeRow].annotations;
232 if (anot.length < av.getColumnSelection().getMax())
234 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
235 System.arraycopy(anot, 0, temp, 0, anot.length);
237 aa[activeRow].annotations = anot;
240 if (evt.getActionCommand().equals(REMOVE))
242 for (int i = 0; i < av.getColumnSelection().size(); i++)
244 anot[av.getColumnSelection().columnAt(i)] = null;
247 else if (evt.getActionCommand().equals(LABEL))
249 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
250 String label = JOptionPane.showInputDialog(this, "Enter label",
258 if ((label.length() > 0) && !aa[activeRow].hasText)
260 aa[activeRow].hasText = true;
263 for (int i = 0; i < av.getColumnSelection().size(); i++)
265 int index = av.getColumnSelection().columnAt(i);
267 if (!av.colSel.isVisible(index))
270 if (anot[index] == null)
272 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
279 anot[index].displayCharacter = label;
283 else if (evt.getActionCommand().equals(COLOUR))
285 Color col = JColorChooser.showDialog(this,
286 "Choose foreground colour", Color.black);
288 for (int i = 0; i < av.getColumnSelection().size(); i++)
290 int index = av.getColumnSelection().columnAt(i);
292 if (!av.colSel.isVisible(index))
295 if (anot[index] == null)
297 anot[index] = new Annotation("", "", ' ', 0);
300 anot[index].colour = col;
307 String symbol = "\u03B1";
309 if (evt.getActionCommand().equals(HELIX))
313 else if (evt.getActionCommand().equals(SHEET))
319 // Added by LML to color stems
320 else if (evt.getActionCommand().equals(STEM))
326 if (!aa[activeRow].hasIcons)
328 aa[activeRow].hasIcons = true;
331 String label = JOptionPane.showInputDialog(
332 "Enter a label for the structure?", symbol);
339 if ((label.length() > 0) && !aa[activeRow].hasText)
341 aa[activeRow].hasText = true;
344 for (int i = 0; i < av.getColumnSelection().size(); i++)
346 int index = av.getColumnSelection().columnAt(i);
348 if (!av.colSel.isVisible(index))
351 if (anot[index] == null)
353 anot[index] = new Annotation(label, "", type, 0);
356 anot[index].secondaryStructure = type;
357 anot[index].displayCharacter = label;
367 private String collectAnnotVals(Annotation[] anot,
368 ColumnSelection columnSelection, String label2)
370 String collatedInput = "";
372 for (int i = 0; i < columnSelection.size(); i++)
374 int index = columnSelection.columnAt(i);
375 // always check for current display state - just in case
376 if (!av.colSel.isVisible(index))
378 String tlabel = null;
379 if (anot[index] != null)
380 { // LML added stem code
381 if (label2.equals(HELIX) || label2.equals(SHEET)
382 || label2.equals(STEM) || label2.equals(LABEL))
384 tlabel = anot[index].description;
385 if (tlabel == null || tlabel.length() < 1)
387 if (label2.equals(HELIX) || label2.equals(SHEET)
388 || label2.equals(STEM))
390 tlabel = "" + anot[index].secondaryStructure;
394 tlabel = "" + anot[index].displayCharacter;
398 if (tlabel != null && !tlabel.equals(last))
400 if (last.length() > 0)
402 collatedInput += " ";
404 collatedInput += tlabel;
408 return collatedInput;
417 public void mousePressed(MouseEvent evt)
420 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
429 for (int i = 0; i < aa.length; i++)
433 height += aa[i].height;
436 if (evt.getY() < height)
442 else if (aa[i].graph > 0)
446 graphStretchY = evt.getY();
453 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
455 if (av.getColumnSelection() == null)
460 JPopupMenu pop = new JPopupMenu("Structure type");
463 * Just display the needed structure options
465 if(av.alignment.isNucleotide()==true){
466 item = new JMenuItem(STEM);
467 item.addActionListener(this);
470 item = new JMenuItem(HELIX);
471 item.addActionListener(this);
473 item = new JMenuItem(SHEET);
474 item.addActionListener(this);
477 item = new JMenuItem(LABEL);
478 item.addActionListener(this);
480 item = new JMenuItem(COLOUR);
481 item.addActionListener(this);
483 item = new JMenuItem(REMOVE);
484 item.addActionListener(this);
486 pop.show(this, evt.getX(), evt.getY());
496 ap.scalePanel.mousePressed(evt);
506 public void mouseReleased(MouseEvent evt)
510 mouseDragging = false;
511 ap.scalePanel.mouseReleased(evt);
520 public void mouseEntered(MouseEvent evt)
522 ap.scalePanel.mouseEntered(evt);
531 public void mouseExited(MouseEvent evt)
533 ap.scalePanel.mouseExited(evt);
542 public void mouseDragged(MouseEvent evt)
544 if (graphStretch > -1)
546 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
548 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
550 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
552 graphStretchY = evt.getY();
554 ap.paintAlignment(true);
558 ap.scalePanel.mouseDragged(evt);
568 public void mouseMoved(MouseEvent evt)
570 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
574 this.setToolTipText(null);
581 for (int i = 0; i < aa.length; i++)
585 height += aa[i].height;
588 if (evt.getY() < height)
598 this.setToolTipText(null);
602 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
604 if (av.hasHiddenColumns)
606 res = av.getColumnSelection().adjustForHiddenColumns(res);
609 if (row > -1 && aa[row].annotations != null
610 && res < (int) aa[row].annotations.length)
612 if (aa[row].graphGroup > -1)
614 StringBuffer tip = new StringBuffer("<html>");
615 for (int gg = 0; gg < aa.length; gg++)
617 if (aa[gg].graphGroup == aa[row].graphGroup
618 && aa[gg].annotations[res] != null)
620 tip.append(aa[gg].label + " "
621 + aa[gg].annotations[res].description + "<br>");
624 if (tip.length() != 6)
626 tip.setLength(tip.length() - 4);
627 this.setToolTipText(tip.toString() + "</html>");
630 else if (aa[row].annotations[res] != null
631 && aa[row].annotations[res].description != null
632 && aa[row].annotations[res].description.length() > 0)
634 this.setToolTipText(aa[row].annotations[res].description);
638 // clear the tooltip.
639 this.setToolTipText(null);
642 if (aa[row].annotations[res] != null)
644 StringBuffer text = new StringBuffer("Sequence position "
647 if (aa[row].annotations[res].description != null)
649 text.append(" " + aa[row].annotations[res].description);
652 ap.alignFrame.statusBar.setText(text.toString());
657 this.setToolTipText(null);
667 public void mouseClicked(MouseEvent evt)
670 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
671 AlignmentAnnotation anot = aa[activeRow];
673 if(anot.description.equals("secondary structure")){
674 //System.out.println(anot.description+" "+anot.getRNAStruc());
678 //TODO mouseClicked-content and drawCursor are quite experimental!
679 public void drawCursor(Graphics graphics, SequenceI seq, int res, int x1, int y1)
681 int pady = av.charHeight / 5;
683 graphics.setColor(Color.black);
684 graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
686 if (av.validCharWidth)
688 graphics.setColor(Color.white);
690 char s = seq.getCharAt(res);
692 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
693 graphics.drawString(String.valueOf(s), charOffset + x1,
694 (y1 + av.charHeight) - pady);
705 public void paintComponent(Graphics g)
707 g.setColor(Color.white);
708 g.fillRect(0, 0, getWidth(), getHeight());
712 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
713 || (getVisibleRect().height != g.getClipBounds().height))
715 g.drawImage(image, 0, 0, this);
720 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
723 if (image == null || imgWidth != image.getWidth()
724 || image.getHeight(this) != getHeight())
726 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
727 BufferedImage.TYPE_INT_RGB);
728 gg = (Graphics2D) image.getGraphics();
732 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
733 RenderingHints.VALUE_ANTIALIAS_ON);
736 gg.setFont(av.getFont());
737 fm = gg.getFontMetrics();
738 gg.setColor(Color.white);
739 gg.fillRect(0, 0, imgWidth, image.getHeight());
742 drawComponent(gg, av.startRes, av.endRes + 1);
743 g.drawImage(image, 0, 0, this);
747 * non-Thread safe repaint
750 * repaint with horizontal shift in alignment
752 public void fastPaint(int horizontal)
755 if ((horizontal == 0) || gg == null
756 || av.alignment.getAlignmentAnnotation() == null
757 || av.alignment.getAlignmentAnnotation().length < 1
758 || av.updatingConsensus || av.updatingConservation)
763 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
765 int sr = av.startRes;
766 int er = av.endRes + 1;
769 if (horizontal > 0) // scrollbar pulled right, image to the left
771 transX = (er - sr - horizontal) * av.charWidth;
772 sr = er - horizontal;
774 else if (horizontal < 0)
776 er = sr - horizontal;
779 gg.translate(transX, 0);
781 drawComponent(gg, sr, er);
783 gg.translate(-transX, 0);
800 public void drawComponent(Graphics g, int startRes, int endRes)
802 if (av.updatingConsensus || av.updatingConservation)
808 // We'll keep a record of the old image,
809 // and draw a faded image until the calculation
811 if (fadedImage == null || fadedImage.getWidth() != imgWidth
812 || fadedImage.getHeight() != image.getHeight())
814 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
815 BufferedImage.TYPE_INT_RGB);
817 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
819 fadedG.setColor(Color.white);
820 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
822 fadedG.setComposite(AlphaComposite.getInstance(
823 AlphaComposite.SRC_OVER, .3f));
824 fadedG.drawImage(image, 0, 0, this);
834 g.setColor(Color.white);
835 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
837 g.setFont(av.getFont());
840 fm = g.getFontMetrics();
843 if ((av.alignment.getAlignmentAnnotation() == null)
844 || (av.alignment.getAlignmentAnnotation().length < 1))
846 g.setColor(Color.white);
847 g.fillRect(0, 0, getWidth(), getHeight());
848 g.setColor(Color.black);
849 if (av.validCharWidth)
851 g.drawString("Alignment has no annotations", 20, 15);
857 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
864 boolean validRes = false;
865 boolean validEnd = false;
866 boolean labelAllCols = false;
867 boolean centreColLabels, centreColLabelsDef = av
868 .getCentreColumnLabels();
869 boolean scaleColLabel = false;
870 boolean[] graphGroupDrawn = new boolean[aa.length];
871 int charOffset = 0; // offset for a label
872 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
874 Font ofont = g.getFont();
876 for (int i = 0; i < aa.length; i++)
878 AlignmentAnnotation row = aa[i];
884 centreColLabels = row.centreColLabels || centreColLabelsDef;
885 labelAllCols = row.showAllColLabels;
886 scaleColLabel = row.scaleColLabel;
891 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
896 // this is so that we draw the characters below the graph
901 iconOffset = av.charHeight - fm.getDescent();
905 else if (row.hasText)
907 iconOffset = av.charHeight - fm.getDescent();
915 if (av.updatingConsensus && aa[i] == av.consensus)
919 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
920 - row.height, imgWidth, y, this);
921 g.setColor(Color.black);
922 // g.drawString("Calculating Consensus....",20, y-row.height/2);
926 else if (av.updatingConservation
927 && aa[i].label.equals("Conservation"))
931 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
932 - row.height, imgWidth, y, this);
934 g.setColor(Color.black);
935 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
939 else if (av.updatingConservation && aa[i].label.equals("Quality"))
943 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
944 - row.height, imgWidth, y, this);
945 g.setColor(Color.black);
946 // / g.drawString("Calculating Quality....",20, y-row.height/2);
951 // first pass sets up state for drawing continuation from left-hand column
953 x = (startRes == 0) ? 0 : -1;
954 while (x < endRes - startRes)
956 if (av.hasHiddenColumns)
958 column = av.getColumnSelection().adjustForHiddenColumns(
960 if (column > row.annotations.length - 1)
967 column = startRes + x;
970 if ((row.annotations == null) || (row.annotations.length <= column)
971 || (row.annotations[column] == null))
983 g.setColor(Color.red);
985 if (av.getColumnSelection() != null)
987 for (int n = 0; n < av.getColumnSelection().size(); n++)
989 int v = av.getColumnSelection().columnAt(n);
993 g.fillRect(x * av.charWidth, y, av.charWidth,
1000 if (av.validCharWidth
1002 && row.annotations[column].displayCharacter != null
1003 && (row.annotations[column].displayCharacter.length() > 0))
1006 if (centreColLabels || scaleColLabel)
1008 fmWidth = (float) fm.charsWidth(
1009 row.annotations[column].displayCharacter
1011 row.annotations[column].displayCharacter.length());
1015 // justify the label and scale to fit in column
1016 if (fmWidth > av.charWidth)
1018 // scale only if the current font isn't already small enough
1019 fmScaling = av.charWidth;
1020 fmScaling /= fmWidth;
1021 g.setFont(ofont.deriveFont(AffineTransform
1022 .getScaleInstance(fmScaling, 1.0)));
1023 // and update the label's width to reflect the scaling.
1024 fmWidth = av.charWidth;
1030 fmWidth = (float) fm
1031 .charWidth(row.annotations[column].displayCharacter
1034 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
1036 if (row.annotations[column].colour == null)
1037 g.setColor(Color.black);
1039 g.setColor(row.annotations[column].colour);
1041 if (column == 0 || row.graph > 0)
1043 g.drawString(row.annotations[column].displayCharacter,
1044 (x * av.charWidth) + charOffset, y + iconOffset);
1046 else if (row.annotations[column - 1] == null
1048 || !row.annotations[column].displayCharacter
1049 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
1050 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
1052 g.drawString(row.annotations[column].displayCharacter, x
1053 * av.charWidth + charOffset, y + iconOffset);
1061 || (row.annotations[column].secondaryStructure != lastSS))
1068 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1069 column, validRes, validEnd);
1073 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1074 column, validRes, validEnd);
1077 case 'S': // Stem case for RNA secondary structure
1078 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1079 column, validRes, validEnd);
1083 g.setColor(Color.gray);
1084 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1092 lastSS = row.annotations[column].secondaryStructure;
1100 lastSSX = (x * av.charWidth);
1109 if (column >= row.annotations.length)
1111 column = row.annotations.length - 1;
1126 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1127 column, validRes, validEnd);
1131 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1132 column, validRes, validEnd);
1134 case 'S': // Stem case for RNA secondary structure
1135 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1136 column, validRes, validEnd);
1139 drawGlyphLine(g, row, lastSSX, x, y, iconOffset, startRes,
1140 column, validRes, validEnd);
1145 if (row.graph > 0 && row.graphHeight > 0)
1147 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1149 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1151 float groupmax = -999999, groupmin = 9999999;
1152 for (int gg = 0; gg < aa.length; gg++)
1154 if (aa[gg].graphGroup != row.graphGroup)
1161 aa[gg].visible = false;
1164 if (aa[gg].graphMax > groupmax)
1166 groupmax = aa[gg].graphMax;
1168 if (aa[gg].graphMin < groupmin)
1170 groupmin = aa[gg].graphMin;
1174 for (int gg = 0; gg < aa.length; gg++)
1176 if (aa[gg].graphGroup == row.graphGroup)
1178 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1179 groupmax, row.graphHeight);
1183 graphGroupDrawn[row.graphGroup] = true;
1187 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1188 row.graphMax, row.graphHeight);
1191 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1193 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1198 if (row.graph > 0 && row.hasText)
1210 private void drawStemAnnot(Graphics g, AlignmentAnnotation row,
1211 int lastSSX, int x, int y, int iconOffset, int startRes,
1212 int column, boolean validRes, boolean validEnd)
1214 g.setColor(STEM_COLOUR);
1215 int sCol = (lastSSX / av.charWidth) + startRes;
1217 int x2 = (x * av.charWidth);
1218 Regex closeparen = new Regex("(\\))");
1221 // If a closing base pair half of the stem, display a backward arrow
1222 if (column>0 && closeparen.search(dc=row.annotations[column - 1].displayCharacter))
1224 if (sCol == 0 || row.annotations[sCol - 1] == null
1225 || !dc.equals(row.annotations[sCol - 1].displayCharacter))
1226 //if (validRes && column>1 && row.annotations[column-2]!=null && dc.equals(row.annotations[column-2].displayCharacter))
1227 { g.fillPolygon(new int[]
1228 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
1229 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
1235 // display a forward arrow
1236 if (!validRes || row.annotations[column] == null
1237 || !dc.equals(row.annotations[column].displayCharacter))
1243 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
1249 g.fillRect(x1, y + 4 + iconOffset, x2-x1, 7);
1252 private void drawGlyphLine(Graphics g, AlignmentAnnotation row,
1253 int lastSSX, int x, int y, int iconOffset, int startRes,
1254 int column, boolean validRes, boolean validEnd)
1256 g.setColor(Color.gray);
1257 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth) - lastSSX, 2);
1260 private void drawSheetAnnot(Graphics g, AlignmentAnnotation row,
1261 int lastSSX, int x, int y, int iconOffset, int startRes,
1262 int column, boolean validRes, boolean validEnd)
1264 g.setColor(SHEET_COLOUR);
1266 if (!validEnd || !validRes || row.annotations[column] == null
1267 || row.annotations[column].secondaryStructure != 'E')
1269 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth) - lastSSX
1273 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1274 (x * av.charWidth) }, new int[]
1275 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1280 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1286 private void drawHelixAnnot(Graphics g, AlignmentAnnotation row,
1287 int lastSSX, int x, int y, int iconOffset, int startRes,
1288 int column, boolean validRes, boolean validEnd)
1290 g.setColor(HELIX_COLOUR);
1292 int sCol = (lastSSX / av.charWidth) + startRes;
1294 int x2 = (x * av.charWidth);
1298 int ofs=av.charWidth/2;
1299 // Off by 1 offset when drawing rects and ovals
1300 // to offscreen image on the MAC
1301 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2-x1, 8, 8, 8);
1302 if (sCol == 0 || row.annotations[sCol - 1] == null
1303 || row.annotations[sCol - 1].secondaryStructure != 'H')
1306 // g.setColor(Color.orange);
1307 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2-x1-ofs+1, 8, 0, 0);
1309 if (!validRes || row.annotations[column] == null
1310 || row.annotations[column].secondaryStructure != 'H')
1314 // g.setColor(Color.magenta);
1315 g.fillRoundRect(lastSSX+ofs, y + 4 + iconOffset, x2-x1-ofs+1, 8, 0, 0);
1322 if (sCol == 0 || row.annotations[sCol - 1] == null
1323 || row.annotations[sCol - 1].secondaryStructure != 'H')
1325 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
1326 x1 += av.charWidth / 2;
1329 if (!validRes || row.annotations[column] == null
1330 || row.annotations[column].secondaryStructure != 'H')
1332 g.fillArc((x * av.charWidth) - av.charWidth, y + 4 + iconOffset,
1333 av.charWidth, 8, 270, 180);
1334 x2 -= av.charWidth / 2;
1337 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1340 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1341 int eRes, int y, float min, float max, int graphHeight)
1343 if (sRes > aa.annotations.length)
1350 // Adjustment for fastpaint to left
1351 if (eRes < av.endRes)
1356 eRes = Math.min(eRes, aa.annotations.length);
1364 float range = max - min;
1369 y2 = y - (int) ((0 - min / range) * graphHeight);
1372 g.setColor(Color.gray);
1373 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1375 eRes = Math.min(eRes, aa.annotations.length);
1378 int aaMax = aa.annotations.length - 1;
1380 while (x < eRes - sRes)
1383 if (av.hasHiddenColumns)
1385 column = av.getColumnSelection().adjustForHiddenColumns(column);
1393 if (aa.annotations[column] == null
1394 || aa.annotations[column - 1] == null)
1400 if (aa.annotations[column].colour == null)
1401 g.setColor(Color.black);
1403 g.setColor(aa.annotations[column].colour);
1406 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1408 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1410 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1411 + av.charWidth / 2, y2);
1415 if (aa.threshold != null)
1417 g.setColor(aa.threshold.colour);
1418 Graphics2D g2 = (Graphics2D) g;
1419 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1420 BasicStroke.JOIN_ROUND, 3f, new float[]
1423 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1424 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1425 g2.setStroke(new BasicStroke());
1429 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1430 int eRes, float min, float max, int y)
1432 ColourSchemeI profcolour = av.getGlobalColourScheme();
1433 if (profcolour == null)
1435 profcolour = new jalview.schemes.ZappoColourScheme();
1437 if (sRes > aa.annotations.length)
1441 Font ofont = g.getFont();
1442 eRes = Math.min(eRes, aa.annotations.length);
1444 int x = 0, y1 = y, y2 = y;
1446 float range = max - min;
1450 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1453 g.setColor(Color.gray);
1455 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1458 int aaMax = aa.annotations.length - 1;
1459 boolean renderHistogram = true, renderProfile = true;
1460 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1462 // TODO: generalise this to have render styles for consensus/profile data
1463 if (aa.groupRef != null)
1465 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1466 renderProfile = aa.groupRef.isShowSequenceLogo();
1470 renderHistogram = av.isShowConsensusHistogram();
1471 renderProfile = av.isShowSequenceLogo();
1474 while (x < eRes - sRes)
1477 if (av.hasHiddenColumns)
1479 column = av.getColumnSelection().adjustForHiddenColumns(column);
1487 if (aa.annotations[column] == null)
1492 if (aa.annotations[column].colour == null)
1493 g.setColor(Color.black);
1495 g.setColor(aa.annotations[column].colour);
1498 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1500 if (renderHistogram)
1504 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1508 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1511 // draw profile if available
1512 if (renderProfile && aa.annotations[column].value != 0)
1514 int profl[] = getProfileFor(aa, column);
1515 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1518 char[] dc = new char[1];
1520 for (int c = 1; profl != null && c < profl[0];)
1522 dc[0] = (char) profl[c++];
1523 wdth = av.charWidth;
1524 wdth /= (float) fm.charsWidth(dc, 0, 1);
1531 // if (aa.annotations[column].value==0) {
1532 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1533 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1534 // ht = y2-(int)ht2;
1536 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1537 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1539 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1542 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1543 // ? );// try to get a
1544 // colourscheme for the
1545 // group(aa.groupRef.cs==null)
1546 // ? av.textColour2 :
1547 // cs.findColour(dc));
1548 g.drawChars(dc, 0, 1, x * av.charWidth,
1549 (int) (ht + lm.getHeight()));
1550 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1557 if (aa.threshold != null)
1559 g.setColor(aa.threshold.colour);
1560 Graphics2D g2 = (Graphics2D) g;
1561 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1562 BasicStroke.JOIN_ROUND, 3f, new float[]
1565 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1566 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1567 g2.setStroke(new BasicStroke());
1571 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1573 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1575 if (aa.groupRef != null && aa.groupRef.consensusData != null
1576 && aa.groupRef.isShowSequenceLogo())
1578 return AAFrequency.extractProfile(
1579 aa.groupRef.consensusData[column],
1580 aa.groupRef.getIgnoreGapsConsensus());
1582 // TODO extend annotation row to enable dynamic and static profile data to
1584 if (aa.groupRef == null && aa.sequenceRef == null
1585 && av.isShowSequenceLogo())
1587 return AAFrequency.extractProfile(av.hconsensus[column],
1588 av.getIgnoreGapsConsensus());
1594 // used by overview window
1595 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1596 int y, int sRes, int eRes)
1598 eRes = Math.min(eRes, aa.annotations.length);
1599 g.setColor(Color.white);
1600 g.fillRect(0, 0, width, y);
1601 g.setColor(new Color(0, 0, 180));
1605 for (int j = sRes; j < eRes; j++)
1607 if (aa.annotations[j] != null)
1609 if (aa.annotations[j].colour == null)
1610 g.setColor(Color.black);
1612 g.setColor(aa.annotations[j].colour);
1614 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1620 g.fillRect(x, y - height, av.charWidth, height);