gvsig-tools / org.gvsig.tools / library / tags / org.gvsig.tools-3.0.13 / org.gvsig.tools.lib / src / test / java / org / gvsig / tools / persistence / case1 / model / Layers.java
History | View | Annotate | Download (2.26 KB)
1 | 802 | cordinyana | /**
|
---|---|---|---|
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 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 | * 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 | 73 | jjdelcerro | package org.gvsig.tools.persistence.case1.model; |
25 | |||
26 | import java.util.ArrayList; |
||
27 | import java.util.Iterator; |
||
28 | import java.util.List; |
||
29 | |||
30 | import org.gvsig.tools.persistence.Persistent; |
||
31 | import org.gvsig.tools.persistence.PersistentState; |
||
32 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
33 | |||
34 | public class Layers extends Base implements Persistent { |
||
35 | |||
36 | private List layers; // List of Layer |
||
37 | private MapContext context;
|
||
38 | |||
39 | public Layers() {
|
||
40 | this(null); |
||
41 | } |
||
42 | |||
43 | public Layers(MapContext context) {
|
||
44 | this.context = context;
|
||
45 | this.layers = new ArrayList(); |
||
46 | } |
||
47 | |||
48 | public Layer add() {
|
||
49 | Layer layer = new Layer(context);
|
||
50 | this.layers.add(layer);
|
||
51 | return layer;
|
||
52 | } |
||
53 | |||
54 | public List getLayers() { |
||
55 | return this.layers; |
||
56 | } |
||
57 | |||
58 | public MapContext getContext() {
|
||
59 | return this.context; |
||
60 | } |
||
61 | |||
62 | public void saveToState(PersistentState state) throws PersistenceException { |
||
63 | super.saveToState(state);
|
||
64 | |||
65 | state.set("context", this.context); |
||
66 | state.set("layers", layers);
|
||
67 | } |
||
68 | |||
69 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
70 | super.loadFromState(state);
|
||
71 | |||
72 | this.context = (MapContext) state.get("context"); |
||
73 | List layers = (List) state.getList("layers"); |
||
74 | Iterator layersIterator = layers.iterator();
|
||
75 | while (layersIterator.hasNext()) {
|
||
76 | Layer layer = (Layer) layersIterator.next(); |
||
77 | this.layers.add( layer);
|
||
78 | } |
||
79 | } |
||
80 | |||
81 | } |