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;
103 * Creates a new AnnotationPanel object.
108 public AnnotationPanel(AlignmentPanel ap)
111 MAC = new jalview.util.Platform().isAMac();
113 ToolTipManager.sharedInstance().registerComponent(this);
114 ToolTipManager.sharedInstance().setInitialDelay(0);
115 ToolTipManager.sharedInstance().setDismissDelay(10000);
118 this.setLayout(null);
119 addMouseListener(this);
120 addMouseMotionListener(this);
121 ap.annotationScroller.getVerticalScrollBar()
122 .addAdjustmentListener(this);
125 public AnnotationPanel(AlignViewport av)
136 public void adjustmentValueChanged(AdjustmentEvent evt)
138 ap.alabels.setScrollOffset(-evt.getValue());
142 * Calculates the height of the annotation displayed in the annotation panel.
143 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
144 * all annotation associated components are updated correctly.
147 public int adjustPanelHeight()
149 int height=calcPanelHeight();
150 this.setPreferredSize(new Dimension(1, height));
153 // revalidate only when the alignment panel is fully constructed
161 * calculate the height for visible annotation, revalidating bounds where necessary
162 * ABSTRACT GUI METHOD
163 * @return total height of annotation
165 public int calcPanelHeight()
167 // setHeight of panels
168 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
173 for (int i = 0; i < aa.length; i++)
177 System.err.println("Null annotation row: ignoring.");
189 aa[i].height += av.charHeight;
199 aa[i].height += aa[i].graphHeight;
202 if (aa[i].height == 0)
207 height += aa[i].height;
224 public void actionPerformed(ActionEvent evt)
226 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
231 Annotation[] anot = aa[activeRow].annotations;
233 if (anot.length < av.getColumnSelection().getMax())
235 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
236 System.arraycopy(anot, 0, temp, 0, anot.length);
238 aa[activeRow].annotations = anot;
241 if (evt.getActionCommand().equals(REMOVE))
243 for (int i = 0; i < av.getColumnSelection().size(); i++)
245 anot[av.getColumnSelection().columnAt(i)] = null;
248 else if (evt.getActionCommand().equals(LABEL))
250 String exMesg = collectAnnotVals(anot, av.getColumnSelection(), LABEL);
251 String label = JOptionPane.showInputDialog(this, "Enter label",
259 if ((label.length() > 0) && !aa[activeRow].hasText)
261 aa[activeRow].hasText = true;
264 for (int i = 0; i < av.getColumnSelection().size(); i++)
266 int index = av.getColumnSelection().columnAt(i);
268 if (!av.colSel.isVisible(index))
271 if (anot[index] == null)
273 anot[index] = new Annotation(label, "", ' ', 0); // TODO: verify that
280 anot[index].displayCharacter = label;
284 else if (evt.getActionCommand().equals(COLOUR))
286 Color col = JColorChooser.showDialog(this,
287 "Choose foreground colour", Color.black);
289 for (int i = 0; i < av.getColumnSelection().size(); i++)
291 int index = av.getColumnSelection().columnAt(i);
293 if (!av.colSel.isVisible(index))
296 if (anot[index] == null)
298 anot[index] = new Annotation("", "", ' ', 0);
301 anot[index].colour = col;
308 String symbol = "\u03B1";
310 if (evt.getActionCommand().equals(HELIX))
314 else if (evt.getActionCommand().equals(SHEET))
320 // Added by LML to color stems
321 else if (evt.getActionCommand().equals(STEM))
327 if (!aa[activeRow].hasIcons)
329 aa[activeRow].hasIcons = true;
332 String label = JOptionPane.showInputDialog(
333 "Enter a label for the structure?", symbol);
340 if ((label.length() > 0) && !aa[activeRow].hasText)
342 aa[activeRow].hasText = true;
345 for (int i = 0; i < av.getColumnSelection().size(); i++)
347 int index = av.getColumnSelection().columnAt(i);
349 if (!av.colSel.isVisible(index))
352 if (anot[index] == null)
354 anot[index] = new Annotation(label, "", type, 0);
357 anot[index].secondaryStructure = type;
358 anot[index].displayCharacter = label;
368 private String collectAnnotVals(Annotation[] anot,
369 ColumnSelection columnSelection, String label2)
371 String collatedInput = "";
373 for (int i = 0; i < columnSelection.size(); i++)
375 int index = columnSelection.columnAt(i);
376 // always check for current display state - just in case
377 if (!av.colSel.isVisible(index))
379 String tlabel = null;
380 if (anot[index] != null)
381 { // LML added stem code
382 if (label2.equals(HELIX) || label2.equals(SHEET)
383 || label2.equals(STEM) || label2.equals(LABEL))
385 tlabel = anot[index].description;
386 if (tlabel == null || tlabel.length() < 1)
388 if (label2.equals(HELIX) || label2.equals(SHEET)
389 || label2.equals(STEM))
391 tlabel = "" + anot[index].secondaryStructure;
395 tlabel = "" + anot[index].displayCharacter;
399 if (tlabel != null && !tlabel.equals(last))
401 if (last.length() > 0)
403 collatedInput += " ";
405 collatedInput += tlabel;
409 return collatedInput;
418 public void mousePressed(MouseEvent evt)
421 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
430 for (int i = 0; i < aa.length; i++)
434 height += aa[i].height;
437 if (evt.getY() < height)
443 else if (aa[i].graph > 0)
447 graphStretchY = evt.getY();
454 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
456 if (av.getColumnSelection() == null)
461 JPopupMenu pop = new JPopupMenu("Structure type");
464 * Just display the needed structure options
466 if(av.alignment.isNucleotide()==true){
467 item = new JMenuItem(STEM);
468 item.addActionListener(this);
471 item = new JMenuItem(HELIX);
472 item.addActionListener(this);
474 item = new JMenuItem(SHEET);
475 item.addActionListener(this);
478 item = new JMenuItem(LABEL);
479 item.addActionListener(this);
481 item = new JMenuItem(COLOUR);
482 item.addActionListener(this);
484 item = new JMenuItem(REMOVE);
485 item.addActionListener(this);
487 pop.show(this, evt.getX(), evt.getY());
497 ap.scalePanel.mousePressed(evt);
507 public void mouseReleased(MouseEvent evt)
511 mouseDragging = false;
512 ap.scalePanel.mouseReleased(evt);
521 public void mouseEntered(MouseEvent evt)
523 ap.scalePanel.mouseEntered(evt);
532 public void mouseExited(MouseEvent evt)
534 ap.scalePanel.mouseExited(evt);
543 public void mouseDragged(MouseEvent evt)
545 if (graphStretch > -1)
547 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
549 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
551 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
553 graphStretchY = evt.getY();
555 ap.paintAlignment(true);
559 ap.scalePanel.mouseDragged(evt);
569 public void mouseMoved(MouseEvent evt)
571 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
575 this.setToolTipText(null);
582 for (int i = 0; i < aa.length; i++)
586 height += aa[i].height;
589 if (evt.getY() < height)
599 this.setToolTipText(null);
603 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
605 if (av.hasHiddenColumns)
607 res = av.getColumnSelection().adjustForHiddenColumns(res);
610 if (row > -1 && aa[row].annotations != null
611 && res < (int) aa[row].annotations.length)
613 if (aa[row].graphGroup > -1)
615 StringBuffer tip = new StringBuffer("<html>");
616 for (int gg = 0; gg < aa.length; gg++)
618 if (aa[gg].graphGroup == aa[row].graphGroup
619 && aa[gg].annotations[res] != null)
621 tip.append(aa[gg].label + " "
622 + aa[gg].annotations[res].description + "<br>");
625 if (tip.length() != 6)
627 tip.setLength(tip.length() - 4);
628 this.setToolTipText(tip.toString() + "</html>");
631 else if (aa[row].annotations[res] != null
632 && aa[row].annotations[res].description != null
633 && aa[row].annotations[res].description.length() > 0)
635 this.setToolTipText(aa[row].annotations[res].description);
639 // clear the tooltip.
640 this.setToolTipText(null);
643 if (aa[row].annotations[res] != null)
645 StringBuffer text = new StringBuffer("Sequence position "
648 if (aa[row].annotations[res].description != null)
650 text.append(" " + aa[row].annotations[res].description);
653 ap.alignFrame.statusBar.setText(text.toString());
658 this.setToolTipText(null);
668 public void mouseClicked(MouseEvent evt)
671 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
672 AlignmentAnnotation anot = aa[activeRow];
674 if(anot.description.equals("secondary structure")){
675 //System.out.println(anot.description+" "+anot.getRNAStruc());
679 //TODO mouseClicked-content and drawCursor are quite experimental!
680 public void drawCursor(Graphics graphics, SequenceI seq, int res, int x1, int y1)
682 int pady = av.charHeight / 5;
684 graphics.setColor(Color.black);
685 graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
687 if (av.validCharWidth)
689 graphics.setColor(Color.white);
691 char s = seq.getCharAt(res);
693 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
694 graphics.drawString(String.valueOf(s), charOffset + x1,
695 (y1 + av.charHeight) - pady);
706 public void paintComponent(Graphics g)
708 g.setColor(Color.white);
709 g.fillRect(0, 0, getWidth(), getHeight());
713 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
714 || (getVisibleRect().height != g.getClipBounds().height))
716 g.drawImage(image, 0, 0, this);
721 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
724 if (image == null || imgWidth != image.getWidth()
725 || image.getHeight(this) != getHeight())
727 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
728 BufferedImage.TYPE_INT_RGB);
729 gg = (Graphics2D) image.getGraphics();
733 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
734 RenderingHints.VALUE_ANTIALIAS_ON);
737 gg.setFont(av.getFont());
738 fm = gg.getFontMetrics();
739 gg.setColor(Color.white);
740 gg.fillRect(0, 0, imgWidth, image.getHeight());
743 drawComponent(gg, av.startRes, av.endRes + 1);
744 g.drawImage(image, 0, 0, this);
748 * non-Thread safe repaint
751 * repaint with horizontal shift in alignment
753 public void fastPaint(int horizontal)
756 if ((horizontal == 0) || gg == null
757 || av.alignment.getAlignmentAnnotation() == null
758 || av.alignment.getAlignmentAnnotation().length < 1
759 || av.updatingConsensus || av.updatingConservation)
764 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
766 int sr = av.startRes;
767 int er = av.endRes + 1;
770 if (horizontal > 0) // scrollbar pulled right, image to the left
772 transX = (er - sr - horizontal) * av.charWidth;
773 sr = er - horizontal;
775 else if (horizontal < 0)
777 er = sr - horizontal;
780 gg.translate(transX, 0);
782 drawComponent(gg, sr, er);
784 gg.translate(-transX, 0);
801 public void drawComponent(Graphics g, int startRes, int endRes)
803 if (av.updatingConsensus || av.updatingConservation)
809 // We'll keep a record of the old image,
810 // and draw a faded image until the calculation
812 if (fadedImage == null || fadedImage.getWidth() != imgWidth
813 || fadedImage.getHeight() != image.getHeight())
815 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
816 BufferedImage.TYPE_INT_RGB);
818 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
820 fadedG.setColor(Color.white);
821 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
823 fadedG.setComposite(AlphaComposite.getInstance(
824 AlphaComposite.SRC_OVER, .3f));
825 fadedG.drawImage(image, 0, 0, this);
835 g.setColor(Color.white);
836 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
838 g.setFont(av.getFont());
841 fm = g.getFontMetrics();
844 if ((av.alignment.getAlignmentAnnotation() == null)
845 || (av.alignment.getAlignmentAnnotation().length < 1))
847 g.setColor(Color.white);
848 g.fillRect(0, 0, getWidth(), getHeight());
849 g.setColor(Color.black);
850 if (av.validCharWidth)
852 g.drawString("Alignment has no annotations", 20, 15);
858 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
865 boolean validRes = false;
866 boolean validEnd = false;
867 boolean labelAllCols = false;
868 boolean centreColLabels, centreColLabelsDef = av
869 .getCentreColumnLabels();
870 boolean scaleColLabel = false;
871 boolean[] graphGroupDrawn = new boolean[aa.length];
872 int charOffset = 0; // offset for a label
873 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
875 Font ofont = g.getFont();
877 for (int i = 0; i < aa.length; i++)
879 AlignmentAnnotation row = aa[i];
885 centreColLabels = row.centreColLabels || centreColLabelsDef;
886 labelAllCols = row.showAllColLabels;
887 scaleColLabel = row.scaleColLabel;
892 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
897 // this is so that we draw the characters below the graph
902 iconOffset = av.charHeight - fm.getDescent();
906 else if (row.hasText)
908 iconOffset = av.charHeight - fm.getDescent();
916 if (av.updatingConsensus && aa[i] == av.consensus)
920 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
921 - row.height, imgWidth, y, this);
922 g.setColor(Color.black);
923 // g.drawString("Calculating Consensus....",20, y-row.height/2);
927 else if (av.updatingConservation
928 && aa[i].label.equals("Conservation"))
932 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
933 - row.height, imgWidth, y, this);
935 g.setColor(Color.black);
936 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
940 else if (av.updatingConservation && aa[i].label.equals("Quality"))
944 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
945 - row.height, imgWidth, y, this);
946 g.setColor(Color.black);
947 // / g.drawString("Calculating Quality....",20, y-row.height/2);
952 // first pass sets up state for drawing continuation from left-hand column
954 x = (startRes == 0) ? 0 : -1;
955 while (x < endRes - startRes)
957 if (av.hasHiddenColumns)
959 column = av.getColumnSelection().adjustForHiddenColumns(
961 if (column > row.annotations.length - 1)
968 column = startRes + x;
971 if ((row.annotations == null) || (row.annotations.length <= column)
972 || (row.annotations[column] == null))
984 g.setColor(Color.red);
986 if (av.getColumnSelection() != null)
988 for (int n = 0; n < av.getColumnSelection().size(); n++)
990 int v = av.getColumnSelection().columnAt(n);
994 g.fillRect(x * av.charWidth, y, av.charWidth,
1001 if (av.validCharWidth
1003 && row.annotations[column].displayCharacter != null
1004 && (row.annotations[column].displayCharacter.length() > 0))
1007 if (centreColLabels || scaleColLabel)
1009 fmWidth = (float) fm.charsWidth(
1010 row.annotations[column].displayCharacter
1012 row.annotations[column].displayCharacter.length());
1016 // justify the label and scale to fit in column
1017 if (fmWidth > av.charWidth)
1019 // scale only if the current font isn't already small enough
1020 fmScaling = av.charWidth;
1021 fmScaling /= fmWidth;
1022 g.setFont(ofont.deriveFont(AffineTransform
1023 .getScaleInstance(fmScaling, 1.0)));
1024 // and update the label's width to reflect the scaling.
1025 fmWidth = av.charWidth;
1031 fmWidth = (float) fm
1032 .charWidth(row.annotations[column].displayCharacter
1035 charOffset = (int) ((av.charWidth - fmWidth) / 2f);
1037 if (row.annotations[column].colour == null)
1038 g.setColor(Color.black);
1040 g.setColor(row.annotations[column].colour);
1042 if (column == 0 || row.graph > 0)
1044 g.drawString(row.annotations[column].displayCharacter,
1045 (x * av.charWidth) + charOffset, y + iconOffset);
1047 else if (row.annotations[column - 1] == null
1049 || !row.annotations[column].displayCharacter
1050 .equals(row.annotations[column - 1].displayCharacter) || (row.annotations[column].displayCharacter
1051 .length() < 2 && row.annotations[column].secondaryStructure == ' ')))
1053 g.drawString(row.annotations[column].displayCharacter, x
1054 * av.charWidth + charOffset, y + iconOffset);
1061 char ss=row.annotations[column].secondaryStructure;
1064 // distinguish between forward/backward base-pairing
1065 if (row.annotations[column].displayCharacter.indexOf(')')>-1)
1078 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1079 column, validRes, validEnd);
1083 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1084 column, validRes, validEnd);
1087 case 'S': // Stem case for RNA secondary structure
1088 case 's': // and opposite direction
1089 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1090 column, validRes, validEnd);
1094 g.setColor(Color.gray);
1095 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)
1111 lastSSX = (x * av.charWidth);
1120 if (column >= row.annotations.length)
1122 column = row.annotations.length - 1;
1137 drawHelixAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1138 column, validRes, validEnd);
1142 drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1143 column, validRes, validEnd);
1146 case 'S': // Stem case for RNA secondary structure
1147 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
1148 column, validRes, validEnd);
1151 drawGlyphLine(g, row, lastSSX, x, y, iconOffset, startRes,
1152 column, validRes, validEnd);
1157 if (row.graph > 0 && row.graphHeight > 0)
1159 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1161 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
1163 float groupmax = -999999, groupmin = 9999999;
1164 for (int gg = 0; gg < aa.length; gg++)
1166 if (aa[gg].graphGroup != row.graphGroup)
1173 aa[gg].visible = false;
1176 if (aa[gg].graphMax > groupmax)
1178 groupmax = aa[gg].graphMax;
1180 if (aa[gg].graphMin < groupmin)
1182 groupmin = aa[gg].graphMin;
1186 for (int gg = 0; gg < aa.length; gg++)
1188 if (aa[gg].graphGroup == row.graphGroup)
1190 drawLineGraph(g, aa[gg], startRes, endRes, y, groupmin,
1191 groupmax, row.graphHeight);
1195 graphGroupDrawn[row.graphGroup] = true;
1199 drawLineGraph(g, row, startRes, endRes, y, row.graphMin,
1200 row.graphMax, row.graphHeight);
1203 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1205 drawBarGraph(g, row, startRes, endRes, row.graphMin,
1210 if (row.graph > 0 && row.hasText)
1222 private void drawStemAnnot(Graphics g, AlignmentAnnotation row,
1223 int lastSSX, int x, int y, int iconOffset, int startRes,
1224 int column, boolean validRes, boolean validEnd)
1226 g.setColor(STEM_COLOUR);
1227 int sCol = (lastSSX / av.charWidth) + startRes;
1229 int x2 = (x * av.charWidth);
1230 Regex closeparen = new Regex("(\\))");
1232 String dc = column==0 ? "" : row.annotations[column - 1].displayCharacter;
1234 boolean diffupstream=sCol == 0 || row.annotations[sCol - 1] == null
1235 || !dc.equals(row.annotations[sCol - 1].displayCharacter);
1236 boolean diffdownstream=!validRes || !validEnd || row.annotations[column] == null
1237 || !dc.equals(row.annotations[column].displayCharacter);
1238 //System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
1239 // If a closing base pair half of the stem, display a backward arrow
1245 // if (validRes && column>1 && row.annotations[column-2]!=null &&
1246 // dc.equals(row.annotations[column-2].displayCharacter))
1248 g.fillPolygon(new int[]
1249 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
1250 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
1260 // display a forward arrow
1263 g.fillPolygon(new int[]
1264 { x2 - 5, x2 - 5, x2 }, new int[]
1265 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
1274 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
1277 private void drawGlyphLine(Graphics g, AlignmentAnnotation row,
1278 int lastSSX, int x, int y, int iconOffset, int startRes,
1279 int column, boolean validRes, boolean validEnd)
1281 g.setColor(Color.gray);
1282 g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth) - lastSSX, 2);
1285 private void drawSheetAnnot(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(SHEET_COLOUR);
1291 if (!validEnd || !validRes || row.annotations[column] == null
1292 || row.annotations[column].secondaryStructure != 'E')
1294 g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth) - lastSSX
1298 { (x * av.charWidth) - 4, (x * av.charWidth) - 4,
1299 (x * av.charWidth) }, new int[]
1300 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1305 g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * av.charWidth
1311 private void drawHelixAnnot(Graphics g, AlignmentAnnotation row,
1312 int lastSSX, int x, int y, int iconOffset, int startRes,
1313 int column, boolean validRes, boolean validEnd)
1315 g.setColor(HELIX_COLOUR);
1317 int sCol = (lastSSX / av.charWidth) + startRes;
1319 int x2 = (x * av.charWidth);
1323 int ofs=av.charWidth/2;
1324 // Off by 1 offset when drawing rects and ovals
1325 // to offscreen image on the MAC
1326 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2-x1, 8, 8, 8);
1327 if (sCol == 0 || row.annotations[sCol - 1] == null
1328 || row.annotations[sCol - 1].secondaryStructure != 'H')
1331 // g.setColor(Color.orange);
1332 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2-x1-ofs+1, 8, 0, 0);
1334 if (!validRes || row.annotations[column] == null
1335 || row.annotations[column].secondaryStructure != 'H')
1339 // g.setColor(Color.magenta);
1340 g.fillRoundRect(lastSSX+ofs, y + 4 + iconOffset, x2-x1-ofs+1, 8, 0, 0);
1347 if (sCol == 0 || row.annotations[sCol - 1] == null
1348 || row.annotations[sCol - 1].secondaryStructure != 'H')
1350 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
1351 x1 += av.charWidth / 2;
1354 if (!validRes || row.annotations[column] == null
1355 || row.annotations[column].secondaryStructure != 'H')
1357 g.fillArc((x * av.charWidth) - av.charWidth, y + 4 + iconOffset,
1358 av.charWidth, 8, 270, 180);
1359 x2 -= av.charWidth / 2;
1362 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1365 public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1366 int eRes, int y, float min, float max, int graphHeight)
1368 if (sRes > aa.annotations.length)
1375 // Adjustment for fastpaint to left
1376 if (eRes < av.endRes)
1381 eRes = Math.min(eRes, aa.annotations.length);
1389 float range = max - min;
1394 y2 = y - (int) ((0 - min / range) * graphHeight);
1397 g.setColor(Color.gray);
1398 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
1400 eRes = Math.min(eRes, aa.annotations.length);
1403 int aaMax = aa.annotations.length - 1;
1405 while (x < eRes - sRes)
1408 if (av.hasHiddenColumns)
1410 column = av.getColumnSelection().adjustForHiddenColumns(column);
1418 if (aa.annotations[column] == null
1419 || aa.annotations[column - 1] == null)
1425 if (aa.annotations[column].colour == null)
1426 g.setColor(Color.black);
1428 g.setColor(aa.annotations[column].colour);
1431 - (int) (((aa.annotations[column - 1].value - min) / range) * graphHeight);
1433 - (int) (((aa.annotations[column].value - min) / range) * graphHeight);
1435 g.drawLine(x * av.charWidth - av.charWidth / 2, y1, x * av.charWidth
1436 + av.charWidth / 2, y2);
1440 if (aa.threshold != null)
1442 g.setColor(aa.threshold.colour);
1443 Graphics2D g2 = (Graphics2D) g;
1444 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1445 BasicStroke.JOIN_ROUND, 3f, new float[]
1448 y2 = (int) (y - ((aa.threshold.value - min) / range) * graphHeight);
1449 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1450 g2.setStroke(new BasicStroke());
1454 public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes,
1455 int eRes, float min, float max, int y)
1457 ColourSchemeI profcolour = av.getGlobalColourScheme();
1458 if (profcolour == null)
1460 profcolour = new jalview.schemes.ZappoColourScheme();
1462 if (sRes > aa.annotations.length)
1466 Font ofont = g.getFont();
1467 eRes = Math.min(eRes, aa.annotations.length);
1469 int x = 0, y1 = y, y2 = y;
1471 float range = max - min;
1475 y2 = y - (int) ((0 - min / (range)) * aa.graphHeight);
1478 g.setColor(Color.gray);
1480 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
1483 int aaMax = aa.annotations.length - 1;
1484 boolean renderHistogram = true, renderProfile = true;
1485 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1487 // TODO: generalise this to have render styles for consensus/profile data
1488 if (aa.groupRef != null)
1490 renderHistogram = aa.groupRef.isShowConsensusHistogram();
1491 renderProfile = aa.groupRef.isShowSequenceLogo();
1495 renderHistogram = av.isShowConsensusHistogram();
1496 renderProfile = av.isShowSequenceLogo();
1499 while (x < eRes - sRes)
1502 if (av.hasHiddenColumns)
1504 column = av.getColumnSelection().adjustForHiddenColumns(column);
1512 if (aa.annotations[column] == null)
1517 if (aa.annotations[column].colour == null)
1518 g.setColor(Color.black);
1520 g.setColor(aa.annotations[column].colour);
1523 - (int) (((aa.annotations[column].value - min) / (range)) * aa.graphHeight);
1525 if (renderHistogram)
1529 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
1533 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
1536 // draw profile if available
1537 if (renderProfile && aa.annotations[column].value != 0)
1539 int profl[] = getProfileFor(aa, column);
1540 /*if(profl != null){
1541 for(int i=0; i<profl.length;i++){
1542 System.out.print(profl[i]+",");
1544 System.out.print("drawProfile\n");
1546 int ht = y1, htn = y2 - y1;// aa.graphHeight;
1549 char[] dc = new char[1];
1551 for (int c = 1; profl != null && c < profl[0];)
1553 dc[0] = (char) profl[c++];
1554 wdth = av.charWidth;
1555 wdth /= (float) fm.charsWidth(dc, 0, 1);
1562 // if (aa.annotations[column].value==0) {
1563 // g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(wdth,
1564 // (ht2=(aa.graphHeight*0.1/av.charHeight)))));
1565 // ht = y2-(int)ht2;
1567 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1568 wdth, (ht2 = (htn * ((double) profl[c++]) / 100.0))
1570 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1573 g.setColor(profcolour.findColour(dc[0])); // (av.globalColourScheme!=null)
1574 // ? );// try to get a
1575 // colourscheme for the
1576 // group(aa.groupRef.cs==null)
1577 // ? av.textColour2 :
1578 // cs.findColour(dc));
1579 //System.out.println(dc[0]);
1580 g.drawChars(dc, 0, 1, x * av.charWidth,
1581 (int) (ht + lm.getHeight()));
1582 // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
1589 if (aa.threshold != null)
1591 g.setColor(aa.threshold.colour);
1592 Graphics2D g2 = (Graphics2D) g;
1593 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1594 BasicStroke.JOIN_ROUND, 3f, new float[]
1597 y2 = (int) (y - ((aa.threshold.value - min) / range) * aa.graphHeight);
1598 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
1599 g2.setStroke(new BasicStroke());
1603 private int[] getProfileFor(AlignmentAnnotation aa, int column)
1605 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
1607 if (aa.groupRef != null && aa.groupRef.consensusData != null
1608 && aa.groupRef.isShowSequenceLogo())
1610 return AAFrequency.extractProfile(
1611 aa.groupRef.consensusData[column],
1612 aa.groupRef.getIgnoreGapsConsensus());
1614 // TODO extend annotation row to enable dynamic and static profile data to
1616 if (aa.groupRef == null && aa.sequenceRef == null
1617 && av.isShowSequenceLogo())
1619 return AAFrequency.extractProfile(av.hconsensus[column],
1620 av.getIgnoreGapsConsensus());
1623 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus")){
1624 if (aa.groupRef != null && aa.groupRef.consensusData != null
1625 && aa.groupRef.isShowSequenceLogo())
1627 return StructureFrequency.extractProfile(
1628 aa.groupRef.consensusData[column],
1629 aa.groupRef.getIgnoreGapsConsensus());
1631 // TODO extend annotation row to enable dynamic and static profile data to
1633 if (aa.groupRef == null && aa.sequenceRef == null
1634 && av.isShowSequenceLogo())
1636 return StructureFrequency.extractProfile(av.hconsensus[column],
1637 av.getIgnoreGapsConsensus());
1645 // used by overview window
1646 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width,
1647 int y, int sRes, int eRes)
1649 eRes = Math.min(eRes, aa.annotations.length);
1650 g.setColor(Color.white);
1651 g.fillRect(0, 0, width, y);
1652 g.setColor(new Color(0, 0, 180));
1656 for (int j = sRes; j < eRes; j++)
1658 if (aa.annotations[j] != null)
1660 if (aa.annotations[j].colour == null)
1661 g.setColor(Color.black);
1663 g.setColor(aa.annotations[j].colour);
1665 height = (int) ((aa.annotations[j].value / aa.graphMax) * y);
1671 g.fillRect(x, y - height, av.charWidth, height);