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

History | View | Annotate | Download (26.7 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.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.geom.Rectangle2D;
30

    
31
import javax.swing.BorderFactory;
32
import javax.swing.ButtonGroup;
33
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
35
import javax.swing.JLabel;
36
import javax.swing.JList;
37
import javax.swing.JOptionPane;
38
import javax.swing.JPanel;
39
import javax.swing.JRadioButton;
40
import javax.swing.JTextField;
41

    
42
import org.gvsig.andami.PluginsLocator;
43
import org.gvsig.andami.ui.mdiManager.IWindow;
44
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
45
import org.gvsig.andami.ui.mdiManager.WindowInfo;
46
import org.gvsig.app.ApplicationLocator;
47
import org.gvsig.app.ApplicationManager;
48
import org.gvsig.app.project.ProjectManager;
49
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
50
import org.gvsig.app.project.documents.layout.LayoutManager;
51
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid;
52
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
53
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
54
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap.SCALE_TYPE;
55
import org.gvsig.app.project.documents.layout.fframes.ListViewModel;
56
import org.gvsig.app.project.documents.layout.fframes.gui.EnvelopePanel;
57
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation;
58
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
59
import org.gvsig.app.project.documents.view.DefaultViewDocument;
60
import org.gvsig.app.project.documents.view.ViewDocument;
61
import org.gvsig.fmap.geom.primitive.Envelope;
62
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
63
import org.gvsig.i18n.Messages;
64
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
65

    
66
/**
67
 * Dialog to add a view to the Layout document, by means of a FFrameView
68
 * 
69
 * @author Vicente Caballero Navarro
70
 * @author Cesar Martinez Izquierdo
71
 */
72
public class FFrameViewDialog extends AbstractFFrameDialog implements
73
    IFFrameDialog, SingletonWindow {
74

    
75
    private static final long serialVersionUID = -7223804566537544559L;
76
    
77
    private final LayoutManager layoutManager;
78
    private javax.swing.JLabel lViews = null;
79
    private javax.swing.JScrollPane jScrollPane = null;
80
    private javax.swing.JList liViews = null; // @jve:visual-info decl-index=0
81
                                               // visual-constraint="98,-3"
82
    private javax.swing.JCheckBox chbSyncLayers = null;
83
    private javax.swing.JButton bAceptar = null;
84
    private javax.swing.JButton bCancelar = null;
85
    private javax.swing.JLabel lCalidad = null;
86
    private javax.swing.JComboBox cbCalidad = null;
87
    private DefaultViewDocument m_projectView = null;
88
    private Rectangle2D rect = new Rectangle2D.Double();
89
    private FFrameView fframeview = null;
90
    private boolean isAcepted = false;
91
    private JPRotation rotation = null;
92
    private FFrameView newFFrameView = null;
93
    private javax.swing.JButton bGrid = null;
94
    private javax.swing.JCheckBox chbShowGrid = null;
95
        private JPanel pnlFirstRow = null;
96
        private JCheckBox chbSyncExtent = null;
97
        
98
        private WindowInfo windowInfo = null;
99

    
100
        private GridBagLayoutPanel pnlSyncGroup = null;
101
        private GridBagLayoutPanel pnlScaleTypeGroup = null;
102
        private ButtonGroup grpScaleType = null;
103
        private JRadioButton btnNormalScale = null;
104
        private JRadioButton btnFixedScale = null;
105
        private JRadioButton btnFixedExtent = null;
106
        private JTextField fldScale = null;
107
        private EnvelopePanel pnlExtent = null;
108
        private JButton btConfigView = null;
109
        private JPanel pnlScale = null;
110

    
111

    
112
    /**
113
     * This is the default constructor
114
     * 
115
     * @param layoutPanel
116
     *            Referencia al Layout.
117
     * @param fframe
118
     *            Referencia al fframe vista.
119
     */
120
    public FFrameViewDialog(LayoutPanel layoutPanel, IFFrame frame) {
121
        super(layoutPanel, frame);
122
        fframeview = (FFrameView) frame;
123
        try {
124
                        newFFrameView = (FFrameView) fframeview.clone();
125
                } catch (CloneNotSupportedException e) {
126
                        LOG.error("It is not possible to clone the object", e);
127
                }
128
        initComponents();
129
        layoutManager = (LayoutManager) ProjectManager.getInstance()
130
            .getDocumentManager("project.document.layout");
131
    }
132

    
133
    /**
134
     * This method initializes this
135
     */
136
    private void initComponents() {
137
        this.setLayout(new GridBagLayout());
138
        GridBagConstraints c = new GridBagConstraints();
139
        Insets insets = new Insets(5, 5, 5, 5);
140
        int row = 0;
141
        c.gridx = 0;
142
        c.gridy = row++;
143
        c.insets = new Insets(0,0,0,0);
144
        c.anchor = GridBagConstraints.LINE_START;
145
        c.gridwidth = GridBagConstraints.REMAINDER;
146
        add(getFirstRowPnl(), c);
147
        c.insets = insets;
148
        c.gridx = 0;
149
        c.gridy = row++;
150
        c.gridwidth = GridBagConstraints.REMAINDER;
151
        c.fill = GridBagConstraints.HORIZONTAL;
152
        
153
        GridBagLayoutPanel pnl = getPnlSyncGroup();
154
        pnl.addComponent(getChbSyncLayers(), insets);
155
        pnl.addComponent(getChbSyncExtent(), insets);
156
        add(pnl, c);
157
        
158
        getGrpScaleType().add(getBtnNormalScale());
159
        getGrpScaleType().add(getBtnFixedScale());
160
        getGrpScaleType().add(getBtnFixedExtent());
161
        
162
        pnl = getPnlScaleTypeGroup();
163
        pnl.addComponent(getBtnNormalScale(), insets);
164
        pnl.addComponent(getPnlScale(), insets); // pnlScale() contains btnFixedScale
165
        pnl.addComponent(getBtnFixedExtent(), new Insets(5, 5, 0, 5));
166
        pnl.addComponent(getPnlExtent(), GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5));
167
        if (fframeview.getScaleType()==SCALE_TYPE.FIXED_SCALE) {
168
                getBtnFixedScale().setSelected(true);
169
                scaleTypeSet(SCALE_TYPE.FIXED_SCALE);
170
        }
171
        else if (fframeview.getScaleType()==SCALE_TYPE.FIXED_EXTENT) {
172
                getBtnFixedExtent().setSelected(true);
173
                scaleTypeSet(SCALE_TYPE.FIXED_EXTENT);
174
        }
175
        else {
176
                getBtnNormalScale().setSelected(true);
177
                scaleTypeSet(SCALE_TYPE.NORMAL);
178
        }
179
        
180
        c.gridy = row++;
181
        add(pnl, c);
182
        
183
        c.fill = GridBagConstraints.NONE;
184
        c.gridx = 0;
185
        c.gridy = row++;
186
        c.gridwidth = 1;
187
        add(getLCalidad(), c);
188
        c.gridx = 1;
189
        c.gridwidth = GridBagConstraints.REMAINDER;
190
        add(getCbCalidad(), c);
191
        c.gridx = 0;
192
        c.gridy = row++;
193
        c.gridwidth = 1;
194
        add(getChbShowGrid(), c);
195
        c.gridx = 1;
196
        c.gridwidth = GridBagConstraints.REMAINDER;
197
        add(getBGrid(), c);
198
        JPanel acceptCancelPnl = new JPanel(new GridBagLayout());
199
        c.anchor = GridBagConstraints.LINE_START;
200
        c.gridx = 0;
201
        c.gridy = 0;
202
        c.gridwidth = 1;
203
        acceptCancelPnl.add(getbAceptar(), c);
204
        c.gridx = 1;
205
        acceptCancelPnl.add(getBCancelar(), c);
206
        c.gridx = 0;
207
        c.gridy = row++;
208
        c.anchor = GridBagConstraints.LINE_END;
209
        c.gridwidth = GridBagConstraints.REMAINDER;
210
        add(acceptCancelPnl, c);
211
    }
212

    
213
    public void setRectangle(Rectangle2D r) {
214
        rect.setRect(r);
215
    }
216
    
217
    private JPanel getFirstRowPnl() {
218
            if (pnlFirstRow==null) {
219
                    pnlFirstRow  = new JPanel(new GridBagLayout());
220
                    GridBagConstraints c = new GridBagConstraints();
221
            Insets insets = new Insets(5, 5, 5, 5);
222
            Insets insetsTop = new Insets(12, 5, 5, 5);
223
            c.gridx = 0;
224
            c.gridy = 0;
225
            c.insets = insetsTop;
226
            c.anchor = GridBagConstraints.PAGE_START;
227
            pnlFirstRow.add(getLViews(), c);
228
            c.gridx = 1;
229
            pnlFirstRow.add(getScrolledViewList(), c);
230
            c.insets = insets;
231
            c.gridx = 2;
232
            c.gridheight = 2;
233
            pnlFirstRow.add(getPRotation(), c);
234
            c.anchor = GridBagConstraints.LINE_END;
235
            c.gridy = 1;
236
            c.gridx = 1;
237
            c.gridheight = 1;
238
            pnlFirstRow.add(getBtnConfigView(), c);
239
            }
240
            return pnlFirstRow; 
241
    }
242
    
243
    protected ViewDocument getSelectedView() {
244
            Object selected = getViewList().getSelectedValue();
245
            if (selected instanceof ViewDocument) {
246
                    return (ViewDocument) selected;
247
            }
248
            return null;
249
    }
250
    
251
    private JButton getBtnConfigView() {
252
                UsabilitySwingManager manager = org.gvsig.tools.swing.api.ToolsSwingLocator.getUsabilitySwingManager();
253
                btConfigView = manager.createJButton(Messages.getText("Configure_view"));
254
                btConfigView.addActionListener(new ActionListener() {
255
                        public void actionPerformed(ActionEvent e) {
256
                                ViewDocument view = getSelectedView();
257
                                if (view!=null) {
258
                                        IWindow propWin = view.getPropertiesWindow();
259
                                        ApplicationManager manager = ApplicationLocator.getManager();
260
                                        manager.getUIManager().addWindow(propWin);
261
                                }
262
                        }
263
                });
264
            return btConfigView;
265
    }
266

    
267
    /**
268
     * This method initializes lVistas
269
     * 
270
     * @return javax.swing.JLabel
271
     */
272
    private javax.swing.JLabel getLViews() {
273
        if (lViews == null) {
274
            lViews = new javax.swing.JLabel();
275
            lViews.setText(Messages.getText("Vista"));
276
        }
277

    
278
        return lViews;
279
    }
280

    
281
    /**
282
     * This method initializes jScrollPane
283
     * 
284
     * @return javax.swing.JScrollPane
285
     */
286
    private javax.swing.JScrollPane getScrolledViewList() {
287
        if (jScrollPane == null) {
288
            jScrollPane = new javax.swing.JScrollPane();
289
            jScrollPane.setViewportView(getViewList());
290
            jScrollPane.setPreferredSize(new java.awt.Dimension(300, 100));
291
        }
292
        return jScrollPane;
293
    }
294

    
295
    /**
296
     * This method initializes liVistas
297
     * 
298
     * @return javax.swing.JList
299
     */
300
    private javax.swing.JList getViewList() {
301
        if (liViews == null) {
302
            ListViewModel listmodel = new ListViewModel();
303
            
304
            if (listmodel.addViews()) {
305
               JOptionPane.showMessageDialog(
306
                   ApplicationLocator.getManager().getRootComponent(),
307
                   Messages.getText("_Some_views_excluded_from_list_because_have_editing_layers"),
308
                   Messages.getText("propiedades_marco_vista"),
309
                   JOptionPane.WARNING_MESSAGE); 
310
            }
311
            
312
            liViews = new javax.swing.JList();
313
            liViews.setModel(listmodel);
314
            for (int i = 0; i < liViews.getModel().getSize(); i++) {
315
                if (fframeview.getMapContext() != null) {
316

    
317
                    DefaultViewDocument pvaux =
318
                        (DefaultViewDocument) liViews.getModel().getElementAt(
319
                            i);
320

    
321
                    if (pvaux.getMapContext()
322
                        .equals(fframeview.getMapContext())) {
323
                        liViews.setSelectedIndex(i);
324
                        m_projectView =
325
                            (DefaultViewDocument) liViews.getModel()
326
                                .getElementAt(i);
327
                    }
328
                }
329
            }
330

    
331
            liViews
332
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
333

    
334
                    private int selectIndex = -1;
335
                    public void valueChanged(
336
                        javax.swing.event.ListSelectionEvent e) {
337
                        int selectInt =
338
                            ((JList) e.getSource()).getSelectedIndex();
339
                        if (selectInt != selectIndex) {
340
                            selectIndex = selectInt;
341
                            if (selectIndex == -1) {
342
                                return;
343
                            }
344
                            m_projectView =
345
                                (DefaultViewDocument) liViews.getModel()
346
                                    .getElementAt(selectInt);
347
                            if (m_projectView.getMapContext()!=null) {
348
                                    newFFrameView.setViewMapContext(m_projectView.getMapContext());
349
                            }
350
                        }
351
                    }
352
                });
353
        }
