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 @ 40874
History | View | Annotate | Download (6.59 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 |
|
82 |
public DynObjectEditor(DynObject parameters, boolean showDefaultsButton) |
83 |
throws ServiceException {
|
84 |
this.data = parameters;
|
85 |
this.form = DynFormLocator.getDynFormManager().createJDynForm(this.data); |
86 |
this.form.setLayoutMode(this.form.USE_TABS); |
87 |
this.setLayout(new BorderLayout()); |
88 |
this.add(this.form.asJComponent(), BorderLayout.CENTER); |
89 |
this.add(getButtonsPanel(showDefaultsButton), BorderLayout.SOUTH); |
90 |
this.setPreferredSize(new Dimension(500,250)); |
91 |
String s = this.data.getDynClass().getDescription(); |
92 |
if( s==null || s.length()==0 ) { |
93 |
s = this.data.getDynClass().getName();
|
94 |
} |
95 |
this.setTitle(s);
|
96 |
} |
97 |
|
98 |
public DynObjectEditor(DynObject parameters) throws ServiceException { |
99 |
this(parameters, false); |
100 |
} |
101 |
|
102 |
private JPanel getButtonsPanel(boolean add_defaults_button) { |
103 |
if (this.panButtons == null) { |
104 |
this.panButtons = new JPanel(); |
105 |
this.panButtons.setLayout(new GridBagLayout()); |
106 |
GridBagConstraints constr = new GridBagConstraints(); |
107 |
constr.anchor = GridBagConstraints.LAST_LINE_END;
|
108 |
constr.fill = GridBagConstraints.HORIZONTAL;
|
109 |
constr.weightx = 1;
|
110 |
constr.weighty = 0;
|
111 |
this.panButtons.add(new JLabel(), constr); |
112 |
|
113 |
constr = this.getDefaultParametersConstraints();
|
114 |
constr.fill = GridBagConstraints.NONE;
|
115 |
constr.weightx = 0;
|
116 |
constr.weighty = 0;
|
117 |
|
118 |
this.panButtons.add(this.getAcceptButton(), constr); |
119 |
this.panButtons.add(this.getCancelButton(), constr); |
120 |
if (add_defaults_button) {
|
121 |
this.panButtons.add(this.getRestoreDefaults(), constr); |
122 |
} |
123 |
} |
124 |
return this.panButtons; |
125 |
} |
126 |
|
127 |
private GridBagConstraints getDefaultParametersConstraints() { |
128 |
GridBagConstraints constr = new GridBagConstraints(); |
129 |
constr.insets = new Insets(2, 2, 2, 2); |
130 |
constr.ipadx = 2;
|
131 |
constr.ipady = 2;
|
132 |
constr.anchor = GridBagConstraints.PAGE_START;
|
133 |
return constr;
|
134 |
|
135 |
} |
136 |
|
137 |
private JButton getRestoreDefaults() { |
138 |
if (this.botRestoreDefaults == null) { |
139 |
this.botRestoreDefaults =
|
140 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
141 |
Messages.getText("restoreDefaults"));
|
142 |
this.botRestoreDefaults.addActionListener(this); |
143 |
} |
144 |
return this.botRestoreDefaults; |
145 |
} |
146 |
|
147 |
private JButton getCancelButton() { |
148 |
if (this.botCancel == null) { |
149 |
this.botCancel =
|
150 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
151 |
Messages.getText("cancel"));
|
152 |
this.botCancel.addActionListener(this); |
153 |
} |
154 |
return this.botCancel; |
155 |
} |
156 |
|
157 |
private JButton getAcceptButton() { |
158 |
if (this.botAcept == null) { |
159 |
this.botAcept =
|
160 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton( |
161 |
Messages.getText("accept"));
|
162 |
this.botAcept.addActionListener(this); |
163 |
} |
164 |
return this.botAcept; |
165 |
} |
166 |
|
167 |
public void actionPerformed(ActionEvent e) { |
168 |
Component source = (Component) e.getSource(); |
169 |
if (source == this.botAcept) { |
170 |
this.form.getValues(this.data); |
171 |
this.closeWindow();
|
172 |
} else if (source == this.botCancel) { |
173 |
this.closeWindow();
|
174 |
} else if (source == this.botRestoreDefaults) { |
175 |
this.form.setValues(this.data); |
176 |
} |
177 |
} |
178 |
|
179 |
protected void closeWindow() { |
180 |
LOG.debug("Closing window, values edited: ", this.data); |
181 |
this.setVisible(false); |
182 |
} |
183 |
|
184 |
public void editObject(boolean modal) { |
185 |
// this.modal = modal;
|
186 |
|
187 |
WindowManager wmanager = ToolsSwingLocator.getWindowManager(); |
188 |
|
189 |
wmanager.showWindow(this,title,WindowManager.MODE.DIALOG);
|
190 |
|
191 |
// wmanager.showWindow(this,
|
192 |
// Messages.getText("explorer_parameters"),
|
193 |
// WindowManager.MODE.DIALOG);
|
194 |
} |
195 |
|
196 |
public String getTitle() { |
197 |
return title;
|
198 |
} |
199 |
|
200 |
public void setTitle(String title) { |
201 |
this.title = title;
|
202 |
} |
203 |
|
204 |
public DynObject getParameters() {
|
205 |
this.form.getValues(this.data); |
206 |
return this.data; |
207 |
} |
208 |
} |