001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.widgets; 003 004import javax.swing.JTextField; 005import javax.swing.text.Document; 006 007/** 008 * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all). 009 * @since 5886 010 */ 011public class JosmTextField extends JTextField { 012 013 /** 014 * Constructs a new <code>JosmTextField</code> that uses the given text 015 * storage model and the given number of columns. 016 * This is the constructor through which the other constructors feed. 017 * If the document is <code>null</code>, a default model is created. 018 * 019 * @param doc the text storage to use; if this is <code>null</code>, 020 * a default will be provided by calling the 021 * <code>createDefaultModel</code> method 022 * @param text the initial string to display, or <code>null</code> 023 * @param columns the number of columns to use to calculate 024 * the preferred width >= 0; if <code>columns</code> 025 * is set to zero, the preferred width will be whatever 026 * naturally results from the component implementation 027 * @exception IllegalArgumentException if <code>columns</code> < 0 028 */ 029 public JosmTextField(Document doc, String text, int columns) { 030 super(doc, text, columns); 031 TextContextualPopupMenu.enableMenuFor(this); 032 } 033 034 /** 035 * Constructs a new <code>JosmTextField</code> initialized with the 036 * specified text and columns. A default model is created. 037 * 038 * @param text the text to be displayed, or <code>null</code> 039 * @param columns the number of columns to use to calculate 040 * the preferred width; if columns is set to zero, the 041 * preferred width will be whatever naturally results from 042 * the component implementation 043 */ 044 public JosmTextField(String text, int columns) { 045 this(null, text, columns); 046 } 047 048 /** 049 * Constructs a new <code>JosmTextField</code> initialized with the 050 * specified text. A default model is created and the number of 051 * columns is 0. 052 * 053 * @param text the text to be displayed, or <code>null</code> 054 */ 055 public JosmTextField(String text) { 056 this(null, text, 0); 057 } 058 059 /** 060 * Constructs a new empty <code>JosmTextField</code> with the specified 061 * number of columns. 062 * A default model is created and the initial string is set to 063 * <code>null</code>. 064 * 065 * @param columns the number of columns to use to calculate 066 * the preferred width; if columns is set to zero, the 067 * preferred width will be whatever naturally results from 068 * the component implementation 069 */ 070 public JosmTextField(int columns) { 071 this(null, null, columns); 072 } 073 074 /** 075 * Constructs a new <code>JosmTextField</code>. A default model is created, 076 * the initial string is <code>null</code>, 077 * and the number of columns is set to 0. 078 */ 079 public JosmTextField() { 080 this(null, null, 0); 081 } 082}