1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package org.jfree.chart.editor; |
27 | |
|
28 | |
import java.awt.Graphics2D; |
29 | |
import java.awt.GridBagLayout; |
30 | |
import java.awt.GridBagConstraints; |
31 | |
import java.awt.Color; |
32 | |
import java.awt.Insets; |
33 | |
import java.awt.Point; |
34 | |
import java.awt.Rectangle; |
35 | |
import java.awt.geom.Rectangle2D; |
36 | |
import java.awt.geom.Point2D; |
37 | |
import java.awt.event.ActionListener; |
38 | |
import java.awt.event.ActionEvent; |
39 | |
|
40 | |
import java.util.ResourceBundle; |
41 | |
import java.util.Set; |
42 | |
import java.util.Iterator; |
43 | |
|
44 | |
import java.lang.IllegalArgumentException; |
45 | |
|
46 | |
import javax.swing.BorderFactory; |
47 | |
import javax.swing.JPanel; |
48 | |
import javax.swing.JColorChooser; |
49 | |
import javax.swing.JLabel; |
50 | |
import javax.swing.JButton; |
51 | |
import javax.swing.JCheckBox; |
52 | |
import javax.swing.event.ChangeEvent; |
53 | |
import javax.swing.event.ChangeListener; |
54 | |
|
55 | |
import org.jfree.ui.RectangleEdge; |
56 | |
import org.jfree.ui.PaintSample; |
57 | |
|
58 | |
import org.jfree.chart.ChartMouseEvent; |
59 | |
import org.jfree.chart.ChartMouseListener; |
60 | |
import org.jfree.chart.axis.HeatMapAxis; |
61 | |
import org.jfree.chart.axis.CategoryLabelPositions; |
62 | |
import org.jfree.chart.entity.HCTreeNodeEntity; |
63 | |
import org.jfree.chart.entity.HeatMapBlockEntity; |
64 | |
import org.jfree.chart.entity.EntityCollection; |
65 | |
import org.jfree.chart.labels.HCToolTipGenerator; |
66 | |
import org.jfree.chart.plot.GradientColorPalette; |
67 | |
import org.jfree.chart.plot.Plot; |
68 | |
import org.jfree.chart.renderer.RendererState; |
69 | |
import org.jfree.data.hc.HCDataset; |
70 | |
import org.jfree.data.hc.HeatMap; |
71 | |
import org.jfree.data.hc.DataRange; |
72 | |
import org.jfree.data.hc.HCTreeNode; |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public class GradientColorPaletteEditor |
80 | |
extends JPanel |
81 | |
implements ActionListener, ChangeListener { |
82 | |
|
83 | |
private JCheckBox logarithmicCB; |
84 | |
private GradientColorPalette palette; |
85 | |
private ColorInfo[] colors; |
86 | |
|
87 | |
public GradientColorPaletteEditor () { |
88 | |
|
89 | 21 | super(); |
90 | 21 | this.palette = null; |
91 | 21 | this.colors = null; |
92 | |
|
93 | 21 | } |
94 | |
|
95 | |
public void setColoring (GradientColorPalette palette) { |
96 | |
|
97 | 22 | this.palette = palette; |
98 | |
|
99 | 22 | } |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public void stateChanged(ChangeEvent e) { |
107 | |
|
108 | 4 | if (e.getSource() == this.logarithmicCB) { |
109 | |
|
110 | 4 | boolean value = this.logarithmicCB.isSelected(); |
111 | 4 | this.palette.setLinear(!value); |
112 | |
|
113 | |
} |
114 | |
|
115 | 4 | } |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public void actionPerformed(ActionEvent e) { |
123 | |
|
124 | |
int i; |
125 | |
Color color; |
126 | 5 | ResourceBundle lr = ResourceBundle.getBundle( |
127 | |
"org.jfree.chart.editor.LocalizationBundle"); |
128 | |
|
129 | 5 | if (colors == null) return; |
130 | |
|
131 | 30 | for (i = 0; i < this.colors.length; i++) { |
132 | |
|
133 | 25 | if (e.getSource() == this.colors[i].button) { |
134 | 5 | color = this.palette.getKeyColor(this.colors[i].value); |
135 | |
|
136 | 5 | color = JColorChooser.showDialog( |
137 | |
this, lr.getString("Change_color")+i, color |
138 | |
); |
139 | 5 | if (color != null) { |
140 | 5 | this.colors[i].sample.setPaint( color); |
141 | 5 | this.palette.setKeyColor(this.colors[i].value, color); |
142 | |
} |
143 | |
} |
144 | |
|
145 | |
} |
146 | |
|
147 | 5 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
public JPanel getPanel() { |
154 | 2 | ResourceBundle lr = ResourceBundle.getBundle( |
155 | |
"org.jfree.chart.editor.LocalizationBundle"); |
156 | 2 | JPanel panel = new JPanel(); |
157 | 2 | GridBagConstraints c = new GridBagConstraints(); |
158 | |
|
159 | 2 | Set keyColors = this.palette.getKeyColors(); |
160 | 2 | Iterator iterator = keyColors.iterator(); |
161 | |
int i; |
162 | |
|
163 | 2 | panel.setLayout(new GridBagLayout()); |
164 | 2 | panel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
165 | |
|
166 | 2 | c.fill = GridBagConstraints.VERTICAL; |
167 | 2 | c.insets = new Insets(5,2,5,2); |
168 | |
|
169 | 2 | c.gridx = 0; |
170 | 2 | c.gridy = 0; |
171 | |
|
172 | 2 | colors = new ColorInfo[keyColors.size()]; |
173 | |
|
174 | 2 | i = 0; |
175 | 10 | while (iterator.hasNext()) { |
176 | |
|
177 | 8 | ColorInfo color = new ColorInfo(); |
178 | 8 | color.value = ((Double)(iterator.next())).doubleValue(); |
179 | |
|
180 | 8 | c.gridx=0; |
181 | |
String nameOfColor; |
182 | 8 | if (i==0) nameOfColor |
183 | |
= lr.getString("Color_for_values_below")+color.value; |
184 | 6 | else if (!iterator.hasNext()) nameOfColor |
185 | |
= lr.getString("Color_for_values_above")+color.value; |
186 | 4 | else nameOfColor |
187 | |
= lr.getString("Color_for_value")+color.value; |
188 | 8 | panel.add(new JLabel(nameOfColor),c); |
189 | |
|
190 | 8 | c.gridx=1; |
191 | 8 | color.sample |
192 | |
= new PaintSample(this.palette.getColor(color.value)); |
193 | 8 | panel.add(color.sample,c); |
194 | |
|
195 | 8 | c.gridx=2; |
196 | 8 | color.button = new JButton(lr.getString("Change")); |
197 | 8 | panel.add(color.button,c); |
198 | 8 | color.button.addActionListener(this); |
199 | |
|
200 | 8 | this.colors[i] = color; |
201 | |
|
202 | 8 | c.gridy++; |
203 | 8 | i++; |
204 | |
|
205 | 8 | } |
206 | |
|
207 | 2 | c.gridx=0; |
208 | 2 | this.logarithmicCB = new JCheckBox( |
209 | |
lr.getString("Use_logarithmic_scale"), |
210 | |
!this.palette.isLinear() |
211 | |
); |
212 | 2 | this.logarithmicCB.addChangeListener(this); |
213 | 2 | panel.add(this.logarithmicCB,c); |
214 | 2 | return panel; |
215 | |
} |
216 | |
|
217 | |
private class ColorInfo { |
218 | |
|
219 | |
private PaintSample sample; |
220 | |
private JButton button; |
221 | |
private double value; |
222 | |
} |
223 | |
|
224 | |
} |
225 | |
|