Statistics
| Revision:

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 @ 225

History | View | Annotate | Download (18.2 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
    /**
159
     * Inserta el rect?ngulo que ocupar? el fframe vista.
160
     * 
161
     * @param r
162
     *            Rect?ngulo.
163
     */
164
    public void setRectangle(Rectangle2D r) {
165
        rect.setRect(r);
166
    }
167
    
168
    private JPanel getFirstRowPnl() {
169
            if (pnlFirstRow==null) {
170
                    pnlFirstRow  = new JPanel(new GridBagLayout());
171
                    GridBagConstraints c = new GridBagConstraints();
172
            Insets insets = new Insets(5, 5, 5, 5);
173
            c.gridx = 0;
174
            c.gridy = 1;
175
            c.insets = insets;
176
            c.anchor = GridBagConstraints.PAGE_START;
177
            pnlFirstRow.add(getLViews(), c);
178
            c.gridx = 1;
179
            pnlFirstRow.add(getScrolledViewList(), c);
180
            c.gridx = 2;
181
            pnlFirstRow.add(getPRotation(), c);
182
            }
183
            return pnlFirstRow; 
184
    }
185

    
186
    /**
187
     * This method initializes lVistas
188
     * 
189
     * @return javax.swing.JLabel
190
     */
191
    private javax.swing.JLabel getLViews() {
192
        if (lViews == null) {
193
            lViews = new javax.swing.JLabel();
194
            lViews.setText(Messages.getText("Vista"));
195
        }
196

    
197
        return lViews;
198
    }
199

    
200
    /**
201
     * This method initializes jScrollPane
202
     * 
203
     * @return javax.swing.JScrollPane
204
     */
205
    private javax.swing.JScrollPane getScrolledViewList() {
206
        if (jScrollPane == null) {
207
            jScrollPane = new javax.swing.JScrollPane();
208
            jScrollPane.setViewportView(getViewList());
209
            jScrollPane.setPreferredSize(new java.awt.Dimension(300, 100));
210
        }
211
        return jScrollPane;
212
    }
213

    
214
    /**
215
     * This method initializes liVistas
216
     * 
217
     * @return javax.swing.JList
218
     */
219
    private javax.swing.JList getViewList() {
220
        if (liViews == null) {
221
            ListViewModel listmodel = new ListViewModel();
222
            
223
            if (listmodel.addViews()) {
224
               JOptionPane.showMessageDialog(
225
                   ApplicationLocator.getManager().getRootComponent(),
226
                   Messages.getText("_Some_views_excluded_from_list_because_have_editing_layers"),
227
                   Messages.getText("propiedades_marco_vista"),
228
                   JOptionPane.WARNING_MESSAGE); 
229
            }
230
            
231
            liViews = new javax.swing.JList();
232
            liViews.setModel(listmodel);
233
            for (int i = 0; i < liViews.getModel().getSize(); i++) {
234
                if (fframeview.getMapContext() != null) {
235

    
236
                    DefaultViewDocument pvaux =
237
                        (DefaultViewDocument) liViews.getModel().getElementAt(
238
                            i);
239

    
240
                    if (pvaux.getMapContext()
241
                        .equals(fframeview.getMapContext())) {
242
                        liViews.setSelectedIndex(i);
243
                        m_projectView =
244
                            (DefaultViewDocument) liViews.getModel()
245
                                .getElementAt(i);
246
                    }
247
                }
248
            }
249

    
250
            liViews
251
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
252

    
253
                    private int selectIndex = -1;
254
                    public void valueChanged(
255
                        javax.swing.event.ListSelectionEvent e) {
256
                        int selectInt =
257
                            ((JList) e.getSource()).getSelectedIndex();
258
                        if (selectInt != selectIndex) {
259
                            selectIndex = selectInt;
260
                            if (selectIndex == -1) {
261
                                return;
262
                            }
263
                            m_projectView =
264
                                (DefaultViewDocument) liViews.getModel()
265
                                    .getElementAt(selectInt);
266
                            ViewPort vp;
267
                            try {
268
                                vp =
269
                                    (ViewPort) m_projectView.getMapContext()
270
                                        .getViewPort().clone();
271
                                vp.setImageSize(new Dimension((int) rect
272
                                    .getWidth(), (int) rect.getHeight()));
273
                            } catch (CloneNotSupportedException e1) {
274
                                NotificationManager.addError("Excepci?n :", e1);
275
                            }
276
                        }
277
                    }
278
                });
279
        }
280

    
281
        return liViews;
