2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.renderer;
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.StructureFrequency;
23 import jalview.api.AlignViewportI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.Annotation;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.schemes.ColourSchemeI;
29 import java.awt.BasicStroke;
30 import java.awt.Color;
32 import java.awt.FontMetrics;
33 import java.awt.Graphics;
34 import java.awt.Graphics2D;
35 import java.awt.Image;
36 import java.awt.font.LineMetrics;
37 import java.awt.geom.AffineTransform;
38 import java.awt.image.ImageObserver;
39 import java.util.BitSet;
40 import java.util.Hashtable;
42 import com.stevesoft.pat.Regex;
44 public class AnnotationRenderer
47 * flag indicating if timing and redraw parameter info should be output
49 private final boolean debugRedraw;
51 public AnnotationRenderer()
56 * Create a new annotation Renderer
57 * @param debugRedraw flag indicating if timing and redraw parameter info should be output
59 public AnnotationRenderer(boolean debugRedraw)
61 this.debugRedraw=debugRedraw;
64 public void drawStemAnnot(Graphics g, Annotation[] row_annotations,
65 int lastSSX, int x, int y, int iconOffset, int startRes,
66 int column, boolean validRes, boolean validEnd)
68 g.setColor(STEM_COLOUR);
69 int sCol = (lastSSX / charWidth) + startRes;
71 int x2 = (x * charWidth);
72 Regex closeparen = new Regex("(\\))");
74 String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
75 : row_annotations[column - 1].displayCharacter;
77 boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
78 || !dc.equals(row_annotations[sCol - 1].displayCharacter);
79 boolean diffdownstream = !validRes || !validEnd
80 || row_annotations[column] == null
81 || !dc.equals(row_annotations[column].displayCharacter);
82 // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
83 // If a closing base pair half of the stem, display a backward arrow
84 if (column > 0 && closeparen.search(dc))
87 // if (validRes && column>1 && row_annotations[column-2]!=null &&
88 // dc.equals(row_annotations[column-2].displayCharacter))
90 g.fillPolygon(new int[]
91 { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
92 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
102 // display a forward arrow
105 g.fillPolygon(new int[]
106 { x2 - 5, x2 - 5, x2 }, new int[]
107 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
116 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
119 private int charWidth, endRes, charHeight;
121 private boolean validCharWidth, hasHiddenColumns;
123 private FontMetrics fm;
125 private final boolean MAC = new jalview.util.Platform().isAMac();
127 boolean av_renderHistogram = true, av_renderProfile = true,
128 av_normaliseProfile = false;
130 ColourSchemeI profcolour = null;
132 private ColumnSelection columnSelection;
134 private Hashtable[] hconsensus;
136 private Hashtable[] hStrucConsensus;
138 private boolean av_ignoreGapsConsensus;
141 * attributes set from AwtRenderPanelI
144 * old image used when data is currently being calculated and cannot be
147 private Image fadedImage;
150 * panel being rendered into
152 private ImageObserver annotationPanel;
155 * width of image to render in panel
157 private int imgWidth;
159 * offset to beginning of visible area
163 * offset to end of visible area
165 private int visHeight;
167 * indicate if the renderer should only render the visible portion of the annotation given the current view settings
169 private boolean useClip=true;
171 * master flag indicating if renderer should ever try to clip. not enabled for jalview 2.8.1
173 private boolean canClip=false;
175 // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
177 public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
180 fm = annotPanel.getFontMetrics();
181 annotationPanel = annotPanel;
182 fadedImage = annotPanel.getFadedImage();
183 imgWidth = annotPanel.getFadedImageWidth();
184 // visible area for rendering
185 int[] bounds=annotPanel.getVisibleVRange();
189 visHeight = bounds[1];
200 updateFromAlignViewport(av);
203 public void updateFromAlignViewport(AlignViewportI av)
205 charWidth = av.getCharWidth();
206 endRes = av.getEndRes();
207 charHeight = av.getCharHeight();
208 hasHiddenColumns = av.hasHiddenColumns();
209 validCharWidth = av.isValidCharWidth();
210 av_renderHistogram = av.isShowConsensusHistogram();
211 av_renderProfile = av.isShowSequenceLogo();
212 av_normaliseProfile = av.isNormaliseSequenceLogo();
213 profcolour = av.getGlobalColourScheme();
214 if (profcolour == null)
216 // Set the default colour for sequence logo if the alignnent has no
218 profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
219 : new jalview.schemes.ZappoColourScheme();
221 columnSelection = av.getColumnSelection();
222 hconsensus = av.getSequenceConsensusHash();// hconsensus;
223 hStrucConsensus = av.getRnaStructureConsensusHash(); // hStrucConsensus;
224 av_ignoreGapsConsensus = av.getIgnoreGapsConsensus();
227 public int[] getProfileFor(AlignmentAnnotation aa, int column)
229 // TODO : consider refactoring the global alignment calculation
230 // properties/rendering attributes as a global 'alignment group' which holds
231 // all vis settings for the alignment as a whole rather than a subset
233 if (aa.autoCalculated && aa.label.startsWith("Consensus"))
235 if (aa.groupRef != null && aa.groupRef.consensusData != null
236 && aa.groupRef.isShowSequenceLogo())
238 return AAFrequency.extractProfile(
239 aa.groupRef.consensusData[column],
240 aa.groupRef.getIgnoreGapsConsensus());
242 // TODO extend annotation row to enable dynamic and static profile data to
244 if (aa.groupRef == null && aa.sequenceRef == null)
246 return AAFrequency.extractProfile(hconsensus[column],
247 av_ignoreGapsConsensus);
252 if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
254 // TODO implement group structure consensus
256 * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
257 * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
258 * group selections return StructureFrequency.extractProfile(
259 * aa.groupRef.consensusData[column], aa.groupRef
260 * .getIgnoreGapsConsensus()); }
262 // TODO extend annotation row to enable dynamic and static profile data
265 if (aa.groupRef == null && aa.sequenceRef == null
266 && hStrucConsensus != null
267 && hStrucConsensus.length > column)
269 return StructureFrequency.extractProfile(hStrucConsensus[column],
270 av_ignoreGapsConsensus);
278 * Render the annotation rows associated with an alignment.
283 * data and view settings to render
285 * destination for graphics
287 * row where a mouse event occured (or -1)
289 * first column that will be drawn
291 * last column that will be drawn
292 * @return true if the fadedImage was used for any alignment annotation rows
293 * currently being calculated
295 public boolean drawComponent(AwtRenderPanelI annotPanel,
296 AlignViewportI av, Graphics g, int activeRow, int startRes,
299 long stime=System.currentTimeMillis();
300 boolean usedFaded = false;
302 // AnnotationPanel needs to implement: ImageObserver, access to
304 updateFromAwtRenderPanel(annotPanel, av);
305 fm = g.getFontMetrics();
306 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
316 boolean validRes = false;
317 boolean validEnd = false;
318 boolean labelAllCols = false;
319 boolean centreColLabels, centreColLabelsDef = av
320 .getCentreColumnLabels();
321 boolean scaleColLabel = false;
322 AlignmentAnnotation consensusAnnot=av.getAlignmentConsensusAnnotation(),structConsensusAnnot=av.getAlignmentStrucConsensusAnnotation();
323 boolean renderHistogram = true, renderProfile = true, normaliseProfile = false;
325 BitSet graphGroupDrawn = new BitSet();
326 int charOffset = 0; // offset for a label
327 float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
329 Font ofont = g.getFont();
332 int yfrom=0,f_i=0,yto=0,f_to=0;
333 boolean clipst=false,clipend=false;
334 for (int i = 0; i < aa.length; i++)
336 AlignmentAnnotation row = aa[i];
338 // check if this is a consensus annotation row and set the display settings appropriately
339 // TODO: generalise this to have render styles for consensus/profile
341 if (row.groupRef != null && row == row.groupRef.getConsensus())
343 renderHistogram = row.groupRef.isShowConsensusHistogram();
344 renderProfile = row.groupRef.isShowSequenceLogo();
345 normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
347 else if (row == consensusAnnot || row == structConsensusAnnot)
349 renderHistogram = av_renderHistogram;
350 renderProfile = av_renderProfile;
351 normaliseProfile = av_normaliseProfile;
353 renderHistogram = true;
354 // don't need to set render/normaliseProfile since they are not currently used in any other annotation track renderer
357 Annotation[] row_annotations = row.annotations;
362 centreColLabels = row.centreColLabels || centreColLabelsDef;
363 labelAllCols = row.showAllColLabels;
364 scaleColLabel = row.scaleColLabel;
368 if (!useClip || ((y-charHeight)<visHeight && (y+row.height+charHeight*2)>=sOffset))
369 {// if_in_visible_region
380 if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup)) {
384 // this is so that we draw the characters below the graph
389 iconOffset = charHeight - fm.getDescent();
393 else if (row.hasText)
395 iconOffset = charHeight - fm.getDescent();
403 if (row.autoCalculated && av.isCalculationInProgress(row))
407 g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
408 - row.height, imgWidth, y, annotationPanel);
409 g.setColor(Color.black);
410 // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
416 * else if (annotationPanel.av.updatingConservation &&
417 * aa[i].label.equals("Conservation")) {
419 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
420 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
421 * annotationPanel.imgWidth, y, annotationPanel);
423 * g.setColor(Color.black); //
424 * g.drawString("Calculating Conservation.....",20, y-row.height/2);
426 * continue; } else if (annotationPanel.av.updatingConservation &&
427 * aa[i].label.equals("Quality")) {
429 * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
430 * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
431 * annotationPanel.imgWidth, y, annotationPanel); g.setColor(Color.black);
432 * // / g.drawString("Calculating Quality....",20, y-row.height/2);
436 // first pass sets up state for drawing continuation from left-hand column
438 x = (startRes == 0) ? 0 : -1;
439 while (x < endRes - startRes)
441 if (hasHiddenColumns)
443 column = columnSelection.adjustForHiddenColumns(startRes + x);
444 if (column > row_annotations.length - 1)
451 column = startRes + x;
454 if ((row_annotations == null) || (row_annotations.length <= column)
455 || (row_annotations[column] == null))
467 g.setColor(Color.red);
469 if (columnSelection != null)
471 for (int n = 0; n < columnSelection.size(); n++)
473 int v = columnSelection.columnAt(n);
477 g.fillRect(x * charWidth, y, charWidth, charHeight);
482 if (!row.isValidStruc())
484 g.setColor(Color.orange);
485 g.fillRect((int) row.getInvalidStrucPos() * charWidth, y,
486 charWidth, charHeight);
490 && row_annotations[column].displayCharacter != null
491 && (row_annotations[column].displayCharacter.length() > 0))
494 if (centreColLabels || scaleColLabel)
496 fmWidth = fm.charsWidth(
497 row_annotations[column].displayCharacter
499 row_annotations[column].displayCharacter.length());
503 // justify the label and scale to fit in column
504 if (fmWidth > charWidth)
506 // scale only if the current font isn't already small enough
507 fmScaling = charWidth;
508 fmScaling /= fmWidth;
509 g.setFont(ofont.deriveFont(AffineTransform
510 .getScaleInstance(fmScaling, 1.0)));
511 // and update the label's width to reflect the scaling.
519 .charWidth(row_annotations[column].displayCharacter
522 charOffset = (int) ((charWidth - fmWidth) / 2f);
524 if (row_annotations[column].colour == null)
525 g.setColor(Color.black);
527 g.setColor(row_annotations[column].colour);
529 if (column == 0 || row.graph > 0)
531 g.drawString(row_annotations[column].displayCharacter,
532 (x * charWidth) + charOffset, y + iconOffset);
534 else if (row_annotations[column - 1] == null
536 || !row_annotations[column].displayCharacter
537 .equals(row_annotations[column - 1].displayCharacter) || (row_annotations[column].displayCharacter
538 .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
540 g.drawString(row_annotations[column].displayCharacter, x
541 * charWidth + charOffset, y + iconOffset);
548 char ss = validRes ? row_annotations[column].secondaryStructure
552 // distinguish between forward/backward base-pairing
553 if (row_annotations[column].displayCharacter.indexOf(')') > -1)
558 if (!validRes || (ss != lastSS))
565 drawHelixAnnot(g, row_annotations, lastSSX, x, y,
566 iconOffset, startRes, column, validRes, validEnd);
570 drawSheetAnnot(g, row_annotations, lastSSX, x, y,
571 iconOffset, startRes, column, validRes, validEnd);
574 case 'S': // Stem case for RNA secondary structure
575 case 's': // and opposite direction
576 drawStemAnnot(g, row_annotations, lastSSX, x, y,
577 iconOffset, startRes, column, validRes, validEnd);
581 g.setColor(Color.gray);
582 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
598 lastSSX = (x * charWidth);
605 if (column >= row_annotations.length)
607 column = row_annotations.length - 1;
614 if ((row_annotations == null) || (row_annotations.length <= column)
615 || (row_annotations[column] == null))
631 drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
632 startRes, column, validRes, validEnd);
636 drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
637 startRes, column, validRes, validEnd);
640 case 'S': // Stem case for RNA secondary structure
641 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
642 startRes, column, validRes, validEnd);
645 drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
646 startRes, column, validRes, validEnd);
651 if (row.graph > 0 && row.graphHeight > 0)
653 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
655 if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
657 // TODO: JAL-1291 revise rendering model so the graphGroup map is computed efficiently for all visible labels
658 float groupmax = -999999, groupmin = 9999999;
659 for (int gg = 0; gg < aa.length; gg++)
661 if (aa[gg].graphGroup != row.graphGroup)
668 aa[gg].visible = false;
670 if (aa[gg].graphMax > groupmax)
672 groupmax = aa[gg].graphMax;
674 if (aa[gg].graphMin < groupmin)
676 groupmin = aa[gg].graphMin;
680 for (int gg = 0; gg < aa.length; gg++)
682 if (aa[gg].graphGroup == row.graphGroup)
684 drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
685 endRes, y, groupmin, groupmax, row.graphHeight);
689 graphGroupDrawn.set(row.graphGroup);
693 drawLineGraph(g, row, row_annotations, startRes, endRes, y,
694 row.graphMin, row.graphMax, row.graphHeight);
697 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
699 drawBarGraph(g, row, row_annotations, startRes, endRes,
700 row.graphMin, row.graphMax, y, renderHistogram,renderProfile,normaliseProfile);
704 if (clipst && !clipend)
708 }// end if_in_visible_region
709 if (row.graph > 0 && row.hasText)
725 System.err.println("Start clip at : " + yfrom + " (index " + f_i
730 System.err.println("End clip at : " + yto + " (index " + f_to
735 System.err.println("Annotation Rendering time:"
736 + (System.currentTimeMillis() - stime));
743 private final Color GLYPHLINE_COLOR = Color.gray;
745 private final Color SHEET_COLOUR = Color.green;
747 private final Color HELIX_COLOUR = Color.red;
749 private final Color STEM_COLOUR = Color.blue;
751 public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
752 int x, int y, int iconOffset, int startRes, int column,
753 boolean validRes, boolean validEnd)
755 g.setColor(GLYPHLINE_COLOR);
756 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
759 public void drawSheetAnnot(Graphics g, Annotation[] row, int lastSSX,
760 int x, int y, int iconOffset, int startRes, int column,
761 boolean validRes, boolean validEnd)
763 g.setColor(SHEET_COLOUR);
765 if (!validEnd || !validRes || row == null || row[column] == null
766 || row[column].secondaryStructure != 'E')
768 g.fillRect(lastSSX, y + 4 + iconOffset,
769 (x * charWidth) - lastSSX - 4, 7);
770 g.fillPolygon(new int[]
771 { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
773 { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
778 g.fillRect(lastSSX, y + 4 + iconOffset,
779 (x + 1) * charWidth - lastSSX, 7);
784 public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
785 int x, int y, int iconOffset, int startRes, int column,
786 boolean validRes, boolean validEnd)
788 g.setColor(HELIX_COLOUR);
790 int sCol = (lastSSX / charWidth) + startRes;
792 int x2 = (x * charWidth);
796 int ofs = charWidth / 2;
797 // Off by 1 offset when drawing rects and ovals
798 // to offscreen image on the MAC
799 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
800 if (sCol == 0 || row[sCol - 1] == null
801 || row[sCol - 1].secondaryStructure != 'H')
806 // g.setColor(Color.orange);
807 g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
810 if (!validRes || row[column] == null
811 || row[column].secondaryStructure != 'H')
817 // g.setColor(Color.magenta);
818 g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
826 if (sCol == 0 || row[sCol - 1] == null
827 || row[sCol - 1].secondaryStructure != 'H')
829 g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
833 if (!validRes || row[column] == null
834 || row[column].secondaryStructure != 'H')
836 g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
841 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
844 public void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
845 Annotation[] aa_annotations, int sRes, int eRes, int y,
846 float min, float max, int graphHeight)
848 if (sRes > aa_annotations.length)
855 // Adjustment for fastpaint to left
861 eRes = Math.min(eRes, aa_annotations.length);
869 float range = max - min;
874 y2 = y - (int) ((0 - min / range) * graphHeight);
877 g.setColor(Color.gray);
878 g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
880 eRes = Math.min(eRes, aa_annotations.length);
883 int aaMax = aa_annotations.length - 1;
885 while (x < eRes - sRes)
888 if (hasHiddenColumns)
890 column = columnSelection.adjustForHiddenColumns(column);
898 if (aa_annotations[column] == null
899 || aa_annotations[column - 1] == null)
905 if (aa_annotations[column].colour == null)
906 g.setColor(Color.black);
908 g.setColor(aa_annotations[column].colour);
911 - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
913 - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
915 g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
916 + charWidth / 2, y2);
920 if (_aa.threshold != null)
922 g.setColor(_aa.threshold.colour);
923 Graphics2D g2 = (Graphics2D) g;
924 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
925 BasicStroke.JOIN_ROUND, 3f, new float[]
928 y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
929 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
930 g2.setStroke(new BasicStroke());
934 public void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
935 Annotation[] aa_annotations, int sRes, int eRes, float min,
936 float max, int y, boolean renderHistogram,boolean renderProfile,boolean normaliseProfile)
938 if (sRes > aa_annotations.length)
942 Font ofont = g.getFont();
943 eRes = Math.min(eRes, aa_annotations.length);
945 int x = 0, y1 = y, y2 = y;
947 float range = max - min;
951 y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
954 g.setColor(Color.gray);
956 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
959 int aaMax = aa_annotations.length - 1;
960 while (x < eRes - sRes)
963 if (hasHiddenColumns)
965 column = columnSelection.adjustForHiddenColumns(column);
973 if (aa_annotations[column] == null)
978 if (aa_annotations[column].colour == null)
979 g.setColor(Color.black);
981 g.setColor(aa_annotations[column].colour);
984 - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
990 g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
994 g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
997 // draw profile if available
1001 int profl[] = getProfileFor(_aa, column);
1002 // just try to draw the logo if profl is not null
1003 if (profl != null && profl[1] != 0)
1005 float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1006 double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1013 * profl.length == 74 indicates that the profile of a secondary
1014 * structure conservation row was accesed. Therefore dc gets length 2,
1015 * to have space for a basepair instead of just a single nucleotide
1017 if (profl.length == 74)
1025 LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1026 double scale = 1f / (normaliseProfile ? profl[1] : 100f);
1027 float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1029 for (int c = 2; c < profl[0];)
1031 dc[0] = (char) profl[c++];
1033 if (_aa.label.startsWith("StrucConsensus"))
1035 dc[1] = (char) profl[c++];
1039 wdth /= fm.charsWidth(dc, 0, dc.length);
1043 scl = htn * scale * profl[c++];
1044 lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1045 .getFontRenderContext());
1046 g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance(
1047 wdth, scl / lm.getAscent())));
1048 lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1050 // Debug - render boxes around characters
1051 // g.setColor(Color.red);
1052 // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1054 // g.setColor(profcolour.findColour(dc[0]).darker());
1055 g.setColor(profcolour.findColour(dc[0], column, null));
1057 hght = (ht + (scl - lm.getDescent() - lm.getBaselineOffsets()[lm
1058 .getBaselineIndex()]));
1060 g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1068 if (_aa.threshold != null)
1070 g.setColor(_aa.threshold.colour);
1071 Graphics2D g2 = (Graphics2D) g;
1072 g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1073 BasicStroke.JOIN_ROUND, 3f, new float[]
1076 y2 = (int) (y - ((_aa.threshold.value - min) / range)
1078 g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1079 g2.setStroke(new BasicStroke());
1083 // used by overview window
1084 public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1085 Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1087 eRes = Math.min(eRes, aa_annotations.length);
1088 g.setColor(Color.white);
1089 g.fillRect(0, 0, width, y);
1090 g.setColor(new Color(0, 0, 180));
1094 for (int j = sRes; j < eRes; j++)
1096 if (aa_annotations[j] != null)
1098 if (aa_annotations[j].colour == null)
1099 g.setColor(Color.black);
1101 g.setColor(aa_annotations[j].colour);
1103 height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1109 g.fillRect(x, y - height, charWidth, height);