svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / swing / dynobject / DynObjectEditor.java @ 41331
History | View | Annotate | Download (7.14 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2008 IVER T.I. S.A. {{Task}}
|
27 |
*/
|
28 |
|
29 |
/**
|
30 |
*
|
31 |
*/
|
32 |
package org.gvsig.fmap.mapcontrol.swing.dynobject; |
33 |
|
34 |
import java.awt.BorderLayout; |
35 |
import java.awt.Component; |
36 |
import java.awt.Dimension; |
37 |
import java.awt.GridBagConstraints; |
38 |
import java.awt.GridBagLayout; |
39 |
import java.awt.Insets; |
40 |
import java.awt.event.ActionEvent; |
41 |
import java.awt.event.ActionListener; |
42 |
|
43 |
import javax.swing.JButton; |
44 |
import javax.swing.JLabel; |
45 |
import javax.swing.JPanel; |
46 |
|
47 |
import org.gvsig.i18n.Messages; |
48 |
import org.gvsig.tools.dynform.DynFormLocator; |
49 |
import org.gvsig.tools.dynform.JDynForm; |
50 |
import org.gvsig.tools.dynobject.DynObject; |
51 |
import org.gvsig.tools.service.ServiceException; |
52 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
53 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
54 |
import org.slf4j.Logger; |
55 |
import org.slf4j.LoggerFactory; |
56 |
|
57 |
/**
|
58 |
* Editor for a store parameters.
|
59 |
*
|
60 |
* @author gvSIG Team
|
61 |
* @version $Id$
|
62 |
*/
|
63 |
public class DynObjectEditor extends JPanel implements ActionListener { |
64 |
|
65 |
private static final long serialVersionUID = 23898787077741411L; |
66 |
|
67 |
private static final Logger LOG = LoggerFactory |
68 |
.getLogger(DynObjectEditor.class); |
69 |
|
70 |
private String title; |
71 |
|
72 |
private JButton botAcept; |
73 |
private JButton botCancel; |
74 |
private JButton botRestoreDefaults; |
75 |
private JPanel panButtons; |
76 |
|
77 |
// private boolean modal;
|
78 |
|
79 |
private JDynForm form = null; |
80 |
private DynObject data = null; |
81 |
private boolean isCanceled = false; |
82 |
|
83 |
public DynObjectEditor(DynObject data, boolean showDefaultsButton) |
84 |
throws ServiceException {
|
85 |
this.data = data;
|
86 |
this.form = DynFormLocator.getDynFormManager().createJDynForm(this.data); |
87 |
this.form.setLayoutMode(this.form.USE_TABS); |
88 |
this.setLayout(new BorderLayout()); |
89 |
this.add(this.form.asJComponent(), BorderLayout.CENTER); |
90 |
this.add(getButtonsPanel(showDefaultsButton), BorderLayout.SOUTH); |
91 |
this.setPreferredSize(new Dimension(500,250)); |
92 |
String s = this.data.getDynClass().getDescription(); |
93 |
if( s==null || s.length()==0 ) { |
94 |
s = this.data.getDynClass().getName();
|
95 |
} |
96 |
this.setTitle(s);
|
97 |
} |
98 |
|
99 |
public DynObjectEditor(DynObject data) throws ServiceException { |
100 |
this(data, false); |
101 |
} |
102 |
|
103 |
private JPanel getButtonsPanel(boolean add_defaults_button) { |
104 |
if (this.panButtons == null) { |
105 |
this.panButtons = new JPanel(); |
106 |
this.panButtons.setLayout(new GridBagLayout()); |
107 |
GridBagConstraints constr = new GridBagConstraints(); |
108 |
constr.anchor = GridBagConstraints.LAST_LINE_END;
|
109 |
constr.fill = GridBagConstraints.HORIZONTAL;
|
110 |
constr.weightx = 1;
|
111 |
constr.weighty = 0;
|
112 |
this.panButtons.add(new JLabel(), constr); |
113 |
|
114 |
constr = this.getDefaultParametersConstraints();
|
115 |
constr.fill = GridBagConstraints.NONE;
|
116 |
constr.weightx = 0;
|
117 |
constr.weighty = 0;
|
118 |
|
119 |
this.panButtons.add(this.getAcceptButton(), constr); |
120 |
this.panButtons.add(this.getCancelButton(), constr); |
121 |
if (add_defaults_button) {
|
122 |
this.panButtons.add(this.getRestoreDefaults(), constr); |
123 |
} |
124 |
} |
125 |
return this.panButtons; |
126 |
} |
127 |
|
128 |
private GridBagConstraints getDefaultParametersConstraints() { |
129 |
GridBagConstraints constr = new GridBagConstraints(); |
130 |
constr.insets = new Insets(2, 2, 2, 2); |
131 |
constr.ipadx = 2;
|
132 |
constr.ipady = 2;
|
133 |
constr.anchor = GridBagConstraints.PAGE_START;
|
134 |
return constr;
|
135 |
|
136 |
} |
137 |
|
138 |
private JButton getRestoreDefaults() { |
139 |
if (this.botRestoreDefaults == null) { |
140 |
this.botRestoreDefaults =
|
141 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
142 |
Messages.getText("restoreDefaults"));
|
143 |
this.botRestoreDefaults.addActionListener(this); |
144 |
} |
145 |
return this.botRestoreDefaults; |
146 |
} |
147 |
|
148 |
private JButton getCancelButton() { |
149 |
if (this.botCancel == null) { |
150 |
this.botCancel =
|
151 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
152 |
Messages.getText("cancel"));
|
153 |
this.botCancel.addActionListener(this); |
154 |
} |
155 |
return this.botCancel; |
156 |
} |
157 |
|
158 |
private JButton getAcceptButton() { |
159 |
if (this.botAcept == null) { |
160 |
this.botAcept =
|
161 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
162 |
Messages.getText("accept"));
|
163 |
this.botAcept.addActionListener(this); |
164 |
} |
165 |
return this.botAcept; |
166 |
} |
167 |
|
168 |
public void actionPerformed(ActionEvent e) { |
169 |
Component source = (Component) e.getSource(); |
170 |
if (source == this.botAcept) { |
171 |
this.form.getValues(this.data); |
172 |
this.isCanceled = false; |
173 |
this.closeWindow();
|
174 |
} else if (source == this.botCancel) { |
175 |
this.isCanceled = true; |
176 |
this.closeWindow();
|
177 |
} else if (source == this.botRestoreDefaults) { |
178 |
this.form.setValues(this.data); |
179 |
} |
180 |
} |
181 |
|
182 |
protected void closeWindow() { |
183 |
LOG.debug("Closing window, values edited: ", this.data); |
184 |
this.setVisible(false); |
185 |
} |
186 |
|
187 |
public void editObject(boolean modal) { |
188 |
// this.modal = modal;
|
189 |
|
190 |
WindowManager wmanager = ToolsSwingLocator.getWindowManager(); |
191 |
|
192 |
wmanager.showWindow(this,title,WindowManager.MODE.DIALOG);
|
193 |
|
194 |
// wmanager.showWindow(this,
|
195 |
// Messages.getText("explorer_parameters"),
|
196 |
// WindowManager.MODE.DIALOG);
|
197 |
} |
198 |
|
199 |
public String getTitle() { |
200 |
return title;
|
201 |
} |
202 |
|
203 |
public void setTitle(String title) { |
204 |
this.title = title;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* @deprecated use getData
|
209 |
* @return the data values of the DynObject managed
|
210 |
*/
|
211 |
public DynObject getParameters() {
|
212 |
return this.getData(); |
213 |
} |
214 |
|
215 |
/**
|
216 |
* Return the data values of the DynObject managed.
|
217 |
* @return the dynobject
|
218 |
*/
|
219 |
public DynObject getData() {
|
220 |
this.form.getValues(this.data); |
221 |
return this.data; |
222 |
} |
223 |
|
224 |
public DynObject getData(DynObject data) {
|
225 |
this.form.getValues(data);
|
226 |
return data;
|
227 |
} |
228 |
|
229 |
public boolean isCanceled() { |
230 |
return this.isCanceled; |
231 |
} |
232 |
} |