354

    
355
        return liViews;
356
    }
357

    
358
    /**
359
     * This method initializes chbEnlaceVivo
360
     * 
361
     * @return javax.swing.JCheckBox
362
     */
363
    private javax.swing.JCheckBox getChbSyncLayers() {
364
        if (chbSyncLayers == null) {
365
            chbSyncLayers = new javax.swing.JCheckBox();
366
            chbSyncLayers.setText(Messages.getText("Synchronize_layers"));
367
            chbSyncLayers.setSelected(fframeview.getLayerSynced());
368
            chbSyncLayers.addActionListener(new ActionListener() {
369

    
370
                                public void actionPerformed(ActionEvent e) {
371
                                        if (chbSyncLayers.isSelected()) {
372
                                                JOptionPane.showMessageDialog(FFrameViewDialog.this,
373
                                                Messages.getText("Warning_Enabling_layer_synchronization_will_discard_any_change_not_present_in_associated_view"),
374
                                                Messages.getText("Warning_Layer_sync"),
375
                                            JOptionPane.WARNING_MESSAGE);
376
                                        }
377
                                }
378
                    
379
            });
380
        }
381

    
382
        return chbSyncLayers;
383
    }
384
    
385
    private javax.swing.JCheckBox getChbSyncExtent() {
386
            if (chbSyncExtent==null) {
387
                    chbSyncExtent  = new  javax.swing.JCheckBox();
388
                    chbSyncExtent.setText(Messages.getText("Synchronize_extents"));
389
                    chbSyncExtent.setSelected(fframeview.getExtentSynced());
390
            }
391
            return chbSyncExtent;
392
    }
