Skip to content

Commit b5dbee2

Browse files
committed
Restoring statuses to initial state after creating or loading notice-tree
1 parent f58b7da commit b5dbee2

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/com/temporaryteam/noticeditor/controller/NoticeController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import com.temporaryteam.noticeditor.io.ExportException;
2424
import com.temporaryteam.noticeditor.io.ExportStrategy;
2525
import com.temporaryteam.noticeditor.io.ExportStrategyHolder;
26-
import com.temporaryteam.noticeditor.model.NoticeItem;
27-
import com.temporaryteam.noticeditor.model.NoticeTree;
28-
import com.temporaryteam.noticeditor.model.NoticeTreeItem;
29-
import com.temporaryteam.noticeditor.model.PreviewStyles;
26+
import com.temporaryteam.noticeditor.model.*;
3027
import com.temporaryteam.noticeditor.view.Chooser;
3128
import com.temporaryteam.noticeditor.view.EditNoticeTreeCell;
3229
import java.util.ResourceBundle;
@@ -224,6 +221,7 @@ private void handleContextMenu(ActionEvent event) {
224221
private void handleNew(ActionEvent event) {
225222
rebuildTree(resources.getString("help"));
226223
fileSaved = null;
224+
NoticeStatus.load();
227225
}
228226

229227
@FXML
@@ -242,6 +240,7 @@ private void handleOpen(ActionEvent event) {
242240
createSearchBinding(noticeTree.getRoot());
243241
currentTreeItem = null;
244242
open();
243+
noticeSettingsController.updateStatuses();
245244
} catch (IOException | JSONException e) {
246245
logger.log(Level.SEVERE, null, e);
247246
}

src/com/temporaryteam/noticeditor/controller/NoticeSettingsController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void setNoticeController(NoticeController noticeController) {
4444
public void initialize(URL url, ResourceBundle rb) {
4545
NoticeStatus.add(rb.getString("normal"));
4646
NoticeStatus.add(rb.getString("important"));
47+
NoticeStatus.save();
4748

4849
choiceBoxNoticeStatus.setItems(NoticeStatus.asObservable());
4950
choiceBoxNoticeStatus.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@@ -58,12 +59,15 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
5859
open(null);
5960
}
6061

62+
public void updateStatuses() {
63+
choiceBoxNoticeStatus.setItems(NoticeStatus.asObservable());
64+
}
65+
6166
public void open(NoticeTreeItem item) {
6267
if (item == null || item.isBranch()) {
6368
choiceBoxNoticeStatus.getSelectionModel().clearSelection();
6469
settingsPane.setDisable(true);
6570
} else {
66-
choiceBoxNoticeStatus.setItems(NoticeStatus.asObservable());
6771
choiceBoxNoticeStatus.getSelectionModel().select(NoticeStatus.getStatusName(item.getStatus()));
6872
settingsPane.setDisable(false);
6973
}

src/com/temporaryteam/noticeditor/io/JsonFormat.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public NoticeTree importDocument() throws IOException, JSONException {
4242
String key = it.next().toString();
4343
NoticeStatus.add(key, status.getInt(key));
4444
}
45+
} else {
46+
NoticeStatus.load();
4547
}
4648

4749
return new NoticeTree(jsonToTree(json));

src/com/temporaryteam/noticeditor/model/NoticeStatus.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,33 @@
1313
* @author Maximillian M.
1414
*/
1515
public class NoticeStatus {
16-
private static final HashMap<String, Integer> map;
16+
private static HashMap<String, Integer> map;
1717
private static int lastIndex;
1818

19+
private static HashMap<String, Integer> mementoMap;
20+
private static int mementoIndex;
21+
1922
static {
2023
map = new HashMap<>();
2124
lastIndex = -1;
2225
}
2326

27+
/**
28+
* Saves statuses
29+
*/
30+
public static void save() {
31+
mementoIndex = lastIndex;
32+
mementoMap = (HashMap) map.clone();
33+
}
34+
35+
/**
36+
* Restores statuses to the saved state
37+
*/
38+
public static void load() {
39+
lastIndex = mementoIndex;
40+
map = mementoMap;
41+
}
42+
2443
/**
2544
* Associates the specified status with next status code
2645
* @param status Status name

0 commit comments

Comments
 (0)