001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.Component;
007
008import javax.swing.BoxLayout;
009import javax.swing.Icon;
010import javax.swing.JLabel;
011import javax.swing.JPanel;
012import javax.swing.JScrollPane;
013
014import org.openstreetmap.josm.gui.widgets.JosmTextArea;
015import org.openstreetmap.josm.tools.ImageProvider;
016
017/**
018 * Class to show user input dialog for notes. It sets up a
019 * simple label and text area to prompt for user input.
020 * @since 7720
021 */
022public class NoteInputDialog extends ExtendedDialog {
023
024    private final JosmTextArea textArea = new JosmTextArea();
025
026    /**
027     * Construct the dialog with a title and button text. A cancel button is
028     * automatically added
029     * @param parent The parent GUI element
030     * @param title Translated string to display in the dialog's title bar
031     * @param buttonText Translated string to display on the action button
032     */
033    public NoteInputDialog(Component parent, String title, String buttonText) {
034        super(parent, title, new String[] {buttonText, tr("Cancel")});
035    }
036
037    /**
038     * Displays the dialog to the user
039     * @param message Translated message to display to the user as input prompt
040     * @param icon Icon to display in the action button
041     */
042    public void showNoteDialog(String message, Icon icon) {
043        textArea.setRows(6);
044        textArea.setColumns(30);
045        textArea.setLineWrap(true);
046        textArea.setWrapStyleWord(true);
047        JScrollPane scrollPane = new JScrollPane(textArea);
048        scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); //without this the label gets pushed to the right
049
050        JLabel label = new JLabel(message);
051        label.setLabelFor(textArea);
052
053        JPanel contentPanel = new JPanel();
054        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
055        contentPanel.add(label);
056        contentPanel.add(scrollPane);
057        setContent(contentPanel, false);
058        setButtonIcons(new Icon[] {icon, ImageProvider.get("cancel.png")});
059
060        showDialog();
061    }
062
063    /** Get the content of the text area
064     * @return Text input by user
065     */
066    public String getInputText() {
067        return textArea.getText();
068    }
069
070}