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

Last change on this file since 8038 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 2.1 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;
7
8import javax.swing.BoxLayout;
9import javax.swing.Icon;
10import javax.swing.JLabel;
11import javax.swing.JPanel;
12import javax.swing.JScrollPane;
13import javax.swing.JTextArea;
14
15import 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 */
22public class NoteInputDialog extends ExtendedDialog {
23
24 private JTextArea textArea = new JTextArea();
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) {
34 super(parent, title, new String[] {buttonText, tr("Cancel")});
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 JLabel label = new JLabel(message);
44 textArea.setRows(6);
45 textArea.setColumns(30);
46 textArea.setLineWrap(true);
47 JScrollPane scrollPane = new JScrollPane(textArea);
48 scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); //without this the label gets pushed to the right
49
50 JPanel contentPanel = new JPanel();
51 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
52 contentPanel.add(label);
53 contentPanel.add(scrollPane);
54 setContent(contentPanel, false);
55 setButtonIcons(new Icon[] {icon, ImageProvider.get("cancel.png")});
56
57 showDialog();
58 }
59
60 /** Get the content of the text area
61 * @return Text input by user
62 */
63 public String getInputText() {
64 return textArea.getText();
65 }
66
67}
Note: See TracBrowser for help on using the repository browser.