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