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