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