root / trunk / extensions / extAnnotations / src / org / gvsig / tools / annotations / labeling / gui / ConfigLabelingExpression.java @ 24994
History | View | Annotate | Download (6.29 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2008 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Lerida 20
|
35 |
* 46009 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.tools.annotations.labeling.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.GridBagConstraints; |
46 |
import java.awt.GridBagLayout; |
47 |
import java.awt.Insets; |
48 |
import java.util.Iterator; |
49 |
import java.util.WeakHashMap; |
50 |
|
51 |
import javax.swing.BorderFactory; |
52 |
import javax.swing.JLabel; |
53 |
import javax.swing.JPanel; |
54 |
import javax.swing.JScrollPane; |
55 |
import javax.swing.JTextField; |
56 |
|
57 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
58 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
59 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
60 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
61 |
|
62 |
import com.iver.andami.PluginServices; |
63 |
import com.iver.andami.ui.mdiManager.IWindow; |
64 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
68 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
69 |
|
70 |
/**
|
71 |
*
|
72 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es>
|
73 |
*
|
74 |
*/
|
75 |
public class ConfigLabelingExpression extends DefaultButtonsPanel |
76 |
implements IWindow, ButtonsPanelListener {
|
77 |
private WindowInfo wInfo = null; |
78 |
private static final long serialVersionUID = 1L; |
79 |
private BaseView view;
|
80 |
private WeakHashMap<FLyrVect, JTextField> layerMap = new WeakHashMap<FLyrVect, JTextField>(); |
81 |
public static String PROPERTYNAME = "SingleLabeling.LabelingExpression"; |
82 |
private JScrollPane scrollPane; |
83 |
private JPanel scrollContent; |
84 |
|
85 |
|
86 |
public ConfigLabelingExpression(BaseView view) {
|
87 |
super();
|
88 |
this.view = view;
|
89 |
addButtonPressedListener(this);
|
90 |
initialize(); |
91 |
} |
92 |
|
93 |
private void initialize() { |
94 |
getContent().setLayout(new GridBagLayout()); |
95 |
JLabel label = new JLabel("<html><b>"+ |
96 |
PluginServices.getText(this, "Define_the_labeling_expression_") |
97 |
+"</b></html>");
|
98 |
GridBagConstraints constraints = new GridBagConstraints(); |
99 |
constraints.gridy = 0;
|
100 |
constraints.gridx = 0;
|
101 |
constraints.gridwidth = 1;
|
102 |
constraints.anchor = GridBagConstraints.WEST;
|
103 |
constraints.fill = GridBagConstraints.HORIZONTAL;
|
104 |
constraints.insets = new Insets(8,4,4,8); |
105 |
this.getContent().add(label, constraints);
|
106 |
|
107 |
scrollContent = new JPanel(new GridBagLayout()); |
108 |
scrollPane = new JScrollPane(scrollContent); |
109 |
|
110 |
FLayers layers = view.getMapControl().getMapContext().getLayers(); |
111 |
addLayers(layers); |
112 |
|
113 |
constraints.gridy = layerMap.size()+1;
|
114 |
constraints.gridx = 0;
|
115 |
constraints.gridwidth = 2;
|
116 |
constraints.anchor = GridBagConstraints.SOUTH;
|
117 |
constraints.fill = GridBagConstraints.BOTH;
|
118 |
constraints.weightx = 1.0;
|
119 |
constraints.weighty = 1.0;
|
120 |
scrollContent.add(new JPanel(), constraints); // empty panel |
121 |
|
122 |
constraints.gridy = 1;
|
123 |
constraints.gridx = 0;
|
124 |
constraints.gridwidth = 1;
|
125 |
constraints.anchor = GridBagConstraints.CENTER;
|
126 |
constraints.fill = GridBagConstraints.BOTH;
|
127 |
constraints.weightx = 1.0;
|
128 |
constraints.weighty = 1.0;
|
129 |
constraints.insets = new Insets(8,4,4,8); |
130 |
JPanel panel = new JPanel(new BorderLayout()); |
131 |
panel.add(scrollPane, BorderLayout.CENTER);
|
132 |
this.getContent().add(panel, constraints);
|
133 |
|
134 |
} |
135 |
|
136 |
private void addLayers(FLayers layers) { |
137 |
for (int i=layers.getLayersCount()-1; i>=0; i--) { |
138 |
FLayer layer = layers.getLayer(i); |
139 |
if (layer instanceof FLyrVect) { |
140 |
addRow((FLyrVect) layer); |
141 |
} |
142 |
else if (layer instanceof FLayers) { |
143 |
addLayers((FLayers)layer); |
144 |
} |
145 |
} |
146 |
} |
147 |
|
148 |
private void addRow(FLyrVect layer) { |
149 |
JTextField tf = new JTextField(20); |
150 |
layerMap.put(layer, tf); |
151 |
|
152 |
JLabel label = new JLabel("<html><b>"+ |
153 |
PluginServices.getText(this, "Layer_")+"</b>"+ |
154 |
" "+layer.getName()+"</html>"); |
155 |
GridBagConstraints constraints = new GridBagConstraints(); |
156 |
constraints.gridy = layerMap.size(); |
157 |
constraints.gridx = 0;
|
158 |
constraints.anchor = GridBagConstraints.WEST;
|
159 |
constraints.insets = new Insets(8,4,4,8); |
160 |
scrollContent.add(label, constraints); |
161 |
|
162 |
constraints.gridy = layerMap.size(); |
163 |
constraints.gridx = 1;
|
164 |
constraints.anchor = GridBagConstraints.WEST;
|
165 |
Object prop = layer.getProperty(PROPERTYNAME);
|
166 |
if (prop!=null && prop instanceof String) { |
167 |
tf.setText((String)prop);
|
168 |
} |
169 |
else {
|
170 |
tf.setText("");
|
171 |
} |
172 |
scrollContent.add(tf, constraints); |
173 |
} |
174 |
|
175 |
public WindowInfo getWindowInfo() {
|
176 |
if (wInfo==null) { |
177 |
wInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
178 |
wInfo.setWidth(500);
|
179 |
wInfo.setHeight(155);
|
180 |
wInfo.setTitle(PluginServices.getText(this, "Set_labeling_expression")); |
181 |
} |
182 |
return wInfo;
|
183 |
} |
184 |
|
185 |
private boolean apply() { |
186 |
Iterator<FLyrVect> iterator = layerMap.keySet().iterator();
|
187 |
while (iterator.hasNext()) {
|
188 |
FLyrVect layer = iterator.next(); |
189 |
JTextField tf = layerMap.get(layer);
|
190 |
if (tf!=null) { |
191 |
layer.setProperty(PROPERTYNAME, tf.getText()); |
192 |
} |
193 |
} |
194 |
return true; |
195 |
} |
196 |
|
197 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
198 |
switch (e.getButton()) {
|
199 |
case ButtonsPanel.BUTTON_ACCEPT:
|
200 |
if (apply()) {
|
201 |
PluginServices.getMDIManager().closeWindow(this);
|
202 |
} |
203 |
break;
|
204 |
case ButtonsPanel.BUTTON_APPLY:
|
205 |
apply(); |
206 |
break;
|
207 |
case ButtonsPanel.BUTTON_CANCEL:
|
208 |
PluginServices.getMDIManager().closeWindow(this);
|
209 |
break;
|
210 |
} |
211 |
|
212 |
} |
213 |
|
214 |
public Object getWindowProfile() { |
215 |
return WindowInfo.DIALOG_PROFILE;
|
216 |
} |
217 |
|
218 |
} |