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 / ConnectToDatabaseWorkspacePanelView.java @ 45650
History | View | Annotate | Download (5.05 KB)
1 | 44304 | jjdelcerro | 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 | 44305 | jjdelcerro | import java.awt.Color; |
8 | 44304 | jjdelcerro | 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.JComboBox; |
||
15 | import javax.swing.JFrame; |
||
16 | import javax.swing.JLabel; |
||
17 | import javax.swing.JPanel; |
||
18 | 44305 | jjdelcerro | import javax.swing.JTextField; |
19 | 44304 | jjdelcerro | |
20 | |||
21 | public class ConnectToDatabaseWorkspacePanelView extends JPanel |
||
22 | { |
||
23 | 44305 | jjdelcerro | JButton btnConnection = new JButton(); |
24 | JTextField txtID = new JTextField(); |
||
25 | JTextField txtLabel = new JTextField(); |
||
26 | 44304 | jjdelcerro | JComboBox cboConnection = new JComboBox(); |
27 | |||
28 | /**
|
||
29 | * Default constructor
|
||
30 | */
|
||
31 | public ConnectToDatabaseWorkspacePanelView()
|
||
32 | { |
||
33 | initializePanel(); |
||
34 | } |
||
35 | |||
36 | /**
|
||
37 | * Adds fill components to empty cells in the first row and first column of the grid.
|
||
38 | * This ensures that the grid spacing will be the same as shown in the designer.
|
||
39 | * @param cols an array of column indices in the first row where fill components should be added.
|
||
40 | * @param rows an array of row indices in the first column where fill components should be added.
|
||
41 | */
|
||
42 | void addFillComponents( Container panel, int[] cols, int[] rows ) |
||
43 | { |
||
44 | Dimension filler = new Dimension(10,10); |
||
45 | |||
46 | boolean filled_cell_11 = false; |
||
47 | CellConstraints cc = new CellConstraints();
|
||
48 | if ( cols.length > 0 && rows.length > 0 ) |
||
49 | { |
||
50 | if ( cols[0] == 1 && rows[0] == 1 ) |
||
51 | { |
||
52 | /** add a rigid area */
|
||
53 | panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
||
54 | filled_cell_11 = true;
|
||
55 | } |
||
56 | } |
||
57 | |||
58 | for( int index = 0; index < cols.length; index++ ) |
||
59 | { |
||
60 | if ( cols[index] == 1 && filled_cell_11 ) |
||
61 | { |
||
62 | continue;
|
||
63 | } |
||
64 | panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
||
65 | } |
||
66 | |||
67 | for( int index = 0; index < rows.length; index++ ) |
||
68 | { |
||
69 | if ( rows[index] == 1 && filled_cell_11 ) |
||
70 | { |
||
71 | continue;
|
||
72 | } |
||
73 | panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
||
74 | } |
||
75 | |||
76 | } |
||
77 | |||
78 | /**
|
||
79 | * Helper method to load an image file from the CLASSPATH
|
||
80 | * @param imageName the package and name of the file to load relative to the CLASSPATH
|
||
81 | * @return an ImageIcon instance with the specified image file
|
||
82 | * @throws IllegalArgumentException if the image resource cannot be loaded.
|
||
83 | */
|
||
84 | public ImageIcon loadImage( String imageName ) |
||
85 | { |
||
86 | try
|
||
87 | { |
||
88 | ClassLoader classloader = getClass().getClassLoader();
|
||
89 | java.net.URL url = classloader.getResource( imageName ); |
||
90 | if ( url != null ) |
||
91 | { |
||
92 | ImageIcon icon = new ImageIcon( url ); |
||
93 | return icon;
|
||
94 | } |
||
95 | } |
||
96 | catch( Exception e ) |
||
97 | { |
||
98 | e.printStackTrace(); |
||
99 | } |
||
100 | throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * Method for recalculating the component orientation for
|
||
105 | * right-to-left Locales.
|
||
106 | * @param orientation the component orientation to be applied
|
||
107 | */
|
||
108 | public void applyComponentOrientation( ComponentOrientation orientation ) |
||
109 | { |
||
110 | // Not yet implemented...
|
||
111 | // I18NUtils.applyComponentOrientation(this, orientation);
|
||
112 | super.applyComponentOrientation(orientation);
|
||
113 | } |
||
114 | |||
115 | public JPanel createPanel() |
||
116 | { |
||
117 | JPanel jpanel1 = new JPanel(); |
||
118 | 44305 | jjdelcerro | FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE"); |
119 | 44304 | jjdelcerro | CellConstraints cc = new CellConstraints();
|
120 | jpanel1.setLayout(formlayout1); |
||
121 | |||
122 | 44305 | jjdelcerro | btnConnection.setActionCommand("...");
|
123 | btnConnection.setName("btnConnection");
|
||
124 | btnConnection.setText("...");
|
||
125 | jpanel1.add(btnConnection,cc.xy(6,2)); |
||
126 | |||
127 | 44304 | jjdelcerro | JLabel jlabel1 = new JLabel(); |
128 | 44305 | jjdelcerro | jlabel1.setText("ID");
|
129 | jpanel1.add(jlabel1,cc.xy(2,4)); |
||
130 | 44304 | jjdelcerro | |
131 | 44305 | jjdelcerro | JLabel jlabel2 = new JLabel(); |
132 | jlabel2.setText("Label");
|
||
133 | jpanel1.add(jlabel2,cc.xy(2,6)); |
||
134 | |||
135 | txtID.setBackground(new Color(236,233,216)); |
||
136 | txtID.setEditable(false);
|
||
137 | txtID.setName("txtID");
|
||
138 | jpanel1.add(txtID,cc.xywh(4,4,3,1)); |
||
139 | |||
140 | txtLabel.setBackground(new Color(236,233,216)); |
||
141 | txtLabel.setEditable(false);
|
||
142 | txtLabel.setName("txtLabel");
|
||
143 | jpanel1.add(txtLabel,cc.xywh(4,6,3,1)); |
||
144 | |||
145 | 44304 | jjdelcerro | cboConnection.setName("cboConnection");
|
146 | 44305 | jjdelcerro | jpanel1.add(cboConnection,cc.xy(4,2)); |
147 | 44304 | jjdelcerro | |
148 | 44305 | jjdelcerro | JLabel jlabel3 = new JLabel(); |
149 | jlabel3.setText("Conection");
|
||
150 | jpanel1.add(jlabel3,cc.xy(2,2)); |
||
151 | 44304 | jjdelcerro | |
152 | 44305 | jjdelcerro | addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3,4,5,6,7 }); |
153 | 44304 | jjdelcerro | return jpanel1;
|
154 | } |
||
155 | |||
156 | /**
|
||
157 | * Initializer
|
||
158 | */
|
||
159 | protected void initializePanel() |
||
160 | { |
||
161 | setLayout(new BorderLayout()); |
||
162 | add(createPanel(), BorderLayout.CENTER);
|
||
163 | } |
||
164 | |||
165 | |||
166 | } |