svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / gui / layerproperties / LabelScaleRange.java @ 40911
History | View | Annotate | Download (7.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.labeling.gui.layerproperties; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Component; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
import java.util.TreeSet; |
48 |
|
49 |
import javax.swing.ButtonGroup; |
50 |
import javax.swing.JLabel; |
51 |
import javax.swing.JPanel; |
52 |
import javax.swing.JRadioButton; |
53 |
|
54 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
55 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
56 |
import org.gvsig.app.ApplicationLocator; |
57 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
58 |
import org.gvsig.gui.beans.controls.comboscale.ComboScale; |
59 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
60 |
import org.gvsig.gui.beans.swing.JBlank; |
61 |
import org.gvsig.i18n.Messages; |
62 |
|
63 |
/**
|
64 |
* <p>Configuration panel to set the range of scales in which the labels
|
65 |
* will be visible.</p>
|
66 |
*
|
67 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Apr 4, 2008
|
68 |
*
|
69 |
*/
|
70 |
public class LabelScaleRange extends JPanel implements IWindow, ActionListener { |
71 |
|
72 |
private static final long serialVersionUID = -450284029750650479L; |
73 |
private static final long[] defaultScales = new long[] { |
74 |
1000,
|
75 |
2000,
|
76 |
5000,
|
77 |
10000,
|
78 |
50000,
|
79 |
100000,
|
80 |
200000,
|
81 |
500000,
|
82 |
}; |
83 |
private long maxScale, minScale; |
84 |
private ComboScale cmbMaxScale;
|
85 |
private ComboScale cmbMinScale;
|
86 |
private JRadioButton rdBtnUseSameRangeThanLayer; |
87 |
private JRadioButton rdBtnDontShowLabelWhenZoomed; |
88 |
|
89 |
public LabelScaleRange(long minScale, long maxScale) { |
90 |
super();
|
91 |
setLayout(new BorderLayout()); |
92 |
this.maxScale = maxScale;
|
93 |
this.minScale = minScale;
|
94 |
|
95 |
getCmbMinScale().setScale(minScale); |
96 |
getCmbMaxScale().setScale(maxScale); |
97 |
GridBagLayoutPanel p = new GridBagLayoutPanel();
|
98 |
|
99 |
p.addComponent(new JLabel(Messages.getText( |
100 |
"specify_the_range_of_scales_at_which_labels_will_be_shown")+":")); |
101 |
p.addComponent(new JBlank(10, 10)); |
102 |
p.addComponent(getRdUseSameRangeThanLayer()); |
103 |
p.addComponent(new JBlank(10, 10)); |
104 |
p.addComponent(getRdDontShowLabelsWhenZoomed()); |
105 |
p.addComponent(new JBlank(10, 10)); |
106 |
ButtonGroup group = new ButtonGroup(); |
107 |
group.add(getRdUseSameRangeThanLayer()); |
108 |
group.add(getRdDontShowLabelsWhenZoomed()); |
109 |
getRdUseSameRangeThanLayer().addActionListener(this);
|
110 |
getRdDontShowLabelsWhenZoomed().addActionListener(this);
|
111 |
getRdUseSameRangeThanLayer().setSelected(maxScale == -1 && minScale == -1); |
112 |
getRdDontShowLabelsWhenZoomed().setSelected(!getRdUseSameRangeThanLayer().isSelected()); |
113 |
getCmbMinScale().setEnabled(getRdDontShowLabelsWhenZoomed().isSelected()); |
114 |
getCmbMaxScale().setEnabled(getRdDontShowLabelsWhenZoomed().isSelected()); |
115 |
|
116 |
JPanel aux;
|
117 |
JLabel l;
|
118 |
l = new JLabel(" "+Messages.getText("out_beyond")+":", JLabel.RIGHT); |
119 |
aux = new JPanel(); |
120 |
aux.add(getCmbMaxScale()); |
121 |
// aux.add(new JLabel("("+PluginServices.getText(this, "min_scale")+")"));
|
122 |
aux.add(new JLabel("("+Messages.getText("max_scale")+")")); |
123 |
p.addComponent(l, aux); |
124 |
|
125 |
|
126 |
l = new JLabel(" "+Messages.getText("in_beyond")+":", JLabel.RIGHT); |
127 |
aux = new JPanel(); |
128 |
aux.add(getCmbMinScale()); |
129 |
// aux.add(new JLabel("("+PluginServices.getText(this, "max_scale")+")"));
|
130 |
aux.add(new JLabel("("+Messages.getText("min_scale")+")")); |
131 |
p.addComponent(l, aux); |
132 |
|
133 |
|
134 |
add(new JBlank(10, 10), BorderLayout.WEST); |
135 |
add(new JBlank(10, 10), BorderLayout.EAST); |
136 |
add(p, BorderLayout.CENTER);
|
137 |
add(new AcceptCancelPanel(this, this), BorderLayout.SOUTH); |
138 |
} |
139 |
|
140 |
|
141 |
private JRadioButton getRdDontShowLabelsWhenZoomed() { |
142 |
if (rdBtnDontShowLabelWhenZoomed == null) { |
143 |
rdBtnDontShowLabelWhenZoomed = new JRadioButton( |
144 |
Messages.getText("dont_show_labels_when_zoomed"));
|
145 |
} |
146 |
return rdBtnDontShowLabelWhenZoomed;
|
147 |
} |
148 |
|
149 |
private JRadioButton getRdUseSameRangeThanLayer() { |
150 |
if (rdBtnUseSameRangeThanLayer == null) { |
151 |
rdBtnUseSameRangeThanLayer = new JRadioButton( |
152 |
Messages.getText("use_the_same_scale_range_as_the_feature_layer"));
|
153 |
} |
154 |
return rdBtnUseSameRangeThanLayer;
|
155 |
} |
156 |
|
157 |
public long getMaxScale() { |
158 |
return maxScale;
|
159 |
} |
160 |
|
161 |
private ComboScale getCmbMaxScale() {
|
162 |
if (cmbMaxScale == null) { |
163 |
cmbMaxScale = new ComboScale();
|
164 |
TreeSet<Long> ts = new TreeSet<Long>(); |
165 |
if (maxScale!=-1) ts.add(maxScale); |
166 |
for (int i = 0; i < defaultScales.length; i++) { |
167 |
ts.add(defaultScales[i]); |
168 |
} |
169 |
long[] items = new long[ts.size()]; |
170 |
for (int i = 0; i < items.length; i++) { |
171 |
items[i] = ts.first(); |
172 |
ts.remove(ts.first()); |
173 |
} |
174 |
cmbMaxScale.setItems(items); |
175 |
|
176 |
} |
177 |
|
178 |
return cmbMaxScale;
|
179 |
} |
180 |
|
181 |
private ComboScale getCmbMinScale() {
|
182 |
if (cmbMinScale == null) { |
183 |
cmbMinScale = new ComboScale();
|
184 |
TreeSet<Long> ts = new TreeSet<Long>(); |
185 |
if (minScale != -1) ts.add(minScale); |
186 |
for (int i = 0; i < defaultScales.length; i++) { |
187 |
ts.add(defaultScales[i]); |
188 |
} |
189 |
long[] items = new long[ts.size()]; |
190 |
for (int i = 0; i < items.length; i++) { |
191 |
items[i] = ts.first(); |
192 |
ts.remove(ts.first()); |
193 |
} |
194 |
cmbMinScale.setItems(items); |
195 |
} |
196 |
|
197 |
return cmbMinScale;
|
198 |
} |
199 |
|
200 |
|
201 |
public long getMinScale() { |
202 |
return minScale;
|
203 |
} |
204 |
|
205 |
public WindowInfo getWindowInfo() {
|
206 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
207 |
wi.setTitle(Messages.getText("scale_range_window_title"));
|
208 |
wi.setWidth(480);
|
209 |
wi.setHeight(200);
|
210 |
return wi;
|
211 |
} |
212 |
|
213 |
public Object getWindowProfile() { |
214 |
return WindowInfo.DIALOG_PROFILE;
|
215 |
} |
216 |
|
217 |
public void actionPerformed(ActionEvent e) { |
218 |
Component c = (Component) e.getSource(); |
219 |
if (getRdDontShowLabelsWhenZoomed().equals(c) ||
|
220 |
getRdUseSameRangeThanLayer().equals(c)) { |
221 |
getCmbMinScale().setEnabled(getRdDontShowLabelsWhenZoomed().isSelected()); |
222 |
getCmbMaxScale().setEnabled(getRdDontShowLabelsWhenZoomed().isSelected()); |
223 |
|
224 |
} |
225 |
|
226 |
if ("OK".equals(e.getActionCommand())) { |
227 |
maxScale = (getRdUseSameRangeThanLayer().isSelected()) ? |
228 |
-1 : getCmbMaxScale().getScale();
|
229 |
minScale = (getRdUseSameRangeThanLayer().isSelected()) ? |
230 |
-1 : getCmbMinScale().getScale();
|
231 |
|
232 |
|
233 |
ApplicationLocator.getManager().getUIManager().closeWindow(this);
|
234 |
} |
235 |
|
236 |
if ("CANCEL".equals(e.getActionCommand())) { |
237 |
ApplicationLocator.getManager().getUIManager().closeWindow(this);
|
238 |
} |
239 |
} |
240 |
} |