svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.raster.legend / org.gvsig.raster.legend.swing / org.gvsig.raster.legend.swing.impl / src / main / java / org / gvsig / raster / swing / legend / impl / colortable / create / CreateColorTablePanelView.java @ 44831
History | View | Annotate | Download (7.87 KB)
1 |
package org.gvsig.raster.swing.legend.impl.colortable.create; |
---|---|
2 |
|
3 |
import com.jeta.open.i18n.I18NUtils; |
4 |
import com.jgoodies.forms.layout.CellConstraints; |
5 |
import com.jgoodies.forms.layout.FormLayout; |
6 |
import java.awt.BorderLayout; |
7 |
import java.awt.Color; |
8 |
import java.awt.ComponentOrientation; |
9 |
import java.awt.Container; |
10 |
import java.awt.Dimension; |
11 |
import javax.swing.Box; |
12 |
import javax.swing.ButtonGroup; |
13 |
import javax.swing.ImageIcon; |
14 |
import javax.swing.JButton; |
15 |
import javax.swing.JCheckBox; |
16 |
import javax.swing.JFormattedTextField; |
17 |
import javax.swing.JFrame; |
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JRadioButton; |
21 |
import javax.swing.JTextField; |
22 |
|
23 |
|
24 |
public class CreateColorTablePanelView extends JPanel |
25 |
{ |
26 |
JLabel lblName = new JLabel(); |
27 |
JLabel lblMinimum = new JLabel(); |
28 |
JLabel lblMaximum = new JLabel(); |
29 |
JRadioButton rdbIntervalSize = new JRadioButton(); |
30 |
ButtonGroup buttongroup1 = new ButtonGroup(); |
31 |
JRadioButton rdbIntervalNumber = new JRadioButton(); |
32 |
JLabel lblFromColor = new JLabel(); |
33 |
JLabel lblToColor = new JLabel(); |
34 |
JFormattedTextField txtIntervals = new JFormattedTextField(); |
35 |
JFormattedTextField txtIntervalSize = new JFormattedTextField(); |
36 |
JFormattedTextField txtMaximum = new JFormattedTextField(); |
37 |
JFormattedTextField txtMinimum = new JFormattedTextField(); |
38 |
JTextField txtName = new JTextField(); |
39 |
JButton btnToColor = new JButton(); |
40 |
JLabel lblToColorPreviewer = new JLabel(); |
41 |
JButton btnFromColor = new JButton(); |
42 |
JLabel lblFromColorPreviewer = new JLabel(); |
43 |
JCheckBox chkInterpolated = new JCheckBox(); |
44 |
|
45 |
/**
|
46 |
* Default constructor
|
47 |
*/
|
48 |
public CreateColorTablePanelView()
|
49 |
{ |
50 |
initializePanel(); |
51 |
} |
52 |
|
53 |
/**
|
54 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
55 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
56 |
* @param cols an array of column indices in the first row where fill components should be added.
|
57 |
* @param rows an array of row indices in the first column where fill components should be added.
|
58 |
*/
|
59 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
60 |
{ |
61 |
Dimension filler = new Dimension(10,10); |
62 |
|
63 |
boolean filled_cell_11 = false; |
64 |
CellConstraints cc = new CellConstraints();
|
65 |
if ( cols.length > 0 && rows.length > 0 ) |
66 |
{ |
67 |
if ( cols[0] == 1 && rows[0] == 1 ) |
68 |
{ |
69 |
/** add a rigid area */
|
70 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
71 |
filled_cell_11 = true;
|
72 |
} |
73 |
} |
74 |
|
75 |
for( int index = 0; index < cols.length; index++ ) |
76 |
{ |
77 |
if ( cols[index] == 1 && filled_cell_11 ) |
78 |
{ |
79 |
continue;
|
80 |
} |
81 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
82 |
} |
83 |
|
84 |
for( int index = 0; index < rows.length; index++ ) |
85 |
{ |
86 |
if ( rows[index] == 1 && filled_cell_11 ) |
87 |
{ |
88 |
continue;
|
89 |
} |
90 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
91 |
} |
92 |
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Helper method to load an image file from the CLASSPATH
|
97 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
98 |
* @return an ImageIcon instance with the specified image file
|
99 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
100 |
*/
|
101 |
public ImageIcon loadImage( String imageName ) |
102 |
{ |
103 |
try
|
104 |
{ |
105 |
ClassLoader classloader = getClass().getClassLoader();
|
106 |
java.net.URL url = classloader.getResource( imageName ); |
107 |
if ( url != null ) |
108 |
{ |
109 |
ImageIcon icon = new ImageIcon( url ); |
110 |
return icon;
|
111 |
} |
112 |
} |
113 |
catch( Exception e ) |
114 |
{ |
115 |
e.printStackTrace(); |
116 |
} |
117 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Method for recalculating the component orientation for
|
122 |
* right-to-left Locales.
|
123 |
* @param orientation the component orientation to be applied
|
124 |
*/
|
125 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
126 |
{ |
127 |
// Not yet implemented...
|
128 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
129 |
super.applyComponentOrientation(orientation);
|
130 |
} |
131 |
|
132 |
public JPanel createPanel() |
133 |
{ |
134 |
JPanel jpanel1 = new JPanel(); |
135 |
FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE"); |
136 |
CellConstraints cc = new CellConstraints();
|
137 |
jpanel1.setLayout(formlayout1); |
138 |
|
139 |
lblName.setName("lblName");
|
140 |
lblName.setText("_name");
|
141 |
jpanel1.add(lblName,cc.xy(2,2)); |
142 |
|
143 |
lblMinimum.setName("lblMinimum");
|
144 |
lblMinimum.setText("_minimum");
|
145 |
jpanel1.add(lblMinimum,cc.xy(2,4)); |
146 |
|
147 |
lblMaximum.setName("lblMaximum");
|
148 |
lblMaximum.setText("_maximum");
|
149 |
jpanel1.add(lblMaximum,cc.xy(2,6)); |
150 |
|
151 |
rdbIntervalSize.setActionCommand("_interval_size");
|
152 |
rdbIntervalSize.setName("rdbIntervalSize");
|
153 |
rdbIntervalSize.setText("_interval_size");
|
154 |
buttongroup1.add(rdbIntervalSize); |
155 |
jpanel1.add(rdbIntervalSize,cc.xy(2,8)); |
156 |
|
157 |
rdbIntervalNumber.setActionCommand("_interval_number");
|
158 |
rdbIntervalNumber.setName("rdbIntervalNumber");
|
159 |
rdbIntervalNumber.setText("_interval_number");
|
160 |
buttongroup1.add(rdbIntervalNumber); |
161 |
jpanel1.add(rdbIntervalNumber,cc.xy(2,10)); |
162 |
|
163 |
lblFromColor.setName("lblFromColor");
|
164 |
lblFromColor.setText("_from_color");
|
165 |
jpanel1.add(lblFromColor,cc.xy(2,12)); |
166 |
|
167 |
lblToColor.setName("lblToColor");
|
168 |
lblToColor.setText("_to_color");
|
169 |
jpanel1.add(lblToColor,cc.xy(2,14)); |
170 |
|
171 |
txtIntervals.setName("txtIntervals");
|
172 |
jpanel1.add(txtIntervals,cc.xywh(4,10,5,1)); |
173 |
|
174 |
txtIntervalSize.setName("txtIntervalSize");
|
175 |
jpanel1.add(txtIntervalSize,cc.xywh(4,8,5,1)); |
176 |
|
177 |
txtMaximum.setName("txtMaximum");
|
178 |
jpanel1.add(txtMaximum,cc.xywh(4,6,5,1)); |
179 |
|
180 |
txtMinimum.setName("txtMinimum");
|
181 |
jpanel1.add(txtMinimum,cc.xywh(4,4,5,1)); |
182 |
|
183 |
txtName.setName("txtName");
|
184 |
jpanel1.add(txtName,cc.xywh(4,2,5,1)); |
185 |
|
186 |
btnToColor.setActionCommand("...");
|
187 |
btnToColor.setName("btnToColor");
|
188 |
btnToColor.setText("...");
|
189 |
jpanel1.add(btnToColor,cc.xy(6,14)); |
190 |
|
191 |
lblToColorPreviewer.setBackground(new Color(255,255,255)); |
192 |
lblToColorPreviewer.setName("lblToColorPreviewer");
|
193 |
lblToColorPreviewer.setOpaque(true);
|
194 |
lblToColorPreviewer.setText(" ");
|
195 |
jpanel1.add(lblToColorPreviewer,new CellConstraints(4,14,1,1,CellConstraints.FILL,CellConstraints.FILL)); |
196 |
|
197 |
btnFromColor.setActionCommand("...");
|
198 |
btnFromColor.setName("btnFromColor");
|
199 |
btnFromColor.setText("...");
|
200 |
jpanel1.add(btnFromColor,cc.xy(6,12)); |
201 |
|
202 |
lblFromColorPreviewer.setBackground(new Color(0,0,0)); |
203 |
lblFromColorPreviewer.setName("lblFromColorPreviewer");
|
204 |
lblFromColorPreviewer.setOpaque(true);
|
205 |
lblFromColorPreviewer.setText(" ");
|
206 |
jpanel1.add(lblFromColorPreviewer,new CellConstraints(4,12,1,1,CellConstraints.FILL,CellConstraints.FILL)); |
207 |
|
208 |
chkInterpolated.setActionCommand("_interpolated");
|
209 |
chkInterpolated.setName("chkInterpolated");
|
210 |
chkInterpolated.setText("_interpolated");
|
211 |
jpanel1.add(chkInterpolated,cc.xy(2,16)); |
212 |
|
213 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 }); |
214 |
return jpanel1;
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Initializer
|
219 |
*/
|
220 |
protected void initializePanel() |
221 |
{ |
222 |
setLayout(new BorderLayout()); |
223 |
add(createPanel(), BorderLayout.CENTER);
|
224 |
} |
225 |
|
226 |
|
227 |
} |