282
    }
283

    
284
    /**
285
     * This method initializes chbEnlaceVivo
286
     * 
287
     * @return javax.swing.JCheckBox
288
     */
289
    private javax.swing.JCheckBox getChbSyncLayers() {
290
        if (chbSyncLayers == null) {
291
            chbSyncLayers = new javax.swing.JCheckBox();
292
            chbSyncLayers.setText(Messages.getText("Synchronize_layers"));
293
            chbSyncLayers.setSelected(fframeview.getLayerSynced());
294
            chbSyncLayers.addActionListener(new ActionListener() {
295

    
296
                                public void actionPerformed(ActionEvent e) {
297
                                        if (chbSyncLayers.isSelected()) {
298
                                                JOptionPane.showMessageDialog(FFrameViewDialog.this,
299
                                                Messages.getText("Warning_Enabling_layer_synchronization_will_discard_any_change_not_present_in_associated_view"),
300
                                                Messages.getText("Warning_Layer_sync"),
301
                                            JOptionPane.WARNING_MESSAGE);
302
                                        }
303
                                }
304
                    
305
            });
306
        }
307

    
308
        return chbSyncLayers;
309
    }
310
    
311
    private javax.swing.JCheckBox getChbSyncExtent() {
312
            if (chbSyncExtent==null) {
313
                    chbSyncExtent  = new  javax.swing.JCheckBox();
314
                    chbSyncExtent.setText(Messages.getText("Synchronize_extents"));
315
                    chbSyncExtent.setSelected(fframeview.getExtentSynced());
316
            }
317
            return chbSyncExtent;
318
    }
319

    
320
    /**
321
     * This method initializes jButton
322
     * 
323
     * @return javax.swing.JButton
324
     */
325
    private javax.swing.JButton getbAceptar() {
326
        if (bAceptar == null) {
327
            bAceptar = new javax.swing.JButton();
328
            bAceptar.setText(Messages.getText("Aceptar"));
329
            bAceptar.addActionListener(new java.awt.event.ActionListener() {
330

    
331
                public void actionPerformed(java.awt.event.ActionEvent e) {
332
                    try {
333
                        newFFrameView = (FFrameView) fframeview.clone();
334
                        newFFrameView.setBoundBox(FLayoutUtilities.toSheetRect(
335
                            rect, layoutPanel.getLayoutControl().getAT()));
336
                        newFFrameView.setRotation(getPRotation().getRotation());
337
                        newFFrameView.setHasToc(true);
338
                        newFFrameView.setLayerSynced(getChbSyncLayers()
339
                                .isSelected());
340
                        newFFrameView.setExtentSynced(getChbSyncExtent().isSelected());
341

    
342
                        if (m_projectView != null) {
343
                            newFFrameView.setView(m_projectView);
344
                            newFFrameView.setQuality(getCbCalidad()
345
                                .getSelectedIndex());
346
                            if (fframeview.getGrid() != null) {                             
347
                                ((FFrameGrid) fframeview.getGrid())
348
                                    .setFFrameDependence(newFFrameView);
349
                                newFFrameView.setGrid(fframeview.getGrid());
350
                            }
351
                            newFFrameView.showGrid(getChbShowGrid()
352
                                .isSelected());
353
                            newFFrameView.setBoundBox(FLayoutUtilities
354
                                .toSheetRect(rect, layoutPanel
355
                                    .getLayoutControl().getAT()));
356
                        }
357
                    } catch (CloneNotSupportedException e1) {
358
                        LOG.error("It is not possible to clone the object", e);
359
                    }
360
                    isAcepted = true;
361
                    ApplicationLocator.getManager().getUIManager().closeWindow(
362
                        FFrameViewDialog.this);
363
                    layoutPanel.getLayoutControl().setDefaultTool();
364
                }
365
            });
366
        }
367

    
368
        return bAceptar;
369
    }
370

    
371
    /**
372
     * This method initializes bCancelar
373
     * 
374
     * @return javax.swing.JButton
375
     */
376
    private javax.swing.JButton getBCancelar() {
377
        if (bCancelar == null) {
378
            bCancelar = new javax.swing.JButton();
379
            bCancelar.setText(Messages.getText("Cancelar"));
380
            bCancelar.addActionListener(new java.awt.event.ActionListener() {
381

    
382
                public void actionPerformed(java.awt.event.ActionEvent e) {
383
                    newFFrameView = null;
384
                    ApplicationLocator.getManager().getUIManager().closeWindow(
385
                        FFrameViewDialog.this);
386
                }
387
            });
388
        }
389

    
390
        return bCancelar;
391
    }
