Search in sources :

Example 1 with MBookmark

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;
}
Also used : MBookmark(org.mapton.api.MBookmark)

Example 2 with MBookmark

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;
}
Also used : Geo(se.trixon.almond.util.io.Geo) GeoPoint(se.trixon.almond.util.io.GeoPoint) MBookmark(org.mapton.api.MBookmark) ArrayList(java.util.ArrayList) Point(java.awt.Point) GeoPoint(se.trixon.almond.util.io.GeoPoint)

Example 3 with MBookmark

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;
}
Also used : MBookmark(org.mapton.api.MBookmark) GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Point(java.awt.Point) GeoPoint(se.trixon.almond.util.io.GeoPoint)

Example 4 with MBookmark

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);
                }
            });
        }
    });
}
Also used : MBookmark(org.mapton.api.MBookmark) SQLException(java.sql.SQLException) DialogDescriptor(org.openide.DialogDescriptor) Timestamp(java.sql.Timestamp) BookmarkPanel(org.mapton.core.ui.bookmark.BookmarkPanel)

Example 5 with MBookmark

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;
}
Also used : MReportSystem(org.mapton.api.report.MReportSystem) Dict(se.trixon.almond.util.Dict) TreeMap(java.util.TreeMap) MBookmark(org.mapton.api.MBookmark) MBookmarkManager(org.mapton.api.MBookmarkManager) MReport(org.mapton.api.report.MReport) ServiceProvider(org.openide.util.lookup.ServiceProvider) TagCreator(j2html.TagCreator) StringUtils(org.apache.commons.lang3.StringUtils) ContainerTag(j2html.tags.ContainerTag) ArrayList(java.util.ArrayList) MBookmark(org.mapton.api.MBookmark) ArrayList(java.util.ArrayList) ContainerTag(j2html.tags.ContainerTag) TreeMap(java.util.TreeMap)

Aggregations

MBookmark (org.mapton.api.MBookmark)12 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)3 GeoPoint (se.trixon.almond.util.io.GeoPoint)3 LatLong (com.dlsc.gmapsfx.javascript.object.LatLong)2 MLatLon (org.mapton.api.MLatLon)2 LatLongBounds (com.dlsc.gmapsfx.javascript.object.LatLongBounds)1 Marker (com.dlsc.gmapsfx.javascript.object.Marker)1 MarkerOptions (com.dlsc.gmapsfx.javascript.object.MarkerOptions)1 GeocoderGeometry (com.dlsc.gmapsfx.service.geocoding.GeocoderGeometry)1 GeocoderStatus (com.dlsc.gmapsfx.service.geocoding.GeocoderStatus)1 GeocodingResult (com.dlsc.gmapsfx.service.geocoding.GeocodingResult)1 GeocodingService (com.dlsc.gmapsfx.service.geocoding.GeocodingService)1 GeocodingServiceCallback (com.dlsc.gmapsfx.service.geocoding.GeocodingServiceCallback)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 Coordinate (com.sothawo.mapjfx.Coordinate)1 MapLabel (com.sothawo.mapjfx.MapLabel)1 Marker (com.sothawo.mapjfx.Marker)1