svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / layerproperties / PlacementProperties.java @ 24166
History | View | Annotate | Download (29.6 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 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: PlacementProperties.java 15674 2007-10-30 16:39:02Z jdominguez $
|
45 |
* $Log$
|
46 |
* Revision 1.7 2007-04-19 14:22:29 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.6 2007/04/13 12:43:08 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.5 2007/04/13 12:10:56 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.4 2007/04/12 16:01:32 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.3 2007/03/28 15:38:56 jaume
|
59 |
* GUI for lines, points and polygons
|
60 |
*
|
61 |
* Revision 1.2 2007/03/09 11:25:00 jaume
|
62 |
* Advanced symbology (start committing)
|
63 |
*
|
64 |
* Revision 1.1.2.2 2007/02/09 11:00:03 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1.2.1 2007/02/01 12:12:41 jaume
|
68 |
* theme manager window and all its components are now dynamic
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
package org.gvsig.symbology.gui.layerproperties; |
73 |
|
74 |
import java.awt.BorderLayout; |
75 |
import java.awt.Color; |
76 |
import java.awt.Component; |
77 |
import java.awt.Dimension; |
78 |
import java.awt.FlowLayout; |
79 |
import java.awt.Font; |
80 |
import java.awt.FontMetrics; |
81 |
import java.awt.Graphics; |
82 |
import java.awt.Graphics2D; |
83 |
import java.awt.GridLayout; |
84 |
import java.awt.Rectangle; |
85 |
import java.awt.event.ActionEvent; |
86 |
import java.awt.event.ActionListener; |
87 |
import java.awt.geom.Rectangle2D; |
88 |
import java.awt.image.BufferedImage; |
89 |
import java.io.File; |
90 |
import java.util.ArrayList; |
91 |
|
92 |
import javax.swing.BorderFactory; |
93 |
import javax.swing.BoxLayout; |
94 |
import javax.swing.ButtonGroup; |
95 |
import javax.swing.JCheckBox; |
96 |
import javax.swing.JComponent; |
97 |
import javax.swing.JLabel; |
98 |
import javax.swing.JPanel; |
99 |
import javax.swing.JRadioButton; |
100 |
|
101 |
import org.cresques.cts.IProjection; |
102 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
103 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
104 |
import org.gvsig.gui.beans.swing.JBlank; |
105 |
import org.gvsig.gui.beans.swing.JButton; |
106 |
import org.gvsig.symbology.fmap.labeling.GeneralLabelingStrategy; |
107 |
import org.gvsig.symbology.fmap.labeling.PlacementManager; |
108 |
import org.gvsig.symbology.fmap.labeling.parse.LabelExpressionParser; |
109 |
import org.gvsig.symbology.fmap.labeling.placements.MultiShapePlacementConstraints; |
110 |
import org.gvsig.symbology.fmap.labeling.placements.PointPlacementConstraints; |
111 |
import org.gvsig.symbology.fmap.styles.PointLabelPositioneer; |
112 |
|
113 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
114 |
import com.iver.andami.PluginServices; |
115 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
116 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
117 |
import com.iver.cit.gvsig.fmap.MapContext; |
118 |
import com.iver.cit.gvsig.fmap.ViewPort; |
119 |
import com.iver.cit.gvsig.fmap.core.FShape; |
120 |
import com.iver.cit.gvsig.fmap.core.styles.ArrowDecoratorStyle; |
121 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
122 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
123 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
124 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
125 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
126 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
127 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
128 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
129 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.DefaultLabelingMethod; |
130 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IPlacementConstraints; |
131 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
132 |
import com.iver.cit.gvsig.gui.styling.AbstractStyleSelectorFilter; |
133 |
import com.iver.cit.gvsig.gui.styling.StylePreviewer; |
134 |
import com.iver.cit.gvsig.gui.styling.StyleSelector; |
135 |
import com.iver.utiles.swing.JComboBox; |
136 |
/**
|
137 |
*
|
138 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
139 |
*
|
140 |
*/
|
141 |
public class PlacementProperties extends JPanel implements IPlacementProperties, ActionListener { |
142 |
private static final long serialVersionUID = 1022470370547576765L; |
143 |
private PointLabelPositioneer pointStyle = new PointLabelPositioneer( |
144 |
new byte[] { 2, 2, 1, 3, 2, 3, 3, 2 }, |
145 |
PluginServices.getText(this, "prefer_top_right_all_allowed") |
146 |
); |
147 |
private int shapeType; |
148 |
private JPanel pnlContent = null; |
149 |
private JPanel pnlCenter = null; |
150 |
IPlacementConstraints constraints; |
151 |
private GridBagLayoutPanel orientationPanel;
|
152 |
private DuplicateLayersMode duplicateLabelsMode;
|
153 |
private JRadioButton rdBtnHorizontal; |
154 |
private JRadioButton rdBtnParallel; |
155 |
private JRadioButton rdBtnFollowingLine; |
156 |
private JRadioButton rdBtnPerpendicular; |
157 |
private JPanel positionPanel; |
158 |
private MiniMapContext preview;
|
159 |
private ArrayList<String> linePositionItem = new ArrayList<String>(); |
160 |
|
161 |
private JPanel polygonSettingsPanel; |
162 |
private JRadioButton rdBtnAlwaysHorizontal; |
163 |
private JRadioButton rdBtnAlwaysStraight; |
164 |
private GridBagLayoutPanel pointSettingsPanel;
|
165 |
private JRadioButton rdBtnOffsetLabelHorizontally; |
166 |
private JRadioButton rdBtnOffsetLabelOnTopPoint; |
167 |
private StylePreviewer stylePreview;
|
168 |
private JButton btnChangeLocation; |
169 |
private JPanel locationPanel; |
170 |
private JComboBox cmbLocationAlongLines; |
171 |
private JRadioButton chkBellow; |
172 |
private JRadioButton chkOnTheLine; |
173 |
private JRadioButton chkAbove; |
174 |
private JComboBox cmbOrientationSystem; |
175 |
private JLabelHTML lblPointPosDesc = new JLabelHTML(pointStyle.getDescription()); |
176 |
IPlacementConstraints oldConstraints; |
177 |
private JCheckBox chkFitInsidePolygon; |
178 |
private boolean fireEvent = false; |
179 |
|
180 |
|
181 |
/**
|
182 |
* Constructs a new panel for PlacementProperties.
|
183 |
*
|
184 |
* @param constraints, if not null this parameters is used to fill the panel. If it is null
|
185 |
* this PlacementProperties constructor creates a new default one that is ready to be used
|
186 |
* for the shapetype passed as second parameter
|
187 |
*
|
188 |
* @param shapeType, defines the target shapetype of the IPlacementConstraints obtained;
|
189 |
* @throws ReadDriverException
|
190 |
*/
|
191 |
public PlacementProperties(IPlacementConstraints constraints, int shapeType) throws ReadDriverException { |
192 |
initialize(constraints, shapeType, getPnlDuplicateLabels()); |
193 |
} |
194 |
|
195 |
PlacementProperties(IPlacementConstraints costraints, |
196 |
int shapeType, DuplicateLayersMode duplicatesMode) {
|
197 |
|
198 |
initialize( costraints, shapeType, duplicatesMode); |
199 |
refreshComponents(); |
200 |
} |
201 |
|
202 |
private void refreshComponents() { |
203 |
fireEvent = false;
|
204 |
getChkOnTheLine().setSelected(constraints.isOnTheLine()); |
205 |
getChkAbove().setSelected(constraints.isAboveTheLine()); |
206 |
getChkBelow().setSelected(constraints.isBelowTheLine()); |
207 |
|
208 |
getRdBtnHorizontal().setSelected(constraints.isHorizontal()); |
209 |
getRdBtnParallel().setSelected(constraints.isParallel()); |
210 |
getRdBtnFollowingLine().setSelected(constraints.isFollowingLine()); |
211 |
getRdBtnPerpendicular().setSelected(constraints.isPerpendicular()); |
212 |
|
213 |
getCmbOrientationSystem().setSelectedIndex(constraints.isPageOriented() ? 1 : 0); |
214 |
|
215 |
// points mode
|
216 |
if (constraints.isOnTopOfThePoint()) {
|
217 |
getRdOffsetLabelOnTopPoint().setSelected(true);
|
218 |
} else if (constraints.isAroundThePoint()) { |
219 |
getRdOffsetLabelHorizontally().setSelected(true);
|
220 |
} |
221 |
|
222 |
// lines mode
|
223 |
if (constraints.isAtTheBeginingOfLine()) {
|
224 |
getCmbLocationAlongLines().setSelectedIndex(1);
|
225 |
} else if (constraints.isInTheMiddleOfLine()) { |
226 |
getCmbLocationAlongLines().setSelectedIndex(0);
|
227 |
} else if (constraints.isAtTheEndOfLine()) { |
228 |
getCmbLocationAlongLines().setSelectedIndex(2);
|
229 |
} else if (constraints.isAtBestOfLine()) { |
230 |
getCmbLocationAlongLines().setSelectedIndex(3);
|
231 |
} |
232 |
|
233 |
// polygon mode
|
234 |
getChkFitInsidePolygon().setSelected(constraints.isFitInsidePolygon()); |
235 |
if (constraints.isHorizontal()) {
|
236 |
getRdBtnAlwaysHorizontal().setSelected(true);
|
237 |
} else if (constraints.isParallel()) { |
238 |
getRdBtnAlwaysStraight().setSelected(true);
|
239 |
} |
240 |
|
241 |
if(constraints.isFollowingLine()){
|
242 |
setComponentEnabled(getPositionPanel(), false);
|
243 |
} |
244 |
|
245 |
|
246 |
// duplicates mode
|
247 |
int dupMode = constraints.getDuplicateLabelsMode();
|
248 |
duplicateLabelsMode.setMode(dupMode); |
249 |
fireEvent = true;
|
250 |
changeIcon(); |
251 |
} |
252 |
|
253 |
private void initialize(IPlacementConstraints constraints, int shapeType, DuplicateLayersMode duplicatesMode) { |
254 |
|
255 |
this.duplicateLabelsMode = duplicatesMode;
|
256 |
this.shapeType = shapeType;
|
257 |
this.oldConstraints = constraints;
|
258 |
this.constraints = constraints != null ? |
259 |
PlacementManager.createPlacementConstraints(constraints.getXMLEntity()) : |
260 |
PlacementManager.createPlacementConstraints(shapeType); |
261 |
|
262 |
linePositionItem.add(PluginServices.getText(this, "in_the_middle")); |
263 |
linePositionItem.add(PluginServices.getText(this, "at_begin")); |
264 |
linePositionItem.add(PluginServices.getText(this, "at_end")); |
265 |
linePositionItem.add(PluginServices.getText(this, "at_best")); |
266 |
|
267 |
this.setLayout(new BorderLayout()); |
268 |
this.setSize(new Dimension(410,380)); |
269 |
this.add(getPnlContent(), BorderLayout.CENTER); |
270 |
} |
271 |
|
272 |
public WindowInfo getWindowInfo() {
|
273 |
WindowInfo viewInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
274 |
viewInfo.setWidth(getWidth()); |
275 |
viewInfo.setHeight(getHeight()); |
276 |
viewInfo.setTitle(PluginServices.getText(this,"placement_properties")); |
277 |
return viewInfo;
|
278 |
} |
279 |
|
280 |
private JPanel getPnlContent() { |
281 |
if (pnlContent == null) { |
282 |
pnlContent = new JPanel(); |
283 |
pnlContent.setLayout(new BorderLayout()); |
284 |
pnlContent.add(getPnlCenter(), java.awt.BorderLayout.CENTER); |
285 |
pnlContent.add(getPnlDuplicateLabels(), java.awt.BorderLayout.SOUTH); |
286 |
} |
287 |
return pnlContent;
|
288 |
} |
289 |
|
290 |
private DuplicateLayersMode getPnlDuplicateLabels() {
|
291 |
if (duplicateLabelsMode == null) { |
292 |
duplicateLabelsMode = new DuplicateLayersMode();
|
293 |
|
294 |
} |
295 |
|
296 |
return duplicateLabelsMode;
|
297 |
} |
298 |
|
299 |
private JPanel getPnlCenter() { |
300 |
if (pnlCenter == null) { |
301 |
pnlCenter = new JPanel(); |
302 |
switch (shapeType) {
|
303 |
case FShape.POINT:
|
304 |
case FShape.MULTIPOINT: // TODO (09/01/08) is this correct?? if not fix it also in PlacementManager, MarkerPlacementAroundPoint |
305 |
pnlCenter.setBorder(BorderFactory.
|
306 |
createTitledBorder(null,
|
307 |
PluginServices.getText(this, "point_settings"))); |
308 |
pnlCenter.add(getPointSettingsPanel()); |
309 |
break;
|
310 |
case FShape.LINE:
|
311 |
pnlCenter.setLayout(new BorderLayout()); |
312 |
pnlCenter.setBorder(BorderFactory.
|
313 |
createTitledBorder(null,
|
314 |
PluginServices.getText(this, "line_settings"))); |
315 |
JPanel aux = new JPanel( |
316 |
new GridLayout(1, 2)); |
317 |
aux.add(getOrientationPanel()); |
318 |
aux.add(getPositionPanel()); |
319 |
pnlCenter.add(aux, BorderLayout.CENTER);
|
320 |
pnlCenter.add(getLocationPanel(), BorderLayout.SOUTH);
|
321 |
|
322 |
break;
|
323 |
|
324 |
case FShape.POLYGON:
|
325 |
pnlCenter.setLayout(new BorderLayout()); |
326 |
pnlCenter.setBorder(BorderFactory.
|
327 |
createTitledBorder(null,
|
328 |
PluginServices.getText(this, "polygon_settings"))); |
329 |
pnlCenter.add(getPolygonSettingsPanel(), BorderLayout.CENTER);
|
330 |
break;
|
331 |
|
332 |
default:
|
333 |
break;
|
334 |
} |
335 |
} |
336 |
return pnlCenter;
|
337 |
} |
338 |
|
339 |
private JPanel getLocationPanel() { |
340 |
if (locationPanel == null) { |
341 |
locationPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
342 |
locationPanel.setBorder(BorderFactory.
|
343 |
createTitledBorder(null,
|
344 |
PluginServices.getText(this, "location"))); |
345 |
locationPanel.add(new JLabel(PluginServices.getText(this, "location_along_the_lines")+":")); |
346 |
locationPanel.add(getCmbLocationAlongLines()); |
347 |
} |
348 |
|
349 |
return locationPanel;
|
350 |
} |
351 |
|
352 |
private JComboBox getCmbLocationAlongLines() { |
353 |
if (cmbLocationAlongLines == null) { |
354 |
cmbLocationAlongLines = new JComboBox((String[]) linePositionItem.toArray(new String[linePositionItem.size()])); |
355 |
cmbLocationAlongLines.addActionListener(this);
|
356 |
} |
357 |
|
358 |
return cmbLocationAlongLines;
|
359 |
} |
360 |
|
361 |
private GridBagLayoutPanel getPointSettingsPanel() {
|
362 |
if (pointSettingsPanel == null) { |
363 |
pointSettingsPanel = new GridBagLayoutPanel();
|
364 |
pointSettingsPanel.addComponent(getRdOffsetLabelHorizontally()); |
365 |
JPanel aux = new JPanel(); |
366 |
aux.add(getStylePreviewer()); |
367 |
|
368 |
JPanel aux2 = new JPanel(); |
369 |
aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS)); |
370 |
aux2.add(lblPointPosDesc); |
371 |
aux2.add(new JBlank(20, 5)); |
372 |
aux2.add(getBtnChangeLocation()); |
373 |
|
374 |
aux.add(aux2); |
375 |
pointSettingsPanel.addComponent("", aux);
|
376 |
pointSettingsPanel.addComponent("",
|
377 |
new JLabel(PluginServices.getText(this, "label-point-priority-help"))); |
378 |
pointSettingsPanel.addComponent(getRdOffsetLabelOnTopPoint()); |
379 |
ButtonGroup group = new ButtonGroup(); |
380 |
group.add(getRdOffsetLabelHorizontally()); |
381 |
group.add(getRdOffsetLabelOnTopPoint()); |
382 |
} |
383 |
|
384 |
return pointSettingsPanel;
|
385 |
} |
386 |
|
387 |
|
388 |
|
389 |
private JButton getBtnChangeLocation() { |
390 |
if (btnChangeLocation == null) { |
391 |
btnChangeLocation = new JButton(PluginServices.getText(this, "change_location")); |
392 |
btnChangeLocation.addActionListener(this);
|
393 |
} |
394 |
|
395 |
return btnChangeLocation;
|
396 |
} |
397 |
|
398 |
private StylePreviewer getStylePreviewer() {
|
399 |
if (stylePreview == null) { |
400 |
stylePreview = new StylePreviewer();
|
401 |
stylePreview.setStyle(pointStyle); |
402 |
stylePreview.setPreferredSize(new Dimension(80, 80)); |
403 |
} |
404 |
return stylePreview;
|
405 |
} |
406 |
|
407 |
private JRadioButton getRdOffsetLabelOnTopPoint() { |
408 |
if (rdBtnOffsetLabelOnTopPoint == null) { |
409 |
rdBtnOffsetLabelOnTopPoint = new JRadioButton( |
410 |
PluginServices.getText(this, "offset_labels_on_top_of_the_points")) ; |
411 |
|
412 |
} |
413 |
|
414 |
return rdBtnOffsetLabelOnTopPoint;
|
415 |
} |
416 |
|
417 |
private JRadioButton getRdOffsetLabelHorizontally() { |
418 |
if (rdBtnOffsetLabelHorizontally == null) { |
419 |
rdBtnOffsetLabelHorizontally = new JRadioButton( |
420 |
PluginServices.getText(this, "offset_labels_horizontally")); |
421 |
|
422 |
} |
423 |
|
424 |
return rdBtnOffsetLabelHorizontally;
|
425 |
} |
426 |
|
427 |
private JPanel getPolygonSettingsPanel() { |
428 |
if (polygonSettingsPanel == null) { |
429 |
polygonSettingsPanel = new JPanel(new BorderLayout(10, 10)); |
430 |
JPanel aux = new JPanel(); |
431 |
aux.setLayout(new BoxLayout(aux, BoxLayout.Y_AXIS)); |
432 |
aux.add(new JBlank(10,10)); |
433 |
aux.add(getRdBtnAlwaysHorizontal()); |
434 |
aux.add(new JBlank(10,10)); |
435 |
aux.add(getRdBtnAlwaysStraight()); |
436 |
aux.add(new JBlank(10,50)); |
437 |
|
438 |
polygonSettingsPanel.add(getPreview(), BorderLayout.CENTER);
|
439 |
polygonSettingsPanel.add(aux, BorderLayout.EAST);
|
440 |
ButtonGroup group = new ButtonGroup(); |
441 |
group.add(getRdBtnAlwaysHorizontal()); |
442 |
group.add(getRdBtnAlwaysStraight()); |
443 |
polygonSettingsPanel.add(getChkFitInsidePolygon(), BorderLayout.SOUTH);
|
444 |
} |
445 |
|
446 |
return polygonSettingsPanel;
|
447 |
} |
448 |
|
449 |
private JCheckBox getChkFitInsidePolygon() { |
450 |
if (chkFitInsidePolygon == null) { |
451 |
chkFitInsidePolygon = new JCheckBox(PluginServices.getText(this, "fit_inside_polygon")); |
452 |
|
453 |
} |
454 |
|
455 |
return chkFitInsidePolygon;
|
456 |
} |
457 |
|
458 |
private JRadioButton getRdBtnAlwaysStraight() { |
459 |
if (rdBtnAlwaysStraight == null) { |
460 |
rdBtnAlwaysStraight = new JRadioButton( |
461 |
PluginServices.getText(this, "always_straight")); |
462 |
rdBtnAlwaysStraight.addActionListener(this);
|
463 |
} |
464 |
|
465 |
return rdBtnAlwaysStraight;
|
466 |
} |
467 |
|
468 |
private JRadioButton getRdBtnAlwaysHorizontal() { |
469 |
if (rdBtnAlwaysHorizontal == null) { |
470 |
rdBtnAlwaysHorizontal = new JRadioButton( |
471 |
PluginServices.getText(this, "always_horizontal")); |
472 |
rdBtnAlwaysHorizontal.addActionListener(this);
|
473 |
} |
474 |
|
475 |
return rdBtnAlwaysHorizontal;
|
476 |
} |
477 |
|
478 |
|
479 |
|
480 |
private JPanel getPositionPanel() { |
481 |
if (positionPanel == null) { |
482 |
positionPanel = new JPanel(new BorderLayout()); |
483 |
positionPanel.setBorder(BorderFactory.
|
484 |
createTitledBorder(null,
|
485 |
PluginServices.getText(this, "position"))); |
486 |
GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
|
487 |
JPanel aux = new JPanel(new GridLayout(4, 1)); |
488 |
|
489 |
aux.add(getChkAbove()); |
490 |
getChkAbove().setSelected(true);
|
491 |
aux.add(getChkOnTheLine()); |
492 |
aux.add(getChkBelow()); |
493 |
|
494 |
ButtonGroup group = new ButtonGroup(); |
495 |
group.add(getChkAbove()); |
496 |
group.add(getChkOnTheLine()); |
497 |
group.add(getChkBelow()); |
498 |
|
499 |
aux2.addComponent(aux); |
500 |
aux2.addComponent( |
501 |
PluginServices.getText(this, "orientation_system"), getCmbOrientationSystem()); |
502 |
positionPanel.add(getPreview(), BorderLayout.CENTER);
|
503 |
positionPanel.add(aux2, BorderLayout.SOUTH);
|
504 |
} |
505 |
return positionPanel;
|
506 |
} |
507 |
|
508 |
private Component getPreview() { |
509 |
if (preview == null) { |
510 |
preview = new MiniMapContext(shapeType);
|
511 |
} |
512 |
return preview;
|
513 |
} |
514 |
|
515 |
private JComboBox getCmbOrientationSystem() { |
516 |
if (cmbOrientationSystem == null) { |
517 |
cmbOrientationSystem = new JComboBox(new String[] { |
518 |
PluginServices.getText(this, "line"), |
519 |
PluginServices.getText(this, "page") |
520 |
}); |
521 |
cmbOrientationSystem.setSelectedIndex(0);
|
522 |
cmbOrientationSystem.addActionListener(this);
|
523 |
} |
524 |
|
525 |
return cmbOrientationSystem;
|
526 |
} |
527 |
|
528 |
private JRadioButton getChkBelow() { |
529 |
if (chkBellow == null) { |
530 |
chkBellow = new JRadioButton(PluginServices.getText(this, "below")); |
531 |
chkBellow.addActionListener(this);
|
532 |
} |
533 |
return chkBellow;
|
534 |
} |
535 |
|
536 |
private JRadioButton getChkOnTheLine() { |
537 |
if (chkOnTheLine == null) { |
538 |
chkOnTheLine = new JRadioButton(PluginServices.getText(this, "on_the_line")); |
539 |
chkOnTheLine.addActionListener(this);
|
540 |
} |
541 |
return chkOnTheLine;
|
542 |
} |
543 |
|
544 |
private JRadioButton getChkAbove() { |
545 |
if (chkAbove == null) { |
546 |
chkAbove = new JRadioButton(PluginServices.getText(this, "above")); |
547 |
chkAbove.addActionListener(this);
|
548 |
} |
549 |
return chkAbove;
|
550 |
} |
551 |
|
552 |
private GridBagLayoutPanel getOrientationPanel() {
|
553 |
if (orientationPanel == null) { |
554 |
orientationPanel = new GridBagLayoutPanel();
|
555 |
orientationPanel.setBorder(BorderFactory.
|
556 |
createTitledBorder(null,
|
557 |
PluginServices.getText(this, "orientation"))); |
558 |
orientationPanel.addComponent(getRdBtnHorizontal()); |
559 |
orientationPanel.addComponent(getRdBtnParallel()); |
560 |
orientationPanel.addComponent(getRdBtnFollowingLine()); |
561 |
orientationPanel.addComponent(getRdBtnPerpendicular()); |
562 |
ButtonGroup group = new ButtonGroup(); |
563 |
group.add(getRdBtnHorizontal()); |
564 |
group.add(getRdBtnParallel()); |
565 |
group.add(getRdBtnFollowingLine()); |
566 |
group.add(getRdBtnPerpendicular()); |
567 |
|
568 |
|
569 |
|
570 |
} |
571 |
return orientationPanel;
|
572 |
} |
573 |
|
574 |
private JRadioButton getRdBtnParallel() { |
575 |
if (rdBtnParallel == null) { |
576 |
rdBtnParallel = new JRadioButton( |
577 |
PluginServices.getText(this, "parallel")); |
578 |
|
579 |
rdBtnParallel.addActionListener(this);
|
580 |
} |
581 |
return rdBtnParallel;
|
582 |
} |
583 |
|
584 |
private JRadioButton getRdBtnFollowingLine() { |
585 |
if (rdBtnFollowingLine == null) { |
586 |
rdBtnFollowingLine = new JRadioButton( |
587 |
PluginServices.getText(this, "following_line")); |
588 |
rdBtnFollowingLine.addActionListener(this);
|
589 |
} |
590 |
return rdBtnFollowingLine;
|
591 |
} |
592 |
|
593 |
private JRadioButton getRdBtnPerpendicular() { |
594 |
if (rdBtnPerpendicular == null) { |
595 |
rdBtnPerpendicular = new JRadioButton( |
596 |
PluginServices.getText(this, "perpedicular")); |
597 |
rdBtnPerpendicular.addActionListener(this);
|
598 |
} |
599 |
return rdBtnPerpendicular;
|
600 |
} |
601 |
|
602 |
private JRadioButton getRdBtnHorizontal() { |
603 |
if (rdBtnHorizontal == null) { |
604 |
rdBtnHorizontal = new JRadioButton( |
605 |
PluginServices.getText(this, "horizontal")); |
606 |
rdBtnHorizontal.addActionListener(this);
|
607 |
} |
608 |
return rdBtnHorizontal;
|
609 |
} |
610 |
|
611 |
|
612 |
|
613 |
|
614 |
void applyConstraints() {
|
615 |
int mode=0; |
616 |
|
617 |
switch (shapeType) {
|
618 |
case FShape.POINT:
|
619 |
case FShape.MULTIPOINT: // TODO (09/01/08) is this correct? if not fix it also in PlacementManager, MarkerPlacementAroundPoint |
620 |
if (getRdOffsetLabelOnTopPoint().isSelected()) {
|
621 |
mode = IPlacementConstraints.ON_TOP_OF_THE_POINT; |
622 |
} else if (getRdOffsetLabelHorizontally().isSelected()) { |
623 |
mode = IPlacementConstraints.OFFSET_HORIZONTALY_AROUND_THE_POINT; |
624 |
} |
625 |
((PointPlacementConstraints) constraints). |
626 |
setPositioneer((PointLabelPositioneer) stylePreview.getStyle()); |
627 |
break;
|
628 |
case FShape.LINE:
|
629 |
if (getRdBtnFollowingLine().isSelected()) {
|
630 |
mode = IPlacementConstraints.FOLLOWING_LINE; |
631 |
} else if (getRdBtnParallel().isSelected()) { |
632 |
mode = IPlacementConstraints.PARALLEL; |
633 |
} else if (getRdBtnPerpendicular().isSelected()) { |
634 |
mode = IPlacementConstraints.PERPENDICULAR; |
635 |
} else {
|
636 |
mode = IPlacementConstraints.HORIZONTAL; |
637 |
} |
638 |
|
639 |
constraints.setAboveTheLine(getChkAbove().isSelected()); |
640 |
constraints.setBelowTheLine(getChkBelow().isSelected()); |
641 |
constraints.setOnTheLine(getChkOnTheLine().isSelected()); |
642 |
|
643 |
constraints.setPageOriented( |
644 |
getCmbOrientationSystem().getSelectedIndex() == 1);
|
645 |
int i = getCmbLocationAlongLines().getSelectedIndex();
|
646 |
if (i == 0) { |
647 |
i = IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE; |
648 |
} else if (i == 1) { |
649 |
i = IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE; |
650 |
} else if (i == 2) { |
651 |
i = IPlacementConstraints.AT_THE_END_OF_THE_LINE; |
652 |
} else if (i == 3) { |
653 |
i = IPlacementConstraints.AT_BEST_OF_LINE; |
654 |
} |
655 |
constraints.setLocationAlongTheLine(i); |
656 |
break;
|
657 |
case FShape.POLYGON:
|
658 |
mode = IPlacementConstraints.HORIZONTAL; |
659 |
if (getRdBtnAlwaysHorizontal().isSelected()) {
|
660 |
mode = IPlacementConstraints.HORIZONTAL; |
661 |
} else if (getRdBtnAlwaysStraight().isSelected()) { |
662 |
mode = IPlacementConstraints.PARALLEL; |
663 |
} |
664 |
|
665 |
constraints.setFitInsidePolygon(getChkFitInsidePolygon().isSelected()); |
666 |
break;
|
667 |
} |
668 |
constraints.setPlacementMode(mode); |
669 |
|
670 |
constraints.setDuplicateLabelsMode(duplicateLabelsMode.getMode()); |
671 |
} |
672 |
|
673 |
private void setComponentEnabled(Component c, boolean b) { |
674 |
if (c instanceof JComponent) { |
675 |
JComponent c1 = (JComponent) c; |
676 |
for (int i = 0; i < c1.getComponentCount(); i++) { |
677 |
setComponentEnabled(c1.getComponent(i), b); |
678 |
} |
679 |
} |
680 |
c.setEnabled(b); |
681 |
} |
682 |
|
683 |
|
684 |
public IPlacementConstraints getPlacementConstraints() {
|
685 |
return constraints;
|
686 |
} |
687 |
|
688 |
public void actionPerformed(ActionEvent e) { |
689 |
JComponent c = (JComponent) e.getSource(); |
690 |
boolean okPressed = "OK".equals(e.getActionCommand()); |
691 |
boolean cancelPressed = "CANCEL".equals(e.getActionCommand()); |
692 |
if (okPressed || cancelPressed) {
|
693 |
if (okPressed)
|
694 |
applyConstraints(); |
695 |
|
696 |
if ("CANCEL".equals(e.getActionCommand())) |
697 |
constraints = oldConstraints; |
698 |
PluginServices.getMDIManager().closeWindow(PlacementProperties.this); |
699 |
|
700 |
return;
|
701 |
} else if (c.equals(rdBtnAlwaysHorizontal) || c.equals(rdBtnAlwaysStraight) ) { |
702 |
|
703 |
} else if (c.equals(rdBtnHorizontal)) { |
704 |
// lock position panel and location panel
|
705 |
setComponentEnabled(getPositionPanel(), false);
|
706 |
setComponentEnabled(getLocationPanel(), false);
|
707 |
} else if (c.equals(rdBtnParallel) || c.equals(rdBtnPerpendicular)) { |
708 |
// unlock position panel and location panel but keep orientation system locked
|
709 |
setComponentEnabled(getLocationPanel(), true);
|
710 |
setComponentEnabled(getPositionPanel(), true);
|
711 |
getCmbOrientationSystem().setEnabled(true);
|
712 |
} else if (c.equals(rdBtnFollowingLine)) { |
713 |
setComponentEnabled(getLocationPanel(), true);
|
714 |
setComponentEnabled(getPositionPanel(), false);
|
715 |
getCmbOrientationSystem().setEnabled(true);
|
716 |
} else if (c.equals(btnChangeLocation)) { |
717 |
StyleSelector stySel = new StyleSelector(
|
718 |
pointStyle, |
719 |
FShape.POINT, new AbstractStyleSelectorFilter(new PointLabelPositioneer())); |
720 |
PluginServices.getMDIManager().addWindow(stySel); |
721 |
IStyle sty = (IStyle) stySel.getSelectedObject(); |
722 |
if (sty != null) { |
723 |
stylePreview.setStyle(sty); |
724 |
lblPointPosDesc.setText(sty.getDescription()); |
725 |
} |
726 |
} |
727 |
|
728 |
changeIcon(); |
729 |
|
730 |
} |
731 |
|
732 |
private void changeIcon() { |
733 |
if (preview != null && fireEvent) { |
734 |
applyConstraints(); |
735 |
preview.setConstraints(constraints); |
736 |
} |
737 |
} |
738 |
|
739 |
private class JLabelHTML extends JLabel { |
740 |
private static final long serialVersionUID = -5031405572546951108L; |
741 |
|
742 |
public JLabelHTML(String text) { |
743 |
super(text);
|
744 |
setPreferredSize(new Dimension(250, 60)); |
745 |
} |
746 |
|
747 |
@Override
|
748 |
public void setText(String text) { |
749 |
// silly fix to avoid too large text lines
|
750 |
super.setText("<html>"+text+"</html>"); |
751 |
} |
752 |
} |
753 |
|
754 |
public static IPlacementProperties createPlacementProperties( |
755 |
IPlacementConstraints placementConstraints, int shapeType) throws ReadDriverException { |
756 |
return createPlacementProperties(placementConstraints, shapeType, null); |
757 |
} |
758 |
|
759 |
protected static IPlacementProperties createPlacementProperties( |
760 |
IPlacementConstraints placementConstraints, int shapeType,
|
761 |
DuplicateLayersMode duplicatesMode) throws ReadDriverException {
|
762 |
IPlacementProperties pp; |
763 |
if (shapeType == FShape.MULTI) {
|
764 |
pp = new MultiShapePlacementProperties(
|
765 |
(MultiShapePlacementConstraints) placementConstraints); |
766 |
} else {
|
767 |
pp = new PlacementProperties(placementConstraints, shapeType, null); |
768 |
} |
769 |
|
770 |
((JPanel) pp).add(new AcceptCancelPanel(pp, pp), BorderLayout.SOUTH); |
771 |
return pp;
|
772 |
} |
773 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
774 |
|
775 |
class MiniMapContext extends JComponent { |
776 |
private static final long serialVersionUID = 229128782038834443L; |
777 |
private static final IProjection PROJ = CRSFactory.getCRS("EPSG:23030"); |
778 |
private static final String DRIVER_NAME = "gvSIG shp driver"; |
779 |
private MapContext theMapContext;
|
780 |
private FLyrVect line;
|
781 |
private FLyrVect backgroundPolygon;
|
782 |
private int hMargin = 5, vMargin = 5; |
783 |
private FLyrVect polygon;
|
784 |
private int type; |
785 |
private IPlacementConstraints placement;
|
786 |
|
787 |
|
788 |
public MiniMapContext(int shapeType) { |
789 |
this.type = shapeType;
|
790 |
} |
791 |
|
792 |
public void setType(int type) { |
793 |
this.type = type;
|
794 |
} |
795 |
|
796 |
public void setConstraints(IPlacementConstraints constraints) { |
797 |
placement = constraints; |
798 |
repaint(); |
799 |
} |
800 |
|
801 |
private MapContext getMapContext() throws LoadLayerException, ReadDriverException { |
802 |
if (theMapContext == null) { |
803 |
String lineFile = getClass().getClassLoader().getResource("docs/line.shp").getFile(); |
804 |
line = (FLyrVect) LayerFactory.createLayer("line", DRIVER_NAME, new File(lineFile), PROJ); |
805 |
|
806 |
SimpleLineSymbol sym = new SimpleLineSymbol();
|
807 |
sym.setLineColor(Color.red);
|
808 |
SimpleLineStyle sty = new SimpleLineStyle();
|
809 |
ArrowDecoratorStyle arrow = new ArrowDecoratorStyle();
|
810 |
arrow.getMarker().setSize(15);
|
811 |
arrow.setArrowMarkerCount(1);
|
812 |
arrow.getMarker().setColor(Color.red);
|
813 |
sty.setArrowDecorator(arrow); |
814 |
sym.setLineStyle(sty); |
815 |
sym.setLineWidth(2);
|
816 |
line.setLegend(new SingleSymbolLegend(sym));
|
817 |
|
818 |
String backgroundPolygonFile = getClass().getClassLoader().getResource("docs/bg-polygon.shp").getFile(); |
819 |
backgroundPolygon = (FLyrVect) LayerFactory.createLayer("bg-polygon", DRIVER_NAME, new File(backgroundPolygonFile), PROJ); |
820 |
String polygonFile = getClass().getClassLoader().getResource("docs/polygon.shp").getFile(); |
821 |
polygon = (FLyrVect) LayerFactory.createLayer("polygon", DRIVER_NAME, new File(polygonFile), PROJ); |
822 |
|
823 |
SimpleFillSymbol sym2 = new SimpleFillSymbol();
|
824 |
sym2.setFillColor(new Color(50, 245, 125)); |
825 |
SimpleLineSymbol outline = new SimpleLineSymbol();
|
826 |
outline.setLineColor(Color.DARK_GRAY);
|
827 |
outline.setLineWidth(0.5);
|
828 |
sym2.setOutline(outline); |
829 |
|
830 |
SingleSymbolLegend polyLegend = new SingleSymbolLegend(sym2);
|
831 |
polygon.setLegend(polyLegend); |
832 |
backgroundPolygon.setLegend(polyLegend); |
833 |
|
834 |
|
835 |
GeneralLabelingStrategy labeling1 = new GeneralLabelingStrategy();
|
836 |
GeneralLabelingStrategy labeling2 = new GeneralLabelingStrategy();
|
837 |
DefaultLabelingMethod method = new DefaultLabelingMethod();
|
838 |
|
839 |
LabelClass lc = null;
|
840 |
if (method.getLabelClasses() != null && method.getLabelClasses().length > 0) { |
841 |
lc = method.getLabelClasses()[0];
|
842 |
} else {
|
843 |
lc = new LabelClass();
|
844 |
method.addLabelClass(lc); |
845 |
} |
846 |
|
847 |
String[] sampleExpression = {PluginServices.getText(this,"text")}; |
848 |
lc.setLabelExpressions(sampleExpression); |
849 |
|
850 |
lc.getTextSymbol().setFontSize(16);
|
851 |
|
852 |
labeling1.setLabelingMethod(method); |
853 |
labeling2.setLabelingMethod(method); |
854 |
labeling1.setLayer(line); |
855 |
labeling2.setLayer(polygon); |
856 |
|
857 |
line.setLabelingStrategy(labeling1); |
858 |
line.setIsLabeled(true);
|
859 |
|
860 |
polygon.setLabelingStrategy(labeling2); |
861 |
polygon.setIsLabeled(true);
|
862 |
ViewPort theViewPort = new ViewPort(PROJ);
|
863 |
|
864 |
theViewPort.setExtent( |
865 |
new Rectangle2D.Double( |
866 |
289600,
|
867 |
3973700,
|
868 |
2000,
|
869 |
2000)
|
870 |
); |
871 |
theMapContext = new MapContext(theViewPort);
|
872 |
theMapContext.getLayers().addLayer(backgroundPolygon); |
873 |
theMapContext.getLayers().addLayer(polygon); |
874 |
theMapContext.getLayers().addLayer(line); |
875 |
|
876 |
|
877 |
} |
878 |
line.getLabelingStrategy().setPlacementConstraints(placement); |
879 |
polygon.getLabelingStrategy().setPlacementConstraints(placement); |
880 |
Dimension sz = getBounds().getSize();
|
881 |
sz.setSize(sz.width-2*hMargin, sz.height-2*vMargin); |
882 |
theMapContext.getViewPort().setImageSize(sz); |
883 |
theMapContext.getViewPort().setBackColor(new Color(255, 0, 0)); |
884 |
|
885 |
return theMapContext;
|
886 |
} |
887 |
|
888 |
@Override
|
889 |
protected void paintComponent(Graphics g) { |
890 |
try {
|
891 |
getMapContext(); |
892 |
if (type == FShape.LINE) {
|
893 |
line.setVisible(true);
|
894 |
polygon.setVisible(false);
|
895 |
} else if (type == FShape.POLYGON) { |
896 |
line.setVisible(false);
|
897 |
polygon.setVisible(true);
|
898 |
} else {
|
899 |
|
900 |
} |
901 |
backgroundPolygon.setVisible(line.isVisible()); |
902 |
|
903 |
Rectangle bounds = getBounds();
|
904 |
Dimension sz = bounds.getSize();
|
905 |
sz.setSize(sz.width-2*vMargin, sz.height-2*hMargin); |
906 |
Dimension imageSize = sz;
|
907 |
BufferedImage bi = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR); |
908 |
getMapContext().draw(bi, bi.createGraphics(), getMapContext().getScaleView()); |
909 |
g.setColor(new Color(150,180,255)); |
910 |
g.fillRect(vMargin, hMargin, bounds.width-2*hMargin, bounds.height-2*vMargin); |
911 |
g.drawImage(bi, vMargin, vMargin, null);
|
912 |
bi = null;
|
913 |
} catch (Exception e) { |
914 |
e.printStackTrace(); |
915 |
String noneSelected = "["+PluginServices.getText(this, "preview_not_available")+"]"; |
916 |
int vGap = 5, hGap = 5; |
917 |
Rectangle r = getBounds();
|
918 |
FontMetrics fm = g.getFontMetrics();
|
919 |
int lineWidth = fm.stringWidth(noneSelected);
|
920 |
float scale = (float) r.getWidth() / lineWidth; |
921 |
Font f = g.getFont();
|
922 |
float fontSize = f.getSize()*scale;
|
923 |
g.setFont( f.deriveFont( fontSize ) ); |
924 |
((Graphics2D) g).drawString(noneSelected, (r.x*scale) - (hGap/2), r.height/2+vGap*scale); |
925 |
} |
926 |
|
927 |
} |
928 |
} |