From 76a63199c8d9053841b002bdc54d7494942be150 Mon Sep 17 00:00:00 2001 From: Jeroen Hoek Date: Tue, 5 May 2020 08:08:06 +0200 Subject: [PATCH] Re-add minimal dialogue --- .../josm/gridify/GridifyAction.java | 25 +-- .../gridify/ui/GridifySettingsDialog.java | 160 ++++++++++++++++++ 2 files changed, 173 insertions(+), 12 deletions(-) create mode 100644 src/nl/jeroenhoek/josm/gridify/ui/GridifySettingsDialog.java diff --git a/src/nl/jeroenhoek/josm/gridify/GridifyAction.java b/src/nl/jeroenhoek/josm/gridify/GridifyAction.java index 9ab4e7c..1b44396 100644 --- a/src/nl/jeroenhoek/josm/gridify/GridifyAction.java +++ b/src/nl/jeroenhoek/josm/gridify/GridifyAction.java @@ -4,6 +4,7 @@ import nl.jeroenhoek.josm.gridify.exception.GridifyException; import nl.jeroenhoek.josm.gridify.exception.UserInputException; import nl.jeroenhoek.josm.gridify.exception.UserCancelledException; +import nl.jeroenhoek.josm.gridify.ui.GridifySettingsDialog; import org.openstreetmap.josm.actions.JosmAction; import org.openstreetmap.josm.command.AddCommand; import org.openstreetmap.josm.command.ChangePropertyCommand; @@ -102,23 +103,23 @@ Collection performGridifyAction(DataSet dataSet) throws GridifyExceptio GridifySettings settings = new GridifySettings(); -// GridifySettingsDialog dialog = new GridifySettingsDialog(inputData, settings); -// dialog.showDialog(); -// -// // Only the OK button returns 1, the rest means 'Cancel' or a closed dialog window. -// if (dialog.getValue() != 1) { -// throw new UserCancelledException(); -// } + GridifySettingsDialog dialog = new GridifySettingsDialog(inputData, settings); + dialog.showDialog(); + + // Only the OK button returns 1, the rest means 'Cancel' or a closed dialog window. + if (dialog.getValue() != 1) { + throw new UserCancelledException(); + } GridExtrema extrema = inputData.getGridExtrema(); Collection commands = new ArrayList<>(); // Read the user provided settings. - int numRows = settings.getNumRows(); - int numColumns = settings.getNumColumns(); - Operation operation = settings.getOperation(); - boolean deleteSourceWay = settings.deleteSource(); - boolean copyTags = settings.copyTagsFromSource(); + int numRows = dialog.getRowCount(); + int numColumns = dialog.getColumnCount(); + Operation operation = dialog.getOperation(); + boolean deleteSourceWay = dialog.deleteSourceWay(); + boolean copyTags = dialog.copyTags(); // Update settings properties now that we are about to commence the operation. // This way the user gets to keep the last settings they entered. diff --git a/src/nl/jeroenhoek/josm/gridify/ui/GridifySettingsDialog.java b/src/nl/jeroenhoek/josm/gridify/ui/GridifySettingsDialog.java new file mode 100644 index 0000000..8efb12d --- /dev/null +++ b/src/nl/jeroenhoek/josm/gridify/ui/GridifySettingsDialog.java @@ -0,0 +1,160 @@ +// License: GPL. For details, see LICENSE file. +package nl.jeroenhoek.josm.gridify.ui; + +import nl.jeroenhoek.josm.gridify.GridifySettings; +import nl.jeroenhoek.josm.gridify.InputData; +import nl.jeroenhoek.josm.gridify.Operation; +import org.openstreetmap.josm.gui.ExtendedDialog; +import org.openstreetmap.josm.gui.MainApplication; + +import javax.swing.*; +import javax.swing.border.Border; +import java.awt.*; + +import static org.openstreetmap.josm.tools.I18n.tr; + +//import nl.jeroenhoek.josm.gridify.ui.GridSizePanel.Nudge; + +/** + * The modal dialog presented to the user when executing the Gridify action. + */ +public class GridifySettingsDialog extends ExtendedDialog { + private final InputData inputData; + private final GridifySettings settings; + +// private GridSizePanel gridSizePanel; +// private OperationChooser operationChooser; +// private SourceWayPanel sourceWayPanel; + + public GridifySettingsDialog(InputData inputData, GridifySettings settings) { + super(MainApplication.getMainFrame(), tr("Gridify preview"), tr("Gridify"), tr("Cancel")); + this.inputData = inputData; + this.settings = settings; + } + + @Override + public void setupDialog() { + final Insets insetsDefault = new Insets(0, 0, 10, 0); + final Insets insetsIndent = new Insets(0, 30, 10, 0); + final Border underline = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black); + + + //Preview preview = new Preview(inputData.getGridExtrema(), this); + JLabel preview = new JLabel("Preview"); + + JPanel rootPanel = new JPanel(); + setMinimumSize(new Dimension(550, 360)); + rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.X_AXIS)); + +// JPanel controlPanel = new JPanel(); +// controlPanel.setLayout(new GridBagLayout()); +// GridBagConstraints constraints = new GridBagConstraints(); +// constraints.fill = GridBagConstraints.HORIZONTAL; + +// JLabel operationChooserLabel = new JLabel(tr("Output shape")); +// operationChooserLabel.setBorder(underline); +// controlPanel.add(operationChooserLabel, constraints); + +// operationChooser = new OperationChooser(settings.getOperation()); +// JLabel operationChooser = new JLabel("Chooser"); +// +// constraints.gridy = 1; +// constraints.insets = insetsIndent; +// controlPanel.add(operationChooser, constraints); +// +// JLabel gridSizePanelLabel = new JLabel(tr("Grid size")); +// gridSizePanelLabel.setBorder(underline); +// constraints.gridy = 2; +// constraints.insets = insetsDefault; +// controlPanel.add(gridSizePanelLabel, constraints); +// +//// gridSizePanel = new GridSizePanel( +//// preview::updateRowsColumns, +//// settings.getNumRows(), +//// settings.getNumColumns() +//// ); +// JLabel gridSizePanel = new JLabel("Size"); +// +// constraints.gridy = 3; +// constraints.insets = insetsIndent; +// controlPanel.add(gridSizePanel, constraints); +// +// if (inputData.getSourceWay().isPresent()) { +// JLabel wayLabel = new JLabel(tr("Source way")); +// wayLabel.setBorder(underline); +// constraints.gridy = 4; +// constraints.insets = insetsDefault; +// controlPanel.add(wayLabel, constraints); +// +// // Always check the 'delete source way' option when a new way is used as template. +// // It tends to have been drawn specifically to cut up. +// boolean deleteSourceWay = inputData.getSourceWay().get().isNew(); +// +//// sourceWayPanel = new SourceWayPanel( +//// settings.copyTagsFromSource(), +//// deleteSourceWay || settings.deleteSource() +//// ); +// JLabel sourceWayPanel = new JLabel("Source"); +// constraints.gridy = 5; +// constraints.insets = insetsIndent; +// controlPanel.add(sourceWayPanel, constraints); +// } + + rootPanel.add(new JLabel("Test")); + rootPanel.add(Box.createHorizontalGlue()); + + rootPanel.add(preview); + + setContent(rootPanel, false); + setButtonIcons("ok.png", "cancel.png"); + setDefaultButton(1); + + super.setupDialog(); + + // gridSizePanel.requestFocusInWindow(); + } + + @Override + public Dimension getMinimumSize() { + return getPreferredSize(); + } + + public int getRowCount() { + return settings.getNumRows(); +// return gridSizePanel == null +// ? settings.getNumRows() +// : gridSizePanel.getRowCount(); + } + + public int getColumnCount() { + return settings.getNumColumns(); +// return gridSizePanel == null +// ? settings.getNumColumns() +// : gridSizePanel.getColumnCount(); + } + +// public void nudgeRowCount(Nudge direction) { +// if (gridSizePanel != null) { +// gridSizePanel.nudgeRowCount(direction); +// } +// } +// +// public void nudgeColumnCount(Nudge direction) { +// if (gridSizePanel != null) { +// gridSizePanel.nudgeColumnCount(direction); +// } +// } + + public Operation getOperation() { + return Operation.BLOCKS; +// return operationChooser.getSelected(); + } + + public boolean copyTags() { + return inputData.getSourceWay().isPresent();// && sourceWayPanel.copyTags(); + } + + public boolean deleteSourceWay() { + return inputData.getSourceWay().isPresent();// && sourceWayPanel.deleteSourceWay(); + } +}