[7720] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.Component;
|
---|
| 7 |
|
---|
| 8 | import javax.swing.BoxLayout;
|
---|
| 9 | import javax.swing.Icon;
|
---|
| 10 | import javax.swing.JLabel;
|
---|
| 11 | import javax.swing.JPanel;
|
---|
| 12 | import javax.swing.JScrollPane;
|
---|
| 13 |
|
---|
[8211] | 14 | import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
---|
[7720] | 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | * Class to show user input dialog for notes. It sets up a
|
---|
| 19 | * simple label and text area to prompt for user input.
|
---|
| 20 | * @since 7720
|
---|
| 21 | */
|
---|
| 22 | public class NoteInputDialog extends ExtendedDialog {
|
---|
| 23 |
|
---|
[9078] | 24 | private final JosmTextArea textArea = new JosmTextArea();
|
---|
[7720] | 25 |
|
---|
| 26 | /**
|
---|
| 27 | * Construct the dialog with a title and button text. A cancel button is
|
---|
| 28 | * automatically added
|
---|
| 29 | * @param parent The parent GUI element
|
---|
| 30 | * @param title Translated string to display in the dialog's title bar
|
---|
| 31 | * @param buttonText Translated string to display on the action button
|
---|
| 32 | */
|
---|
| 33 | public NoteInputDialog(Component parent, String title, String buttonText) {
|
---|
[12279] | 34 | super(parent, title, buttonText, tr("Cancel"));
|
---|
[7720] | 35 | }
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * Displays the dialog to the user
|
---|
| 39 | * @param message Translated message to display to the user as input prompt
|
---|
| 40 | * @param icon Icon to display in the action button
|
---|
| 41 | */
|
---|
| 42 | public void showNoteDialog(String message, Icon icon) {
|
---|
| 43 | textArea.setRows(6);
|
---|
| 44 | textArea.setColumns(30);
|
---|
| 45 | textArea.setLineWrap(true);
|
---|
[8211] | 46 | textArea.setWrapStyleWord(true);
|
---|
[7720] | 47 | JScrollPane scrollPane = new JScrollPane(textArea);
|
---|
| 48 | scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); //without this the label gets pushed to the right
|
---|
| 49 |
|
---|
[8426] | 50 | JLabel label = new JLabel(message);
|
---|
| 51 | label.setLabelFor(textArea);
|
---|
| 52 |
|
---|
[7720] | 53 | JPanel contentPanel = new JPanel();
|
---|
| 54 | contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
|
---|
| 55 | contentPanel.add(label);
|
---|
| 56 | contentPanel.add(scrollPane);
|
---|
| 57 | setContent(contentPanel, false);
|
---|
[12280] | 58 | setButtonIcons(icon, ImageProvider.get("cancel"));
|
---|
[7720] | 59 |
|
---|
| 60 | showDialog();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /** Get the content of the text area
|
---|
| 64 | * @return Text input by user
|
---|
| 65 | */
|
---|
| 66 | public String getInputText() {
|
---|
| 67 | return textArea.getText();
|
---|
| 68 | }
|
---|
| 69 | }
|
---|