gvsig-projects-pool / org.gvsig.topology / trunk / org.gvsig.topology / org.gvsig.topology.swing / org.gvsig.topology.swing.impl / src / main / java / org / gvsig / topology / swing / impl / CreateRuleDialogView.java @ 728
History | View | Annotate | Download (6.57 KB)
1 |
package org.gvsig.topology.swing.impl; |
---|---|
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.ComponentOrientation; |
8 |
import java.awt.Container; |
9 |
import java.awt.Dimension; |
10 |
import javax.swing.Box; |
11 |
import javax.swing.ImageIcon; |
12 |
import javax.swing.JComboBox; |
13 |
import javax.swing.JEditorPane; |
14 |
import javax.swing.JFrame; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JPanel; |
17 |
import javax.swing.JScrollPane; |
18 |
import javax.swing.JTextField; |
19 |
|
20 |
|
21 |
public class CreateRuleDialogView extends JPanel |
22 |
{ |
23 |
JTextField txtTolerance = new JTextField(); |
24 |
JComboBox cboDataSet1 = new JComboBox(); |
25 |
JLabel lblDataSet1 = new JLabel(); |
26 |
JLabel lblRule = new JLabel(); |
27 |
JComboBox cboRule = new JComboBox(); |
28 |
JLabel lblDataSet2 = new JLabel(); |
29 |
JComboBox cboDataSet2 = new JComboBox(); |
30 |
JLabel lblTolerance = new JLabel(); |
31 |
JEditorPane txtDescription = new JEditorPane(); |
32 |
|
33 |
/**
|
34 |
* Default constructor
|
35 |
*/
|
36 |
public CreateRuleDialogView()
|
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:4DLU:NONE,FILL:DEFAULT:GROW(0.5),FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.5),FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE"); |
124 |
CellConstraints cc = new CellConstraints();
|
125 |
jpanel1.setLayout(formlayout1); |
126 |
|
127 |
jpanel1.add(createPanel1(),cc.xy(2,2)); |
128 |
jpanel1.add(createPanel2(),cc.xy(4,2)); |
129 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3 }); |
130 |
return jpanel1;
|
131 |
} |
132 |
|
133 |
public JPanel createPanel1() |
134 |
{ |
135 |
JPanel jpanel1 = new JPanel(); |
136 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE"); |
137 |
CellConstraints cc = new CellConstraints();
|
138 |
jpanel1.setLayout(formlayout1); |
139 |
|
140 |
txtTolerance.setName("txtTolerance");
|
141 |
txtTolerance.setHorizontalAlignment(JTextField.RIGHT);
|
142 |
jpanel1.add(txtTolerance,cc.xy(1,15)); |
143 |
|
144 |
cboDataSet1.setName("cboDataSet1");
|
145 |
jpanel1.add(cboDataSet1,cc.xy(1,3)); |
146 |
|
147 |
lblDataSet1.setName("lblDataSet1");
|
148 |
lblDataSet1.setText("_Primary_dataset");
|
149 |
jpanel1.add(lblDataSet1,cc.xy(1,1)); |
150 |
|
151 |
lblRule.setName("lblRule");
|
152 |
lblRule.setText("_Rule");
|
153 |
jpanel1.add(lblRule,cc.xy(1,5)); |
154 |
|
155 |
cboRule.setEnabled(false);
|
156 |
cboRule.setName("cboRule");
|
157 |
jpanel1.add(cboRule,cc.xy(1,7)); |
158 |
|
159 |
lblDataSet2.setName("lblDataSet2");
|
160 |
lblDataSet2.setText("_Secondary_dataset");
|
161 |
jpanel1.add(lblDataSet2,cc.xy(1,9)); |
162 |
|
163 |
cboDataSet2.setEnabled(false);
|
164 |
cboDataSet2.setName("cboDataSet2");
|
165 |
jpanel1.add(cboDataSet2,cc.xy(1,11)); |
166 |
|
167 |
lblTolerance.setName("lblTolerance");
|
168 |
lblTolerance.setText("_Tolerance");
|
169 |
jpanel1.add(lblTolerance,cc.xy(1,13)); |
170 |
|
171 |
addFillComponents(jpanel1,new int[0],new int[]{ 2,4,6,8,10,12,14 }); |
172 |
return jpanel1;
|
173 |
} |
174 |
|
175 |
public JPanel createPanel2() |
176 |
{ |
177 |
JPanel jpanel1 = new JPanel(); |
178 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(0.7)","FILL:DEFAULT:GROW(1.0)"); |
179 |
CellConstraints cc = new CellConstraints();
|
180 |
jpanel1.setLayout(formlayout1); |
181 |
|
182 |
txtDescription.setName("txtDescription");
|
183 |
JScrollPane jscrollpane1 = new JScrollPane(); |
184 |
jscrollpane1.setViewportView(txtDescription); |
185 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
186 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
187 |
jpanel1.add(jscrollpane1,cc.xy(1,1)); |
188 |
|
189 |
addFillComponents(jpanel1,new int[0],new int[0]); |
190 |
return jpanel1;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* Initializer
|
195 |
*/
|
196 |
protected void initializePanel() |
197 |
{ |
198 |
setLayout(new BorderLayout()); |
199 |
add(createPanel(), BorderLayout.CENTER);
|
200 |
} |
201 |
|
202 |
|
203 |
} |