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