392

    
393
    /**
394
     * This method initializes lCalidad
395
     * 
396
     * @return javax.swing.JLabel
397
     */
398
    private javax.swing.JLabel getLCalidad() {
399
        if (lCalidad == null) {
400
            lCalidad = new javax.swing.JLabel();
401
            lCalidad.setText(Messages.getText("calidad"));
402
        }
403

    
404
        return lCalidad;
405
    }
406

    
407
    /**
408
     * This method initializes cbCalidad
409
     * 
410
     * @return javax.swing.JComboBox
411
     */
412
    private javax.swing.JComboBox getCbCalidad() {
413
        if (cbCalidad == null) {
414
            // String[] s={"Presentaci?n","Borrador"};
415
            cbCalidad = new javax.swing.JComboBox();
416
            cbCalidad.addItem(Messages.getText("presentacion"));
417
            cbCalidad.addItem(Messages.getText("borrador"));
418
            cbCalidad.setSelectedIndex(fframeview.getQuality());
419
        }
420

    
421
        return cbCalidad;
422
    }
423

    
424
    /*
425
     * (non-Javadoc)
426
     * 
427
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
428
     */
429
    public WindowInfo getWindowInfo() {
430
            if (windowInfo==null) {
431
                    windowInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
432
                    windowInfo.setHeight(300);
433
                    windowInfo.setWidth(550);
434
                    windowInfo.setTitle(Messages.getText(
435
                                    "propiedades_marco_vista"));
436
            }
437
            return windowInfo;
438
    }
439

    
440
    /**
441
     * @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
442
     */
443
    public boolean getIsAcepted() {
444
        return isAcepted;
445
    }
446

    
447
    /**
448
     * This method initializes rotation
449
     * 
450
     * @return javax.swing.JPanel
451
     */
452
    private JPRotation getPRotation() {
453
        if (rotation == null) {
454
            rotation = new JPRotation();
455
            rotation.setRotation(fframeview.getRotation());
456
        }
457
        return rotation;
458
    }
459

    
460
    public IFFrame getFFrame() {
461
        return newFFrameView;
462
    }
463

    
464
    /**
465
     * This method initializes bGrid
466
     * 
467
     * @return javax.swing.JButton
468
     */
469
    private JButton getBGrid() {
470
        if (bGrid == null) {
471
            bGrid = new JButton();
472
            bGrid.setText(Messages.getText("configurar"));
473
            bGrid.addActionListener(new java.awt.event.ActionListener() {
474

    
475
                public void actionPerformed(java.awt.event.ActionEvent e) {                
476
                    FFrameGrid fframeGrid = null;
477

    
478
                    if (fframeview.getGrid() != null) {
479
                        fframeGrid = (FFrameGrid) fframeview.getGrid();
480
                    } else {                       
481
                        fframeGrid = (FFrameGrid) layoutManager.createFrame(FFrameGrid.PERSISTENCE_DEFINITION_NAME);                
482
                        fframeGrid.setFFrameDependence(fframeview);             
483
                    }
484

    
485
                    FFrameGridDialog fframeGridDialog = 
486
                        (FFrameGridDialog)layoutManager.createFFrameDialog(fframeGrid, layoutPanel);
487
                    fframeGridDialog.setFFrameView(fframeview);
488
                        
489
   
490
                    if (fframeGridDialog != null) {
491
                        ApplicationLocator.getManager().getUIManager().addWindow(fframeGridDialog);
492
                    }
493
                    IFFrame newFrame = fframeGridDialog.getFFrame();
494
                    if (newFrame != null) {
495
                        fframeview.setGrid(newFrame);
496
                    }
497
                }
498
            });
499
        }
500
        return bGrid;
501
    }
502

    
503
    /**
504
     * This method initializes chbShowGrid
505
     * 
506
     * @return javax.swing.JCheckBox
507
     */
508
    private JCheckBox getChbShowGrid() {
509
        if (chbShowGrid == null) {
510
            chbShowGrid = new JCheckBox();
511
            chbShowGrid.setSelected(fframeview.isShowGrid());
512
            chbShowGrid.setText(Messages.getText("Show_grid"));
513
        }
514
        return chbShowGrid;
515
    }
516

    
517
    public Object getWindowProfile() {
518
        return WindowInfo.DIALOG_PROFILE;
519
    }
520

    
521
} // @jve:decl-index=0:visual-constraint="10,10"