JAL-3184 class Javadoc added
[jalview.git] / src / jalview / viewmodel / seqfeatures / FeatureRendererSettings.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.FeatureColourI;
24 import jalview.datamodel.features.FeatureMatcherSetI;
25 import jalview.schemes.FeatureColour;
26
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.Map;
31 import java.util.concurrent.ConcurrentHashMap;
32
33 /**
34  * A data bean that holds
35  * <ul>
36  * <li>feature types and their render order</li>
37  * <li>feature groups and their visibility</li>
38  * <li>colour for each feature type</li>
39  * <li>filters (if any) for each feature type</li>
40  * <li>feature colour transparency</li>
41  * </ul>
42  * Note that feature type visibility settings are not held here.
43  */
44 public class FeatureRendererSettings implements Cloneable
45 {
46   String[] renderOrder;
47
48   /*
49    * map of {groupName, isDisplayed}
50    */
51   Map<String, Boolean> featureGroups;
52
53   /*
54    * map of {featureType, colourScheme}
55    */
56   Map<String, FeatureColourI> featureColours;
57
58   /*
59    * map of {featureType, filters}
60    */
61   Map<String, FeatureMatcherSetI> featureFilters;
62
63   float transparency;
64
65   Map<String, Float> featureOrder;
66
67   public FeatureRendererSettings(String[] renderOrder,
68           Map<String, Boolean> featureGroups,
69           Map<String, FeatureColourI> featureColours, float transparency,
70           Map<String, Float> featureOrder)
71   {
72     super();
73     this.renderOrder = Arrays.copyOf(renderOrder, renderOrder.length);
74     this.featureGroups = new ConcurrentHashMap<>(
75             featureGroups);
76     this.featureColours = new ConcurrentHashMap<>(
77             featureColours);
78     this.transparency = transparency;
79     this.featureOrder = new ConcurrentHashMap<>(featureOrder);
80   }
81
82   /**
83    * create an independent instance of the feature renderer settings
84    * 
85    * @param fr
86    */
87   public FeatureRendererSettings(
88           jalview.viewmodel.seqfeatures.FeatureRendererModel fr)
89   {
90     renderOrder = null;
91     featureGroups = new ConcurrentHashMap<>();
92     featureColours = new ConcurrentHashMap<>();
93     featureFilters = new HashMap<>();
94     featureOrder = new ConcurrentHashMap<>();
95
96     if (fr.renderOrder != null)
97     {
98       this.renderOrder = new String[fr.renderOrder.length];
99       System.arraycopy(fr.renderOrder, 0, renderOrder, 0,
100               fr.renderOrder.length);
101     }
102     if (fr.featureGroups != null)
103     {
104       this.featureGroups = new ConcurrentHashMap<>(
105               fr.featureGroups);
106     }
107     if (fr.featureColours != null)
108     {
109       this.featureColours = new ConcurrentHashMap<>(
110               fr.featureColours);
111     }
112     Iterator<String> en = fr.featureColours.keySet().iterator();
113     while (en.hasNext())
114     {
115       String next = en.next();
116       FeatureColourI val = featureColours.get(next);
117       // if (val instanceof GraduatedColor)
118       if (val.isGraduatedColour() || val.isColourByLabel()) // why this test?
119       {
120         featureColours.put(next, new FeatureColour((FeatureColour) val));
121       }
122     }
123
124     if (fr.featureFilters != null)
125     {
126       this.featureFilters.putAll(fr.featureFilters);
127     }
128
129     this.transparency = fr.transparency;
130     if (fr.featureOrder != null)
131     {
132       this.featureOrder = new ConcurrentHashMap<>(
133               fr.featureOrder);
134     }
135   }
136 }