JAL-1645 source formatting and organise imports
[jalview.git] / src / jalview / viewmodel / seqfeatures / FeatureRendererModel.java
1 package jalview.viewmodel.seqfeatures;
2
3 import jalview.api.AlignViewportI;
4 import jalview.api.FeaturesDisplayedI;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.SequenceFeature;
7 import jalview.datamodel.SequenceI;
8 import jalview.renderer.seqfeatures.FeatureRenderer;
9 import jalview.schemes.GraduatedColor;
10 import jalview.viewmodel.AlignmentViewport;
11
12 import java.awt.Color;
13 import java.beans.PropertyChangeListener;
14 import java.beans.PropertyChangeSupport;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.Hashtable;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22 import java.util.concurrent.ConcurrentHashMap;
23
24 public abstract class FeatureRendererModel implements
25         jalview.api.FeatureRenderer
26 {
27
28   /**
29    * global transparency for feature
30    */
31   protected float transparency = 1.0f;
32
33   protected Map<String, Object> featureColours = new ConcurrentHashMap<String, Object>();
34
35   protected Map<String, Boolean> featureGroups = new ConcurrentHashMap<String, Boolean>();
36
37   protected Object currentColour;
38
39   protected String[] renderOrder;
40
41   protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
42           this);
43
44   protected AlignmentViewport av;
45
46   public AlignViewportI getViewport()
47   {
48     return av;
49   }
50
51   public FeatureRendererSettings getSettings()
52   {
53     return new FeatureRendererSettings(this);
54   }
55
56   public void transferSettings(FeatureRendererSettings fr)
57   {
58     this.renderOrder = fr.renderOrder;
59     this.featureGroups = fr.featureGroups;
60     this.featureColours = fr.featureColours;
61     this.transparency = fr.transparency;
62     this.featureOrder = fr.featureOrder;
63   }
64
65   /**
66    * update from another feature renderer
67    * 
68    * @param fr
69    *          settings to copy
70    */
71   public void transferSettings(jalview.api.FeatureRenderer _fr)
72   {
73     FeatureRenderer fr = (FeatureRenderer) _fr;
74     FeatureRendererSettings frs = new FeatureRendererSettings(fr);
75     this.renderOrder = frs.renderOrder;
76     this.featureGroups = frs.featureGroups;
77     this.featureColours = frs.featureColours;
78     this.transparency = frs.transparency;
79     this.featureOrder = frs.featureOrder;
80     if (av != null && av != fr.getViewport())
81     {
82       // copy over the displayed feature settings
83       if (_fr.getFeaturesDisplayed() != null)
84       {
85         FeaturesDisplayedI fd = getFeaturesDisplayed();
86         if (fd == null)
87         {
88           setFeaturesDisplayedFrom(_fr.getFeaturesDisplayed());
89         }
90         else
91         {
92           synchronized (fd)
93           {
94             fd.clear();
95             java.util.Iterator<String> fdisp = _fr.getFeaturesDisplayed()
96                     .getVisibleFeatures();
97             while (fdisp.hasNext())
98             {
99               fd.setVisible(fdisp.next());
100             }
101           }
102         }
103       }
104     }
105   }
106
107   public void setFeaturesDisplayedFrom(FeaturesDisplayedI featuresDisplayed)
108   {
109     av.setFeaturesDisplayed(new FeaturesDisplayed(featuresDisplayed));
110   }
111
112   @Override
113   public void setVisible(String featureType)
114   {
115     FeaturesDisplayedI fdi = av.getFeaturesDisplayed();
116     if (fdi == null)
117     {
118       av.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
119     }
120     if (!fdi.isRegistered(featureType))
121     {
122       pushFeatureType(Arrays.asList(new String[] { featureType }));
123     }
124     fdi.setVisible(featureType);
125   }
126
127   @Override
128   public void setAllVisible(List<String> featureTypes)
129   {
130     FeaturesDisplayedI fdi = av.getFeaturesDisplayed();
131     if (fdi == null)
132     {
133       av.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
134     }
135     List<String> nft = new ArrayList<String>();
136     for (String featureType : featureTypes)
137     {
138       if (!fdi.isRegistered(featureType))
139       {
140         nft.add(featureType);
141       }
142     }
143     if (nft.size() > 0)
144     {
145       pushFeatureType(nft);
146     }
147     fdi.setAllVisible(featureTypes);
148   }
149
150   /**
151    * push a set of new types onto the render order stack. Note - this is a
152    * direct mechanism rather than the one employed in updateRenderOrder
153    * 
154    * @param types
155    */
156   private void pushFeatureType(List<String> types)
157   {
158
159     int ts = types.size();
160     String neworder[] = new String[(renderOrder == null ? 0
161             : renderOrder.length) + ts];
162     types.toArray(neworder);
163     if (renderOrder != null)
164     {
165       System.arraycopy(neworder, 0, neworder, renderOrder.length, ts);
166       System.arraycopy(renderOrder, 0, neworder, 0, renderOrder.length);
167     }
168     renderOrder = neworder;
169   }
170
171   protected Hashtable minmax = new Hashtable();
172
173   public Hashtable getMinMax()
174   {
175     return minmax;
176   }
177
178   /**
179    * normalise a score against the max/min bounds for the feature type.
180    * 
181    * @param sequenceFeature
182    * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
183    *         (0-255) value.
184    */
185   protected final byte[] normaliseScore(SequenceFeature sequenceFeature)
186   {
187     float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
188     final byte[] r = new byte[] { 0, (byte) 255 };
189     if (mm != null)
190     {
191       if (r[0] != 0 || mm[0] < 0.0)
192       {
193         r[0] = 1;
194         r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
195       }
196       else
197       {
198         r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
199       }
200     }
201     return r;
202   }
203
204   boolean newFeatureAdded = false;
205
206   boolean findingFeatures = false;
207
208   protected boolean updateFeatures()
209   {
210     if (av.getFeaturesDisplayed() == null || renderOrder == null
211             || newFeatureAdded)
212     {
213       findAllFeatures();
214       if (av.getFeaturesDisplayed().getVisibleFeatureCount() < 1)
215       {
216         return false;
217       }
218     }
219     // TODO: decide if we should check for the visible feature count first
220     return true;
221   }
222
223   /**
224    * search the alignment for all new features, give them a colour and display
225    * them. Then fires a PropertyChangeEvent on the changeSupport object.
226    * 
227    */
228   protected void findAllFeatures()
229   {
230     synchronized (firing)
231     {
232       if (firing.equals(Boolean.FALSE))
233       {
234         firing = Boolean.TRUE;
235         findAllFeatures(true); // add all new features as visible
236         changeSupport.firePropertyChange("changeSupport", null, null);
237         firing = Boolean.FALSE;
238       }
239     }
240   }
241
242   @Override
243   public List<SequenceFeature> findFeaturesAtRes(SequenceI sequence, int res)
244   {
245     ArrayList<SequenceFeature> tmp = new ArrayList<SequenceFeature>();
246     SequenceFeature[] features = sequence.getSequenceFeatures();
247
248     if (features != null)
249     {
250       for (int i = 0; i < features.length; i++)
251       {
252         if (!av.areFeaturesDisplayed()
253                 || !av.getFeaturesDisplayed().isVisible(
254                         features[i].getType()))
255         {
256           continue;
257         }
258
259         if (features[i].featureGroup != null
260                 && featureGroups != null
261                 && featureGroups.containsKey(features[i].featureGroup)
262                 && !featureGroups.get(features[i].featureGroup)
263                         .booleanValue())
264         {
265           continue;
266         }
267
268         if ((features[i].getBegin() <= res)
269                 && (features[i].getEnd() >= res))
270         {
271           tmp.add(features[i]);
272         }
273       }
274     }
275     return tmp;
276   }
277
278   /**
279    * Searches alignment for all features and updates colours
280    * 
281    * @param newMadeVisible
282    *          if true newly added feature types will be rendered immediatly
283    *          TODO: check to see if this method should actually be proxied so
284    *          repaint events can be propagated by the renderer code
285    */
286   @Override
287   public synchronized void findAllFeatures(boolean newMadeVisible)
288   {
289     newFeatureAdded = false;
290
291     if (findingFeatures)
292     {
293       newFeatureAdded = true;
294       return;
295     }
296
297     findingFeatures = true;
298     if (av.getFeaturesDisplayed() == null)
299     {
300       av.setFeaturesDisplayed(new FeaturesDisplayed());
301     }
302     FeaturesDisplayedI featuresDisplayed = av.getFeaturesDisplayed();
303
304     ArrayList<String> allfeatures = new ArrayList<String>();
305     ArrayList<String> oldfeatures = new ArrayList<String>();
306     if (renderOrder != null)
307     {
308       for (int i = 0; i < renderOrder.length; i++)
309       {
310         if (renderOrder[i] != null)
311         {
312           oldfeatures.add(renderOrder[i]);
313         }
314       }
315     }
316     if (minmax == null)
317     {
318       minmax = new Hashtable();
319     }
320     AlignmentI alignment = av.getAlignment();
321     for (int i = 0; i < alignment.getHeight(); i++)
322     {
323       SequenceI asq = alignment.getSequenceAt(i);
324       SequenceFeature[] features = asq.getSequenceFeatures();
325
326       if (features == null)
327       {
328         continue;
329       }
330
331       int index = 0;
332       while (index < features.length)
333       {
334         if (!featuresDisplayed.isRegistered(features[index].getType()))
335         {
336           String fgrp = features[index].getFeatureGroup();
337           if (fgrp != null)
338           {
339             Boolean groupDisplayed = featureGroups.get(fgrp);
340             if (groupDisplayed == null)
341             {
342               groupDisplayed = Boolean.valueOf(newMadeVisible);
343               featureGroups.put(fgrp, groupDisplayed);
344             }
345             if (!groupDisplayed.booleanValue())
346             {
347               index++;
348               continue;
349             }
350           }
351           if (!(features[index].begin == 0 && features[index].end == 0))
352           {
353             // If beginning and end are 0, the feature is for the whole sequence
354             // and we don't want to render the feature in the normal way
355
356             if (newMadeVisible
357                     && !oldfeatures.contains(features[index].getType()))
358             {
359               // this is a new feature type on the alignment. Mark it for
360               // display.
361               featuresDisplayed.setVisible(features[index].getType());
362               setOrder(features[index].getType(), 0);
363             }
364           }
365         }
366         if (!allfeatures.contains(features[index].getType()))
367         {
368           allfeatures.add(features[index].getType());
369         }
370         if (!Float.isNaN(features[index].score))
371         {
372           int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
373           float[][] mm = (float[][]) minmax.get(features[index].getType());
374           if (mm == null)
375           {
376             mm = new float[][] { null, null };
377             minmax.put(features[index].getType(), mm);
378           }
379           if (mm[nonpos] == null)
380           {
381             mm[nonpos] = new float[] { features[index].score,
382                 features[index].score };
383
384           }
385           else
386           {
387             if (mm[nonpos][0] > features[index].score)
388             {
389               mm[nonpos][0] = features[index].score;
390             }
391             if (mm[nonpos][1] < features[index].score)
392             {
393               mm[nonpos][1] = features[index].score;
394             }
395           }
396         }
397         index++;
398       }
399     }
400     updateRenderOrder(allfeatures);
401     findingFeatures = false;
402   }
403
404   protected Boolean firing = Boolean.FALSE;
405
406   /**
407    * replaces the current renderOrder with the unordered features in
408    * allfeatures. The ordering of any types in both renderOrder and allfeatures
409    * is preserved, and all new feature types are rendered on top of the existing
410    * types, in the order given by getOrder or the order given in allFeatures.
411    * Note. this operates directly on the featureOrder hash for efficiency. TODO:
412    * eliminate the float storage for computing/recalling the persistent ordering
413    * New Cability: updates min/max for colourscheme range if its dynamic
414    * 
415    * @param allFeatures
416    */
417   private void updateRenderOrder(List<String> allFeatures)
418   {
419     List<String> allfeatures = new ArrayList<String>(allFeatures);
420     String[] oldRender = renderOrder;
421     renderOrder = new String[allfeatures.size()];
422     Object mmrange, fc = null;
423     boolean initOrders = (featureOrder == null);
424     int opos = 0;
425     if (oldRender != null && oldRender.length > 0)
426     {
427       for (int j = 0; j < oldRender.length; j++)
428       {
429         if (oldRender[j] != null)
430         {
431           if (initOrders)
432           {
433             setOrder(oldRender[j], (1 - (1 + (float) j) / oldRender.length));
434           }
435           if (allfeatures.contains(oldRender[j]))
436           {
437             renderOrder[opos++] = oldRender[j]; // existing features always
438             // appear below new features
439             allfeatures.remove(oldRender[j]);
440             if (minmax != null)
441             {
442               mmrange = minmax.get(oldRender[j]);
443               if (mmrange != null)
444               {
445                 fc = featureColours.get(oldRender[j]);
446                 if (fc != null && fc instanceof GraduatedColor
447                         && ((GraduatedColor) fc).isAutoScale())
448                 {
449                   ((GraduatedColor) fc).updateBounds(
450                           ((float[][]) mmrange)[0][0],
451                           ((float[][]) mmrange)[0][1]);
452                 }
453               }
454             }
455           }
456         }
457       }
458     }
459     if (allfeatures.size() == 0)
460     {
461       // no new features - leave order unchanged.
462       return;
463     }
464     int i = allfeatures.size() - 1;
465     int iSize = i;
466     boolean sort = false;
467     String[] newf = new String[allfeatures.size()];
468     float[] sortOrder = new float[allfeatures.size()];
469     for (String newfeat : allfeatures)
470     {
471       newf[i] = newfeat;
472       if (minmax != null)
473       {
474         // update from new features minmax if necessary
475         mmrange = minmax.get(newf[i]);
476         if (mmrange != null)
477         {
478           fc = featureColours.get(newf[i]);
479           if (fc != null && fc instanceof GraduatedColor
480                   && ((GraduatedColor) fc).isAutoScale())
481           {
482             ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
483                     ((float[][]) mmrange)[0][1]);
484           }
485         }
486       }
487       if (initOrders || !featureOrder.containsKey(newf[i]))
488       {
489         int denom = initOrders ? allfeatures.size() : featureOrder.size();
490         // new unordered feature - compute persistent ordering at head of
491         // existing features.
492         setOrder(newf[i], i / (float) denom);
493       }
494       // set order from newly found feature from persisted ordering.
495       sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
496       if (i < iSize)
497       {
498         // only sort if we need to
499         sort = sort || sortOrder[i] > sortOrder[i + 1];
500       }
501       i--;
502     }
503     if (iSize > 1 && sort)
504     {
505       jalview.util.QuickSort.sort(sortOrder, newf);
506     }
507     sortOrder = null;
508     System.arraycopy(newf, 0, renderOrder, opos, newf.length);
509   }
510
511   /**
512    * get a feature style object for the given type string. Creates a
513    * java.awt.Color for a featureType with no existing colourscheme. TODO:
514    * replace return type with object implementing standard abstract colour/style
515    * interface
516    * 
517    * @param featureType
518    * @return java.awt.Color or GraduatedColor
519    */
520   public Object getFeatureStyle(String featureType)
521   {
522     Object fc = featureColours.get(featureType);
523     if (fc == null)
524     {
525       jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
526       Color col = ucs.createColourFromName(featureType);
527       featureColours.put(featureType, fc = col);
528     }
529     return fc;
530   }
531
532   /**
533    * return a nominal colour for this feature
534    * 
535    * @param featureType
536    * @return standard color, or maximum colour for graduated colourscheme
537    */
538   public Color getColour(String featureType)
539   {
540     Object fc = getFeatureStyle(featureType);
541
542     if (fc instanceof Color)
543     {
544       return (Color) fc;
545     }
546     else
547     {
548       if (fc instanceof GraduatedColor)
549       {
550         return ((GraduatedColor) fc).getMaxColor();
551       }
552     }
553     throw new Error("Implementation Error: Unrecognised render object "
554             + fc.getClass() + " for features of type " + featureType);
555   }
556
557   /**
558    * calculate the render colour for a specific feature using current feature
559    * settings.
560    * 
561    * @param feature
562    * @return render colour for the given feature
563    */
564   public Color getColour(SequenceFeature feature)
565   {
566     Object fc = getFeatureStyle(feature.getType());
567     if (fc instanceof Color)
568     {
569       return (Color) fc;
570     }
571     else
572     {
573       if (fc instanceof GraduatedColor)
574       {
575         return ((GraduatedColor) fc).findColor(feature);
576       }
577     }
578     throw new Error("Implementation Error: Unrecognised render object "
579             + fc.getClass() + " for features of type " + feature.getType());
580   }
581
582   protected boolean showFeature(SequenceFeature sequenceFeature)
583   {
584     Object fc = getFeatureStyle(sequenceFeature.type);
585     if (fc instanceof GraduatedColor)
586     {
587       return ((GraduatedColor) fc).isColored(sequenceFeature);
588     }
589     else
590     {
591       return true;
592     }
593   }
594
595   protected boolean showFeatureOfType(String type)
596   {
597     return av.getFeaturesDisplayed().isVisible(type);
598   }
599
600   public void setColour(String featureType, Object col)
601   {
602     // overwrite
603     // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof
604     // GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
605     // Object c = featureColours.get(featureType);
606     // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
607     // !((GraduatedColor)c).getMaxColor().equals(_col)))
608     {
609       featureColours.put(featureType, col);
610     }
611   }
612
613   public void setTransparency(float value)
614   {
615     transparency = value;
616   }
617
618   public float getTransparency()
619   {
620     return transparency;
621   }
622
623   Map featureOrder = null;
624
625   /**
626    * analogous to colour - store a normalized ordering for all feature types in
627    * this rendering context.
628    * 
629    * @param type
630    *          Feature type string
631    * @param position
632    *          normalized priority - 0 means always appears on top, 1 means
633    *          always last.
634    */
635   public float setOrder(String type, float position)
636   {
637     if (featureOrder == null)
638     {
639       featureOrder = new Hashtable();
640     }
641     featureOrder.put(type, new Float(position));
642     return position;
643   }
644
645   /**
646    * get the global priority (0 (top) to 1 (bottom))
647    * 
648    * @param type
649    * @return [0,1] or -1 for a type without a priority
650    */
651   public float getOrder(String type)
652   {
653     if (featureOrder != null)
654     {
655       if (featureOrder.containsKey(type))
656       {
657         return ((Float) featureOrder.get(type)).floatValue();
658       }
659     }
660     return -1;
661   }
662
663   @Override
664   public Map<String, Object> getFeatureColours()
665   {
666     return new ConcurrentHashMap<String, Object>(featureColours);
667   }
668
669   /**
670    * Replace current ordering with new ordering
671    * 
672    * @param data
673    *          { String(Type), Colour(Type), Boolean(Displayed) }
674    */
675   public void setFeaturePriority(Object[][] data)
676   {
677     setFeaturePriority(data, true);
678   }
679
680   /**
681    * 
682    * @param data
683    *          { String(Type), Colour(Type), Boolean(Displayed) }
684    * @param visibleNew
685    *          when true current featureDisplay list will be cleared
686    */
687   public void setFeaturePriority(Object[][] data, boolean visibleNew)
688   {
689     FeaturesDisplayedI av_featuresdisplayed = null;
690     if (visibleNew)
691     {
692       if ((av_featuresdisplayed = av.getFeaturesDisplayed()) != null)
693       {
694         av.getFeaturesDisplayed().clear();
695       }
696       else
697       {
698         av.setFeaturesDisplayed(av_featuresdisplayed = new FeaturesDisplayed());
699       }
700     }
701     else
702     {
703       av_featuresdisplayed = av.getFeaturesDisplayed();
704     }
705     if (data == null)
706     {
707       return;
708     }
709     // The feature table will display high priority
710     // features at the top, but theses are the ones
711     // we need to render last, so invert the data
712     renderOrder = new String[data.length];
713
714     if (data.length > 0)
715     {
716       for (int i = 0; i < data.length; i++)
717       {
718         String type = data[i][0].toString();
719         setColour(type, data[i][1]); // todo : typesafety - feature color
720         // interface object
721         if (((Boolean) data[i][2]).booleanValue())
722         {
723           av_featuresdisplayed.setVisible(type);
724         }
725
726         renderOrder[data.length - i - 1] = type;
727       }
728     }
729
730   }
731
732   /**
733    * @param listener
734    * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
735    */
736   public void addPropertyChangeListener(PropertyChangeListener listener)
737   {
738     changeSupport.addPropertyChangeListener(listener);
739   }
740
741   /**
742    * @param listener
743    * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
744    */
745   public void removePropertyChangeListener(PropertyChangeListener listener)
746   {
747     changeSupport.removePropertyChangeListener(listener);
748   }
749
750   public Set getAllFeatureColours()
751   {
752     return featureColours.keySet();
753   }
754
755   public void clearRenderOrder()
756   {
757     renderOrder = null;
758   }
759
760   public boolean hasRenderOrder()
761   {
762     return renderOrder != null;
763   }
764
765   public List<String> getRenderOrder()
766   {
767     if (renderOrder == null)
768     {
769       return Arrays.asList(new String[] {});
770     }
771     return Arrays.asList(renderOrder);
772   }
773
774   public int getFeatureGroupsSize()
775   {
776     return featureGroups != null ? 0 : featureGroups.size();
777   }
778
779   @Override
780   public List<String> getFeatureGroups()
781   {
782     // conflict between applet and desktop - featureGroups returns the map in
783     // the desktop featureRenderer
784     return (featureGroups == null) ? Arrays.asList(new String[0]) : Arrays
785             .asList(featureGroups.keySet().toArray(new String[0]));
786   }
787
788   public boolean checkGroupVisibility(String group, boolean newGroupsVisible)
789   {
790     if (featureGroups == null)
791     {
792       // then an exception happens next..
793     }
794     if (featureGroups.containsKey(group))
795     {
796       return featureGroups.get(group).booleanValue();
797     }
798     if (newGroupsVisible)
799     {
800       featureGroups.put(group, new Boolean(true));
801       return true;
802     }
803     return false;
804   }
805
806   /**
807    * get visible or invisible groups
808    * 
809    * @param visible
810    *          true to return visible groups, false to return hidden ones.
811    * @return list of groups
812    */
813   @Override
814   public List getGroups(boolean visible)
815   {
816     if (featureGroups != null)
817     {
818       ArrayList gp = new ArrayList();
819
820       for (Object grp : featureGroups.keySet())
821       {
822         Boolean state = featureGroups.get(grp);
823         if (state.booleanValue() == visible)
824         {
825           gp.add(grp);
826         }
827       }
828       return gp;
829     }
830     return null;
831   }
832
833   @Override
834   public void setGroupVisibility(String group, boolean visible)
835   {
836     featureGroups.put(group, new Boolean(visible));
837   }
838
839   @Override
840   public void setGroupVisibility(List<String> toset, boolean visible)
841   {
842     if (toset != null && toset.size() > 0 && featureGroups != null)
843     {
844       boolean rdrw = false;
845       for (String gst : toset)
846       {
847         Boolean st = featureGroups.get(gst);
848         featureGroups.put(gst, new Boolean(visible));
849         if (st != null)
850         {
851           rdrw = rdrw || (visible != st.booleanValue());
852         }
853       }
854       if (rdrw)
855       {
856         // set local flag indicating redraw needed ?
857       }
858     }
859   }
860
861   @Override
862   public Hashtable getDisplayedFeatureCols()
863   {
864     Hashtable fcols = new Hashtable();
865     if (getViewport().getFeaturesDisplayed() == null)
866     {
867       return fcols;
868     }
869     Iterator<String> en = getViewport().getFeaturesDisplayed()
870             .getVisibleFeatures();
871     while (en.hasNext())
872     {
873       String col = en.next();
874       fcols.put(col, getColour(col));
875     }
876     return fcols;
877   }
878
879   @Override
880   public FeaturesDisplayedI getFeaturesDisplayed()
881   {
882     return av.getFeaturesDisplayed();
883   }
884
885   @Override
886   public String[] getDisplayedFeatureTypes()
887   {
888     String[] typ = null;
889     typ = getRenderOrder().toArray(new String[0]);
890     FeaturesDisplayedI feature_disp = av.getFeaturesDisplayed();
891     if (feature_disp != null)
892     {
893       synchronized (feature_disp)
894       {
895         for (int i = 0; i < typ.length; i++)
896         {
897           if (!feature_disp.isVisible(typ[i]))
898           {
899             typ[i] = null;
900           }
901         }
902       }
903     }
904     return typ;
905   }
906
907   @Override
908   public String[] getDisplayedFeatureGroups()
909   {
910     String[] gps = null;
911     ArrayList<String> _gps = new ArrayList<String>();
912     Iterator en = getFeatureGroups().iterator();
913     int g = 0;
914     boolean valid = false;
915     while (en.hasNext())
916     {
917       String gp = (String) en.next();
918       if (checkGroupVisibility(gp, false))
919       {
920         valid = true;
921         _gps.add(gp);
922       }
923       if (!valid)
924       {
925         return null;
926       }
927       else
928       {
929         gps = new String[_gps.size()];
930         _gps.toArray(gps);
931       }
932     }
933     return gps;
934   }
935
936 }