393
    
394
    protected void disableChbSyncExtent() {
395
            getChbSyncExtent().setEnabled(false);
396
            getChbSyncExtent().setToolTipText(Messages.getText("Extent_cant_be_synchronized_when_using_fixed_scale_or_fixed_extent"));
397
    }
398
    
399
    protected void enableChbSyncExtent() {
400
            getChbSyncExtent().setEnabled(true);
401
            getChbSyncExtent().setToolTipText(null);
402
    }
403

    
404
    /**
405
     * This method initializes jButton
406
     * 
407
     * @return javax.swing.JButton
408
     */
409
    private javax.swing.JButton getbAceptar() {
410
        if (bAceptar == null) {
411
            bAceptar = new javax.swing.JButton();
412
            bAceptar.setText(Messages.getText("Aceptar"));
413
            bAceptar.addActionListener(new java.awt.event.ActionListener() {
414

    
415
                    public void actionPerformed(java.awt.event.ActionEvent e) {
416
                            newFFrameView.setBoundBox(FLayoutUtilities.toSheetRect(
417
                                            rect, layoutPanel.getLayoutControl().getAT()));
418
                            newFFrameView.setRotation(getPRotation().getRotation());
419
                            newFFrameView.setHasToc(true);
420
                            newFFrameView.setLayerSynced(getChbSyncLayers()
421
                                            .isSelected());
422
                            newFFrameView.setExtentSynced(getChbSyncExtent().isSelected());
423
                            try {
424
                                    if (getBtnFixedScale().isSelected()) {
425
                                            Double d = Double.parseDouble(getFldScale().getText());
426
                                            newFFrameView.setScaleType(SCALE_TYPE.FIXED_SCALE, d);
427
                                    }
428
                                    else if (getBtnFixedExtent().isSelected()) {
429
                                            Envelope envelope = getPnlExtent().getEnvelope();
430
                                            if (envelope!=null) {
431
                                                    newFFrameView.setScaleType(SCALE_TYPE.FIXED_EXTENT, envelope);
432
                                            }
433
                                            else {
434
                                                    newFFrameView.setScaleType(SCALE_TYPE.NORMAL);
435
                                            }
436
                                    }
437
                                    else {
438
                                            newFFrameView.setScaleType(SCALE_TYPE.NORMAL);
439
                                    }
440
                            }
441
                            catch (Exception ex) {
442
                                    newFFrameView.setScaleType(SCALE_TYPE.NORMAL);
443
                            }
444
                            if (m_projectView != null) {
445
                                    newFFrameView.setView(m_projectView);
446
                                    newFFrameView.setQuality(getCbCalidad()
447
                                                    .getSelectedIndex());
448
                                    if (newFFrameView.getGrid()!=null) {
449
                                            ((FFrameGrid)newFFrameView.getGrid()).setFFrameDependence(newFFrameView);
450
                                    }
451
                                    newFFrameView.showGrid(getChbShowGrid()
452
                                                    .isSelected());
453
                                    newFFrameView.setBoundBox(FLayoutUtilities
454
                                                    .toSheetRect(rect, layoutPanel
455
                                                                    .getLayoutControl().getAT()));
456
                            }
457
                            isAcepted = true;
458
                            ApplicationLocator.getManager().getUIManager().closeWindow(
459
                                            FFrameViewDialog.this);
460
                            notifyDialogClosed();
461
                            PluginsLocator.getMainFrame().refreshControls();
462
                            layoutPanel.getLayoutControl().setDefaultTool();
463
                    }
464
            });
465
        }
466

    
467
        return bAceptar;
468
    }
