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