gvsig-3d / org.gvsig.netcdf3d / trunk / org.gvsig.netcdf3d / org.gvsig.netcdf3d.swing / org.gvsig.netcdf3d.swing.impl / src / main / java / org / gvsig / netcdf3d / swing / impl / JNetCDFLoaderParametersView.java @ 727
History | View | Annotate | Download (5.66 KB)
1 |
package org.gvsig.netcdf3d.swing.impl; |
---|---|
2 |
|
3 |
import com.jgoodies.forms.layout.CellConstraints; |
4 |
import com.jgoodies.forms.layout.FormLayout; |
5 |
import java.awt.BorderLayout; |
6 |
import java.awt.ComponentOrientation; |
7 |
import java.awt.Container; |
8 |
import java.awt.Dimension; |
9 |
import javax.swing.Box; |
10 |
import javax.swing.ImageIcon; |
11 |
import javax.swing.JComboBox; |
12 |
import javax.swing.JFrame; |
13 |
import javax.swing.JLabel; |
14 |
import javax.swing.JPanel; |
15 |
import javax.swing.JTextField; |
16 |
|
17 |
|
18 |
public class JNetCDFLoaderParametersView extends JPanel |
19 |
{ |
20 |
JLabel lapseText = new JLabel(); |
21 |
JLabel finalTimeText = new JLabel(); |
22 |
JLabel initialTimeText = new JLabel(); |
23 |
JLabel levelText = new JLabel(); |
24 |
JLabel variableText = new JLabel(); |
25 |
JPanel rasterLoaderParameters = new JPanel(); |
26 |
JComboBox finalTimes = new JComboBox(); |
27 |
JComboBox initialTimes = new JComboBox(); |
28 |
JComboBox levels = new JComboBox(); |
29 |
JComboBox variables = new JComboBox(); |
30 |
JTextField lapse = new JTextField(); |
31 |
JLabel unitText = new JLabel(); |
32 |
|
33 |
/**
|
34 |
* Default constructor
|
35 |
*/
|
36 |
public JNetCDFLoaderParametersView()
|
37 |
{ |
38 |
initializePanel(); |
39 |
} |
40 |
|
41 |
/**
|
42 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
43 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
44 |
* @param cols an array of column indices in the first row where fill components should be added.
|
45 |
* @param rows an array of row indices in the first column where fill components should be added.
|
46 |
*/
|
47 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
48 |
{ |
49 |
Dimension filler = new Dimension(10,10); |
50 |
|
51 |
boolean filled_cell_11 = false; |
52 |
CellConstraints cc = new CellConstraints();
|
53 |
if ( cols.length > 0 && rows.length > 0 ) |
54 |
{ |
55 |
if ( cols[0] == 1 && rows[0] == 1 ) |
56 |
{ |
57 |
/** add a rigid area */
|
58 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
59 |
filled_cell_11 = true;
|
60 |
} |
61 |
} |
62 |
|
63 |
for( int index = 0; index < cols.length; index++ ) |
64 |
{ |
65 |
if ( cols[index] == 1 && filled_cell_11 ) |
66 |
{ |
67 |
continue;
|
68 |
} |
69 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
70 |
} |
71 |
|
72 |
for( int index = 0; index < rows.length; index++ ) |
73 |
{ |
74 |
if ( rows[index] == 1 && filled_cell_11 ) |
75 |
{ |
76 |
continue;
|
77 |
} |
78 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
79 |
} |
80 |
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Helper method to load an image file from the CLASSPATH
|
85 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
86 |
* @return an ImageIcon instance with the specified image file
|
87 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
88 |
*/
|
89 |
public ImageIcon loadImage( String imageName ) |
90 |
{ |
91 |
try
|
92 |
{ |
93 |
ClassLoader classloader = getClass().getClassLoader();
|
94 |
java.net.URL url = classloader.getResource( imageName ); |
95 |
if ( url != null ) |
96 |
{ |
97 |
ImageIcon icon = new ImageIcon( url ); |
98 |
return icon;
|
99 |
} |
100 |
} |
101 |
catch( Exception e ) |
102 |
{ |
103 |
e.printStackTrace(); |
104 |
} |
105 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Method for recalculating the component orientation for
|
110 |
* right-to-left Locales.
|
111 |
* @param orientation the component orientation to be applied
|
112 |
*/
|
113 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
114 |
{ |
115 |
// Not yet implemented...
|
116 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
117 |
super.applyComponentOrientation(orientation);
|
118 |
} |
119 |
|
120 |
public JPanel createPanel() |
121 |
{ |
122 |
JPanel jpanel1 = new JPanel(); |
123 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:4DLU:NONE,FILL:DEFAULT:NONE,CENTER:4DLU:NONE,FILL:DEFAULT:NONE,CENTER:4DLU:NONE,FILL:DEFAULT:NONE,CENTER:4DLU:NONE,FILL:DEFAULT:NONE,CENTER:4DLU:NONE,FILL:DEFAULT:NONE,CENTER:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE"); |
124 |
CellConstraints cc = new CellConstraints();
|
125 |
jpanel1.setLayout(formlayout1); |
126 |
|
127 |
lapseText.setName("lapseText");
|
128 |
lapseText.setText("lapse_XxparenthesisxX_s_XxparenthesisxX");
|
129 |
jpanel1.add(lapseText,cc.xy(1,12)); |
130 |
|
131 |
finalTimeText.setName("finalTimeText");
|
132 |
finalTimeText.setText("final_time");
|
133 |
jpanel1.add(finalTimeText,cc.xy(1,10)); |
134 |
|
135 |
initialTimeText.setName("initialTimeText");
|
136 |
initialTimeText.setText("initial_time");
|
137 |
jpanel1.add(initialTimeText,cc.xy(1,8)); |
138 |
|
139 |
levelText.setName("levelText");
|
140 |
levelText.setText("level");
|
141 |
jpanel1.add(levelText,cc.xy(1,6)); |
142 |
|
143 |
variableText.setName("variableText");
|
144 |
variableText.setText("variable");
|
145 |
jpanel1.add(variableText,cc.xy(1,4)); |
146 |
|
147 |
rasterLoaderParameters.setName("rasterLoaderParameters");
|
148 |
jpanel1.add(rasterLoaderParameters,cc.xywh(1,2,5,1)); |
149 |
|
150 |
finalTimes.setName("finalTimes");
|
151 |
jpanel1.add(finalTimes,cc.xywh(3,10,3,1)); |
152 |
|
153 |
initialTimes.setName("initialTimes");
|
154 |
jpanel1.add(initialTimes,cc.xywh(3,8,3,1)); |
155 |
|
156 |
levels.setName("levels");
|
157 |
jpanel1.add(levels,cc.xy(3,6)); |
158 |
|
159 |
variables.setName("variables");
|
160 |
jpanel1.add(variables,cc.xywh(3,4,3,1)); |
161 |
|
162 |
lapse.setName("lapse");
|
163 |
jpanel1.add(lapse,cc.xywh(3,12,3,1)); |
164 |
|
165 |
unitText.setName("unitText");
|
166 |
jpanel1.add(unitText,cc.xy(5,6)); |
167 |
|
168 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,3,5,7,9,11,13 }); |
169 |
return jpanel1;
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Initializer
|
174 |
*/
|
175 |
protected void initializePanel() |
176 |
{ |
177 |
setLayout(new BorderLayout()); |
178 |
add(createPanel(), BorderLayout.CENTER);
|
179 |
} |
180 |
|
181 |
|
182 |
} |