1 /*
2 * ObjectLab, http://www.objectlab.co.uk/open is supporting JTreeMap.
3 *
4 * Based in London, we are world leaders in the design and development
5 * of bespoke applications for the securities financing markets.
6 *
7 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
8 * ___ _ _ _ _ _
9 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
10 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
11 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
12 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
13 * |__/
14 *
15 * www.ObjectLab.co.uk
16 *
17 * $Id: UniqueColorProvider.java 74 2006-10-24 22:19:05Z benoitx $
18 *
19 * Copyright 2006 the original author or authors.
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
22 * use this file except in compliance with the License. You may obtain a copy of
23 * the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
30 * License for the specific language governing permissions and limitations under
31 * the License.
32 */
33 package net.sf.jtreemap.swing;
34
35 import java.awt.Color;
36 import java.awt.Graphics;
37
38 import javax.swing.JPanel;
39
40 /**
41 * Color Provider by default.<BR>
42 * All values are associated to a unique color.
43 *
44 * @author Laurent DUTHEIL
45 *
46 */
47 public class UniqueColorProvider extends ColorProvider {
48 /**
49 *
50 */
51 private static final long serialVersionUID = -7571926934516139432L;
52
53 private static final Color DEFAULT_COLOR = new Color(153, 153, 51);
54
55 private Color color;
56
57 private JPanel legend;
58
59 /**
60 * Constructor.
61 */
62 public UniqueColorProvider() {
63 this.color = DEFAULT_COLOR;
64 }
65
66 /**
67 * Constructor.
68 *
69 * @param color
70 * unique color
71 */
72 public UniqueColorProvider(final Color color) {
73 this.color = color;
74 }
75
76 /*
77 * (non-Javadoc)
78 *
79 * @see net.sf.jtreemap.swing.ColorProvider#getColor(double)
80 */
81 @Override
82 public Color getColor(final Value value) {
83 return this.color;
84 }
85
86 /*
87 * (non-Javadoc)
88 *
89 * @see net.sf.jtreemap.swing.ColorProvider#getLegendPanel()
90 */
91 @Override
92 public JPanel getLegendPanel() {
93 if (this.legend == null) {
94 this.legend = new Legend();
95 }
96 return this.legend;
97 }
98
99 /**
100 * Panel with the legend.
101 *
102 * @author Laurent Dutheil
103 */
104 private static class Legend extends JPanel {
105 private static final int LEGEND_Y_POS = 20;
106
107 private static final int LEGEND_X_POS = 20;
108
109 private static final int LEGEND_HEIGHT = 40;
110
111 private static final int LEGEND_WIDTH = 100;
112
113 private static final long serialVersionUID = -8046211081305644785L;
114
115 private static final String TEXT = "Unique Color Provider";
116
117 /**
118 * Constructor.
119 */
120 public Legend() {
121 this.setPreferredSize(new java.awt.Dimension(LEGEND_WIDTH, LEGEND_HEIGHT));
122
123 }
124
125 @Override
126 public void paint(final Graphics g) {
127 g.setColor(Color.black);
128 g.drawString(Legend.TEXT, LEGEND_X_POS, LEGEND_Y_POS);
129 }
130 }
131 }
132 /*
133 * ObjectLab is supporing JTreeMap
134 *
135 * Based in London, we are world leaders in the design and development
136 * of bespoke applications for the securities financing markets.
137 *
138 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
139 * ___ _ _ _ _ _
140 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
141 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
142 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
143 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
144 * |__/
145 *
146 * www.ObjectLab.co.uk
147 */