root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFramePictureDialog.java @ 36648
History | View | Annotate | Download (14.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.fframes.gui.dialogs; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.io.File; |
28 |
|
29 |
import javax.swing.JFileChooser; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.messages.NotificationManager; |
33 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
34 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
35 |
import org.gvsig.app.project.documents.layout.fframes.FFramePicture; |
36 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
37 |
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation; |
38 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
39 |
import org.gvsig.utils.GenericFileFilter; |
40 |
|
41 |
/**
|
42 |
* Dialogo para a?adir una imagen al Layout.
|
43 |
*
|
44 |
* @author Vicente Caballero Navarro
|
45 |
*/
|
46 |
public class FFramePictureDialog extends AbstractFFrameDialog implements |
47 |
IFFrameDialog { |
48 |
|
49 |
private static final long serialVersionUID = -5270176004672972463L; |
50 |
private javax.swing.JPanel jContentPane = null; |
51 |
private javax.swing.JLabel lFichero = null; |
52 |
private javax.swing.JTextField tFichero = null; |
53 |
private javax.swing.JButton bExaminar = null; |
54 |
private javax.swing.JLabel lVisualizacion = null; |
55 |
private javax.swing.JComboBox cbVisualizacion = null; |
56 |
private javax.swing.JLabel lCalidad = null; |
57 |
private javax.swing.JComboBox cbCalidad = null; |
58 |
private javax.swing.JButton bAceptar = null; |
59 |
private javax.swing.JButton bCancelar = null; |
60 |
private Rectangle2D rect = new Rectangle2D.Double(); |
61 |
private FFramePicture fframepicture = null; // = new FFramePicture(); |
62 |
private String namefile = null; |
63 |
private boolean isAcepted = false; |
64 |
private JPRotation pRotation = null; |
65 |
private String path; |
66 |
private FFramePicture newFFramePicture = null; |
67 |
|
68 |
/**
|
69 |
* This is the default constructor
|
70 |
*
|
71 |
* @param layoutPanel
|
72 |
* Referencia al Layout.
|
73 |
* @param fframe
|
74 |
* Referencia al fframe de imagen.
|
75 |
*/
|
76 |
public FFramePictureDialog(LayoutPanel layoutPanel, IFFrame frame) {
|
77 |
super(layoutPanel, frame);
|
78 |
fframepicture = (FFramePicture) frame; |
79 |
initialize(); |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Inserta el rect?ngulo que ocupar? el fframe de imagen.
|
84 |
*
|
85 |
* @param r
|
86 |
* Rect?ngulo.
|
87 |
*/
|
88 |
public void setRectangle(Rectangle2D r) { |
89 |
rect.setRect(r); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* This method initializes this
|
94 |
*/
|
95 |
private void initialize() { |
96 |
this.setLayout(null); |
97 |
this.add(getJContentPane(), null); |
98 |
this.setSize(505, 142); |
99 |
getPRotation().setRotation(fframepicture.getRotation()); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* This method initializes jContentPane
|
104 |
*
|
105 |
* @return javax.swing.JPanel
|
106 |
*/
|
107 |
private javax.swing.JPanel getJContentPane() {
|
108 |
if (jContentPane == null) { |
109 |
jContentPane = new javax.swing.JPanel();
|
110 |
jContentPane.setLayout(null);
|
111 |
jContentPane.add(getLFichero(), null);
|
112 |
jContentPane.add(getLCalidad(), null);
|
113 |
jContentPane.add(getCbCalidad(), null);
|
114 |
jContentPane.add(getTFichero(), null);
|
115 |
jContentPane.add(getBExaminar(), null);
|
116 |
jContentPane.add(getLVisualizacion(), null);
|
117 |
jContentPane.add(getCbVisualizacion(), null);
|
118 |
jContentPane.add(getBAceptar(), null);
|
119 |
jContentPane.add(getBCancelar(), null);
|
120 |
jContentPane.setSize(499, 139); |
121 |
jContentPane.setLocation(3, 0); |
122 |
jContentPane.add(getPRotation(), null);
|
123 |
} |
124 |
|
125 |
return jContentPane;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* This method initializes lFichero
|
130 |
*
|
131 |
* @return javax.swing.JLabel
|
132 |
*/
|
133 |
private javax.swing.JLabel getLFichero() {
|
134 |
if (lFichero == null) { |
135 |
lFichero = new javax.swing.JLabel();
|
136 |
lFichero.setSize(42, 20); |
137 |
lFichero.setText(PluginServices.getText(this, "Fichero")); |
138 |
lFichero.setLocation(10, 9); |
139 |
} |
140 |
|
141 |
return lFichero;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* This method initializes tFichero
|
146 |
*
|
147 |
* @return javax.swing.JTextField
|
148 |
*/
|
149 |
private javax.swing.JTextField getTFichero() {
|
150 |
if (tFichero == null) { |
151 |
tFichero = new javax.swing.JTextField();
|
152 |
tFichero.setBounds(62, 8, 200, 20); |
153 |
tFichero.setPreferredSize(new java.awt.Dimension(200, 20)); |
154 |
} |
155 |
|
156 |
if (fframepicture.getPath() != null) { |
157 |
tFichero.setText(fframepicture.getPath()); |
158 |
} |
159 |
|
160 |
return tFichero;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* This method initializes bExaminar
|
165 |
*
|
166 |
* @return javax.swing.JButton
|
167 |
*/
|
168 |
private javax.swing.JButton getBExaminar() {
|
169 |
if (bExaminar == null) { |
170 |
bExaminar = new javax.swing.JButton();
|
171 |
bExaminar.setSize(88, 23); |
172 |
bExaminar.setText(PluginServices.getText(this, "Examinar")); |
173 |
bExaminar.setLocation(275, 6); |
174 |
bExaminar.setPreferredSize(new java.awt.Dimension(88, 23)); |
175 |
bExaminar.addActionListener(new java.awt.event.ActionListener() {
|
176 |
|
177 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
178 |
String[] extensions = |
179 |
{ "jpeg", "jpg", "gif", "png", "bmp", "svg" }; |
180 |
GenericFileFilter filter = |
181 |
new GenericFileFilter(extensions,
|
182 |
"Image files (jpeg, jpg, gif, png, bmp, svg)");
|
183 |
|
184 |
JFileChooser jfc = new JFileChooser(); |
185 |
jfc.addChoosableFileFilter(filter); |
186 |
if (jfc.showOpenDialog((Component) PluginServices |
187 |
.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
188 |
File file = jfc.getSelectedFile();
|
189 |
namefile = file.getName(); |
190 |
getTFichero().setText(file.getAbsolutePath()); |
191 |
path = file.getAbsolutePath(); |
192 |
// fframepicture.setPath(file.getAbsolutePath());
|
193 |
} |
194 |
} |
195 |
}); |
196 |
} |
197 |
|
198 |
return bExaminar;
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* Inserta el path al TFichero.
|
203 |
*
|
204 |
* @param val
|
205 |
* path del fichero.
|
206 |
*/
|
207 |
public void setText(String val) { |
208 |
getTFichero().setText(val); |
209 |
} |
210 |
|
211 |
/**
|
212 |
* This method initializes lVisualizacion
|
213 |
*
|
214 |
* @return javax.swing.JLabel
|
215 |
*/
|
216 |
private javax.swing.JLabel getLVisualizacion() {
|
217 |
if (lVisualizacion == null) { |
218 |
lVisualizacion = new javax.swing.JLabel();
|
219 |
lVisualizacion.setBounds(9, 62, 105, 20); |
220 |
lVisualizacion.setText(PluginServices |
221 |
.getText(this, "visualizacion")); |
222 |
lVisualizacion.setVisible(false);
|
223 |
} |
224 |
|
225 |
return lVisualizacion;
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* This method initializes cbVisualizacion
|
230 |
*
|
231 |
* @return javax.swing.JComboBox
|
232 |
*/
|
233 |
private javax.swing.JComboBox getCbVisualizacion() {
|
234 |
if (cbVisualizacion == null) { |
235 |
cbVisualizacion = new javax.swing.JComboBox();
|
236 |
cbVisualizacion.setSize(245, 20); |
237 |
cbVisualizacion.addItem(PluginServices.getText(this,
|
238 |
"cuando_activo"));
|
239 |
cbVisualizacion.addItem(PluginServices.getText(this, "siempre")); |
240 |
cbVisualizacion.setSelectedIndex(fframepicture.getViewing()); |
241 |
cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20)); |
242 |
cbVisualizacion.setLocation(118, 62); |
243 |
cbVisualizacion.setEnabled(false);
|
244 |
cbVisualizacion.setVisible(false);
|
245 |
} |
246 |
|
247 |
return cbVisualizacion;
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* This method initializes lCalidad
|
252 |
*
|
253 |
* @return javax.swing.JLabel
|
254 |
*/
|
255 |
private javax.swing.JLabel getLCalidad() {
|
256 |
if (lCalidad == null) { |
257 |
lCalidad = new javax.swing.JLabel();
|
258 |
lCalidad.setSize(103, 20); |
259 |
lCalidad.setText(PluginServices.getText(this, "calidad")); |
260 |
lCalidad.setPreferredSize(new java.awt.Dimension(73, 16)); |
261 |
lCalidad.setLocation(10, 35); |
262 |
} |
263 |
|
264 |
return lCalidad;
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* This method initializes cbCalidad
|
269 |
*
|
270 |
* @return javax.swing.JComboBox
|
271 |
*/
|
272 |
private javax.swing.JComboBox getCbCalidad() {
|
273 |
if (cbCalidad == null) { |
274 |
cbCalidad = new javax.swing.JComboBox();
|
275 |
cbCalidad.setSize(245, 20); |
276 |
cbCalidad.addItem(PluginServices.getText(this, "presentacion")); |
277 |
cbCalidad.addItem(PluginServices.getText(this, "borrador")); |
278 |
cbCalidad.setSelectedIndex(fframepicture.getQuality()); |
279 |
cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20)); |
280 |
cbCalidad.setLocation(118, 35); |
281 |
} |
282 |
|
283 |
return cbCalidad;
|
284 |
} |
285 |
|
286 |
/**
|
287 |
* This method initializes bAceptar
|
288 |
*
|
289 |
* @return javax.swing.JButton
|
290 |
*/
|
291 |
private javax.swing.JButton getBAceptar() {
|
292 |
if (bAceptar == null) { |
293 |
bAceptar = new javax.swing.JButton();
|
294 |
bAceptar.setSize(85, 26); |
295 |
bAceptar.setText(PluginServices.getText(this, "Aceptar")); |
296 |
bAceptar.setLocation(70, 89); |
297 |
bAceptar.addActionListener(new java.awt.event.ActionListener() {
|
298 |
|
299 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
300 |
Dimension dimension = null; |
301 |
try {
|
302 |
// ImageIcon imageIcon = new
|
303 |
// ImageIcon(getTFichero().getText());
|
304 |
dimension = |
305 |
fframepicture.getBound(getTFichero().getText()); |
306 |
} catch (Exception ex) { |
307 |
NotificationManager.addError("Excepci?n :", ex);
|
308 |
} |
309 |
try {
|
310 |
newFFramePicture = |
311 |
(FFramePicture) fframepicture.clone(); |
312 |
if (path == null) { |
313 |
path = getTFichero().getText(); |
314 |
} |
315 |
newFFramePicture.setPath(path); |
316 |
newFFramePicture.setViewing(getCbVisualizacion() |
317 |
.getSelectedIndex()); |
318 |
newFFramePicture.setQuality(getCbCalidad() |
319 |
.getSelectedIndex()); |
320 |
|
321 |
// if (namefile != null) {
|
322 |
// newFFramePicture.setName(namefile);
|
323 |
// }
|
324 |
// // Ajustamos la relaci?n de aspecto a la altura.
|
325 |
double ratio =
|
326 |
(float) (dimension.getWidth())
|
327 |
/ (float) (dimension.getHeight());
|
328 |
|
329 |
double newWidth = rect.getHeight() * ratio;
|
330 |
Rectangle2D.Double rAdjust =
|
331 |
new Rectangle2D.Double(rect.getMinX(), rect |
332 |
.getMinY(), newWidth, rect.getHeight()); |
333 |
rect = rAdjust; |
334 |
|
335 |
newFFramePicture.setBoundBox(FLayoutUtilities |
336 |
.toSheetRect(rect, layoutPanel.getLayoutControl() |
337 |
.getAT())); |
338 |
newFFramePicture.setRotation(getPRotation() |
339 |
.getRotation()); |
340 |
} catch (CloneNotSupportedException e1) { |
341 |
LOG.error("It is not possible clonate the object", e);
|
342 |
} |
343 |
|
344 |
PluginServices.getMDIManager().closeWindow( |
345 |
FFramePictureDialog.this); |
346 |
// m_layout.refresh();
|
347 |
isAcepted = true;
|
348 |
} |
349 |
}); |
350 |
} |
351 |
|
352 |
return bAceptar;
|
353 |
} |
354 |
|
355 |
/**
|
356 |
* This method initializes bCancelar
|
357 |
*
|
358 |
* @return javax.swing.JButton
|
359 |
*/
|
360 |
private javax.swing.JButton getBCancelar() {
|
361 |
if (bCancelar == null) { |
362 |
bCancelar = new javax.swing.JButton();
|
363 |
bCancelar.setSize(85, 26); |
364 |
bCancelar.setText(PluginServices.getText(this, "Cancelar")); |
365 |
bCancelar.setLocation(219, 89); |
366 |
bCancelar.addActionListener(new java.awt.event.ActionListener() {
|
367 |
|
368 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
369 |
newFFramePicture = null;
|
370 |
PluginServices.getMDIManager().closeWindow( |
371 |
FFramePictureDialog.this); |
372 |
} |
373 |
}); |
374 |
} |
375 |
|
376 |
return bCancelar;
|
377 |
} |
378 |
|
379 |
/*
|
380 |
* (non-Javadoc)
|
381 |
*
|
382 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
383 |
*/
|
384 |
public WindowInfo getWindowInfo() {
|
385 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
386 |
m_viewinfo.setTitle(PluginServices.getText(this,
|
387 |
"propiedades_marco_imagenes"));
|
388 |
|
389 |
return m_viewinfo;
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
|
394 |
*/
|
395 |
public boolean getIsAcepted() { |
396 |
return isAcepted;
|
397 |
} |
398 |
|
399 |
/**
|
400 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
401 |
*/
|
402 |
public void viewActivated() { |
403 |
} |
404 |
|
405 |
/**
|
406 |
* This method initializes pRotation
|
407 |
*
|
408 |
* @return javax.swing.JPanel
|
409 |
*/
|
410 |
private JPRotation getPRotation() {
|
411 |
if (pRotation == null) { |
412 |
pRotation = new JPRotation();
|
413 |
pRotation.setBounds(373, 14, 120, 120); |
414 |
} |
415 |
return pRotation;
|
416 |
} |
417 |
|
418 |
public IFFrame getFFrame() {
|
419 |
return newFFramePicture;
|
420 |
} |
421 |
|
422 |
public Object getWindowProfile() { |
423 |
return WindowInfo.DIALOG_PROFILE;
|
424 |
} |
425 |
|
426 |
} // @jve:decl-index=0:visual-constraint="10,10"
|