469

    
470
    /**
471
     * This method initializes bCancelar
472
     * 
473
     * @return javax.swing.JButton
474
     */
475
    private javax.swing.JButton getBCancelar() {
476
        if (bCancelar == null) {
477
            bCancelar = new javax.swing.JButton();
478
            bCancelar.setText(Messages.getText("Cancelar"));
479
            bCancelar.addActionListener(new java.awt.event.ActionListener() {
480

    
481
                public void actionPerformed(java.awt.event.ActionEvent e) {
482
                    newFFrameView = null;
483
                    ApplicationLocator.getManager().getUIManager().closeWindow(
484
                        FFrameViewDialog.this);
485
                    notifyDialogClosed();
486
                }
487
            });
488
        }
489

    
490
        return bCancelar;
491
    }
492

    
493
    /**
494
     * This method initializes lCalidad
495
     * 
496
     * @return javax.swing.JLabel
497
     */
498
    private javax.swing.JLabel getLCalidad() {
499
        if (lCalidad == null) {
500
            lCalidad = new javax.swing.JLabel();
501
            lCalidad.setText(Messages.getText("calidad"));
502
        }
503

    
504
        return lCalidad;
505
    }
506

    
507
    /**
508
     * This method initializes cbCalidad
509
     * 
510
     * @return javax.swing.JComboBox
511
     */
