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 / FFrameBoxDialog.java @ 717

History | View | Annotate | Download (10.6 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.Graphics;
25
import java.awt.Graphics2D;
26
import java.awt.event.ActionEvent;
27
import java.awt.geom.Rectangle2D;
28

    
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31
import javax.swing.JTextField;
32

    
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.ui.mdiManager.WindowInfo;
35
import org.gvsig.app.project.documents.layout.fframes.FFrameTable;
36
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
37
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation;
38
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
39
import org.gvsig.gui.beans.AcceptCancelPanel;
40

    
41
public class FFrameBoxDialog extends AbstractFFrameDialog implements
42
    IFFrameDialog {
43

    
44
    private static final long serialVersionUID = 8263909754475456840L;
45

    
46
    /*
47
     * This class is a workaround to eliminate the dependency with
48
     * the package de.ios.framework.
49
     */
50
    private class NumberField extends JTextField {
51
        private static final long serialVersionUID = 2011942753522279875L;
52

    
53
        public Integer getIntegerValue() {
54
            try{
55
                return Integer.valueOf(getText());
56
            }catch(NumberFormatException e){
57
                if (getText().equals("")){
58
                    return 0;
59
                }                
60
                return 0;
61
            }
62
        }
63
    }
64

    
65
    private JPanel jPanel = null;
66
    private JLabel jLabel = null;
67
    private JLabel jLabel1 = null;
68
    private NumberField txtNumColumns = null;
69
    private NumberField txtNumRows = null;
70
    private Rectangle2D rect = new Rectangle2D.Double();
71
    private FFrameTable fframebox;
72
    private boolean isAcepted = false;
73
    private JPanel pBox = null;
74
    private FFrameTable thefframebox;
75
    private JPRotation pRotation;
76
    private AcceptCancelPanel acceptCancel = null;
77
    private FFrameTable newFFrameBox;
78

    
79
    /**
80
     * This is the default constructor
81
     * 
82
     * @param layoutPanel
83
     *            Referencia al Layout.
84
     * @param fframe
85
     *            Referencia al fframe del cajet?n.
86
     * @throws CloneNotSupportedException
87
     */
88
    public FFrameBoxDialog(LayoutPanel layoutPanel, IFFrame frame)
89
        throws CloneNotSupportedException {
90
        super(layoutPanel, frame);
91
        fframebox = (FFrameTable) frame;
92
        thefframebox = (FFrameTable) fframebox.clone();
93
        initialize();
94
    }
95

    
96
    /**
97
     * This method initializes this
98
     * 
99
     * @return void
100
     */
101
    private void initialize() {
102
        this.setLayout(null);
103
        this.setSize(380, 185);
104
        this.add(getJPanel(), null);
105
        this.add(getPRotation(), null);
106
        this.add(getAcceptCancel());
107
        getPRotation().setRotation(fframebox.getRotation());
108
    }
109

    
110
    private AcceptCancelPanel getAcceptCancel() {
111
        if (this.acceptCancel == null) {
112
            this.acceptCancel =
113
                new AcceptCancelPanel(new java.awt.event.ActionListener() {
114

    
115
                    public void actionPerformed(java.awt.event.ActionEvent e) {
116
                        try {
117
                            newFFrameBox = (FFrameTable) fframebox.clone();
118
                            if (getTxtNumColumns().getText().equals("")) {
119
                                getTxtNumColumns().setText("0");
120
                            }
121
                            if (getTxtNumRows().getText().equals("")) {
122
                                getTxtNumRows().setText("0");
123
                            }
124
                            newFFrameBox.setNumColumns(getTxtNumColumns().getIntegerValue());                               
125
                            newFFrameBox.setNumRows(getTxtNumRows().getIntegerValue());                            
126
                            newFFrameBox.setRotation(getPRotation()
127
                                .getRotation());
128
                            Rectangle2D r = fframebox.getBoundBox();
129
                            newFFrameBox.calculateTable(r);
130
                        } catch (CloneNotSupportedException e1) {
131
                            LOG.error("It is not possible clonate the object",
132
                                e);
133
                        }
134
                        PluginServices.getMDIManager().closeWindow(
135
                            FFrameBoxDialog.this);
136
                        isAcepted = true;
137
                        notifyDialogClosed();
138
                        layoutPanel.getLayoutControl().setDefaultTool();
139
                        fireActionEvent(new ActionEvent(FFrameBoxDialog.this, 1, "accept"));
140

    
141
                    }
142
                },
143

    
144
                new java.awt.event.ActionListener() {
145

    
146
                    public void actionPerformed(java.awt.event.ActionEvent e) {
147
                        newFFrameBox = null;
148
                        PluginServices.getMDIManager().closeWindow(
149
                            FFrameBoxDialog.this);
150
                        notifyDialogClosed();
151
                    }
152
                });
153
            this.acceptCancel.setBounds(5, 150, this.getWidth() - 10, 30);
154

    
155
        }
156
        return this.acceptCancel;
157
    }
158

    
159
    /**
160
     * This method initializes jPanel
161
     * 
162
     * @return javax.swing.JPanel
163
     */
164
    private JPanel getJPanel() {
165
        if (jPanel == null) {
166
            jLabel1 = new JLabel();
167
            jLabel1.setBounds(new java.awt.Rectangle(5, 32, 165, 19));
168
            jLabel1.setText(PluginServices.getText(this, "num_filas"));
169
            jLabel = new JLabel();
170
            jLabel.setBounds(new java.awt.Rectangle(5, 8, 165, 19));
171
            jLabel.setText(PluginServices.getText(this, "num_columnas"));
172
            jPanel = new JPanel();
173
            jPanel.setLayout(null);
174
            jPanel.setBounds(new java.awt.Rectangle(12, 9, 220, 140));
175
            jPanel.add(jLabel, null);
176
            jPanel.add(jLabel1, null);
177
            jPanel.add(getTxtNumColumns(), null);
178
            jPanel.add(getTxtNumRows(), null);
179
            jPanel.add(getPBox(), null);
180

    
181
        }
182
        return jPanel;
183
    }
184

    
185
    /**
186
     * This method initializes txtNumColumns
187
     * 
188
     * @return javax.swing.JTextField
189
     */
190
    private NumberField getTxtNumColumns() {
191
        if (txtNumColumns == null) {
192
            txtNumColumns = new NumberField();
193
            txtNumColumns.setText(String.valueOf(fframebox.getNumColumns()));
194
            txtNumColumns.setBounds(new java.awt.Rectangle(175, 8, 35, 19));
195
            txtNumColumns.addKeyListener(new java.awt.event.KeyAdapter() {
196

    
197
                public void keyReleased(java.awt.event.KeyEvent e) {
198
                    if (getTxtNumColumns().getText().equals("")
199
                        || getTxtNumColumns().getText().equals("0")) {
200
                        return;
201
                    }
202
                    thefframebox.setNumColumns(txtNumColumns.getIntegerValue()
203
                        .intValue());
204
                    getPBox().repaint();
205
                }
206
            });
207
        }
208
        return txtNumColumns;
209
    }
210

    
211
    /**
212
     * This method initializes txtNumRows
213
     * 
214
     * @return javax.swing.JTextField
215
     */
216
    private NumberField getTxtNumRows() {
217
        if (txtNumRows == null) {
218
            txtNumRows = new NumberField();
219
            txtNumRows.setText(String.valueOf(fframebox.getNumRows()));
220
            txtNumRows.setBounds(new java.awt.Rectangle(175, 32, 35, 19));
221
            txtNumRows.addKeyListener(new java.awt.event.KeyAdapter() {
222

    
223
                public void keyReleased(java.awt.event.KeyEvent e) {                  
224
                    if (getTxtNumRows().getText().equals("")
225
                        || getTxtNumRows().getText().equals("0")) {
226
                        return;
227
                    }                       
228
                    thefframebox.setNumRows(txtNumRows.getIntegerValue().intValue());
229
                    getPBox().repaint();
230
                }
231
            });
232
        }
233
        return txtNumRows;
234
    }
235

    
236
    public void setRectangle(Rectangle2D r) {
237
        rect.setRect(r);
238
    }
239

    
240
    public WindowInfo getWindowInfo() {
241
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
242
        m_viewinfo
243
            .setTitle(PluginServices.getText(this, "propiedades_cajetin"));
244

    
245
        return m_viewinfo;
246
    }
247

    
248
    public boolean getIsAcepted() {
249
        return isAcepted;
250
    }
251

    
252
    /**
253
     * This method initializes jPanel1
254
     * 
255
     * @return javax.swing.JPanel
256
     */
257
    private JPanel getPBox() {
258
        if (pBox == null) {
259
            pBox = new PanelBox();
260
            pBox.setBackground(java.awt.Color.white);
261
            pBox.setSize(new java.awt.Dimension(202, 75));
262
            pBox.setLocation(new java.awt.Point(5, 55));
263
            pBox.addMouseListener(new java.awt.event.MouseAdapter() {
264

    
265
                public void mouseReleased(java.awt.event.MouseEvent e) {
266
                    // /Rectangle2D r = new Rectangle2D.Double(5, 5, 155, 65);
267
                }
268
            });
269
        }
270
        return pBox;
271
    }
272

    
273
    /**
274
     * This method initializes pRotation
275
     * 
276
     * @return javax.swing.JPanel
277
     */
278
    private JPRotation getPRotation() {
279
        if (pRotation == null) {
280
            pRotation = new JPRotation();
281
            pRotation.setBounds(240, 14, 120, 120);
282
        }
283
        return pRotation;
284
    }
285

    
286
    class PanelBox extends JPanel {
287

    
288
        /**
289
         * 
290
         */
291
        private static final long serialVersionUID = 7266620645304277646L;
292

    
293
        protected void paintComponent(Graphics g) {
294
            super.paintComponent(g);
295
            Rectangle2D r =
296
                new Rectangle2D.Double(5, 5, this.getWidth() - 10,
297
                    this.getHeight() - 10);
298
            thefframebox.drawBox(r, (Graphics2D) g);
299
        }
300

    
301
    }
302

    
303
    public IFFrame getFFrame() {
304
        return newFFrameBox;
305
    }
306

    
307
    public Object getWindowProfile() {
308
        return WindowInfo.DIALOG_PROFILE;
309
    }
310
} // @jve:decl-index=0:visual-constraint="10,10"