gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.lib / org.gvsig.online.lib.impl / src / main / java / org / gvsig / online / lib / impl / workspace / WorkingAreaImpl.java @ 9512
History | View | Annotate | Download (3.54 KB)
1 |
/*
|
---|---|
2 |
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
3 |
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
4 |
*/
|
5 |
package org.gvsig.online.lib.impl.workspace; |
6 |
|
7 |
import javax.json.JsonObject; |
8 |
import org.gvsig.fmap.geom.GeometryUtils; |
9 |
import org.gvsig.fmap.geom.primitive.Envelope; |
10 |
import org.gvsig.json.Json; |
11 |
import org.gvsig.json.JsonObjectBuilder; |
12 |
import org.gvsig.online.lib.api.workingcopy.WorkingArea; |
13 |
import org.gvsig.tools.ToolsLocator; |
14 |
import org.gvsig.tools.dynobject.DynStruct; |
15 |
import org.gvsig.tools.lang.CloneableUtils; |
16 |
import org.gvsig.tools.persistence.PersistenceManager; |
17 |
import org.gvsig.tools.persistence.PersistentState; |
18 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author fdiaz
|
23 |
*/
|
24 |
public class WorkingAreaImpl implements WorkingArea { |
25 |
|
26 |
private static final String WORKINGAREA_PERSISTENCE_DEFINITION_NAME = "Online_WorkingAreaImpl"; |
27 |
|
28 |
private String label; |
29 |
private Envelope envelope;
|
30 |
|
31 |
public WorkingAreaImpl() {
|
32 |
} |
33 |
|
34 |
WorkingAreaImpl(String label, Envelope envelope){
|
35 |
this.label = label;
|
36 |
this.envelope = envelope;
|
37 |
} |
38 |
|
39 |
@Override
|
40 |
public void setLabel(String label) { |
41 |
this.label = label;
|
42 |
} |
43 |
|
44 |
@Override
|
45 |
public void setValue(Envelope envelope) { |
46 |
this.envelope = envelope;
|
47 |
} |
48 |
|
49 |
@Override
|
50 |
public String getLabel() { |
51 |
return this.label; |
52 |
} |
53 |
|
54 |
@Override
|
55 |
public Envelope getValue() {
|
56 |
return this.envelope; |
57 |
} |
58 |
|
59 |
@Override
|
60 |
public void saveToState(PersistentState state) throws PersistenceException { |
61 |
state.set("label", this.label); |
62 |
state.set("envelope", this.envelope); |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public void loadFromState(PersistentState state) throws PersistenceException { |
67 |
this.label = (String) state.get("label"); |
68 |
this.envelope = (Envelope) state.get("envelope"); |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public String toString() { |
73 |
return this.getLabel(); |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public void fromJson(JsonObject json) { |
78 |
this.label = json.getString("label"); |
79 |
this.envelope = (Envelope) GeometryUtils.createFrom(json.getString("envelope")); |
80 |
} |
81 |
|
82 |
@Override
|
83 |
public JsonObjectBuilder toJsonBuilder() {
|
84 |
try {
|
85 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
86 |
builder.add("label", this.label); |
87 |
builder.add("envelope", this.envelope.getGeometry().convertToHexWKB()); |
88 |
return builder;
|
89 |
} catch (Exception ex) { |
90 |
throw new RuntimeException("Can't create JsonObject.", ex); |
91 |
} |
92 |
} |
93 |
|
94 |
public static void selfRegister() { |
95 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
96 |
|
97 |
if (manager.getDefinition(WORKINGAREA_PERSISTENCE_DEFINITION_NAME)
|
98 |
== null) {
|
99 |
DynStruct definition = manager.addDefinition(WorkingAreaImpl.class, |
100 |
WORKINGAREA_PERSISTENCE_DEFINITION_NAME, |
101 |
WORKINGAREA_PERSISTENCE_DEFINITION_NAME |
102 |
+ " persistent definition",
|
103 |
null,
|
104 |
null
|
105 |
); |
106 |
definition.addDynFieldString("label");
|
107 |
definition.addDynFieldObject("envelope").setClassOfValue(Envelope.class);
|
108 |
} |
109 |
|
110 |
} |
111 |
|
112 |
@Override
|
113 |
public Object clone() throws CloneNotSupportedException { |
114 |
WorkingAreaImpl other = (WorkingAreaImpl) super.clone();
|
115 |
other.envelope = (Envelope) CloneableUtils.cloneQuietly(this.envelope);
|
116 |
return other;
|
117 |
} |
118 |
|
119 |
} |