svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFrameViewDialog.java @ 228
History | View | Annotate | Download (18 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.Dimension; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.GridBagLayout; |
27 |
import java.awt.Insets; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.awt.geom.Rectangle2D; |
31 |
|
32 |
import javax.swing.JButton; |
33 |
import javax.swing.JCheckBox; |
34 |
import javax.swing.JList; |
35 |
import javax.swing.JOptionPane; |
36 |
import javax.swing.JPanel; |
37 |
|
38 |
import org.gvsig.andami.messages.NotificationManager; |
39 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
40 |
import org.gvsig.app.ApplicationLocator; |
41 |
import org.gvsig.app.project.ProjectManager; |
42 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
43 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
44 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid; |
45 |
import org.gvsig.app.project.documents.layout.fframes.FFrameView; |
46 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
47 |
import org.gvsig.app.project.documents.layout.fframes.ListViewModel; |
48 |
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation; |
49 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
50 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
51 |
import org.gvsig.fmap.mapcontext.ViewPort; |
52 |
import org.gvsig.i18n.Messages; |
53 |
|
54 |
/**
|
55 |
* Dialog to add a view to the Layout document, by means of a FFrameView
|
56 |
*
|
57 |
* @author Vicente Caballero Navarro
|
58 |
* @author Cesar Martinez Izquierdo
|
59 |
*/
|
60 |
public class FFrameViewDialog extends AbstractFFrameDialog implements |
61 |
IFFrameDialog { |
62 |
|
63 |
private static final long serialVersionUID = -7223804566537544559L; |
64 |
|
65 |
private final LayoutManager layoutManager; |
66 |
private javax.swing.JLabel lViews = null; |
67 |
private javax.swing.JScrollPane jScrollPane = null; |
68 |
private javax.swing.JList liViews = null; // @jve:visual-info decl-index=0 |
69 |
// visual-constraint="98,-3"
|
70 |
private javax.swing.JCheckBox chbSyncLayers = null; |
71 |
private javax.swing.JButton bAceptar = null; |
72 |
private javax.swing.JButton bCancelar = null; |
73 |
private javax.swing.JLabel lCalidad = null; |
74 |
private javax.swing.JComboBox cbCalidad = null; |
75 |
private DefaultViewDocument m_projectView = null; |
76 |
private Rectangle2D rect = new Rectangle2D.Double(); |
77 |
private FFrameView fframeview = null; // new FFrameView(); |
78 |
private boolean isAcepted = false; |
79 |
private JPRotation rotation = null; |
80 |
private FFrameView newFFrameView = null; |
81 |
private javax.swing.JButton bGrid = null; |
82 |
private javax.swing.JCheckBox chbShowGrid = null; |
83 |
private JPanel pnlFirstRow = null; |
84 |
private JCheckBox chbSyncExtent = null; |
85 |
|
86 |
private WindowInfo windowInfo = null; |
87 |
|
88 |
|
89 |
/**
|
90 |
* This is the default constructor
|
91 |
*
|
92 |
* @param layoutPanel
|
93 |
* Referencia al Layout.
|
94 |
* @param fframe
|
95 |
* Referencia al fframe vista.
|
96 |
*/
|
97 |
public FFrameViewDialog(LayoutPanel layoutPanel, IFFrame frame) {
|
98 |
super(layoutPanel, frame);
|
99 |
fframeview = (FFrameView) frame; |
100 |
initComponents(); |
101 |
layoutManager = (LayoutManager) ProjectManager.getInstance()
|
102 |
.getDocumentManager("project.document.layout");
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* This method initializes this
|
107 |
*/
|
108 |
private void initComponents() { |
109 |
this.setLayout(new GridBagLayout()); |
110 |
GridBagConstraints c = new GridBagConstraints(); |
111 |
Insets insets = new Insets(5, 5, 5, 5); |
112 |
int row = 0; |
113 |
c.gridx = 0;
|
114 |
c.gridy = row++; |
115 |
c.insets = new Insets(0,0,0,0); |
116 |
c.anchor = GridBagConstraints.LINE_START;
|
117 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
118 |
add(getFirstRowPnl(), c); |
119 |
c.insets = insets; |
120 |
c.gridx = 0;
|
121 |
c.gridy = row++; |
122 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
123 |
add(getChbSyncLayers(), c); |
124 |
c.insets = insets; |
125 |
c.gridx = 0;
|
126 |
c.gridy = row++; |
127 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
128 |
add(getChbSyncExtent(), c); |
129 |
c.gridx = 0;
|
130 |
c.gridy = row++; |
131 |
c.gridwidth = 1;
|
132 |
add(getLCalidad(), c); |
133 |
c.gridx = 1;
|
134 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
135 |
add(getCbCalidad(), c); |
136 |
c.gridx = 0;
|
137 |
c.gridy = row++; |
138 |
c.gridwidth = 1;
|
139 |
add(getChbShowGrid(), c); |
140 |
c.gridx = 1;
|
141 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
142 |
add(getBGrid(), c); |
143 |
JPanel acceptCancelPnl = new JPanel(new GridBagLayout()); |
144 |
c.anchor = GridBagConstraints.LINE_START;
|
145 |
c.gridx = 0;
|
146 |
c.gridy = 0;
|
147 |
c.gridwidth = 1;
|
148 |
acceptCancelPnl.add(getbAceptar(), c); |
149 |
c.gridx = 1;
|
150 |
acceptCancelPnl.add(getBCancelar(), c); |
151 |
c.gridx = 0;
|
152 |
c.gridy = row++; |
153 |
c.anchor = GridBagConstraints.LINE_END;
|
154 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
155 |
add(acceptCancelPnl, c); |
156 |
} |
157 |
|
158 |
public void setRectangle(Rectangle2D r) { |
159 |
rect.setRect(r); |
160 |
} |
161 |
|
162 |
private JPanel getFirstRowPnl() { |
163 |
if (pnlFirstRow==null) { |
164 |
pnlFirstRow = new JPanel(new GridBagLayout()); |
165 |
GridBagConstraints c = new GridBagConstraints(); |
166 |
Insets insets = new Insets(5, 5, 5, 5); |
167 |
c.gridx = 0;
|
168 |
c.gridy = 1;
|
169 |
c.insets = insets; |
170 |
c.anchor = GridBagConstraints.PAGE_START;
|
171 |
pnlFirstRow.add(getLViews(), c); |
172 |
c.gridx = 1;
|
173 |
pnlFirstRow.add(getScrolledViewList(), c); |
174 |
c.gridx = 2;
|
175 |
pnlFirstRow.add(getPRotation(), c); |
176 |
} |
177 |
return pnlFirstRow;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* This method initializes lVistas
|
182 |
*
|
183 |
* @return javax.swing.JLabel
|
184 |
*/
|
185 |
private javax.swing.JLabel getLViews() {
|
186 |
if (lViews == null) { |
187 |
lViews = new javax.swing.JLabel();
|
188 |
lViews.setText(Messages.getText("Vista"));
|
189 |
} |
190 |
|
191 |
return lViews;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* This method initializes jScrollPane
|
196 |
*
|
197 |
* @return javax.swing.JScrollPane
|
198 |
*/
|
199 |
private javax.swing.JScrollPane getScrolledViewList() {
|
200 |
if (jScrollPane == null) { |
201 |
jScrollPane = new javax.swing.JScrollPane();
|
202 |
jScrollPane.setViewportView(getViewList()); |
203 |
jScrollPane.setPreferredSize(new java.awt.Dimension(300, 100)); |
204 |
} |
205 |
return jScrollPane;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* This method initializes liVistas
|
210 |
*
|
211 |
* @return javax.swing.JList
|
212 |
*/
|
213 |
private javax.swing.JList getViewList() {
|
214 |
if (liViews == null) { |
215 |
ListViewModel listmodel = new ListViewModel();
|
216 |
|
217 |
if (listmodel.addViews()) {
|
218 |
JOptionPane.showMessageDialog(
|
219 |
ApplicationLocator.getManager().getRootComponent(), |
220 |
Messages.getText("_Some_views_excluded_from_list_because_have_editing_layers"),
|
221 |
Messages.getText("propiedades_marco_vista"),
|
222 |
JOptionPane.WARNING_MESSAGE);
|
223 |
} |
224 |
|
225 |
liViews = new javax.swing.JList();
|
226 |
liViews.setModel(listmodel); |
227 |
for (int i = 0; i < liViews.getModel().getSize(); i++) { |
228 |
if (fframeview.getMapContext() != null) { |
229 |
|
230 |
DefaultViewDocument pvaux = |
231 |
(DefaultViewDocument) liViews.getModel().getElementAt( |
232 |
i); |
233 |
|
234 |
if (pvaux.getMapContext()
|
235 |
.equals(fframeview.getMapContext())) { |
236 |
liViews.setSelectedIndex(i); |
237 |
m_projectView = |
238 |
(DefaultViewDocument) liViews.getModel() |
239 |
.getElementAt(i); |
240 |
} |
241 |
} |
242 |
} |
243 |
|
244 |
liViews |
245 |
.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
246 |
|
247 |
private int selectIndex = -1; |
248 |
public void valueChanged( |
249 |
javax.swing.event.ListSelectionEvent e) { |
250 |
int selectInt =
|
251 |
((JList) e.getSource()).getSelectedIndex();
|
252 |
if (selectInt != selectIndex) {
|
253 |
selectIndex = selectInt; |
254 |
if (selectIndex == -1) { |
255 |
return;
|
256 |
} |
257 |
m_projectView = |
258 |
(DefaultViewDocument) liViews.getModel() |
259 |
.getElementAt(selectInt); |
260 |
ViewPort vp; |
261 |
try {
|
262 |
vp = |
263 |
(ViewPort) m_projectView.getMapContext() |
264 |
.getViewPort().clone(); |
265 |
vp.setImageSize(new Dimension((int) rect |
266 |
.getWidth(), (int) rect.getHeight()));
|
267 |
} catch (CloneNotSupportedException e1) { |
268 |
NotificationManager.addError("Excepci?n :", e1);
|
269 |
} |
270 |
} |
271 |
} |
272 |
}); |
273 |
} |
274 |
|
275 |
return liViews;
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* This method initializes chbEnlaceVivo
|
280 |
*
|
281 |
* @return javax.swing.JCheckBox
|
282 |
*/
|
283 |
private javax.swing.JCheckBox getChbSyncLayers() {
|
284 |
if (chbSyncLayers == null) { |
285 |
chbSyncLayers = new javax.swing.JCheckBox();
|
286 |
chbSyncLayers.setText(Messages.getText("Synchronize_layers"));
|
287 |
chbSyncLayers.setSelected(fframeview.getLayerSynced()); |
288 |
chbSyncLayers.addActionListener(new ActionListener() { |
289 |
|
290 |
public void actionPerformed(ActionEvent e) { |
291 |
if (chbSyncLayers.isSelected()) {
|
292 |
JOptionPane.showMessageDialog(FFrameViewDialog.this,
|
293 |
Messages.getText("Warning_Enabling_layer_synchronization_will_discard_any_change_not_present_in_associated_view"),
|
294 |
Messages.getText("Warning_Layer_sync"),
|
295 |
JOptionPane.WARNING_MESSAGE);
|
296 |
} |
297 |
} |
298 |
|
299 |
}); |
300 |
} |
301 |
|
302 |
return chbSyncLayers;
|
303 |
} |
304 |
|
305 |
private javax.swing.JCheckBox getChbSyncExtent() {
|
306 |
if (chbSyncExtent==null) { |
307 |
chbSyncExtent = new javax.swing.JCheckBox();
|
308 |
chbSyncExtent.setText(Messages.getText("Synchronize_extents"));
|
309 |
chbSyncExtent.setSelected(fframeview.getExtentSynced()); |
310 |
} |
311 |
return chbSyncExtent;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* This method initializes jButton
|
316 |
*
|
317 |
* @return javax.swing.JButton
|
318 |
*/
|
319 |
private javax.swing.JButton getbAceptar() {
|
320 |
if (bAceptar == null) { |
321 |
bAceptar = new javax.swing.JButton();
|
322 |
bAceptar.setText(Messages.getText("Aceptar"));
|
323 |
bAceptar.addActionListener(new java.awt.event.ActionListener() {
|
324 |
|
325 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
326 |
try {
|
327 |
newFFrameView = (FFrameView) fframeview.clone(); |
328 |
newFFrameView.setBoundBox(FLayoutUtilities.toSheetRect( |
329 |
rect, layoutPanel.getLayoutControl().getAT())); |
330 |
newFFrameView.setRotation(getPRotation().getRotation()); |
331 |
newFFrameView.setHasToc(true);
|
332 |
newFFrameView.setLayerSynced(getChbSyncLayers() |
333 |
.isSelected()); |
334 |
newFFrameView.setExtentSynced(getChbSyncExtent().isSelected()); |
335 |
|
336 |
if (m_projectView != null) { |
337 |
newFFrameView.setView(m_projectView); |
338 |
newFFrameView.setQuality(getCbCalidad() |
339 |
.getSelectedIndex()); |
340 |
if (fframeview.getGrid() != null) { |
341 |
((FFrameGrid) fframeview.getGrid()) |
342 |
.setFFrameDependence(newFFrameView); |
343 |
newFFrameView.setGrid(fframeview.getGrid()); |
344 |
} |
345 |
newFFrameView.showGrid(getChbShowGrid() |
346 |
.isSelected()); |
347 |
newFFrameView.setBoundBox(FLayoutUtilities |
348 |
.toSheetRect(rect, layoutPanel |
349 |
.getLayoutControl().getAT())); |
350 |
} |
351 |
} catch (CloneNotSupportedException e1) { |
352 |
LOG.error("It is not possible to clone the object", e);
|
353 |
} |
354 |
isAcepted = true;
|
355 |
ApplicationLocator.getManager().getUIManager().closeWindow( |
356 |
FFrameViewDialog.this); |
357 |
layoutPanel.getLayoutControl().setDefaultTool(); |
358 |
} |
359 |
}); |
360 |
} |
361 |
|
362 |
return bAceptar;
|
363 |
} |
364 |
|
365 |
/**
|
366 |
* This method initializes bCancelar
|
367 |
*
|
368 |
* @return javax.swing.JButton
|
369 |
*/
|
370 |
private javax.swing.JButton getBCancelar() {
|
371 |
if (bCancelar == null) { |
372 |
bCancelar = new javax.swing.JButton();
|
373 |
bCancelar.setText(Messages.getText("Cancelar"));
|
374 |
bCancelar.addActionListener(new java.awt.event.ActionListener() {
|
375 |
|
376 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
377 |
newFFrameView = null;
|
378 |
ApplicationLocator.getManager().getUIManager().closeWindow( |
379 |
FFrameViewDialog.this); |
380 |
} |
381 |
}); |
382 |
} |
383 |
|
384 |
return bCancelar;
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* This method initializes lCalidad
|
389 |
*
|
390 |
* @return javax.swing.JLabel
|
391 |
*/
|
392 |
private javax.swing.JLabel getLCalidad() {
|
393 |
if (lCalidad == null) { |
394 |
lCalidad = new javax.swing.JLabel();
|
395 |
lCalidad.setText(Messages.getText("calidad"));
|
396 |
} |
397 |
|
398 |
return lCalidad;
|
399 |
} |
400 |
|
401 |
/**
|
402 |
* This method initializes cbCalidad
|
403 |
*
|
404 |
* @return javax.swing.JComboBox
|
405 |
*/
|
406 |
private javax.swing.JComboBox getCbCalidad() {
|
407 |
if (cbCalidad == null) { |
408 |
// String[] s={"Presentaci?n","Borrador"};
|
409 |
cbCalidad = new javax.swing.JComboBox();
|
410 |
cbCalidad.addItem(Messages.getText("presentacion"));
|
411 |
cbCalidad.addItem(Messages.getText("borrador"));
|
412 |
cbCalidad.setSelectedIndex(fframeview.getQuality()); |
413 |
} |
414 |
|
415 |
return cbCalidad;
|
416 |
} |
417 |
|
418 |
/*
|
419 |
* (non-Javadoc)
|
420 |
*
|
421 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
422 |
*/
|
423 |
public WindowInfo getWindowInfo() {
|
424 |
if (windowInfo==null) { |
425 |
windowInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
426 |
windowInfo.setHeight(300);
|
427 |
windowInfo.setWidth(550);
|
428 |
windowInfo.setTitle(Messages.getText( |
429 |
"propiedades_marco_vista"));
|
430 |
} |
431 |
return windowInfo;
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
|
436 |
*/
|
437 |
public boolean getIsAcepted() { |
438 |
return isAcepted;
|
439 |
} |
440 |
|
441 |
/**
|
442 |
* This method initializes rotation
|
443 |
*
|
444 |
* @return javax.swing.JPanel
|
445 |
*/
|
446 |
private JPRotation getPRotation() {
|
447 |
if (rotation == null) { |
448 |
rotation = new JPRotation();
|
449 |
rotation.setRotation(fframeview.getRotation()); |
450 |
} |
451 |
return rotation;
|
452 |
} |
453 |
|
454 |
public IFFrame getFFrame() {
|
455 |
return newFFrameView;
|
456 |
} |
457 |
|
458 |
/**
|
459 |
* This method initializes bGrid
|
460 |
*
|
461 |
* @return javax.swing.JButton
|
462 |
*/
|
463 |
private JButton getBGrid() { |
464 |
if (bGrid == null) { |
465 |
bGrid = new JButton(); |
466 |
bGrid.setText(Messages.getText("configurar"));
|
467 |
bGrid.addActionListener(new java.awt.event.ActionListener() {
|
468 |
|
469 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
470 |
FFrameGrid fframeGrid = null;
|
471 |
|
472 |
if (fframeview.getGrid() != null) { |
473 |
fframeGrid = (FFrameGrid) fframeview.getGrid(); |
474 |
} else {
|
475 |
fframeGrid = (FFrameGrid) layoutManager.createFrame(FFrameGrid.PERSISTENCE_DEFINITION_NAME); |
476 |
fframeGrid.setFFrameDependence(fframeview); |
477 |
} |
478 |
|
479 |
FFrameGridDialog fframeGridDialog = |
480 |
(FFrameGridDialog)layoutManager.createFFrameDialog(fframeGrid, layoutPanel); |
481 |
fframeGridDialog.setFFrameView(fframeview); |
482 |
|
483 |
|
484 |
if (fframeGridDialog != null) { |
485 |
ApplicationLocator.getManager().getUIManager().addWindow(fframeGridDialog); |
486 |
} |
487 |
IFFrame newFrame = fframeGridDialog.getFFrame(); |
488 |
if (newFrame != null) { |
489 |
fframeview.setGrid(newFrame); |
490 |
} |
491 |
} |
492 |
}); |
493 |
} |
494 |
return bGrid;
|
495 |
} |
496 |
|
497 |
/**
|
498 |
* This method initializes chbShowGrid
|
499 |
*
|
500 |
* @return javax.swing.JCheckBox
|
501 |
*/
|
502 |
private JCheckBox getChbShowGrid() { |
503 |
if (chbShowGrid == null) { |
504 |
chbShowGrid = new JCheckBox(); |
505 |
chbShowGrid.setSelected(fframeview.isShowGrid()); |
506 |
chbShowGrid.setText(Messages.getText("Show_grid"));
|
507 |
} |
508 |
return chbShowGrid;
|
509 |
} |
510 |
|
511 |
public Object getWindowProfile() { |
512 |
return WindowInfo.DIALOG_PROFILE;
|
513 |
} |
514 |
|
515 |
} // @jve:decl-index=0:visual-constraint="10,10"
|