d7ae9504f068e29d0e4b50745f34000793ff5f1c
[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.ProfileI;
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 ProfileI[] 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 alignnent 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[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(hconsensus[column],
370                   av_ignoreGapsConsensus);
371         }
372       }
373     }
374     else
375     {
376       if (aa.autoCalculated && aa.label.startsWith("StrucConsensus"))
377       {
378         // TODO implement group structure consensus
379         /*
380          * if (aa.groupRef != null && aa.groupRef.consensusData != null &&
381          * aa.groupRef.isShowSequenceLogo()) { //TODO check what happens for
382          * group selections return StructureFrequency.extractProfile(
383          * aa.groupRef.consensusData[column], aa.groupRef
384          * .getIgnoreGapsConsensus()); }
385          */
386         // TODO extend annotation row to enable dynamic and static profile data
387         // to
388         // be stored
389         if (aa.groupRef == null && aa.sequenceRef == null
390                 && hStrucConsensus != null
391                 && hStrucConsensus.length > column)
392         {
393           return StructureFrequency.extractProfile(hStrucConsensus[column],
394                   av_ignoreGapsConsensus);
395         }
396       }
397     }
398     return null;
399   }
400
401   boolean rna = false;
402
403   /**
404    * Render the annotation rows associated with an alignment.
405    * 
406    * @param annotPanel
407    *          container frame
408    * @param av
409    *          data and view settings to render
410    * @param g
411    *          destination for graphics
412    * @param activeRow
413    *          row where a mouse event occured (or -1)
414    * @param startRes
415    *          first column that will be drawn
416    * @param endRes
417    *          last column that will be drawn
418    * @return true if the fadedImage was used for any alignment annotation rows
419    *         currently being calculated
420    */
421   public boolean drawComponent(AwtRenderPanelI annotPanel,
422           AlignViewportI av, Graphics g, int activeRow, int startRes,
423           int endRes)
424   {
425     long stime = System.currentTimeMillis();
426     boolean usedFaded = false;
427     // NOTES:
428     // AnnotationPanel needs to implement: ImageObserver, access to
429     // AlignViewport
430     updateFromAwtRenderPanel(annotPanel, av);
431     fm = g.getFontMetrics();
432     AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
433     int temp = 0;
434     if (aa == null)
435     {
436       return false;
437     }
438     int x = 0, y = 0;
439     int column = 0;
440     char lastSS;
441     int lastSSX;
442     int iconOffset = 0;
443     boolean validRes = false;
444     boolean validEnd = false;
445     boolean labelAllCols = false;
446     boolean centreColLabels;
447     boolean centreColLabelsDef = av.isCentreColumnLabels();
448     boolean scaleColLabel = false;
449     final AlignmentAnnotation consensusAnnot = av
450             .getAlignmentConsensusAnnotation();
451     final AlignmentAnnotation structConsensusAnnot = av
452             .getAlignmentStrucConsensusAnnotation();
453     final AlignmentAnnotation complementConsensusAnnot = av
454             .getComplementConsensusAnnotation();
455     boolean renderHistogram = true, renderProfile = true, normaliseProfile = false, isRNA = rna;
456
457     BitSet graphGroupDrawn = new BitSet();
458     int charOffset = 0; // offset for a label
459     float fmWidth, fmScaling = 1f; // scaling for a label to fit it into a
460     // column.
461     Font ofont = g.getFont();
462     // \u03B2 \u03B1
463     // debug ints
464     int yfrom = 0, f_i = 0, yto = 0, f_to = 0;
465     boolean clipst = false, clipend = false;
466     for (int i = 0; i < aa.length; i++)
467     {
468       AlignmentAnnotation row = aa[i];
469       isRNA = row.isRNA();
470       {
471         // check if this is a consensus annotation row and set the display
472         // settings appropriately
473         // TODO: generalise this to have render styles for consensus/profile
474         // data
475         if (row.groupRef != null && row == row.groupRef.getConsensus())
476         {
477           renderHistogram = row.groupRef.isShowConsensusHistogram();
478           renderProfile = row.groupRef.isShowSequenceLogo();
479           normaliseProfile = row.groupRef.isNormaliseSequenceLogo();
480         }
481         else if (row == consensusAnnot || row == structConsensusAnnot
482                 || row == complementConsensusAnnot)
483         {
484           renderHistogram = av_renderHistogram;
485           renderProfile = av_renderProfile;
486           normaliseProfile = av_normaliseProfile;
487         }
488         else
489         {
490           renderHistogram = true;
491           // don't need to set render/normaliseProfile since they are not
492           // currently used in any other annotation track renderer
493         }
494       }
495       Annotation[] row_annotations = row.annotations;
496       if (!row.visible)
497       {
498         continue;
499       }
500       centreColLabels = row.centreColLabels || centreColLabelsDef;
501       labelAllCols = row.showAllColLabels;
502       scaleColLabel = row.scaleColLabel;
503       lastSS = ' ';
504       lastSSX = 0;
505
506       if (!useClip
507               || ((y - charHeight) < visHeight && (y + row.height + charHeight * 2) >= sOffset))
508       {// if_in_visible_region
509         if (!clipst)
510         {
511           clipst = true;
512           yfrom = y;
513           f_i = i;
514         }
515         yto = y;
516         f_to = i;
517         if (row.graph > 0)
518         {
519           if (row.graphGroup > -1 && graphGroupDrawn.get(row.graphGroup))
520           {
521             continue;
522           }
523
524           // this is so that we draw the characters below the graph
525           y += row.height;
526
527           if (row.hasText)
528           {
529             iconOffset = charHeight - fm.getDescent();
530             y -= charHeight;
531           }
532         }
533         else if (row.hasText)
534         {
535           iconOffset = charHeight - fm.getDescent();
536
537         }
538         else
539         {
540           iconOffset = 0;
541         }
542
543         if (row.autoCalculated && av.isCalculationInProgress(row))
544         {
545           y += charHeight;
546           usedFaded = true;
547           g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
548                   - row.height, imgWidth, y, annotationPanel);
549           g.setColor(Color.black);
550           // g.drawString("Calculating "+aa[i].label+"....",20, y-row.height/2);
551
552           continue;
553         }
554
555         /*
556          * else if (annotationPanel.av.updatingConservation &&
557          * aa[i].label.equals("Conservation")) {
558          * 
559          * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
560          * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
561          * annotationPanel.imgWidth, y, annotationPanel);
562          * 
563          * g.setColor(Color.black); //
564          * g.drawString("Calculating Conservation.....",20, y-row.height/2);
565          * 
566          * continue; } else if (annotationPanel.av.updatingConservation &&
567          * aa[i].label.equals("Quality")) {
568          * 
569          * y += charHeight; g.drawImage(annotationPanel.fadedImage, 0, y -
570          * row.height, annotationPanel.imgWidth, y, 0, y - row.height,
571          * annotationPanel.imgWidth, y, annotationPanel);
572          * g.setColor(Color.black); // /
573          * g.drawString("Calculating Quality....",20, y-row.height/2);
574          * 
575          * continue; }
576          */
577         // first pass sets up state for drawing continuation from left-hand
578         // column
579         // of startRes
580         x = (startRes == 0) ? 0 : -1;
581         while (x < endRes - startRes)
582         {
583           if (hasHiddenColumns)
584           {
585             column = columnSelection.adjustForHiddenColumns(startRes + x);
586             if (column > row_annotations.length - 1)
587             {
588               break;
589             }
590           }
591           else
592           {
593             column = startRes + x;
594           }
595
596           if ((row_annotations == null)
597                   || (row_annotations.length <= column)
598                   || (row_annotations[column] == null))
599           {
600             validRes = false;
601           }
602           else
603           {
604             validRes = true;
605           }
606           final String displayChar = validRes ? row_annotations[column].displayCharacter
607                   : null;
608           if (x > -1)
609           {
610             if (activeRow == i)
611             {
612               g.setColor(Color.red);
613
614               if (columnSelection != null)
615               {
616                 if (columnSelection.contains(column))
617                 {
618                   g.fillRect(x * charWidth, y, charWidth, charHeight);
619                 }
620               }
621             }
622             if (row.getInvalidStrucPos() > x)
623             {
624               g.setColor(Color.orange);
625               g.fillRect(x * charWidth, y, charWidth, charHeight);
626             }
627             else if (row.getInvalidStrucPos() == x)
628             {
629               g.setColor(Color.orange.darker());
630               g.fillRect(x * charWidth, y, charWidth, charHeight);
631             }
632             if (validCharWidth && validRes && displayChar != null
633                     && (displayChar.length() > 0))
634             {
635
636               fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
637                       displayChar.length());
638               if (/* centreColLabels || */scaleColLabel)
639               {
640                 // fmWidth = fm.charsWidth(displayChar.toCharArray(), 0,
641                 // displayChar.length());
642                 //
643                 // if (scaleColLabel)
644                 // {
645                 // justify the label and scale to fit in column
646                 if (fmWidth > charWidth)
647                 {
648                   // scale only if the current font isn't already small enough
649                   fmScaling = charWidth;
650                   fmScaling /= fmWidth;
651                   g.setFont(ofont.deriveFont(AffineTransform
652                           .getScaleInstance(fmScaling, 1.0)));
653                   // and update the label's width to reflect the scaling.
654                   fmWidth = charWidth;
655                 }
656                 // }
657               }
658               // TODO is it ok to use width of / show all characters here?
659               // else
660               // {
661               // fmWidth = fm.charWidth(displayChar.charAt(0));
662               // }
663               charOffset = (int) ((charWidth - fmWidth) / 2f);
664
665               if (row_annotations[column].colour == null)
666               {
667                 g.setColor(Color.black);
668               }
669               else
670               {
671                 g.setColor(row_annotations[column].colour);
672               }
673
674               if (column == 0 || row.graph > 0)
675               {
676                 g.drawString(displayChar, (x * charWidth) + charOffset, y
677                         + iconOffset);
678               }
679               else if (row_annotations[column - 1] == null
680                       || (labelAllCols
681                               || !displayChar
682                                       .equals(row_annotations[column - 1].displayCharacter) || (displayChar
683                               .length() < 2 && row_annotations[column].secondaryStructure == ' ')))
684               {
685                 g.drawString(displayChar, x * charWidth + charOffset, y
686                         + iconOffset);
687               }
688               g.setFont(ofont);
689             }
690           }
691           if (row.hasIcons)
692           {
693             char ss = validRes ? row_annotations[column].secondaryStructure
694                     : '-';
695
696             if (ss == '(')
697             {
698               // distinguish between forward/backward base-pairing
699               if (displayChar.indexOf(')') > -1)
700               {
701
702                 ss = ')';
703
704               }
705             }
706             if (ss == '[')
707             {
708               if ((displayChar.indexOf(']') > -1))
709               {
710                 ss = ']';
711
712               }
713             }
714             if (ss == '{')
715             {
716               // distinguish between forward/backward base-pairing
717               if (displayChar.indexOf('}') > -1)
718               {
719                 ss = '}';
720
721               }
722             }
723             if (ss == '<')
724             {
725               // distinguish between forward/backward base-pairing
726               if (displayChar.indexOf('<') > -1)
727               {
728                 ss = '>';
729
730               }
731             }
732             if (isRNA && (ss >= CHAR_A) && (ss <= CHAR_Z))
733             {
734               // distinguish between forward/backward base-pairing
735               int ssLowerCase = ss + UPPER_TO_LOWER;
736               // TODO would .equals() be safer here? or charAt(0)?
737               if (displayChar.indexOf(ssLowerCase) > -1)
738               {
739                 ss = (char) ssLowerCase;
740               }
741             }
742
743             if (!validRes || (ss != lastSS))
744             {
745
746               if (x > -1)
747               {
748
749                 int nb_annot = x - temp;
750                 // System.out.println("\t type :"+lastSS+"\t x :"+x+"\t nbre annot :"+nb_annot);
751                 switch (lastSS)
752                 {
753                 case '(': // Stem case for RNA secondary structure
754                 case ')': // and opposite direction
755                   drawStemAnnot(g, row_annotations, lastSSX, x, y,
756                           iconOffset, startRes, column, validRes, validEnd);
757                   temp = x;
758                   break;
759
760                 case 'H':
761                   if (!isRNA)
762                   {
763                     drawHelixAnnot(g, row_annotations, lastSSX, x, y,
764                             iconOffset, startRes, column, validRes,
765                             validEnd);
766                     break;
767                   }
768                   // no break if isRNA - falls through to drawNotCanonicalAnnot!
769                 case 'E':
770                   if (!isRNA)
771                   {
772                     drawSheetAnnot(g, row_annotations, lastSSX, x, y,
773                             iconOffset, startRes, column, validRes,
774                             validEnd);
775                     break;
776                   }
777                   // no break if isRNA - fall through to drawNotCanonicalAnnot!
778
779                 case '{':
780                 case '}':
781                 case '[':
782                 case ']':
783                 case '>':
784                 case '<':
785                 case 'A':
786                 case 'a':
787                 case 'B':
788                 case 'b':
789                 case 'C':
790                 case 'c':
791                 case 'D':
792                 case 'd':
793                 case 'e':
794                 case 'F':
795                 case 'f':
796                 case 'G':
797                 case 'g':
798                 case 'h':
799                 case 'I':
800                 case 'i':
801                 case 'J':
802                 case 'j':
803                 case 'K':
804                 case 'k':
805                 case 'L':
806                 case 'l':
807                 case 'M':
808                 case 'm':
809                 case 'N':
810                 case 'n':
811                 case 'O':
812                 case 'o':
813                 case 'P':
814                 case 'p':
815                 case 'Q':
816                 case 'q':
817                 case 'R':
818                 case 'r':
819                 case 'S':
820                 case 's':
821                 case 'T':
822                 case 't':
823                 case 'U':
824                 case 'u':
825                 case 'V':
826                 case 'v':
827                 case 'W':
828                 case 'w':
829                 case 'X':
830                 case 'x':
831                 case 'Y':
832                 case 'y':
833                 case 'Z':
834                 case 'z':
835
836                   Color nonCanColor = getNotCanonicalColor(lastSS);
837                   drawNotCanonicalAnnot(g, nonCanColor, row_annotations,
838                           lastSSX, x, y, iconOffset, startRes, column,
839                           validRes, validEnd);
840                   temp = x;
841                   break;
842                 default:
843                   g.setColor(Color.gray);
844                   g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
845                           - lastSSX, 2);
846                   temp = x;
847                   break;
848                 }
849               }
850               if (validRes)
851               {
852                 lastSS = ss;
853               }
854               else
855               {
856                 lastSS = ' ';
857               }
858               if (x > -1)
859               {
860                 lastSSX = (x * charWidth);
861               }
862             }
863           }
864           column++;
865           x++;
866         }
867         if (column >= row_annotations.length)
868         {
869           column = row_annotations.length - 1;
870           validEnd = false;
871         }
872         else
873         {
874           validEnd = true;
875         }
876         if ((row_annotations == null) || (row_annotations.length <= column)
877                 || (row_annotations[column] == null))
878         {
879           validRes = false;
880         }
881         else
882         {
883           validRes = true;
884         }
885         // x ++;
886
887         if (row.hasIcons)
888         {
889           switch (lastSS)
890           {
891
892           case 'H':
893             if (!isRNA)
894             {
895               drawHelixAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
896                       startRes, column, validRes, validEnd);
897               break;
898             }
899             // no break if isRNA - fall through to drawNotCanonicalAnnot!
900
901           case 'E':
902             if (!isRNA)
903             {
904               drawSheetAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
905                       startRes, column, validRes, validEnd);
906               break;
907             }
908             // no break if isRNA - fall through to drawNotCanonicalAnnot!
909
910           case '(':
911           case ')': // Stem case for RNA secondary structure
912
913             drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset,
914                     startRes, column, validRes, validEnd);
915
916             break;
917           case '{':
918           case '}':
919           case '[':
920           case ']':
921           case '>':
922           case '<':
923           case 'A':
924           case 'a':
925           case 'B':
926           case 'b':
927           case 'C':
928           case 'c':
929           case 'D':
930           case 'd':
931           case 'e':
932           case 'F':
933           case 'f':
934           case 'G':
935           case 'g':
936           case 'h':
937           case 'I':
938           case 'i':
939           case 'J':
940           case 'j':
941           case 'K':
942           case 'k':
943           case 'L':
944           case 'l':
945           case 'M':
946           case 'm':
947           case 'N':
948           case 'n':
949           case 'O':
950           case 'o':
951           case 'P':
952           case 'p':
953           case 'Q':
954           case 'q':
955           case 'R':
956           case 'r':
957           case 'T':
958           case 't':
959           case 'U':
960           case 'u':
961           case 'V':
962           case 'v':
963           case 'W':
964           case 'w':
965           case 'X':
966           case 'x':
967           case 'Y':
968           case 'y':
969           case 'Z':
970           case 'z':
971             // System.out.println(lastSS);
972             Color nonCanColor = getNotCanonicalColor(lastSS);
973             drawNotCanonicalAnnot(g, nonCanColor, row_annotations, lastSSX,
974                     x, y, iconOffset, startRes, column, validRes, validEnd);
975             break;
976           default:
977             drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset,
978                     startRes, column, validRes, validEnd);
979             break;
980           }
981         }
982
983         if (row.graph > 0 && row.graphHeight > 0)
984         {
985           if (row.graph == AlignmentAnnotation.LINE_GRAPH)
986           {
987             if (row.graphGroup > -1 && !graphGroupDrawn.get(row.graphGroup))
988             {
989               // TODO: JAL-1291 revise rendering model so the graphGroup map is
990               // computed efficiently for all visible labels
991               float groupmax = -999999, groupmin = 9999999;
992               for (int gg = 0; gg < aa.length; gg++)
993               {
994                 if (aa[gg].graphGroup != row.graphGroup)
995                 {
996                   continue;
997                 }
998
999                 if (aa[gg] != row)
1000                 {
1001                   aa[gg].visible = false;
1002                 }
1003                 if (aa[gg].graphMax > groupmax)
1004                 {
1005                   groupmax = aa[gg].graphMax;
1006                 }
1007                 if (aa[gg].graphMin < groupmin)
1008                 {
1009                   groupmin = aa[gg].graphMin;
1010                 }
1011               }
1012
1013               for (int gg = 0; gg < aa.length; gg++)
1014               {
1015                 if (aa[gg].graphGroup == row.graphGroup)
1016                 {
1017                   drawLineGraph(g, aa[gg], aa[gg].annotations, startRes,
1018                           endRes, y, groupmin, groupmax, row.graphHeight);
1019                 }
1020               }
1021
1022               graphGroupDrawn.set(row.graphGroup);
1023             }
1024             else
1025             {
1026               drawLineGraph(g, row, row_annotations, startRes, endRes, y,
1027                       row.graphMin, row.graphMax, row.graphHeight);
1028             }
1029           }
1030           else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
1031           {
1032             drawBarGraph(g, row, row_annotations, startRes, endRes,
1033                     row.graphMin, row.graphMax, y, renderHistogram,
1034                     renderProfile, normaliseProfile);
1035           }
1036         }
1037       }
1038       else
1039       {
1040         if (clipst && !clipend)
1041         {
1042           clipend = true;
1043         }
1044       }// end if_in_visible_region
1045       if (row.graph > 0 && row.hasText)
1046       {
1047         y += charHeight;
1048       }
1049
1050       if (row.graph == 0)
1051       {
1052         y += aa[i].height;
1053       }
1054     }
1055     if (debugRedraw)
1056     {
1057       if (canClip)
1058       {
1059         if (clipst)
1060         {
1061           System.err.println("Start clip at : " + yfrom + " (index " + f_i
1062                   + ")");
1063         }
1064         if (clipend)
1065         {
1066           System.err.println("End clip at : " + yto + " (index " + f_to
1067                   + ")");
1068         }
1069       }
1070       ;
1071       System.err.println("Annotation Rendering time:"
1072               + (System.currentTimeMillis() - stime));
1073     }
1074     ;
1075
1076     return !usedFaded;
1077   }
1078
1079   public static final Color GLYPHLINE_COLOR = Color.gray;
1080
1081   public static final Color SHEET_COLOUR = Color.green;
1082
1083   public static final Color HELIX_COLOUR = Color.red;
1084
1085   public static final Color STEM_COLOUR = Color.blue;
1086
1087   private Color sdNOTCANONICAL_COLOUR;
1088
1089   void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
1090           int y, int iconOffset, int startRes, int column,
1091           boolean validRes, boolean validEnd)
1092   {
1093     g.setColor(GLYPHLINE_COLOR);
1094     g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2);
1095   }
1096
1097   void drawSheetAnnot(Graphics g, Annotation[] row,
1098
1099   int lastSSX, int x, int y, int iconOffset, int startRes, int column,
1100           boolean validRes, boolean validEnd)
1101   {
1102     g.setColor(SHEET_COLOUR);
1103
1104     if (!validEnd || !validRes || row == null || row[column] == null
1105             || row[column].secondaryStructure != 'E')
1106     {
1107       g.fillRect(lastSSX, y + 4 + iconOffset,
1108               (x * charWidth) - lastSSX - 4, 7);
1109       g.fillPolygon(new int[] { (x * charWidth) - 4, (x * charWidth) - 4,
1110           (x * charWidth) }, new int[] { y + iconOffset,
1111           y + 14 + iconOffset, y + 7 + iconOffset }, 3);
1112     }
1113     else
1114     {
1115       g.fillRect(lastSSX, y + 4 + iconOffset,
1116               (x + 1) * charWidth - lastSSX, 7);
1117     }
1118
1119   }
1120
1121   void drawHelixAnnot(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(HELIX_COLOUR);
1126
1127     int sCol = (lastSSX / charWidth) + startRes;
1128     int x1 = lastSSX;
1129     int x2 = (x * charWidth);
1130
1131     if (MAC)
1132     {
1133       int ofs = charWidth / 2;
1134       // Off by 1 offset when drawing rects and ovals
1135       // to offscreen image on the MAC
1136       g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8);
1137       if (sCol == 0 || row[sCol - 1] == null
1138               || row[sCol - 1].secondaryStructure != 'H')
1139       {
1140       }
1141       else
1142       {
1143         // g.setColor(Color.orange);
1144         g.fillRoundRect(lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8,
1145                 0, 0);
1146       }
1147       if (!validRes || row[column] == null
1148               || row[column].secondaryStructure != 'H')
1149       {
1150
1151       }
1152       else
1153       {
1154         // g.setColor(Color.magenta);
1155         g.fillRoundRect(lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs
1156                 + 1, 8, 0, 0);
1157
1158       }
1159
1160       return;
1161     }
1162
1163     if (sCol == 0 || row[sCol - 1] == null
1164             || row[sCol - 1].secondaryStructure != 'H')
1165     {
1166       g.fillArc(lastSSX, y + 4 + iconOffset, charWidth, 8, 90, 180);
1167       x1 += charWidth / 2;
1168     }
1169
1170     if (!validRes || row[column] == null
1171             || row[column].secondaryStructure != 'H')
1172     {
1173       g.fillArc((x * charWidth) - charWidth, y + 4 + iconOffset, charWidth,
1174               8, 270, 180);
1175       x2 -= charWidth / 2;
1176     }
1177
1178     g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
1179   }
1180
1181   void drawLineGraph(Graphics g, AlignmentAnnotation _aa,
1182           Annotation[] aa_annotations, int sRes, int eRes, int y,
1183           float min, float max, int graphHeight)
1184   {
1185     if (sRes > aa_annotations.length)
1186     {
1187       return;
1188     }
1189
1190     int x = 0;
1191
1192     // Adjustment for fastpaint to left
1193     if (eRes < endRes)
1194     {
1195       eRes++;
1196     }
1197
1198     eRes = Math.min(eRes, aa_annotations.length);
1199
1200     if (sRes == 0)
1201     {
1202       x++;
1203     }
1204
1205     int y1 = y, y2 = y;
1206     float range = max - min;
1207
1208     // //Draw origin
1209     if (min < 0)
1210     {
1211       y2 = y - (int) ((0 - min / range) * graphHeight);
1212     }
1213
1214     g.setColor(Color.gray);
1215     g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2);
1216
1217     eRes = Math.min(eRes, aa_annotations.length);
1218
1219     int column;
1220     int aaMax = aa_annotations.length - 1;
1221
1222     while (x < eRes - sRes)
1223     {
1224       column = sRes + x;
1225       if (hasHiddenColumns)
1226       {
1227         column = columnSelection.adjustForHiddenColumns(column);
1228       }
1229
1230       if (column > aaMax)
1231       {
1232         break;
1233       }
1234
1235       if (aa_annotations[column] == null
1236               || aa_annotations[column - 1] == null)
1237       {
1238         x++;
1239         continue;
1240       }
1241
1242       if (aa_annotations[column].colour == null)
1243       {
1244         g.setColor(Color.black);
1245       }
1246       else
1247       {
1248         g.setColor(aa_annotations[column].colour);
1249       }
1250
1251       y1 = y
1252               - (int) (((aa_annotations[column - 1].value - min) / range) * graphHeight);
1253       y2 = y
1254               - (int) (((aa_annotations[column].value - min) / range) * graphHeight);
1255
1256       g.drawLine(x * charWidth - charWidth / 2, y1, x * charWidth
1257               + charWidth / 2, y2);
1258       x++;
1259     }
1260
1261     if (_aa.threshold != null)
1262     {
1263       g.setColor(_aa.threshold.colour);
1264       Graphics2D g2 = (Graphics2D) g;
1265       g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
1266               BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
1267
1268       y2 = (int) (y - ((_aa.threshold.value - min) / range) * graphHeight);
1269       g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
1270       g2.setStroke(new BasicStroke());
1271     }
1272   }
1273
1274   void drawBarGraph(Graphics g, AlignmentAnnotation _aa,
1275           Annotation[] aa_annotations, int sRes, int eRes, float min,
1276           float max, int y, boolean renderHistogram, boolean renderProfile,
1277           boolean normaliseProfile)
1278   {
1279     if (sRes > aa_annotations.length)
1280     {
1281       return;
1282     }
1283     Font ofont = g.getFont();
1284     eRes = Math.min(eRes, aa_annotations.length);
1285
1286     int x = 0, y1 = y, y2 = y;
1287
1288     float range = max - min;
1289
1290     if (min < 0)
1291     {
1292       y2 = y - (int) ((0 - min / (range)) * _aa.graphHeight);
1293     }
1294
1295     g.setColor(Color.gray);
1296
1297     g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
1298
1299     int column;
1300     int aaMax = aa_annotations.length - 1;
1301     while (x < eRes - sRes)
1302     {
1303       column = sRes + x;
1304       if (hasHiddenColumns)
1305       {
1306         column = columnSelection.adjustForHiddenColumns(column);
1307       }
1308
1309       if (column > aaMax)
1310       {
1311         break;
1312       }
1313
1314       if (aa_annotations[column] == null)
1315       {
1316         x++;
1317         continue;
1318       }
1319       if (aa_annotations[column].colour == null)
1320       {
1321         g.setColor(Color.black);
1322       }
1323       else
1324       {
1325         g.setColor(aa_annotations[column].colour);
1326       }
1327
1328       y1 = y
1329               - (int) (((aa_annotations[column].value - min) / (range)) * _aa.graphHeight);
1330
1331       if (renderHistogram)
1332       {
1333         if (y1 - y2 > 0)
1334         {
1335           g.fillRect(x * charWidth, y2, charWidth, y1 - y2);
1336         }
1337         else
1338         {
1339           g.fillRect(x * charWidth, y1, charWidth, y2 - y1);
1340         }
1341       }
1342       // draw profile if available
1343       if (renderProfile)
1344       {
1345
1346         /*
1347          * {profile type, #values, total count, char1, pct1, char2, pct2...}
1348          */
1349         int profl[] = getProfileFor(_aa, column);
1350
1351         // just try to draw the logo if profl is not null
1352         if (profl != null && profl[2] != 0)
1353         {
1354           boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
1355           boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
1356           float ht = normaliseProfile ? y - _aa.graphHeight : y1;
1357           double htn = normaliseProfile ? _aa.graphHeight : (y2 - y1);// aa.graphHeight;
1358           double hght;
1359           float wdth;
1360           double ht2 = 0;
1361           char[] dc;
1362
1363           /**
1364            * Render a single base for a sequence profile, a base pair for
1365            * structure profile, and a triplet for a cdna profile
1366            */
1367           dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
1368
1369           LineMetrics lm = g.getFontMetrics(ofont).getLineMetrics("Q", g);
1370           double scale = 1f / (normaliseProfile ? profl[2] : 100f);
1371           float ofontHeight = 1f / lm.getAscent();// magnify to fill box
1372           double scl = 0.0;
1373
1374           /*
1375            * Traverse the character(s)/percentage data in the array
1376            */
1377           int c = 3;
1378           int valuesProcessed = 0;
1379           // profl[1] is the number of values in the profile
1380           while (valuesProcessed < profl[1])
1381           {
1382             if (isStructureProfile)
1383             {
1384               // todo can we encode a structure pair as an int, like codons?
1385               dc[0] = (char) profl[c++];
1386               dc[1] = (char) profl[c++];
1387             }
1388             else if (isCdnaProfile)
1389             {
1390               dc = CodingUtils.decodeCodon(profl[c++]);
1391             }
1392             else
1393             {
1394               dc[0] = (char) profl[c++];
1395             }
1396
1397             wdth = charWidth;
1398             wdth /= fm.charsWidth(dc, 0, dc.length);
1399
1400             ht += scl;
1401             // next profl[] position is profile % for the character(s)
1402             scl = htn * scale * profl[c++];
1403             lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics()
1404                     .getFontRenderContext());
1405             Font font = ofont.deriveFont(AffineTransform.getScaleInstance(
1406                     wdth, scl / lm.getAscent()));
1407             g.setFont(font);
1408             lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g);
1409
1410             // Debug - render boxes around characters
1411             // g.setColor(Color.red);
1412             // g.drawRect(x*av.charWidth, (int)ht, av.charWidth,
1413             // (int)(scl));
1414             // g.setColor(profcolour.findColour(dc[0]).darker());
1415
1416             /*
1417              * Set character colour as per alignment colour scheme; use the
1418              * codon translation if a cDNA profile
1419              */
1420             Color colour = null;
1421             if (isCdnaProfile)
1422             {
1423               final String codonTranslation = ResidueProperties
1424                       .codonTranslate(new String(dc));
1425               colour = profcolour.findColour(codonTranslation.charAt(0),
1426                       column, null);
1427             }
1428             else
1429             {
1430               colour = profcolour.findColour(dc[0], column, null);
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 }