Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / raster / impl / DefaultBandAttributeDescriptor.java @ 43876

History | View | Annotate | Download (5.9 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23

    
24
package org.gvsig.fmap.dal.raster.impl;
25

    
26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.List;
29

    
30
import org.gvsig.fmap.dal.raster.BandAttributeDescriptor;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.dynobject.DynStruct;
33
import org.gvsig.tools.lang.Cloneable;
34
import org.gvsig.tools.persistence.PersistenceManager;
35
import org.gvsig.tools.persistence.PersistentState;
36
import org.gvsig.tools.persistence.exception.PersistenceException;
37

    
38
/**
39
 * Default implementation of {@link BandAttributeDescriptor}.
40
 *
41
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
42
 *
43
 */
44
public class DefaultBandAttributeDescriptor implements BandAttributeDescriptor {
45

    
46
    private static final String PERSISTENCE_NAME = "BandAttributeDescriptor";
47
    private static final String PERSISTENCE_DESCRIPTION = "";
48

    
49
    private static final String BAND_FIELD_NAME = "band";
50
    private static final String NAME_FIELD_NAME = "name";
51
    private static final String DESCRIPTION_FIELD_NAME = "description";
52
    private static final String VALUES_FIELD_NAME = "values";
53
    private static final String UNITS_FIELD_NAME = "units";
54

    
55
    private int band;
56
    private String name;
57
    private String description;
58
    private List<Object> values;
59
    private String units;
60
    private Object value;
61

    
62
    /**
63
     *
64
     * @param band
65
     * @param name
66
     * @param description
67
     * @param values
68
     */
69
    public DefaultBandAttributeDescriptor(int band, String name, String description,
70
        List<Object> values) {
71
        super();
72
        this.band = band;
73
        this.name = name;
74
        this.values = values;
75
        this.description = description;
76
        this.units = "";
77
        this.value = null;
78
    }
79

    
80
    /**
81
    *
82
    * @param band
83
    * @param name
84
    * @param description
85
    * @param values
86
     * @param units
87
    */
88
   public DefaultBandAttributeDescriptor(int band, String name, String description,
89
       List<Object> values, String units) {
90
       this(band, name, description, values);
91
       this.units = units;
92
   }
93

    
94
   /**
95
   *
96
   * @param band
97
   * @param name
98
   * @param description
99
   * @param values
100
    * @param units
101
   */
102
  public DefaultBandAttributeDescriptor(int band, String name, Object value, String description,
103
      List<Object> values, String units) {
104
      this(band, name, description, values, units);
105
      this.value = value;
106
  }
107

    
108
    @Override
109
    public int getBand() {
110
        return this.band;
111
    }
112

    
113
    @Override
114
    public String getName() {
115
        return this.name;
116
    }
117

    
118
    @Override
119
    public String getDescription() {
120
        return this.description;
121
    }
122

    
123
    @Override
124
    public List<Object> getAvailableValues() {
125
        return Collections.unmodifiableList(this.values);
126
    }
127

    
128
    public static void registerPersitenceDefinition() {
129

    
130
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
131
        DynStruct definition = persistenceManager.getDefinition(PERSISTENCE_NAME);
132
        if (definition == null) {
133

    
134
            definition =
135
                persistenceManager.addDefinition(BandAttributeDescriptor.class, PERSISTENCE_NAME,
136
                    PERSISTENCE_DESCRIPTION, null, null);
137
            definition.addDynFieldInt(BAND_FIELD_NAME);
138
            definition.addDynFieldString(NAME_FIELD_NAME);
139
            definition.addDynFieldString(DESCRIPTION_FIELD_NAME);
140
            definition.addDynFieldList(VALUES_FIELD_NAME).setClassOfItems(Object.class);
141
            definition.addDynFieldString(UNITS_FIELD_NAME);
142
        }
143
    }
144

    
145
    @Override
146
    public void saveToState(PersistentState state) throws PersistenceException {
147
        state.set(BAND_FIELD_NAME, this.getBand());
148
        state.set(NAME_FIELD_NAME, this.getName());
149
        state.set(DESCRIPTION_FIELD_NAME, this.getDescription());
150
        state.set(VALUES_FIELD_NAME, this.getAvailableValues());
151
        state.set(UNITS_FIELD_NAME, this.getUnits());
152
    }
153

    
154
    @Override
155
    public void loadFromState(PersistentState state) throws PersistenceException {
156
        this.band = state.getInt(BAND_FIELD_NAME);
157
        this.name = state.getString(NAME_FIELD_NAME);
158
        this.description = state.getString(DESCRIPTION_FIELD_NAME);
159
        this.values = new ArrayList<Object>(state.getList(VALUES_FIELD_NAME));
160
        this.units = state.getString(UNITS_FIELD_NAME);
161
    }
162

    
163
    @Override
164
    public Object clone() throws CloneNotSupportedException {
165
        DefaultBandAttributeDescriptor newDescriptor = (DefaultBandAttributeDescriptor) this.clone();
166
        newDescriptor.values = new ArrayList<Object>();
167
        for (Object object : values) {
168
            if( object instanceof Cloneable){
169
                newDescriptor.values.add(((Cloneable) object).clone());
170
            } else {
171
                newDescriptor.values.add(object);
172
            }
173
        }
174
        return newDescriptor;
175
    }
176

    
177
    @Override
178
    public String getUnits() {
179
        return this.units;
180
    }
181

    
182
    @Override
183
    public Object getValue() {
184
        // TODO Auto-generated method stub
185
        return null;
186
    }
187
}