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