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 | import java.awt.Dimension;
|
---|
8 |
|
---|
9 | import javax.swing.BoxLayout;
|
---|
10 | import javax.swing.Icon;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JScrollPane;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.gui.util.WindowGeometry;
|
---|
16 | import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
---|
17 | import 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 | */
|
---|
24 | public 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 | textArea.setRows(6);
|
---|
48 | textArea.setColumns(30);
|
---|
49 | textArea.setLineWrap(true);
|
---|
50 | textArea.setWrapStyleWord(true);
|
---|
51 | JScrollPane scrollPane = new JScrollPane(textArea);
|
---|
52 | scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); //without this the label gets pushed to the right
|
---|
53 |
|
---|
54 | JLabel label = new JLabel(message);
|
---|
55 | label.setLabelFor(textArea);
|
---|
56 |
|
---|
57 | JPanel contentPanel = new JPanel();
|
---|
58 | contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
|
---|
59 | contentPanel.add(label);
|
---|
60 | contentPanel.add(scrollPane);
|
---|
61 | setContent(contentPanel, false);
|
---|
62 | setButtonIcons(icon, ImageProvider.get("cancel"));
|
---|
63 |
|
---|
64 | showDialog();
|
---|
65 | }
|
---|
66 |
|
---|
67 | /** Get the content of the text area
|
---|
68 | * @return Text input by user
|
---|
69 | */
|
---|
70 | public String getInputText() {
|
---|
71 | return textArea.getText();
|
---|
72 | }
|
---|
73 | }
|
---|