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