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 = row.annotations[column].secondaryStructure;
1073 // distinguish between forward/backward base-pairing
1074 if (row.annotations[column].displayCharacter.indexOf(')') > -1)
1079 if (!validRes || (ss != lastSS))
1086 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1087 column, validRes, validEnd);
1091 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1092 column, validRes, validEnd);
1095 case 'S': // Stem case for RNA secondary structure
1096 case 's': // and opposite direction
1097 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1098 column, validRes, validEnd);
1102 g.setColor(Color.gray);
1103 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1119 lastSSX = (x * av.charWidth);
1128 if (column >= row.annotations.length)
1130 column = row.annotations.length - 1;
1145 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1146 column, validRes, validEnd);
1150 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1151 column, validRes, validEnd);
1154 case 'S': // Stem case for RNA secondary structure
1155 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1156 column, validRes, validEnd);
1159 drawGlyphLine(g, row, lastSSX, x, y, iconOffset, startRes,
1160 column, validRes, validEnd);
1165 if (row.graph > 0 && row.graphHeight > 0)
1167 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1169 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1171 float groupmax = -999999, groupmin = 9999999;
1172 for (int gg = 0; gg < aa.length; gg++)
1174 if (aa[gg].graphGroup != row.graphGroup)
1181 aa[gg].visible = false;
1184 if (aa[gg].graphMax > groupmax)
1186 groupmax = aa[gg].graphMax;
1188 if (aa[gg].graphMin < groupmin)
1190 groupmin = aa[gg].graphMin;
1194 for (int gg = 0; gg < aa.length; gg++)
1196 if (aa[gg].graphGroup == row.graphGroup)
1198 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1199 groupmax, row.graphHeight);
1203 graphGroupDrawn[row.graphGroup] = true;
1207 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1208 row.graphMax, row.graphHeight);
1211 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1213 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1218 if (row.graph > 0 && row.hasText)
1230 private void drawStemAnnot(Graphics g, AlignmentAnnotation row,
1231 int lastSSX, int x, int y, int iconOffset, int startRes,
1232 int column, boolean validRes, boolean validEnd)
1234 g.setColor(STEM_COLOUR);
1235 int sCol = (lastSSX / av.charWidth) + startRes;
1237 int x2 = (x * av.charWidth);
1238 Regex closeparen = new Regex("(\\))");
1240 String dc = column == 0 ? ""
1241 : row.annotations[column - 1].displayCharacter;
1243 boolean diffupstream = sCol == 0 || row.annotations[sCol - 1] == null
1244 || !dc.equals(row.annotations[sCol - 1].displayCharacter);
1245 boolean diffdownstream = !validRes || !validEnd
1246 || row.annotations[column] == null
1247 || !dc.equals(row.annotations[column].displayCharacter);
1248 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
1249 // If a closing base pair half of the stem, display a backward arrow
1250 if (column > 0 && closeparen.search(dc))
1253 // if (validRes && column>1 && row.annotations[column-2]!=null &&
1254 // dc.equals(row.annotations[column-2].displayCharacter))
1256 g.fillPolygon(new int[]
1257 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
1258 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
1268 // display a forward arrow
1271 g.fillPolygon(new int[]
1272 { x2 - 5, x2 - 5, x2 }, new int[]
1273 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
1282 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
1285 private void drawGlyphLine(Graphics g, AlignmentAnnotation row,
1286 int lastSSX, int x, int y, int iconOffset, int startRes,
1287 int column, boolean validRes, boolean validEnd)
1289 g.setColor(Color.gray);
1291 .fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1295 private void drawSheetAnnot(Graphics g, AlignmentAnnotation row,
1296 int lastSSX, int x, int y, int iconOffset, int startRes,
1297 int column, boolean validRes, boolean validEnd)
1299 g.setColor(SHEET_COLOUR);
1301 if (!validEnd || !validRes || row.annotations[column] == null
1302 || row.annotations[column].secondaryStructure != 'E')
1304 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth) - lastSSX
1308 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1309 (x * av.charWidth) }, new int[]
1310 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1315 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1321 private void drawHelixAnnot(Graphics g, AlignmentAnnotation row,
1322 int lastSSX, int x, int y, int iconOffset, int startRes,
1323 int column, boolean validRes, boolean validEnd)
1325 g.setColor(HELIX_COLOUR);
1327 int sCol = (lastSSX / av.charWidth) + startRes;
1329 int x2 = (x * av.charWidth);
1333 int ofs = av.charWidth / 2;
1334 // Off by 1 offset when drawing rects and ovals
1335 // to offscreen image on the MAC
1336 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1337 if (sCol == 0 || row.annotations[sCol - 1] == null
1338 || row.annotations[sCol - 1].secondaryStructure != 'H')
1343 // g.setColor(Color.orange);
1344 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1347 if (!validRes || row.annotations[column] == null
1348 || row.annotations[column].secondaryStructure != 'H')
1354 // g.setColor(Color.magenta);
1355 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1363 if (sCol == 0 || row.annotations[sCol - 1] == null
1364 || row.annotations[sCol - 1].secondaryStructure != 'H')
1366 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
1367 x1 += av.charWidth / 2;
1370 if (!validRes || row.annotations[column] == null
1371 || row.annotations[column].secondaryStructure != 'H')
1373 g.fillArc((x * av.charWidth) - av.charWidth, y + 4 + iconOffset,
1374 av.charWidth, 8, 270, 180);
1375 x2 -= av.charWidth / 2;
1378 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1381 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1382 int eRes, int y, float min, float max, int graphHeight)
1384 if (sRes > aa.annotations.length)
1391 // Adjustment for fastpaint to left
1392 if (eRes < av.endRes)
1397 eRes = Math.min(eRes, aa.annotations.length);
1405 float range = max - min;
1410 y2 = y - (int) ((0 - min / range) * graphHeight);
1413 g.setColor(Color.gray);
1414 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1416 eRes = Math.min(eRes, aa.annotations.length);
1419 int aaMax = aa.annotations.length - 1;
1421 while (x < eRes - sRes)
1424 if (av.hasHiddenColumns)
1426 column = av.getColumnSelection().adjustForHiddenColumns(column);
1434 if (aa.annotations[column] == null
1435 || aa.annotations[column - 1] == null)
1441 if (aa.annotations[column].colour == null)
1442 g.setColor(Color.black);
1444 g.setColor(aa.annotations[column].colour);
1447 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1449 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1451 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1452 + av.charWidth / 2, y2);
1456 if (aa.threshold != null)
1458 g.setColor(aa.threshold.colour);
1459 Graphics2D g2 = (Graphics2D) g;
1460 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1461 BasicStroke.JOIN_ROUND, 3f, new float[]
1464 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1465 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1466 g2.setStroke(new BasicStroke());
1470 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1471 int eRes, float min, float max, int y)
1473 ColourSchemeI profcolour = av.getGlobalColourScheme();
1474 if (profcolour == null)
1476 profcolour = new jalview.schemes.ZappoColourScheme();
1478 if (sRes > aa.annotations.length)
1482 Font ofont = g.getFont();
1483 eRes = Math.min(eRes, aa.annotations.length);
1485 int x = 0, y1 = y, y2 = y;
1487 float range = max - min;
1491 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1494 g.setColor(Color.gray);
1496 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1499 int aaMax = aa.annotations.length - 1;
1500 boolean renderHistogram = true, renderProfile = true;
1501 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1503 // TODO: generalise this to have render styles for consensus/profile data
1504 if (aa.groupRef != null)
1506 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1507 renderProfile = aa.groupRef.isShowSequenceLogo();
1511 renderHistogram = av.isShowConsensusHistogram();
1512 renderProfile = av.isShowSequenceLogo();
1515 while (x < eRes - sRes)
1518 if (av.hasHiddenColumns)
1520 column = av.getColumnSelection().adjustForHiddenColumns(column);
1528 if (aa.annotations[column] == null)
1533 if (aa.annotations[column].colour == null)
1534 g.setColor(Color.black);
1536 g.setColor(aa.annotations[column].colour);
1539 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1541 if (renderHistogram)
1545 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1549 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1552 // draw profile if available
1553 if (renderProfile && aa.annotations[column].value != 0)
1556 int profl[] = getProfileFor(aa, column);
1557 // just try to draw the logo if profl is not null
1562 * if (profl != null) {
1564 * for (int i = 0; i < profl.length; i++) { System.out.print(profl[i]
1569 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1575 * profl.length == 11 indicates that the profile of a secondary
1576 * structure conservation row was accesed.
1577 * Therefore dc gets length 2, to have space for a basepair instead of
1578 * just a single nucleotide
1580 if (profl.length == 22)
1590 for (int c = 1; profl != null && c < profl[0];)
1592 dc[0] = (char) profl[c++];
1594 if (aa.label.startsWith("StrucConsensus"))
1599 wdth = av.charWidth;
1600 wdth /= (float) fm.charsWidth(dc, 0, dc.length);
1607 // if (aa.annotations[column].value==0) {
1608 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1609 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1610 // ht = y2-(int)ht2;
1612 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1613 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1615 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1618 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1619 // ? );// try to get a
1620 // colourscheme for the
1621 // group(aa.groupRef.cs==null)
1622 // ? av.textColour2 :
1623 // cs.findColour(dc));
1624 // System.out.println(dc[0]);
1626 g.drawChars(dc, 0, dc.length, x * av.charWidth,
1627 (int) (ht + lm.getHeight()));
1629 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1637 if (aa.threshold != null)
1639 g.setColor(aa.threshold.colour);
1640 Graphics2D g2 = (Graphics2D) g;
1641 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1642 BasicStroke.JOIN_ROUND, 3f, new float[]
1645 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1646 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1647 g2.setStroke(new BasicStroke());
1651 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1653 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1655 if (aa.groupRef != null && aa.groupRef.consensusData != null
1656 && aa.groupRef.isShowSequenceLogo())
1658 return AAFrequency.extractProfile(
1659 aa.groupRef.consensusData[column], aa.groupRef
1660 .getIgnoreGapsConsensus());
1662 // TODO extend annotation row to enable dynamic and static profile data to
1664 if (aa.groupRef == null && aa.sequenceRef == null
1665 && av.isShowSequenceLogo())
1667 return AAFrequency.extractProfile(av.hconsensus[column], av
1668 .getIgnoreGapsConsensus());
1673 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
1675 if (aa.groupRef != null && aa.groupRef.consensusData != null
1676 && aa.groupRef.isShowSequenceLogo())
1678 //TODO check what happens for group selections
1679 return StructureFrequency.extractProfile(
1680 aa.groupRef.consensusData[column], aa.groupRef
1681 .getIgnoreGapsConsensus(),column);
1683 // TODO extend annotation row to enable dynamic and static profile data
1686 if (aa.groupRef == null && aa.sequenceRef == null
1687 && av.isShowSequenceLogo())
1689 return StructureFrequency.extractProfile(av.hStrucConsensus[column],
1690 av.getIgnoreGapsConsensus(),column);
1698 // used by overview window
1699 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1700 int y, int sRes, int eRes)
1702 eRes = Math.min(eRes, aa.annotations.length);
1703 g.setColor(Color.white);
1704 g.fillRect(0, 0, width, y);
1705 g.setColor(new Color(0, 0, 180));
1709 for (int j = sRes; j < eRes; j++)
1711 if (aa.annotations[j] != null)
1713 if (aa.annotations[j].colour == null)
1714 g.setColor(Color.black);
1716 g.setColor(aa.annotations[j].colour);
1718 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1724 g.fillRect(x, y - height, av.charWidth, height);