512
    private javax.swing.JComboBox getCbCalidad() {
513
        if (cbCalidad == null) {
514
            // String[] s={"Presentaci?n","Borrador"};
515
            cbCalidad = new javax.swing.JComboBox();
516
            cbCalidad.addItem(Messages.getText("presentacion"));
517
            cbCalidad.addItem(Messages.getText("borrador"));
518
            cbCalidad.setSelectedIndex(fframeview.getQuality());
519
        }
520

    
521
        return cbCalidad;
522
    }
523

    
524
    /*
525
     * (non-Javadoc)
526
     * 
527
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
528
     */
529
    public WindowInfo getWindowInfo() {
530
            if (windowInfo==null) {
531
                    windowInfo = new WindowInfo(WindowInfo.RESIZABLE);
532
                    windowInfo.setHeight(600);
533
                    windowInfo.setWidth(550);
534
                    windowInfo.setTitle(Messages.getText(
535
                                    "propiedades_marco_vista"));
536
            }
537
            return windowInfo;
538
    }
539

    
540
    /**
541
     * @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
542
     */
543
    public boolean getIsAcepted() {
544
        return isAcepted;
545
    }
546

    
547
    /**
548
     * This method initializes rotation
549
     * 
550
     * @return javax.swing.JPanel
551
     */
