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 / MultiShapePlacementProperties.java @ 40911
History | View | Annotate | Download (5.14 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.event.ActionEvent; |
45 |
|
46 |
import javax.swing.JPanel; |
47 |
import javax.swing.JTabbedPane; |
48 |
|
49 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
50 |
import org.gvsig.app.ApplicationLocator; |
51 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
52 |
import org.gvsig.fmap.geom.GeometryException; |
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
54 |
import org.gvsig.i18n.Messages; |
55 |
import org.gvsig.labeling.placements.AbstractPlacementConstraints; |
56 |
import org.gvsig.labeling.placements.LinePlacementConstraints; |
57 |
import org.gvsig.labeling.placements.MultiShapePlacementConstraints; |
58 |
import org.gvsig.labeling.placements.PlacementManager; |
59 |
import org.gvsig.labeling.placements.PointPlacementConstraints; |
60 |
import org.gvsig.labeling.placements.PolygonPlacementConstraints; |
61 |
import org.slf4j.Logger; |
62 |
import org.slf4j.LoggerFactory; |
63 |
|
64 |
|
65 |
public class MultiShapePlacementProperties extends JPanel |
66 |
implements IPlacementProperties {
|
67 |
|
68 |
private static Logger logger = LoggerFactory.getLogger( |
69 |
MultiShapePlacementProperties.class); |
70 |
private static final long serialVersionUID = 2935114466845029008L; |
71 |
private PlacementProperties pointProperties;
|
72 |
private PlacementProperties lineProperties;
|
73 |
private PlacementProperties polygonProperties;
|
74 |
private DuplicateLayersMode dupMode;
|
75 |
|
76 |
|
77 |
public MultiShapePlacementProperties(
|
78 |
MultiShapePlacementConstraints constraints) throws Exception { |
79 |
|
80 |
MultiShapePlacementConstraints c = null;
|
81 |
if (constraints != null) { |
82 |
c = (MultiShapePlacementConstraints) constraints.clone(); |
83 |
} else {
|
84 |
c = (MultiShapePlacementConstraints) |
85 |
PlacementManager.createPlacementConstraints(TYPES.GEOMETRY); |
86 |
} |
87 |
|
88 |
this.pointProperties = new PlacementProperties( |
89 |
c.getPointConstraints(), TYPES.POINT, getDuplicatesMode()); |
90 |
this.lineProperties = new PlacementProperties( |
91 |
c.getLineConstraints(), TYPES.CURVE, getDuplicatesMode()); |
92 |
this.polygonProperties = new PlacementProperties( |
93 |
c.getPolygonConstraints(), TYPES.SURFACE, getDuplicatesMode()); |
94 |
initialize(); |
95 |
} |
96 |
|
97 |
private DuplicateLayersMode getDuplicatesMode() {
|
98 |
if (dupMode == null) { |
99 |
dupMode = new DuplicateLayersMode(null); |
100 |
} |
101 |
return dupMode;
|
102 |
} |
103 |
|
104 |
private void initialize() { |
105 |
setLayout(new BorderLayout()); |
106 |
JPanel aux = new JPanel(new BorderLayout()); |
107 |
JTabbedPane p = new JTabbedPane(); |
108 |
|
109 |
p.addTab(Messages.getText("points"), pointProperties);
|
110 |
p.addTab(Messages.getText("lines"), lineProperties);
|
111 |
p.addTab(Messages.getText("polygon"), polygonProperties);
|
112 |
setLayout(new BorderLayout()); |
113 |
aux.add(p, BorderLayout.CENTER);
|
114 |
aux.add(getDuplicatesMode(), BorderLayout.SOUTH);
|
115 |
add(aux, BorderLayout.CENTER);
|
116 |
} |
117 |
|
118 |
public IPlacementConstraints getPlacementConstraints() {
|
119 |
return new MultiShapePlacementConstraints( |
120 |
(PointPlacementConstraints) pointProperties.getPlacementConstraints(), |
121 |
(LinePlacementConstraints) lineProperties.getPlacementConstraints(), |
122 |
(PolygonPlacementConstraints) polygonProperties.getPlacementConstraints()); |
123 |
|
124 |
} |
125 |
|
126 |
public WindowInfo getWindowInfo() {
|
127 |
return pointProperties.getWindowInfo();
|
128 |
} |
129 |
|
130 |
public Object getWindowProfile() { |
131 |
return pointProperties.getWindowProfile();
|
132 |
} |
133 |
|
134 |
|
135 |
public void actionPerformed(ActionEvent e) { |
136 |
boolean okPressed = "OK".equals(e.getActionCommand()); |
137 |
boolean cancelPressed = "CANCEL".equals(e.getActionCommand()); |
138 |
if (okPressed || cancelPressed) {
|
139 |
if (okPressed) {
|
140 |
try {
|
141 |
pointProperties.applyConstraints(); |
142 |
lineProperties.applyConstraints(); |
143 |
polygonProperties.applyConstraints(); |
144 |
} catch (GeometryException e1) {
|
145 |
logger.error("While applying constraints.", e1);
|
146 |
} |
147 |
} |
148 |
|
149 |
if ("CANCEL".equals(e.getActionCommand())) { |
150 |
pointProperties.constraints = pointProperties.oldConstraints; |
151 |
lineProperties.constraints = lineProperties.oldConstraints; |
152 |
polygonProperties.constraints = polygonProperties.oldConstraints; |
153 |
} |
154 |
|
155 |
ApplicationLocator.getManager().getUIManager().closeWindow(this);
|
156 |
|
157 |
return;
|
158 |
} |
159 |
} |
160 |
} |