2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* Copyright @ 1999-2005, The Institute for Genomic Research (TIGR). All rights |
2 |
26 Feb 07 |
jari |
* reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
|
2 |
26 Feb 07 |
jari |
6 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: SetRatioScaleDialog.java,v $ $Revision: 1.5 $ $Date: 2005/02/10 |
2 |
26 Feb 07 |
jari |
* 16:06:10 $ $Author: caliente $ $State: Exp $ |
2 |
26 Feb 07 |
jari |
9 |
*/ |
2 |
26 Feb 07 |
jari |
10 |
package org.tigr.microarray.mev; |
2 |
26 Feb 07 |
jari |
11 |
|
2 |
26 Feb 07 |
jari |
12 |
|
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.FontMetrics; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.GradientPaint; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.event.KeyEvent; |
2 |
26 Feb 07 |
jari |
26 |
import java.awt.event.KeyListener; |
2 |
26 Feb 07 |
jari |
27 |
import java.awt.event.WindowAdapter; |
2 |
26 Feb 07 |
jari |
28 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
29 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
30 |
import java.text.DecimalFormat; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.ButtonGroup; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
35 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
36 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
37 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
38 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
39 |
import javax.swing.JRadioButton; |
2 |
26 Feb 07 |
jari |
40 |
import javax.swing.JSeparator; |
2 |
26 Feb 07 |
jari |
41 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
44 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
45 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
46 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
47 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel; |
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
49 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
50 |
import org.tigr.util.QSort; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
/** |
2 |
26 Feb 07 |
jari |
* Permits the alteration of color scale value range for rendering data |
2 |
26 Feb 07 |
jari |
* as color extracted from a gradient. Upper and Lower values represent the |
2 |
26 Feb 07 |
jari |
* values beyond which the color representation is staturated. (beyond color range) |
2 |
26 Feb 07 |
jari |
* Values within the range will be represented as a color from the gradient while |
2 |
26 Feb 07 |
jari |
* values outside the bounds of the range will be represented by the end colors of |
2 |
26 Feb 07 |
jari |
* the gradient or gradients. |
2 |
26 Feb 07 |
jari |
60 |
*/ |
2 |
26 Feb 07 |
jari |
61 |
|
2 |
26 Feb 07 |
jari |
62 |
public class SetRatioScaleDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
private int result; |
2 |
26 Feb 07 |
jari |
65 |
private boolean doubleGradient; |
2 |
26 Feb 07 |
jari |
66 |
private boolean origDoubleGradient; |
2 |
26 Feb 07 |
jari |
67 |
private BufferedImage origPosImage, origNegImage; |
2 |
26 Feb 07 |
jari |
68 |
private JTextField upperTextField, lowerTextField, midTextField; |
2 |
26 Feb 07 |
jari |
69 |
private JLabel midLabel; |
2 |
26 Feb 07 |
jari |
70 |
private JRadioButton singleGradientButton, doubleGradientButton; |
2 |
26 Feb 07 |
jari |
71 |
|
2 |
26 Feb 07 |
jari |
72 |
|
2 |
26 Feb 07 |
jari |
73 |
private float currMinValue, currMaxValue, currMidValue; |
2 |
26 Feb 07 |
jari |
74 |
private float origUpper, origLower, origMid; |
2 |
26 Feb 07 |
jari |
75 |
private String formattedUpper, formattedLower, formattedMid; |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
private StatsPanel statsPanel; |
2 |
26 Feb 07 |
jari |
78 |
private GradientPreviewPanel gradientPreviewPanel; |
2 |
26 Feb 07 |
jari |
79 |
private IFramework framework; |
2 |
26 Feb 07 |
jari |
80 |
private MultipleArrayMenubar menubar; |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
private DecimalFormat twoDecimalFormat, oneDecimalFormat; |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
85 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a new SetRatioScaleDialog |
2 |
26 Feb 07 |
jari |
87 |
* |
2 |
26 Feb 07 |
jari |
* @param parent parent frame |
2 |
26 Feb 07 |
jari |
* @param framework permits interaction with MultipleArrayViewer and data |
2 |
26 Feb 07 |
jari |
* @param menubar permits setting of new limits on update |
2 |
26 Feb 07 |
jari |
* @param upper current upper limit |
2 |
26 Feb 07 |
jari |
* @param lower current lower limit |
2 |
26 Feb 07 |
jari |
* @param doubleGradient true if the gradient is a double gradient |
2 |
26 Feb 07 |
jari |
94 |
*/ |
2 |
26 Feb 07 |
jari |
95 |
public SetRatioScaleDialog(JFrame parent, IFramework framework, MultipleArrayMenubar menubar, float upper, float lower, float mid, boolean doubleGradient) { |
2 |
26 Feb 07 |
jari |
96 |
super(parent, "Color Scale Limits", true); |
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
EventListener listener = new EventListener(); |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
Experiment experiment = framework.getData().getExperiment(); |
2 |
26 Feb 07 |
jari |
101 |
FloatMatrix matrix = experiment.getMatrix(); |
2 |
26 Feb 07 |
jari |
102 |
float [] extreems = experiment.getMinAndMax(); |
2 |
26 Feb 07 |
jari |
103 |
float minValue = extreems[0]; |
2 |
26 Feb 07 |
jari |
104 |
float maxValue = extreems[1]; |
2 |
26 Feb 07 |
jari |
105 |
this.menubar = menubar; |
2 |
26 Feb 07 |
jari |
106 |
this.doubleGradient = doubleGradient; |
2 |
26 Feb 07 |
jari |
107 |
this.origDoubleGradient = doubleGradient; |
2 |
26 Feb 07 |
jari |
108 |
|
2 |
26 Feb 07 |
jari |
109 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
110 |
origLower = lower; |
2 |
26 Feb 07 |
jari |
111 |
origUpper = upper; |
2 |
26 Feb 07 |
jari |
112 |
origMid = mid; |
2 |
26 Feb 07 |
jari |
113 |
origNegImage = framework.getDisplayMenu().getNegativeGradientImage(); |
2 |
26 Feb 07 |
jari |
114 |
origPosImage = framework.getDisplayMenu().getPositiveGradientImage(); |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
twoDecimalFormat = new DecimalFormat(); |
2 |
26 Feb 07 |
jari |
117 |
twoDecimalFormat.setMaximumFractionDigits(2); |
2 |
26 Feb 07 |
jari |
118 |
twoDecimalFormat.setMinimumFractionDigits(2); |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
oneDecimalFormat = new DecimalFormat(); |
2 |
26 Feb 07 |
jari |
121 |
oneDecimalFormat.setMaximumFractionDigits(1); |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
formattedUpper = twoDecimalFormat.format(origUpper); |
2 |
26 Feb 07 |
jari |
124 |
formattedLower = twoDecimalFormat.format(origLower); |
2 |
26 Feb 07 |
jari |
125 |
formattedMid = twoDecimalFormat.format(origMid); |
2 |
26 Feb 07 |
jari |
126 |
|
2 |
26 Feb 07 |
jari |
//build stats panel, get median value |
2 |
26 Feb 07 |
jari |
128 |
statsPanel = new StatsPanel(framework); |
2 |
26 Feb 07 |
jari |
129 |
float medianValue = statsPanel.getMedian(); |
2 |
26 Feb 07 |
jari |
130 |
|
2 |
26 Feb 07 |
jari |
131 |
ButtonGroup bg = new ButtonGroup(); |
2 |
26 Feb 07 |
jari |
132 |
|
2 |
26 Feb 07 |
jari |
133 |
doubleGradientButton = new JRadioButton("Double Gradient", doubleGradient); |
2 |
26 Feb 07 |
jari |
134 |
doubleGradientButton.setActionCommand("change-gradient-command"); |
2 |
26 Feb 07 |
jari |
135 |
doubleGradientButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
136 |
doubleGradientButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
137 |
doubleGradientButton.setOpaque(false); |
2 |
26 Feb 07 |
jari |
138 |
bg.add(doubleGradientButton); |
2 |
26 Feb 07 |
jari |
139 |
|
2 |
26 Feb 07 |
jari |
140 |
singleGradientButton = new JRadioButton("Single Gradient", !doubleGradient); |
2 |
26 Feb 07 |
jari |
141 |
singleGradientButton.setActionCommand("change-gradient-command"); |
2 |
26 Feb 07 |
jari |
142 |
singleGradientButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
143 |
singleGradientButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
144 |
singleGradientButton.setOpaque(false); |
2 |
26 Feb 07 |
jari |
145 |
bg.add(singleGradientButton); |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
//special case, rainbow scale is considered single gradient, and transition |
2 |
26 Feb 07 |
jari |
//to double from rainbow is not good. If rainbow disable double gradient option. |
2 |
26 Feb 07 |
jari |
149 |
if(framework.getDisplayMenu().getColorScheme() == IDisplayMenu.RAINBOW_COLOR_SCHEME) |
2 |
26 Feb 07 |
jari |
150 |
doubleGradientButton.setEnabled(false); |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
152 |
ParameterPanel gradientPanel = new ParameterPanel("Gradient Style"); |
2 |
26 Feb 07 |
jari |
153 |
gradientPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
154 |
gradientPanel.add(doubleGradientButton, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,0,10,20),0,0)); |
2 |
26 Feb 07 |
jari |
155 |
gradientPanel.add(singleGradientButton, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,20,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
156 |
|
2 |
26 Feb 07 |
jari |
157 |
DecimalFormat format = new DecimalFormat(); |
2 |
26 Feb 07 |
jari |
158 |
format.setMaximumFractionDigits(2); |
2 |
26 Feb 07 |
jari |
159 |
JLabel upperLabel = new JLabel("Upper Limit ( max. data value = " + format.format(maxValue) + " ): "); |
2 |
26 Feb 07 |
jari |
160 |
upperLabel.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
161 |
|
2 |
26 Feb 07 |
jari |
162 |
upperTextField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
163 |
upperTextField.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
164 |
upperTextField.setText("" + upper); |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
|
2 |
26 Feb 07 |
jari |
167 |
midLabel = new JLabel("Midpoint Value ( median data value = " + format.format(medianValue) + " ): "); |
2 |
26 Feb 07 |
jari |
168 |
midLabel.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
169 |
|
2 |
26 Feb 07 |
jari |
170 |
midTextField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
171 |
midTextField.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
172 |
midTextField.setText("" + mid); |
2 |
26 Feb 07 |
jari |
173 |
|
2 |
26 Feb 07 |
jari |
174 |
JLabel lowerLabel = new JLabel("Lower Limit ( min. data value = " + format.format(minValue) + " ): "); |
2 |
26 Feb 07 |
jari |
175 |
lowerLabel.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
lowerTextField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
178 |
lowerTextField.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
179 |
lowerTextField.setText("" + lower); |
2 |
26 Feb 07 |
jari |
180 |
|
2 |
26 Feb 07 |
jari |
181 |
JButton updateLimitsButton = new JButton("Update Limits"); |
2 |
26 Feb 07 |
jari |
182 |
updateLimitsButton.setPreferredSize(new Dimension(130,30)); |
2 |
26 Feb 07 |
jari |
183 |
updateLimitsButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
184 |
updateLimitsButton.setActionCommand("update-command"); |
2 |
26 Feb 07 |
jari |
185 |
updateLimitsButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
186 |
|
2 |
26 Feb 07 |
jari |
187 |
ParameterPanel rangePanel = new ParameterPanel("Color Range Selection"); |
2 |
26 Feb 07 |
jari |
188 |
rangePanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
189 |
rangePanel.add(lowerLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,0,10,10),0,0)); |
2 |
26 Feb 07 |
jari |
190 |
rangePanel.add(lowerTextField, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,0,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
191 |
|
2 |
26 Feb 07 |
jari |
192 |
rangePanel.add(midLabel, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,10),0,0)); |
2 |
26 Feb 07 |
jari |
193 |
rangePanel.add(midTextField, new GridBagConstraints(1,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
194 |
|
2 |
26 Feb 07 |
jari |
195 |
rangePanel.add(upperLabel, new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,25,10),0,0)); |
2 |
26 Feb 07 |
jari |
196 |
rangePanel.add(upperTextField, new GridBagConstraints(1,2,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,25,0),0,0)); |
2 |
26 Feb 07 |
jari |
197 |
rangePanel.add(updateLimitsButton, new GridBagConstraints(0,3,2,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,20,0),0,0)); |
2 |
26 Feb 07 |
jari |
198 |
|
2 |
26 Feb 07 |
jari |
199 |
ParameterPanel preview = new ParameterPanel("Gradient and Limits Preview"); |
2 |
26 Feb 07 |
jari |
200 |
preview.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
201 |
gradientPreviewPanel = new GradientPreviewPanel(framework); |
2 |
26 Feb 07 |
jari |
202 |
preview.add(gradientPreviewPanel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,10,10,10), 0,0)); |
2 |
26 Feb 07 |
jari |
203 |
|
2 |
26 Feb 07 |
jari |
204 |
JPanel mainPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
205 |
mainPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
206 |
|
2 |
26 Feb 07 |
jari |
207 |
mainPanel.add(gradientPanel,new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
208 |
mainPanel.add(rangePanel,new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
209 |
mainPanel.add(statsPanel, new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
210 |
mainPanel.add(preview, new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
211 |
|
2 |
26 Feb 07 |
jari |
212 |
addContent(mainPanel); |
2 |
26 Feb 07 |
jari |
213 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
214 |
setActionListeners(listener); |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
pack(); |
2 |
26 Feb 07 |
jari |
217 |
setResizable(false); |
2 |
26 Feb 07 |
jari |
218 |
lowerTextField.grabFocus(); |
2 |
26 Feb 07 |
jari |
219 |
lowerTextField.selectAll(); |
2 |
26 Feb 07 |
jari |
220 |
} |
2 |
26 Feb 07 |
jari |
221 |
|
2 |
26 Feb 07 |
jari |
222 |
/** |
2 |
26 Feb 07 |
jari |
* Displays the dialog, centered in scree |
2 |
26 Feb 07 |
jari |
224 |
* |
2 |
26 Feb 07 |
jari |
* @return returns the exit state, OK or CANCEL |
2 |
26 Feb 07 |
jari |
226 |
*/ |
2 |
26 Feb 07 |
jari |
227 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
228 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
229 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
230 |
show(); |
2 |
26 Feb 07 |
jari |
231 |
return result; |
2 |
26 Feb 07 |
jari |
232 |
} |
2 |
26 Feb 07 |
jari |
233 |
|
2 |
26 Feb 07 |
jari |
234 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the upper ratio limit |
2 |
26 Feb 07 |
jari |
* @return upper limit |
2 |
26 Feb 07 |
jari |
237 |
*/ |
2 |
26 Feb 07 |
jari |
238 |
public float getUpperLimit() { |
2 |
26 Feb 07 |
jari |
239 |
return Float.parseFloat(upperTextField.getText()); |
2 |
26 Feb 07 |
jari |
240 |
} |
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the lower limit |
2 |
26 Feb 07 |
jari |
* @return lower limit |
2 |
26 Feb 07 |
jari |
245 |
*/ |
2 |
26 Feb 07 |
jari |
246 |
public float getLowerLimit() { |
2 |
26 Feb 07 |
jari |
247 |
return Float.parseFloat(lowerTextField.getText()); |
2 |
26 Feb 07 |
jari |
248 |
} |
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
250 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the mid point value |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
253 |
*/ |
2 |
26 Feb 07 |
jari |
254 |
public float getMidValue() { |
2 |
26 Feb 07 |
jari |
255 |
return Float.parseFloat(midTextField.getText()); |
2 |
26 Feb 07 |
jari |
256 |
} |
2 |
26 Feb 07 |
jari |
257 |
|
2 |
26 Feb 07 |
jari |
258 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if the gradient style is double |
2 |
26 Feb 07 |
jari |
* @return true if using double gradient style, false if single gradient |
2 |
26 Feb 07 |
jari |
261 |
*/ |
2 |
26 Feb 07 |
jari |
262 |
public boolean getUseDoubleGradient() { |
2 |
26 Feb 07 |
jari |
263 |
return doubleGradientButton.isSelected(); |
2 |
26 Feb 07 |
jari |
264 |
} |
2 |
26 Feb 07 |
jari |
265 |
|
2 |
26 Feb 07 |
jari |
266 |
public boolean isGradientStyleAltered() { |
2 |
26 Feb 07 |
jari |
267 |
return (origDoubleGradient == doubleGradient); |
2 |
26 Feb 07 |
jari |
268 |
} |
2 |
26 Feb 07 |
jari |
269 |
|
2 |
26 Feb 07 |
jari |
270 |
public BufferedImage getPosImage() { |
2 |
26 Feb 07 |
jari |
271 |
return gradientPreviewPanel.getPosImage(); |
2 |
26 Feb 07 |
jari |
272 |
} |
2 |
26 Feb 07 |
jari |
273 |
|
2 |
26 Feb 07 |
jari |
274 |
/** |
2 |
26 Feb 07 |
jari |
* Validates the values then updates the stats panel and the preview panel |
2 |
26 Feb 07 |
jari |
276 |
*/ |
2 |
26 Feb 07 |
jari |
277 |
private void updateLimits() { |
2 |
26 Feb 07 |
jari |
278 |
if(validateValues()) { |
2 |
26 Feb 07 |
jari |
279 |
currMinValue = Float.parseFloat(lowerTextField.getText()); |
2 |
26 Feb 07 |
jari |
280 |
currMaxValue = Float.parseFloat(upperTextField.getText()); |
2 |
26 Feb 07 |
jari |
281 |
currMidValue = Float.parseFloat(midTextField.getText()); |
2 |
26 Feb 07 |
jari |
282 |
formattedLower = twoDecimalFormat.format(currMinValue); |
2 |
26 Feb 07 |
jari |
283 |
formattedUpper = twoDecimalFormat.format(currMaxValue); |
2 |
26 Feb 07 |
jari |
284 |
formattedMid = twoDecimalFormat.format(currMidValue); |
2 |
26 Feb 07 |
jari |
285 |
statsPanel.updateStats(currMinValue, currMaxValue); |
2 |
26 Feb 07 |
jari |
286 |
menubar.setUseDoubleGradient(getUseDoubleGradient()); |
2 |
26 Feb 07 |
jari |
287 |
menubar.setMaxRatioScale(currMaxValue); |
2 |
26 Feb 07 |
jari |
288 |
menubar.setMinRatioScale(currMinValue); |
2 |
26 Feb 07 |
jari |
289 |
menubar.setMidRatioValue(currMidValue); |
2 |
26 Feb 07 |
jari |
290 |
framework.refreshCurrentViewer(); |
2 |
26 Feb 07 |
jari |
291 |
repaint(); |
2 |
26 Feb 07 |
jari |
292 |
} |
2 |
26 Feb 07 |
jari |
293 |
} |
2 |
26 Feb 07 |
jari |
294 |
|
2 |
26 Feb 07 |
jari |
295 |
|
2 |
26 Feb 07 |
jari |
296 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a gradient image given specified <CODE>Color</CODE>(s) |
2 |
26 Feb 07 |
jari |
* @param color1 <CODE>Color</CODE> to display at left side of gradient |
2 |
26 Feb 07 |
jari |
* @param color2 <CODE>Color</CODE> to display at right side of gradient |
2 |
26 Feb 07 |
jari |
* @return returns a gradient image |
2 |
26 Feb 07 |
jari |
301 |
*/ |
2 |
26 Feb 07 |
jari |
302 |
private BufferedImage createGradientImage(Color color1, Color color2) { |
2 |
26 Feb 07 |
jari |
303 |
BufferedImage image = (BufferedImage)java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(256,1); |
2 |
26 Feb 07 |
jari |
304 |
Graphics2D graphics = image.createGraphics(); |
2 |
26 Feb 07 |
jari |
305 |
GradientPaint gp = new GradientPaint(0, 0, color1, 255, 0, color2); |
2 |
26 Feb 07 |
jari |
306 |
graphics.setPaint(gp); |
2 |
26 Feb 07 |
jari |
307 |
graphics.drawRect(0, 0, 255, 1); |
2 |
26 Feb 07 |
jari |
308 |
return image; |
2 |
26 Feb 07 |
jari |
309 |
} |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
311 |
|
2 |
26 Feb 07 |
jari |
312 |
/** |
2 |
26 Feb 07 |
jari |
* Validates the entered values. |
2 |
26 Feb 07 |
jari |
* Double gradient => lower<0 && upper>0 |
2 |
26 Feb 07 |
jari |
* single gradient => lower<upper |
2 |
26 Feb 07 |
jari |
* @return returns true if the values are valid, else false |
2 |
26 Feb 07 |
jari |
317 |
*/ |
2 |
26 Feb 07 |
jari |
318 |
private boolean validateValues() { |
2 |
26 Feb 07 |
jari |
319 |
int progress = 0; |
2 |
26 Feb 07 |
jari |
320 |
boolean valid = false; |
2 |
26 Feb 07 |
jari |
321 |
float newLower, newUpper, newMid; |
2 |
26 Feb 07 |
jari |
322 |
try { |
2 |
26 Feb 07 |
jari |
323 |
newLower = Float.parseFloat(this.lowerTextField.getText()); |
2 |
26 Feb 07 |
jari |
324 |
progress++; |
2 |
26 Feb 07 |
jari |
325 |
newUpper = Float.parseFloat(this.upperTextField.getText()); |
2 |
26 Feb 07 |
jari |
326 |
progress++; |
2 |
26 Feb 07 |
jari |
327 |
newMid = Float.parseFloat(this.midTextField.getText()); |
2 |
26 Feb 07 |
jari |
328 |
|
2 |
26 Feb 07 |
jari |
329 |
if(this.doubleGradient) { |
2 |
26 Feb 07 |
jari |
330 |
if(newLower < newMid && newMid < newUpper) |
2 |
26 Feb 07 |
jari |
331 |
valid = true; |
2 |
26 Feb 07 |
jari |
332 |
|
2 |
26 Feb 07 |
jari |
333 |
} else { //single gradient |
2 |
26 Feb 07 |
jari |
334 |
if(newLower < newUpper) |
2 |
26 Feb 07 |
jari |
335 |
valid = true; |
2 |
26 Feb 07 |
jari |
336 |
} |
2 |
26 Feb 07 |
jari |
337 |
} catch (NumberFormatException nfe) { |
2 |
26 Feb 07 |
jari |
338 |
valid = false; |
2 |
26 Feb 07 |
jari |
339 |
JOptionPane.showMessageDialog(this, "Input Error, Values cannot be parsed as floating point numbers.", "Input Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
340 |
} |
2 |
26 Feb 07 |
jari |
341 |
|
2 |
26 Feb 07 |
jari |
342 |
if(!valid) { |
2 |
26 Feb 07 |
jari |
343 |
if(doubleGradient) { |
2 |
26 Feb 07 |
jari |
344 |
JOptionPane.showMessageDialog(this, "Input Error (Double Gradient), Value Limits: floating point number, lower < mid < upper", "Input Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
345 |
} else { |
2 |
26 Feb 07 |
jari |
346 |
JOptionPane.showMessageDialog(this, "Input Error (Single Gradient), Value Limits: floating point number, lower limit < upper limit", "Input Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
347 |
} |
2 |
26 Feb 07 |
jari |
348 |
} |
2 |
26 Feb 07 |
jari |
349 |
return valid; |
2 |
26 Feb 07 |
jari |
350 |
} |
2 |
26 Feb 07 |
jari |
351 |
|
2 |
26 Feb 07 |
jari |
352 |
|
2 |
26 Feb 07 |
jari |
353 |
/** |
2 |
26 Feb 07 |
jari |
* Resets the text fields to original values, updates stats, repaints preview |
2 |
26 Feb 07 |
jari |
355 |
*/ |
2 |
26 Feb 07 |
jari |
356 |
private void resetControls() { |
2 |
26 Feb 07 |
jari |
//set original values |
2 |
26 Feb 07 |
jari |
358 |
upperTextField.setText(String.valueOf(origUpper)); |
2 |
26 Feb 07 |
jari |
359 |
lowerTextField.setText(String.valueOf(origLower)); |
2 |
26 Feb 07 |
jari |
360 |
midTextField.setText(String.valueOf(origMid)); |
2 |
26 Feb 07 |
jari |
361 |
if(origDoubleGradient) { |
2 |
26 Feb 07 |
jari |
362 |
doubleGradientButton.setSelected(true); |
2 |
26 Feb 07 |
jari |
363 |
} else |
2 |
26 Feb 07 |
jari |
364 |
singleGradientButton.setSelected(true); |
2 |
26 Feb 07 |
jari |
365 |
doubleGradient = origDoubleGradient; |
2 |
26 Feb 07 |
jari |
366 |
midLabel.setEnabled(origDoubleGradient); |
2 |
26 Feb 07 |
jari |
367 |
midTextField.setEnabled(origDoubleGradient); |
2 |
26 Feb 07 |
jari |
368 |
|
2 |
26 Feb 07 |
jari |
//update the limits and reset the viewer |
2 |
26 Feb 07 |
jari |
370 |
updateLimits(); |
2 |
26 Feb 07 |
jari |
371 |
} |
2 |
26 Feb 07 |
jari |
372 |
|
2 |
26 Feb 07 |
jari |
373 |
|
2 |
26 Feb 07 |
jari |
374 |
/** |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
376 |
* |
2 |
26 Feb 07 |
jari |
* Preview class to display the current gradient type and limits. |
2 |
26 Feb 07 |
jari |
378 |
*/ |
2 |
26 Feb 07 |
jari |
379 |
private class GradientPreviewPanel extends JPanel { |
2 |
26 Feb 07 |
jari |
380 |
|
2 |
26 Feb 07 |
jari |
381 |
private BufferedImage negImage, posImage; |
2 |
26 Feb 07 |
jari |
382 |
private String centerPointStr; |
2 |
26 Feb 07 |
jari |
383 |
private int TIC_HEIGHT = 35; |
2 |
26 Feb 07 |
jari |
384 |
private int GRAD_HEIGHT = 30; |
2 |
26 Feb 07 |
jari |
385 |
private int TEXT_BUFFER = 20; |
2 |
26 Feb 07 |
jari |
386 |
private Insets insets; |
2 |
26 Feb 07 |
jari |
387 |
|
2 |
26 Feb 07 |
jari |
388 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a new GradientPreviewPanel |
2 |
26 Feb 07 |
jari |
* @param framework IFramework implementatin to provide display menu |
2 |
26 Feb 07 |
jari |
391 |
*/ |
2 |
26 Feb 07 |
jari |
392 |
public GradientPreviewPanel(IFramework framework) { |
2 |
26 Feb 07 |
jari |
393 |
super(); |
2 |
26 Feb 07 |
jari |
394 |
insets = new Insets(5,5,5,5); |
2 |
26 Feb 07 |
jari |
395 |
negImage = framework.getDisplayMenu().getNegativeGradientImage(); |
2 |
26 Feb 07 |
jari |
396 |
posImage = framework.getDisplayMenu().getPositiveGradientImage(); |
2 |
26 Feb 07 |
jari |
397 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
398 |
setBorder(BorderFactory.createLineBorder(Color.black)); |
2 |
26 Feb 07 |
jari |
399 |
super.setPreferredSize(new Dimension(negImage.getWidth()+posImage.getWidth()+insets.left+insets.right, GRAD_HEIGHT+insets.top+insets.bottom+TEXT_BUFFER)); |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
|
2 |
26 Feb 07 |
jari |
402 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see java.awt.Component#paint(java.awt.Graphics) |
2 |
26 Feb 07 |
jari |
405 |
*/ |
2 |
26 Feb 07 |
jari |
406 |
public void paint(Graphics g) { |
2 |
26 Feb 07 |
jari |
407 |
super.paint(g); |
2 |
26 Feb 07 |
jari |
408 |
|
2 |
26 Feb 07 |
jari |
409 |
FontMetrics fm = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
410 |
int totalWidth = negImage.getWidth()+posImage.getWidth(); |
2 |
26 Feb 07 |
jari |
411 |
|
2 |
26 Feb 07 |
jari |
412 |
if(doubleGradient) { |
2 |
26 Feb 07 |
jari |
413 |
|
2 |
26 Feb 07 |
jari |
414 |
g.drawImage(negImage, insets.left, insets.top, negImage.getWidth(), GRAD_HEIGHT, null); |
2 |
26 Feb 07 |
jari |
415 |
g.drawImage(posImage, insets.left+negImage.getWidth()+1, insets.top, posImage.getWidth(), GRAD_HEIGHT, null); |
2 |
26 Feb 07 |
jari |
416 |
|
2 |
26 Feb 07 |
jari |
//draw center tic |
2 |
26 Feb 07 |
jari |
418 |
g.drawLine(insets.left+negImage.getWidth(), insets.top, insets.left+negImage.getWidth(), insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
419 |
g.drawLine(insets.left+negImage.getWidth()-1, insets.top, insets.left+negImage.getWidth()-1, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
420 |
g.drawLine(insets.left+negImage.getWidth()+1, insets.top, insets.left+negImage.getWidth()+1, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
421 |
|
2 |
26 Feb 07 |
jari |
//draw center point string |
2 |
26 Feb 07 |
jari |
423 |
g.drawString(formattedMid, insets.left+negImage.getWidth()-(int)(fm.stringWidth(formattedMid)/2f), insets.top+TIC_HEIGHT+fm.getHeight()); |
2 |
26 Feb 07 |
jari |
424 |
} else { |
2 |
26 Feb 07 |
jari |
425 |
g.drawImage(posImage, insets.left, insets.top, totalWidth, GRAD_HEIGHT, null); |
2 |
26 Feb 07 |
jari |
426 |
} |
2 |
26 Feb 07 |
jari |
427 |
|
2 |
26 Feb 07 |
jari |
//draw left tic |
2 |
26 Feb 07 |
jari |
429 |
g.drawLine(insets.left, insets.top, insets.left, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
430 |
g.drawLine(insets.left+1, insets.top, insets.left+1, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
431 |
g.drawLine(insets.left+2, insets.top, insets.left+2, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
432 |
|
2 |
26 Feb 07 |
jari |
//draw right tic |
2 |
26 Feb 07 |
jari |
434 |
g.drawLine(insets.left+totalWidth, insets.top, insets.left+totalWidth, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
435 |
g.drawLine(insets.left+totalWidth-1, insets.top, insets.left+totalWidth-1, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
436 |
g.drawLine(insets.left+totalWidth-2, insets.top, insets.left+totalWidth-2, insets.top+TIC_HEIGHT); |
2 |
26 Feb 07 |
jari |
437 |
|
2 |
26 Feb 07 |
jari |
//put limits on axis |
2 |
26 Feb 07 |
jari |
439 |
g.drawString(formattedLower, insets.left, insets.top+TIC_HEIGHT+fm.getHeight()); |
2 |
26 Feb 07 |
jari |
440 |
g.drawString(formattedUpper, insets.left+totalWidth-fm.stringWidth(formattedUpper), insets.top+TIC_HEIGHT+fm.getHeight()); |
2 |
26 Feb 07 |
jari |
441 |
} |
2 |
26 Feb 07 |
jari |
442 |
|
2 |
26 Feb 07 |
jari |
443 |
public void setPosImage(BufferedImage posBI) { |
2 |
26 Feb 07 |
jari |
444 |
posImage = posBI; |
2 |
26 Feb 07 |
jari |
445 |
repaint(); |
2 |
26 Feb 07 |
jari |
446 |
} |
2 |
26 Feb 07 |
jari |
447 |
|
2 |
26 Feb 07 |
jari |
448 |
public BufferedImage getPosImage() { |
2 |
26 Feb 07 |
jari |
449 |
return posImage; |
2 |
26 Feb 07 |
jari |
450 |
} |
2 |
26 Feb 07 |
jari |
451 |
|
2 |
26 Feb 07 |
jari |
452 |
public BufferedImage getNegImage() { |
2 |
26 Feb 07 |
jari |
453 |
return negImage; |
2 |
26 Feb 07 |
jari |
454 |
} |
2 |
26 Feb 07 |
jari |
455 |
} |
2 |
26 Feb 07 |
jari |
456 |
|
2 |
26 Feb 07 |
jari |
457 |
|
2 |
26 Feb 07 |
jari |
458 |
/** |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
460 |
* |
2 |
26 Feb 07 |
jari |
* Presents staturation statistics for the current limits |
2 |
26 Feb 07 |
jari |
462 |
*/ |
2 |
26 Feb 07 |
jari |
463 |
public class StatsPanel extends ParameterPanel { |
2 |
26 Feb 07 |
jari |
464 |
|
2 |
26 Feb 07 |
jari |
465 |
private JTextField offScaleField, lowEndField, highEndField; |
2 |
26 Feb 07 |
jari |
466 |
private JTextField offScalePercentField, lowEndPercentField, highEndPercentField; |
2 |
26 Feb 07 |
jari |
467 |
private float [] sortedValues; |
2 |
26 Feb 07 |
jari |
468 |
private DecimalFormat format; |
2 |
26 Feb 07 |
jari |
469 |
|
2 |
26 Feb 07 |
jari |
470 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a new StatsPanel |
2 |
26 Feb 07 |
jari |
* @param framework |
2 |
26 Feb 07 |
jari |
473 |
*/ |
2 |
26 Feb 07 |
jari |
474 |
public StatsPanel(IFramework framework) { |
2 |
26 Feb 07 |
jari |
475 |
super("Color Saturation Statistics"); |
2 |
26 Feb 07 |
jari |
476 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
477 |
format = new DecimalFormat(); |
2 |
26 Feb 07 |
jari |
478 |
format.setMaximumIntegerDigits(3); |
2 |
26 Feb 07 |
jari |
479 |
format.setMaximumFractionDigits(1); |
2 |
26 Feb 07 |
jari |
480 |
format.setMinimumFractionDigits(1); |
2 |
26 Feb 07 |
jari |
481 |
|
2 |
26 Feb 07 |
jari |
482 |
JLabel numberLabel = new JLabel("Number"); |
2 |
26 Feb 07 |
jari |
483 |
numberLabel.setOpaque(false); |
2 |
26 Feb 07 |
jari |
484 |
|
2 |
26 Feb 07 |
jari |
485 |
JLabel percentLabel = new JLabel("Percent"); |
2 |
26 Feb 07 |
jari |
486 |
percentLabel.setOpaque(false); |
2 |
26 Feb 07 |
jari |
487 |
|
2 |
26 Feb 07 |
jari |
488 |
JLabel offScaleLabel = new JLabel("Elements Off Color Scale"); |
2 |
26 Feb 07 |
jari |
489 |
JLabel lowEndLabel = new JLabel("Elements Below Lower Limit"); |
2 |
26 Feb 07 |
jari |
490 |
JLabel highEndLabel = new JLabel("Elements Above Upper Limit"); |
2 |
26 Feb 07 |
jari |
491 |
|
2 |
26 Feb 07 |
jari |
492 |
offScaleField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
493 |
offScaleField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
494 |
offScaleField.setEditable(false); |
2 |
26 Feb 07 |
jari |
495 |
offScaleField.setHorizontalAlignment(JTextField.RIGHT); |
2 |
26 Feb 07 |
jari |
496 |
|
2 |
26 Feb 07 |
jari |
497 |
lowEndField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
498 |
lowEndField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
499 |
lowEndField.setEditable(false); |
2 |
26 Feb 07 |
jari |
500 |
lowEndField.setHorizontalAlignment(JTextField.RIGHT); |
2 |
26 Feb 07 |
jari |
501 |
|
2 |
26 Feb 07 |
jari |
502 |
highEndField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
503 |
highEndField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
504 |
highEndField.setEditable(false); |
2 |
26 Feb 07 |
jari |
505 |
highEndField.setHorizontalAlignment(JTextField.RIGHT); |
2 |
26 Feb 07 |
jari |
506 |
|
2 |
26 Feb 07 |
jari |
507 |
offScalePercentField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
508 |
offScalePercentField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
509 |
offScalePercentField.setEditable(false); |
2 |
26 Feb 07 |
jari |
510 |
offScalePercentField.setHorizontalAlignment(JTextField.RIGHT); |
2 |
26 Feb 07 |
jari |
511 |
|
2 |
26 Feb 07 |
jari |
512 |
lowEndPercentField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
513 |
lowEndPercentField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
514 |
lowEndPercentField.setEditable(false); |
2 |
26 Feb 07 |
jari |
515 |
lowEndPercentField.setHorizontalAlignment(JTextField.RIGHT); |
2 |
26 Feb 07 |
jari |
516 |
|
2 |
26 Feb 07 |
jari |
517 |
highEndPercentField = new JTextField(5); |
2 |
26 Feb 07 |
jari |
518 |
highEndPercentField.setBackground(Color.lightGray); |
2 |
26 Feb 07 |
jari |
519 |
highEndPercentField.setEditable(false); |
2 |
26 Feb 07 |
jari |
520 |
highEndPercentField.setHorizontalAlignment(JTextField.RIGHT); |
2 |
26 Feb 07 |
jari |
521 |
|
2 |
26 Feb 07 |
jari |
522 |
sortedValues = initSortedValues(framework.getData().getExperiment().getMatrix()); |
2 |
26 Feb 07 |
jari |
523 |
updateStats(origLower, origUpper); |
2 |
26 Feb 07 |
jari |
524 |
|
2 |
26 Feb 07 |
jari |
525 |
JPanel dummyPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
526 |
dummyPanel.setOpaque(false); |
2 |
26 Feb 07 |
jari |
527 |
|
2 |
26 Feb 07 |
jari |
528 |
add(numberLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,20), 0,0)); |
2 |
26 Feb 07 |
jari |
529 |
add(numberLabel, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,4,10), 0,0)); |
2 |
26 Feb 07 |
jari |
530 |
add(percentLabel, new GridBagConstraints(2,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,4,0), 0,0)); |
2 |
26 Feb 07 |
jari |
531 |
|
2 |
26 Feb 07 |
jari |
532 |
add(offScaleLabel, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,20), 0,0)); |
2 |
26 Feb 07 |
jari |
533 |
add(offScaleField, new GridBagConstraints(1,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,10), 0,0)); |
2 |
26 Feb 07 |
jari |
534 |
add(offScalePercentField, new GridBagConstraints(2,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
535 |
|
2 |
26 Feb 07 |
jari |
536 |
JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); |
2 |
26 Feb 07 |
jari |
537 |
sep.setPreferredSize(new Dimension(200,1)); |
2 |
26 Feb 07 |
jari |
538 |
sep.setOpaque(true); |
2 |
26 Feb 07 |
jari |
539 |
add(sep, new GridBagConstraints(0,2,3,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
540 |
|
2 |
26 Feb 07 |
jari |
541 |
add(lowEndLabel, new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,5,20), 0,0)); |
2 |
26 Feb 07 |
jari |
542 |
add(lowEndField, new GridBagConstraints(1,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,5,10), 0,0)); |
2 |
26 Feb 07 |
jari |
543 |
add(lowEndPercentField, new GridBagConstraints(2,3,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,5,0), 0,0)); |
2 |
26 Feb 07 |
jari |
544 |
|
2 |
26 Feb 07 |
jari |
545 |
add(highEndLabel, new GridBagConstraints(0,4,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,5,20), 0,0)); |
2 |
26 Feb 07 |
jari |
546 |
add(highEndField, new GridBagConstraints(1,4,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,5,10), 0,0)); |
2 |
26 Feb 07 |
jari |
547 |
add(highEndPercentField, new GridBagConstraints(2,4,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,5,0), 0,0)); |
2 |
26 Feb 07 |
jari |
548 |
} |
2 |
26 Feb 07 |
jari |
549 |
|
2 |
26 Feb 07 |
jari |
550 |
/** |
2 |
26 Feb 07 |
jari |
* Initializes the sorted values array of all matrix values, sorted array will |
2 |
26 Feb 07 |
jari |
* consist of only !NaN values and will be sorted from low to high |
2 |
26 Feb 07 |
jari |
* @param m <code>org.tigr.util.FloatMatrix</code> |
2 |
26 Feb 07 |
jari |
* @return returns the sorted float array of !NaN values |
2 |
26 Feb 07 |
jari |
555 |
*/ |
2 |
26 Feb 07 |
jari |
556 |
private float [] initSortedValues(FloatMatrix m) { |
2 |
26 Feb 07 |
jari |
557 |
float [] vals = m.getColumnPackedCopy(); |
2 |
26 Feb 07 |
jari |
558 |
QSort qsort = new QSort(vals, QSort.ASCENDING); |
2 |
26 Feb 07 |
jari |
559 |
vals = qsort.getSorted(); |
2 |
26 Feb 07 |
jari |
560 |
|
2 |
26 Feb 07 |
jari |
561 |
int numberNaN = 0; |
2 |
26 Feb 07 |
jari |
562 |
|
2 |
26 Feb 07 |
jari |
563 |
for(int i = 0; i < vals.length; i++) { |
2 |
26 Feb 07 |
jari |
564 |
if(Float.isNaN(vals[i])) |
2 |
26 Feb 07 |
jari |
565 |
numberNaN++; |
2 |
26 Feb 07 |
jari |
566 |
else |
2 |
26 Feb 07 |
jari |
567 |
break; |
2 |
26 Feb 07 |
jari |
568 |
} |
2 |
26 Feb 07 |
jari |
569 |
|
2 |
26 Feb 07 |
jari |
570 |
int validN = vals.length-numberNaN; |
2 |
26 Feb 07 |
jari |
571 |
|
2 |
26 Feb 07 |
jari |
572 |
float [] values = new float[validN]; |
2 |
26 Feb 07 |
jari |
573 |
|
2 |
26 Feb 07 |
jari |
574 |
for(int i = 0; i < values.length; i++) { |
2 |
26 Feb 07 |
jari |
575 |
values[i] = vals[i+numberNaN]; |
2 |
26 Feb 07 |
jari |
576 |
} |
2 |
26 Feb 07 |
jari |
577 |
|
2 |
26 Feb 07 |
jari |
578 |
return values; |
2 |
26 Feb 07 |
jari |
579 |
|
2 |
26 Feb 07 |
jari |
580 |
} |
2 |
26 Feb 07 |
jari |
581 |
/** |
2 |
26 Feb 07 |
jari |
* returns the median from the sorted array |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
584 |
*/ |
2 |
26 Feb 07 |
jari |
585 |
public float getMedian() { |
2 |
26 Feb 07 |
jari |
586 |
float median; |
2 |
26 Feb 07 |
jari |
587 |
if(sortedValues.length % 2 == 0) |
2 |
26 Feb 07 |
jari |
588 |
median = (sortedValues[sortedValues.length/2] + sortedValues[sortedValues.length/2 + 1])/2.0f; |
2 |
26 Feb 07 |
jari |
589 |
else |
2 |
26 Feb 07 |
jari |
590 |
median = sortedValues[sortedValues.length/2 + 1]; |
2 |
26 Feb 07 |
jari |
591 |
return median; |
2 |
26 Feb 07 |
jari |
592 |
} |
2 |
26 Feb 07 |
jari |
593 |
|
2 |
26 Feb 07 |
jari |
594 |
/** |
2 |
26 Feb 07 |
jari |
* Updates the stats panel with the current limits and resulting |
2 |
26 Feb 07 |
jari |
* saturation stats. |
2 |
26 Feb 07 |
jari |
* @param lower current lower limit |
2 |
26 Feb 07 |
jari |
* @param upper current upper limit |
2 |
26 Feb 07 |
jari |
599 |
*/ |
2 |
26 Feb 07 |
jari |
600 |
public void updateStats(float lower, float upper) { |
2 |
26 Feb 07 |
jari |
601 |
|
2 |
26 Feb 07 |
jari |
602 |
int lowCount = getLowCount(lower); |
2 |
26 Feb 07 |
jari |
603 |
int highCount = getHighCount(upper); |
2 |
26 Feb 07 |
jari |
604 |
|
2 |
26 Feb 07 |
jari |
605 |
float lowPerc = ((float)lowCount/sortedValues.length)*100f; |
2 |
26 Feb 07 |
jari |
606 |
float highPerc = ((float)highCount/sortedValues.length)*100f; |
2 |
26 Feb 07 |
jari |
607 |
float offPerc = ((float)(lowCount+highCount)/sortedValues.length)*100f; |
2 |
26 Feb 07 |
jari |
608 |
|
2 |
26 Feb 07 |
jari |
609 |
this.offScaleField.setText(String.valueOf(lowCount+highCount)); |
2 |
26 Feb 07 |
jari |
610 |
this.offScalePercentField.setText(format.format(offPerc)); |
2 |
26 Feb 07 |
jari |
611 |
|
2 |
26 Feb 07 |
jari |
612 |
this.lowEndField.setText(String.valueOf(lowCount)); |
2 |
26 Feb 07 |
jari |
613 |
this.lowEndPercentField.setText(format.format(lowPerc)); |
2 |
26 Feb 07 |
jari |
614 |
|
2 |
26 Feb 07 |
jari |
615 |
this.highEndField.setText(String.valueOf(highCount)); |
2 |
26 Feb 07 |
jari |
616 |
this.highEndPercentField.setText(format.format(highPerc)); |
2 |
26 Feb 07 |
jari |
617 |
|
2 |
26 Feb 07 |
jari |
618 |
} |
2 |
26 Feb 07 |
jari |
619 |
|
2 |
26 Feb 07 |
jari |
620 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the number of !NaN values in the data below the lower limit |
2 |
26 Feb 07 |
jari |
* @param lower current lower limit |
2 |
26 Feb 07 |
jari |
* @return number of points off low end |
2 |
26 Feb 07 |
jari |
624 |
*/ |
2 |
26 Feb 07 |
jari |
625 |
private int getLowCount(float lower) { |
2 |
26 Feb 07 |
jari |
626 |
int index = 0; |
2 |
26 Feb 07 |
jari |
627 |
while(index < sortedValues.length && sortedValues[index]<lower) { |
2 |
26 Feb 07 |
jari |
628 |
index++; |
2 |
26 Feb 07 |
jari |
629 |
} |
2 |
26 Feb 07 |
jari |
630 |
return index; |
2 |
26 Feb 07 |
jari |
631 |
} |
2 |
26 Feb 07 |
jari |
632 |
|
2 |
26 Feb 07 |
jari |
633 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the number of !NaN values in the data above the upper limit |
2 |
26 Feb 07 |
jari |
* @param upper current upper limit |
2 |
26 Feb 07 |
jari |
* @return number of points off high end |
2 |
26 Feb 07 |
jari |
637 |
*/ |
2 |
26 Feb 07 |
jari |
638 |
private int getHighCount(float upper) { |
2 |
26 Feb 07 |
jari |
639 |
int index = sortedValues.length-1; |
2 |
26 Feb 07 |
jari |
640 |
int highCount = 0; |
2 |
26 Feb 07 |
jari |
641 |
while(index > -1 && sortedValues[index]>upper) { |
2 |
26 Feb 07 |
jari |
642 |
index--; |
2 |
26 Feb 07 |
jari |
643 |
highCount++; |
2 |
26 Feb 07 |
jari |
644 |
} |
2 |
26 Feb 07 |
jari |
645 |
return highCount; |
2 |
26 Feb 07 |
jari |
646 |
} |
2 |
26 Feb 07 |
jari |
647 |
} |
2 |
26 Feb 07 |
jari |
648 |
|
2 |
26 Feb 07 |
jari |
649 |
|
2 |
26 Feb 07 |
jari |
650 |
/** |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
652 |
* |
2 |
26 Feb 07 |
jari |
* Handles dialog events |
2 |
26 Feb 07 |
jari |
654 |
*/ |
2 |
26 Feb 07 |
jari |
655 |
public class EventListener extends WindowAdapter implements ActionListener, KeyListener { |
2 |
26 Feb 07 |
jari |
656 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) |
2 |
26 Feb 07 |
jari |
659 |
*/ |
2 |
26 Feb 07 |
jari |
660 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
661 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
662 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
663 |
if(validateValues()) { |
2 |
26 Feb 07 |
jari |
664 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
665 |
dispose(); |
2 |
26 Feb 07 |
jari |
666 |
} |
2 |
26 Feb 07 |
jari |
667 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
668 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
669 |
dispose(); |
2 |
26 Feb 07 |
jari |
670 |
} else if (command.equals("reset-command")) { |
2 |
26 Feb 07 |
jari |
671 |
resetControls(); |
2 |
26 Feb 07 |
jari |
672 |
} else if (command.equals("info-command")) { |
2 |
26 Feb 07 |
jari |
673 |
HelpWindow hw = new HelpWindow(SetRatioScaleDialog.this, "Color Scale Dialog"); |
2 |
26 Feb 07 |
jari |
674 |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
675 |
hw.setSize(575,550); |
2 |
26 Feb 07 |
jari |
676 |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
677 |
hw.show(); |
2 |
26 Feb 07 |
jari |
678 |
} else { |
2 |
26 Feb 07 |
jari |
679 |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
680 |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
681 |
} |
2 |
26 Feb 07 |
jari |
682 |
} else if (command.equals("update-command")) { |
2 |
26 Feb 07 |
jari |
683 |
updateLimits(); |
2 |
26 Feb 07 |
jari |
684 |
} else if (command.equals("change-gradient-command")) { |
2 |
26 Feb 07 |
jari |
685 |
doubleGradient = doubleGradientButton.isSelected(); |
2 |
26 Feb 07 |
jari |
686 |
|
2 |
26 Feb 07 |
jari |
687 |
if(doubleGradient) { //might have to alter pos image to have proper neutal |
2 |
26 Feb 07 |
jari |
688 |
BufferedImage posImage = createGradientImage(new Color(gradientPreviewPanel.getNegImage().getRGB(255,0)), new Color(gradientPreviewPanel.getPosImage().getRGB(255,0))); |
2 |
26 Feb 07 |
jari |
689 |
gradientPreviewPanel.setPosImage(posImage); |
2 |
26 Feb 07 |
jari |
690 |
} |
2 |
26 Feb 07 |
jari |
691 |
|
2 |
26 Feb 07 |
jari |
692 |
midLabel.setEnabled(doubleGradient); |
2 |
26 Feb 07 |
jari |
693 |
midTextField.setEnabled(doubleGradient); |
2 |
26 Feb 07 |
jari |
694 |
|
2 |
26 Feb 07 |
jari |
695 |
repaint(); |
2 |
26 Feb 07 |
jari |
696 |
} |
2 |
26 Feb 07 |
jari |
697 |
} |
2 |
26 Feb 07 |
jari |
698 |
|
2 |
26 Feb 07 |
jari |
699 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
700 |
result = JOptionPane.CLOSED_OPTION; |
2 |
26 Feb 07 |
jari |
701 |
dispose(); |
2 |
26 Feb 07 |
jari |
702 |
} |
2 |
26 Feb 07 |
jari |
703 |
|
2 |
26 Feb 07 |
jari |
704 |
public void keyPressed(KeyEvent event) { |
2 |
26 Feb 07 |
jari |
705 |
if (event.getKeyCode() == KeyEvent.VK_ENTER) { |
2 |
26 Feb 07 |
jari |
706 |
try { |
2 |
26 Feb 07 |
jari |
707 |
Float.parseFloat(lowerTextField.getText()); |
2 |
26 Feb 07 |
jari |
708 |
Float.parseFloat(upperTextField.getText()); |
2 |
26 Feb 07 |
jari |
709 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
710 |
} catch (Exception exception) { |
2 |
26 Feb 07 |
jari |
711 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
712 |
} |
2 |
26 Feb 07 |
jari |
713 |
dispose(); |
2 |
26 Feb 07 |
jari |
714 |
} |
2 |
26 Feb 07 |
jari |
715 |
} |
2 |
26 Feb 07 |
jari |
716 |
|
2 |
26 Feb 07 |
jari |
717 |
public void keyReleased(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
718 |
public void keyTyped(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
719 |
} |
2 |
26 Feb 07 |
jari |
720 |
} |