001package org.jdesktop.swingx; 002 003import java.awt.Color; 004import java.awt.Component; 005import java.awt.Insets; 006import java.util.List; 007 008import javax.swing.JTextField; 009 010import org.jdesktop.beans.JavaBean; 011import org.jdesktop.swingx.prompt.BuddySupport; 012import org.jdesktop.swingx.prompt.PromptSupport; 013import org.jdesktop.swingx.prompt.BuddySupport.Position; 014import org.jdesktop.swingx.prompt.PromptSupport.FocusBehavior; 015 016/** 017 * {@link JTextField}, with integrated support for prompts and buddies. 018 * 019 * @see PromptSupport 020 * @see BuddySupport 021 * @author Peter Weishapl <petw@gmx.net> 022 * 023 */ 024@JavaBean 025public class JXTextField extends JTextField { 026 public JXTextField() { 027 this(null); 028 } 029 030 public JXTextField(String promptText) { 031 this(promptText, null); 032 } 033 034 public JXTextField(String promptText, Color promptForeground) { 035 this(promptText, promptForeground, null); 036 } 037 038 public JXTextField(String promptText, Color promptForeground, 039 Color promptBackground) { 040 PromptSupport.init(promptText, promptForeground, promptBackground, 041 this); 042 } 043 044 /** 045 * @see PromptSupport#getFocusBehavior(javax.swing.text.JTextComponent) 046 */ 047 public FocusBehavior getFocusBehavior() { 048 return PromptSupport.getFocusBehavior(this); 049 } 050 051 /** 052 * @see PromptSupport#getPrompt(javax.swing.text.JTextComponent) 053 */ 054 public String getPrompt() { 055 return PromptSupport.getPrompt(this); 056 } 057 058 /** 059 * @see PromptSupport#getForeground(javax.swing.text.JTextComponent) 060 */ 061 public Color getPromptForeground() { 062 return PromptSupport.getForeground(this); 063 } 064 065 /** 066 * @see PromptSupport#getForeground(javax.swing.text.JTextComponent) 067 */ 068 public Color getPromptBackground() { 069 return PromptSupport.getBackground(this); 070 } 071 072 /** 073 * @see PromptSupport#getFontStyle(javax.swing.text.JTextComponent) 074 */ 075 public Integer getPromptFontStyle() { 076 return PromptSupport.getFontStyle(this); 077 } 078 079 /** 080 * @see PromptSupport#getFocusBehavior(javax.swing.text.JTextComponent) 081 */ 082 public void setFocusBehavior(FocusBehavior focusBehavior) { 083 PromptSupport.setFocusBehavior(focusBehavior, this); 084 } 085 086 /** 087 * @see PromptSupport#setPrompt(String, javax.swing.text.JTextComponent) 088 */ 089 public void setPrompt(String labelText) { 090 PromptSupport.setPrompt(labelText, this); 091 } 092 093 /** 094 * @see PromptSupport#setForeground(Color, javax.swing.text.JTextComponent) 095 */ 096 public void setPromptForeground(Color promptTextColor) { 097 PromptSupport.setForeground(promptTextColor, this); 098 } 099 100 /** 101 * @see PromptSupport#setBackground(Color, javax.swing.text.JTextComponent) 102 */ 103 public void setPromptBackround(Color promptTextColor) { 104 PromptSupport.setBackground(promptTextColor, this); 105 } 106 107 /** 108 * @see PromptSupport#setFontStyle(Integer, javax.swing.text.JTextComponent) 109 */ 110 public void setPromptFontStyle(Integer fontStyle) { 111 PromptSupport.setFontStyle(fontStyle, this); 112 } 113 114 /** 115 * @see BuddySupport#setOuterMargin(JTextField, Insets) 116 */ 117 public void setOuterMargin(Insets margin) { 118 BuddySupport.setOuterMargin(this, margin); 119 } 120 121 /** 122 * @see BuddySupport#getOuterMargin(JTextField) 123 */ 124 public Insets getOuterMargin() { 125 return BuddySupport.getOuterMargin(this); 126 } 127 128 /** 129 * @see BuddySupport#add(Component, Position, JTextField) 130 */ 131 public void addBuddy(Component buddy, Position pos) { 132 BuddySupport.add(buddy, pos, this); 133 } 134 135 /** 136 * @see BuddySupport#addGap(int, Position, JTextField) 137 */ 138 public void addGap(int width, Position pos) { 139 BuddySupport.addGap(width, pos, this); 140 } 141 142 /** 143 * @see BuddySupport#getBuddies(Position, JTextField) 144 */ 145 public List<Component> getBuddies(Position pos) { 146 return BuddySupport.getBuddies(pos, this); 147 } 148 149 /** 150 * @see BuddySupport#removeAll(JTextField) 151 */ 152 public void removeAllBuddies() { 153 BuddySupport.removeAll(this); 154 } 155}