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

Last change on this file since 17299 was 16435, checked in by simon04, 4 years ago

fix #18975 - NoteInputDialog: remember windows geometry

  • Property svn:eol-style set to native
File size: 2.5 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;
7import java.awt.Dimension;
8
9import javax.swing.BoxLayout;
10import javax.swing.Icon;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JScrollPane;
14
15import org.openstreetmap.josm.gui.util.WindowGeometry;
16import org.openstreetmap.josm.gui.widgets.JosmTextArea;
17import 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 */
24public 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}
Note: See TracBrowser for help on using the repository browser.