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