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