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