cd6f51b11f27f1b90f69d36b17535938af92bd73
[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
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   /**
68    * Constructor
69    * 
70    * @param renderOrder
71    * @param featureGroups
72    * @param featureColours
73    * @param transparency
74    * @param featureOrder
75    * @param filters
76    */
77   public FeatureRendererSettings(String[] renderOrder,
78           Map<String, Boolean> featureGroups,
79           Map<String, FeatureColourI> featureColours, float transparency,
80           Map<String, Float> featureOrder,
81           Map<String, FeatureMatcherSetI> filters)
82   {
83     super();
84     this.renderOrder = Arrays.copyOf(renderOrder, renderOrder.length);
85     this.featureGroups = new ConcurrentHashMap<>(
86             featureGroups);
87     this.featureColours = new ConcurrentHashMap<>(
88             featureColours);
89     this.transparency = transparency;
90     this.featureOrder = new ConcurrentHashMap<>(featureOrder);
91     featureFilters = filters;
92   }
93
94   /**
95    * create an independent instance of the feature renderer settings
96    * 
97    * @param fr
98    */
99   public FeatureRendererSettings(
100           jalview.viewmodel.seqfeatures.FeatureRendererModel fr)
101   {
102     renderOrder = null;
103     featureGroups = new ConcurrentHashMap<>();
104     featureColours = new ConcurrentHashMap<>();
105     featureFilters = new HashMap<>();
106     featureOrder = new ConcurrentHashMap<>();
107
108     if (fr.renderOrder != null)
109     {
110       this.renderOrder = new String[fr.renderOrder.length];
111       System.arraycopy(fr.renderOrder, 0, renderOrder, 0,
112               fr.renderOrder.length);
113     }
114     if (fr.featureGroups != null)
115     {
116       this.featureGroups = new ConcurrentHashMap<>(
117               fr.featureGroups);
118     }
119     if (fr.featureColours != null)
120     {
121       this.featureColours = new ConcurrentHashMap<>(
122               fr.featureColours);
123     }
124     Iterator<String> en = fr.featureColours.keySet().iterator();
125     while (en.hasNext())
126     {
127       String next = en.next();
128       FeatureColourI val = featureColours.get(next);
129       // if (val instanceof GraduatedColor)
130       if (val.isGraduatedColour() || val.isColourByLabel()) // why this test?
131       {
132         featureColours.put(next, new FeatureColour((FeatureColour) val));
133       }
134     }
135
136     if (fr.featureFilters != null)
137     {
138       this.featureFilters.putAll(fr.featureFilters);
139     }
140
141     this.transparency = fr.transparency;
142     if (fr.featureOrder != null)
143     {
144       this.featureOrder = new ConcurrentHashMap<>(
145               fr.featureOrder);
146     }
147   }
148 }