source: josm/trunk/src/org/openstreetmap/josm/gui/NoteInputDialog.java@ 18959

Last change on this file since 18959 was 18918, checked in by taylor.smock, 6 months ago

Fix #23290: Validate the regions a tag is expected to be in (patch by Sarabjeet108, modified)

Modifications are as follows:

  • Allow the use of the new region attributes for keys inside a preset
  • Basic tests

regions comes from Vespucci's extensions: https://vespucci.io/tutorials/presets/#extensions

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.awt.Dimension;
8
9import javax.swing.BoxLayout;
10import javax.swing.Icon;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JScrollPane;
14
15import org.openstreetmap.josm.gui.util.WindowGeometry;
16import org.openstreetmap.josm.gui.widgets.JosmTextArea;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Class to show user input dialog for notes. It sets up a
21 * simple label and text area to prompt for user input.
22 * @since 7720
23 */
24public class NoteInputDialog extends ExtendedDialog {
25
26 private final JosmTextArea textArea = new JosmTextArea();
27
28 /**
29 * Construct the dialog with a title and button text. A cancel button is
30 * automatically added
31 * @param parent The parent GUI element
32 * @param title Translated string to display in the dialog's title bar
33 * @param buttonText Translated string to display on the action button
34 */
35 public NoteInputDialog(Component parent, String title, String buttonText) {
36 super(parent, title, buttonText, tr("Cancel"));
37 setRememberWindowGeometry(getClass().getName() + ".geometry",
38 WindowGeometry.centerInWindow(MainApplication.getMainFrame(), new Dimension(400, 300)));
39 }
40
41 /**
42 * Displays the dialog to the user
43 * @param message Translated message to display to the user as input prompt
44 * @param icon Icon to display in the action button
45 */
46 public void showNoteDialog(String message, Icon icon) {
47 showNoteDialog(message, icon, "");
48 }
49
50 /**
51 * Displays the dialog to the user
52 * @param message Translated message to display to the user as input prompt
53 * @param icon Icon to display in the action button
54 * @param text Default text of the note's comment
55 * @since 18839
56 */
57 public void showNoteDialog(String message, Icon icon, String text) {
58 textArea.setText(text);
59 textArea.setRows(6);
60 textArea.setColumns(30);
61 textArea.setLineWrap(true);
62 textArea.setWrapStyleWord(true);
63 JScrollPane scrollPane = new JScrollPane(textArea);
64 scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); //without this the label gets pushed to the right
65
66 JLabel label = new JLabel(message);
67 label.setLabelFor(textArea);
68
69 JPanel contentPanel = new JPanel();
70 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
71 contentPanel.add(label);
72 contentPanel.add(scrollPane);
73 setContent(contentPanel, false);
74 setButtonIcons(icon, ImageProvider.get("cancel"));
75
76 showDialog();
77 }
78
79 /** Get the content of the text area
80 * @return Text input by user
81 */
82 public String getInputText() {
83 return textArea.getText();
84 }
85}
Note: See TracBrowser for help on using the repository browser.