2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2006, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
package org.tigr.microarray.mev.cluster.gui.impl.lem; |
2 |
26 Feb 07 |
jari |
6 |
|
2 |
26 Feb 07 |
jari |
7 |
import java.awt.AlphaComposite; |
2 |
26 Feb 07 |
jari |
8 |
import java.awt.BasicStroke; |
2 |
26 Feb 07 |
jari |
9 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
10 |
import java.awt.Component; |
2 |
26 Feb 07 |
jari |
11 |
import java.awt.Composite; |
2 |
26 Feb 07 |
jari |
12 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Stroke; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
22 |
import java.util.Hashtable; |
2 |
26 Feb 07 |
jari |
23 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.ButtonGroup; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JCheckBox; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JColorChooser; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JComboBox; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JList; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.JRadioButton; |
2 |
26 Feb 07 |
jari |
35 |
import javax.swing.JSeparator; |
2 |
26 Feb 07 |
jari |
36 |
import javax.swing.JTabbedPane; |
2 |
26 Feb 07 |
jari |
37 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
38 |
import javax.swing.ListCellRenderer; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
/** |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
45 |
* |
2 |
26 Feb 07 |
jari |
* Dialog to support Linear Expression Graph rendering options |
2 |
26 Feb 07 |
jari |
47 |
*/ |
2 |
26 Feb 07 |
jari |
48 |
public class GraphScaleCustomizationDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
private JTabbedPane pane; |
2 |
26 Feb 07 |
jari |
51 |
private YScalePanel yPanel; |
2 |
26 Feb 07 |
jari |
52 |
private GraphRenderingPanel graphRenderingPanel; |
2 |
26 Feb 07 |
jari |
53 |
private Hashtable props; |
2 |
26 Feb 07 |
jari |
54 |
private int result; |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
//use display menu limits |
2 |
26 Feb 07 |
jari |
57 |
public static final int YRANGE_OPTION_DISPLAY_MENU = 0; |
2 |
26 Feb 07 |
jari |
//define custom limites |
2 |
26 Feb 07 |
jari |
59 |
public static final int YRANGE_OPTION_CUSTOM_RANGE = 1; |
2 |
26 Feb 07 |
jari |
//use data to automatically set range |
2 |
26 Feb 07 |
jari |
61 |
public static final int YRANGE_OPTION_AUTO_RANGE = 2; |
2 |
26 Feb 07 |
jari |
62 |
|
2 |
26 Feb 07 |
jari |
63 |
/** |
2 |
26 Feb 07 |
jari |
* Constructor |
2 |
26 Feb 07 |
jari |
* @param parent parent fram |
2 |
26 Feb 07 |
jari |
* @param modal modal |
2 |
26 Feb 07 |
jari |
67 |
*/ |
2 |
26 Feb 07 |
jari |
68 |
public GraphScaleCustomizationDialog(JFrame parent, boolean modal, Hashtable props) { |
2 |
26 Feb 07 |
jari |
69 |
super(parent, "Customize Graph", modal); |
2 |
26 Feb 07 |
jari |
70 |
this.props = props; |
2 |
26 Feb 07 |
jari |
71 |
|
2 |
26 Feb 07 |
jari |
72 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
73 |
pane = new JTabbedPane(); |
2 |
26 Feb 07 |
jari |
74 |
yPanel = new YScalePanel(); |
2 |
26 Feb 07 |
jari |
75 |
graphRenderingPanel = new GraphRenderingPanel(); |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
pane.add("Y Range and X Axis Parameters", yPanel); |
2 |
26 Feb 07 |
jari |
78 |
pane.add("Graph Rendering Options", graphRenderingPanel); |
2 |
26 Feb 07 |
jari |
79 |
pane.setBackgroundAt(0,Color.white); |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
81 |
this.addContent(pane); |
2 |
26 Feb 07 |
jari |
82 |
this.setActionListeners(new Listener()); |
2 |
26 Feb 07 |
jari |
83 |
pack(); |
2 |
26 Feb 07 |
jari |
84 |
} |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
/** |
2 |
26 Feb 07 |
jari |
* Displays dialog, returns closing state |
2 |
26 Feb 07 |
jari |
* @return closeing state from JOptionPane.OK_OPTION, JOptionPane.CANCEL_OPTION |
2 |
26 Feb 07 |
jari |
89 |
*/ |
2 |
26 Feb 07 |
jari |
90 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
91 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
92 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
93 |
show(); |
2 |
26 Feb 07 |
jari |
94 |
return result; |
2 |
26 Feb 07 |
jari |
95 |
} |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the range mode option selected |
2 |
26 Feb 07 |
jari |
* @return mode |
2 |
26 Feb 07 |
jari |
100 |
*/ |
2 |
26 Feb 07 |
jari |
101 |
public int getYRangeMode() { |
2 |
26 Feb 07 |
jari |
102 |
int mode; |
2 |
26 Feb 07 |
jari |
103 |
if(yPanel.displaySettingRangeButton.isSelected()) |
2 |
26 Feb 07 |
jari |
104 |
mode = YRANGE_OPTION_DISPLAY_MENU; |
2 |
26 Feb 07 |
jari |
105 |
else if(yPanel.customRangeButton.isSelected()) |
2 |
26 Feb 07 |
jari |
106 |
mode = YRANGE_OPTION_CUSTOM_RANGE; |
2 |
26 Feb 07 |
jari |
107 |
else |
2 |
26 Feb 07 |
jari |
108 |
mode = YRANGE_OPTION_AUTO_RANGE; |
2 |
26 Feb 07 |
jari |
109 |
return mode; |
2 |
26 Feb 07 |
jari |
110 |
} |
2 |
26 Feb 07 |
jari |
111 |
|
2 |
26 Feb 07 |
jari |
112 |
/** |
2 |
26 Feb 07 |
jari |
* Minium custom y limit |
2 |
26 Feb 07 |
jari |
* @return min. limit |
2 |
26 Feb 07 |
jari |
115 |
*/ |
2 |
26 Feb 07 |
jari |
116 |
public float getYMin() { |
2 |
26 Feb 07 |
jari |
117 |
return Float.parseFloat(yPanel.minField.getText()); |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
/** |
2 |
26 Feb 07 |
jari |
* Max custom y limit |
2 |
26 Feb 07 |
jari |
* @return max. limit |
2 |
26 Feb 07 |
jari |
123 |
*/ |
2 |
26 Feb 07 |
jari |
124 |
public float getYMax() { |
2 |
26 Feb 07 |
jari |
125 |
return Float.parseFloat(yPanel.maxField.getText()); |
2 |
26 Feb 07 |
jari |
126 |
} |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the cutom tick interval |
2 |
26 Feb 07 |
jari |
130 |
*/ |
2 |
26 Feb 07 |
jari |
131 |
public float getYTicInterval() { |
2 |
26 Feb 07 |
jari |
132 |
return Float.parseFloat(yPanel.ticIntervalField.getText()); |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if X axis should be displayed |
2 |
26 Feb 07 |
jari |
* @return state |
2 |
26 Feb 07 |
jari |
138 |
*/ |
2 |
26 Feb 07 |
jari |
139 |
public boolean showXAxisLine() { |
2 |
26 Feb 07 |
jari |
140 |
return yPanel.showXAxisBox.isSelected(); |
2 |
26 Feb 07 |
jari |
141 |
} |
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
/** |
2 |
26 Feb 07 |
jari |
* returns the y value for x axis, often zero |
2 |
26 Feb 07 |
jari |
* @return value for crossing |
2 |
26 Feb 07 |
jari |
146 |
*/ |
2 |
26 Feb 07 |
jari |
147 |
public float getXAxisCrossPoint() { |
2 |
26 Feb 07 |
jari |
148 |
return Float.parseFloat(yPanel.xAxisField.getText()); |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
|
2 |
26 Feb 07 |
jari |
151 |
/** |
2 |
26 Feb 07 |
jari |
* Current color selected for x axis |
2 |
26 Feb 07 |
jari |
* @return current color |
2 |
26 Feb 07 |
jari |
154 |
*/ |
2 |
26 Feb 07 |
jari |
155 |
public Color getXAxisColor() { |
2 |
26 Feb 07 |
jari |
156 |
if(yPanel.xAxisColorBox.getSelectedItem() instanceof Color) |
2 |
26 Feb 07 |
jari |
157 |
return (Color)yPanel.xAxisColorBox.getSelectedItem(); |
2 |
26 Feb 07 |
jari |
158 |
return yPanel.getCustomXAxisColor(); |
2 |
26 Feb 07 |
jari |
159 |
} |
2 |
26 Feb 07 |
jari |
160 |
|
2 |
26 Feb 07 |
jari |
161 |
/** |
2 |
26 Feb 07 |
jari |
* Current x axis style |
2 |
26 Feb 07 |
jari |
* @return stroke pattern |
2 |
26 Feb 07 |
jari |
164 |
*/ |
2 |
26 Feb 07 |
jari |
165 |
public BasicStroke getXAxisStyle() { |
2 |
26 Feb 07 |
jari |
166 |
return ((StrokePreview)yPanel.xAxisLineBox.getSelectedItem()).getBasicStroke(); |
2 |
26 Feb 07 |
jari |
167 |
} |
2 |
26 Feb 07 |
jari |
168 |
|
2 |
26 Feb 07 |
jari |
169 |
/** |
2 |
26 Feb 07 |
jari |
* True for offset lines mode rather than connected mode |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
172 |
*/ |
2 |
26 Feb 07 |
jari |
173 |
public boolean isOffsetLinesModeSelected() { |
2 |
26 Feb 07 |
jari |
174 |
return this.graphRenderingPanel.isOffsetLinesModeSelected(); |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
/** |
2 |
26 Feb 07 |
jari |
* Offset mode midpoint value |
2 |
26 Feb 07 |
jari |
* @return midpoint |
2 |
26 Feb 07 |
jari |
180 |
*/ |
2 |
26 Feb 07 |
jari |
181 |
public float getOffsetMidpoint() { |
2 |
26 Feb 07 |
jari |
182 |
return this.graphRenderingPanel.getOffsetMidpoint(); |
2 |
26 Feb 07 |
jari |
183 |
} |
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
/** |
2 |
26 Feb 07 |
jari |
* Retruns min. value for offset used for discrete rendering |
2 |
26 Feb 07 |
jari |
* @return min value |
2 |
26 Feb 07 |
jari |
188 |
*/ |
2 |
26 Feb 07 |
jari |
189 |
public float getOffsetMin() { |
2 |
26 Feb 07 |
jari |
190 |
return this.graphRenderingPanel.getOffsetMin(); |
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
|
2 |
26 Feb 07 |
jari |
193 |
/** |
2 |
26 Feb 07 |
jari |
* Retruns max. value for offset used for discrete rendering |
2 |
26 Feb 07 |
jari |
* @return max value |
2 |
26 Feb 07 |
jari |
196 |
*/ |
2 |
26 Feb 07 |
jari |
197 |
public float getOffsetMax() { |
2 |
26 Feb 07 |
jari |
198 |
return this.graphRenderingPanel.getOffsetMax(); |
2 |
26 Feb 07 |
jari |
199 |
} |
2 |
26 Feb 07 |
jari |
200 |
|
2 |
26 Feb 07 |
jari |
201 |
/** |
2 |
26 Feb 07 |
jari |
* True if overlay is selected |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
204 |
*/ |
2 |
26 Feb 07 |
jari |
205 |
public boolean getShowOverlay() { |
2 |
26 Feb 07 |
jari |
206 |
return this.graphRenderingPanel.getShowOverlay(); |
2 |
26 Feb 07 |
jari |
207 |
} |
2 |
26 Feb 07 |
jari |
208 |
|
2 |
26 Feb 07 |
jari |
209 |
/* |
2 |
26 Feb 07 |
jari |
public static void main(String [] args) { |
2 |
26 Feb 07 |
jari |
Hashtable props = new Hashtable(); |
2 |
26 Feb 07 |
jari |
props.put("x-axis-color", Color.magenta); |
2 |
26 Feb 07 |
jari |
GraphScaleCustomizationDialog d = new GraphScaleCustomizationDialog(null, true, props); |
2 |
26 Feb 07 |
jari |
d.show(); |
2 |
26 Feb 07 |
jari |
215 |
} |
2 |
26 Feb 07 |
jari |
216 |
*/ |
2 |
26 Feb 07 |
jari |
217 |
|
2 |
26 Feb 07 |
jari |
218 |
/** |
2 |
26 Feb 07 |
jari |
* Validates range, true if valid |
2 |
26 Feb 07 |
jari |
220 |
*/ |
2 |
26 Feb 07 |
jari |
221 |
public boolean validateRange() { |
2 |
26 Feb 07 |
jari |
222 |
if(this.yPanel.customRangeButton.isSelected()) { |
2 |
26 Feb 07 |
jari |
223 |
float min, max, interval; |
2 |
26 Feb 07 |
jari |
224 |
int level = 0; |
2 |
26 Feb 07 |
jari |
225 |
String msg; |
2 |
26 Feb 07 |
jari |
226 |
|
2 |
26 Feb 07 |
jari |
//try to parse |
2 |
26 Feb 07 |
jari |
228 |
try { |
2 |
26 Feb 07 |
jari |
229 |
min = Float.parseFloat(yPanel.minField.getText()); |
2 |
26 Feb 07 |
jari |
230 |
level++; |
2 |
26 Feb 07 |
jari |
231 |
max = Float.parseFloat(yPanel.maxField.getText()); |
2 |
26 Feb 07 |
jari |
232 |
level++; |
2 |
26 Feb 07 |
jari |
233 |
interval = Float.parseFloat(yPanel.ticIntervalField.getText()); |
2 |
26 Feb 07 |
jari |
234 |
level++; |
2 |
26 Feb 07 |
jari |
235 |
} catch (NumberFormatException nfe) { |
2 |
26 Feb 07 |
jari |
236 |
msg = "Minimum Value entry is not a number."; |
2 |
26 Feb 07 |
jari |
237 |
if(level == 1) |
2 |
26 Feb 07 |
jari |
238 |
msg = "Maximum Value entry is not a number."; |
2 |
26 Feb 07 |
jari |
239 |
else if(level == 2) |
2 |
26 Feb 07 |
jari |
240 |
msg = "Tick Interval Value entry is not a number."; |
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
JOptionPane.showMessageDialog(this, msg, "Number Format Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
243 |
return false; |
2 |
26 Feb 07 |
jari |
244 |
} |
2 |
26 Feb 07 |
jari |
245 |
|
2 |
26 Feb 07 |
jari |
246 |
if(min >= max) { |
2 |
26 Feb 07 |
jari |
247 |
msg = "Min Value should be < Max Value."; |
2 |
26 Feb 07 |
jari |
248 |
JOptionPane.showMessageDialog(this, msg, "Value Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
249 |
return false; |
2 |
26 Feb 07 |
jari |
250 |
} |
2 |
26 Feb 07 |
jari |
251 |
|
2 |
26 Feb 07 |
jari |
252 |
if(max-min < interval) { |
2 |
26 Feb 07 |
jari |
253 |
msg = "The tick interval is larger than the y range. Please make an appropriate change\n to either the range limits or tick interval."; |
2 |
26 Feb 07 |
jari |
254 |
JOptionPane.showMessageDialog(this, msg, "Value Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
255 |
return false; |
2 |
26 Feb 07 |
jari |
256 |
} |
2 |
26 Feb 07 |
jari |
257 |
} |
2 |
26 Feb 07 |
jari |
258 |
return true; |
2 |
26 Feb 07 |
jari |
259 |
} |
2 |
26 Feb 07 |
jari |
260 |
|
2 |
26 Feb 07 |
jari |
261 |
/** |
2 |
26 Feb 07 |
jari |
262 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
264 |
* |
2 |
26 Feb 07 |
jari |
* Contains first pane of controls |
2 |
26 Feb 07 |
jari |
266 |
*/ |
2 |
26 Feb 07 |
jari |
267 |
public class YScalePanel extends JPanel { |
2 |
26 Feb 07 |
jari |
//private JRadioButton globalAutoFitButton; |
2 |
26 Feb 07 |
jari |
//private JCheckBox symetricRangeBox; |
2 |
26 Feb 07 |
jari |
270 |
private JRadioButton displaySettingRangeButton; |
2 |
26 Feb 07 |
jari |
271 |
private JRadioButton customRangeButton; |
2 |
26 Feb 07 |
jari |
272 |
|
2 |
26 Feb 07 |
jari |
273 |
private JTextField minField; |
2 |
26 Feb 07 |
jari |
274 |
private JTextField maxField; |
2 |
26 Feb 07 |
jari |
275 |
private JTextField ticIntervalField; |
2 |
26 Feb 07 |
jari |
276 |
private JLabel minLabel, maxLabel, ticLabel; |
2 |
26 Feb 07 |
jari |
277 |
|
2 |
26 Feb 07 |
jari |
278 |
private JCheckBox showXAxisBox; |
2 |
26 Feb 07 |
jari |
279 |
private JLabel xAxisCrossesLabel, lineLabel, colorLabel; |
2 |
26 Feb 07 |
jari |
280 |
private JTextField xAxisField; |
2 |
26 Feb 07 |
jari |
281 |
private StrokePreviewBox xAxisLineBox; |
2 |
26 Feb 07 |
jari |
282 |
private JComboBox xAxisColorBox; |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
284 |
private MyCellRenderer renderer; |
2 |
26 Feb 07 |
jari |
285 |
|
2 |
26 Feb 07 |
jari |
286 |
public YScalePanel() { |
2 |
26 Feb 07 |
jari |
287 |
|
2 |
26 Feb 07 |
jari |
288 |
super(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
289 |
|
2 |
26 Feb 07 |
jari |
290 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
291 |
ParameterPanel rangeOptionPanel = new ParameterPanel("Y Range Options"); |
2 |
26 Feb 07 |
jari |
292 |
rangeOptionPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
293 |
ButtonGroup bg = new ButtonGroup(); |
2 |
26 Feb 07 |
jari |
294 |
|
2 |
26 Feb 07 |
jari |
//intial option, external display setting |
2 |
26 Feb 07 |
jari |
296 |
displaySettingRangeButton = new JRadioButton("External Display Menu Range Setting", true); |
2 |
26 Feb 07 |
jari |
297 |
displaySettingRangeButton.setOpaque(false); |
2 |
26 Feb 07 |
jari |
298 |
displaySettingRangeButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
299 |
displaySettingRangeButton.setActionCommand("y-range-selection-command"); |
2 |
26 Feb 07 |
jari |
300 |
displaySettingRangeButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
301 |
bg.add(displaySettingRangeButton); |
2 |
26 Feb 07 |
jari |
302 |
|
2 |
26 Feb 07 |
jari |
//second option, custom display option |
2 |
26 Feb 07 |
jari |
304 |
JSeparator sep1 = new JSeparator(JSeparator.HORIZONTAL); |
2 |
26 Feb 07 |
jari |
305 |
sep1.setPreferredSize(new Dimension(250,10)); |
2 |
26 Feb 07 |
jari |
306 |
sep1.setSize(250,10); |
2 |
26 Feb 07 |
jari |
307 |
customRangeButton = new JRadioButton("Custom Y Range"); |
2 |
26 Feb 07 |
jari |
308 |
customRangeButton.setOpaque(false); |
2 |
26 Feb 07 |
jari |
309 |
customRangeButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
310 |
customRangeButton.setActionCommand("y-range-selection-command"); |
2 |
26 Feb 07 |
jari |
311 |
customRangeButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
312 |
bg.add(customRangeButton); |
2 |
26 Feb 07 |
jari |
313 |
|
2 |
26 Feb 07 |
jari |
314 |
Dimension fieldDim = new Dimension(60, 20); |
2 |
26 Feb 07 |
jari |
315 |
minLabel = new JLabel("Minimum Value"); |
2 |
26 Feb 07 |
jari |
316 |
minField = new JTextField(((Float)(props.get("y-axis-min"))).toString()); |
2 |
26 Feb 07 |
jari |
317 |
minField.setPreferredSize(fieldDim); |
2 |
26 Feb 07 |
jari |
318 |
minField.setSize(fieldDim); |
2 |
26 Feb 07 |
jari |
319 |
maxLabel = new JLabel("Maximum Value"); |
2 |
26 Feb 07 |
jari |
320 |
maxField = new JTextField(((Float)(props.get("y-axis-max"))).toString()); |
2 |
26 Feb 07 |
jari |
321 |
maxField.setPreferredSize(fieldDim); |
2 |
26 Feb 07 |
jari |
322 |
maxField.setSize(fieldDim); |
2 |
26 Feb 07 |
jari |
323 |
ticLabel = new JLabel("Tick Interval"); |
2 |
26 Feb 07 |
jari |
324 |
ticIntervalField = new JTextField(((Float)(props.get("y-axis-tic-interval"))).toString()); |
2 |
26 Feb 07 |
jari |
325 |
ticIntervalField.setPreferredSize(fieldDim); |
2 |
26 Feb 07 |
jari |
326 |
ticIntervalField.setSize(fieldDim); |
2 |
26 Feb 07 |
jari |
327 |
|
2 |
26 Feb 07 |
jari |
//last option |
2 |
26 Feb 07 |
jari |
//JSeparator sep2 = new JSeparator(JSeparator.HORIZONTAL); |
2 |
26 Feb 07 |
jari |
//sep2.setPreferredSize(new Dimension(250,10)); |
2 |
26 Feb 07 |
jari |
//sep1.setSize(250,10); |
2 |
26 Feb 07 |
jari |
332 |
|
2 |
26 Feb 07 |
jari |
//globalAutoFitButton = new JRadioButton("Autofit to Data Range"); |
2 |
26 Feb 07 |
jari |
//globalAutoFitButton.setOpaque(false); |
2 |
26 Feb 07 |
jari |
//globalAutoFitButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
//globalAutoFitButton.setActionCommand("y-range-selection-command"); |
2 |
26 Feb 07 |
jari |
//globalAutoFitButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
//bg.add(globalAutoFitButton); |
2 |
26 Feb 07 |
jari |
339 |
|
2 |
26 Feb 07 |
jari |
//symetricRangeBox = new JCheckBox("Symetric Range about y=0"); |
2 |
26 Feb 07 |
jari |
//symetricRangeBox.setOpaque(false); |
2 |
26 Feb 07 |
jari |
//symetricRangeBox.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
//symetricRangeBox.setSelected(((Boolean)(props.get("y-axis-symetry"))).booleanValue()); |
2 |
26 Feb 07 |
jari |
344 |
|
2 |
26 Feb 07 |
jari |
//load the range panel |
2 |
26 Feb 07 |
jari |
346 |
rangeOptionPanel.add(displaySettingRangeButton, new GridBagConstraints(0,0,2,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,10,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
347 |
rangeOptionPanel.add(sep1, new GridBagConstraints(0,1,2,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
348 |
rangeOptionPanel.add(customRangeButton, new GridBagConstraints(0,2,2,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,10,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
349 |
rangeOptionPanel.add(minLabel, new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0,10,5,15),0,0)); |
2 |
26 Feb 07 |
jari |
350 |
rangeOptionPanel.add(minField, new GridBagConstraints(1,3,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0,0,5,0),0,0)); |
2 |
26 Feb 07 |
jari |
351 |
rangeOptionPanel.add(maxLabel, new GridBagConstraints(0,4,1,1,0,0,GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0,10,5,15),0,0)); |
2 |
26 Feb 07 |
jari |
352 |
rangeOptionPanel.add(maxField, new GridBagConstraints(1,4,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0,0,5,0),0,0)); |
2 |
26 Feb 07 |
jari |
353 |
rangeOptionPanel.add(ticLabel, new GridBagConstraints(0,5,1,1,0,0,GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0,10,10,15),0,0)); |
2 |
26 Feb 07 |
jari |
354 |
rangeOptionPanel.add(ticIntervalField, new GridBagConstraints(1,5,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0,0,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
//rangeOptionPanel.add(sep2, new GridBagConstraints(0,6,2,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
356 |
|
2 |
26 Feb 07 |
jari |
//rangeOptionPanel.add(globalAutoFitButton, new GridBagConstraints(0,7,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,10,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
//rangeOptionPanel.add(symetricRangeBox, new GridBagConstraints(1,7,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
359 |
|
2 |
26 Feb 07 |
jari |
360 |
ParameterPanel xAxisOptionPanel = new ParameterPanel("X Axis Display Options"); |
2 |
26 Feb 07 |
jari |
361 |
xAxisOptionPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
362 |
|
2 |
26 Feb 07 |
jari |
363 |
showXAxisBox = new JCheckBox("Show X Axis Line"); |
2 |
26 Feb 07 |
jari |
364 |
showXAxisBox.setOpaque(false); |
2 |
26 Feb 07 |
jari |
365 |
showXAxisBox.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
366 |
showXAxisBox.setActionCommand("y-range-selection-command"); |
2 |
26 Feb 07 |
jari |
367 |
showXAxisBox.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
368 |
showXAxisBox.setSelected(((Boolean)(props.get("show-x-axis"))).booleanValue()); |
2 |
26 Feb 07 |
jari |
369 |
|
2 |
26 Feb 07 |
jari |
370 |
xAxisCrossesLabel = new JLabel("X axis crosses at"); |
2 |
26 Feb 07 |
jari |
371 |
xAxisCrossesLabel.setOpaque(false); |
2 |
26 Feb 07 |
jari |
372 |
|
2 |
26 Feb 07 |
jari |
373 |
xAxisField = new JTextField(((Float)(props.get("x-axis-cross-point"))).toString()); |
2 |
26 Feb 07 |
jari |
374 |
xAxisField.setPreferredSize(fieldDim); |
2 |
26 Feb 07 |
jari |
375 |
xAxisField.setSize(fieldDim); |
2 |
26 Feb 07 |
jari |
376 |
|
2 |
26 Feb 07 |
jari |
377 |
xAxisLineBox = new StrokePreviewBox(); |
2 |
26 Feb 07 |
jari |
378 |
Dimension dim = new Dimension(80,18); |
2 |
26 Feb 07 |
jari |
379 |
xAxisLineBox.setPreferredSize(dim); |
2 |
26 Feb 07 |
jari |
380 |
xAxisLineBox.setSize(dim); |
2 |
26 Feb 07 |
jari |
381 |
|
2 |
26 Feb 07 |
jari |
382 |
StrokePreview currStrokePreview = new StrokePreview((BasicStroke)(props.get("x-axis-stroke"))); |
2 |
26 Feb 07 |
jari |
383 |
|
2 |
26 Feb 07 |
jari |
384 |
for(int i = 0; i < xAxisLineBox.getItemCount(); i++) { |
2 |
26 Feb 07 |
jari |
385 |
if(((StrokePreview)(xAxisLineBox.getItemAt(i))).compareTo(currStrokePreview) == 0) { |
2 |
26 Feb 07 |
jari |
386 |
xAxisLineBox.setSelectedIndex(i); |
2 |
26 Feb 07 |
jari |
387 |
break; |
2 |
26 Feb 07 |
jari |
388 |
} |
2 |
26 Feb 07 |
jari |
389 |
} |
2 |
26 Feb 07 |
jari |
390 |
|
2 |
26 Feb 07 |
jari |
391 |
|
2 |
26 Feb 07 |
jari |
392 |
xAxisLineBox.setSelectedItem(new StrokePreview((BasicStroke)(props.get("x-axis-stroke")))); |
2 |
26 Feb 07 |
jari |
393 |
((StrokePreview)(xAxisLineBox.getSelectedItem())).setSelected(true); |
2 |
26 Feb 07 |
jari |
394 |
|
2 |
26 Feb 07 |
jari |
395 |
Vector v = new Vector(); |
2 |
26 Feb 07 |
jari |
396 |
v.add(Color.lightGray); |
2 |
26 Feb 07 |
jari |
397 |
v.add(new Color(150, 150, 250)); |
2 |
26 Feb 07 |
jari |
398 |
v.add(Color.gray); |
2 |
26 Feb 07 |
jari |
399 |
v.add(Color.black); |
2 |
26 Feb 07 |
jari |
400 |
v.add("Customize"); |
2 |
26 Feb 07 |
jari |
401 |
|
2 |
26 Feb 07 |
jari |
402 |
xAxisColorBox = new JComboBox(v); |
2 |
26 Feb 07 |
jari |
403 |
xAxisColorBox.setBackground((Color)xAxisColorBox.getSelectedItem()); |
2 |
26 Feb 07 |
jari |
404 |
xAxisColorBox.setEditable(false); |
2 |
26 Feb 07 |
jari |
405 |
xAxisColorBox.setOpaque(true); |
2 |
26 Feb 07 |
jari |
406 |
|
2 |
26 Feb 07 |
jari |
407 |
Color currXAxisColor = (Color)(props.get("x-axis-color")); |
2 |
26 Feb 07 |
jari |
408 |
xAxisColorBox.setBackground(currXAxisColor); |
2 |
26 Feb 07 |
jari |
409 |
|
2 |
26 Feb 07 |
jari |
410 |
if(currXAxisColor.equals(Color.gray) |
2 |
26 Feb 07 |
jari |
411 |
|| currXAxisColor.equals(Color.black) |
2 |
26 Feb 07 |
jari |
412 |
|| currXAxisColor.equals(new Color(150,150,250))) { |
2 |
26 Feb 07 |
jari |
413 |
xAxisColorBox.setSelectedItem(currXAxisColor); |
2 |
26 Feb 07 |
jari |
414 |
renderer = new MyCellRenderer(); |
2 |
26 Feb 07 |
jari |
415 |
} else { |
2 |
26 Feb 07 |
jari |
416 |
xAxisColorBox.setSelectedIndex(3); |
2 |
26 Feb 07 |
jari |
417 |
renderer = new MyCellRenderer(currXAxisColor); |
2 |
26 Feb 07 |
jari |
418 |
} |
2 |
26 Feb 07 |
jari |
419 |
|
2 |
26 Feb 07 |
jari |
420 |
xAxisColorBox.setRenderer(renderer); |
2 |
26 Feb 07 |
jari |
421 |
|
2 |
26 Feb 07 |
jari |
422 |
xAxisColorBox.setPreferredSize(dim); |
2 |
26 Feb 07 |
jari |
423 |
xAxisColorBox.setSize(dim); |
2 |
26 Feb 07 |
jari |
424 |
xAxisColorBox.addActionListener(new ListListener()); |
2 |
26 Feb 07 |
jari |
425 |
|
2 |
26 Feb 07 |
jari |
426 |
xAxisOptionPanel.add(showXAxisBox, new GridBagConstraints(0,0,2,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,10,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
//xAxisOptionPanel.add(xAxisCrossesLabel, new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
//xAxisOptionPanel.add(xAxisField, new GridBagConstraints(1,1,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
429 |
|
2 |
26 Feb 07 |
jari |
430 |
JPanel xCrossesPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
431 |
xCrossesPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
432 |
Dimension panDim = new Dimension(200, 20); |
2 |
26 Feb 07 |
jari |
433 |
xCrossesPanel.setPreferredSize(panDim); |
2 |
26 Feb 07 |
jari |
434 |
xCrossesPanel.setSize(panDim); |
2 |
26 Feb 07 |
jari |
435 |
|
2 |
26 Feb 07 |
jari |
436 |
xCrossesPanel.add(xAxisCrossesLabel, new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
437 |
xCrossesPanel.add(xAxisField, new GridBagConstraints(1,0,1,1,1,1,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
438 |
xAxisOptionPanel.add(xCrossesPanel, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0,10,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
439 |
|
2 |
26 Feb 07 |
jari |
440 |
JPanel fillPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
441 |
fillPanel.setPreferredSize(panDim); |
2 |
26 Feb 07 |
jari |
442 |
fillPanel.setSize(panDim); |
2 |
26 Feb 07 |
jari |
443 |
fillPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
444 |
xAxisOptionPanel.add(fillPanel, new GridBagConstraints(1,1,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
445 |
|
2 |
26 Feb 07 |
jari |
446 |
lineLabel = new JLabel("Line Style"); |
2 |
26 Feb 07 |
jari |
447 |
colorLabel = new JLabel("Line Color"); |
2 |
26 Feb 07 |
jari |
448 |
xAxisOptionPanel.add(lineLabel, new GridBagConstraints(0,2,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,10,4,10),0,0)); |
2 |
26 Feb 07 |
jari |
449 |
xAxisOptionPanel.add(colorLabel, new GridBagConstraints(1,2,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,0,4,10),0,0)); |
2 |
26 Feb 07 |
jari |
450 |
|
2 |
26 Feb 07 |
jari |
451 |
xAxisOptionPanel.add(xAxisLineBox, new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,10,10,10),0,0)); |
2 |
26 Feb 07 |
jari |
452 |
xAxisOptionPanel.add(xAxisColorBox, new GridBagConstraints(1,3,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,10),0,0)); |
2 |
26 Feb 07 |
jari |
453 |
|
2 |
26 Feb 07 |
jari |
454 |
add(rangeOptionPanel, new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
455 |
add(xAxisOptionPanel, new GridBagConstraints(0,1,1,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
456 |
|
2 |
26 Feb 07 |
jari |
//Set range option selection |
2 |
26 Feb 07 |
jari |
458 |
int rangeMode = ((Integer)(props.get("y-range-mode"))).intValue(); |
2 |
26 Feb 07 |
jari |
459 |
if(rangeMode == GraphScaleCustomizationDialog.YRANGE_OPTION_DISPLAY_MENU) |
2 |
26 Feb 07 |
jari |
460 |
this.displaySettingRangeButton.setSelected(true); |
2 |
26 Feb 07 |
jari |
461 |
else if(rangeMode == GraphScaleCustomizationDialog.YRANGE_OPTION_CUSTOM_RANGE) |
2 |
26 Feb 07 |
jari |
462 |
this.customRangeButton.setSelected(true); |
2 |
26 Feb 07 |
jari |
//else |
2 |
26 Feb 07 |
jari |
//this.globalAutoFitButton.setSelected(true); |
2 |
26 Feb 07 |
jari |
465 |
|
2 |
26 Feb 07 |
jari |
466 |
|
2 |
26 Feb 07 |
jari |
467 |
updateForRangeModeSelection(); |
2 |
26 Feb 07 |
jari |
468 |
} |
2 |
26 Feb 07 |
jari |
469 |
|
2 |
26 Feb 07 |
jari |
470 |
|
2 |
26 Feb 07 |
jari |
471 |
|
2 |
26 Feb 07 |
jari |
472 |
/** |
2 |
26 Feb 07 |
jari |
* refreshes state of control based on range mode * |
2 |
26 Feb 07 |
jari |
474 |
*/ |
2 |
26 Feb 07 |
jari |
475 |
private void updateForRangeModeSelection() { |
2 |
26 Feb 07 |
jari |
476 |
minField.setEnabled(this.customRangeButton.isSelected()); |
2 |
26 Feb 07 |
jari |
477 |
minLabel.setEnabled(this.customRangeButton.isSelected()); |
2 |
26 Feb 07 |
jari |
478 |
maxField.setEnabled(this.customRangeButton.isSelected()); |
2 |
26 Feb 07 |
jari |
479 |
maxLabel.setEnabled(this.customRangeButton.isSelected()); |
2 |
26 Feb 07 |
jari |
480 |
ticIntervalField.setEnabled(this.customRangeButton.isSelected()); |
2 |
26 Feb 07 |
jari |
481 |
ticLabel.setEnabled(this.customRangeButton.isSelected()); |
2 |
26 Feb 07 |
jari |
//this.symetricRangeBox.setEnabled(this.globalAutoFitButton.isSelected()); |
2 |
26 Feb 07 |
jari |
483 |
this.xAxisCrossesLabel.setEnabled(this.showXAxisBox.isSelected()); |
2 |
26 Feb 07 |
jari |
484 |
this.xAxisField.setEnabled(this.showXAxisBox.isSelected()); |
2 |
26 Feb 07 |
jari |
485 |
this.colorLabel.setEnabled(this.showXAxisBox.isSelected()); |
2 |
26 Feb 07 |
jari |
486 |
this.lineLabel.setEnabled(this.showXAxisBox.isSelected()); |
2 |
26 Feb 07 |
jari |
487 |
this.xAxisLineBox.setEnabled(this.showXAxisBox.isSelected()); |
2 |
26 Feb 07 |
jari |
488 |
this.xAxisColorBox.setEnabled(this.showXAxisBox.isSelected()); |
2 |
26 Feb 07 |
jari |
489 |
} |
2 |
26 Feb 07 |
jari |
490 |
|
2 |
26 Feb 07 |
jari |
491 |
/** |
2 |
26 Feb 07 |
jari |
* Opens a color chooser for axis color selection. |
2 |
26 Feb 07 |
jari |
* @param startColor current color |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
495 |
*/ |
2 |
26 Feb 07 |
jari |
496 |
public Color setCustomXAxisColor(Color startColor) { |
2 |
26 Feb 07 |
jari |
497 |
Color color = JColorChooser.showDialog(this, "Custom X-Axis Color", startColor); |
2 |
26 Feb 07 |
jari |
498 |
if(color != null) |
2 |
26 Feb 07 |
jari |
499 |
renderer.setCustomColor(color); |
2 |
26 Feb 07 |
jari |
500 |
repaint(); |
2 |
26 Feb 07 |
jari |
501 |
return color; |
2 |
26 Feb 07 |
jari |
502 |
} |
2 |
26 Feb 07 |
jari |
503 |
|
2 |
26 Feb 07 |
jari |
504 |
/** |
2 |
26 Feb 07 |
jari |
* returns the current axis color |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
507 |
*/ |
2 |
26 Feb 07 |
jari |
508 |
public Color getCustomXAxisColor() { |
2 |
26 Feb 07 |
jari |
509 |
return renderer.getCustomColor(); |
2 |
26 Feb 07 |
jari |
510 |
} |
2 |
26 Feb 07 |
jari |
511 |
|
2 |
26 Feb 07 |
jari |
512 |
|
2 |
26 Feb 07 |
jari |
513 |
} |
2 |
26 Feb 07 |
jari |
514 |
|
2 |
26 Feb 07 |
jari |
515 |
|
2 |
26 Feb 07 |
jari |
516 |
/** |
2 |
26 Feb 07 |
jari |
517 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
519 |
* |
2 |
26 Feb 07 |
jari |
* JPanel extension to render a preview |
2 |
26 Feb 07 |
jari |
521 |
*/ |
2 |
26 Feb 07 |
jari |
522 |
public class GraphRenderingPanel extends JPanel { |
2 |
26 Feb 07 |
jari |
523 |
|
2 |
26 Feb 07 |
jari |
524 |
private JRadioButton offsetLineButton; |
2 |
26 Feb 07 |
jari |
525 |
private JRadioButton connectPointsButton; |
2 |
26 Feb 07 |
jari |
526 |
|
2 |
26 Feb 07 |
jari |
527 |
private JTextField midPointField; |
2 |
26 Feb 07 |
jari |
528 |
private JTextField maxField; |
2 |
26 Feb 07 |
jari |
529 |
private JTextField minField; |
2 |
26 Feb 07 |
jari |
530 |
|
2 |
26 Feb 07 |
jari |
531 |
private JCheckBox discreteOverlayBox; |
2 |
26 Feb 07 |
jari |
532 |
private GraphPreview preview; |
2 |
26 Feb 07 |
jari |
533 |
|
2 |
26 Feb 07 |
jari |
534 |
|
2 |
26 Feb 07 |
jari |
535 |
public GraphRenderingPanel() { |
2 |
26 Feb 07 |
jari |
536 |
super(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
537 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
538 |
PreviewListener listener = new PreviewListener(); |
2 |
26 Feb 07 |
jari |
539 |
|
2 |
26 Feb 07 |
jari |
540 |
ButtonGroup bg = new ButtonGroup(); |
2 |
26 Feb 07 |
jari |
541 |
|
2 |
26 Feb 07 |
jari |
542 |
offsetLineButton = new JRadioButton("Offset Lines from Midpoint"); |
2 |
26 Feb 07 |
jari |
543 |
offsetLineButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
544 |
offsetLineButton.setOpaque(false); |
2 |
26 Feb 07 |
jari |
545 |
offsetLineButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
546 |
bg.add(offsetLineButton); |
2 |
26 Feb 07 |
jari |
547 |
|
2 |
26 Feb 07 |
jari |
548 |
minField = new JTextField(((Float)(props.get("offset-graph-min"))).toString()); |
2 |
26 Feb 07 |
jari |
549 |
midPointField = new JTextField(((Float)(props.get("offset-graph-midpoint"))).toString()); |
2 |
26 Feb 07 |
jari |
550 |
maxField = new JTextField(((Float)(props.get("offset-graph-max"))).toString()); |
2 |
26 Feb 07 |
jari |
551 |
|
2 |
26 Feb 07 |
jari |
552 |
connectPointsButton = new JRadioButton("Connect Points"); |
2 |
26 Feb 07 |
jari |
553 |
connectPointsButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
554 |
connectPointsButton.setOpaque(false); |
2 |
26 Feb 07 |
jari |
555 |
connectPointsButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
556 |
bg.add(connectPointsButton); |
2 |
26 Feb 07 |
jari |
557 |
|
2 |
26 Feb 07 |
jari |
558 |
discreteOverlayBox = new JCheckBox("Discrete Value Overlay"); |
2 |
26 Feb 07 |
jari |
559 |
discreteOverlayBox.setOpaque(false); |
2 |
26 Feb 07 |
jari |
560 |
discreteOverlayBox.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
561 |
discreteOverlayBox.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
562 |
|
2 |
26 Feb 07 |
jari |
563 |
offsetLineButton.setSelected(((Boolean)(props.get("offset-lines-mode"))).booleanValue()); |
2 |
26 Feb 07 |
jari |
564 |
connectPointsButton.setSelected(!((Boolean)(props.get("offset-lines-mode"))).booleanValue()); |
2 |
26 Feb 07 |
jari |
565 |
discreteOverlayBox.setSelected(((Boolean)(props.get("show-discrete-overlay"))).booleanValue()); |
2 |
26 Feb 07 |
jari |
566 |
|
2 |
26 Feb 07 |
jari |
567 |
|
2 |
26 Feb 07 |
jari |
568 |
preview = new GraphPreview(offsetLineButton.isSelected(), discreteOverlayBox.isSelected()); |
2 |
26 Feb 07 |
jari |
569 |
|
2 |
26 Feb 07 |
jari |
570 |
add(offsetLineButton, new GridBagConstraints(0,0,2,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,0,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
571 |
|
2 |
26 Feb 07 |
jari |
572 |
add(new JLabel("Lower Cutoff"), new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20,15,10,10), 0,0)); |
2 |
26 Feb 07 |
jari |
573 |
add(minField, new GridBagConstraints(1,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
574 |
|
2 |
26 Feb 07 |
jari |
575 |
add(new JLabel("Neutral Point"), new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,15,10,10), 0,0)); |
2 |
26 Feb 07 |
jari |
576 |
add(midPointField, new GridBagConstraints(1,2,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
577 |
|
2 |
26 Feb 07 |
jari |
578 |
add(new JLabel("Upper Cutoff"), new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,15,10,10), 0,0)); |
2 |
26 Feb 07 |
jari |
579 |
add(maxField, new GridBagConstraints(1,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
580 |
|
2 |
26 Feb 07 |
jari |
581 |
add(discreteOverlayBox, new GridBagConstraints(0,4,2,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,15,20,0), 0,0)); |
2 |
26 Feb 07 |
jari |
582 |
|
2 |
26 Feb 07 |
jari |
583 |
add(connectPointsButton, new GridBagConstraints(0,5,2,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
584 |
add(preview, new GridBagConstraints(2,0,1,6,0,0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0,20,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
585 |
} |
2 |
26 Feb 07 |
jari |
586 |
|
2 |
26 Feb 07 |
jari |
587 |
public boolean isOffsetLinesModeSelected() { |
2 |
26 Feb 07 |
jari |
588 |
return this.offsetLineButton.isSelected(); |
2 |
26 Feb 07 |
jari |
589 |
} |
2 |
26 Feb 07 |
jari |
590 |
|
2 |
26 Feb 07 |
jari |
591 |
public float getOffsetMidpoint() { |
2 |
26 Feb 07 |
jari |
592 |
return Float.parseFloat(this.midPointField.getText()); |
2 |
26 Feb 07 |
jari |
593 |
} |
2 |
26 Feb 07 |
jari |
594 |
|
2 |
26 Feb 07 |
jari |
595 |
public float getOffsetMax() { |
2 |
26 Feb 07 |
jari |
596 |
return Float.parseFloat(this.maxField.getText()); |
2 |
26 Feb 07 |
jari |
597 |
} |
2 |
26 Feb 07 |
jari |
598 |
|
2 |
26 Feb 07 |
jari |
599 |
public float getOffsetMin() { |
2 |
26 Feb 07 |
jari |
600 |
return Float.parseFloat(this.minField.getText()); |
2 |
26 Feb 07 |
jari |
601 |
} |
2 |
26 Feb 07 |
jari |
602 |
|
2 |
26 Feb 07 |
jari |
603 |
public boolean getShowOverlay() { |
2 |
26 Feb 07 |
jari |
604 |
return discreteOverlayBox.isSelected(); |
2 |
26 Feb 07 |
jari |
605 |
} |
2 |
26 Feb 07 |
jari |
606 |
|
2 |
26 Feb 07 |
jari |
607 |
|
2 |
26 Feb 07 |
jari |
608 |
public class GraphPreview extends ParameterPanel { |
2 |
26 Feb 07 |
jari |
609 |
|
2 |
26 Feb 07 |
jari |
610 |
float [] previewValues; |
2 |
26 Feb 07 |
jari |
611 |
boolean offsetMode; |
2 |
26 Feb 07 |
jari |
612 |
float min = 0.3f; |
2 |
26 Feb 07 |
jari |
613 |
float max = 0.8f; |
2 |
26 Feb 07 |
jari |
614 |
float mid = 0.5f; |
2 |
26 Feb 07 |
jari |
615 |
|
2 |
26 Feb 07 |
jari |
616 |
boolean discreteOverlay; |
2 |
26 Feb 07 |
jari |
617 |
|
2 |
26 Feb 07 |
jari |
618 |
public GraphPreview(boolean offsetMode, boolean discreteOverlay) { |
2 |
26 Feb 07 |
jari |
619 |
super("Preview"); |
2 |
26 Feb 07 |
jari |
620 |
this.offsetMode = offsetMode; |
2 |
26 Feb 07 |
jari |
621 |
this.discreteOverlay = discreteOverlay; |
2 |
26 Feb 07 |
jari |
622 |
previewValues = new float[10]; |
2 |
26 Feb 07 |
jari |
623 |
previewValues[0] = 0.85f; |
2 |
26 Feb 07 |
jari |
624 |
previewValues[1] = 0.90f; |
2 |
26 Feb 07 |
jari |
625 |
previewValues[2] = 0.83f; |
2 |
26 Feb 07 |
jari |
626 |
previewValues[3] = 0.91f; |
2 |
26 Feb 07 |
jari |
627 |
previewValues[4] = 0.43f; |
2 |
26 Feb 07 |
jari |
628 |
previewValues[5] = 0.55f; |
2 |
26 Feb 07 |
jari |
629 |
previewValues[6] = 0.45f; |
2 |
26 Feb 07 |
jari |
630 |
previewValues[7] = 0.2f; |
2 |
26 Feb 07 |
jari |
631 |
previewValues[8] = 0.25f; |
2 |
26 Feb 07 |
jari |
632 |
previewValues[9] = 0.22f; |
2 |
26 Feb 07 |
jari |
633 |
|
2 |
26 Feb 07 |
jari |
634 |
setPreferredSize(new Dimension(200,200)); |
2 |
26 Feb 07 |
jari |
635 |
} |
2 |
26 Feb 07 |
jari |
636 |
|
2 |
26 Feb 07 |
jari |
637 |
public void enableOffsetMode(boolean isOffset) { |
2 |
26 Feb 07 |
jari |
638 |
offsetMode = isOffset; |
2 |
26 Feb 07 |
jari |
639 |
} |
2 |
26 Feb 07 |
jari |
640 |
|
2 |
26 Feb 07 |
jari |
641 |
public void enableOverlay(boolean enable) { |
2 |
26 Feb 07 |
jari |
642 |
this.discreteOverlay = enable; |
2 |
26 Feb 07 |
jari |
643 |
} |
2 |
26 Feb 07 |
jari |
644 |
|
2 |
26 Feb 07 |
jari |
645 |
public void paint(Graphics g) { |
2 |
26 Feb 07 |
jari |
646 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
647 |
int w = getWidth(); |
2 |
26 Feb 07 |
jari |
648 |
int h = getHeight(); |
2 |
26 Feb 07 |
jari |
649 |
int xoffset = 25; |
2 |
26 Feb 07 |
jari |
650 |
int yoffset = 25; |
2 |
26 Feb 07 |
jari |
651 |
int x = xoffset; |
2 |
26 Feb 07 |
jari |
652 |
int y = yoffset; |
2 |
26 Feb 07 |
jari |
653 |
|
2 |
26 Feb 07 |
jari |
654 |
int xInt, yInt; |
2 |
26 Feb 07 |
jari |
655 |
|
2 |
26 Feb 07 |
jari |
656 |
Graphics2D g2 = (Graphics2D)g; |
2 |
26 Feb 07 |
jari |
657 |
Composite defaultComp = g2.getComposite(); |
2 |
26 Feb 07 |
jari |
658 |
|
2 |
26 Feb 07 |
jari |
659 |
xInt = (w-xoffset)/(previewValues.length-1); |
2 |
26 Feb 07 |
jari |
660 |
|
2 |
26 Feb 07 |
jari |
661 |
g.drawLine(xoffset/2, h/2+yoffset, w-xoffset/2, h/2+yoffset); |
2 |
26 Feb 07 |
jari |
662 |
|
2 |
26 Feb 07 |
jari |
663 |
int yLoc, yLoc1=0; |
2 |
26 Feb 07 |
jari |
664 |
|
2 |
26 Feb 07 |
jari |
665 |
if(discreteOverlay) { |
2 |
26 Feb 07 |
jari |
666 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); |
2 |
26 Feb 07 |
jari |
667 |
} else { |
2 |
26 Feb 07 |
jari |
668 |
g2.setComposite(defaultComp); |
2 |
26 Feb 07 |
jari |
669 |
} |
2 |
26 Feb 07 |
jari |
670 |
|
2 |
26 Feb 07 |
jari |
671 |
if(offsetMode) { |
2 |
26 Feb 07 |
jari |
672 |
for(int i = 0; i < previewValues.length;i++) { |
2 |
26 Feb 07 |
jari |
673 |
|
2 |
26 Feb 07 |
jari |
674 |
yLoc = (int)(h*(1f-previewValues[i]))+yoffset; |
2 |
26 Feb 07 |
jari |
675 |
|
2 |
26 Feb 07 |
jari |
676 |
if(previewValues[i]<min) |
2 |
26 Feb 07 |
jari |
677 |
g.setColor(Color.green); |
2 |
26 Feb 07 |
jari |
678 |
else if(previewValues[i]>max) |
2 |
26 Feb 07 |
jari |
679 |
g.setColor(Color.red); |
2 |
26 Feb 07 |
jari |
680 |
|
2 |
26 Feb 07 |
jari |
681 |
g.drawLine(xInt*i+xoffset/2,h/2+yoffset, xInt*i+xoffset/2, yLoc); |
2 |
26 Feb 07 |
jari |
682 |
|
2 |
26 Feb 07 |
jari |
683 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
684 |
g.fillOval(xInt*i+xoffset/2-2, yLoc, 4,4); |
2 |
26 Feb 07 |
jari |
685 |
|
2 |
26 Feb 07 |
jari |
686 |
} |
2 |
26 Feb 07 |
jari |
687 |
} else { |
2 |
26 Feb 07 |
jari |
688 |
for(int i = 0; i < previewValues.length-1;i++) { |
2 |
26 Feb 07 |
jari |
689 |
yLoc = (int)(h*(1f-previewValues[i]))+yoffset; |
2 |
26 Feb 07 |
jari |
690 |
yLoc1 = (int)(h*(1f-previewValues[i+1]))+yoffset; |
2 |
26 Feb 07 |
jari |
691 |
|
2 |
26 Feb 07 |
jari |
692 |
g.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
693 |
g.drawLine(xInt*i+xoffset/2,yLoc+2, xInt*(i+1)+xoffset/2, yLoc1+2); |
2 |
26 Feb 07 |
jari |
694 |
|
2 |
26 Feb 07 |
jari |
695 |
g.setColor(Color.blue); |
2 |
26 Feb 07 |
jari |
696 |
g.fillOval(xInt*i+xoffset/2-2, yLoc, 4,4); |
2 |
26 Feb 07 |
jari |
//g.fillOval(xInt*i+xoffset/2, yLoc1, 4,4); |
2 |
26 Feb 07 |
jari |
698 |
} |
2 |
26 Feb 07 |
jari |
699 |
g.setColor(Color.blue); |
2 |
26 Feb 07 |
jari |
700 |
g.fillOval(xInt*(previewValues.length-1)+xoffset/2-2, yLoc1, 4,4); |
2 |
26 Feb 07 |
jari |
701 |
} |
2 |
26 Feb 07 |
jari |
702 |
|
2 |
26 Feb 07 |
jari |
703 |
if(discreteOverlay) { |
2 |
26 Feb 07 |
jari |
//set default Composite |
2 |
26 Feb 07 |
jari |
705 |
g2.setComposite(defaultComp); |
2 |
26 Feb 07 |
jari |
706 |
g2.setStroke(new BasicStroke(2f)); |
2 |
26 Feb 07 |
jari |
707 |
g2.setColor(Color.black); |
2 |
26 Feb 07 |
jari |
708 |
|
2 |
26 Feb 07 |
jari |
709 |
int x1 = 0, x2 = 0; |
2 |
26 Feb 07 |
jari |
710 |
float prevY = mid; |
2 |
26 Feb 07 |
jari |
711 |
float currY = mid; |
2 |
26 Feb 07 |
jari |
712 |
|
2 |
26 Feb 07 |
jari |
//intialize previous y |
2 |
26 Feb 07 |
jari |
714 |
if(previewValues[0] >= max) |
2 |
26 Feb 07 |
jari |
715 |
prevY = max; |
2 |
26 Feb 07 |
jari |
716 |
else if(previewValues[0] <= min) |
2 |
26 Feb 07 |
jari |
717 |
prevY = min; |
2 |
26 Feb 07 |
jari |
718 |
else |
2 |
26 Feb 07 |
jari |
719 |
prevY = mid; |
2 |
26 Feb 07 |
jari |
720 |
|
2 |
26 Feb 07 |
jari |
721 |
|
2 |
26 Feb 07 |
jari |
722 |
for(int i = 1; i < previewValues.length;i++) { |
2 |
26 Feb 07 |
jari |
723 |
|
2 |
26 Feb 07 |
jari |
//set current y position |
2 |
26 Feb 07 |
jari |
725 |
if(previewValues[i] >= max) |
2 |
26 Feb 07 |
jari |
726 |
currY = max; |
2 |
26 Feb 07 |
jari |
727 |
else if(previewValues[i] <= min) |
2 |
26 Feb 07 |
jari |
728 |
currY = min; |
2 |
26 Feb 07 |
jari |
729 |
else |
2 |
26 Feb 07 |
jari |
730 |
currY = mid; |
2 |
26 Feb 07 |
jari |
731 |
|
2 |
26 Feb 07 |
jari |
//set current x position |
2 |
26 Feb 07 |
jari |
733 |
x2 = xInt*i+xoffset/2; |
2 |
26 Feb 07 |
jari |
734 |
x1 = x2-xInt; |
2 |
26 Feb 07 |
jari |
735 |
|
2 |
26 Feb 07 |
jari |
736 |
if(currY == prevY) { |
2 |
26 Feb 07 |
jari |
//draw a horizontal line from currY to prevY |
2 |
26 Feb 07 |
jari |
738 |
g.drawLine(x1, (int)(h*(1f-prevY))+yoffset, x2, (int)(h*(1f-currY))+yoffset); |
2 |
26 Feb 07 |
jari |
739 |
} else if(prevY == mid) { |
2 |
26 Feb 07 |
jari |
//draw horizontal on mid |
2 |
26 Feb 07 |
jari |
741 |
g.drawLine(x1, (int)(h*(1f-prevY))+yoffset, x2, (int)(h*(1f-prevY))+yoffset); |
2 |
26 Feb 07 |
jari |
//draw vertical line from mid to currY |
2 |
26 Feb 07 |
jari |
743 |
g.drawLine(x2, (int)(h*(1f-prevY))+yoffset, x2, (int)(h*(1f-currY))+yoffset); |
2 |
26 Feb 07 |
jari |
744 |
} else if(currY == mid) { |
2 |
26 Feb 07 |
jari |
//draw vertical line from prevY to mid |
2 |
26 Feb 07 |
jari |
746 |
g.drawLine(x1, (int)(h*(1f-prevY))+yoffset, x1, (int)(h*(1f-mid))+yoffset); |
2 |
26 Feb 07 |
jari |
//draw horizontal line from mid to mid |
2 |
26 Feb 07 |
jari |
748 |
g.drawLine(x1, (int)(h*(1f-mid))+yoffset, x2, (int)(h*(1f-mid))+yoffset); |
2 |
26 Feb 07 |
jari |
749 |
} else { |
2 |
26 Feb 07 |
jari |
//draw vertical line from prevY to mid |
2 |
26 Feb 07 |
jari |
751 |
g.drawLine(x1, (int)(h*(1f-prevY))+yoffset, x1, (int)(h*(1f-mid))+yoffset); |
2 |
26 Feb 07 |
jari |
//draw horizontal line from mid to mid |
2 |
26 Feb 07 |
jari |
753 |
g.drawLine(x1, (int)(h*(1f-mid))+yoffset, x2, (int)(h*(1f-mid))+yoffset); |
2 |
26 Feb 07 |
jari |
//draw vertical line from mid to currY |
2 |
26 Feb 07 |
jari |
755 |
g.drawLine(x2, (int)(h*(1f-mid))+yoffset, x2, (int)(h*(1f-currY))+yoffset); |
2 |
26 Feb 07 |
jari |
756 |
} |
2 |
26 Feb 07 |
jari |
757 |
|
2 |
26 Feb 07 |
jari |
758 |
prevY = currY; |
2 |
26 Feb 07 |
jari |
759 |
|
2 |
26 Feb 07 |
jari |
760 |
|
2 |
26 Feb 07 |
jari |
761 |
|
2 |
26 Feb 07 |
jari |
762 |
} |
2 |
26 Feb 07 |
jari |
763 |
|
2 |
26 Feb 07 |
jari |
764 |
} |
2 |
26 Feb 07 |
jari |
765 |
g2.setComposite(defaultComp); |
2 |
26 Feb 07 |
jari |
766 |
g2.setStroke(new BasicStroke(1f)); |
2 |
26 Feb 07 |
jari |
767 |
} |
2 |
26 Feb 07 |
jari |
768 |
|
2 |
26 Feb 07 |
jari |
769 |
|
2 |
26 Feb 07 |
jari |
770 |
} |
2 |
26 Feb 07 |
jari |
771 |
|
2 |
26 Feb 07 |
jari |
772 |
public class PreviewListener implements ActionListener { |
2 |
26 Feb 07 |
jari |
773 |
public void actionPerformed(ActionEvent ae) { |
2 |
26 Feb 07 |
jari |
774 |
preview.enableOffsetMode(offsetLineButton.isSelected()); |
2 |
26 Feb 07 |
jari |
775 |
preview.enableOverlay(discreteOverlayBox.isSelected()); |
2 |
26 Feb 07 |
jari |
776 |
preview.repaint(); |
2 |
26 Feb 07 |
jari |
777 |
} |
2 |
26 Feb 07 |
jari |
778 |
} |
2 |
26 Feb 07 |
jari |
779 |
} |
2 |
26 Feb 07 |
jari |
780 |
|
2 |
26 Feb 07 |
jari |
781 |
|
2 |
26 Feb 07 |
jari |
782 |
/** |
2 |
26 Feb 07 |
jari |
783 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
785 |
* |
2 |
26 Feb 07 |
jari |
* JComboBox extension to present line stroke options |
2 |
26 Feb 07 |
jari |
787 |
*/ |
2 |
26 Feb 07 |
jari |
788 |
public class StrokePreviewBox extends JComboBox { |
2 |
26 Feb 07 |
jari |
789 |
|
2 |
26 Feb 07 |
jari |
790 |
public StrokePreviewBox() { |
2 |
26 Feb 07 |
jari |
791 |
super(); |
2 |
26 Feb 07 |
jari |
792 |
this.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
793 |
this.setRenderer(new MyCellRenderer()); |
2 |
26 Feb 07 |
jari |
794 |
addItem(new StrokePreview(new BasicStroke(2f))); |
2 |
26 Feb 07 |
jari |
795 |
addItem(new StrokePreview(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {5f, 5f}, 0f))); |
2 |
26 Feb 07 |
jari |
796 |
addItem(new StrokePreview(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {2f, 2f}, 0f))); |
2 |
26 Feb 07 |
jari |
797 |
addItem(new StrokePreview(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {20f, 10f}, 0f))); |
2 |
26 Feb 07 |
jari |
798 |
addItem(new StrokePreview(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {20f, 5f, 5f, 5f}, 0f))); |
2 |
26 Feb 07 |
jari |
799 |
addItem(new StrokePreview(new BasicStroke(1f))); |
2 |
26 Feb 07 |
jari |
800 |
addItem(new StrokePreview(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {5f, 5f}, 0f))); |
2 |
26 Feb 07 |
jari |
801 |
addItem(new StrokePreview(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {2f, 2f}, 0f))); |
2 |
26 Feb 07 |
jari |
802 |
addItem(new StrokePreview(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {20f, 10f}, 0f))); |
2 |
26 Feb 07 |
jari |
803 |
addItem(new StrokePreview(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1f, new float[] {20f, 5f, 5f, 5f}, 0f))); |
2 |
26 Feb 07 |
jari |
804 |
} |
2 |
26 Feb 07 |
jari |
805 |
} |
2 |
26 Feb 07 |
jari |
806 |
|
2 |
26 Feb 07 |
jari |
807 |
public class ListListener implements ActionListener { |
2 |
26 Feb 07 |
jari |
808 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
809 |
JComboBox source = (JComboBox)e.getSource(); |
2 |
26 Feb 07 |
jari |
810 |
if(source.getSelectedItem() instanceof Color) |
2 |
26 Feb 07 |
jari |
811 |
source.setBackground((Color)source.getSelectedItem()); |
2 |
26 Feb 07 |
jari |
812 |
else { |
2 |
26 Feb 07 |
jari |
813 |
Color color = yPanel.setCustomXAxisColor(yPanel.getCustomXAxisColor()); |
2 |
26 Feb 07 |
jari |
814 |
if(color != null) { |
2 |
26 Feb 07 |
jari |
815 |
source.setBackground(color); |
2 |
26 Feb 07 |
jari |
816 |
} |
2 |
26 Feb 07 |
jari |
817 |
} |
2 |
26 Feb 07 |
jari |
818 |
|
2 |
26 Feb 07 |
jari |
819 |
} |
2 |
26 Feb 07 |
jari |
820 |
} |
2 |
26 Feb 07 |
jari |
821 |
|
2 |
26 Feb 07 |
jari |
822 |
/** |
2 |
26 Feb 07 |
jari |
823 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
825 |
* |
2 |
26 Feb 07 |
jari |
* JLabel extension to handle color selections |
2 |
26 Feb 07 |
jari |
827 |
*/ |
2 |
26 Feb 07 |
jari |
828 |
public class MyCellRenderer extends JLabel implements ListCellRenderer { |
2 |
26 Feb 07 |
jari |
829 |
|
2 |
26 Feb 07 |
jari |
830 |
boolean isSelected; |
2 |
26 Feb 07 |
jari |
831 |
Color customColor = Color.lightGray; |
2 |
26 Feb 07 |
jari |
832 |
|
2 |
26 Feb 07 |
jari |
833 |
public MyCellRenderer() { |
2 |
26 Feb 07 |
jari |
834 |
setPreferredSize(new Dimension(20,20)); |
2 |
26 Feb 07 |
jari |
835 |
setSize(20,20); |
2 |
26 Feb 07 |
jari |
836 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
837 |
setOpaque(true); |
2 |
26 Feb 07 |
jari |
838 |
} |
2 |
26 Feb 07 |
jari |
839 |
|
2 |
26 Feb 07 |
jari |
840 |
public MyCellRenderer(Color color) { |
2 |
26 Feb 07 |
jari |
841 |
setPreferredSize(new Dimension(20,20)); |
2 |
26 Feb 07 |
jari |
842 |
setSize(20,20); |
2 |
26 Feb 07 |
jari |
843 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
844 |
setOpaque(true); |
2 |
26 Feb 07 |
jari |
845 |
customColor = color; |
2 |
26 Feb 07 |
jari |
846 |
} |
2 |
26 Feb 07 |
jari |
847 |
|
2 |
26 Feb 07 |
jari |
848 |
public void setSelected(boolean selected) { |
2 |
26 Feb 07 |
jari |
849 |
this.isSelected = selected; |
2 |
26 Feb 07 |
jari |
850 |
} |
2 |
26 Feb 07 |
jari |
851 |
|
2 |
26 Feb 07 |
jari |
852 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
2 |
26 Feb 07 |
jari |
853 |
if(value instanceof Color) { |
2 |
26 Feb 07 |
jari |
854 |
setText(""); |
2 |
26 Feb 07 |
jari |
855 |
setBackground((Color)value); |
2 |
26 Feb 07 |
jari |
856 |
return this; |
2 |
26 Feb 07 |
jari |
857 |
} else if(value instanceof String){ |
2 |
26 Feb 07 |
jari |
858 |
setText("Custom Color"); |
2 |
26 Feb 07 |
jari |
859 |
setBackground(customColor); |
2 |
26 Feb 07 |
jari |
860 |
return this; |
2 |
26 Feb 07 |
jari |
861 |
} |
2 |
26 Feb 07 |
jari |
//return the object (StrokePreview) if it's not a Color object |
2 |
26 Feb 07 |
jari |
863 |
return (Component)value; |
2 |
26 Feb 07 |
jari |
864 |
} |
2 |
26 Feb 07 |
jari |
865 |
|
2 |
26 Feb 07 |
jari |
866 |
public void paint(Graphics g) { |
2 |
26 Feb 07 |
jari |
867 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
868 |
} |
2 |
26 Feb 07 |
jari |
869 |
|
2 |
26 Feb 07 |
jari |
870 |
public Color getCustomColor() { |
2 |
26 Feb 07 |
jari |
871 |
return customColor; |
2 |
26 Feb 07 |
jari |
872 |
} |
2 |
26 Feb 07 |
jari |
873 |
|
2 |
26 Feb 07 |
jari |
874 |
public void setCustomColor(Color c) { |
2 |
26 Feb 07 |
jari |
875 |
customColor = c; |
2 |
26 Feb 07 |
jari |
876 |
} |
2 |
26 Feb 07 |
jari |
877 |
|
2 |
26 Feb 07 |
jari |
878 |
} |
2 |
26 Feb 07 |
jari |
879 |
/** |
2 |
26 Feb 07 |
jari |
880 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
882 |
* |
2 |
26 Feb 07 |
jari |
* Stroke preview object |
2 |
26 Feb 07 |
jari |
884 |
*/ |
2 |
26 Feb 07 |
jari |
885 |
public class StrokePreview extends JLabel implements Comparable { |
2 |
26 Feb 07 |
jari |
886 |
private BasicStroke stroke; |
2 |
26 Feb 07 |
jari |
887 |
private boolean isSelected; |
2 |
26 Feb 07 |
jari |
888 |
|
2 |
26 Feb 07 |
jari |
889 |
public StrokePreview(BasicStroke stroke) { |
2 |
26 Feb 07 |
jari |
890 |
setOpaque(false); |
2 |
26 Feb 07 |
jari |
891 |
this.stroke = stroke; |
2 |
26 Feb 07 |
jari |
892 |
setPreferredSize(new Dimension(100, 20)); |
2 |
26 Feb 07 |
jari |
893 |
setSize(100,15); |
2 |
26 Feb 07 |
jari |
894 |
isSelected = false; |
2 |
26 Feb 07 |
jari |
895 |
} |
2 |
26 Feb 07 |
jari |
896 |
|
2 |
26 Feb 07 |
jari |
897 |
public BasicStroke getBasicStroke() { |
2 |
26 Feb 07 |
jari |
898 |
return stroke; |
2 |
26 Feb 07 |
jari |
899 |
} |
2 |
26 Feb 07 |
jari |
900 |
|
2 |
26 Feb 07 |
jari |
901 |
public void setSelected(boolean sel) { |
2 |
26 Feb 07 |
jari |
902 |
isSelected = sel; |
2 |
26 Feb 07 |
jari |
903 |
} |
2 |
26 Feb 07 |
jari |
904 |
|
2 |
26 Feb 07 |
jari |
905 |
public void paint(Graphics g) { |
2 |
26 Feb 07 |
jari |
906 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
907 |
Graphics2D g2 = (Graphics2D)g; |
2 |
26 Feb 07 |
jari |
908 |
Stroke origStroke = g2.getStroke(); |
2 |
26 Feb 07 |
jari |
909 |
g2.setStroke(stroke); |
2 |
26 Feb 07 |
jari |
910 |
g2.drawLine(3, getHeight()/2, getWidth()-3, getHeight()/2); |
2 |
26 Feb 07 |
jari |
911 |
g2.setStroke(origStroke); |
2 |
26 Feb 07 |
jari |
912 |
} |
2 |
26 Feb 07 |
jari |
913 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see java.lang.Comparable#compareTo(java.lang.Object) |
2 |
26 Feb 07 |
jari |
916 |
*/ |
2 |
26 Feb 07 |
jari |
917 |
public int compareTo(Object o) { |
2 |
26 Feb 07 |
jari |
918 |
StrokePreview other = (StrokePreview)o; |
2 |
26 Feb 07 |
jari |
919 |
|
2 |
26 Feb 07 |
jari |
920 |
if(other.getBasicStroke().equals(stroke)) |
2 |
26 Feb 07 |
jari |
921 |
return 0; |
2 |
26 Feb 07 |
jari |
922 |
else |
2 |
26 Feb 07 |
jari |
923 |
return 1; |
2 |
26 Feb 07 |
jari |
924 |
} |
2 |
26 Feb 07 |
jari |
925 |
|
2 |
26 Feb 07 |
jari |
926 |
} |
2 |
26 Feb 07 |
jari |
927 |
|
2 |
26 Feb 07 |
jari |
928 |
public class Listener implements ActionListener { |
2 |
26 Feb 07 |
jari |
929 |
|
2 |
26 Feb 07 |
jari |
930 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
931 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
932 |
if(command.equals("y-range-selection-command")) { |
2 |
26 Feb 07 |
jari |
933 |
yPanel.updateForRangeModeSelection(); |
2 |
26 Feb 07 |
jari |
934 |
} else if(command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
//check range parameters |
2 |
26 Feb 07 |
jari |
936 |
if(!validateRange()) { |
2 |
26 Feb 07 |
jari |
937 |
return; |
2 |
26 Feb 07 |
jari |
938 |
} |
2 |
26 Feb 07 |
jari |
939 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
940 |
dispose(); |
2 |
26 Feb 07 |
jari |
941 |
} else if(command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
942 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
943 |
dispose(); |
2 |
26 Feb 07 |
jari |
944 |
} else if(command.equals("")) { |
2 |
26 Feb 07 |
jari |
945 |
|
2 |
26 Feb 07 |
jari |
946 |
} else if(command.equals("")) { |
2 |
26 Feb 07 |
jari |
947 |
|
2 |
26 Feb 07 |
jari |
948 |
} |
2 |
26 Feb 07 |
jari |
949 |
} |
2 |
26 Feb 07 |
jari |
950 |
|
2 |
26 Feb 07 |
jari |
951 |
} |
2 |
26 Feb 07 |
jari |
952 |
|
2 |
26 Feb 07 |
jari |
953 |
} |