Package org.jdesktop.swingx.plaf
Class PromptTextUI
- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.TextUI
-
- org.jdesktop.swingx.plaf.PromptTextUI
-
- Direct Known Subclasses:
PromptTextAreaUI,PromptTextFieldUI
public abstract class PromptTextUI extends javax.swing.plaf.TextUIAbstract
TextUIclass that delegates most work to anotherTextUIand additionally renders a prompt text as specified in theJTextComponents client properties byPromptSupport.Subclasses of this class must provide a prompt component used for rendering the prompt text.
- Author:
- Peter Weishapl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classPromptTextUI.PainterHighlighter
-
Field Summary
Fields Modifier and Type Field Description protected javax.swing.plaf.TextUIdelegateDelegate the hard work to this object.protected javax.swing.text.JTextComponentpromptComponentThis component ist painted when rendering the prompt text.
-
Constructor Summary
Constructors Constructor Description PromptTextUI(javax.swing.plaf.TextUI delegate)Creates a newPromptTextUIwhich delegates most work to anotherTextUI.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancontains(javax.swing.JComponent c, int x, int y)protected abstract javax.swing.text.JTextComponentcreatePromptComponent()Creates a component which should be used to render the prompt text.voiddamageRange(javax.swing.text.JTextComponent t, int p0, int p1)voiddamageRange(javax.swing.text.JTextComponent t, int p0, int p1, javax.swing.text.Position.Bias firstBias, javax.swing.text.Position.Bias secondBias)booleanequals(java.lang.Object obj)javax.accessibility.AccessiblegetAccessibleChild(javax.swing.JComponent c, int i)intgetAccessibleChildrenCount(javax.swing.JComponent c)intgetBaseline(javax.swing.JComponent c, int width, int height)Tries to callComponentUI#getBaseline(int, int)on the delegate via Reflection.javax.swing.text.EditorKitgetEditorKit(javax.swing.text.JTextComponent t)java.awt.DimensiongetMaximumSize(javax.swing.JComponent c)java.awt.DimensiongetMinimumSize(javax.swing.JComponent c)intgetNextVisualPositionFrom(javax.swing.text.JTextComponent t, int pos, javax.swing.text.Position.Bias b, int direction, javax.swing.text.Position.Bias[] biasRet)java.awt.DimensiongetPreferredSize(javax.swing.JComponent c)WhenshouldPaintPrompt(JTextComponent)returns true, the prompt component is retrieved by callinggetPromptComponent(JTextComponent)and it's preferred size is returned.javax.swing.text.JTextComponentgetPromptComponent(javax.swing.text.JTextComponent txt)Creates a label component, if none has already been created.javax.swing.text.ViewgetRootView(javax.swing.text.JTextComponent t)java.lang.StringgetToolTipText(javax.swing.text.JTextComponent t, java.awt.Point pt)inthashCode()voidinstallUI(javax.swing.JComponent c)Calls TextUI#installUI(JComponent) on the delegate and installs a focus listener oncwhich repaints the component when it gains or loses the focus.java.awt.RectanglemodelToView(javax.swing.text.JTextComponent t, int pos)CallsmodelToView(JTextComponent, int, Bias)withPosition.Bias.Forward.java.awt.RectanglemodelToView(javax.swing.text.JTextComponent t, int pos, javax.swing.text.Position.Bias bias)Delegate whenshouldPaintPrompt(JTextComponent)returns false.voidpaint(java.awt.Graphics g, javax.swing.JComponent c)Delegates painting whenshouldPaintPrompt(JTextComponent)returns false.protected voidpaintPromptComponent(java.awt.Graphics g, javax.swing.text.JTextComponent txt)booleanshouldPaintPrompt(javax.swing.text.JTextComponent txt)Returns if the prompt or the text field should be painted, depending on the state oftxt.java.lang.StringtoString()voiduninstallUI(javax.swing.JComponent c)Delegates, then uninstalls the focus listener.voidupdate(java.awt.Graphics g, javax.swing.JComponent c)Calls super.update(Graphics, JComponent), which in turn calls the paint method of this object.intviewToModel(javax.swing.text.JTextComponent t, java.awt.Point pt)intviewToModel(javax.swing.text.JTextComponent t, java.awt.Point pt, javax.swing.text.Position.Bias[] biasReturn)
-
-
-
Constructor Detail
-
PromptTextUI
public PromptTextUI(javax.swing.plaf.TextUI delegate)
Creates a newPromptTextUIwhich delegates most work to anotherTextUI.- Parameters:
delegate-
-
-
Method Detail
-
createPromptComponent
protected abstract javax.swing.text.JTextComponent createPromptComponent()
Creates a component which should be used to render the prompt text.- Returns:
-
installUI
public void installUI(javax.swing.JComponent c)
Calls TextUI#installUI(JComponent) on the delegate and installs a focus listener oncwhich repaints the component when it gains or loses the focus.- Overrides:
installUIin classjavax.swing.plaf.ComponentUI
-
uninstallUI
public void uninstallUI(javax.swing.JComponent c)
Delegates, then uninstalls the focus listener.- Overrides:
uninstallUIin classjavax.swing.plaf.ComponentUI
-
getPromptComponent
public javax.swing.text.JTextComponent getPromptComponent(javax.swing.text.JTextComponent txt)
Creates a label component, if none has already been created. Sets the prompt components properties to reflect the givenJTextComponents properties and returns it.- Parameters:
txt-- Returns:
- the adjusted prompt component
-
getPreferredSize
public java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
WhenshouldPaintPrompt(JTextComponent)returns true, the prompt component is retrieved by callinggetPromptComponent(JTextComponent)and it's preferred size is returned. Otherwise supergetPreferredSize(JComponent)is called.- Overrides:
getPreferredSizein classjavax.swing.plaf.ComponentUI
-
paint
public void paint(java.awt.Graphics g, javax.swing.JComponent c)Delegates painting whenshouldPaintPrompt(JTextComponent)returns false. Otherwise the prompt component is retrieved by callinggetPromptComponent(JTextComponent)and painted. Then the caret of the given text component is painted.- Overrides:
paintin classjavax.swing.plaf.ComponentUI
-
paintPromptComponent
protected void paintPromptComponent(java.awt.Graphics g, javax.swing.text.JTextComponent txt)
-
shouldPaintPrompt
public boolean shouldPaintPrompt(javax.swing.text.JTextComponent txt)
Returns if the prompt or the text field should be painted, depending on the state oftxt.- Parameters:
txt-- Returns:
- true when
txtcontains not text, otherwise false
-
update
public void update(java.awt.Graphics g, javax.swing.JComponent c)Calls super.update(Graphics, JComponent), which in turn calls the paint method of this object.- Overrides:
updatein classjavax.swing.plaf.ComponentUI
-
modelToView
public java.awt.Rectangle modelToView(javax.swing.text.JTextComponent t, int pos, javax.swing.text.Position.Bias bias) throws javax.swing.text.BadLocationExceptionDelegate whenshouldPaintPrompt(JTextComponent)returns false. Otherwise get the prompt component's UI and delegate to it. This ensures that theCaretis painted on the correct position (this is important when the text is centered, so that the caret will not be painted inside the label text)- Specified by:
modelToViewin classjavax.swing.plaf.TextUI- Throws:
javax.swing.text.BadLocationException
-
modelToView
public java.awt.Rectangle modelToView(javax.swing.text.JTextComponent t, int pos) throws javax.swing.text.BadLocationExceptionCallsmodelToView(JTextComponent, int, Bias)withPosition.Bias.Forward.- Specified by:
modelToViewin classjavax.swing.plaf.TextUI- Throws:
javax.swing.text.BadLocationException
-
contains
public boolean contains(javax.swing.JComponent c, int x, int y)- Overrides:
containsin classjavax.swing.plaf.ComponentUI
-
damageRange
public void damageRange(javax.swing.text.JTextComponent t, int p0, int p1, javax.swing.text.Position.Bias firstBias, javax.swing.text.Position.Bias secondBias)- Specified by:
damageRangein classjavax.swing.plaf.TextUI
-
damageRange
public void damageRange(javax.swing.text.JTextComponent t, int p0, int p1)- Specified by:
damageRangein classjavax.swing.plaf.TextUI
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getAccessibleChild
public javax.accessibility.Accessible getAccessibleChild(javax.swing.JComponent c, int i)- Overrides:
getAccessibleChildin classjavax.swing.plaf.ComponentUI
-
getAccessibleChildrenCount
public int getAccessibleChildrenCount(javax.swing.JComponent c)
- Overrides:
getAccessibleChildrenCountin classjavax.swing.plaf.ComponentUI
-
getEditorKit
public javax.swing.text.EditorKit getEditorKit(javax.swing.text.JTextComponent t)
- Specified by:
getEditorKitin classjavax.swing.plaf.TextUI
-
getMaximumSize
public java.awt.Dimension getMaximumSize(javax.swing.JComponent c)
- Overrides:
getMaximumSizein classjavax.swing.plaf.ComponentUI
-
getMinimumSize
public java.awt.Dimension getMinimumSize(javax.swing.JComponent c)
- Overrides:
getMinimumSizein classjavax.swing.plaf.ComponentUI
-
getNextVisualPositionFrom
public int getNextVisualPositionFrom(javax.swing.text.JTextComponent t, int pos, javax.swing.text.Position.Bias b, int direction, javax.swing.text.Position.Bias[] biasRet) throws javax.swing.text.BadLocationException- Specified by:
getNextVisualPositionFromin classjavax.swing.plaf.TextUI- Throws:
javax.swing.text.BadLocationException
-
getRootView
public javax.swing.text.View getRootView(javax.swing.text.JTextComponent t)
- Specified by:
getRootViewin classjavax.swing.plaf.TextUI
-
getToolTipText
public java.lang.String getToolTipText(javax.swing.text.JTextComponent t, java.awt.Point pt)- Overrides:
getToolTipTextin classjavax.swing.plaf.TextUI
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
viewToModel
public int viewToModel(javax.swing.text.JTextComponent t, java.awt.Point pt, javax.swing.text.Position.Bias[] biasReturn)- Specified by:
viewToModelin classjavax.swing.plaf.TextUI
-
viewToModel
public int viewToModel(javax.swing.text.JTextComponent t, java.awt.Point pt)- Specified by:
viewToModelin classjavax.swing.plaf.TextUI
-
getBaseline
public int getBaseline(javax.swing.JComponent c, int width, int height)Tries to callComponentUI#getBaseline(int, int)on the delegate via Reflection. Workaround to maintain compatibility with Java 5. Ideally we should also overrideComponentUI.getBaselineResizeBehavior(JComponent), but that's impossible since theComponent.BaselineResizeBehaviorclass, which does not exist in Java 5, is involved.- Overrides:
getBaselinein classjavax.swing.plaf.ComponentUI- Returns:
- the baseline, or -2 if
getBaselinecould not be invoked on the delegate.
-
-