Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFrameGridDialog.java @ 36648

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.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
    /**
93
     * This is the default constructor
94
     */
95
    public FFrameGridDialog(LayoutPanel layout, FFrameGrid frame,
96
        FFrameView view) {
97
        super(layout, frame);
98
        this.fframegrid = frame;
99
        this.fframeview = view;
100
        // textcolor=fframegrid.getFontColor();
101
        initialize();
102
    }
103

    
104
    /**
105
     * This method initializes this
106
     * 
107
     * @return void
108
     */
109
    private void initialize() {
110
        this.setLayout(new BorderLayout());
111
        this.setSize(350, 265);
112
        this.add(getJPanel1(), java.awt.BorderLayout.CENTER);
113
        this.add(getAcceptCancelPanel(), java.awt.BorderLayout.SOUTH);
114
    }
115

    
116
    /**
117
     * This method initializes jPanel1
118
     * 
119
     * @return javax.swing.JPanel
120
     */
121
    private JPanel getJPanel1() {
122
        if (jPanel1 == null) {
123
            jPanel1 = new JPanel();
124
            jPanel1.setLayout(new BorderLayout());
125
            jPanel1.add(getJPanel5(), java.awt.BorderLayout.NORTH);
126
            jPanel1.add(getJPanel15(), java.awt.BorderLayout.CENTER);
127
        }
128
        return jPanel1;
129
    }
130

    
131
    /**
132
     * This method initializes jPanel4
133
     * 
134
     * @return javax.swing.JPanel
135
     */
136
    private JPanel getJPanel4() {
137
        if (jPanel4 == null) {
138
            lblUnitsX = new JLabel();
139
            if (fframeview.getMapContext() != null)
140
                lblUnitsX.setText(MapContext.getDistanceNames()[fframeview
141
                    .getMapContext().getViewPort().getMapUnits()]);
142
            jLabel = new JLabel();
143
            jLabel.setText("x");
144
            jLabel.setName("jLabel");
145
            jPanel4 = new JPanel();
146
            jPanel4.setLayout(new FlowLayout());
147
            jPanel4.add(jLabel, null);
148
            jPanel4.add(getTxtIntervalX(), null);
149
            jPanel4.add(lblUnitsX, null);
150
        }
151
        return jPanel4;
152
    }
153

    
154
    /**
155
     * This method initializes txtIntervalX
156
     * 
157
     * @return javax.swing.JTextField
158
     */
159
    private JTextField getTxtIntervalX() {
160
        if (txtIntervalX == null) {
161
            txtIntervalX = new JTextField();
162
            txtIntervalX.setText(String.valueOf(fframegrid.getIntervalX()));
163
            txtIntervalX.setPreferredSize(new java.awt.Dimension(60, 20));
164
            txtIntervalX.setName("txtIntervalX");
165
        }
166
        return txtIntervalX;
167
    }
168

    
169
    /**
170
     * This method initializes jPanel5
171
     * 
172
     * @return javax.swing.JPanel
173
     */
174
    private JPanel getJPanel5() {
175
        if (jPanel5 == null) {
176
            jPanel5 = new JPanel();
177
            jPanel5.setLayout(new FlowLayout());
178
            jPanel5.add(getJPanel6(), null);
179
            jPanel5.add(getJPanel8(), null);
180
        }
181
        return jPanel5;
182
    }
183

    
184
    /**
185
     * This method initializes jPanel6
186
     * 
187
     * @return javax.swing.JPanel
188
     */
