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