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 / DefaultJTopologyPlanPropertiesView.java @ 727
History | View | Annotate | Download (9.43 KB)
1 | 688 | jjdelcerro | 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.JButton; |
||
13 | import javax.swing.JFrame; |
||
14 | import javax.swing.JLabel; |
||
15 | import javax.swing.JList; |
||
16 | import javax.swing.JPanel; |
||
17 | import javax.swing.JScrollPane; |
||
18 | import javax.swing.JTabbedPane; |
||
19 | import javax.swing.JTextField; |
||
20 | import javax.swing.border.EmptyBorder; |
||
21 | |||
22 | |||
23 | public class DefaultJTopologyPlanPropertiesView extends JPanel |
||
24 | { |
||
25 | JLabel lblName = new JLabel(); |
||
26 | JTextField txtName = new JTextField(); |
||
27 | JTabbedPane tabPanel = new JTabbedPane(); |
||
28 | JList lstDataSets = new JList(); |
||
29 | JButton btnAddDataSet = new JButton(); |
||
30 | JButton btnRemoveDataSet = new JButton(); |
||
31 | JList lstRules = new JList(); |
||
32 | JButton btnAddRule = new JButton(); |
||
33 | JButton btnRemoveRule = new JButton(); |
||
34 | 727 | jjdelcerro | JButton btnEditRule = new JButton(); |
35 | 688 | jjdelcerro | JLabel lblTolerance = new JLabel(); |
36 | JTextField txtTolerance = new JTextField(); |
||
37 | |||
38 | /**
|
||
39 | * Default constructor
|
||
40 | */
|
||
41 | public DefaultJTopologyPlanPropertiesView()
|
||
42 | { |
||
43 | initializePanel(); |
||
44 | } |
||
45 | |||
46 | /**
|
||
47 | * Adds fill components to empty cells in the first row and first column of the grid.
|
||
48 | * This ensures that the grid spacing will be the same as shown in the designer.
|
||
49 | * @param cols an array of column indices in the first row where fill components should be added.
|
||
50 | * @param rows an array of row indices in the first column where fill components should be added.
|
||
51 | */
|
||
52 | void addFillComponents( Container panel, int[] cols, int[] rows ) |
||
53 | { |
||
54 | Dimension filler = new Dimension(10,10); |
||
55 | |||
56 | boolean filled_cell_11 = false; |
||
57 | CellConstraints cc = new CellConstraints();
|
||
58 | if ( cols.length > 0 && rows.length > 0 ) |
||
59 | { |
||
60 | if ( cols[0] == 1 && rows[0] == 1 ) |
||
61 | { |
||
62 | /** add a rigid area */
|
||
63 | panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
||
64 | filled_cell_11 = true;
|
||
65 | } |
||
66 | } |
||
67 | |||
68 | for( int index = 0; index < cols.length; index++ ) |
||
69 | { |
||
70 | if ( cols[index] == 1 && filled_cell_11 ) |
||
71 | { |
||
72 | continue;
|
||
73 | } |
||
74 | panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
||
75 | } |
||
76 | |||
77 | for( int index = 0; index < rows.length; index++ ) |
||
78 | { |
||
79 | if ( rows[index] == 1 && filled_cell_11 ) |
||
80 | { |
||
81 | continue;
|
||
82 | } |
||
83 | panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
||
84 | } |
||
85 | |||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * Helper method to load an image file from the CLASSPATH
|
||
90 | * @param imageName the package and name of the file to load relative to the CLASSPATH
|
||
91 | * @return an ImageIcon instance with the specified image file
|
||
92 | * @throws IllegalArgumentException if the image resource cannot be loaded.
|
||
93 | */
|
||
94 | public ImageIcon loadImage( String imageName ) |
||
95 | { |
||
96 | try
|
||
97 | { |
||
98 | ClassLoader classloader = getClass().getClassLoader();
|
||
99 | java.net.URL url = classloader.getResource( imageName ); |
||
100 | if ( url != null ) |
||
101 | { |
||
102 | ImageIcon icon = new ImageIcon( url ); |
||
103 | return icon;
|
||
104 | } |
||
105 | } |
||
106 | catch( Exception e ) |
||
107 | { |
||
108 | e.printStackTrace(); |
||
109 | } |
||
110 | throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
||
111 | } |
||
112 | |||
113 | /**
|
||
114 | * Method for recalculating the component orientation for
|
||
115 | * right-to-left Locales.
|
||
116 | * @param orientation the component orientation to be applied
|
||
117 | */
|
||
118 | public void applyComponentOrientation( ComponentOrientation orientation ) |
||
119 | { |
||
120 | // Not yet implemented...
|
||
121 | // I18NUtils.applyComponentOrientation(this, orientation);
|
||
122 | super.applyComponentOrientation(orientation);
|
||
123 | } |
||
124 | |||
125 | public JPanel createPanel() |
||
126 | { |
||
127 | JPanel jpanel1 = new JPanel(); |
||
128 | FormLayout formlayout1 = new FormLayout("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,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE"); |
||
129 | CellConstraints cc = new CellConstraints();
|
||
130 | jpanel1.setLayout(formlayout1); |
||
131 | |||
132 | lblName.setName("lblName");
|
||
133 | lblName.setText("_Name");
|
||
134 | jpanel1.add(lblName,cc.xy(2,2)); |
||
135 | |||
136 | txtName.setName("txtName");
|
||
137 | jpanel1.add(txtName,cc.xy(4,2)); |
||
138 | |||
139 | tabPanel.setName("tabPanel");
|
||
140 | tabPanel.addTab("_DataSets",null,createPanel1()); |
||
141 | tabPanel.addTab("_Rules",null,createPanel3()); |
||
142 | jpanel1.add(tabPanel,cc.xywh(2,6,3,1)); |
||
143 | |||
144 | lblTolerance.setName("lblTolerance");
|
||
145 | lblTolerance.setText("_Tolerance");
|
||
146 | jpanel1.add(lblTolerance,cc.xy(2,4)); |
||
147 | |||
148 | txtTolerance.setName("txtTolerance");
|
||
149 | txtTolerance.setHorizontalAlignment(JTextField.RIGHT);
|
||
150 | jpanel1.add(txtTolerance,cc.xy(4,4)); |
||
151 | |||
152 | addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7 }); |
||
153 | return jpanel1;
|
||
154 | } |
||
155 | |||
156 | public JPanel createPanel1() |
||
157 | { |
||
158 | JPanel jpanel1 = new JPanel(); |
||
159 | FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE"); |
||
160 | CellConstraints cc = new CellConstraints();
|
||
161 | jpanel1.setLayout(formlayout1); |
||
162 | |||
163 | lstDataSets.setName("lstDataSets");
|
||
164 | JScrollPane jscrollpane1 = new JScrollPane(); |
||
165 | jscrollpane1.setViewportView(lstDataSets); |
||
166 | jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||
167 | jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
168 | jpanel1.add(jscrollpane1,cc.xy(2,2)); |
||
169 | |||
170 | jpanel1.add(createPanel2(),cc.xy(2,4)); |
||
171 | addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 }); |
||
172 | return jpanel1;
|
||
173 | } |
||
174 | |||
175 | public JPanel createPanel2() |
||
176 | { |
||
177 | JPanel jpanel1 = new JPanel(); |
||
178 | FormLayout formlayout1 = new FormLayout("FILL:8DLU:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
||
179 | CellConstraints cc = new CellConstraints();
|
||
180 | jpanel1.setLayout(formlayout1); |
||
181 | |||
182 | 727 | jjdelcerro | btnAddDataSet.setIcon(loadImage("org/gvsig/topology/swing/impl/images/topology-plan-dataset-add.png"));
|
183 | 688 | jjdelcerro | btnAddDataSet.setName("btnAddDataSet");
|
184 | btnAddDataSet.setToolTipText("_Add_dataset");
|
||
185 | EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
||
186 | btnAddDataSet.setBorder(emptyborder1); |
||
187 | jpanel1.add(btnAddDataSet,cc.xy(6,1)); |
||
188 | |||
189 | 727 | jjdelcerro | btnRemoveDataSet.setIcon(loadImage("org/gvsig/topology/swing/impl/images/topology-plan-dataset-remove.png"));
|
190 | 688 | jjdelcerro | btnRemoveDataSet.setName("btnRemoveDataSet");
|
191 | btnRemoveDataSet.setToolTipText("_Remove_dataset");
|
||
192 | EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2); |
||
193 | btnRemoveDataSet.setBorder(emptyborder2); |
||
194 | jpanel1.add(btnRemoveDataSet,cc.xy(4,1)); |
||
195 | |||
196 | addFillComponents(jpanel1,new int[]{ 1,2,3,5 },new int[]{ 1 }); |
||
197 | return jpanel1;
|
||
198 | } |
||
199 | |||
200 | public JPanel createPanel3() |
||
201 | { |
||
202 | JPanel jpanel1 = new JPanel(); |
||
203 | FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE"); |
||
204 | CellConstraints cc = new CellConstraints();
|
||
205 | jpanel1.setLayout(formlayout1); |
||
206 | |||
207 | lstRules.setName("lstRules");
|
||
208 | JScrollPane jscrollpane1 = new JScrollPane(); |
||
209 | jscrollpane1.setViewportView(lstRules); |
||
210 | jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||
211 | jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
212 | jpanel1.add(jscrollpane1,cc.xy(2,2)); |
||
213 | |||
214 | jpanel1.add(createPanel4(),cc.xy(2,4)); |
||
215 | addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 }); |
||
216 | return jpanel1;
|
||
217 | } |
||
218 | |||
219 | public JPanel createPanel4() |
||
220 | { |
||
221 | JPanel jpanel1 = new JPanel(); |
||
222 | 727 | jjdelcerro | FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
223 | 688 | jjdelcerro | CellConstraints cc = new CellConstraints();
|
224 | jpanel1.setLayout(formlayout1); |
||
225 | |||
226 | 727 | jjdelcerro | btnAddRule.setIcon(loadImage("org/gvsig/topology/swing/impl/images/topology-plan-rule-add.png"));
|
227 | 688 | jjdelcerro | btnAddRule.setName("btnAddRule");
|
228 | btnAddRule.setToolTipText("_Add_rule");
|
||
229 | EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
||
230 | btnAddRule.setBorder(emptyborder1); |
||
231 | 727 | jjdelcerro | jpanel1.add(btnAddRule,cc.xy(7,1)); |
232 | 688 | jjdelcerro | |
233 | 727 | jjdelcerro | btnRemoveRule.setIcon(loadImage("org/gvsig/topology/swing/impl/images/topology-plan-rule-remove.png"));
|
234 | 688 | jjdelcerro | btnRemoveRule.setName("btnRemoveRule");
|
235 | btnRemoveRule.setToolTipText("_Remove_rule");
|
||
236 | EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2); |
||
237 | btnRemoveRule.setBorder(emptyborder2); |
||
238 | jpanel1.add(btnRemoveRule,cc.xy(3,1)); |
||
239 | |||
240 | 727 | jjdelcerro | btnEditRule.setIcon(loadImage("org/gvsig/topology/swing/impl/images/topology-plan-rule-edit.png"));
|
241 | btnEditRule.setName("btnEditRule");
|
||
242 | btnEditRule.setToolTipText("_Edit_rule");
|
||
243 | EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2); |
||
244 | btnEditRule.setBorder(emptyborder3); |
||
245 | jpanel1.add(btnEditRule,cc.xy(5,1)); |
||
246 | |||
247 | addFillComponents(jpanel1,new int[]{ 1,2,4,6 },new int[]{ 1 }); |
||
248 | 688 | jjdelcerro | return jpanel1;
|
249 | } |
||
250 | |||
251 | /**
|
||
252 | * Initializer
|
||
253 | */
|
||
254 | protected void initializePanel() |
||
255 | { |
||
256 | setLayout(new BorderLayout()); |
||
257 | add(createPanel(), BorderLayout.CENTER);
|
||
258 | } |
||
259 | |||
260 | |||
261 | } |