gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.dynform / org.gvsig.tools.dynform.impl / src / main / java / org / gvsig / tools / dynform / impl / DynObjectEditor.java @ 1031
History | View | Annotate | Download (6.74 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.tools.dynform.impl; |
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.tools.ToolsLocator; |
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.i18n.I18nManager; |
52 |
import org.gvsig.tools.service.ServiceException; |
53 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
54 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
/**
|
59 |
* Editor for a store parameters.
|
60 |
*
|
61 |
* @author gvSIG Team
|
62 |
* @version $Id$
|
63 |
*/
|
64 |
public class DynObjectEditor extends JPanel implements ActionListener { |
65 |
|
66 |
private static final long serialVersionUID = 23898787077741411L; |
67 |
|
68 |
private static final Logger LOG = LoggerFactory |
69 |
.getLogger(DynObjectEditor.class); |
70 |
|
71 |
private String title; |
72 |
|
73 |
private JButton botAcept; |
74 |
private JButton botCancel; |
75 |
private JButton botRestoreDefaults; |
76 |
private JPanel panButtons; |
77 |
private I18nManager i18nManager;
|
78 |
|
79 |
// private boolean modal;
|
80 |
|
81 |
private JDynForm form = null; |
82 |
private DynObject data = null; |
83 |
|
84 |
public DynObjectEditor(DynObject parameters, boolean showDefaultsButton) |
85 |
throws ServiceException {
|
86 |
this.i18nManager = ToolsLocator.getI18nManager();
|
87 |
this.data = parameters;
|
88 |
this.form = DynFormLocator.getDynFormManager().createJDynForm(this.data); |
89 |
this.form.setLayoutMode(this.form.USE_TABS); |
90 |
this.setLayout(new BorderLayout()); |
91 |
this.add(this.form.asJComponent(), BorderLayout.CENTER); |
92 |
this.add(getButtonsPanel(showDefaultsButton), BorderLayout.SOUTH); |
93 |
this.setPreferredSize(new Dimension(500,250)); |
94 |
String s = this.data.getDynClass().getDescription(); |
95 |
if( s==null || s.length()==0 ) { |
96 |
s = this.data.getDynClass().getName();
|
97 |
} |
98 |
this.setTitle(s);
|
99 |
} |
100 |
|
101 |
public DynObjectEditor(DynObject parameters) throws ServiceException { |
102 |
this(parameters, false); |
103 |
} |
104 |
|
105 |
private JPanel getButtonsPanel(boolean add_defaults_button) { |
106 |
if (this.panButtons == null) { |
107 |
this.panButtons = new JPanel(); |
108 |
this.panButtons.setLayout(new GridBagLayout()); |
109 |
GridBagConstraints constr = new GridBagConstraints(); |
110 |
constr.anchor = GridBagConstraints.LAST_LINE_END;
|
111 |
constr.fill = GridBagConstraints.HORIZONTAL;
|
112 |
constr.weightx = 1;
|
113 |
constr.weighty = 0;
|
114 |
this.panButtons.add(new JLabel(), constr); |
115 |
|
116 |
constr = this.getDefaultParametersConstraints();
|
117 |
constr.fill = GridBagConstraints.NONE;
|
118 |
constr.weightx = 0;
|
119 |
constr.weighty = 0;
|
120 |
|
121 |
this.panButtons.add(this.getAcceptButton(), constr); |
122 |
this.panButtons.add(this.getCancelButton(), constr); |
123 |
if (add_defaults_button) {
|
124 |
this.panButtons.add(this.getRestoreDefaults(), constr); |
125 |
} |
126 |
} |
127 |
return this.panButtons; |
128 |
} |
129 |
|
130 |
private GridBagConstraints getDefaultParametersConstraints() { |
131 |
GridBagConstraints constr = new GridBagConstraints(); |
132 |
constr.insets = new Insets(2, 2, 2, 2); |
133 |
constr.ipadx = 2;
|
134 |
constr.ipady = 2;
|
135 |
constr.anchor = GridBagConstraints.PAGE_START;
|
136 |
return constr;
|
137 |
|
138 |
} |
139 |
|
140 |
private JButton getRestoreDefaults() { |
141 |
if (this.botRestoreDefaults == null) { |
142 |
this.botRestoreDefaults =
|
143 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
144 |
i18nManager.getTranslation("restoreDefaults"));
|
145 |
this.botRestoreDefaults.addActionListener(this); |
146 |
} |
147 |
return this.botRestoreDefaults; |
148 |
} |
149 |
|
150 |
private JButton getCancelButton() { |
151 |
if (this.botCancel == null) { |
152 |
this.botCancel =
|
153 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
154 |
i18nManager.getTranslation("cancel"));
|
155 |
this.botCancel.addActionListener(this); |
156 |
} |
157 |
return this.botCancel; |
158 |
} |
159 |
|
160 |
private JButton getAcceptButton() { |
161 |
if (this.botAcept == null) { |
162 |
this.botAcept =
|
163 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
164 |
i18nManager.getTranslation("accept"));
|
165 |
this.botAcept.addActionListener(this); |
166 |
} |
167 |
return this.botAcept; |
168 |
} |
169 |
|
170 |
public void actionPerformed(ActionEvent e) { |
171 |
Component source = (Component) e.getSource(); |
172 |
if (source == this.botAcept) { |
173 |
this.form.getValues(this.data); |
174 |
this.closeWindow();
|
175 |
} else if (source == this.botCancel) { |
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 |
public DynObject getParameters() {
|
208 |
this.form.getValues(this.data); |
209 |
return this.data; |
210 |
} |
211 |
} |