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 / FFrameGridDialog.java @ 250

History | View | Annotate | Download (17.9 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.BorderLayout;
25
import java.awt.FlowLayout;
26
import java.awt.Font;
27
import java.awt.event.ActionListener;
28
import java.awt.geom.Rectangle2D;
29

    
30
import javax.swing.BoxLayout;
31
import javax.swing.ButtonGroup;
32
import javax.swing.JButton;
33
import javax.swing.JLabel;
34
import javax.swing.JPanel;
35
import javax.swing.JRadioButton;
36
import javax.swing.JTextField;
37

    
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.ui.mdiManager.WindowInfo;
40
import org.gvsig.app.gui.panels.ColorChooserPanel;
41
import org.gvsig.app.gui.utils.FontChooser;
42
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid;
43
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
44
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
45
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
46
import org.gvsig.app.project.documents.view.legend.gui.PanelEditSymbol;
47
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.mapcontext.MapContext;
49
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
50
import org.gvsig.gui.beans.AcceptCancelPanel;
51

    
52
public class FFrameGridDialog extends AbstractFFrameDialog implements
53
IFFrameDialog {
54

    
55
    private static final long serialVersionUID = 1L;
56
    private JPanel jPanel1 = null;
57
    private JPanel jPanel4 = null;
58
    private JLabel jLabel = null;
59
    private JTextField txtIntervalX = null;
60
    private JPanel jPanel5 = null;
61
    private JPanel jPanel6 = null;
62
    private JPanel jPanel7 = null;
63
    private JLabel jLabel1 = null;
64
    private JTextField txtIntervalY = null;
65
    private JLabel lblUnitsX = null;
66
    private JLabel lblUnitsY = null;
67
    private JPanel jPanel8 = null;
68
    private JPanel jPanel9 = null;
69
    private JRadioButton rbPoints = null;
70
    private JRadioButton rbLines = null;
71
    private JButton bSymbol = null;
72
    private JPanel jPanel10 = null;
73
    private JPanel jPanel11 = null;
74
    private JButton jButton = null;
75
    private ColorChooserPanel colorChooserPanel = null;
76
    private JPanel jPanel12 = null;
77
    private JLabel jLabel2 = null;
78
    private JTextField txtSize = null;
79

    
80
    private FFrameGrid fframegrid;
81
    private FFrameView fframeview;
82
    private AcceptCancelPanel accept;
83
    private FFrameGrid newFFrameGrid;
84
    private Rectangle2D rect; // @jve:decl-index=0:
85
    private LayoutPanel layout;
86
    // private Color textcolor;
87
    private ISymbol symbol;
88
    private Font m_font;
89
    private ButtonGroup bg = new ButtonGroup();
90
    private JPanel jPanel15 = null;
91

    
92
    public FFrameGridDialog(LayoutPanel layout, FFrameGrid fframe) {
93
        super(layout, fframe);
94
        this.fframegrid = fframe;         
95
        initialize();
96
    }
97

    
98
    /**
99
     * This method initializes this
100
     * 
101
     * @return void
102
     */
103
    private void initialize() {
104
        this.setLayout(new BorderLayout());
105
        this.setSize(350, 265);
106
        this.add(getJPanel1(), java.awt.BorderLayout.CENTER);
107
        this.add(getAcceptCancelPanel(), java.awt.BorderLayout.SOUTH);
108
    }
109

    
110
    /**
111
     * This method initializes jPanel1
112
     * 
113
     * @return javax.swing.JPanel
114
     */
115
    private JPanel getJPanel1() {
116
        if (jPanel1 == null) {
117
            jPanel1 = new JPanel();
118
            jPanel1.setLayout(new BorderLayout());
119
            jPanel1.add(getJPanel5(), java.awt.BorderLayout.NORTH);
120
            jPanel1.add(getJPanel15(), java.awt.BorderLayout.CENTER);
121
        }
122
        return jPanel1;
123
    }
124

    
125
    /**
126
     * This method initializes jPanel4
127
     * 
128
     * @return javax.swing.JPanel
129
     */
130
    private JPanel getJPanel4() {
131
        if (jPanel4 == null) {
132
            lblUnitsX = new JLabel();           
133
            jLabel = new JLabel();
134
            jLabel.setText("x");
135
            jLabel.setName("jLabel");
136
            jPanel4 = new JPanel();
137
            jPanel4.setLayout(new FlowLayout());
138
            jPanel4.add(jLabel, null);
139
            jPanel4.add(getTxtIntervalX(), null);
140
            jPanel4.add(lblUnitsX, null);
141
        }
142
        return jPanel4;
143
    }
144

    
145
    /**
146
     * This method initializes txtIntervalX
147
     * 
148
     * @return javax.swing.JTextField
149
     */
150
    private JTextField getTxtIntervalX() {
151
        if (txtIntervalX == null) {
152
            txtIntervalX = new JTextField();
153
            txtIntervalX.setText(String.valueOf(fframegrid.getIntervalX()));
154
            txtIntervalX.setPreferredSize(new java.awt.Dimension(60, 20));
155
            txtIntervalX.setName("txtIntervalX");
156
        }
157
        return txtIntervalX;
158
    }
159

    
160
    /**
161
     * This method initializes jPanel5
162
     * 
163
     * @return javax.swing.JPanel
164
     */
165
    private JPanel getJPanel5() {
166
        if (jPanel5 == null) {
167
            jPanel5 = new JPanel();
168
            jPanel5.setLayout(new FlowLayout());
169
            jPanel5.add(getJPanel6(), null);
170
            jPanel5.add(getJPanel8(), null);
171
        }
172
        return jPanel5;
173
    }
174

    
175
    /**
176
     * This method initializes jPanel6
177
     * 
178
     * @return javax.swing.JPanel
179
     */
180
    private JPanel getJPanel6() {
181
        if (jPanel6 == null) {
182
            jPanel6 = new JPanel();
183
            jPanel6.setLayout(new BoxLayout(getJPanel6(), BoxLayout.Y_AXIS));
184
            jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(
185
                null, PluginServices.getText(this, "Intervalo"),
186
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
187
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
188
            jPanel6.add(getJPanel4(), null);
189
            jPanel6.add(getJPanel7(), null);
190
        }
191
        return jPanel6;
192
    }
193

    
194
    /**
195
     * This method initializes jPanel7
196
     * 
197
     * @return javax.swing.JPanel
198
     */
199
    private JPanel getJPanel7() {
200
        if (jPanel7 == null) {
201
            lblUnitsY = new JLabel();           
202
            jLabel1 = new JLabel();
203
            jLabel1.setText("y");
204
            jPanel7 = new JPanel();
205
            jPanel7.add(jLabel1, null);
206
            jPanel7.add(getTxtIntervalY(), null);
207
            jPanel7.add(lblUnitsY, null);
208
        }
209
        return jPanel7;
210
    }
211

    
212
    /**
213
     * This method initializes txtIntervalY
214
     * 
215
     * @return javax.swing.JTextField
216
     */
217
    private JTextField getTxtIntervalY() {
218
        if (txtIntervalY == null) {
219
            txtIntervalY = new JTextField();
220
            txtIntervalY.setText(String.valueOf(fframegrid.getIntervalY()));
221
            txtIntervalY.setPreferredSize(new java.awt.Dimension(60, 20));
222
        }
223
        return txtIntervalY;
224
    }
225

    
226
    /**
227
     * This method initializes jPanel8
228
     * 
229
     * @return javax.swing.JPanel
230
     */
231
    private JPanel getJPanel8() {
232
        if (jPanel8 == null) {
233
            jPanel8 = new JPanel();
234
            jPanel8.setLayout(new BoxLayout(getJPanel8(), BoxLayout.Y_AXIS));
235
            jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(
236
                null, PluginServices.getText(this, "Simbologia"),
237
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
238
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
239
            jPanel8.add(getJPanel9(), null);
240
            jPanel8.add(getBSymbol(), null);
241
        }
242
        return jPanel8;
243
    }
244

    
245
    /**
246
     * This method initializes jPanel9
247
     * 
248
     * @return javax.swing.JPanel
249
     */
250
    private JPanel getJPanel9() {
251
        if (jPanel9 == null) {
252
            jPanel9 = new JPanel();
253
            jPanel9.add(getRbPoints(), null);
254
            jPanel9.add(getRbLines(), null);
255
        }
256
        return jPanel9;
257
    }
258

    
259
    /**
260
     * This method initializes rbPoints
261
     * 
262
     * @return javax.swing.JRadioButton
263
     */
264
    private JRadioButton getRbPoints() {
265
        if (rbPoints == null) {
266
            rbPoints = new JRadioButton();
267
            bg.add(rbPoints);
268
            rbPoints.setSelected(!fframegrid.isLine());
269
            rbPoints.setText(PluginServices.getText(this, "points"));
270
        }
271
        return rbPoints;
272
    }
273

    
274
    /**
275
     * This method initializes rbLines
276
     * 
277
     * @return javax.swing.JRadioButton
278
     */
279
    private JRadioButton getRbLines() {
280
        if (rbLines == null) {
281
            rbLines = new JRadioButton();
282
            bg.add(rbLines);
283
            rbLines.setSelected(fframegrid.isLine());
284
            rbLines.setText(PluginServices.getText(this, "lines"));
285
        }
286
        return rbLines;
287
    }
288

    
289
    /**
290
     * This method initializes bSymbol
291
     * 
292
     * @return javax.swing.JButton
293
     */
294
    private JButton getBSymbol() {
295
        if (bSymbol == null) {
296
            bSymbol = new JButton();
297
            bSymbol.setText(PluginServices.getText(this, "symbol"));
298
            bSymbol.addActionListener(new java.awt.event.ActionListener() {
299

    
300
                public void actionPerformed(java.awt.event.ActionEvent e) {
301
                    PanelEditSymbol pes = new PanelEditSymbol();
302
                    if (getRbLines().isSelected()) {
303
                        pes.setSymbol(fframegrid.getSymbolLine());
304
                        pes.setShapeType(Geometry.TYPES.CURVE);
305
                    } else {
306
                        pes.setSymbol(fframegrid.getSymbolPoint());
307
                        pes.setShapeType(Geometry.TYPES.POINT);
308
                    }
309
                    PluginServices.getMDIManager().addWindow(pes);
310
                    symbol = pes.getSymbol();
311
                    // FPanelLegendDefault pld=new FPanelLegendDefault();
312
                    // pld.setFSymbol(fframegrid.getSymbolLine());
313

    
314
                }
315
            });
316
        }
317
        return bSymbol;
318
    }
319

    
320
    /**
321
     * This method initializes jPanel10
322
     * 
323
     * @return javax.swing.JPanel
324
     */
325
    private JPanel getJPanel10() {
326
        if (jPanel10 == null) {
327
            jPanel10 = new JPanel();
328
            jPanel10.setLayout(new BorderLayout());
329
            jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(
330
                null, PluginServices.getText(this, "Font"),
331
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
332
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
333
            jPanel10.add(getJPanel11(), java.awt.BorderLayout.NORTH);
334
            jPanel10.add(getJPanel12(), java.awt.BorderLayout.CENTER);
335
        }
336
        return jPanel10;
337
    }
338

    
339
    /**
340
     * This method initializes jPanel11
341
     * 
342
     * @return javax.swing.JPanel
343
     */
344
    private JPanel getJPanel11() {
345
        if (jPanel11 == null) {
346
            jPanel11 = new JPanel();
347
            jPanel11.add(getJButton(), null);
348
            jPanel11.add(getColorChooserPanel(), null);
349
        }
350
        return jPanel11;
351
    }
352

    
353
    /**
354
     * This method initializes jButton
355
     * 
356
     * @return javax.swing.JButton
357
     */
358
    private JButton getJButton() {
359
        if (jButton == null) {
360
            jButton = new JButton();
361
            jButton.setText(PluginServices.getText(this, "Font"));
362
            m_font = fframegrid.getFont();
363
            jButton.addActionListener(new java.awt.event.ActionListener() {
364

    
365
                public void actionPerformed(java.awt.event.ActionEvent e) {
366
                    Font font =
367
                        FontChooser.showDialog(PluginServices.getText(this,
368
                        "__seleccion_de_fuente"), m_font);
369
                    if (font != null)
370
                        m_font = font; // fchoser=new
371
                    // FontChooser();
372
                    // //$NON-NLS-1$
373
                }
374
            });
375
        }
376
        return jButton;
377
    }
378

    
379
    /**
380
     * This method initializes colorChooserPanel
381
     * 
382
     * @return com.iver.cit.gvsig.gui.panels.ColorChooserPanel
383
     */
384
    private ColorChooserPanel getColorChooserPanel() {
385
        if (colorChooserPanel == null) {
386
            colorChooserPanel = new ColorChooserPanel();
387
            colorChooserPanel.setAlpha(255);
388
            colorChooserPanel.setColor(fframegrid.getFontColor());
389
        }
390
        return colorChooserPanel;
391
    }
392

    
393
    /**
394
     * This method initializes jPanel12
395
     * 
396
     * @return javax.swing.JPanel
397
     */
398
    private JPanel getJPanel12() {
399
        if (jPanel12 == null) {
400
            jLabel2 = new JLabel();
401
            jLabel2.setText(PluginServices.getText(this, "size"));
402
            jPanel12 = new JPanel();
403
            jPanel12.add(jLabel2, null);
404
            jPanel12.add(getTxtSize(), null);
405
        }
406
        return jPanel12;
407
    }
408

    
409
    /**
410
     * This method initializes txtSize
411
     * 
412
     * @return javax.swing.JTextField
413
     */
414
    private JTextField getTxtSize() {
415
        if (txtSize == null) {
416
            txtSize = new JTextField();
417
            txtSize.setText(String.valueOf(fframegrid.getFontSize()));
418
            txtSize.setPreferredSize(new java.awt.Dimension(40, 20));
419
        }
420
        return txtSize;
421
    }
422

    
423
    public IFFrame getFFrame() {
424
        return newFFrameGrid;
425
    }
426

    
427
    private AcceptCancelPanel getAcceptCancelPanel() {
428
        if (accept == null) {
429
            ActionListener okAction, cancelAction;
430
            okAction = new java.awt.event.ActionListener() {
431

    
432
                public void actionPerformed(java.awt.event.ActionEvent e) {
433
                    try {
434
                        newFFrameGrid = (FFrameGrid) fframegrid.clone();
435
                        newFFrameGrid.setFFrameDependence(fframeview);
436
                        // newFFrameGrid.setBoundBox();
437
                        newFFrameGrid
438
                        .setIntervalX(Double.parseDouble(getTxtIntervalX()
439
                            .getText().toString()));
440
                        newFFrameGrid
441
                        .setIntervalY(Double.parseDouble(getTxtIntervalY()
442
                            .getText().toString()));
443

    
444
                        if (getRbLines().isSelected()) {
445
                            if (symbol != null)
446
                                newFFrameGrid.setSymbolLine(symbol);
447
                        } else {
448
                            if (symbol != null)
449
                                newFFrameGrid.setSymbolPoint(symbol);
450
                        }
451

    
452
                        newFFrameGrid.setTextColor(getColorChooserPanel()
453
                            .getColor());
454
                        newFFrameGrid.setSizeFont(Integer.parseInt(getTxtSize()
455
                            .getText()));
456
                        newFFrameGrid.setIsLine(getRbLines().isSelected());
457
                        newFFrameGrid.setFont(m_font);
458
                        newFFrameGrid.setRotation(fframeview.getRotation());
459
                    } catch (CloneNotSupportedException e1) {
460
                        LOG.error("It is not possible clonate the object", e);
461
                    }
462
                    PluginServices.getMDIManager().closeWindow(
463
                        FFrameGridDialog.this);
464
                    notifyDialogClosed();
465
                }
466
            };
467
            cancelAction = new java.awt.event.ActionListener() {
468

    
469
                public void actionPerformed(java.awt.event.ActionEvent e) {
470
                    newFFrameGrid = null;
471
                    PluginServices.getMDIManager().closeWindow(
472
                        FFrameGridDialog.this);
473
                    notifyDialogClosed();
474
                }
475
            };
476
            accept = new AcceptCancelPanel(okAction, cancelAction);
477
            // accept.setPreferredSize(new java.awt.Dimension(300, 300));
478
            // accept.setBounds(new java.awt.Rectangle(243,387,160,28));
479
            accept.setEnabled(true);
480
            // accept.setBounds(new java.awt.Rectangle(45, 250, 300, 32));
481
            accept.setVisible(true);
482
        }
483
        return accept;
484
    }
485

    
486
    public void setRectangle(Rectangle2D r) {
487
        rect = r;
488
    }
489

    
490
    public WindowInfo getWindowInfo() {
491
        WindowInfo m_viewinfo =
492
            new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
493
        m_viewinfo.setTitle(PluginServices.getText(this, "Grid_settings"));
494

    
495
        return m_viewinfo;
496
    }
497

    
498
    public boolean getIsAcepted() {
499
        // TODO Auto-generated method stub
500
        return false;
501
    }
502

    
503
    /**
504
     * This method initializes jPanel15
505
     * 
506
     * @return javax.swing.JPanel
507
     */
508
    private JPanel getJPanel15() {
509
        if (jPanel15 == null) {
510
            jPanel15 = new JPanel();
511
            jPanel15.add(getJPanel10(), null);
512
        }
513
        return jPanel15;
514
    }
515

    
516
    public void setFFrameView(FFrameView fview) {
517
        fframeview = fview;
518
        //Set the label
519
        if (fframeview.getMapContext() != null){
520
            lblUnitsX.setText(MapContext.getDistanceNames()[
521
                   fframeview.getMapContext().getViewPort().getMapUnits()]);
522
            lblUnitsY.setText(MapContext.getDistanceNames()[
523
                   fframeview.getMapContext().getViewPort().getMapUnits()]);
524
        }
525
    }
526

    
527
    public Object getWindowProfile() {
528
        return WindowInfo.DIALOG_PROFILE;
529
    }
530

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