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