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 @ 250
History | View | Annotate | Download (10.5 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.geom.Rectangle2D; |
27 |
|
28 |
import javax.swing.JLabel; |
29 |
import javax.swing.JPanel; |
30 |
import javax.swing.JTextField; |
31 |
|
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
34 |
import org.gvsig.app.project.documents.layout.fframes.FFrameTable; |
35 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
36 |
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation; |
37 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
38 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
39 |
|
40 |
public class FFrameBoxDialog extends AbstractFFrameDialog implements |
41 |
IFFrameDialog { |
42 |
|
43 |
private static final long serialVersionUID = 8263909754475456840L; |
44 |
|
45 |
/*
|
46 |
* This class is a workaround to eliminate the dependency with
|
47 |
* the package de.ios.framework.
|
48 |
*/
|
49 |
private class NumberField extends JTextField { |
50 |
private static final long serialVersionUID = 2011942753522279875L; |
51 |
|
52 |
public Integer getIntegerValue() { |
53 |
try{
|
54 |
return Integer.valueOf(getText()); |
55 |
}catch(NumberFormatException e){ |
56 |
if (getText().equals("")){ |
57 |
return 0; |
58 |
} |
59 |
return 0; |
60 |
} |
61 |
} |
62 |
} |
63 |
|
64 |
private JPanel jPanel = null; |
65 |
private JLabel jLabel = null; |
66 |
private JLabel jLabel1 = null; |
67 |
private NumberField txtNumColumns = null; |
68 |
private NumberField txtNumRows = null; |
69 |
private Rectangle2D rect = new Rectangle2D.Double(); |
70 |
private FFrameTable fframebox;
|
71 |
private boolean isAcepted = false; |
72 |
private JPanel pBox = null; |
73 |
private FFrameTable thefframebox;
|
74 |
private JPRotation pRotation;
|
75 |
private AcceptCancelPanel acceptCancel = null; |
76 |
private FFrameTable newFFrameBox;
|
77 |
|
78 |
/**
|
79 |
* This is the default constructor
|
80 |
*
|
81 |
* @param layoutPanel
|
82 |
* Referencia al Layout.
|
83 |
* @param fframe
|
84 |
* Referencia al fframe del cajet?n.
|
85 |
* @throws CloneNotSupportedException
|
86 |
*/
|
87 |
public FFrameBoxDialog(LayoutPanel layoutPanel, IFFrame frame)
|
88 |
throws CloneNotSupportedException { |
89 |
super(layoutPanel, frame);
|
90 |
fframebox = (FFrameTable) frame; |
91 |
thefframebox = (FFrameTable) fframebox.clone(); |
92 |
initialize(); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* This method initializes this
|
97 |
*
|
98 |
* @return void
|
99 |
*/
|
100 |
private void initialize() { |
101 |
this.setLayout(null); |
102 |
this.setSize(380, 185); |
103 |
this.add(getJPanel(), null); |
104 |
this.add(getPRotation(), null); |
105 |
this.add(getAcceptCancel());
|
106 |
getPRotation().setRotation(fframebox.getRotation()); |
107 |
} |
108 |
|
109 |
private AcceptCancelPanel getAcceptCancel() {
|
110 |
if (this.acceptCancel == null) { |
111 |
this.acceptCancel =
|
112 |
new AcceptCancelPanel(new java.awt.event.ActionListener() { |
113 |
|
114 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
115 |
try {
|
116 |
newFFrameBox = (FFrameTable) fframebox.clone(); |
117 |
if (getTxtNumColumns().getText().equals("")) { |
118 |
getTxtNumColumns().setText("0");
|
119 |
} |
120 |
if (getTxtNumRows().getText().equals("")) { |
121 |
getTxtNumRows().setText("0");
|
122 |
} |
123 |
newFFrameBox.setNumColumns(getTxtNumColumns().getIntegerValue()); |
124 |
newFFrameBox.setNumRows(getTxtNumRows().getIntegerValue()); |
125 |
newFFrameBox.setRotation(getPRotation() |
126 |
.getRotation()); |
127 |
Rectangle2D r = fframebox.getBoundBox();
|
128 |
newFFrameBox.calculateTable(r); |
129 |
} catch (CloneNotSupportedException e1) { |
130 |
LOG.error("It is not possible clonate the object",
|
131 |
e); |
132 |
} |
133 |
PluginServices.getMDIManager().closeWindow( |
134 |
FFrameBoxDialog.this); |
135 |
isAcepted = true;
|
136 |
notifyDialogClosed(); |
137 |
layoutPanel.getLayoutControl().setDefaultTool(); |
138 |
} |
139 |
}, |
140 |
|
141 |
new java.awt.event.ActionListener() {
|
142 |
|
143 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
144 |
newFFrameBox = null;
|
145 |
PluginServices.getMDIManager().closeWindow( |
146 |
FFrameBoxDialog.this); |
147 |
notifyDialogClosed(); |
148 |
} |
149 |
}); |
150 |
this.acceptCancel.setBounds(5, 150, this.getWidth() - 10, 30); |
151 |
|
152 |
} |
153 |
return this.acceptCancel; |
154 |
} |
155 |
|
156 |
/**
|
157 |
* This method initializes jPanel
|
158 |
*
|
159 |
* @return javax.swing.JPanel
|
160 |
*/
|
161 |
private JPanel getJPanel() { |
162 |
if (jPanel == null) { |
163 |
jLabel1 = new JLabel(); |
164 |
jLabel1.setBounds(new java.awt.Rectangle(5, 32, 165, 19)); |
165 |
jLabel1.setText(PluginServices.getText(this, "num_filas")); |
166 |
jLabel = new JLabel(); |
167 |
jLabel.setBounds(new java.awt.Rectangle(5, 8, 165, 19)); |
168 |
jLabel.setText(PluginServices.getText(this, "num_columnas")); |
169 |
jPanel = new JPanel(); |
170 |
jPanel.setLayout(null);
|
171 |
jPanel.setBounds(new java.awt.Rectangle(12, 9, 220, 140)); |
172 |
jPanel.add(jLabel, null);
|
173 |
jPanel.add(jLabel1, null);
|
174 |
jPanel.add(getTxtNumColumns(), null);
|
175 |
jPanel.add(getTxtNumRows(), null);
|
176 |
jPanel.add(getPBox(), null);
|
177 |
|
178 |
} |
179 |
return jPanel;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* This method initializes txtNumColumns
|
184 |
*
|
185 |
* @return javax.swing.JTextField
|
186 |
*/
|
187 |
private NumberField getTxtNumColumns() {
|
188 |
if (txtNumColumns == null) { |
189 |
txtNumColumns = new NumberField();
|
190 |
txtNumColumns.setText(String.valueOf(fframebox.getNumColumns()));
|
191 |
txtNumColumns.setBounds(new java.awt.Rectangle(175, 8, 35, 19)); |
192 |
txtNumColumns.addKeyListener(new java.awt.event.KeyAdapter() {
|
193 |
|
194 |
public void keyReleased(java.awt.event.KeyEvent e) { |
195 |
if (getTxtNumColumns().getText().equals("") |
196 |
|| getTxtNumColumns().getText().equals("0")) {
|
197 |
return;
|
198 |
} |
199 |
thefframebox.setNumColumns(txtNumColumns.getIntegerValue() |
200 |
.intValue()); |
201 |
getPBox().repaint(); |
202 |
} |
203 |
}); |
204 |
} |
205 |
return txtNumColumns;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* This method initializes txtNumRows
|
210 |
*
|
211 |
* @return javax.swing.JTextField
|
212 |
*/
|
213 |
private NumberField getTxtNumRows() {
|
214 |
if (txtNumRows == null) { |
215 |
txtNumRows = new NumberField();
|
216 |
txtNumRows.setText(String.valueOf(fframebox.getNumRows()));
|
217 |
txtNumRows.setBounds(new java.awt.Rectangle(175, 32, 35, 19)); |
218 |
txtNumRows.addKeyListener(new java.awt.event.KeyAdapter() {
|
219 |
|
220 |
public void keyReleased(java.awt.event.KeyEvent e) { |
221 |
if (getTxtNumRows().getText().equals("") |
222 |
|| getTxtNumRows().getText().equals("0")) {
|
223 |
return;
|
224 |
} |
225 |
thefframebox.setNumRows(txtNumRows.getIntegerValue().intValue()); |
226 |
getPBox().repaint(); |
227 |
} |
228 |
}); |
229 |
} |
230 |
return txtNumRows;
|
231 |
} |
232 |
|
233 |
public void setRectangle(Rectangle2D r) { |
234 |
rect.setRect(r); |
235 |
} |
236 |
|
237 |
public WindowInfo getWindowInfo() {
|
238 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
239 |
m_viewinfo |
240 |
.setTitle(PluginServices.getText(this, "propiedades_cajetin")); |
241 |
|
242 |
return m_viewinfo;
|
243 |
} |
244 |
|
245 |
public boolean getIsAcepted() { |
246 |
return isAcepted;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* This method initializes jPanel1
|
251 |
*
|
252 |
* @return javax.swing.JPanel
|
253 |
*/
|
254 |
private JPanel getPBox() { |
255 |
if (pBox == null) { |
256 |
pBox = new PanelBox();
|
257 |
pBox.setBackground(java.awt.Color.white); |
258 |
pBox.setSize(new java.awt.Dimension(202, 75)); |
259 |
pBox.setLocation(new java.awt.Point(5, 55)); |
260 |
pBox.addMouseListener(new java.awt.event.MouseAdapter() {
|
261 |
|
262 |
public void mouseReleased(java.awt.event.MouseEvent e) { |
263 |
// /Rectangle2D r = new Rectangle2D.Double(5, 5, 155, 65);
|
264 |
} |
265 |
}); |
266 |
} |
267 |
return pBox;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* This method initializes pRotation
|
272 |
*
|
273 |
* @return javax.swing.JPanel
|
274 |
*/
|
275 |
private JPRotation getPRotation() {
|
276 |
if (pRotation == null) { |
277 |
pRotation = new JPRotation();
|
278 |
pRotation.setBounds(240, 14, 120, 120); |
279 |
} |
280 |
return pRotation;
|
281 |
} |
282 |
|
283 |
class PanelBox extends JPanel { |
284 |
|
285 |
/**
|
286 |
*
|
287 |
*/
|
288 |
private static final long serialVersionUID = 7266620645304277646L; |
289 |
|
290 |
protected void paintComponent(Graphics g) { |
291 |
super.paintComponent(g);
|
292 |
Rectangle2D r =
|
293 |
new Rectangle2D.Double(5, 5, this.getWidth() - 10, |
294 |
this.getHeight() - 10); |
295 |
thefframebox.drawBox(r, (Graphics2D) g);
|
296 |
} |
297 |
|
298 |
} |
299 |
|
300 |
public IFFrame getFFrame() {
|
301 |
return newFFrameBox;
|
302 |
} |
303 |
|
304 |
public Object getWindowProfile() { |
305 |
return WindowInfo.DIALOG_PROFILE;
|
306 |
} |
307 |
} // @jve:decl-index=0:visual-constraint="10,10"
|