552
    private JPRotation getPRotation() {
553
        if (rotation == null) {
554
            rotation = new JPRotation();
555
            rotation.setRotation(fframeview.getRotation());
556
        }
557
        return rotation;
558
    }
559

    
560
    public IFFrame getFFrame() {
561
        return newFFrameView;
562
    }
563

    
564
    /**
565
     * This method initializes bGrid
566
     * 
567
     * @return javax.swing.JButton
568
     */
569
    private JButton getBGrid() {
570
        if (bGrid == null) {
571
            bGrid = new JButton();
572
            bGrid.setText(Messages.getText("configurar"));
573
            bGrid.addActionListener(new java.awt.event.ActionListener() {
574

    
575
                public void actionPerformed(java.awt.event.ActionEvent e) {                
576
                    FFrameGrid fframeGrid = null;
577

    
578
                    if (newFFrameView.getGrid() != null) {
579
                        fframeGrid = (FFrameGrid) newFFrameView.getGrid();
580
                    } else {                       
581
                        fframeGrid = (FFrameGrid) layoutManager.createFrame(FFrameGrid.PERSISTENCE_DEFINITION_NAME);                
582
                        fframeGrid.setFFrameDependence(fframeview);
583
                    }
584

    
585
                    FFrameGridDialog fframeGridDialog = 
586
                        (FFrameGridDialog)layoutManager.createFFrameDialog(fframeGrid, layoutPanel);
587
                    fframeGridDialog.setFFrameView(newFFrameView);
588
   
589
                    if (fframeGridDialog != null) {
590
                        ApplicationLocator.getManager().getUIManager().addWindow(fframeGridDialog);
591
                    }
592
                    IFFrame newFrame = fframeGridDialog.getFFrame();
593
                    if (newFrame != null) {
594
                        newFFrameView.setGrid(newFrame);
595
                    }
596
                }
597
            });
598
        }
599
        return bGrid;
600
    }
601
    
602
    /**
603
     * This method initializes chbShowGrid
604
     * 
605
     * @return javax.swing.JCheckBox
606
     */
