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

Last change on this file since 12051 was 9078, checked in by Don-vip, 8 years ago

sonar - Immutable Field

  • Property svn:eol-style set to native
File size: 2.2 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;
13
14import org.openstreetmap.josm.gui.widgets.JosmTextArea;
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 final JosmTextArea textArea = new JosmTextArea();
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 textArea.setRows(6);
44 textArea.setColumns(30);
45 textArea.setLineWrap(true);
46 textArea.setWrapStyleWord(true);
47 JScrollPane scrollPane = new JScrollPane(textArea);
48 scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); //without this the label gets pushed to the right
49
50 JLabel label = new JLabel(message);
51 label.setLabelFor(textArea);
52
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);
58 setButtonIcons(new Icon[] {icon, ImageProvider.get("cancel.png")});
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
70}
Note: See TracBrowser for help on using the repository browser.