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