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; 013import javax.swing.JTextArea; 014 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 JTextArea textArea = new JTextArea(); 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 JLabel label = new JLabel(message); 044 textArea.setRows(6); 045 textArea.setColumns(30); 046 textArea.setLineWrap(true); 047 JScrollPane scrollPane = new JScrollPane(textArea); 048 scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); //without this the label gets pushed to the right 049 050 JPanel contentPanel = new JPanel(); 051 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); 052 contentPanel.add(label); 053 contentPanel.add(scrollPane); 054 setContent(contentPanel, false); 055 setButtonIcons(new Icon[] {icon, ImageProvider.get("cancel.png")}); 056 057 showDialog(); 058 } 059 060 /** Get the content of the text area 061 * @return Text input by user 062 */ 063 public String getInputText() { 064 return textArea.getText(); 065 } 066 067}