svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / resourcesmanager / ResourcesLoaderPanelView.java @ 46338
History | View | Annotate | Download (11 KB)
1 |
package org.gvsig.app.extension.resourcesmanager; |
---|---|
2 |
|
3 |
import com.jeta.forms.components.border.TitledBorderLabel; |
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.JCheckBox; |
15 |
import javax.swing.JComboBox; |
16 |
import javax.swing.JFrame; |
17 |
import javax.swing.JList; |
18 |
import javax.swing.JPanel; |
19 |
import javax.swing.JScrollPane; |
20 |
import javax.swing.border.EmptyBorder; |
21 |
|
22 |
|
23 |
public class ResourcesLoaderPanelView extends JPanel |
24 |
{ |
25 |
TitledBorderLabel lblConnection = new TitledBorderLabel();
|
26 |
JComboBox cboConnection = new JComboBox(); |
27 |
JButton btnConnection = new JButton(); |
28 |
TitledBorderLabel lblDBResources = new TitledBorderLabel();
|
29 |
TitledBorderLabel lblLocalResources = new TitledBorderLabel();
|
30 |
JList lstLocalResources = new JList(); |
31 |
JList lstDBResources = new JList(); |
32 |
JButton btnDeleteLocal = new JButton(); |
33 |
JButton btnAddLocal = new JButton(); |
34 |
JButton btnDownload = new JButton(); |
35 |
JButton btnUpload = new JButton(); |
36 |
JButton btnDeleteRemote = new JButton(); |
37 |
JCheckBox chkUseLocalResources = new JCheckBox(); |
38 |
|
39 |
/**
|
40 |
* Default constructor
|
41 |
*/
|
42 |
public ResourcesLoaderPanelView()
|
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:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:2DLU:NONE"); |
130 |
CellConstraints cc = new CellConstraints();
|
131 |
jpanel1.setLayout(formlayout1); |
132 |
|
133 |
lblConnection.setName("lblConnection");
|
134 |
lblConnection.setText("_Connection");
|
135 |
jpanel1.add(lblConnection,cc.xy(2,2)); |
136 |
|
137 |
jpanel1.add(createPanel1(),cc.xy(2,3)); |
138 |
jpanel1.add(createPanel2(),new CellConstraints(2,7,1,1,CellConstraints.FILL,CellConstraints.FILL)); |
139 |
chkUseLocalResources.setActionCommand("_Use_local_resources");
|
140 |
chkUseLocalResources.setName("chkUseLocalResources");
|
141 |
chkUseLocalResources.setText("_Use_local_resources");
|
142 |
chkUseLocalResources.setToolTipText("_Use_local_resources");
|
143 |
jpanel1.add(chkUseLocalResources,cc.xy(2,5)); |
144 |
|
145 |
addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5,6,7,8 }); |
146 |
return jpanel1;
|
147 |
} |
148 |
|
149 |
public JPanel createPanel1() |
150 |
{ |
151 |
JPanel jpanel1 = new JPanel(); |
152 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
153 |
CellConstraints cc = new CellConstraints();
|
154 |
jpanel1.setLayout(formlayout1); |
155 |
|
156 |
cboConnection.setName("cboConnection");
|
157 |
jpanel1.add(cboConnection,cc.xy(1,1)); |
158 |
|
159 |
btnConnection.setActionCommand("...");
|
160 |
btnConnection.setName("btnConnection");
|
161 |
btnConnection.setOpaque(false);
|
162 |
btnConnection.setText("...");
|
163 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
164 |
btnConnection.setBorder(emptyborder1); |
165 |
jpanel1.add(btnConnection,cc.xy(3,1)); |
166 |
|
167 |
addFillComponents(jpanel1,new int[]{ 2 },new int[0]); |
168 |
return jpanel1;
|
169 |
} |
170 |
|
171 |
public JPanel createPanel2() |
172 |
{ |
173 |
JPanel jpanel1 = new JPanel(); |
174 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(0.5),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE"); |
175 |
CellConstraints cc = new CellConstraints();
|
176 |
jpanel1.setLayout(formlayout1); |
177 |
|
178 |
lblDBResources.setName("lblDBResources");
|
179 |
lblDBResources.setText("_Resources_in_database");
|
180 |
jpanel1.add(lblDBResources,cc.xy(1,1)); |
181 |
|
182 |
lblLocalResources.setName("lblLocalResources");
|
183 |
lblLocalResources.setText("_Local_resources");
|
184 |
jpanel1.add(lblLocalResources,cc.xy(5,1)); |
185 |
|
186 |
lstLocalResources.setName("lstLocalResources");
|
187 |
JScrollPane jscrollpane1 = new JScrollPane(); |
188 |
jscrollpane1.setViewportView(lstLocalResources); |
189 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
190 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
191 |
jpanel1.add(jscrollpane1,new CellConstraints(5,3,1,2,CellConstraints.FILL,CellConstraints.FILL)); |
192 |
|
193 |
lstDBResources.setName("lstDBResources");
|
194 |
JScrollPane jscrollpane2 = new JScrollPane(); |
195 |
jscrollpane2.setViewportView(lstDBResources); |
196 |
jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
197 |
jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
198 |
jpanel1.add(jscrollpane2,new CellConstraints(1,3,1,1,CellConstraints.FILL,CellConstraints.FILL)); |
199 |
|
200 |
jpanel1.add(createPanel3(),cc.xy(5,5)); |
201 |
jpanel1.add(createPanel4(),new CellConstraints(3,3,1,1,CellConstraints.FILL,CellConstraints.FILL)); |
202 |
jpanel1.add(createPanel5(),cc.xy(1,5)); |
203 |
addFillComponents(jpanel1,new int[]{ 2,3,4 },new int[]{ 2,4,5 }); |
204 |
return jpanel1;
|
205 |
} |
206 |
|
207 |
public JPanel createPanel3() |
208 |
{ |
209 |
JPanel jpanel1 = new JPanel(); |
210 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
211 |
CellConstraints cc = new CellConstraints();
|
212 |
jpanel1.setLayout(formlayout1); |
213 |
|
214 |
btnDeleteLocal.setActionCommand("Ninguno");
|
215 |
btnDeleteLocal.setIcon(loadImage("resourcesmanager/remove-resource.png"));
|
216 |
btnDeleteLocal.setName("btnDeleteLocal");
|
217 |
btnDeleteLocal.setOpaque(false);
|
218 |
btnDeleteLocal.setToolTipText("_Delete_local_resource");
|
219 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
220 |
btnDeleteLocal.setBorder(emptyborder1); |
221 |
jpanel1.add(btnDeleteLocal,cc.xy(4,1)); |
222 |
|
223 |
btnAddLocal.setActionCommand("Ninguno");
|
224 |
btnAddLocal.setIcon(loadImage("resourcesmanager/add-resource.png"));
|
225 |
btnAddLocal.setName("btnAddLocal");
|
226 |
btnAddLocal.setOpaque(false);
|
227 |
btnAddLocal.setToolTipText("_Add_local_resource");
|
228 |
EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2); |
229 |
btnAddLocal.setBorder(emptyborder2); |
230 |
jpanel1.add(btnAddLocal,cc.xy(2,1)); |
231 |
|
232 |
addFillComponents(jpanel1,new int[]{ 1,3 },new int[]{ 1 }); |
233 |
return jpanel1;
|
234 |
} |
235 |
|
236 |
public JPanel createPanel4() |
237 |
{ |
238 |
JPanel jpanel1 = new JPanel(); |
239 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0)"); |
240 |
CellConstraints cc = new CellConstraints();
|
241 |
jpanel1.setLayout(formlayout1); |
242 |
|
243 |
btnDownload.setActionCommand("Todos");
|
244 |
btnDownload.setIcon(loadImage("resourcesmanager/download-resource.png"));
|
245 |
btnDownload.setName("btnDownload");
|
246 |
btnDownload.setOpaque(false);
|
247 |
btnDownload.setToolTipText("_Download");
|
248 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
249 |
btnDownload.setBorder(emptyborder1); |
250 |
jpanel1.add(btnDownload,cc.xy(1,1)); |
251 |
|
252 |
btnUpload.setActionCommand("Todos");
|
253 |
btnUpload.setIcon(loadImage("resourcesmanager/upload-resource.png"));
|
254 |
btnUpload.setName("btnUpload");
|
255 |
btnUpload.setOpaque(false);
|
256 |
btnUpload.setToolTipText("_Upload");
|
257 |
EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2); |
258 |
btnUpload.setBorder(emptyborder2); |
259 |
jpanel1.add(btnUpload,cc.xy(1,3)); |
260 |
|
261 |
addFillComponents(jpanel1,new int[0],new int[]{ 2,4 }); |
262 |
return jpanel1;
|
263 |
} |
264 |
|
265 |
public JPanel createPanel5() |
266 |
{ |
267 |
JPanel jpanel1 = new JPanel(); |
268 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
269 |
CellConstraints cc = new CellConstraints();
|
270 |
jpanel1.setLayout(formlayout1); |
271 |
|
272 |
btnDeleteRemote.setActionCommand("Ninguno");
|
273 |
btnDeleteRemote.setIcon(loadImage("resourcesmanager/remove-resource.png"));
|
274 |
btnDeleteRemote.setName("btnDeleteRemote");
|
275 |
btnDeleteRemote.setOpaque(false);
|
276 |
btnDeleteRemote.setToolTipText("_Delete_remote_resource");
|
277 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
278 |
btnDeleteRemote.setBorder(emptyborder1); |
279 |
jpanel1.add(btnDeleteRemote,cc.xy(2,1)); |
280 |
|
281 |
addFillComponents(jpanel1,new int[]{ 1 },new int[]{ 1 }); |
282 |
return jpanel1;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* Initializer
|
287 |
*/
|
288 |
protected void initializePanel() |
289 |
{ |
290 |
setLayout(new BorderLayout()); |
291 |
add(createPanel(), BorderLayout.CENTER);
|
292 |
} |
293 |
|
294 |
|
295 |
} |