Statistics
| Revision:

svn-gvsig-desktop / trunk / extSymbology / src / org / gvsig / symbology / fmap / labeling / placements / AbstractPlacementConstraints.java @ 18755

History | View | Annotate | Download (8.54 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 org.gvsig.symbology.fmap.labeling.placements;
90
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IPlacementConstraints;
91
import com.iver.utiles.XMLEntity;
92

    
93
/**
94
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
95
 */
96
public abstract class AbstractPlacementConstraints implements Cloneable, IPlacementConstraints {
97
        // CAUTION, THIS IS A CLONEABLE OBJECT, DON'T FORGET TO 
98
        // UPDATE clone() METHOD WHEN ADDING FIELDS
99
        private int duplicateLabelsMode = ONE_LABEL_PER_FEATURE_PART; // default duplicate treatment
100
        private int placementMode;
101
        private boolean bellowTheLine;
102
        private boolean aboveTheLine;
103
        private boolean onTheLine;
104
        private boolean pageOriented;
105
        private int locationAlongLine;
106
        private boolean fitInsidePolygon;
107
        // CAUTION, THIS IS A CLONEABLE OBJECT, DON'T FORGET TO 
108
        // UPDATE clone() METHOD WHEN ADDING FIELDS
109
        
110
        
111
        public void setDuplicateLabelsMode(int mode) {
112
                if (mode != REMOVE_DUPLICATE_LABELS &&
113
                        mode != ONE_LABEL_PER_FEATURE &&
114
                        mode != ONE_LABEL_PER_FEATURE_PART)
115
                        throw new IllegalArgumentException(
116
                                        "Only REMOVE_DUPLICATE_LABELS, " +
117
                                        "ONE_LABEL_PER_FEATURE " +
118
                                        "or ONE_LABEL_PER_FEATURE_PARTS allowed");
119
                this.duplicateLabelsMode = mode;
120
        }
121

    
122
        public void setPlacementMode(int mode) {
123
                if (this instanceof PointPlacementConstraints) {
124
                        if (mode != OFFSET_HORIZONTALY_AROUND_THE_POINT &&
125
                                mode != ON_TOP_OF_THE_POINT &&
126
                                mode != AT_SPECIFIED_ANGLE &&
127
                                mode != AT_ANGLE_SPECIFIED_BY_A_FIELD)
128
                                throw new IllegalArgumentException(
129
                                                "Only OFFSET_HORIZONTALY_AROUND_THE_POINT, " +
130
                                                "ON_TOP_OF_THE_POINT, " +
131
                                                "AT_SPECIFIED_ANGLE " +
132
                                                "or AT_ANGLE_SPECIFIED_BY_A_FIELD allowed for points");
133
                }
134

    
135
                if (this instanceof PolygonPlacementConstraints) {
136
                        if (mode != HORIZONTAL &&
137
                                mode != PARALLEL )
138
                                        throw new IllegalArgumentException(
139
                                                        "Only HORIZONTAL, " +
140
                                                        "or PARALLEL allowed for polygons");
141
                }
142

    
143
                if (this instanceof LinePlacementConstraints) {
144
                                        if (mode != HORIZONTAL &&
145
                                mode != PARALLEL &&
146
                                mode != FOLLOWING_LINE &&
147
                                mode != PERPENDICULAR)
148
                                throw new IllegalArgumentException(
149
                                                "Only HORIZONTAL, PARALLEL," +
150
                                                "FOLLOWING_LINE, or PERPENDICULAR allowed for lines");
151
                }
152
                this.placementMode = mode;
153
        }
154

    
155
        public boolean isHorizontal() {
156
                return placementMode == HORIZONTAL;
157
        }
158

    
159
        public boolean isPerpendicular() {
160
                return placementMode  == PERPENDICULAR;
161
        }
162

    
163
        public boolean isFollowingLine() {
164
                return placementMode  == FOLLOWING_LINE;
165
        }
166

    
167
        public boolean isParallel() {
168
                return placementMode == PARALLEL;
169
        }
170

    
171
        public int getDuplicateLabelsMode() {
172
                return duplicateLabelsMode;
173
        }
174

    
175
        /**
176
         * Tells if the place mode selected is to put the label over the <b>POINT</b>
177
         * @return boolean
178
         */
179
        public boolean isOnTopOfThePoint() {
180
                return placementMode == ON_TOP_OF_THE_POINT;
181
        }
182

    
183
        public boolean isBellowTheLine() {
184
                return bellowTheLine;
185
        }
186

    
187
        public boolean isAboveTheLine() {
188
                return aboveTheLine;
189
        }
190

    
191
        public boolean isOnTheLine() {
192
                return onTheLine;
193
        }
194

    
195
        public boolean isPageOriented() {
196
                return pageOriented;
197
        }
198

    
199
        public void setOnTheLine(boolean b) {
200
                this.onTheLine = b;
201
        }
202

    
203
        public void setPageOriented(boolean b) {
204
                this.pageOriented = b;
205
        }
206

    
207
        public void setBellowTheLine(boolean b) {
208
                this.bellowTheLine = b;
209
        }
210

    
211
        public void setAboveTheLine(boolean b) {
212
                this.aboveTheLine = b;
213
        }
214

    
215
        public boolean isAtTheEndOfLine() {
216
                return locationAlongLine == AT_THE_END_OF_THE_LINE;
217
        }
218

    
219
        public boolean isAtTheBeginingOfLine() {
220
                return locationAlongLine == AT_THE_BEGINING_OF_THE_LINE;
221
        }
222

    
223
        public boolean isInTheMiddleOfLine() {
224
                return locationAlongLine == AT_THE_MIDDLE_OF_THE_LINE;
225
        }
226
        
227
        public boolean isAtBestOfLine() {
228
                return locationAlongLine == AT_BEST_OF_LINE;
229
        }
230

    
231
        public boolean isAroundThePoint() {
232
                return placementMode == OFFSET_HORIZONTALY_AROUND_THE_POINT;
233
        }
234

    
235
        public boolean isFitInsidePolygon() {
236
                return fitInsidePolygon;
237
        }
238

    
239
        public void setFitInsidePolygon(boolean b) {
240
                fitInsidePolygon = b;
241
        }
242

    
243
        public void setLocationAlongTheLine(int location) {
244
                if (location != IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE
245
                        && location != IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE
246
                        && location != IPlacementConstraints.AT_THE_END_OF_THE_LINE
247
                        && location != IPlacementConstraints.AT_BEST_OF_LINE) {
248
                        throw new IllegalArgumentException("Only IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE, " +
249
                                        "IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE, or " +
250
                                        "IPlacementConstraints.AT_THE_END_OF_THE_LINE, or " +
251
                                        "IPlacementConstraints.AT_BEST_OF_LINE values are allowed" );
252
                }
253
                this.locationAlongLine = location;
254
        }
255

    
256
        public XMLEntity getXMLEntity() {
257
                XMLEntity xml = new XMLEntity();
258
                xml.putProperty("duplicateLabelsMode", getDuplicateLabelsMode());
259
                xml.putProperty("placementMode", placementMode);
260
                xml.putProperty("bellowTheLine", isBellowTheLine());
261
                xml.putProperty("aboveTheLine", isAboveTheLine());
262
                xml.putProperty("onTheLine", isOnTheLine());
263
                xml.putProperty("pageOriented", isPageOriented());
264
                xml.putProperty("locationAlongLine", locationAlongLine);
265
                xml.putProperty("fitInsidePolygon", isFitInsidePolygon());
266
                return xml;
267
        }
268

    
269
        public void setXMLEntity(XMLEntity xml) {
270
                setDuplicateLabelsMode(xml.getIntProperty("duplicateLabelsMode"));
271
                setPlacementMode(xml.getIntProperty("placementMode"));
272
                setBellowTheLine(xml.getBooleanProperty("bellowTheLine"));
273
                setAboveTheLine(xml.getBooleanProperty("aboveTheLine"));
274
                setOnTheLine(xml.getBooleanProperty("onTheLine"));
275
                setPageOriented(xml.getBooleanProperty("pageOriented"));
276
                locationAlongLine = xml.getIntProperty("locationAlongLine");
277
                setFitInsidePolygon(xml.getBooleanProperty("fitInsidePolygon"));
278
        }
279
        
280
        @Override
281
        protected Object clone() throws CloneNotSupportedException {
282
                try {
283
                        AbstractPlacementConstraints clone = getClass().newInstance();
284
                        clone.aboveTheLine        = this.aboveTheLine;
285
                        clone.bellowTheLine       = this.bellowTheLine;
286
                        clone.duplicateLabelsMode = this.duplicateLabelsMode;
287
                        clone.fitInsidePolygon    = this.fitInsidePolygon;
288
                        clone.locationAlongLine   = this.locationAlongLine;
289
                        clone.onTheLine           = this.onTheLine;
290
                        clone.pageOriented        = this.pageOriented;
291
                        clone.placementMode       = this.placementMode;
292
                        return clone;
293
                } catch (Exception e) {
294
                        throw new CloneNotSupportedException(e.getMessage());
295
                }
296
        }
297
}