607
    private JCheckBox getChbShowGrid() {
608
        if (chbShowGrid == null) {
609
            chbShowGrid = new JCheckBox();
610
            chbShowGrid.setSelected(fframeview.isShowGrid());
611
            chbShowGrid.setText(Messages.getText("Show_grid"));
612
            chbShowGrid.addActionListener(new ActionListener() {
613

    
614
                                public void actionPerformed(ActionEvent e) {
615
                                        if (e.getSource() instanceof JCheckBox) {
616
                                                JCheckBox cb = (JCheckBox) e.getSource();
617
                                                if (cb.isSelected()) {
618
                                                        if (newFFrameView.getGrid()==null) {
619
                                                                // ensure we have a non-null grid if the checkbox is selected
620
                                                                FFrameGrid fframeGrid = (FFrameGrid) layoutManager.createFrame(FFrameGrid.PERSISTENCE_DEFINITION_NAME);                
621
                                        fframeGrid.setFFrameDependence(newFFrameView);
622
                                        newFFrameView.setGrid(fframeGrid);
623
                                                        }
624
                                                }
625
                                        }
626
                                }
627
            });
628
        }
629
        return chbShowGrid;
630
    }
631
    
632
    private GridBagLayoutPanel getPnlSyncGroup() {
633
            if (pnlSyncGroup ==null) {
634
                    pnlSyncGroup = new GridBagLayoutPanel();
635
                    pnlSyncGroup.setBorder(BorderFactory.createTitledBorder(Messages.getText("Synchronization_of_the_view_and_the_frame_view")));
636
            }
637
            return pnlSyncGroup;
638
    }
639
    
640
    private GridBagLayoutPanel getPnlScaleTypeGroup() {
641
            if (pnlScaleTypeGroup ==null) {
642
                    pnlScaleTypeGroup  = new GridBagLayoutPanel();
643
                    pnlScaleTypeGroup.setBorder(BorderFactory.createTitledBorder(Messages.getText("Fixed_scale_and_extent")));
644
            }
645
            return pnlScaleTypeGroup;
646
    }
647
    
648
    private ButtonGroup getGrpScaleType() {
649
            if (grpScaleType==null) {
650
                    grpScaleType  = new ButtonGroup();
651
            }
652
            return grpScaleType;
653
    }
654
    
655
    private JRadioButton getBtnNormalScale() {
656
            if (btnNormalScale==null) {
657
                    btnNormalScale  = new JRadioButton(Messages.getText("Non_fixed"));
658
                    btnNormalScale.addActionListener(new ActionListener() {
659
                                public void actionPerformed(ActionEvent e) {
660
                                        FFrameViewDialog.this.scaleTypeSet(SCALE_TYPE.NORMAL);
661
                                        FFrameViewDialog.this.enableChbSyncExtent();
662
                                }
663
                        });
664
            }
665
            return btnNormalScale;
666
    }
667
    
668
    private JRadioButton getBtnFixedScale() {
669
            if (btnFixedScale==null) {
670
                    btnFixedScale  = new JRadioButton(Messages.getText("Fixed_scale"));
671
                    btnFixedScale.addActionListener(new ActionListener() {
672
                                public void actionPerformed(ActionEvent e) {
673
                                        FFrameViewDialog.this.scaleTypeSet(SCALE_TYPE.FIXED_SCALE);
674
                                        FFrameViewDialog.this.disableChbSyncExtent();
675
                                }
676
                        });
677
            }
678
            return btnFixedScale;
679
    }
680
    
