Statistics
| Revision:

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 @ 44256

History | View | Annotate | Download (4.53 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.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DefaultDynamicLabelingStrategy;
77
import org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend.DynamicLabelingStrategy;
78
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
80

    
81

    
82
public class LabelingFactory {
83
        final static private Logger logger = LoggerFactory.getLogger(LabelingFactory.class);
84
        @SuppressWarnings("unchecked")
85
        private static Class defaultLabelingStrategy =
86
                        AttrInTableLabelingStrategy.class;
87
        /**
88
         * Given a layer, a labeling method, a label placements constraints, and a label
89
         * zoom constraints it will figure out the best ILabelingStrategy that meets all
90
         * the needs.
91
         * @param layer, the target layer
92
         * @param method, the desired methods
93
         * @param placement, the desired placement constraints
94
         * @param zoom, the desired zoom constraints
95
         * @return ILabelingStrategy
96
         */
97
        public static ILabelingStrategy createStrategy(FLayer layer,
98
                        ILabelingMethod method, IPlacementConstraints placement,
99
                        IZoomConstraints zoom)         {
100
                if (method == null && placement == null && zoom == null)
101
                        return createDefaultStrategy(layer);
102

    
103
                ILabelingStrategy strat = createDefaultStrategy(layer);
104
                if (method != null)
105
                        strat.setLabelingMethod(method);
106
                if (placement != null)
107
                        strat.setPlacementConstraints(placement);
108
                return strat;
109

    
110
        }
111

    
112
        public static DynamicLabelingStrategy createDynamicLabelingStrategy() {
113
            return new DefaultDynamicLabelingStrategy();
114
        }
115

    
116
        /**
117
         * Creates a default labeling strategy from an XMLEntity.
118
         * @param layer
119
         * @return an instance of DefaultStrategy
120
         */
121
        public static ILabelingStrategy createDefaultStrategy(FLayer layer) {
122
                ILabelingStrategy st;
123
                try {
124
                        st = (ILabelingStrategy) defaultLabelingStrategy.newInstance();
125
                        st.setLayer(layer);
126
                        return st;
127
                } catch (Exception e) {
128
                        logger.error(e.getMessage());
129
                        return null;
130
                }
131

    
132
        }
133

    
134
        @SuppressWarnings("unchecked")
135
        public static void setDefaultLabelingStrategy(Class defaultLabelingStrategy) {
136
                LabelingFactory.defaultLabelingStrategy = defaultLabelingStrategy;
137
        }
138
}