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