681
    private JPanel getPnlScale() {
682
            if (pnlScale==null) {
683
                    pnlScale  = new JPanel(new GridBagLayout());
684
                    GridBagConstraints c = new GridBagConstraints();
685
                    c.insets = new Insets(0, 0, 0, 0);
686
                    c.gridx = 0;
687
                    pnlScale.add(getBtnFixedScale());
688
                    c.anchor = GridBagConstraints.LINE_START;
689
                    c.gridx = 1;
690
                    c.insets = new Insets(0, 25, 0, 5);
691
                    c.anchor = GridBagConstraints.LINE_END;
692
                    pnlScale.add(getLblScale(), c);
693
                    c.gridx = 2;
694
                    c.insets = new Insets(0, 5, 0, 5);;
695
                    c.anchor = GridBagConstraints.LINE_START;
696
                    pnlScale.add(getFldScale(), c);
697
            }
698
            return pnlScale;
699
    }
700
    
701
    private JTextField getFldScale() {
702
                if (fldScale==null) {
703
                    fldScale  = new JTextField(8);
704
                    if (fframeview!=null &&
705
                                    fframeview.getMapContext()!=null &&
706
                                    fframeview.getMapContext().getViewPort().getEnvelope()!=null) {
707
                            fldScale.setText(Long.toString(fframeview.getMapContext().getScaleView()));
708
                    }
709
            }
710
            return fldScale;
711
    }
712
    
713
    private JLabel getLblScale() {
714
            return new JLabel(Messages.getText("1__"));
715
    }
716
    
717
    private JRadioButton getBtnFixedExtent() {
718
            if (btnFixedExtent==null) {
719
                    btnFixedExtent   = new JRadioButton(Messages.getText("Fixed_extent"));
720
                    btnFixedExtent.addActionListener(new ActionListener() {
721
                                public void actionPerformed(ActionEvent e) {
722
                                        FFrameViewDialog.this.scaleTypeSet(SCALE_TYPE.FIXED_EXTENT);
723
                                        FFrameViewDialog.this.disableChbSyncExtent();
724
                                }
725
                        });
726
            }
727
            return btnFixedExtent;
728
    }
729
    
730
    private EnvelopePanel getPnlExtent() {
731
            if (pnlExtent==null) {
732
                    pnlExtent  = new EnvelopePanel();
733
                    if (fframeview!=null &&
734
                                    fframeview.getMapContext()!=null &&
735
                                    fframeview.getMapContext().getViewPort().getEnvelope()!=null) {
736
                            pnlExtent.setEnvelope(fframeview.getMapContext().getViewPort().getEnvelope());
737
                    }
738
            }
739
            return pnlExtent;
740
    }
741

    
742
    public Object getWindowProfile() {
743
        return WindowInfo.DIALOG_PROFILE;
744
    }
745

    
746
        public Object getWindowModel() {
747
                return fframeview;
748
        }
749
        
750
        protected void scaleTypeSet(SCALE_TYPE type) {
751
                if (type==SCALE_TYPE.NORMAL) {
752
                        getFldScale().setEditable(false);
753
                        getFldScale().setEnabled(false);
754
                        getPnlExtent().setEditable(false);
755
                        getPnlExtent().setEnabled(false);
756
                }
757
                else if (type==SCALE_TYPE.FIXED_SCALE) {
758
                        getFldScale().setEditable(true);
759
                        getFldScale().setEnabled(true);
760
                        getPnlExtent().setEditable(false);
761
                        getPnlExtent().setEnabled(false);
762
                }
763
                else if (type==SCALE_TYPE.FIXED_EXTENT) {
764
                        getFldScale().setEditable(false);
765
                        getFldScale().setEnabled(false);
766
                        getPnlExtent().setEditable(true);
767
                        getPnlExtent().setEnabled(true);
768
                }
769
                
770
        }
771
        
772
        protected SCALE_TYPE getSelectedScaleType() {
773
                if (getBtnFixedScale().isSelected()) {
774
                        return SCALE_TYPE.FIXED_SCALE;
775
                }
776
                else if (getBtnFixedExtent().isSelected()) {
777
                        return SCALE_TYPE.FIXED_EXTENT;
778
                }
779
                return SCALE_TYPE.NORMAL;                
780
        }
781

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