Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / gui / layerproperties / AbstractLabelingMethodPanel.java @ 42981

History | View | Annotate | Download (3.42 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
package org.gvsig.labeling.gui.layerproperties;
25

    
26
import java.beans.PropertyChangeListener;
27

    
28
import javax.swing.JPanel;
29

    
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.exception.ReadException;
32
import org.gvsig.fmap.dal.feature.FeatureType;
33
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
34
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod;
35

    
36

    
37
/**
38
 * @author gvSIG Team
39
 *
40
 */
41
public abstract class AbstractLabelingMethodPanel extends JPanel implements PropertyChangeListener {
42

    
43
        /**
44
     *
45
     */
46
    private static final long serialVersionUID = 3042343486793818865L;
47
    /**
48
     *
49
     */
50
    public static final String PLACEMENT_CONSTRAINTS = "PLACEMENT_CONSTRAINTS";
51
        /**
52
         *
53
         */
54
        public static final String ALLOW_OVERLAP = "ALLOW_OVERLAP";
55
        /**
56
         *
57
         */
58
        public static final String ZOOM_CONSTRAINTS= "ZOOM_CONSTRAINTS";
59

    
60
        protected FLyrVect layer;
61
        protected ILabelingMethod method;
62

    
63
        public abstract String getName();
64

    
65
        /**
66
         * @return the labeling method class.
67
         */
68
        public abstract Class<? extends ILabelingMethod> getLabelingMethodClass();
69

    
70
        /**
71
         * @param method
72
         * @param srcLayer
73
         * @throws ReadException
74
         */
75
        public void setModel(ILabelingMethod method, FLyrVect srcLayer)
76
                        throws ReadException {
77

    
78
                if (srcLayer == null) {
79
                        throw new ReadException("FLyrVect is null",
80
                                        new Exception("FLyrVect is null"));
81
                }
82
                this.layer = srcLayer;
83

    
84
                try {
85
                        Class<? extends ILabelingMethod> labelingMethodClass = getLabelingMethodClass();
86
            if (method!= null && method.getClass().equals(labelingMethodClass)) {
87
                                this.method = method;
88
                        } else {
89
                                this.method = labelingMethodClass.newInstance();
90
                        }
91

    
92
                } catch (Exception e) {
93

    
94
                        throw new ReadException(
95
                                        srcLayer.getFeatureStore().getName(),
96
                                        new Exception("Unable to load labeling method. Is it in your classpath?", e));
97
                }
98
                initializePanel();
99

    
100
                try {
101
                        fillPanel(srcLayer.getFeatureStore().getDefaultFeatureType());
102
                } catch (DataException de) {
103
                        throw new ReadException(srcLayer.getFeatureStore().getName(), de);
104
                }
105

    
106
        }
107

    
108
        protected abstract void initializePanel() ;
109
        /**
110
         * @param ftype
111
         * @throws ReadException
112
         */
113
        public abstract void fillPanel(
114
                        FeatureType ftype) throws ReadException;
115

    
116
        public String toString() {
117
                return getName();
118
        }
119

    
120
        /**
121
         * @return the labeling method
122
         */
123
        public ILabelingMethod getMethod() {
124
                return method;
125
        }
126

    
127
        public boolean equals(Object obj) {
128
                if (obj == null) return false;
129
                return getClass().equals(obj.getClass());
130
        }
131
}