root / branches / v2_0_0_prep / libraries / org.gvsig.annotation / org.gvsig.annotation.lib / org.gvsig.annotation.lib.impl / src / main / java / org / gvsig / annotation / impl / DefaultAnnotationManager.java @ 33272
History | View | Annotate | Download (6.04 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.annotation.impl; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.util.ArrayList; |
26 |
import java.util.Collections; |
27 |
import java.util.List; |
28 |
|
29 |
import org.gvsig.annotation.AnnotationCreationService; |
30 |
import org.gvsig.annotation.AnnotationCreationServiceException; |
31 |
import org.gvsig.annotation.AnnotationManager; |
32 |
import org.gvsig.annotation.calculator.AnnotationPositionCalculator; |
33 |
import org.gvsig.annotation.calculator.AnnotationPositionCalculatorCreationException; |
34 |
import org.gvsig.fmap.dal.exception.DataException; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
36 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
38 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
39 |
import org.gvsig.tools.service.ServiceException; |
40 |
|
41 |
/**
|
42 |
* Default {@link AnnotationManager} implementation.
|
43 |
*
|
44 |
* @author gvSIG Team
|
45 |
* @version $Id$
|
46 |
*/
|
47 |
public class DefaultAnnotationManager implements AnnotationManager { |
48 |
private static final String ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT = "AnnotationPositionCalculatorExtensionPoint"; |
49 |
private ExtensionPointManager extensionPointManager = ToolsLocator.getExtensionPointManager();
|
50 |
private static final String DEFAULT_ANNOTATION_POSITION_CALCULATOR = "DefaultAnnotationPositionCalculator"; |
51 |
|
52 |
private String defaultTextValue = null; |
53 |
private int defaultFontColor = -1; |
54 |
private double defaultFontHeight = -1; |
55 |
private double defaultFontRotation = -1; |
56 |
private String defaultFontStyle = null; |
57 |
private String defaultFontType = null; |
58 |
|
59 |
private List<String> fontTypes = Collections.synchronizedList(new ArrayList<String>()); |
60 |
private List<String> fontStyles = Collections.synchronizedList(new ArrayList<String>()); |
61 |
|
62 |
|
63 |
public AnnotationCreationService getAnnotationCreationService(FeatureStore featureStore)
|
64 |
throws ServiceException {
|
65 |
AnnotationCreationService fc; |
66 |
try {
|
67 |
fc = new DefaultAnnotationCreationService(featureStore, this); |
68 |
} catch (DataException e) {
|
69 |
throw new AnnotationCreationServiceException("Impossible to create the annotation service", e); |
70 |
} |
71 |
return fc;
|
72 |
} |
73 |
|
74 |
public AnnotationPositionCalculator getAnnotationPositionCalculator(
|
75 |
String name) throws AnnotationPositionCalculatorCreationException { |
76 |
if (extensionPointManager.get(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT).has(name)){
|
77 |
try {
|
78 |
return (AnnotationPositionCalculator)extensionPointManager.get(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT).create(name);
|
79 |
} catch (InstantiationException e) { |
80 |
throw new AnnotationPositionCalculatorCreationException(name, e); |
81 |
} catch (IllegalAccessException e) { |
82 |
throw new AnnotationPositionCalculatorCreationException(name, e); |
83 |
} |
84 |
}else{
|
85 |
throw new IllegalArgumentException("There is not an annotation position calculator registered with this name"); |
86 |
} |
87 |
} |
88 |
|
89 |
public List<String> getAnnotationPositionCalculatorList() { |
90 |
return extensionPointManager.get(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT).getNames();
|
91 |
} |
92 |
|
93 |
public AnnotationPositionCalculator getDefaultAnnotationPositionCalculator() throws AnnotationPositionCalculatorCreationException { |
94 |
return getAnnotationPositionCalculator(DEFAULT_ANNOTATION_POSITION_CALCULATOR);
|
95 |
} |
96 |
|
97 |
public void registerAnnotationPositionCalculator(String name, |
98 |
Class annotationPositionCalculatorClass) {
|
99 |
if (!AnnotationPositionCalculator.class.isAssignableFrom(annotationPositionCalculatorClass)) {
|
100 |
throw new IllegalArgumentException(annotationPositionCalculatorClass.getName() |
101 |
+ " must implement the AnnotationPositionCalculator interface");
|
102 |
} |
103 |
|
104 |
ExtensionPoint extensionPoint = extensionPointManager.add(ANNOTATION_POSITION_CALCULATOR_EXTENSION_POINT, "");
|
105 |
extensionPoint.append(name, name, annotationPositionCalculatorClass); |
106 |
} |
107 |
|
108 |
public void registerDefaultAnnotationPositionCalculator(Class annotationPositionCalculatorClass) { |
109 |
registerAnnotationPositionCalculator(DEFAULT_ANNOTATION_POSITION_CALCULATOR, |
110 |
annotationPositionCalculatorClass); |
111 |
} |
112 |
|
113 |
public void addFontStyle(String fontStyle) { |
114 |
fontStyles.add(fontStyle); |
115 |
} |
116 |
|
117 |
public void addFontType(String fontType) { |
118 |
fontTypes.add(fontType); |
119 |
} |
120 |
|
121 |
public int getDefaultFontColor() { |
122 |
return defaultFontColor;
|
123 |
} |
124 |
|
125 |
public double getDefaultFontHeight() { |
126 |
return defaultFontHeight;
|
127 |
} |
128 |
|
129 |
public double getDefaultFontRotation() { |
130 |
return defaultFontRotation;
|
131 |
} |
132 |
|
133 |
public String getDefaultFontStyle() { |
134 |
return defaultFontStyle;
|
135 |
} |
136 |
|
137 |
public String getDefaultFontType() { |
138 |
return defaultFontType;
|
139 |
} |
140 |
|
141 |
public String getDefaultTextValue() { |
142 |
return defaultTextValue;
|
143 |
} |
144 |
|
145 |
public List<String> getFontStyles() { |
146 |
return fontStyles;
|
147 |
} |
148 |
|
149 |
public List<String> getFontTypes() { |
150 |
return fontTypes;
|
151 |
} |
152 |
|
153 |
public void setDefaultFontColor(int fontColor) { |
154 |
this.defaultFontColor = fontColor;
|
155 |
} |
156 |
|
157 |
public void setDefaultFontHeight(double fontHeight) { |
158 |
this.defaultFontHeight = fontHeight;
|
159 |
} |
160 |
|
161 |
public void setDefaultFontRotation(double fontRotation) { |
162 |
this.defaultFontRotation = fontRotation;
|
163 |
} |
164 |
|
165 |
public void setDefaultFontStyle(String fontStyle) { |
166 |
this.defaultFontStyle = fontStyle;
|
167 |
} |
168 |
|
169 |
public void setDefaultFontType(String fontType) { |
170 |
this.defaultFontType = fontType;
|
171 |
} |
172 |
|
173 |
public void setDefaultTextValue(String textValue) { |
174 |
this.defaultTextValue = textValue;
|
175 |
} |
176 |
|
177 |
|
178 |
} |