Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / Size.java @ 1736

History | View | Annotate | Download (3.36 KB)

1 5 jldominguez
/* 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 228 cmartinez
     * Gets the height of the sheet, measured in centimeters.
64 5 jldominguez
     *
65 228 cmartinez
     * @return Height.
66 5 jldominguez
     */
67 228 cmartinez
    public double getHeight() {
68 5 jldominguez
        return alto;
69
    }
70
71
    /**
72 228 cmartinez
     * Gets the width of the sheet, measured in centimeters.
73 5 jldominguez
     *
74 228 cmartinez
     * @return Width of the sheet.
75 5 jldominguez
     */
76 228 cmartinez
    public double getWidth() {
77 5 jldominguez
        return ancho;
78
    }
79 287 cmartinez
80
    /**
81
     * @deprecated Use {@link #getWidth()} instead
82
     */
83 288 cmartinez
    @Deprecated
84 287 cmartinez
    public double getAncho() {
85
            return getWidth();
86
    }
87
    /**
88
     * @deprecated Use {@link #getHeight()} instead
89
     */
90 288 cmartinez
    @Deprecated
91 287 cmartinez
    public double getAlto() {
92
            return getHeight();
93
    }
94 5 jldominguez
95
    public static void registerPersistent() {
96
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
97
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
98
            DynStruct definition =
99
                manager.addDefinition(Size.class, PERSISTENCE_DEFINITION_NAME,
100
                    "Size persistence definition", null, null);
101
102
            definition.addDynFieldDouble(HEIGHT_FIELD).setMandatory(true);
103
            definition.addDynFieldDouble(WIDTH_FIELD).setMandatory(true);
104
        }
105
    }
106
107
    public void loadFromState(PersistentState state)
108
        throws PersistenceException {
109
        alto = state.getDouble(HEIGHT_FIELD);
110
        ancho = state.getDouble(WIDTH_FIELD);
111
    }
112
113
    public void saveToState(PersistentState state) throws PersistenceException {
114
        state.set(HEIGHT_FIELD, alto);
115
        state.set(WIDTH_FIELD, ancho);
116
    }
117
}