JAL-3285 small code changes to AnnotationRenderer not included in merge
[jalview.git] / src / jalview / renderer / AnnotationRenderer.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.renderer;
22
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.CodingUtils;
25 import jalview.analysis.Rna;
26 import jalview.analysis.StructureFrequency;
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.HiddenMarkovModel;
33 import jalview.datamodel.ProfilesI;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.NucleotideColourScheme;
36 import jalview.schemes.ResidueProperties;
37 import jalview.schemes.ZappoColourScheme;
38 import jalview.util.Platform;
39 import jalview.workers.InformationThread;
40
41 import java.awt.BasicStroke;
42 import java.awt.Color;
43 import java.awt.Font;
44 import java.awt.FontMetrics;
45 import java.awt.Graphics;
46 import java.awt.Graphics2D;
47 import java.awt.Image;
48 import java.awt.font.LineMetrics;
49 import java.awt.geom.AffineTransform;
50 import java.awt.image.ImageObserver;
51 import java.util.BitSet;
52 import java.util.Hashtable;
53
54 public class AnnotationRenderer
55 {
56   private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32
57
58   private static final int CHAR_A = 'A'; // 65
59
60   private static final int CHAR_Z = 'Z'; // 90
61
62   /**
63    * flag indicating if timing and redraw parameter info should be output
64    */
65   private final boolean debugRedraw;
66
67   private int charWidth, endRes, charHeight;
68
69   private boolean validCharWidth, hasHiddenColumns;
70
71   private FontMetrics fm;
72
73   private final boolean MAC = Platform.isAMac();
74
75   // todo remove these flags, read from group/viewport where needed
76   boolean av_renderHistogram = true;
77
78   boolean av_renderProfile = true;
79
80   boolean av_normaliseProfile = false;
81
82   boolean av_infoHeight = false;
83
84   ResidueShaderI profcolour = null;
85
86   private ColumnSelection columnSelection;
87
88   private HiddenColumns hiddenColumns;
89
90   private ProfilesI hconsensus;
91
92   private Hashtable[] complementConsensus;
93
94   private Hashtable[] hStrucConsensus;
95
96   private boolean av_ignoreGapsConsensus;
97
98   private boolean av_ignoreBelowBackground;
99
100   /**
101    * attributes set from AwtRenderPanelI
102    */
103   /**
104    * old image used when data is currently being calculated and cannot be
105    * rendered
106    */
107   private Image fadedImage;
108
109   /**
110    * panel being rendered into
111    */
112   private ImageObserver annotationPanel;
113
114   /**
115    * width of image to render in panel
116    */
117   private int imgWidth;
118
119   /**
120    * offset to beginning of visible area
121    */
122   private int sOffset;
123
124   /**
125    * offset to end of visible area
126    */
127   private int visHeight;
128
129   /**
130    * indicate if the renderer should only render the visible portion of the
131    * annotation given the current view settings
132    */
133   private boolean useClip = true;
134
135   /**
136    * master flag indicating if renderer should ever try to clip. not enabled for
137    * jalview 2.8.1
138    */
139   private boolean canClip = false;
140
141   public AnnotationRenderer()
142   {
143     this(false);
144   }
145
146   /**
147    * Create a new annotation Renderer
148    * 
149    * @param debugRedraw
150    *          flag indicating if timing and redraw parameter info should be
151    *          output
152    */
153   public AnnotationRenderer(boolean debugRedraw)
154   {
155     this.debugRedraw = debugRedraw;
156   }
157
158   /**
159    * Remove any references and resources when this object is no longer required
160    */
161   public void dispose()
162   {
163     hconsensus = null;
164     complementConsensus = null;
165     hStrucConsensus = null;
166     fadedImage = null;
167     annotationPanel = null;
168   }
169
170   void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
171           int x, int y, int iconOffset, int startRes, int column,
172           boolean validRes, boolean validEnd)
173   {
174     g.setColor(STEM_COLOUR);
175     int sCol = (lastSSX / charWidth)
176             + hiddenColumns.visibleToAbsoluteColumn(startRes);
177     int x1 = lastSSX;
178     int x2 = (x * charWidth);
179
180     char dc = (column == 0 || row_annotations[column - 1] == null) ? ' '
181             : row_annotations[column - 1].secondaryStructure;
182
183     boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
184             || dc != row_annotations[sCol - 1].secondaryStructure;
185     boolean diffdownstream = !validRes || !validEnd
186             || row_annotations[column] == null
187             || dc != row_annotations[column].secondaryStructure;
188
189     if (column > 0 && Rna.isClosingParenthesis(dc))
190     {
191       if (diffupstream)
192       // if (validRes && column>1 && row_annotations[column-2]!=null &&
193       // dc.equals(row_annotations[column-2].displayCharacter))
194       {
195         /*
196          * if new annotation with a closing base pair half of the stem, 
197          * display a backward arrow
198          */
199         g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
200                 new int[]
201                 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
202                 3);
203         x1 += 5;
204       }
205       if (diffdownstream)
206       {
207         x2 -= 1;
208       }
209     }
210     else
211     {
212       // display a forward arrow
213       if (diffdownstream)
214       {
215         /*
216          * if annotation ending with an opeing base pair half of the stem, 
217          * display a forward arrow
218          */
219         g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
220                 new int[]
221                 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
222                 3);
223         x2 -= 5;
224       }
225       if (diffupstream)
226       {
227         x1 += 1;
228       }
229     }
230     // draw arrow body
231     g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
232   }
233
234   void drawNotCanonicalAnnot(Graphics g, Color nonCanColor,
235           Annotation[] row_annotations, int lastSSX, int x, int y,
236           int iconOffset, int startRes, int column, boolean validRes,
237           boolean validEnd)
238   {
239     // System.out.println(nonCanColor);
240
241     g.setColor(nonCanColor);
242     int sCol = (lastSSX / charWidth)
243             + hiddenColumns.visibleToAbsoluteColumn(startRes);
244     int x1 = lastSSX;
245     int x2 = (x * charWidth);
246
247     String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
248             : row_annotations[column - 1].displayCharacter;
249
250     boolean diffupstream = sCol == 0 || row_annotations[sCol - 1] == null
251             || !dc.equals(row_annotations[sCol - 1].displayCharacter);
252     boolean diffdownstream = !validRes || !validEnd
253             || row_annotations[column] == null
254             || !dc.equals(row_annotations[column].displayCharacter);
255     // System.out.println("Column "+column+" diff up: "+diffupstream+"
256     // down:"+diffdownstream);
257     // If a closing base pair half of the stem, display a backward arrow
258     if (column > 0 && Rna.isClosingParenthesis(dc))
259     {
260
261       if (diffupstream)
262       // if (validRes && column>1 && row_annotations[column-2]!=null &&
263       // dc.equals(row_annotations[column-2].displayCharacter))
264       {
265         g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX },
266                 new int[]
267                 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
268                 3);
269         x1 += 5;
270       }
271       if (diffdownstream)
272       {
273         x2 -= 1;
274       }
275     }
276     else
277     {
278
279       // display a forward arrow
280       if (diffdownstream)
281       {
282         g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 },
283                 new int[]
284                 { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
285                 3);
286         x2 -= 5;
287       }
288       if (diffupstream)
289       {
290         x1 += 1;
291       }
292     }
293     // draw arrow body
294     g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
295   }
296
297   // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
298   // av)
299   public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
300           AlignViewportI av)
301   {
302     fm = annotPanel.getFontMetrics();
303     annotationPanel = annotPanel;
304     fadedImage = annotPanel.getFadedImage();
305     imgWidth = annotPanel.getFadedImageWidth();
306     // visible area for rendering
307     int[] bounds = annotPanel.getVisibleVRange();
308     if (bounds != null)
309     {
310       sOffset = bounds[0];
311       visHeight = bounds[1];
312       if (visHeight == 0)
313       {
314         useClip = false;
315       }
316       else
317       {
318         useClip = canClip;
319       }
320     }
321     else
322     {
323       useClip = false;
324     }
325
326     updateFromAlignViewport(av);
327   }
328
329   public void updateFromAlignViewport(AlignViewportI av)
330   {
331     charWidth = av.getCharWidth();
332     endRes = av.getRanges().getEndRes();
333     charHeight = av.getCharHeight();
334     hasHiddenColumns = av.hasHiddenColumns();
335     validCharWidth = av.isValidCharWidth();
336     av_renderHistogram = av.isShowConsensusHistogram();
337     av_renderProfile = av.isShowSequenceLogo();
338     av_normaliseProfile = av.isNormaliseSequenceLogo();
339     profcolour = av.getResidueShading();
340     if (profcolour == null || profcolour.getColourScheme() == null)
341     {
342       /*
343        * Use default colour for sequence logo if 
344        * the alignment has no colourscheme set
345        * (would like to use user preference but n/a for applet)
346        */
347       ColourSchemeI col = av.getAlignment().isNucleotide()
348               ? new NucleotideColourScheme()
349               : new ZappoColourScheme();
350       profcolour = new ResidueShader(col);
351     }
352     columnSelection = av.getColumnSelection();
353     hiddenColumns = av.getAlignment().getHiddenColumns();
354     hconsensus = av.getSequenceConsensusHash();
355     complementConsensus = av.getComplementConsensusHash();
356     hStrucConsensus = av.getRnaStructureConsensusHash();
357     av_ignoreGapsConsensus = av.isIgnoreGapsConsensus();
358     av_ignoreBelowBackground = av.isIgnoreBelowBackground();
359     av_infoHeight = av.isInfoLetterHeight();
360   }
361
362
363
364   /**
365    * Returns profile data; the first element is the profile type, the second is
366    * the number of distinct values, the third the total count, and the remainder
367    * depend on the profile type.
368    * 
369    * @param aa
370    * @param column
371    * @return
372    */
373   int[] getProfileFor(AlignmentAnnotation aa, int column)
374   {
375     // TODO : consider refactoring the global alignment calculation
376     // properties/rendering attributes as a global 'alignment group' which holds
377     // all vis settings for the alignment as a whole rather than a subset
378     //
379     if (InformationThread.HMM_CALC_ID.equals(aa.getCalcId()))
380     {
381       HiddenMarkovModel hmm = aa.sequenceRef.getHMM();
382       return AAFrequency.extractHMMProfile(hmm, column,
383               av_ignoreBelowBackground, av_infoHeight); // TODO check if this follows standard
384                                          // pipeline
385     }
386     if (aa.autoCalculated
387             && (aa.label.startsWith("Consensus") || aa.label
388                     .startsWith("cDNA Consensus")))
389     {
390       boolean forComplement = aa.label.startsWith("cDNA Consensus");
391       if (aa.groupRef != null && aa.groupRef.getConsensusData() != null
392               && aa.groupRef.isShowSequenceLogo())
393       {
394         // TODO? group consensus for cDNA complement
395         return AAFrequency.extractProfile(
396                 aa.groupRef.getConsensusData().get(column),
397                 aa.groupRef.isIgnoreGapsConsensus());
398       }
399       // TODO extend annotation row to enable dynamic and static profile data to
400       // be stored
401       if (aa.groupRef == null && aa.sequenceRef == null)
402       {
403         if (forComplement)
404         {
405           return AAFrequency.extractCdnaProfile(complementConsensus[column],
406                   av_ignoreGapsConsensus);
407         }
408         else
409         {
410           return AAFrequency.extractProfile(hconsensus.get(column),
411                   av_ignoreGapsConsensus);
412         }
413       }
414     }
415     else
416     {
417       if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
418       {
419         // TODO implement group structure consensus
420         /*
421          * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
422          * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
423          * group selections return StructureFrequency.extractProfile(
424          * aa.groupRef.consensusData[column], aa.groupRef
425          * .getIgnoreGapsConsensus()); }
426          */
427         // TODO extend annotation row to enable dynamic and static profile data
428         // to
429         // be stored
430         if (aa.groupRef == null && aa.sequenceRef == null
431                 && hStrucConsensus != null
432                 && hStrucConsensus.length > column)
433         {
434           return StructureFrequency.extractProfile(hStrucConsensus[column],
435                   av_ignoreGapsConsensus);
436         }
437       }
438     }
439     return null;
440   }
441
442   boolean rna = false;
443
444   /**
445    * Render the annotation rows associated with an alignment.
446    * 
447    * @param annotPanel
448    *          container frame
449    * @param av
450    *          data and view settings to render
451    * @param g
452    *          destination for graphics
453    * @param activeRow
454    *          row where a mouse event occured (or -1)
455    * @param startRes
456    *          first column that will be drawn
457    * @param endRes
458    *          last column that will be drawn
459    * @return true if the fadedImage was used for any alignment annotation rows
460    *         currently being calculated
461    */
462   public boolean drawComponent(AwtRenderPanelI annotPanel,
463           AlignViewportI av, Graphics g, int activeRow, int startRes,
464           int endRes)
465   {
466     long stime = System.currentTimeMillis();
467     boolean usedFaded = false;
468     // NOTES:
469     // AnnotationPanel needs to implement: ImageObserver, access to
470     // AlignViewport
471     updateFromAwtRenderPanel(annotPanel, av);
472     fm = g.getFontMetrics();
473     AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
474     int temp = 0;
475     if (aa == null)
476     {
477       return false;
478     }
479     int x = 0, y = 0;
480     int column = 0;
481     char lastSS;
482     int lastSSX;
483     int iconOffset = 0;
484     boolean validRes = false;
485     boolean validEnd = false;
486     boolean labelAllCols = false;
487     boolean centreColLabels;
488     boolean centreColLabelsDef = av.isCentreColumnLabels();
489     boolean scaleColLabel = false;
490     final AlignmentAnnotation consensusAnnot = av
491             .getAlignmentConsensusAnnotation();
492     final AlignmentAnnotation structConsensusAnnot = av
493             .getAlignmentStrucConsensusAnnotation();
494     final AlignmentAnnotation complementConsensusAnnot = av
495             .getComplementConsensusAnnotation();
496     boolean renderHistogram = true, renderProfile = true,
497             normaliseProfile = false, isRNA = rna;
498
499     BitSet graphGroupDrawn = new BitSet();
500     int charOffset = 0; // offset for a label
501     float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
502     // column.
503     Font ofont = g.getFont();
504     // \u03B2 \u03B1
505     // debug ints
506     int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
507     boolean clipst = false, clipend = false;
508     for (int i = 0; i < aa.length; i++)
509     {
510       AlignmentAnnotation row = aa[i];
511       isRNA = row.isRNA();
512       {
513         // check if this is a consensus annotation row and set the display
514         // settings appropriately
515         // TODO: generalise this to have render styles for consensus/profile
516         // data
517         if (row.groupRef != null && row == row.groupRef.getConsensus())
518         {
519           renderHistogram = row.groupRef.isShowConsensusHistogram();
520           renderProfile = row.groupRef.isShowSequenceLogo();
521           normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
522         }
523         else if (row == consensusAnnot || row == structConsensusAnnot
524                 || row == complementConsensusAnnot)
525         {
526           renderHistogram = av_renderHistogram;
527           renderProfile = av_renderProfile;
528           normaliseProfile = av_normaliseProfile;
529         }
530         else if (InformationThread.HMM_CALC_ID.equals(row.getCalcId()))
531         {
532           if (row.groupRef != null)
533           {
534             renderHistogram = row.groupRef.isShowInformationHistogram();
535             renderProfile = row.groupRef.isShowHMMSequenceLogo();
536             normaliseProfile = row.groupRef.isNormaliseHMMSequenceLogo();
537           }
538           else
539           {
540             renderHistogram = av.isShowInformationHistogram();
541             renderProfile = av.isShowHMMSequenceLogo();
542             normaliseProfile = av.isNormaliseHMMSequenceLogo();
543           }
544         }
545         else
546         {
547           renderHistogram = true;
548           // don't need to set render/normaliseProfile since they are not
549           // currently used in any other annotation track renderer
550         }
551       }
552       Annotation[] row_annotations = row.annotations;
553       if (!row.visible)
554       {
555         continue;
556       }
557       centreColLabels = row.centreColLabels || centreColLabelsDef;
558       labelAllCols = row.showAllColLabels;
559       scaleColLabel = row.scaleColLabel;
560       lastSS = ' ';
561       lastSSX = 0;
562
563       if (!useClip || ((y - charHeight) < visHeight
564               && (y + row.height + charHeight * 2) >= sOffset))
565       {// if_in_visible_region
566         if (!clipst)
567         {
568           clipst = true;
569           yfrom = y;
570           f_i = i;
571         }
572         yto = y;
573         f_to = i;
574         if (row.graph > 0)
575         {
576           if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
577           {
578             continue;
579           }
580
581           // this is so that we draw the characters below the graph
582           y += row.height;
583
584           if (row.hasText)
585           {
586             iconOffset = charHeight - fm.getDescent();
587             y -= charHeight;
588           }
589         }
590         else if (row.hasText)
591         {
592           iconOffset = charHeight - fm.getDescent();
593
594         }
595         else
596         {
597           iconOffset = 0;
598         }
599
600         if (row.autoCalculated && av.isCalculationInProgress(row))
601         {
602           y += charHeight;
603           usedFaded = true;
604           g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0,
605                   y - row.height, imgWidth, y, annotationPanel);
606           g.setColor(Color.black);
607           // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
608
609           continue;
610         }
611
612         /*
613          * else if (annotationPanel.av.updatingConservation &&
614          * aa[i].label.equals("Conservation")) {
615          * 
616          * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
617          * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
618          * annotationPanel.imgWidth, y, annotationPanel);
619          * 
620          * g.setColor(Color.black); //
621          * g.drawString("Calculating Conservation.....",20, y-row.height/2);
622          * 
623          * continue; } else if (annotationPanel.av.updatingConservation &&
624          * aa[i].label.equals("Quality")) {
625          * 
626          * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
627          * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
628          * annotationPanel.imgWidth, y, annotationPanel);
629          * g.setColor(Color.black); // /
630          * g.drawString("Calculating Quality....",20, y-row.height/2);
631          * 
632          * continue; }
633          */
634         // first pass sets up state for drawing continuation from left-hand
635         // column
636         // of startRes
637         x = (startRes == 0) ? 0 : -1;
638         while (x < endRes - startRes)
639         {
640           if (hasHiddenColumns)
641           {
642             column = hiddenColumns.visibleToAbsoluteColumn(startRes + x);
643             if (column > row_annotations.length - 1)
644             {
645               break;
646             }
647           }
648           else
649           {
650             column = startRes + x;
651           }
652
653           if ((row_annotations == null)
654                   || (row_annotations.length <= column)
655                   || (row_annotations[column] == null))
656           {
657             validRes = false;
658           }
659           else
660           {
661             validRes = true;
662           }
663           final String displayChar = validRes
664                   ? row_annotations[column].displayCharacter
665                   : null;
666           if (x > -1)
667           {
668             if (activeRow == i)
669             {
670               g.setColor(Color.red);
671
672               if (columnSelection != null)
673               {
674                 if (columnSelection.contains(column))
675                 {
676                   g.fillRect(x * charWidth, y, charWidth, charHeight);
677                 }
678               }
679             }
680             if (row.getInvalidStrucPos() > x)
681             {
682               g.setColor(Color.orange);
683               g.fillRect(x * charWidth, y, charWidth, charHeight);
684             }
685             else if (row.getInvalidStrucPos() == x)
686             {
687               g.setColor(Color.orange.darker());
688               g.fillRect(x * charWidth, y, charWidth, charHeight);
689             }
690             if (validCharWidth && validRes && displayChar != null
691                     && (displayChar.length() > 0))
692             {
693
694               fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
695                       displayChar.length());
696               if (/* centreColLabels || */scaleColLabel)
697               {
698                 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
699                 // displayChar.length());
700                 //
701                 // if (scaleColLabel)
702                 // {
703                 // justify the label and scale to fit in column
704                 if (fmWidth > charWidth)
705                 {
706                   // scale only if the current font isn't already small enough
707                   fmScaling = charWidth;
708                   fmScaling /= fmWidth;
709                   g.setFont(ofont.deriveFont(AffineTransform
710                           .getScaleInstance(fmScaling, 1.0)));
711                   // and update the label's width to reflect the scaling.
712                   fmWidth = charWidth;
713                 }
714                 // }
715               }
716               // TODO is it ok to use width of / show all characters here?
717               // else
718               // {
719               // fmWidth = fm.charWidth(displayChar.charAt(0));
720               // }
721               charOffset = (int) ((charWidth - fmWidth) / 2f);
722
723               if (row_annotations[column].colour == null)
724               {
725                 g.setColor(Color.black);
726               }
727               else
728               {
729                 g.setColor(row_annotations[column].colour);
730               }
731
732               if (column == 0 || row.graph > 0)
733               {
734                 g.drawString(displayChar, (x * charWidth) + charOffset,
735                         y + iconOffset);
736               }
737               else if (row_annotations[column - 1] == null || (labelAllCols
738                       || !displayChar.equals(
739                               row_annotations[column - 1].displayCharacter)
740                       || (displayChar.length() < 2
741                               && row_annotations[column].secondaryStructure == ' ')))
742               {
743                 g.drawString(displayChar, x * charWidth + charOffset,
744                         y + iconOffset);
745               }
746               g.setFont(ofont);
747             }
748           }
749           if (row.hasIcons)
750           {
751             char ss = validRes ? row_annotations[column].secondaryStructure
752                     : '-';
753
754             if (ss == '(')
755             {
756               // distinguish between forward/backward base-pairing
757               if (displayChar.indexOf(')') > -1)
758               {
759
760                 ss = ')';
761
762               }
763             }
764             if (ss == '[')
765             {
766               if ((displayChar.indexOf(']') > -1))
767               {
768                 ss = ']';
769
770               }
771             }
772             if (ss == '{')
773             {
774               // distinguish between forward/backward base-pairing
775               if (displayChar.indexOf('}') > -1)
776               {
777                 ss = '}';
778
779               }
780             }
781             if (ss == '<')
782             {
783               // distinguish between forward/backward base-pairing
784               if (displayChar.indexOf('<') > -1)
785               {
786                 ss = '>';
787
788               }
789             }
790             if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
791             {
792               // distinguish between forward/backward base-pairing
793               int ssLowerCase = ss + UPPER_TO_LOWER;
794               // TODO would .equals() be safer here? or charAt(0)?
795               if (displayChar.indexOf(ssLowerCase) > -1)
796               {
797                 ss = (char) ssLowerCase;
798               }
799             }
800
801             if (!validRes || (ss != lastSS))
802             {
803
804               if (x > -1)
805               {
806
807                 int nb_annot = x - temp;
808                 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre
809                 // annot :"+nb_annot);
810                 switch (lastSS)
811                 {
812                 case '(': // Stem case for RNA secondary structure
813                 case ')': // and opposite direction
814                   drawStemAnnot(g, row_annotations, lastSSX, x, y,
815                           iconOffset, startRes, column, validRes, validEnd);
816                   temp = x;
817                   break;
818
819                 case 'H':
820                   if (!isRNA)
821                   {
822                     drawHelixAnnot(g, row_annotations, lastSSX, x, y,
823                             iconOffset, startRes, column, validRes,
824                             validEnd);
825                     break;
826                   }
827                   // no break if isRNA - falls through to drawNotCanonicalAnnot!
828                 case 'E':
829                   if (!isRNA)
830                   {
831                     drawSheetAnnot(g, row_annotations, lastSSX, x, y,
832                             iconOffset, startRes, column, validRes,
833                             validEnd);
834                     break;
835                   }
836                   // no break if isRNA - fall through to drawNotCanonicalAnnot!
837
838                 case '{':
839                 case '}':
840                 case '[':
841                 case ']':
842                 case '>':
843                 case '<':
844                 case 'A':
845                 case 'a':
846                 case 'B':
847                 case 'b':
848                 case 'C':
849                 case 'c':
850                 case 'D':
851                 case 'd':
852                 case 'e':
853                 case 'F':
854                 case 'f':
855                 case 'G':
856                 case 'g':
857                 case 'h':
858                 case 'I':
859                 case 'i':
860                 case 'J':
861                 case 'j':
862                 case 'K':
863                 case 'k':
864                 case 'L':
865                 case 'l':
866                 case 'M':
867                 case 'm':
868                 case 'N':
869                 case 'n':
870                 case 'O':
871                 case 'o':
872                 case 'P':
873                 case 'p':
874                 case 'Q':
875                 case 'q':
876                 case 'R':
877                 case 'r':
878                 case 'S':
879                 case 's':
880                 case 'T':
881                 case 't':
882                 case 'U':
883                 case 'u':
884                 case 'V':
885                 case 'v':
886                 case 'W':
887                 case 'w':
888                 case 'X':
889                 case 'x':
890                 case 'Y':
891                 case 'y':
892                 case 'Z':
893                 case 'z':
894
895                   Color nonCanColor = getNotCanonicalColor(lastSS);
896                   drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
897                           lastSSX, x, y, iconOffset, startRes, column,
898                           validRes, validEnd);
899                   temp = x;
900                   break;
901                 default:
902                   g.setColor(Color.gray);
903                   g.fillRect(lastSSX, y + 6 + iconOffset,
904                           (x * charWidth) - lastSSX, 2);
905                   temp = x;
906                   break;
907                 }
908               }
909               if (validRes)
910               {
911                 lastSS = ss;
912               }
913               else
914               {
915                 lastSS = ' ';
916               }
917               if (x > -1)
918               {
919                 lastSSX = (x * charWidth);
920               }
921             }
922           }
923           column++;
924           x++;
925         }
926         if (column >= row_annotations.length)
927         {
928           column = row_annotations.length - 1;
929           validEnd = false;
930         }
931         else
932         {
933           validEnd = true;
934         }
935         if ((row_annotations == null) || (row_annotations.length <= column)
936                 || (row_annotations[column] == null))
937         {
938           validRes = false;
939         }
940         else
941         {
942           validRes = true;
943         }
944         // x ++;
945
946         if (row.hasIcons)
947         {
948           switch (lastSS)
949           {
950
951           case 'H':
952             if (!isRNA)
953             {
954               drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
955                       startRes, column, validRes, validEnd);
956               break;
957             }
958             // no break if isRNA - fall through to drawNotCanonicalAnnot!
959
960           case 'E':
961             if (!isRNA)
962             {
963               drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
964                       startRes, column, validRes, validEnd);
965               break;
966             }
967             // no break if isRNA - fall through to drawNotCanonicalAnnot!
968
969           case '(':
970           case ')': // Stem case for RNA secondary structure
971
972             drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
973                     startRes, column, validRes, validEnd);
974
975             break;
976           case '{':
977           case '}':
978           case '[':
979           case ']':
980           case '>':
981           case '<':
982           case 'A':
983           case 'a':
984           case 'B':
985           case 'b':
986           case 'C':
987           case 'c':
988           case 'D':
989           case 'd':
990           case 'e':
991           case 'F':
992           case 'f':
993           case 'G':
994           case 'g':
995           case 'h':
996           case 'I':
997           case 'i':
998           case 'J':
999           case 'j':
1000           case 'K':
1001           case 'k':
1002           case 'L':
1003           case 'l':
1004           case 'M':
1005           case 'm':
1006           case 'N':
1007           case 'n':
1008           case 'O':
1009           case 'o':
1010           case 'P':
1011           case 'p':
1012           case 'Q':
1013           case 'q':
1014           case 'R':
1015           case 'r':
1016           case 'T':
1017           case 't':
1018           case 'U':
1019           case 'u':
1020           case 'V':
1021           case 'v':
1022           case 'W':
1023           case 'w':
1024           case 'X':
1025           case 'x':
1026           case 'Y':
1027           case 'y':
1028           case 'Z':
1029           case 'z':
1030             // System.out.println(lastSS);
1031             Color nonCanColor = getNotCanonicalColor(lastSS);
1032             drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
1033                     x, y, iconOffset, startRes, column, validRes, validEnd);
1034             break;
1035           default:
1036             drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
1037                     startRes, column, validRes, validEnd);
1038             break;
1039           }
1040         }
1041
1042         if (row.graph > 0 && row.graphHeight > 0)
1043         {
1044           if (row.graph == AlignmentAnnotation.LINE_GRAPH)
1045           {
1046             if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
1047             {
1048               // TODO: JAL-1291 revise rendering model so the graphGroup map is
1049               // computed efficiently for all visible labels
1050               float groupmax = -999999, groupmin = 9999999;
1051               for (int gg = 0; gg < aa.length; gg++)
1052               {
1053                 if (aa[gg].graphGroup != row.graphGroup)
1054                 {
1055                   continue;
1056                 }
1057
1058                 if (aa[gg] != row)
1059                 {
1060                   aa[gg].visible = false;
1061                 }
1062                 if (aa[gg].graphMax > groupmax)
1063                 {
1064                   groupmax = aa[gg].graphMax;
1065                 }
1066                 if (aa[gg].graphMin < groupmin)
1067                 {
1068                   groupmin = aa[gg].graphMin;
1069                 }
1070               }
1071
1072               for (int gg = 0; gg < aa.length; gg++)
1073               {
1074                 if (aa[gg].graphGroup == row.graphGroup)
1075                 {
1076                   drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1077                           endRes, y, groupmin, groupmax, row.graphHeight);
1078                 }
1079               }
1080
1081               graphGroupDrawn.set(row.graphGroup);
1082             }
1083             else
1084             {
1085               drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1086                       row.graphMin, row.graphMax, row.graphHeight);
1087             }
1088           }
1089           else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1090           {
1091             drawBarGraph(g, row, row_annotations, startRes, endRes,
1092                     row.graphMin, row.graphMax, y, renderHistogram,
1093                     renderProfile, normaliseProfile);
1094           }
1095         }
1096       }
1097       else
1098       {
1099         if (clipst && !clipend)
1100         {
1101           clipend = true;
1102         }
1103       } // end if_in_visible_region
1104       if (row.graph > 0 && row.hasText)
1105       {
1106         y += charHeight;
1107       }
1108
1109       if (row.graph == 0)
1110       {
1111         y += aa[i].height;
1112       }
1113     }
1114     if (debugRedraw)
1115     {
1116       if (canClip)
1117       {
1118         if (clipst)
1119         {
1120           System.err.println(
1121                   "Start clip at : " + yfrom + " (index " + f_i + ")");
1122         }
1123         if (clipend)
1124         {
1125           System.err.println(
1126                   "End clip at : " + yto + " (index " + f_to + ")");
1127         }
1128       }
1129       ;
1130       System.err.println("Annotation Rendering time:"
1131               + (System.currentTimeMillis() - stime));
1132     }
1133     ;
1134
1135     return !usedFaded;
1136   }
1137
1138   public static final Color GLYPHLINE_COLOR = Color.gray;
1139
1140   public static final Color SHEET_COLOUR = Color.green;
1141
1142   public static final Color HELIX_COLOUR = Color.red;
1143
1144   public static final Color STEM_COLOUR = Color.blue;
1145
1146   private Color sdNOTCANONICAL_COLOUR;
1147
1148   void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1149           int y, int iconOffset, int startRes, int column, boolean validRes,
1150           boolean validEnd)
1151   {
1152     g.setColor(GLYPHLINE_COLOR);
1153     g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1154   }
1155
1156   void drawSheetAnnot(Graphics g, Annotation[] row,
1157
1158           int lastSSX, int x, int y, int iconOffset, int startRes,
1159           int column, boolean validRes, boolean validEnd)
1160   {
1161     g.setColor(SHEET_COLOUR);
1162
1163     if (!validEnd || !validRes || row == null || row[column] == null
1164             || row[column].secondaryStructure != 'E')
1165     {
1166       g.fillRect(lastSSX, y + 4 + iconOffset, (x * charWidth) - lastSSX - 4,
1167               7);
1168       g.fillPolygon(
1169               new int[]
1170               { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) },
1171               new int[]
1172               { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset },
1173               3);
1174     }
1175     else
1176     {
1177       g.fillRect(lastSSX, y + 4 + iconOffset, (x + 1) * charWidth - lastSSX,
1178               7);
1179     }
1180
1181   }
1182
1183   void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
1184           int y, int iconOffset, int startRes, int column, boolean validRes,
1185           boolean validEnd)
1186   {
1187     g.setColor(HELIX_COLOUR);
1188
1189     int sCol = (lastSSX / charWidth)
1190             + hiddenColumns.visibleToAbsoluteColumn(startRes);
1191     int x1 = lastSSX;
1192     int x2 = (x * charWidth);
1193
1194     if (MAC)
1195     {
1196       int ofs = charWidth / 2;
1197       // Off by 1 offset when drawing rects and ovals
1198       // to offscreen image on the MAC
1199       g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1200       if (sCol == 0 || row[sCol - 1] == null
1201               || row[sCol - 1].secondaryStructure != 'H')
1202       {
1203       }
1204       else
1205       {
1206         // g.setColor(Color.orange);
1207         g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1208                 0, 0);
1209       }
1210       if (!validRes || row[column] == null
1211               || row[column].secondaryStructure != 'H')
1212       {
1213
1214       }
1215       else
1216       {
1217         // g.setColor(Color.magenta);
1218         g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset,
1219                 x2 - x1 - ofs + 1, 8, 0, 0);
1220
1221       }
1222
1223       return;
1224     }
1225
1226     if (sCol == 0 || row[sCol - 1] == null
1227             || row[sCol - 1].secondaryStructure != 'H')
1228     {
1229       g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1230       x1 += charWidth / 2;
1231     }
1232
1233     if (!validRes || row[column] == null
1234             || row[column].secondaryStructure != 'H')
1235     {
1236       g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1237               8, 270, 180);
1238       x2 -= charWidth / 2;
1239     }
1240
1241     g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1242   }
1243
1244   void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1245           Annotation[] aa_annotations, int sRes, int eRes, int y, float min,
1246           float max, int graphHeight)
1247   {
1248     if (sRes > aa_annotations.length)
1249     {
1250       return;
1251     }
1252
1253     int x = 0;
1254
1255     // Adjustment for fastpaint to left
1256     if (eRes < endRes)
1257     {
1258       eRes++;
1259     }
1260
1261     eRes = Math.min(eRes, aa_annotations.length);
1262
1263     if (sRes == 0)
1264     {
1265       x++;
1266     }
1267
1268     int y1 = y, y2 = y;
1269     float range = max - min;
1270
1271     // //Draw origin
1272     if (min < 0)
1273     {
1274       y2 = y - (int) ((0 - min / range) * graphHeight);
1275     }
1276
1277     g.setColor(Color.gray);
1278     g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1279
1280     eRes = Math.min(eRes, aa_annotations.length);
1281
1282     int column;
1283     int aaMax = aa_annotations.length - 1;
1284
1285     while (x < eRes - sRes)
1286     {
1287       column = sRes + x;
1288       if (hasHiddenColumns)
1289       {
1290         column = hiddenColumns.visibleToAbsoluteColumn(column);
1291       }
1292
1293       if (column > aaMax)
1294       {
1295         break;
1296       }
1297
1298       if (aa_annotations[column] == null
1299               || aa_annotations[column - 1] == null)
1300       {
1301         x++;
1302         continue;
1303       }
1304
1305       if (aa_annotations[column].colour == null)
1306       {
1307         g.setColor(Color.black);
1308       }
1309       else
1310       {
1311         g.setColor(aa_annotations[column].colour);
1312       }
1313
1314       y1 = y - (int) (((aa_annotations[column - 1].value - min) / range)
1315               * graphHeight);
1316       y2 = y - (int) (((aa_annotations[column].value - min) / range)
1317               * graphHeight);
1318
1319       g.drawLine(x * charWidth - charWidth / 2, y1,
1320               x * charWidth + charWidth / 2, y2);
1321       x++;
1322     }
1323
1324     if (_aa.threshold != null)
1325     {
1326       g.setColor(_aa.threshold.colour);
1327       Graphics2D g2 = (Graphics2D) g;
1328       g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1329               BasicStroke.JOIN_ROUND, 3f, new float[]
1330               { 5f, 3f }, 0f));
1331
1332       y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1333       g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1334       g2.setStroke(new BasicStroke());
1335     }
1336   }
1337
1338   void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1339           Annotation[] aa_annotations, int sRes, int eRes, float min,
1340           float max, int y, boolean renderHistogram, boolean renderProfile,
1341           boolean normaliseProfile)
1342   {
1343     if (sRes > aa_annotations.length)
1344     {
1345       return;
1346     }
1347     Font ofont = g.getFont();
1348     eRes = Math.min(eRes, aa_annotations.length);
1349
1350     int x = 0, y1 = y, y2 = y;
1351
1352     float range = max - min;
1353
1354     if (min < 0)
1355     {
1356       y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1357     }
1358
1359     g.setColor(Color.gray);
1360
1361     g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1362
1363     int column;
1364     int aaMax = aa_annotations.length - 1;
1365     while (x < eRes - sRes)
1366     {
1367       column = sRes + x;
1368       if (hasHiddenColumns)
1369       {
1370         column = hiddenColumns.visibleToAbsoluteColumn(column);
1371       }
1372
1373       if (column > aaMax)
1374       {
1375         break;
1376       }
1377
1378       if (aa_annotations[column] == null)
1379       {
1380         x++;
1381         continue;
1382       }
1383       if (aa_annotations[column].colour == null)
1384       {
1385         g.setColor(Color.black);
1386       }
1387       else
1388       {
1389         g.setColor(aa_annotations[column].colour);
1390       }
1391
1392       y1 = y - (int) (((aa_annotations[column].value - min) / (range))
1393               * _aa.graphHeight);
1394
1395       if (renderHistogram)
1396       {
1397         if (y1 - y2 > 0)
1398         {
1399           g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1400         }
1401         else
1402         {
1403           g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1404         }
1405       }
1406       // draw profile if available
1407       if (renderProfile)
1408       {
1409
1410         /*
1411          * {profile type, #values, total count, char1, pct1, char2, pct2...}
1412          */
1413         int profl[] = getProfileFor(_aa, column);
1414
1415         // just try to draw the logo if profl is not null
1416         if (profl != null && profl[2] != 0)
1417         {
1418           boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1419           boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1420           float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1421           double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1422           double hght;
1423           float wdth;
1424           double ht2 = 0;
1425           char[] dc;
1426
1427           /**
1428            * Render a single base for a sequence profile, a base pair for
1429            * structure profile, and a triplet for a cdna profile
1430            */
1431           dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1432
1433           LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1434           double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1435           float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1436           double scl = 0.0;
1437
1438           /*
1439            * Traverse the character(s)/percentage data in the array
1440            */
1441           int c = 3;
1442           int valuesProcessed = 0;
1443           // profl[1] is the number of values in the profile
1444           while (valuesProcessed < profl[1])
1445           {
1446             if (isStructureProfile)
1447             {
1448               // todo can we encode a structure pair as an int, like codons?
1449               dc[0] = (char) profl[c++];
1450               dc[1] = (char) profl[c++];
1451             }
1452             else if (isCdnaProfile)
1453             {
1454               dc = CodingUtils.decodeCodon(profl[c++]);
1455             }
1456             else
1457             {
1458               dc[0] = (char) profl[c++];
1459             }
1460
1461             wdth = charWidth;
1462             wdth /= fm.charsWidth(dc, 0, dc.length);
1463
1464             ht += scl;
1465             // next profl[] position is profile % for the character(s)
1466             scl = htn * scale * profl[c++];
1467             lm = ofont.getLineMetrics(dc, 0, 1,
1468                     g.getFontMetrics().getFontRenderContext());
1469             Font font = ofont.deriveFont(AffineTransform
1470                     .getScaleInstance(wdth, scl / lm.getAscent()));
1471             g.setFont(font);
1472             lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1473
1474             // Debug - render boxes around characters
1475             // g.setColor(Color.red);
1476             // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1477             // (int)(scl));
1478             // g.setColor(profcolour.findColour(dc[0]).darker());
1479
1480             /*
1481              * Set character colour as per alignment colour scheme; use the
1482              * codon translation if a cDNA profile
1483              */
1484             Color colour = null;
1485             if (isCdnaProfile)
1486             {
1487               final String codonTranslation = ResidueProperties
1488                       .codonTranslate(new String(dc));
1489               colour = profcolour.findColour(codonTranslation.charAt(0),
1490                       column, null);
1491             }
1492             else
1493             {
1494               colour = profcolour.findColour(dc[0], column, null);
1495             }
1496             g.setColor(colour == Color.white ? Color.lightGray : colour);
1497
1498             hght = (ht + (scl - lm.getDescent()
1499                     - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
1500
1501             g.drawChars(dc, 0, dc.length, x * charWidth, (int) hght);
1502             valuesProcessed++;
1503           }
1504           g.setFont(ofont);
1505         }
1506       }
1507       x++;
1508     }
1509     if (_aa.threshold != null)
1510     {
1511       g.setColor(_aa.threshold.colour);
1512       Graphics2D g2 = (Graphics2D) g;
1513       g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1514               BasicStroke.JOIN_ROUND, 3f, new float[]
1515               { 5f, 3f }, 0f));
1516
1517       y2 = (int) (y
1518               - ((_aa.threshold.value - min) / range) * _aa.graphHeight);
1519       g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1520       g2.setStroke(new BasicStroke());
1521     }
1522   }
1523
1524   // used by overview window
1525   public void drawGraph(Graphics g, AlignmentAnnotation _aa,
1526           Annotation[] aa_annotations, int width, int y, int sRes, int eRes)
1527   {
1528     eRes = Math.min(eRes, aa_annotations.length);
1529     g.setColor(Color.white);
1530     g.fillRect(0, 0, width, y);
1531     g.setColor(new Color(0, 0, 180));
1532
1533     int x = 0, height;
1534
1535     for (int j = sRes; j < eRes; j++)
1536     {
1537       if (aa_annotations[j] != null)
1538       {
1539         if (aa_annotations[j].colour == null)
1540         {
1541           g.setColor(Color.black);
1542         }
1543         else
1544         {
1545           g.setColor(aa_annotations[j].colour);
1546         }
1547
1548         height = (int) ((aa_annotations[j].value / _aa.graphMax) * y);
1549         if (height > y)
1550         {
1551           height = y;
1552         }
1553
1554         g.fillRect(x, y - height, charWidth, height);
1555       }
1556       x += charWidth;
1557     }
1558   }
1559
1560   Color getNotCanonicalColor(char lastss)
1561   {
1562     switch (lastss)
1563     {
1564     case '{':
1565     case '}':
1566       return new Color(255, 125, 5);
1567
1568     case '[':
1569     case ']':
1570       return new Color(245, 115, 10);
1571
1572     case '>':
1573     case '<':
1574       return new Color(235, 135, 15);
1575
1576     case 'A':
1577     case 'a':
1578       return new Color(225, 105, 20);
1579
1580     case 'B':
1581     case 'b':
1582       return new Color(215, 145, 30);
1583
1584     case 'C':
1585     case 'c':
1586       return new Color(205, 95, 35);
1587
1588     case 'D':
1589     case 'd':
1590       return new Color(195, 155, 45);
1591
1592     case 'E':
1593     case 'e':
1594       return new Color(185, 85, 55);
1595
1596     case 'F':
1597     case 'f':
1598       return new Color(175, 165, 65);
1599
1600     case 'G':
1601     case 'g':
1602       return new Color(170, 75, 75);
1603
1604     case 'H':
1605     case 'h':
1606       return new Color(160, 175, 85);
1607
1608     case 'I':
1609     case 'i':
1610       return new Color(150, 65, 95);
1611
1612     case 'J':
1613     case 'j':
1614       return new Color(140, 185, 105);
1615
1616     case 'K':
1617     case 'k':
1618       return new Color(130, 55, 110);
1619
1620     case 'L':
1621     case 'l':
1622       return new Color(120, 195, 120);
1623
1624     case 'M':
1625     case 'm':
1626       return new Color(110, 45, 130);
1627
1628     case 'N':
1629     case 'n':
1630       return new Color(100, 205, 140);
1631
1632     case 'O':
1633     case 'o':
1634       return new Color(90, 35, 150);
1635
1636     case 'P':
1637     case 'p':
1638       return new Color(85, 215, 160);
1639
1640     case 'Q':
1641     case 'q':
1642       return new Color(75, 25, 170);
1643
1644     case 'R':
1645     case 'r':
1646       return new Color(65, 225, 180);
1647
1648     case 'S':
1649     case 's':
1650       return new Color(55, 15, 185);
1651
1652     case 'T':
1653     case 't':
1654       return new Color(45, 235, 195);
1655
1656     case 'U':
1657     case 'u':
1658       return new Color(35, 5, 205);
1659
1660     case 'V':
1661     case 'v':
1662       return new Color(25, 245, 215);
1663
1664     case 'W':
1665     case 'w':
1666       return new Color(15, 0, 225);
1667
1668     case 'X':
1669     case 'x':
1670       return new Color(10, 255, 235);
1671
1672     case 'Y':
1673     case 'y':
1674       return new Color(5, 150, 245);
1675
1676     case 'Z':
1677     case 'z':
1678       return new Color(0, 80, 255);
1679
1680     default:
1681       System.out.println("This is not a interaction : " + lastss);
1682       return null;
1683
1684     }
1685   }
1686 }