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