svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / styling / LabelingFactory.java @ 40560
History | View | Annotate | Download (4.2 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/* CVS MESSAGES:
|
25 |
*
|
26 |
* $Id: LabelingFactory.java 13913 2007-09-20 09:36:02Z jaume $
|
27 |
* $Log$
|
28 |
* Revision 1.9 2007-09-20 09:33:15 jaume
|
29 |
* Refactored: fixed name of IPersistAnce to IPersistence
|
30 |
*
|
31 |
* Revision 1.8 2007/05/22 12:17:41 jaume
|
32 |
* *** empty log message ***
|
33 |
*
|
34 |
* Revision 1.7 2007/05/22 10:05:31 jaume
|
35 |
* *** empty log message ***
|
36 |
*
|
37 |
* Revision 1.6 2007/04/13 11:59:30 jaume
|
38 |
* *** empty log message ***
|
39 |
*
|
40 |
* Revision 1.5 2007/03/28 16:48:01 jaume
|
41 |
* *** empty log message ***
|
42 |
*
|
43 |
* Revision 1.4 2007/03/20 16:16:20 jaume
|
44 |
* refactored to use ISymbol instead of FSymbol
|
45 |
*
|
46 |
* Revision 1.3 2007/03/09 11:20:57 jaume
|
47 |
* Advanced symbology (start committing)
|
48 |
*
|
49 |
* Revision 1.2 2007/03/09 08:33:43 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1.2.4 2007/02/21 07:34:08 jaume
|
53 |
* labeling starts working
|
54 |
*
|
55 |
* Revision 1.1.2.3 2007/02/12 15:15:20 jaume
|
56 |
* refactored interval legend and added graduated symbol legend
|
57 |
*
|
58 |
* Revision 1.1.2.2 2007/02/09 07:47:05 jaume
|
59 |
* Isymbol moved
|
60 |
*
|
61 |
* Revision 1.1.2.1 2007/02/02 16:21:24 jaume
|
62 |
* start commiting labeling stuff
|
63 |
*
|
64 |
* Revision 1.1.2.1 2007/01/30 18:10:45 jaume
|
65 |
* start commiting labeling stuff
|
66 |
*
|
67 |
*
|
68 |
*/
|
69 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling; |
70 |
|
71 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
72 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
73 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
74 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
75 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints; |
76 |
import org.slf4j.Logger; |
77 |
import org.slf4j.LoggerFactory; |
78 |
|
79 |
|
80 |
public class LabelingFactory { |
81 |
final static private Logger logger = LoggerFactory.getLogger(LabelingFactory.class); |
82 |
@SuppressWarnings("unchecked") |
83 |
private static Class defaultLabelingStrategy = |
84 |
AttrInTableLabelingStrategy.class; |
85 |
/**
|
86 |
* Given a layer, a labeling method, a label placements constraints, and a label
|
87 |
* zoom constraints it will figure out the best ILabelingStrategy that meets all
|
88 |
* the needs.
|
89 |
* @param layer, the target layer
|
90 |
* @param method, the desired methods
|
91 |
* @param placement, the desired placement constraints
|
92 |
* @param zoom, the desired zoom constraints
|
93 |
* @return ILabelingStrategy
|
94 |
*/
|
95 |
public static ILabelingStrategy createStrategy(FLayer layer, |
96 |
ILabelingMethod method, IPlacementConstraints placement, |
97 |
IZoomConstraints zoom) { |
98 |
if (method == null && placement == null && zoom == null) |
99 |
return createDefaultStrategy(layer);
|
100 |
|
101 |
ILabelingStrategy strat = createDefaultStrategy(layer); |
102 |
if (method != null) |
103 |
strat.setLabelingMethod(method); |
104 |
if (placement != null) |
105 |
strat.setPlacementConstraints(placement); |
106 |
return strat;
|
107 |
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* Creates a default labeling strategy from an XMLEntity.
|
112 |
* @param layer
|
113 |
* @return an instance of DefaultStrategy
|
114 |
*/
|
115 |
public static ILabelingStrategy createDefaultStrategy(FLayer layer) { |
116 |
ILabelingStrategy st; |
117 |
try {
|
118 |
st = (ILabelingStrategy) defaultLabelingStrategy.newInstance(); |
119 |
st.setLayer(layer); |
120 |
return st;
|
121 |
} catch (Exception e) { |
122 |
logger.error(e.getMessage()); |
123 |
return null; |
124 |
} |
125 |
|
126 |
} |
127 |
|
128 |
@SuppressWarnings("unchecked") |
129 |
public static void setDefaultLabelingStrategy(Class defaultLabelingStrategy) { |
130 |
LabelingFactory.defaultLabelingStrategy = defaultLabelingStrategy; |
131 |
} |
132 |
} |