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.analysis.StructureFrequency;
33 import jalview.datamodel.*;
34 import jalview.schemes.ColourSchemeI;
42 public class AnnotationPanel extends JPanel implements MouseListener,
43 MouseMotionListener, ActionListener, AdjustmentListener
45 final String HELIX = "Helix";
47 final String SHEET = "Sheet";
50 * For RNA secondary structure "stems" aka helices
52 final String STEM = "RNA Helix";
54 final String LABEL = "Label";
56 final String REMOVE = "Remove Annotation";
58 final String COLOUR = "Colour";
60 final Color HELIX_COLOUR = Color.red.darker();
62 final Color SHEET_COLOUR = Color.green.darker().darker();
64 final Color STEM_COLOUR = Color.blue.darker();
75 BufferedImage fadedImage;
83 boolean fastPaint = false;
85 // Used For mouse Dragging and resizing graphs
86 int graphStretch = -1;
88 int graphStretchY = -1;
90 int min; // used by mouseDragged to see if user
92 int max; // used by mouseDragged to see if user
94 boolean mouseDragging = false;
104 * Creates a new AnnotationPanel object.
109 public AnnotationPanel(AlignmentPanel ap)
112 MAC = new jalview.util.Platform().isAMac();
114 ToolTipManager.sharedInstance().registerComponent(this);
115 ToolTipManager.sharedInstance().setInitialDelay(0);
116 ToolTipManager.sharedInstance().setDismissDelay(10000);
119 this.setLayout(null);
120 addMouseListener(this);
121 addMouseMotionListener(this);
122 ap.annotationScroller.getVerticalScrollBar()
123 .addAdjustmentListener(this);
126 public AnnotationPanel(AlignViewport av)
137 public void adjustmentValueChanged(AdjustmentEvent evt)
139 ap.alabels.setScrollOffset(-evt.getValue());
143 * Calculates the height of the annotation displayed in the annotation panel.
144 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
145 * all annotation associated components are updated correctly.
148 public int adjustPanelHeight()
150 int height = calcPanelHeight();
151 this.setPreferredSize(new Dimension(1, height));
154 // revalidate only when the alignment panel is fully constructed
162 * calculate the height for visible annotation, revalidating bounds where
163 * necessary ABSTRACT GUI METHOD
165 * @return total height of annotation
167 public int calcPanelHeight()
169 // setHeight of panels
170 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
175 for (int i = 0; i < aa.length; i++)
179 System.err.println("Null annotation row: ignoring.");
191 aa[i].height += av.charHeight;
201 aa[i].height += aa[i].graphHeight;
204 if (aa[i].height == 0)
209 height += aa[i].height;
226 public void actionPerformed(ActionEvent evt)
228 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
233 Annotation[] anot = aa[activeRow].annotations;
235 if (anot.length < av.getColumnSelection().getMax())
237 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
238 System.arraycopy(anot, 0, temp, 0, anot.length);
240 aa[activeRow].annotations = anot;
243 if (evt.getActionCommand().equals(REMOVE))
245 for (int i = 0; i < av.getColumnSelection().size(); i++)
247 anot[av.getColumnSelection().columnAt(i)] = null;
250 else if (evt.getActionCommand().equals(LABEL))
252 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
253 String label = JOptionPane.showInputDialog(this, "Enter label",
261 if ((label.length() > 0) && !aa[activeRow].hasText)
263 aa[activeRow].hasText = true;
266 for (int i = 0; i < av.getColumnSelection().size(); i++)
268 int index = av.getColumnSelection().columnAt(i);
270 if (!av.colSel.isVisible(index))
273 if (anot[index] == null)
275 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
282 anot[index].displayCharacter = label;
286 else if (evt.getActionCommand().equals(COLOUR))
288 Color col = JColorChooser.showDialog(this,
289 "Choose foreground colour", Color.black);
291 for (int i = 0; i < av.getColumnSelection().size(); i++)
293 int index = av.getColumnSelection().columnAt(i);
295 if (!av.colSel.isVisible(index))
298 if (anot[index] == null)
300 anot[index] = new Annotation("", "", ' ', 0);
303 anot[index].colour = col;
310 String symbol = "\u03B1";
312 if (evt.getActionCommand().equals(HELIX))
316 else if (evt.getActionCommand().equals(SHEET))
322 // Added by LML to color stems
323 else if (evt.getActionCommand().equals(STEM))
329 if (!aa[activeRow].hasIcons)
331 aa[activeRow].hasIcons = true;
334 String label = JOptionPane.showInputDialog(
335 "Enter a label for the structure?", symbol);
342 if ((label.length() > 0) && !aa[activeRow].hasText)
344 aa[activeRow].hasText = true;
347 for (int i = 0; i < av.getColumnSelection().size(); i++)
349 int index = av.getColumnSelection().columnAt(i);
351 if (!av.colSel.isVisible(index))
354 if (anot[index] == null)
356 anot[index] = new Annotation(label, "", type, 0);
359 anot[index].secondaryStructure = type;
360 anot[index].displayCharacter = label;
370 private String collectAnnotVals(Annotation[] anot,
371 ColumnSelection columnSelection, String label2)
373 String collatedInput = "";
375 for (int i = 0; i < columnSelection.size(); i++)
377 int index = columnSelection.columnAt(i);
378 // always check for current display state - just in case
379 if (!av.colSel.isVisible(index))
381 String tlabel = null;
382 if (anot[index] != null)
383 { // LML added stem code
384 if (label2.equals(HELIX) || label2.equals(SHEET)
385 || label2.equals(STEM) || label2.equals(LABEL))
387 tlabel = anot[index].description;
388 if (tlabel == null || tlabel.length() < 1)
390 if (label2.equals(HELIX) || label2.equals(SHEET)
391 || label2.equals(STEM))
393 tlabel = "" + anot[index].secondaryStructure;
397 tlabel = "" + anot[index].displayCharacter;
401 if (tlabel != null && !tlabel.equals(last))
403 if (last.length() > 0)
405 collatedInput += " ";
407 collatedInput += tlabel;
411 return collatedInput;
420 public void mousePressed(MouseEvent evt)
423 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
432 for (int i = 0; i < aa.length; i++)
436 height += aa[i].height;
439 if (evt.getY() < height)
445 else if (aa[i].graph > 0)
449 graphStretchY = evt.getY();
456 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
458 if (av.getColumnSelection() == null)
463 JPopupMenu pop = new JPopupMenu("Structure type");
466 * Just display the needed structure options
468 if (av.alignment.isNucleotide() == true)
470 item = new JMenuItem(STEM);
471 item.addActionListener(this);
476 item = new JMenuItem(HELIX);
477 item.addActionListener(this);
479 item = new JMenuItem(SHEET);
480 item.addActionListener(this);
483 item = new JMenuItem(LABEL);
484 item.addActionListener(this);
486 item = new JMenuItem(COLOUR);
487 item.addActionListener(this);
489 item = new JMenuItem(REMOVE);
490 item.addActionListener(this);
492 pop.show(this, evt.getX(), evt.getY());
502 ap.scalePanel.mousePressed(evt);
512 public void mouseReleased(MouseEvent evt)
516 mouseDragging = false;
517 ap.scalePanel.mouseReleased(evt);
526 public void mouseEntered(MouseEvent evt)
528 ap.scalePanel.mouseEntered(evt);
537 public void mouseExited(MouseEvent evt)
539 ap.scalePanel.mouseExited(evt);
548 public void mouseDragged(MouseEvent evt)
550 if (graphStretch > -1)
552 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
554 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
556 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
558 graphStretchY = evt.getY();
560 ap.paintAlignment(true);
564 ap.scalePanel.mouseDragged(evt);
574 public void mouseMoved(MouseEvent evt)
576 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
580 this.setToolTipText(null);
587 for (int i = 0; i < aa.length; i++)
591 height += aa[i].height;
594 if (evt.getY() < height)
604 this.setToolTipText(null);
608 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
610 if (av.hasHiddenColumns)
612 res = av.getColumnSelection().adjustForHiddenColumns(res);
615 if (row > -1 && aa[row].annotations != null
616 && res < (int) aa[row].annotations.length)
618 if (aa[row].graphGroup > -1)
620 StringBuffer tip = new StringBuffer("<html>");
621 for (int gg = 0; gg < aa.length; gg++)
623 if (aa[gg].graphGroup == aa[row].graphGroup
624 && aa[gg].annotations[res] != null)
626 tip.append(aa[gg].label + " "
627 + aa[gg].annotations[res].description + "<br>");
630 if (tip.length() != 6)
632 tip.setLength(tip.length() - 4);
633 this.setToolTipText(tip.toString() + "</html>");
636 else if (aa[row].annotations[res] != null
637 && aa[row].annotations[res].description != null
638 && aa[row].annotations[res].description.length() > 0)
640 this.setToolTipText(aa[row].annotations[res].description);
644 // clear the tooltip.
645 this.setToolTipText(null);
648 if (aa[row].annotations[res] != null)
650 StringBuffer text = new StringBuffer("Sequence position "
653 if (aa[row].annotations[res].description != null)
655 text.append(" " + aa[row].annotations[res].description);
658 ap.alignFrame.statusBar.setText(text.toString());
663 this.setToolTipText(null);
673 public void mouseClicked(MouseEvent evt)
677 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
678 AlignmentAnnotation anot = aa[activeRow];
680 if (anot.description.equals("secondary structure"))
682 // System.out.println(anot.description+" "+anot.getRNAStruc());
687 // TODO mouseClicked-content and drawCursor are quite experimental!
688 public void drawCursor(Graphics graphics, SequenceI seq, int res, int x1,
691 int pady = av.charHeight / 5;
693 graphics.setColor(Color.black);
694 graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
696 if (av.validCharWidth)
698 graphics.setColor(Color.white);
700 char s = seq.getCharAt(res);
702 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
703 graphics.drawString(String.valueOf(s), charOffset + x1,
704 (y1 + av.charHeight) - pady);
715 public void paintComponent(Graphics g)
717 g.setColor(Color.white);
718 g.fillRect(0, 0, getWidth(), getHeight());
722 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
723 || (getVisibleRect().height != g.getClipBounds().height))
725 g.drawImage(image, 0, 0, this);
730 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
733 if (image == null || imgWidth != image.getWidth()
734 || image.getHeight(this) != getHeight())
736 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
737 BufferedImage.TYPE_INT_RGB);
738 gg = (Graphics2D) image.getGraphics();
742 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
743 RenderingHints.VALUE_ANTIALIAS_ON);
746 gg.setFont(av.getFont());
747 fm = gg.getFontMetrics();
748 gg.setColor(Color.white);
749 gg.fillRect(0, 0, imgWidth, image.getHeight());
752 drawComponent(gg, av.startRes, av.endRes + 1);
753 g.drawImage(image, 0, 0, this);
757 * non-Thread safe repaint
760 * repaint with horizontal shift in alignment
762 public void fastPaint(int horizontal)
765 if ((horizontal == 0) || gg == null
766 || av.alignment.getAlignmentAnnotation() == null
767 || av.alignment.getAlignmentAnnotation().length < 1
768 || av.updatingConsensus || av.updatingConservation)
773 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
775 int sr = av.startRes;
776 int er = av.endRes + 1;
779 if (horizontal > 0) // scrollbar pulled right, image to the left
781 transX = (er - sr - horizontal) * av.charWidth;
782 sr = er - horizontal;
784 else if (horizontal < 0)
786 er = sr - horizontal;
789 gg.translate(transX, 0);
791 drawComponent(gg, sr, er);
793 gg.translate(-transX, 0);
810 public void drawComponent(Graphics g, int startRes, int endRes)
812 if (av.updatingConsensus || av.updatingConservation)
818 // We'll keep a record of the old image,
819 // and draw a faded image until the calculation
821 if (fadedImage == null || fadedImage.getWidth() != imgWidth
822 || fadedImage.getHeight() != image.getHeight())
824 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
825 BufferedImage.TYPE_INT_RGB);
827 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
829 fadedG.setColor(Color.white);
830 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
832 fadedG.setComposite(AlphaComposite.getInstance(
833 AlphaComposite.SRC_OVER, .3f));
834 fadedG.drawImage(image, 0, 0, this);
844 g.setColor(Color.white);
845 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
847 g.setFont(av.getFont());
850 fm = g.getFontMetrics();
853 if ((av.alignment.getAlignmentAnnotation() == null)
854 || (av.alignment.getAlignmentAnnotation().length < 1))
856 g.setColor(Color.white);
857 g.fillRect(0, 0, getWidth(), getHeight());
858 g.setColor(Color.black);
859 if (av.validCharWidth)
861 g.drawString("Alignment has no annotations", 20, 15);
867 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
874 boolean validRes = false;
875 boolean validEnd = false;
876 boolean labelAllCols = false;
877 boolean centreColLabels, centreColLabelsDef = av
878 .getCentreColumnLabels();
879 boolean scaleColLabel = false;
880 boolean[] graphGroupDrawn = new boolean[aa.length];
881 int charOffset = 0; // offset for a label
882 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
884 Font ofont = g.getFont();
886 for (int i = 0; i < aa.length; i++)
888 AlignmentAnnotation row = aa[i];
894 centreColLabels = row.centreColLabels || centreColLabelsDef;
895 labelAllCols = row.showAllColLabels;
896 scaleColLabel = row.scaleColLabel;
901 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
906 // this is so that we draw the characters below the graph
911 iconOffset = av.charHeight - fm.getDescent();
915 else if (row.hasText)
917 iconOffset = av.charHeight - fm.getDescent();
925 if (av.updatingConsensus && aa[i] == av.consensus)
929 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
930 - row.height, imgWidth, y, this);
931 g.setColor(Color.black);
932 // g.drawString("Calculating Consensus....",20, y-row.height/2);
936 else if (av.updatingConservation
937 && aa[i].label.equals("Conservation"))
941 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
942 - row.height, imgWidth, y, this);
944 g.setColor(Color.black);
945 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
949 else if (av.updatingConservation && aa[i].label.equals("Quality"))
953 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
954 - row.height, imgWidth, y, this);
955 g.setColor(Color.black);
956 // / g.drawString("Calculating Quality....",20, y-row.height/2);
961 // first pass sets up state for drawing continuation from left-hand column
963 x = (startRes == 0) ? 0 : -1;
964 while (x < endRes - startRes)
966 if (av.hasHiddenColumns)
968 column = av.getColumnSelection().adjustForHiddenColumns(
970 if (column > row.annotations.length - 1)
977 column = startRes + x;
980 if ((row.annotations == null) || (row.annotations.length <= column)
981 || (row.annotations[column] == null))
993 g.setColor(Color.red);
995 if (av.getColumnSelection() != null)
997 for (int n = 0; n < av.getColumnSelection().size(); n++)
999 int v = av.getColumnSelection().columnAt(n);
1003 g.fillRect(x * av.charWidth, y, av.charWidth,
1010 if (av.validCharWidth
1012 && row.annotations[column].displayCharacter != null
1013 && (row.annotations[column].displayCharacter.length() > 0))
1016 if (centreColLabels || scaleColLabel)
1018 fmWidth = (float) fm.charsWidth(
1019 row.annotations[column].displayCharacter
1021 row.annotations[column].displayCharacter.length());
1025 // justify the label and scale to fit in column
1026 if (fmWidth > av.charWidth)
1028 // scale only if the current font isn't already small enough
1029 fmScaling = av.charWidth;
1030 fmScaling /= fmWidth;
1031 g.setFont(ofont.deriveFont(AffineTransform
1032 .getScaleInstance(fmScaling, 1.0)));
1033 // and update the label's width to reflect the scaling.
1034 fmWidth = av.charWidth;
1040 fmWidth = (float) fm
1041 .charWidth(row.annotations[column].displayCharacter
1044 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
1046 if (row.annotations[column].colour == null)
1047 g.setColor(Color.black);
1049 g.setColor(row.annotations[column].colour);
1051 if (column == 0 || row.graph > 0)
1053 g.drawString(row.annotations[column].displayCharacter,
1054 (x * av.charWidth) + charOffset, y + iconOffset);
1056 else if (row.annotations[column - 1] == null
1058 || !row.annotations[column].displayCharacter
1059 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
1060 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
1062 g.drawString(row.annotations[column].displayCharacter, x
1063 * av.charWidth + charOffset, y + iconOffset);
1070 char ss = validRes ? row.annotations[column].secondaryStructure
1074 // distinguish between forward/backward base-pairing
1075 if (row.annotations[column].displayCharacter.indexOf(')') > -1)
1080 if (!validRes || (ss != lastSS))
1087 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1088 column, validRes, validEnd);
1092 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1093 column, validRes, validEnd);
1096 case 'S': // Stem case for RNA secondary structure
1097 case 's': // and opposite direction
1098 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1099 column, validRes, validEnd);
1103 g.setColor(Color.gray);
1104 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1120 lastSSX = (x * av.charWidth);
1127 if (column >= row.annotations.length)
1129 column = row.annotations.length - 1;
1144 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1145 column, validRes, validEnd);
1149 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1150 column, validRes, validEnd);
1153 case 'S': // Stem case for RNA secondary structure
1154 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1155 column, validRes, validEnd);
1158 drawGlyphLine(g, row, lastSSX, x, y, iconOffset, startRes,
1159 column, validRes, validEnd);
1164 if (row.graph > 0 && row.graphHeight > 0)
1166 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1168 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1170 float groupmax = -999999, groupmin = 9999999;
1171 for (int gg = 0; gg < aa.length; gg++)
1173 if (aa[gg].graphGroup != row.graphGroup)
1180 aa[gg].visible = false;
1183 if (aa[gg].graphMax > groupmax)
1185 groupmax = aa[gg].graphMax;
1187 if (aa[gg].graphMin < groupmin)
1189 groupmin = aa[gg].graphMin;
1193 for (int gg = 0; gg < aa.length; gg++)
1195 if (aa[gg].graphGroup == row.graphGroup)
1197 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1198 groupmax, row.graphHeight);
1202 graphGroupDrawn[row.graphGroup] = true;
1206 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1207 row.graphMax, row.graphHeight);
1210 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1212 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1217 if (row.graph > 0 && row.hasText)
1229 private void drawStemAnnot(Graphics g, AlignmentAnnotation row,
1230 int lastSSX, int x, int y, int iconOffset, int startRes,
1231 int column, boolean validRes, boolean validEnd)
1233 g.setColor(STEM_COLOUR);
1234 int sCol = (lastSSX / av.charWidth) + startRes;
1236 int x2 = (x * av.charWidth);
1237 Regex closeparen = new Regex("(\\))");
1239 String dc = column == 0 ? ""
1240 : row.annotations[column - 1].displayCharacter;
1242 boolean diffupstream = sCol == 0 || row.annotations[sCol - 1] == null
1243 || !dc.equals(row.annotations[sCol - 1].displayCharacter);
1244 boolean diffdownstream = !validRes || !validEnd
1245 || row.annotations[column] == null
1246 || !dc.equals(row.annotations[column].displayCharacter);
1247 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
1248 // If a closing base pair half of the stem, display a backward arrow
1249 if (column > 0 && closeparen.search(dc))
1252 // if (validRes && column>1 && row.annotations[column-2]!=null &&
1253 // dc.equals(row.annotations[column-2].displayCharacter))
1255 g.fillPolygon(new int[]
1256 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
1257 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
1267 // display a forward arrow
1270 g.fillPolygon(new int[]
1271 { x2 - 5, x2 - 5, x2 }, new int[]
1272 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
1281 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
1284 private void drawGlyphLine(Graphics g, AlignmentAnnotation row,
1285 int lastSSX, int x, int y, int iconOffset, int startRes,
1286 int column, boolean validRes, boolean validEnd)
1288 g.setColor(Color.gray);
1290 .fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1294 private void drawSheetAnnot(Graphics g, AlignmentAnnotation row,
1295 int lastSSX, int x, int y, int iconOffset, int startRes,
1296 int column, boolean validRes, boolean validEnd)
1298 g.setColor(SHEET_COLOUR);
1300 if (!validEnd || !validRes || row.annotations[column] == null
1301 || row.annotations[column].secondaryStructure != 'E')
1303 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth) - lastSSX
1307 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1308 (x * av.charWidth) }, new int[]
1309 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1314 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1320 private void drawHelixAnnot(Graphics g, AlignmentAnnotation row,
1321 int lastSSX, int x, int y, int iconOffset, int startRes,
1322 int column, boolean validRes, boolean validEnd)
1324 g.setColor(HELIX_COLOUR);
1326 int sCol = (lastSSX / av.charWidth) + startRes;
1328 int x2 = (x * av.charWidth);
1332 int ofs = av.charWidth / 2;
1333 // Off by 1 offset when drawing rects and ovals
1334 // to offscreen image on the MAC
1335 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1336 if (sCol == 0 || row.annotations[sCol - 1] == null
1337 || row.annotations[sCol - 1].secondaryStructure != 'H')
1342 // g.setColor(Color.orange);
1343 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1346 if (!validRes || row.annotations[column] == null
1347 || row.annotations[column].secondaryStructure != 'H')
1353 // g.setColor(Color.magenta);
1354 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1362 if (sCol == 0 || row.annotations[sCol - 1] == null
1363 || row.annotations[sCol - 1].secondaryStructure != 'H')
1365 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
1366 x1 += av.charWidth / 2;
1369 if (!validRes || row.annotations[column] == null
1370 || row.annotations[column].secondaryStructure != 'H')
1372 g.fillArc((x * av.charWidth) - av.charWidth, y + 4 + iconOffset,
1373 av.charWidth, 8, 270, 180);
1374 x2 -= av.charWidth / 2;
1377 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1380 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1381 int eRes, int y, float min, float max, int graphHeight)
1383 if (sRes > aa.annotations.length)
1390 // Adjustment for fastpaint to left
1391 if (eRes < av.endRes)
1396 eRes = Math.min(eRes, aa.annotations.length);
1404 float range = max - min;
1409 y2 = y - (int) ((0 - min / range) * graphHeight);
1412 g.setColor(Color.gray);
1413 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1415 eRes = Math.min(eRes, aa.annotations.length);
1418 int aaMax = aa.annotations.length - 1;
1420 while (x < eRes - sRes)
1423 if (av.hasHiddenColumns)
1425 column = av.getColumnSelection().adjustForHiddenColumns(column);
1433 if (aa.annotations[column] == null
1434 || aa.annotations[column - 1] == null)
1440 if (aa.annotations[column].colour == null)
1441 g.setColor(Color.black);
1443 g.setColor(aa.annotations[column].colour);
1446 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1448 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1450 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1451 + av.charWidth / 2, y2);
1455 if (aa.threshold != null)
1457 g.setColor(aa.threshold.colour);
1458 Graphics2D g2 = (Graphics2D) g;
1459 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1460 BasicStroke.JOIN_ROUND, 3f, new float[]
1463 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1464 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1465 g2.setStroke(new BasicStroke());
1469 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1470 int eRes, float min, float max, int y)
1472 ColourSchemeI profcolour = av.getGlobalColourScheme();
1473 if (profcolour == null)
1475 profcolour = new jalview.schemes.ZappoColourScheme();
1477 if (sRes > aa.annotations.length)
1481 Font ofont = g.getFont();
1482 eRes = Math.min(eRes, aa.annotations.length);
1484 int x = 0, y1 = y, y2 = y;
1486 float range = max - min;
1490 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1493 g.setColor(Color.gray);
1495 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1498 int aaMax = aa.annotations.length - 1;
1499 boolean renderHistogram = true, renderProfile = true;
1500 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1502 // TODO: generalise this to have render styles for consensus/profile data
1503 if (aa.groupRef != null)
1505 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1506 renderProfile = aa.groupRef.isShowSequenceLogo();
1510 renderHistogram = av.isShowConsensusHistogram();
1511 renderProfile = av.isShowSequenceLogo();
1514 while (x < eRes - sRes)
1517 if (av.hasHiddenColumns)
1519 column = av.getColumnSelection().adjustForHiddenColumns(column);
1527 if (aa.annotations[column] == null)
1532 if (aa.annotations[column].colour == null)
1533 g.setColor(Color.black);
1535 g.setColor(aa.annotations[column].colour);
1538 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1540 if (renderHistogram)
1544 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1548 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1551 // draw profile if available
1552 if (renderProfile && aa.annotations[column].value != 0)
1555 int profl[] = getProfileFor(aa, column);
1556 // just try to draw the logo if profl is not null
1561 * if (profl != null) {
1563 * for (int i = 0; i < profl.length; i++) { System.out.print(profl[i]
1568 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1574 * profl.length == 51 indicates that the profile of a secondary
1575 * structure conservation row was accesed.
1576 * Therefore dc gets length 2, to have space for a basepair instead of
1577 * just a single nucleotide
1579 if (profl.length == 51)
1589 for (int c = 1; profl != null && c < profl[0];)
1591 dc[0] = (char) profl[c++];
1593 if (aa.label.startsWith("StrucConsensus"))
1595 dc[1] = (char) profl[c++];
1598 wdth = av.charWidth;
1599 wdth /= (float) fm.charsWidth(dc, 0, dc.length);
1606 // if (aa.annotations[column].value==0) {
1607 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1608 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1609 // ht = y2-(int)ht2;
1611 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1612 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1614 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1617 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1618 // ? );// try to get a
1619 // colourscheme for the
1620 // group(aa.groupRef.cs==null)
1621 // ? av.textColour2 :
1622 // cs.findColour(dc));
1623 // System.out.println(dc[0]);
1625 g.drawChars(dc, 0, dc.length, x * av.charWidth,
1626 (int) (ht + lm.getHeight()));
1628 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1636 if (aa.threshold != null)
1638 g.setColor(aa.threshold.colour);
1639 Graphics2D g2 = (Graphics2D) g;
1640 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1641 BasicStroke.JOIN_ROUND, 3f, new float[]
1644 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1645 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1646 g2.setStroke(new BasicStroke());
1650 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1652 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1654 if (aa.groupRef != null && aa.groupRef.consensusData != null
1655 && aa.groupRef.isShowSequenceLogo())
1657 return AAFrequency.extractProfile(
1658 aa.groupRef.consensusData[column], aa.groupRef
1659 .getIgnoreGapsConsensus());
1661 // TODO extend annotation row to enable dynamic and static profile data to
1663 if (aa.groupRef == null && aa.sequenceRef == null
1664 && av.isShowSequenceLogo())
1666 return AAFrequency.extractProfile(av.hconsensus[column], av
1667 .getIgnoreGapsConsensus());
1672 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
1674 if (aa.groupRef != null && aa.groupRef.consensusData != null
1675 && aa.groupRef.isShowSequenceLogo())
1677 //TODO check what happens for group selections
1678 return StructureFrequency.extractProfile(
1679 aa.groupRef.consensusData[column], aa.groupRef
1680 .getIgnoreGapsConsensus(),column);
1682 // TODO extend annotation row to enable dynamic and static profile data
1685 if (aa.groupRef == null && aa.sequenceRef == null
1686 && av.isShowSequenceLogo())
1688 return StructureFrequency.extractProfile(av.hStrucConsensus[column],
1689 av.getIgnoreGapsConsensus(),column);
1697 // used by overview window
1698 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1699 int y, int sRes, int eRes)
1701 eRes = Math.min(eRes, aa.annotations.length);
1702 g.setColor(Color.white);
1703 g.fillRect(0, 0, width, y);
1704 g.setColor(new Color(0, 0, 180));
1708 for (int j = sRes; j < eRes; j++)
1710 if (aa.annotations[j] != null)
1712 if (aa.annotations[j].colour == null)
1713 g.setColor(Color.black);
1715 g.setColor(aa.annotations[j].colour);
1717 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1723 g.fillRect(x, y - height, av.charWidth, height);