Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / Size.java @ 36648

History | View | Annotate | Download (3.01 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.app.project.documents.layout;
23

    
24
import org.gvsig.tools.ToolsLocator;
25
import org.gvsig.tools.dynobject.DynStruct;
26
import org.gvsig.tools.persistence.PersistenceManager;
27
import org.gvsig.tools.persistence.Persistent;
28
import org.gvsig.tools.persistence.PersistentState;
29
import org.gvsig.tools.persistence.exception.PersistenceException;
30

    
31
/**
32
 * Clase que almacena la altura y anchura de un folio.
33
 * 
34
 * @author Vicente Caballero Navarro
35
 */
36
public class Size implements Persistent {
37

    
38
    public static final String PERSISTENCE_DEFINITION_NAME = "Size";
39
    private static final String HEIGHT_FIELD = "height";
40
    private static final String WIDTH_FIELD = "width";
41

    
42
    private double alto;
43
    private double ancho;
44

    
45
    public Size() {
46

    
47
    }
48

    
49
    /**
50
     * Creates a new Size object.
51
     * 
52
     * @param al
53
     *            Altura
54
     * @param an
55
     *            Anchura
56
     */
57
    public Size(double al, double an) {
58
        alto = al;
59
        ancho = an;
60
    }
61

    
62
    /**
63
     * Devuelve el alto del folio.
64
     * 
65
     * @return altura.
66
     */
67
    public double getAlto() {
68
        return alto;
69
    }
70

    
71
    /**
72
     * Devuelve la anchura del folio.
73
     * 
74
     * @return Anchura.
75
     */
76
    public double getAncho() {
77
        return ancho;
78
    }
79

    
80
    public static void registerPersistent() {
81
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
82
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
83
            DynStruct definition =
84
                manager.addDefinition(Size.class, PERSISTENCE_DEFINITION_NAME,
85
                    "Size persistence definition", null, null);
86

    
87
            definition.addDynFieldDouble(HEIGHT_FIELD).setMandatory(true);
88
            definition.addDynFieldDouble(WIDTH_FIELD).setMandatory(true);
89
        }
90
    }
91

    
92
    public void loadFromState(PersistentState state)
93
        throws PersistenceException {
94
        alto = state.getDouble(HEIGHT_FIELD);
95
        ancho = state.getDouble(WIDTH_FIELD);
96
    }
97

    
98
    public void saveToState(PersistentState state) throws PersistenceException {
99
        state.set(HEIGHT_FIELD, alto);
100
        state.set(WIDTH_FIELD, ancho);
101
    }
102
}