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