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