Revision 19344 trunk/extensions/extSymbology/src/org/gvsig/symbology/gui/styling/PictureFill.java
PictureFill.java | ||
---|---|---|
44 | 44 |
import java.awt.Component; |
45 | 45 |
import java.awt.Container; |
46 | 46 |
import java.awt.FlowLayout; |
47 |
import java.awt.Font; |
|
47 | 48 |
import java.awt.GridLayout; |
48 | 49 |
import java.awt.event.ActionEvent; |
49 | 50 |
import java.awt.event.ActionListener; |
50 | 51 |
import java.io.File; |
51 | 52 |
import java.io.IOException; |
53 |
import java.net.MalformedURLException; |
|
54 |
import java.net.URL; |
|
52 | 55 |
import java.util.ArrayList; |
53 | 56 |
|
54 | 57 |
import javax.swing.JCheckBox; |
... | ... | |
101 | 104 |
private static File lastDir; |
102 | 105 |
|
103 | 106 |
private JLabel lblFileName; |
107 |
private JLabel lblSelFileName; |
|
104 | 108 |
private ArrayList<JPanel> tabs = new ArrayList<JPanel>(); |
105 | 109 |
private MarkerFillProperties fillProperties; |
106 | 110 |
private File picFile; |
111 |
private File selPicFile; |
|
107 | 112 |
private JIncrementalNumberField incrAngle; |
108 | 113 |
private JIncrementalNumberField incrScaleX; |
109 | 114 |
private JIncrementalNumberField incrScaleY; |
... | ... | |
115 | 120 |
private ActionListener chooseAction = new ActionListener() { |
116 | 121 |
public void actionPerformed(ActionEvent e) { |
117 | 122 |
boolean isSelection; |
123 |
JLabel targetLbl; |
|
124 |
|
|
125 |
if (e.getSource().equals(btnBrowseFile)) { |
|
126 |
targetLbl = lblFileName; |
|
127 |
isSelection = false; |
|
128 |
} else { |
|
129 |
targetLbl = lblSelFileName; |
|
130 |
isSelection = true; |
|
131 |
} |
|
132 |
|
|
118 | 133 |
FileFilter ff = new FileFilter() { |
119 | 134 |
public boolean accept(File f) { |
120 | 135 |
if (f.isDirectory()) return true; |
... | ... | |
145 | 160 |
File myFile = jfc.getSelectedFile(); |
146 | 161 |
lastDir = jfc.getCurrentDirectory(); |
147 | 162 |
if (myFile != null && myFile.exists()) { |
148 |
|
|
149 |
picFile = myFile; |
|
150 |
|
|
151 |
lblFileName.setText(myFile.getAbsolutePath()); |
|
163 |
if(!isSelection){ |
|
164 |
picFile = myFile; |
|
165 |
} |
|
166 |
else{ |
|
167 |
selPicFile = myFile; |
|
168 |
} |
|
169 |
try { |
|
170 |
targetLbl.setText(myFile.toURL().toString()); |
|
171 |
} catch (MalformedURLException e1) { |
|
172 |
NotificationManager.addError(PluginServices.getText(this, "invalid_url"), e1); |
|
173 |
} |
|
152 | 174 |
fireSymbolChangedEvent(); |
153 | 175 |
} |
154 | 176 |
} |
... | ... | |
157 | 179 |
}; |
158 | 180 |
|
159 | 181 |
private JButton btnBrowseFile; |
182 |
private JButton btnBrowseFileSelected; |
|
183 |
|
|
160 | 184 |
/** |
161 | 185 |
* Constructor method |
162 | 186 |
* @param owner |
... | ... | |
179 | 203 |
btnBrowseFile = new JButton(PluginServices.getText(this, "browse")); |
180 | 204 |
btnBrowseFile.addActionListener(chooseAction); |
181 | 205 |
|
206 |
btnBrowseFileSelected = new JButton(PluginServices.getText(this,"browse")); |
|
207 |
btnBrowseFileSelected.addActionListener(chooseAction); |
|
208 |
|
|
182 | 209 |
JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5)); |
183 | 210 |
|
211 |
JPanel auxLabelPic=new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5)); |
|
212 |
JLabel lblName = new JLabel(); |
|
213 |
lblName.setFont(lblName.getFont().deriveFont(Font.BOLD)); |
|
214 |
lblName.setText(PluginServices.getText(this, "picture_file")+":"); |
|
215 |
auxLabelPic.add(lblName); |
|
216 |
|
|
184 | 217 |
aux2.add(btnBrowseFile); |
185 |
aux2.add(lblFileName = new JLabel( |
|
186 |
PluginServices.getText(this, "none_selected"))); |
|
218 |
aux2.add(lblFileName = new JLabel("")); |
|
187 | 219 |
|
220 |
JPanel auxLabelSelPic=new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5)); |
|
221 |
JLabel lblSelName = new JLabel(); |
|
222 |
lblSelName.setFont(lblSelName.getFont().deriveFont(Font.BOLD)); |
|
223 |
lblSelName.setText(PluginServices.getText(this, "selection_picture_file")+":"); |
|
224 |
auxLabelSelPic.add(lblSelName); |
|
225 |
|
|
226 |
JPanel aux4 = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5)); |
|
227 |
aux4.add(btnBrowseFileSelected); |
|
228 |
aux4.add(lblSelFileName = new JLabel("")); |
|
229 |
|
|
188 | 230 |
GridBagLayoutPanel aux = new GridBagLayoutPanel(); |
189 |
aux.addComponent(new JBlank(20, 20)); |
|
231 |
aux.addComponent(new JBlank(5, 5)); |
|
232 |
aux.addComponent(auxLabelPic); |
|
190 | 233 |
aux.addComponent(aux2); |
234 |
aux.addComponent(auxLabelSelPic); |
|
235 |
aux.addComponent(aux4); |
|
191 | 236 |
|
237 |
|
|
192 | 238 |
aux2 = new JPanel(new GridLayout(1, 2, 20, 5)); |
193 | 239 |
GridBagLayoutPanel aux3; |
194 | 240 |
aux3 = new GridBagLayoutPanel(); |
... | ... | |
224 | 270 |
aux2.add(aux3); |
225 | 271 |
|
226 | 272 |
aux.addComponent(aux2); |
227 |
aux.addComponent(new JBlank(20, 20));
|
|
273 |
aux.addComponent(new JBlank(10, 10));
|
|
228 | 274 |
aux2 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
229 | 275 |
aux2.add(btnOutline = new JSymbolPreviewButton(FShape.LINE)); |
230 | 276 |
useBorder = new JCheckBox(PluginServices.getText(this, "use_outline")); |
... | ... | |
245 | 291 |
|
246 | 292 |
tabs.add(myTab); |
247 | 293 |
tabs.add(fillProperties); |
248 |
setControlsEnabled(false); |
|
249 | 294 |
|
250 | 295 |
} |
251 | 296 |
|
... | ... | |
256 | 301 |
|
257 | 302 |
public ISymbol getLayer() { |
258 | 303 |
File imageFile = new File(lblFileName.getText()); |
259 |
|
|
260 |
boolean enabled = imageFile.exists(); |
|
261 |
setControlsEnabled(enabled); |
|
262 |
|
|
263 |
PictureFillSymbol sym = new PictureFillSymbol();
|
|
304 |
File imageSelFile = new File(lblSelFileName.getText()); |
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
PictureFillSymbol sym=null;
|
|
264 | 309 |
try { |
265 |
sym.setImage(imageFile); |
|
310 |
|
|
311 |
if( lblFileName.getText().equals("") ) |
|
312 |
sym=null; |
|
313 |
|
|
314 |
else { |
|
315 |
sym = new PictureFillSymbol(new URL(lblFileName.getText()),null); |
|
316 |
if (!lblSelFileName.getText().equals("")) |
|
317 |
sym = new PictureFillSymbol(new URL(lblFileName.getText()),new URL(lblSelFileName.getText())); |
|
318 |
|
|
319 |
sym.setHasFill(jccFillColor.getUseColorisSelected()); |
|
320 |
Color c = jccFillColor.getColor(); |
|
321 |
if (c != null) |
|
322 |
c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); |
|
323 |
sym.setFillColor(c); |
|
324 |
|
|
325 |
sym.setHasOutline(useBorder.isSelected()); |
|
326 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
|
327 |
sym.setOutline(outline); |
|
328 |
|
|
329 |
sym.setAngle(incrAngle.getDouble()*FConstant.DEGREE_TO_RADIANS); |
|
330 |
sym.setXScale(incrScaleX.getDouble()); |
|
331 |
sym.setYScale(incrScaleY.getDouble()); |
|
332 |
sym.setMarkerFillProperties(fillProperties.getMarkerFillProperties()); |
|
333 |
} |
|
266 | 334 |
|
267 |
sym.setHasFill(jccFillColor.getUseColorisSelected()); |
|
268 |
Color c = jccFillColor.getColor(); |
|
269 |
if (c != null) |
|
270 |
c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); |
|
271 |
sym.setFillColor(c); |
|
272 |
|
|
273 |
sym.setHasOutline(useBorder.isSelected()); |
|
274 |
outline = (ILineSymbol) btnOutline.getSymbol(); |
|
275 |
sym.setOutline(outline); |
|
276 |
|
|
277 |
sym.setAngle(incrAngle.getDouble()*FConstant.DEGREE_TO_RADIANS); |
|
278 |
sym.setXScale(incrScaleX.getDouble()); |
|
279 |
sym.setYScale(incrScaleY.getDouble()); |
|
280 |
sym.setMarkerFillProperties(fillProperties.getMarkerFillProperties()); |
|
281 |
return sym; |
|
282 | 335 |
} catch (IOException e) { |
283 | 336 |
// TODO Auto-generated catch block |
284 | 337 |
NotificationManager.addError(PluginServices.getText(this, "could_not_open_picture_file"), e); |
285 | 338 |
return null; |
286 | 339 |
} |
287 | 340 |
|
341 |
return sym; |
|
342 |
|
|
343 |
|
|
288 | 344 |
} |
289 | 345 |
|
290 | 346 |
private void setControlsEnabled(boolean enabled) { |
... | ... | |
327 | 383 |
PictureFillSymbol sym = (PictureFillSymbol) layer; |
328 | 384 |
|
329 | 385 |
File imageFile = new File(sym.getImagePath()); |
330 |
|
|
331 |
boolean enabled = imageFile.exists(); |
|
332 |
setControlsEnabled(enabled); |
|
333 |
|
|
386 |
File selImageFile = new File (sym.getSelImagePath()); |
|
387 |
|
|
388 |
// boolean enabled = imageFile.exists(); |
|
389 |
// setControlsEnabled(enabled); |
|
390 |
|
|
334 | 391 |
lblFileName.setText(sym.getImagePath()); |
392 |
lblSelFileName.setText(sym.getSelImagePath()); |
|
335 | 393 |
jccFillColor.setUseColorIsSelected(sym.hasFill()); |
336 | 394 |
jccFillColor.setColor(sym.getFillColor()); |
337 |
|
|
395 |
|
|
338 | 396 |
outline=sym.getOutline(); |
339 | 397 |
btnOutline.setSymbol(outline); |
340 | 398 |
useBorder.setSelected(sym.hasOutline()); |
341 |
|
|
399 |
|
|
342 | 400 |
incrAngle.setDouble(sym.getAngle()/FConstant.DEGREE_TO_RADIANS); |
343 | 401 |
incrScaleX.setDouble(sym.getXScale()); |
344 | 402 |
incrScaleY.setDouble(sym.getYScale()); |
345 | 403 |
fillProperties.setModel(sym.getMarkerFillProperties()); |
404 |
|
|
346 | 405 |
|
347 | 406 |
|
348 | 407 |
} |
Also available in: Unified diff