package com.dwave.gui; import java.awt.event.FocusListener; import java.awt.event.FocusEvent; import java.util.StringTokenizer; import javax.swing.JTextField; import javax.swing.BorderFactory; import javax.swing.text.Document; public class DTextField extends JTextField implements FocusListener { /** * Constructs a new TextField. A default model is created, the initial * string is null, and the number of columns is set to 0. */ public DTextField() { this(null, null, 0); } /** * Constructs a new TextField initialized with the specified text. * A default model is created and the number of columns is 0. * * @param text the text to be displayed, or null */ public DTextField(String text) { this(null, text, 0); } /** * Constructs a new empty TextField with the specified number of columns. * A default model is created and the initial string is set to null. * * @param columns the number of columns to use to calculate * the preferred width. If columns is set to zero, the * preferred width will be whatever naturally results from * the component implementation. */ public DTextField(int columns) { this(null, null, columns); } /** * Constructs a new TextField initialized with the specified text * and columns. A default model is created. * * @param text the text to be displayed, or null * @param columns the number of columns to use to calculate * the preferred width. If columns is set to zero, the * preferred width will be whatever naturally results from * the component implementation. */ public DTextField(String text, int columns) { this(null, text, columns); } /** * Constructs a new DTextField that uses the given text storage * model and the given number of columns. This is the constructor * through which the other constructors feed. If the document is null, * a default model is created. * * @param doc the text storage to use. If this is null, a default * will be provided by calling the createDefaultModel method. * @param text the initial string to display, or null * @param columns the number of columns to use to calculate * the preferred width >= 0. If columns is set to zero, the * preferred width will be whatever naturally results from * the component implementation. * @exception IllegalArgumentException if columns < 0 */ public DTextField(Document doc, String text, int columns) { super(doc, text, columns); this.addFocusListener(this); this.setBorder(BorderFactory.createLoweredBevelBorder()); } /** * Invoked when a component gains the keyboard focus. */ public void focusGained(FocusEvent fe) { this.selectAll(); } /** * Invoked when a component loses the keyboard focus. */ public void focusLost(FocusEvent fe) {} }