Skip to content

Commit

Permalink
Fix long descriptions on upload
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <tsmock@meta.com>
  • Loading branch information
tsmock committed May 30, 2024
1 parent c05029a commit fb5ac8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -114,7 +115,7 @@ public CurrentTaskPanel() {
final var gbc = GBC.eol();
this.panel.add(this.idLabel, gbc);
this.panel.add(new JLabel(tr("Instructions: ")), gbc);
gbc.fill(GBC.BOTH);
gbc.fill(GridBagConstraints.BOTH);
this.panel.add(this.instructionPane, gbc);
this.panel.add(this.cooperativeWork, gbc);
super.createLayout(this.panel.getVerticalScrollPane(), false, sideButtons);
Expand Down Expand Up @@ -204,8 +205,8 @@ private void refreshPanel() {
&& OsmDataManager.getInstance().getEditDataSet() != null) {
cooperativePanel.add(new JLabel(tr("Tag Updates")), GBC.eol());
final var table = new TagChangeTable();
cooperativePanel.add(table.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
cooperativePanel.add(table, GBC.eol().fill(GBC.HORIZONTAL));
cooperativePanel.add(table.getTableHeader(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
cooperativePanel.add(table, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
for (var updates : taskCooperativeWork.updates()) {
var row = 0;
final var current = OsmDataManager.getInstance().getEditDataSet().getPrimitiveById(updates.osmId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.openstreetmap.josm.plugins.maproulette.gui.task.current.CurrentTaskPanel.getSelections;
import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -18,6 +19,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Expand All @@ -34,8 +36,7 @@
import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.gui.widgets.JosmEditorPane;
import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
import org.openstreetmap.josm.plugins.maproulette.api.TaskAPI;
import org.openstreetmap.josm.plugins.maproulette.api.enums.TaskStatus;
import org.openstreetmap.josm.plugins.maproulette.api.model.ClusteredPoint;
Expand Down Expand Up @@ -104,13 +105,17 @@ public boolean checkUpload(APIDataSet apiDataSet) {
ConditionalOptionPaneUtil.startBulkOperation(PREF_CHECK_IF_FINISHED);
for (var task : possibleTasks) {
if (ids.containsAll(TaskPrimitives.getPrimitiveIds(task))) {
final var descriptivePanel = createDescriptivePanel(task, apiDataSet);
final var didFix = ConditionalOptionPaneUtil.showConfirmationDialog(PREF_CHECK_IF_FINISHED,
MainApplication.getMainFrame(), descriptivePanel,
tr("Did you finish the following MapRoulette Task: {0}?", task.id()),
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_OPTION);
if (didFix) {
final var doc = (HTMLDocument) ((JosmEditorPane) descriptivePanel.getComponent(1)).getDocument();
final var descriptivePanel = GuiHelper
.runInEDTAndWaitAndReturn(() -> createDescriptivePanel(task, apiDataSet));
Objects.requireNonNull(descriptivePanel);
final var didFix = GuiHelper.runInEDTAndWaitAndReturn(
() -> ConditionalOptionPaneUtil.showConfirmationDialog(PREF_CHECK_IF_FINISHED,
MainApplication.getMainFrame(), descriptivePanel,
tr("Did you finish the following MapRoulette Task: {0}?", task.id()),
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_OPTION));
if (Boolean.TRUE.equals(didFix)) {
final var doc = (HTMLDocument) ((JMultilineLabel) descriptivePanel.getComponent(1)).getDocument();
ModifiedObjects.addModifiedTask(
new ModifiedTask(task, TaskStatus.FIXED, null, null, null, getSelections(doc)));
}
Expand Down Expand Up @@ -163,14 +168,11 @@ private static Long getPrimitiveId(TaskClusteredPoint point) {
return null;
}

private static JPanel createDescriptivePanel(Task task, APIDataSet dataSet) {
final var panel = new VerticallyScrollablePanel(new GridBagLayout());
final var gbc = GBC.eol().fill(GBC.HORIZONTAL);
final var instructionPane = new JosmEditorPane();
JosmEditorPane.makeJLabelLike(instructionPane, false);
instructionPane.setText(MRGuiHelper.getInstructionText(task));
panel.add(new JLabel(tr("Instructions:")), gbc);
panel.add(instructionPane, gbc);
private static JComponent createDescriptivePanel(Task task, APIDataSet dataSet) {
final var panel = new JPanel(new GridBagLayout());
final var instructionPane = new JMultilineLabel(MRGuiHelper.getInstructionText(task));
panel.add(new JLabel(tr("Instructions:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
panel.add(instructionPane, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
final var map = TaskPrimitives.getPrimitiveIdMap(task);
for (var taskPrimitive : task.geometries().allPrimitives()) {
if (taskPrimitive.isTagged()) {
Expand All @@ -191,9 +193,9 @@ private static JPanel createDescriptivePanel(Task task, APIDataSet dataSet) {
table.setValueAt(taskPrimitive.get(key), row, 1);
table.setValueAt(osmPrimitive.get(key), row, 2);
}
panel.add(new JSeparator(), gbc);
panel.add(new JLabel(tr("Changes for {0}", id)), gbc);
panel.add(new JScrollPane(table), gbc);
panel.add(new JSeparator(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
panel.add(new JLabel(tr("Changes for {0}", id)), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
panel.add(new JScrollPane(table), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
}
}
}
Expand Down

0 comments on commit fb5ac8c

Please sign in to comment.