189
    private JPanel getJPanel6() {
190
        if (jPanel6 == null) {
191
            jPanel6 = new JPanel();
192
            jPanel6.setLayout(new BoxLayout(getJPanel6(), BoxLayout.Y_AXIS));
193
            jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(
194
                null, PluginServices.getText(this, "Intervalo"),
195
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
196
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
197
            jPanel6.add(getJPanel4(), null);
198
            jPanel6.add(getJPanel7(), null);
199
        }
200
        return jPanel6;
201
    }
202

    
203
    /**
204
     * This method initializes jPanel7
205
     * 
206
     * @return javax.swing.JPanel
207
     */
208
    private JPanel getJPanel7() {
209
        if (jPanel7 == null) {
210
            lblUnitsY = new JLabel();
211
            if (fframeview.getMapContext() != null)
212
                lblUnitsY.setText(MapContext.getDistanceNames()[fframeview
213
                    .getMapContext().getViewPort().getMapUnits()]);
214
            jLabel1 = new JLabel();
215
            jLabel1.setText("y");
216
            jPanel7 = new JPanel();
217
            jPanel7.add(jLabel1, null);
218
            jPanel7.add(getTxtIntervalY(), null);
219
            jPanel7.add(lblUnitsY, null);
220
        }
221
        return jPanel7;
222
    }
223

    
224
    /**
225
     * This method initializes txtIntervalY
226
     * 
227
     * @return javax.swing.JTextField
228
     */
229
    private JTextField getTxtIntervalY() {
230
        if (txtIntervalY == null) {
231
            txtIntervalY = new JTextField();
232
            txtIntervalY.setText(String.valueOf(fframegrid.getIntervalY()));
233
            txtIntervalY.setPreferredSize(new java.awt.Dimension(60, 20));
234
        }
235
        return txtIntervalY;
236
    }
237

    
238
    /**
239
     * This method initializes jPanel8
240
     * 
241
     * @return javax.swing.JPanel
242
     */
243
    private JPanel getJPanel8() {
244
        if (jPanel8 == null) {
245
            jPanel8 = new JPanel();
246
            jPanel8.setLayout(new BoxLayout(getJPanel8(), BoxLayout.Y_AXIS));
247
            jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(
248
                null, PluginServices.getText(this, "Simbologia"),
249
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
250
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
251
            jPanel8.add(getJPanel9(), null);
252
            jPanel8.add(getBSymbol(), null);
253
        }
254
        return jPanel8;
255
    }
256

    
257
    /**
258
     * This method initializes jPanel9
259
     * 
260
     * @return javax.swing.JPanel
261
     */
262
    private JPanel getJPanel9() {
263
        if (jPanel9 == null) {
264
            jPanel9 = new JPanel();
265
            jPanel9.add(getRbPoints(), null);
266
            jPanel9.add(getRbLines(), null);
267
        }
268
        return jPanel9;
269
    }
270

    
271
    /**
272
     * This method initializes rbPoints
273
     * 
274
     * @return javax.swing.JRadioButton
275
     */
276
    private JRadioButton getRbPoints() {
277
        if (rbPoints == null) {
278
            rbPoints = new JRadioButton();
279
            bg.add(rbPoints);
280
            rbPoints.setSelected(!fframegrid.isLine());
281
            rbPoints.setText(PluginServices.getText(this, "points"));
282
        }
283
        return rbPoints;
284
    }
285

    
286
    /**
287
     * This method initializes rbLines
288
     * 
289
     * @return javax.swing.JRadioButton
290
     */
291
    private JRadioButton getRbLines() {
292
        if (rbLines == null) {
293
            rbLines = new JRadioButton();
294
            bg.add(rbLines);
295
            rbLines.setSelected(fframegrid.isLine());
296
            rbLines.setText(PluginServices.getText(this, "lines"));
297
        }
298
        return rbLines;
299
    }
300

    
301
    /**
302
     * This method initializes bSymbol
303
     * 
304
     * @return javax.swing.JButton
305
     */
306
    private JButton getBSymbol() {
307
        if (bSymbol == null) {
308
            bSymbol = new JButton();
309
            bSymbol.setText(PluginServices.getText(this, "symbol"));
310
            bSymbol.addActionListener(new java.awt.event.ActionListener() {
311

    
312
                public void actionPerformed(java.awt.event.ActionEvent e) {
313
                    PanelEditSymbol pes = new PanelEditSymbol();
314
                    if (getRbLines().isSelected()) {
315
                        pes.setSymbol(fframegrid.getSymbolLine());
316
                        pes.setShapeType(Geometry.TYPES.CURVE);
317
                    } else {
318
                        pes.setSymbol(fframegrid.getSymbolPoint());
319
                        pes.setShapeType(Geometry.TYPES.POINT);
320
                    }
321
                    PluginServices.getMDIManager().addWindow(pes);
322
                    symbol = pes.getSymbol();
323
                    // FPanelLegendDefault pld=new FPanelLegendDefault();
324
                    // pld.setFSymbol(fframegrid.getSymbolLine());
325

    
326
                }
327
            });
328
        }
329
        return bSymbol;
330
    }
331

    
332
    /**
333
     * This method initializes jPanel10
334
     * 
335
     * @return javax.swing.JPanel
336
     */
337
    private JPanel getJPanel10() {
338
        if (jPanel10 == null) {
339
            jPanel10 = new JPanel();
340
            jPanel10.setLayout(new BorderLayout());
341
            jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(
342
                null, PluginServices.getText(this, "Font"),
343
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
344
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
345
            jPanel10.add(getJPanel11(), java.awt.BorderLayout.NORTH);
346
            jPanel10.add(getJPanel12(), java.awt.BorderLayout.CENTER);
347
        }
348
        return jPanel10;
349
    }
350

    
351
    /**
352
     * This method initializes jPanel11
353
     * 
354
     * @return javax.swing.JPanel
355
     */
356
    private JPanel getJPanel11() {
357
        if (jPanel11 == null) {
358
            jPanel11 = new JPanel();
359
            jPanel11.add(getJButton(), null);
360
            jPanel11.add(getColorChooserPanel(), null);
361
        }
362
        return jPanel11;
363
    }
364

    
365
    /**
366
     * This method initializes jButton
367
     * 
368
     * @return javax.swing.JButton
369
     */
370
    private JButton getJButton() {
371
        if (jButton == null) {
372
            jButton = new JButton();
373
            jButton.setText(PluginServices.getText(this, "Font"));
374
            m_font = fframegrid.getFont();
375
            jButton.addActionListener(new java.awt.event.ActionListener() {
376

    
377
                public void actionPerformed(java.awt.event.ActionEvent e) {
378
                    Font font =
379
                        FontChooser.showDialog(PluginServices.getText(this,
380
                            "__seleccion_de_fuente"), m_font);
381
                    if (font != null)
382
                        m_font = font; // fchoser=new
383
                    // FontChooser();
384
                    // //$NON-NLS-1$
385
                }
386
            });
387
        }
388
        return jButton;
389
    }
390

    
391
    /**
392
     * This method initializes colorChooserPanel
393
     * 
394
     * @return com.iver.cit.gvsig.gui.panels.ColorChooserPanel
395
     */
396
    private ColorChooserPanel getColorChooserPanel() {
397
        if (colorChooserPanel == null) {
398
            colorChooserPanel = new ColorChooserPanel();
399
            colorChooserPanel.setAlpha(255);
400
            colorChooserPanel.setColor(fframegrid.getFontColor());
401
        }
402
        return colorChooserPanel;
403
    }
404

    
405
    /**
406
     * This method initializes jPanel12
407
     * 
408
     * @return javax.swing.JPanel
409
     */
410
    private JPanel getJPanel12() {
411
        if (jPanel12 == null) {
412
            jLabel2 = new JLabel();
413
            jLabel2.setText(PluginServices.getText(this, "size"));
414
            jPanel12 = new JPanel();
415
            jPanel12.add(jLabel2, null);
416
            jPanel12.add(getTxtSize(), null);
417
        }
418
        return jPanel12;
419
    }
420

    
421
    /**
422
     * This method initializes txtSize
423
     * 
424
     * @return javax.swing.JTextField
425
     */
426
    private JTextField getTxtSize() {
427
        if (txtSize == null) {
428
            txtSize = new JTextField();
429
            txtSize.setText(String.valueOf(fframegrid.getFontSize()));
430
            txtSize.setPreferredSize(new java.awt.Dimension(40, 20));
431
        }
432
        return txtSize;
433
    }
434

    
435
    public IFFrame getFFrame() {
436
        return newFFrameGrid;
437
    }
438

    
439
    private AcceptCancelPanel getAcceptCancelPanel() {
440
        if (accept == null) {
441
            ActionListener okAction, cancelAction;
442
            okAction = new java.awt.event.ActionListener() {
443

    
444
                public void actionPerformed(java.awt.event.ActionEvent e) {
445
                    try {
446
                        newFFrameGrid = (FFrameGrid) fframegrid.clone();
447
                        newFFrameGrid.setFFrameDependence(fframeview);
448
                        // newFFrameGrid.setBoundBox();
449
                        newFFrameGrid
450
                            .setIntervalX(Double.parseDouble(getTxtIntervalX()
451
                                .getText().toString()));
452
                        newFFrameGrid
453
                            .setIntervalY(Double.parseDouble(getTxtIntervalY()
454
                                .getText().toString()));
455

    
456
                        if (getRbLines().isSelected()) {
457
                            if (symbol != null)
458
                                newFFrameGrid.setSymbolLine(symbol);
459
                        } else {
460
                            if (symbol != null)
461
                                newFFrameGrid.setSymbolPoint(symbol);
462
                        }
463

    
464
                        newFFrameGrid.setTextColor(getColorChooserPanel()
465
                            .getColor());
466
                        newFFrameGrid.setSizeFont(Integer.parseInt(getTxtSize()
467
                            .getText()));
468
                        newFFrameGrid.setIsLine(getRbLines().isSelected());
469
                        newFFrameGrid.setFont(m_font);
470
                        newFFrameGrid.setRotation(fframeview.getRotation());
471
                    } catch (CloneNotSupportedException e1) {
472
                        LOG.error("It is not possible clonate the object", e);
473
                    }
474
                    PluginServices.getMDIManager().closeWindow(
475
                        FFrameGridDialog.this);
476
                }
477
            };
478
            cancelAction = new java.awt.event.ActionListener() {
479

    
480
                public void actionPerformed(java.awt.event.ActionEvent e) {
481
                    newFFrameGrid = null;
482
                    PluginServices.getMDIManager().closeWindow(
483
                        FFrameGridDialog.this);
484
                }
485
            };
486
            accept = new AcceptCancelPanel(okAction, cancelAction);
487
            // accept.setPreferredSize(new java.awt.Dimension(300, 300));
488
            // accept.setBounds(new java.awt.Rectangle(243,387,160,28));
489
            accept.setEnabled(true);
490
            // accept.setBounds(new java.awt.Rectangle(45, 250, 300, 32));
491
            accept.setVisible(true);
492
        }
493
        return accept;
494
    }
495

    
496
    public void setRectangle(Rectangle2D r) {
497
        rect = r;
498
    }
499

    
500
    public WindowInfo getWindowInfo() {
501
        WindowInfo m_viewinfo =
502
            new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
503
        m_viewinfo.setTitle(PluginServices.getText(this, "Grid_settings"));
504

    
505
        return m_viewinfo;
506
    }
507

    
508
    public boolean getIsAcepted() {
509
        // TODO Auto-generated method stub
510
        return false;
511
    }
512

    
513
    /**
514
     * This method initializes jPanel15
515
     * 
516
     * @return javax.swing.JPanel
517
     */
518
    private JPanel getJPanel15() {
519
        if (jPanel15 == null) {
520
            jPanel15 = new JPanel();
521
            jPanel15.add(getJPanel10(), null);
522
        }
523
        return jPanel15;
524
    }
525

    
526
    public void setFFrameView(FFrameView fview) {
527
        fframeview = fview;
528

    
529
    }
530

    
531
    public Object getWindowProfile() {
532
        return WindowInfo.DIALOG_PROFILE;
533
    }
534

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