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