svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toc / gui / ChangeName.java @ 40558
History | View | Annotate | Download (6.13 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | package org.gvsig.app.project.documents.view.toc.gui; |
||
25 | |||
26 | import java.awt.Dimension; |
||
27 | import java.awt.GridBagConstraints; |
||
28 | import java.awt.GridBagLayout; |
||
29 | import java.awt.Insets; |
||
30 | import java.awt.event.ActionListener; |
||
31 | import java.awt.event.KeyEvent; |
||
32 | import java.awt.event.KeyListener; |
||
33 | |||
34 | import javax.swing.BorderFactory; |
||
35 | import javax.swing.JLabel; |
||
36 | import javax.swing.JPanel; |
||
37 | import javax.swing.JTextField; |
||
38 | |||
39 | import org.gvsig.andami.PluginServices; |
||
40 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
41 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
42 | import org.gvsig.gui.beans.AcceptCancelPanel; |
||
43 | import org.gvsig.i18n.Messages; |
||
44 | |||
45 | /**
|
||
46 | * Di?logo para cambiar el nombre de una capa.
|
||
47 | *
|
||
48 | * @author Vicente Caballero Navarro
|
||
49 | * @author gvSIG Team
|
||
50 | */
|
||
51 | public class ChangeName extends JPanel implements IWindow { |
||
52 | |||
53 | private static final long serialVersionUID = -1366865045507066336L; |
||
54 | private JLabel lblName = null; |
||
55 | private JTextField txtName = null; |
||
56 | private String name; |
||
57 | private AcceptCancelPanel jPanelAcceptCancel = null; |
||
58 | private boolean isAccepted = false; |
||
59 | |||
60 | /**
|
||
61 | * This is the default constructor
|
||
62 | *
|
||
63 | * @param layout
|
||
64 | * Referencia al Layout.
|
||
65 | * @param fframe
|
||
66 | * Referencia al fframe de imagen.
|
||
67 | */
|
||
68 | public ChangeName(String n) { |
||
69 | super();
|
||
70 | if (n == null) { |
||
71 | name = PluginServices.getText(this, "agrupacion"); |
||
72 | } else {
|
||
73 | name = n; |
||
74 | } |
||
75 | initialize(); |
||
76 | } |
||
77 | |||
78 | /**
|
||
79 | * This method initializes this
|
||
80 | */
|
||
81 | private void initialize() { |
||
82 | setLayout(new GridBagLayout()); |
||
83 | setBorder(BorderFactory.createEmptyBorder(4, 5, 4, 5)); |
||
84 | |||
85 | GridBagConstraints c = new GridBagConstraints(); |
||
86 | c.insets = new Insets(2, 5, 2, 5); |
||
87 | c.gridy = -1;
|
||
88 | |||
89 | c.anchor = GridBagConstraints.WEST;
|
||
90 | c.weightx = 0.0d;
|
||
91 | c.gridx = 0;
|
||
92 | c.gridy++; |
||
93 | add(getLblName(), c); |
||
94 | |||
95 | c.fill = GridBagConstraints.HORIZONTAL;
|
||
96 | c.weightx = 1.0d;
|
||
97 | c.gridx = 1;
|
||
98 | add(getTxtName(), c); |
||
99 | |||
100 | c.anchor = GridBagConstraints.EAST;
|
||
101 | c.gridx = 0;
|
||
102 | c.gridwidth = 2;
|
||
103 | c.gridy++; |
||
104 | c.weightx = 1.0d;
|
||
105 | add(getJPanelAcceptCancel(), c); |
||
106 | } |
||
107 | |||
108 | /**
|
||
109 | * This method initializes lFichero
|
||
110 | *
|
||
111 | * @return javax.swing.JLabel
|
||
112 | */
|
||
113 | private JLabel getLblName() { |
||
114 | if (lblName == null) { |
||
115 | lblName = new JLabel(Messages.getText("nombre")); |
||
116 | } |
||
117 | |||
118 | return lblName;
|
||
119 | } |
||
120 | |||
121 | /**
|
||
122 | * This method initializes tFichero
|
||
123 | *
|
||
124 | * @return javax.swing.JTextField
|
||
125 | */
|
||
126 | private JTextField getTxtName() { |
||
127 | if (txtName == null) { |
||
128 | txtName = new JTextField(name, 20); |
||
129 | txtName.addKeyListener(new KeyListener() { |
||
130 | |||
131 | public void keyPressed(KeyEvent e) { |
||
132 | if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
||
133 | acceptAction(); |
||
134 | } else
|
||
135 | if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { |
||
136 | cancelAction(); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | public void keyReleased(KeyEvent e) { |
||
141 | // Nothing to do
|
||
142 | } |
||
143 | |||
144 | public void keyTyped(KeyEvent e) { |
||
145 | // Nothing to do
|
||
146 | } |
||
147 | |||
148 | }); |
||
149 | } |
||
150 | return txtName;
|
||
151 | } |
||
152 | |||
153 | /**
|
||
154 | * Inserta el path al TFichero.
|
||
155 | *
|
||
156 | * @param val
|
||
157 | * path del fichero.
|
||
158 | */
|
||
159 | public void setText(String val) { |
||
160 | getTxtName().setText(val); |
||
161 | } |
||
162 | |||
163 | public WindowInfo getWindowInfo() {
|
||
164 | WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
||
165 | m_viewinfo.setTitle(Messages.getText("cambio_nombre"));
|
||
166 | Dimension dim = getPreferredSize();
|
||
167 | m_viewinfo.setWidth(dim.width); |
||
168 | m_viewinfo.setHeight(dim.height); |
||
169 | return m_viewinfo;
|
||
170 | } |
||
171 | |||
172 | public String getName() { |
||
173 | return name;
|
||
174 | } |
||
175 | |||
176 | /**
|
||
177 | * This method initializes jPanel1
|
||
178 | *
|
||
179 | * @return javax.swing.JPanel
|
||
180 | */
|
||
181 | private AcceptCancelPanel getJPanelAcceptCancel() {
|
||
182 | if (jPanelAcceptCancel == null) { |
||
183 | ActionListener okActionListener, cancelActionListener;
|
||
184 | okActionListener = new java.awt.event.ActionListener() {
|
||
185 | |||
186 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
187 | acceptAction(); |
||
188 | } |
||
189 | }; |
||
190 | cancelActionListener = new java.awt.event.ActionListener() {
|
||
191 | |||
192 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
193 | cancelAction(); |
||
194 | } |
||
195 | }; |
||
196 | jPanelAcceptCancel = |
||
197 | new AcceptCancelPanel(okActionListener, cancelActionListener);
|
||
198 | } |
||
199 | return jPanelAcceptCancel;
|
||
200 | } |
||
201 | |||
202 | public boolean isAccepted() { |
||
203 | return isAccepted;
|
||
204 | } |
||
205 | |||
206 | protected void acceptAction() { |
||
207 | name = getTxtName().getText(); |
||
208 | isAccepted = true;
|
||
209 | PluginServices.getMDIManager().closeWindow(ChangeName.this); |
||
210 | |||
211 | } |
||
212 | |||
213 | protected void cancelAction() { |
||
214 | isAccepted = false;
|
||
215 | PluginServices.getMDIManager().closeWindow(ChangeName.this); |
||
216 | |||
217 | } |
||
218 | |||
219 | public Object getWindowProfile() { |
||
220 | return WindowInfo.DIALOG_PROFILE;
|
||
221 | } |
||
222 | |||
223 | } |