use of org.mapton.api.MBookmark in project mapton by trixon.
the class BookmarksView method getParent.
private TreeItem<MBookmark> getParent(TreeItem<MBookmark> parent, String category) {
String[] categorySegments = StringUtils.split(category, "/");
StringBuilder sb = new StringBuilder();
for (String segment : categorySegments) {
sb.append(segment);
String path = sb.toString();
if (mBookmarkParents.containsKey(path)) {
parent = mBookmarkParents.get(path);
} else {
MBookmark bookmark = new MBookmark();
bookmark.setCategory(path);
bookmark.setName(segment);
parent.getChildren().add(parent = mBookmarkParents.computeIfAbsent(sb.toString(), k -> new TreeItem<>(bookmark)));
}
sb.append("/");
}
return parent;
}
use of org.mapton.api.MBookmark in project mapton by trixon.
the class FileImportAction method importGeo.
private void importGeo() throws IOException {
Geo geo = new Geo();
geo.read(mFile);
ArrayList<MBookmark> bookmarks = new ArrayList<>();
for (GeoPoint point : geo.getPoints()) {
MBookmark bookmark = new MBookmark();
bookmark.setName(point.getPointId());
bookmark.setCategory(point.getRemark());
bookmark.setLatitude(point.getX());
bookmark.setLongitude(point.getY());
bookmark.setZoom(0.999);
bookmarks.add(bookmark);
}
Point result = mManager.dbInsert(bookmarks);
mImports = result.x;
mErrors = result.y;
}
use of org.mapton.api.MBookmark in project mapton by trixon.
the class FileImportAction method importJson.
private void importJson() throws IOException {
Gson gson = new GsonBuilder().setVersion(1.0).setPrettyPrinting().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
String json = FileUtils.readFileToString(mFile, "UTF-8");
ArrayList<MBookmark> bookmarks = gson.fromJson(json, new TypeToken<ArrayList<MBookmark>>() {
}.getType());
Point result = mManager.dbInsert(bookmarks);
mImports = result.x;
mErrors = result.y;
}
use of org.mapton.api.MBookmark in project mapton by trixon.
the class BookmarkEditor method editBookmark.
public void editBookmark(final MBookmark aBookmark) {
SwingUtilities.invokeLater(() -> {
var newBookmark = aBookmark;
boolean add = aBookmark == null;
if (add) {
newBookmark = new MBookmark();
newBookmark.setZoom(Mapton.getEngine().getZoom());
newBookmark.setLatitude(Mapton.getEngine().getLockedLatitude());
newBookmark.setLongitude(Mapton.getEngine().getLockedLongitude());
}
final var bookmark = newBookmark;
var bookmarkPanel = new BookmarkPanel();
var d = new DialogDescriptor(bookmarkPanel, Dict.BOOKMARK.toString());
bookmarkPanel.setNotifyDescriptor(d);
bookmarkPanel.initFx(() -> {
bookmarkPanel.load(bookmark);
});
bookmarkPanel.setPreferredSize(SwingHelper.getUIScaledDim(300, 550));
if (DialogDescriptor.OK_OPTION == DialogDisplayer.getDefault().notify(d)) {
bookmarkPanel.save(bookmark);
Platform.runLater(() -> {
try {
if (add) {
mManager.dbInsert(bookmark);
} else {
bookmark.setTimeModified(new Timestamp(System.currentTimeMillis()));
mManager.dbUpdate(bookmark);
mManager.dbLoad();
}
} catch (ClassNotFoundException | SQLException ex) {
Exceptions.printStackTrace(ex);
}
});
}
});
}
use of org.mapton.api.MBookmark in project mapton by trixon.
the class BookmarkReport method getContent.
@Override
public ContainerTag getContent() {
final TreeMap<String, ArrayList<MBookmark>> bookmarkCategories = new TreeMap<>();
for (MBookmark bookmark : mManager.dbLoad("*", false)) {
bookmarkCategories.computeIfAbsent(bookmark.getCategory(), k -> new ArrayList<>()).add(bookmark);
}
ContainerTag html = html(head(title(mName)), body(h1(mName), hr(), div(each(bookmarkCategories.keySet(), category -> div(h2(category), table(tr(th(Dict.NAME.toString()), th(Dict.DESCRIPTION.toString()), th("URL"), th(Dict.LATITUDE.toString()), th(Dict.LONGITUDE.toString())), tbody(each(filter(mManager.dbLoad(), bookmark -> bookmark.getCategory().equals(category)), bookmark -> tr(td(bookmark.getName()), td(StringUtils.defaultString(bookmark.getDescription())), td(StringUtils.defaultString(bookmark.getUrl())), td(String.format("%.6f", bookmark.getLatitude())), td(String.format("%.6f", bookmark.getLongitude())))))))))));
return html;
}
Aggregations