Statistics
| Revision:

svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / styling / AbstractPlacementConstraints.java @ 19509

History | View | Annotate | Download (7.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: AbstractPlacementConstraints.java 13884 2007-09-19 16:26:04Z jaume $
45
* $Log$
46
* Revision 1.8  2007-09-19 16:25:39  jaume
47
* ReadExpansionFileException removed from this context and removed unnecessary imports
48
*
49
* Revision 1.7  2007/04/18 15:35:11  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.6  2007/04/13 12:42:45  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.5  2007/04/13 11:59:30  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.4  2007/04/12 16:01:11  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.3  2007/04/11 16:01:08  jaume
62
* maybe a label placer refactor
63
*
64
* Revision 1.2  2007/03/09 08:33:43  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1.2.2  2007/02/15 16:23:44  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.1.2.1  2007/02/09 07:47:05  jaume
71
* Isymbol moved
72
*
73
* Revision 1.1.2.3  2007/02/02 16:21:24  jaume
74
* start commiting labeling stuff
75
*
76
* Revision 1.1.2.2  2007/02/01 11:42:47  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.1.2.1  2007/01/30 18:10:45  jaume
80
* start commiting labeling stuff
81
*
82
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
83
* *** empty log message ***
84
*
85
*
86
*/
87

    
88

    
89
package com.iver.cit.gvsig.fmap.rendering.styling;
90
import com.iver.utiles.XMLEntity;
91

    
92
/**
93
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
94
 */
95
public abstract class AbstractPlacementConstraints implements Cloneable, IPlacementConstraints {
96
        private int duplicateLabelsMode = ONE_LABEL_PER_FEATURE_PART; // default duplicate treatment
97
        private int placementMode;
98
        private boolean bellowTheLine;
99
        private boolean aboveTheLine;
100
        private boolean onTheLine;
101
        private boolean pageOriented;
102
        private int locationAlongLine;
103
        private boolean fitInsidePolygon;
104

    
105
        public void setDuplicateLabelsMode(int mode) {
106
                if (mode != REMOVE_DUPLICATE_LABELS &&
107
                        mode != ONE_LABEL_PER_FEATURE &&
108
                        mode != ONE_LABEL_PER_FEATURE_PART)
109
                        throw new IllegalArgumentException(
110
                                        "Only REMOVE_DUPLICATE_LABELS, " +
111
                                        "ONE_LABEL_PER_FEATURE " +
112
                                        "or ONE_LABEL_PER_FEATURE_PARTS allowed");
113
                this.duplicateLabelsMode = mode;
114
        }
115

    
116
        public void setPlacementMode(int mode) {
117
                if (this instanceof PointPlacementConstraints) {
118
                        if (mode != OFFSET_HORIZONTALY_AROUND_THE_POINT &&
119
                                mode != ON_TOP_OF_THE_POINT &&
120
                                mode != AT_SPECIFIED_ANGLE &&
121
                                mode != AT_ANGLE_SPECIFIED_BY_A_FIELD)
122
                                throw new IllegalArgumentException(
123
                                                "Only OFFSET_HORIZONTALY_AROUND_THE_POINT, " +
124
                                                "ON_TOP_OF_THE_POINT, " +
125
                                                "AT_SPECIFIED_ANGLE " +
126
                                                "or AT_ANGLE_SPECIFIED_BY_A_FIELD allowed for points");
127
                }
128

    
129
                if (this instanceof PolygonPlacementConstraints) {
130
                        if (mode != HORIZONTAL &&
131
                                mode != PARALLEL )
132
                                        throw new IllegalArgumentException(
133
                                                        "Only HORIZONTAL, " +
134
                                                        "or PARALEL allowed for polygons");
135
                }
136

    
137
                if (this instanceof LinePlacementConstraints) {
138
                                        if (mode != HORIZONTAL &&
139
                                mode != PARALLEL &&
140
                                mode != FOLLOWING_LINE &&
141
                                mode != PERPENDICULAR)
142
                                throw new IllegalArgumentException(
143
                                                "Only HORIZONTAL, " +
144
                                                "or PARALEL allowed for lines");
145
                }
146
                this.placementMode = mode;
147
        }
148

    
149
        public boolean isHorizontal() {
150
                return placementMode == HORIZONTAL;
151
        }
152

    
153
        public boolean isPerpendicular() {
154
                return placementMode  == PERPENDICULAR;
155
        }
156

    
157
        public boolean isFollowingLine() {
158
                return placementMode  == FOLLOWING_LINE;
159
        }
160

    
161
        public boolean isParallel() {
162
                return placementMode == PARALLEL;
163
        }
164

    
165
        public int getDuplicateLabelsMode() {
166
                return duplicateLabelsMode;
167
        }
168

    
169
        /**
170
         * Tells if the place mode selected is to put the label over the <b>POINT</b>
171
         * @return boolean
172
         */
173
        public boolean isOnTopOfThePoint() {
174
                return placementMode == ON_TOP_OF_THE_POINT;
175
        }
176

    
177
        public boolean isBellowTheLine() {
178
                return bellowTheLine;
179
        }
180

    
181
        public boolean isAboveTheLine() {
182
                return aboveTheLine;
183
        }
184

    
185
        public boolean isOnTheLine() {
186
                return onTheLine;
187
        }
188

    
189
        public boolean isPageOriented() {
190
                return pageOriented;
191
        }
192

    
193
        public void setOnTheLine(boolean b) {
194
                this.onTheLine = b;
195
        }
196

    
197
        public void setPageOriented(boolean b) {
198
                this.pageOriented = b;
199
        }
200

    
201
        public void setBellowTheLine(boolean b) {
202
                this.bellowTheLine = b;
203
        }
204

    
205
        public void setAboveTheLine(boolean b) {
206
                this.aboveTheLine = b;
207
        }
208

    
209
        public boolean isAtTheEndOfLine() {
210
                return locationAlongLine == AT_THE_END_OF_THE_LINE;
211
        }
212

    
213
        public boolean isAtTheBeginingOfLine() {
214
                return locationAlongLine == AT_THE_BEGINING_OF_THE_LINE;
215
        }
216

    
217
        public boolean isInTheMiddleOfLine() {
218
                return locationAlongLine == AT_THE_MIDDLE_OF_THE_LINE;
219
        }
220

    
221
        public boolean isAroundThePoint() {
222
                return placementMode == OFFSET_HORIZONTALY_AROUND_THE_POINT;
223
        }
224

    
225
        public boolean isFitInsidePolygon() {
226
                return fitInsidePolygon;
227
        }
228

    
229
        public void setFitInsidePolygon(boolean b) {
230
                fitInsidePolygon = b;
231
        }
232

    
233
        public void setLocationAlongTheLine(int location) {
234
                if (location != IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE
235
                        && location != IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE
236
                        && location != IPlacementConstraints.AT_THE_END_OF_THE_LINE) {
237
                        throw new IllegalArgumentException("Only IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE, " +
238
                                        "IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE, or " +
239
                                        "IPlacementConstraints.AT_THE_END_OF_THE_LINE values are allowed");
240
                }
241
                this.locationAlongLine = location;
242
        }
243

    
244
        public XMLEntity getXMLEntity() {
245
                XMLEntity xml = new XMLEntity();
246
                xml.putProperty("duplicateLabelsMode", duplicateLabelsMode);
247
                xml.putProperty("placementMode", placementMode);
248
                xml.putProperty("bellowTheLine", bellowTheLine);
249
                xml.putProperty("aboveTheLine", aboveTheLine);
250
                xml.putProperty("onTheLine", onTheLine);
251
                xml.putProperty("pageOriented", pageOriented);
252
                xml.putProperty("locationAlongLine", locationAlongLine);
253
                xml.putProperty("fitInsidePolygon", fitInsidePolygon);
254
                return xml;
255
        }
256

    
257
        public void setXMLEntity(XMLEntity xml) {
258
                duplicateLabelsMode = xml.getIntProperty("duplicateLabelsMode");
259
                placementMode = xml.getIntProperty("placementMode");
260
                bellowTheLine = xml.getBooleanProperty("bellowTheLine");
261
                aboveTheLine = xml.getBooleanProperty("aboveTheLine");
262
                onTheLine = xml.getBooleanProperty("onTheLine");
263
                pageOriented = xml.getBooleanProperty("pageOriented");
264
                locationAlongLine = xml.getIntProperty("locationAlongLine");
265
                fitInsidePolygon = xml.getBooleanProperty("fitInsidePolygon");
266
        }
267
}