Skip to content

Commit 57e533a

Browse files
committed
Document now stores paths as object, not array
1 parent 1dcf4a8 commit 57e533a

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repositories {
2222
}
2323

2424
dependencies {
25-
implementation("com.github.jlbabilino:json:0.2.0")
25+
implementation("com.github.jlbabilino:json:master-SNAPSHOT")
2626
// implementation "javax.measure:unit-api:2.1.3"
2727
// implementation "tec.units:unit-ri:1.0.3"
2828
// implementation "tech.units:indriya:2.1.3"

app/src/main/java/org/team2363/helixnavigator/document/DocumentManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private final boolean openDocument(File file) {
134134
HDocument openedDocument = JSONDeserializer.deserialize(file, HDocument.class);
135135
openedDocument.setSaveLocation(file);
136136
setDocument(openedDocument);
137-
logger.info("File \"" + file.getAbsolutePath() + "\" succesffully opened.");
137+
logger.info("File \"" + file.getAbsolutePath() + "\" successfully opened.");
138138
return true;
139139
} catch (IOException e) {
140140
logger.finer("Could not read file " + file.getAbsolutePath() + ": " + e.getMessage());

app/src/main/java/org/team2363/helixnavigator/document/HDocument.java

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
package org.team2363.helixnavigator.document;
1818

1919
import java.io.File;
20-
import java.util.List;
20+
import java.util.HashMap;
21+
import java.util.Map;
2122
import java.util.logging.Logger;
2223

24+
import org.team2363.helixnavigator.document.field.image.HFieldImage;
25+
import org.team2363.helixnavigator.document.field.image.HReferenceFieldImage;
26+
import org.team2363.helixnavigator.global.Standards;
27+
2328
import com.jlbabilino.json.DeserializedJSONConstructor;
2429
import com.jlbabilino.json.DeserializedJSONObjectValue;
2530
import com.jlbabilino.json.DeserializedJSONTarget;
2631
import com.jlbabilino.json.JSONDeserializable;
32+
import com.jlbabilino.json.JSONEntry.JSONType;
2733
import com.jlbabilino.json.JSONSerializable;
2834
import com.jlbabilino.json.SerializedJSONObjectValue;
29-
import com.jlbabilino.json.JSONEntry.JSONType;
30-
31-
import org.team2363.helixnavigator.document.field.image.HFieldImage;
32-
import org.team2363.helixnavigator.document.field.image.HReferenceFieldImage;
33-
import org.team2363.helixnavigator.global.Standards;
3435

3536
import javafx.beans.property.BooleanProperty;
3637
import javafx.beans.property.DoubleProperty;
@@ -129,10 +130,22 @@ public HDocument() {
129130
selectedPathIndex.addListener((currentIndex, oldIndex, newIndex) -> updateSelectedPath());
130131
}
131132

133+
// @DeserializedJSONConstructor
134+
// public HDocument(@DeserializedJSONObjectValue(key = "paths") List<? extends HPath> initialPaths) {
135+
// this();
136+
// paths.setAll(initialPaths);
137+
// }
138+
132139
@DeserializedJSONConstructor
133-
public HDocument(@DeserializedJSONObjectValue(key = "paths") List<? extends HPath> initialPaths) {
140+
public HDocument(@DeserializedJSONObjectValue(key = "paths") Map<String, HPath> initialPathsMap) {
134141
this();
135-
paths.setAll(initialPaths);
142+
143+
initialPathsMap.entrySet().stream().sorted((a, b) -> a.getKey().compareTo(b.getKey())).forEach(entry -> {
144+
String pathName = entry.getKey();
145+
HPath path = entry.getValue();
146+
path.setName(pathName);
147+
paths.add(path);
148+
});
136149
}
137150

138151
/**
@@ -222,12 +235,12 @@ public final DoubleProperty zoomScaleProperty() {
222235
return zoomScale;
223236
}
224237

225-
@DeserializedJSONTarget
238+
// @DeserializedJSONTarget
226239
public final void setZoomScale(@DeserializedJSONObjectValue(key = "zoom_scale") double value) {
227240
zoomScale.set(value);
228241
}
229242

230-
@SerializedJSONObjectValue(key = "zoom_scale")
243+
// @SerializedJSONObjectValue(key = "zoom_scale")
231244
public final double getZoomScale() {
232245
return zoomScale.get();
233246
}
@@ -236,12 +249,12 @@ public final DoubleProperty zoomTranslateXProperty() {
236249
return zoomTranslateX;
237250
}
238251

239-
@DeserializedJSONTarget
252+
// @DeserializedJSONTarget
240253
public final void setZoomTranslateX(@DeserializedJSONObjectValue(key = "zoom_translate_x") double value) {
241254
zoomTranslateX.set(value);
242255
}
243256

244-
@SerializedJSONObjectValue(key = "zoom_translate_x")
257+
// @SerializedJSONObjectValue(key = "zoom_translate_x")
245258
public final double getZoomTranslateX() {
246259
return zoomTranslateX.get();
247260
}
@@ -250,21 +263,30 @@ public final DoubleProperty zoomTranslateYProperty() {
250263
return zoomTranslateY;
251264
}
252265

253-
@DeserializedJSONTarget
266+
// @DeserializedJSONTarget
254267
public final void setZoomTranslateY(@DeserializedJSONObjectValue(key = "zoom_translate_y") double value) {
255268
zoomTranslateY.set(value);
256269
}
257270

258-
@SerializedJSONObjectValue(key = "zoom_translate_y")
271+
// @SerializedJSONObjectValue(key = "zoom_translate_y")
259272
public final double getZoomTranslateY() {
260273
return zoomTranslateY.get();
261274
}
262275

263-
@SerializedJSONObjectValue(key = "paths")
276+
// @SerializedJSONObjectValue(key = "paths")
264277
public final ObservableList<HPath> getPaths() {
265278
return paths;
266279
}
267280

281+
@SerializedJSONObjectValue(key = "paths")
282+
public final Map<String, HPath> getPathsMap() {
283+
Map<String, HPath> map = new HashMap<>(getPaths().size());
284+
for (HPath path : getPaths()) {
285+
map.put(path.getName(), path);
286+
}
287+
return map;
288+
}
289+
268290
public final ReadOnlyIntegerProperty selectedPathIndexProperty() {
269291
return selectedPathIndex.getReadOnlyProperty();
270292
}

app/src/main/java/org/team2363/helixnavigator/document/HPath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ public final StringProperty nameProperty() {
130130
return name;
131131
}
132132

133-
@DeserializedJSONTarget
133+
// @DeserializedJSONTarget
134134
public final void setName(@DeserializedJSONObjectValue(key = "name") String value) {
135135
name.set(value);
136136
}
137137

138-
@SerializedJSONObjectValue(key = "name")
138+
// @SerializedJSONObjectValue(key = "name")
139139
public final String getName() {
140140
return name.get();
141141
}

0 commit comments

Comments
 (0)