Search in sources :

Example 1 with MLocalGrid

use of org.mapton.api.MLocalGrid in project mapton by trixon.

the class FileExportAction method getAction.

@Override
public Action getAction(Node owner) {
    FxActionSwing action = new FxActionSwing(Dict.EXPORT.toString(), () -> {
        ArrayList<MLocalGrid> selectedGrids = new ArrayList<>();
        mManager.getItems().stream().filter((grid) -> (grid.isVisible())).forEachOrdered((grid) -> {
            selectedGrids.add(grid);
        });
        if (!selectedGrids.isEmpty()) {
            SimpleDialog.clearFilters();
            SimpleDialog.addFilters("grid");
            SimpleDialog.setFilter("grid");
            final String dialogTitle = String.format("%s %s", Dict.EXPORT.toString(), mTitle.toLowerCase());
            SimpleDialog.setTitle(dialogTitle);
            if (mFile == null) {
                SimpleDialog.setPath(FileUtils.getUserDirectory());
            } else {
                SimpleDialog.setPath(mFile.getParentFile());
                SimpleDialog.setSelectedFile(new File(""));
            }
            if (SimpleDialog.saveFile(new String[] { "grid" })) {
                new Thread(() -> {
                    mFile = SimpleDialog.getPath();
                    try {
                        mManager.gridExport(mFile, selectedGrids);
                        NotificationDisplayer.getDefault().notify(Dict.OPERATION_COMPLETED.toString(), MNotificationIcons.getInformationIcon(), dialogTitle, null, NotificationDisplayer.Priority.LOW);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }).start();
            }
        }
    });
    action.setGraphic(MaterialIcon._Content.SAVE.getImageView(getIconSizeToolBarInt()));
    return action;
}
Also used : NotificationDisplayer(org.openide.awt.NotificationDisplayer) SimpleDialog(se.trixon.almond.util.swing.dialogs.SimpleDialog) Node(javafx.scene.Node) Action(org.controlsfx.control.action.Action) MaterialIcon(se.trixon.almond.util.icons.material.MaterialIcon) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) ArrayList(java.util.ArrayList) MLocalGrid(org.mapton.api.MLocalGrid) MNotificationIcons(org.mapton.api.MNotificationIcons) Dict(se.trixon.almond.util.Dict) Exceptions(org.openide.util.Exceptions) Mapton.getIconSizeToolBarInt(org.mapton.api.Mapton.getIconSizeToolBarInt) FxActionSwing(se.trixon.almond.util.fx.FxActionSwing) FxActionSwing(se.trixon.almond.util.fx.FxActionSwing) ArrayList(java.util.ArrayList) MLocalGrid(org.mapton.api.MLocalGrid) IOException(java.io.IOException) File(java.io.File)

Example 2 with MLocalGrid

use of org.mapton.api.MLocalGrid in project mapton by trixon.

the class LocalGridEditor method edit.

public void edit(final MLocalGrid aLocalGrid) {
    SwingUtilities.invokeLater(() -> {
        MLocalGrid newLocalGrid = aLocalGrid;
        boolean add = aLocalGrid == null;
        if (add) {
            newLocalGrid = new MLocalGrid();
        }
        final MLocalGrid localGrid = newLocalGrid;
        LocalGridPanel localGridPanel = new LocalGridPanel();
        DialogDescriptor d = new DialogDescriptor(localGridPanel, MDict.GRID.toString());
        localGridPanel.setNotifyDescriptor(d);
        localGridPanel.initFx(() -> {
            localGridPanel.load(localGrid);
        });
        localGridPanel.setPreferredSize(SwingHelper.getUIScaledDim(600, 380));
        if (DialogDescriptor.OK_OPTION == DialogDisplayer.getDefault().notify(d)) {
            Platform.runLater(() -> {
                localGridPanel.save(localGrid);
                if (add) {
                    mManager.getItems().add(localGrid);
                }
                FXCollections.sort(mManager.getItems(), (MLocalGrid o1, MLocalGrid o2) -> o1.getName().compareTo(o2.getName()));
            });
        }
    });
}
Also used : MLocalGrid(org.mapton.api.MLocalGrid) DialogDescriptor(org.openide.DialogDescriptor)

Aggregations

MLocalGrid (org.mapton.api.MLocalGrid)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Node (javafx.scene.Node)1 FileUtils (org.apache.commons.io.FileUtils)1 Action (org.controlsfx.control.action.Action)1 MNotificationIcons (org.mapton.api.MNotificationIcons)1 Mapton.getIconSizeToolBarInt (org.mapton.api.Mapton.getIconSizeToolBarInt)1 DialogDescriptor (org.openide.DialogDescriptor)1 NotificationDisplayer (org.openide.awt.NotificationDisplayer)1 Exceptions (org.openide.util.Exceptions)1 Dict (se.trixon.almond.util.Dict)1 FxActionSwing (se.trixon.almond.util.fx.FxActionSwing)1 MaterialIcon (se.trixon.almond.util.icons.material.MaterialIcon)1 SimpleDialog (se.trixon.almond.util.swing.dialogs.SimpleDialog)1