2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2010 Christian M. Zmasek
6 // Copyright (C) 2008-2010 Burnham Institute for Medical Research
7 // Copyright (C) 2003-2010 Ethalinda K.S. Cannon
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
27 package org.forester.archaeopteryx;
29 import java.awt.Color;
32 import org.forester.util.ForesterUtil;
35 * Maintains the color schemes and a set of colors for drawing a tree.
37 public final class TreeColorSet {
39 public static final String OVERVIEW = "Overview";
40 public static final String ANNOTATION = "Annotation";
41 public static final String BINARY_DOMAIN_COMBINATIONS = "Binary Domain Combinations";
42 public static final String DOMAINS = "Domains";
43 public static final String DUPLICATION_OR_SPECATION = "Duplication or Specation";
44 public static final String SPECIATION = "Speciation";
45 public static final String DUPLICATION = "Duplication";
46 public static final String MATCHING_NODES = "Matching Nodes";
47 public static final String COLLAPSED = "Collapsed";
48 public static final String NODE_BOX = "Node Box";
49 public static final String BRANCH = "Branch";
50 public static final String BRANCH_LENGTH = "Branch Length";
51 public static final String CONFIDENCE = "Confidence";
52 public static final String TAXONOMY = "Taxonomy";
53 public static final String SEQUENCE = "Sequence";
54 public static final String BACKGROUND_GRADIENT_BOTTOM = "Background Gradient Bottom";
55 public static final String BACKGROUND = "Background";
56 static final String[] SCHEME_NAMES = { "Default", "Black", "Black & White", "Silver",
57 "The Matrix", "White & Blue", "Cyan", "Clockwork", "Blue", "Blue & White", "Neon" };
58 static final String[] COLOR_FIELDS = { BACKGROUND, BACKGROUND_GRADIENT_BOTTOM, SEQUENCE,
59 TAXONOMY, CONFIDENCE, BRANCH_LENGTH, BRANCH, NODE_BOX, COLLAPSED, MATCHING_NODES, DUPLICATION, SPECIATION,
60 DUPLICATION_OR_SPECATION, DOMAINS, BINARY_DOMAIN_COMBINATIONS, ANNOTATION, OVERVIEW };
61 // All the color sets; better be the same # of sets as there are names!
62 private final Color[][] _color_schemes = { { new Color( 0, 0, 0 ), // background_color
63 new Color( 0, 100, 100 ), // background_color_gradient_bottom
64 new Color( 220, 220, 220 ), // sequence __ Default (same as Black)
65 new Color( 180, 180, 180 ), // taxonomy
66 new Color( 56, 176, 222 ), // support
67 new Color( 140, 140, 140 ), // branch_length_color
68 new Color( 255, 255, 255 ), // branch_color
69 new Color( 255, 255, 255 ), // box_color
70 new Color( 255, 255, 0 ), // collapesed_fill_color
71 new Color( 0, 255, 0 ), // found_color
72 new Color( 255, 0, 0 ), // duplication_box_color
73 new Color( 0, 255, 0 ), // speciation_box_color
74 new Color( 255, 255, 0 ), // duplication_speciation_color
75 new Color( 123, 104, 238 ), // domains_color
76 new Color( 65, 105, 255 ), // binary_domain_combinations_color
77 new Color( 173, 255, 47 ) // annotation
78 , new Color( 130, 130, 130 ) // overview
79 }, { new Color( 0, 0, 0 ), // background_color
80 new Color( 0, 255, 255 ), // background_color_gradient_bottom
81 new Color( 220, 220, 220 ), // sequence __ Black
82 new Color( 180, 180, 180 ), // taxonomy
83 new Color( 56, 176, 222 ), // support
84 new Color( 140, 140, 140 ), // branch_length_color
85 new Color( 255, 255, 255 ), // branch_color
86 new Color( 255, 255, 255 ), // box_color
87 new Color( 255, 255, 0 ), // collapesed_fill_color
88 new Color( 0, 255, 0 ), // found_color
89 new Color( 255, 0, 0 ), // duplication_box_color
90 new Color( 0, 255, 0 ), // speciation_box_color
91 new Color( 255, 255, 0 ), // duplication_speciation_color
92 new Color( 123, 104, 238 ), // domains_color
93 new Color( 65, 105, 255 ), // binary_domain_combinations_color
94 new Color( 173, 255, 47 ) // annotation
95 , new Color( 130, 130, 130 ) // ov
96 }, { new Color( 255, 255, 255 ), // background_color
97 new Color( 0, 255, 255 ), // background_color_gradient_bottom
98 new Color( 0, 0, 0 ), // sequence __ Black & White
99 new Color( 0, 0, 0 ), // taxonomy
100 new Color( 0, 0, 0 ), // support
101 new Color( 0, 0, 0 ), // branch_length_color
102 new Color( 0, 0, 0 ), // branch_color
103 new Color( 0, 0, 0 ), // box_color
104 new Color( 0, 0, 0 ), // collapesed_fill_color
105 new Color( 255, 0, 0 ), // found_color
106 new Color( 0, 0, 0 ), // duplication_box_color
107 new Color( 200, 200, 200 ), // speciation_box_color
108 new Color( 0, 0, 0 ), // duplication_speciation_color
109 new Color( 0, 0, 0 ), // domains_color
110 new Color( 0, 0, 0 ), // binary_domain_combinations_color
111 new Color( 0, 0, 0 ) // annotation
112 , new Color( 220, 220, 220 ) // ov
113 }, { new Color( 0, 0, 0 ), // background_color
114 new Color( 0, 255, 255 ), // background_color_gradient_bottom
115 new Color( 220, 220, 220 ), // sequence __ Silver
116 new Color( 180, 180, 180 ), // taxonomy
117 new Color( 140, 140, 140 ), // support
118 new Color( 140, 140, 140 ), // branch_length_color
119 new Color( 240, 240, 240 ), // branch_color
120 new Color( 140, 140, 140 ), // box_color
121 new Color( 140, 140, 140 ), // collapesed_fill_color
122 new Color( 255, 0, 0 ), // found_color
123 new Color( 255, 0, 0 ), // duplication_box_color
124 new Color( 200, 200, 200 ), // speciation_box_color
125 new Color( 140, 140, 140 ), // duplication_speciation_color
126 new Color( 180, 180, 180 ), // domains_color
127 new Color( 180, 180, 180 ), // binary_domain_combinations_color
128 new Color( 140, 140, 140 ) // annotation
129 , new Color( 40, 40, 40 ) // ov
130 }, { new Color( 0, 10, 0 ), // background_color
131 new Color( 0, 255, 255 ), // background_color_gradient_bottom
132 new Color( 0, 255, 0 ), // sequence __ the Matrix
133 new Color( 30, 200, 30 ), // taxonomy
134 new Color( 0, 155, 0 ), // support
135 new Color( 0, 100, 0 ), // branch_length_color
136 new Color( 0, 155, 0 ), // branch_color
137 new Color( 0, 255, 0 ), // box_color
138 new Color( 0, 255, 0 ), // collapesed_fill_color
139 new Color( 255, 255, 255 ), // found_color
140 new Color( 255, 255, 255 ), // duplication_box_color
141 new Color( 0, 255, 0 ), // speciation_box_color
142 new Color( 120, 120, 120 ), // duplication_speciation_color
143 new Color( 0, 235, 0 ), // domains_color
144 new Color( 0, 235, 0 ), // binary_domain_combinations_color
145 new Color( 0, 235, 0 ) // annotation
146 , new Color( 40, 40, 40 ) // ov
147 }, { new Color( 255, 255, 255 ), // background_color
148 new Color( 0, 255, 255 ), // background_color_gradient_bottom
149 new Color( 0, 0, 0 ), //sequence __ White & Blue
150 new Color( 40, 40, 40 ), // taxonomy
151 new Color( 0, 125, 0 ), // support
152 new Color( 70, 70, 0 ), // branch_length_color
153 new Color( 0, 20, 200 ), // branch_color
154 new Color( 0, 20, 200 ), // box_color
155 new Color( 255, 255, 0 ), // collapesed_fill_color
156 new Color( 0, 255, 0 ), // found_color
157 new Color( 255, 0, 0 ), // duplication_box_color
158 new Color( 0, 255, 0 ), // speciation_box_color
159 new Color( 255, 255, 0 ), // duplication_speciation_color
160 new Color( 123, 104, 238 ), // domains_color
161 new Color( 65, 105, 225 ), // binary_domain_combinations_color
162 new Color( 173, 255, 47 ) // annotation
163 , new Color( 220, 220, 220 ) // ov
164 }, { new Color( 0, 0, 0 ), // background_color
165 new Color( 0, 255, 255 ), // background_color_gradient_bottom
166 new Color( 255, 255, 255 ), // sequence __ Cyan
167 new Color( 200, 200, 200 ), // taxonomy
168 new Color( 255, 255, 255 ), // support
169 new Color( 200, 200, 200 ), // branch_length_color
170 new Color( 0, 255, 255 ), // branch_color
171 new Color( 0, 255, 255 ), // box_color
172 new Color( 255, 255, 0 ), // collapesed_fill_color
173 new Color( 0, 255, 0 ), // found_color
174 new Color( 255, 0, 0 ), // duplication_box_color
175 new Color( 0, 255, 0 ), // speciation_box_color
176 new Color( 255, 255, 0 ), // duplication_speciation_color
177 new Color( 123, 104, 238 ), // domains_color
178 new Color( 65, 105, 225 ), // binary_domain_combinations_color
179 new Color( 173, 255, 47 ) // annotation
180 , new Color( 0, 120, 120 ) // ov
181 }, { new Color( 0, 0, 0 ), // background_color
182 new Color( 0, 255, 255 ), // background_color_gradient_bottom
183 new Color( 255, 200, 0 ), // sequence __ Clockwork
184 new Color( 255, 200, 0 ), // taxonomy
185 new Color( 255, 200, 0 ), // support
186 new Color( 255, 200, 0 ), // branch_length_color
187 new Color( 255, 200, 0 ), // branch_color
188 new Color( 255, 200, 0 ), // box_color
189 new Color( 255, 255, 255 ), // collapesed_fill_color
190 new Color( 255, 255, 255 ), // found_color
191 new Color( 255, 0, 0 ), // duplication_box_color
192 new Color( 0, 255, 0 ), // speciation_box_color
193 new Color( 255, 255, 0 ), // duplication_speciation_color
194 new Color( 150, 150, 150 ), // domains_color
195 new Color( 150, 150, 150 ), // binary_domain_combinations_color
196 new Color( 150, 150, 150 ) // annotation
197 , new Color( 150, 150, 150 ) // ov
198 }, { new Color( 0, 0, 100 ), // background_color
199 new Color( 0, 255, 255 ), // background_color_gradient_bottom
200 new Color( 255, 255, 255 ), // sequence __ Blue
201 new Color( 255, 255, 255 ), // taxonomy
202 new Color( 255, 0, 0 ), // support
203 new Color( 255, 0, 0 ), // branch_length_color
204 new Color( 255, 0, 0 ), // branch_color
205 new Color( 255, 0, 0 ), // box_color
206 new Color( 0, 0, 0 ), // collapesed_fill_color
207 new Color( 0, 255, 0 ), // found_color
208 new Color( 255, 0, 255 ), // duplication_box_color
209 new Color( 255, 255, 255 ), // speciation_box_color
210 new Color( 100, 100, 100 ), // duplication_speciation_color
211 new Color( 255, 255, 255 ), // domains_color
212 new Color( 255, 255, 255 ), // binary_domain_combinations_color
213 new Color( 255, 255, 255 ) // annotation
214 , new Color( 77, 77, 255 ) // ov
215 }, { new Color( 0, 0, 0 ), // background_color
216 new Color( 0, 255, 255 ), // background_color_gradient_bottom
217 new Color( 255, 255, 255 ), // sequence __ blue & white
218 new Color( 255, 255, 255 ), // taxonomy
219 new Color( 255, 255, 255 ), // support
220 new Color( 0, 191, 255 ), // branch_length_color
221 new Color( 0, 191, 255 ), // branch_color
222 new Color( 0, 191, 255 ), // box_color
223 new Color( 255, 255, 255 ), // collapesed_fill_color
224 new Color( 255, 0, 0 ), // found_color
225 new Color( 255, 0, 0 ), // duplication_box_color
226 new Color( 0, 255, 0 ), // speciation_box_color
227 new Color( 255, 255, 0 ), // duplication_speciation_color
228 new Color( 255, 255, 255 ), // domains_color
229 new Color( 255, 255, 255 ), // binary_domain_combinations_color
230 new Color( 255, 255, 255 ) // annotation
231 , new Color( 170, 187, 204 ) // ov
232 }, { new Color( 0, 0, 0 ), // background_color
233 new Color( 255, 255, 0 ), // background_color_gradient_bottom
234 new Color( 127, 255, 0 ), // sequence __ Neon
235 new Color( 255, 110, 199 ), // taxonomy
236 new Color( 234, 173, 234 ), // support
237 new Color( 77, 77, 255 ), // branch_length_color
238 new Color( 234, 173, 234 ), // branch_color
239 new Color( 77, 77, 255 ), // box_color
240 new Color( 77, 77, 255 ), // collapesed_fill_color
241 new Color( 243, 243, 21 ), // found_color
242 new Color( 255, 0, 0 ), // duplication_box_color
243 new Color( 0, 255, 0 ), // speciation_box_color
244 new Color( 255, 255, 0 ), // duplication_speciation_color
245 new Color( 27, 255, 0 ), // domains_color
246 new Color( 27, 255, 0 ), // binary_domain_combinations_color
247 new Color( 27, 255, 0 ) // annotation
248 , new Color( 77, 77, 255 ) // ov
251 private int _color_scheme;
252 // The drawing colors
253 private Color seq_color;
254 private Color taxonomy_color;
255 private Color bootstrap_color;
256 private Color branch_length_color;
257 private Color branch_color;
258 private Color box_color;
259 private Color background_color;
260 private Color background_color_gradient_bottom;
261 private Color dup_box_color;
262 private Color spec_box_color;
263 private Color collapse_fill_color;
264 private Color found_color;
265 private Color duplication_or_specation_color;
266 private Color domains_color;
267 private Color binary_domain_combinations_color;
268 private Color annotation_color;
269 private Color ov_color;
271 private TreeColorSet() {
272 // Hidden constructor.
275 void cycleColorScheme() {
276 if ( getCurrentColorScheme() >= _color_schemes.length - 1 ) {
280 setColorSchema( getCurrentColorScheme() + 1 );
284 Color getAnnotationColor() {
285 return annotation_color;
288 Color getBackgroundColor() {
289 return background_color;
292 Color getBackgroundColorGradientBottom() {
293 return background_color_gradient_bottom;
296 Color getBinaryDomainCombinationsColor() {
297 if ( Constants.SPECIAL_CUSTOM ) {
298 return new Color( 50, 50, 50 );
300 return binary_domain_combinations_color;
303 Color getBoxColor() {
307 Color getBranchColor() {
311 Color getBranchColorForPdf() {
315 Color getBranchLengthColor() {
316 return branch_length_color;
319 Color getCollapseFillColor() {
320 return collapse_fill_color;
323 Color[][] getColorSchemes() {
324 return _color_schemes;
327 Color getConfidenceColor() {
328 return bootstrap_color;
331 int getCurrentColorScheme() {
332 return _color_scheme;
335 String getCurrentColorSchemeName() {
336 return SCHEME_NAMES[ getCurrentColorScheme() ];
339 Color getDomainsColor() {
340 return domains_color;
343 Color getDuplicationBoxColor() {
344 return dup_box_color;
347 Color getDuplicationOrSpeciationColor() {
348 return duplication_or_specation_color;
351 Color getFoundColor() {
355 Color getGainedCharactersColor() {
359 Color getLostCharactersColor() {
367 Color getSequenceColor() {
371 Color getSpecBoxColor() {
372 return spec_box_color;
375 Color getTaxonomyColor() {
376 return taxonomy_color;
379 void setColorforDefault( final String color_field_name, final Color color ) {
380 final String query = color_field_name.trim().replace( '_', ' ' );
381 boolean found = false;
383 for( final String cf : COLOR_FIELDS ) {
384 if ( query.equalsIgnoreCase( cf ) ) {
386 setColorForDefault( i, color );
392 throw new IllegalArgumentException( "unknown color field name [" + color_field_name + "]" );
396 private void setColorForDefault( final int i, final Color color ) {
397 _color_schemes[ 0 ][ i ] = color;
401 * Switches colors between different schemes.
403 void setColorSchema( final int scheme ) {
404 _color_scheme = scheme;
405 background_color = _color_schemes[ scheme ][ 0 ];
406 background_color_gradient_bottom = _color_schemes[ scheme ][ 1 ];
407 seq_color = _color_schemes[ scheme ][ 2 ];
408 taxonomy_color = _color_schemes[ scheme ][ 3 ];
409 bootstrap_color = _color_schemes[ scheme ][ 4 ];
410 branch_length_color = _color_schemes[ scheme ][ 5 ];
411 branch_color = _color_schemes[ scheme ][ 6 ];
412 box_color = _color_schemes[ scheme ][ 7 ];
413 collapse_fill_color = _color_schemes[ scheme ][ 8 ];
414 found_color = _color_schemes[ scheme ][ 9 ];
415 dup_box_color = _color_schemes[ scheme ][ 10 ];
416 spec_box_color = _color_schemes[ scheme ][ 11 ];
417 duplication_or_specation_color = _color_schemes[ scheme ][ 12 ];
418 domains_color = _color_schemes[ scheme ][ 13 ];
419 binary_domain_combinations_color = _color_schemes[ scheme ][ 14 ];
420 annotation_color = _color_schemes[ scheme ][ 15 ];
421 ov_color = _color_schemes[ scheme ][ 16 ];
424 void setCurrentColorScheme( final int color_scheme ) {
425 _color_scheme = color_scheme;
428 static TreeColorSet createInstance() {
429 final TreeColorSet tcs = new TreeColorSet();
430 tcs.setColorSchema( 0 );
434 static TreeColorSet createInstance( final Configuration configuration ) {
435 final TreeColorSet tcs = new TreeColorSet();
436 if ( ( configuration != null ) && ( configuration.getDisplayColors() != null )
437 && ( configuration.getDisplayColors().size() > 0 ) ) {
438 final Map<String, Color> colors = configuration.getDisplayColors();
439 for( final String field : colors.keySet() ) {
440 final Color color = colors.get( field );
442 tcs.setColorforDefault( field, color );
444 catch ( final IllegalArgumentException ex ) {
445 ForesterUtil.printWarningMessage( Constants.PRG_NAME, ex.getMessage() );
449 tcs.setColorSchema( 0 );