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