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 TextUI
Abstract
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 TextUIdelegateDelegate the hard work to this object.protected JTextComponentpromptComponentThis component ist painted when rendering the prompt text.
-
Constructor Summary
Constructors Constructor Description PromptTextUI(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(JComponent c, int x, int y)protected abstract JTextComponentcreatePromptComponent()Creates a component which should be used to render the prompt text.voiddamageRange(JTextComponent t, int p0, int p1)voiddamageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias)booleanequals(Object obj)AccessiblegetAccessibleChild(JComponent c, int i)intgetAccessibleChildrenCount(JComponent c)intgetBaseline(JComponent c, int width, int height)Tries to callComponentUI#getBaseline(int, int)on the delegate via Reflection.EditorKitgetEditorKit(JTextComponent t)DimensiongetMaximumSize(JComponent c)DimensiongetMinimumSize(JComponent c)intgetNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet)DimensiongetPreferredSize(JComponent c)WhenshouldPaintPrompt(JTextComponent)returns true, the prompt component is retrieved by callinggetPromptComponent(JTextComponent)and it's preferred size is returned.JTextComponentgetPromptComponent(JTextComponent txt)Creates a label component, if none has already been created.ViewgetRootView(JTextComponent t)StringgetToolTipText(JTextComponent t, Point pt)inthashCode()voidinstallUI(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.RectanglemodelToView(JTextComponent t, int pos)RectanglemodelToView(JTextComponent t, int pos, Position.Bias bias)Delegate whenshouldPaintPrompt(JTextComponent)returns false.voidpaint(Graphics g, JComponent c)Delegates painting whenshouldPaintPrompt(JTextComponent)returns false.protected voidpaintPromptComponent(Graphics g, JTextComponent txt)booleanshouldPaintPrompt(JTextComponent txt)Returns if the prompt or the text field should be painted, depending on the state oftxt.StringtoString()voiduninstallUI(JComponent c)Delegates, then uninstalls the focus listener.voidupdate(Graphics g, JComponent c)Calls super.update(Graphics, JComponent), which in turn calls the paint method of this object.intviewToModel(JTextComponent t, Point pt)intviewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn)-
Methods inherited from class javax.swing.plaf.TextUI
getToolTipText2D, modelToView2D, viewToModel2D
-
Methods inherited from class javax.swing.plaf.ComponentUI
createUI, getBaselineResizeBehavior
-
-
-
-
Field Detail
-
delegate
protected final TextUI delegate
Delegate the hard work to this object.
-
promptComponent
protected JTextComponent promptComponent
This component ist painted when rendering the prompt text.
-
-
Constructor Detail
-
PromptTextUI
public PromptTextUI(TextUI delegate)
Creates a newPromptTextUIwhich delegates most work to anotherTextUI.- Parameters:
delegate-
-
-
Method Detail
-
createPromptComponent
protected abstract JTextComponent createPromptComponent()
Creates a component which should be used to render the prompt text.- Returns:
-
installUI
public void installUI(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 classComponentUI
-
uninstallUI
public void uninstallUI(JComponent c)
Delegates, then uninstalls the focus listener.- Overrides:
uninstallUIin classComponentUI
-
getPromptComponent
public JTextComponent getPromptComponent(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 Dimension getPreferredSize(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 classComponentUI
-
paint
public void paint(Graphics g, 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 classComponentUI
-
paintPromptComponent
protected void paintPromptComponent(Graphics g, JTextComponent txt)
-
shouldPaintPrompt
public boolean shouldPaintPrompt(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(Graphics g, JComponent c)
Calls super.update(Graphics, JComponent), which in turn calls the paint method of this object.- Overrides:
updatein classComponentUI
-
modelToView
public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException
Delegate 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 classTextUI- Throws:
BadLocationException
-
modelToView
public Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException
- Specified by:
modelToViewin classTextUI- Throws:
BadLocationException
-
contains
public boolean contains(JComponent c, int x, int y)
- Overrides:
containsin classComponentUI
-
damageRange
public void damageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias)
- Specified by:
damageRangein classTextUI
-
damageRange
public void damageRange(JTextComponent t, int p0, int p1)
- Specified by:
damageRangein classTextUI
-
getAccessibleChild
public Accessible getAccessibleChild(JComponent c, int i)
- Overrides:
getAccessibleChildin classComponentUI
-
getAccessibleChildrenCount
public int getAccessibleChildrenCount(JComponent c)
- Overrides:
getAccessibleChildrenCountin classComponentUI
-
getEditorKit
public EditorKit getEditorKit(JTextComponent t)
- Specified by:
getEditorKitin classTextUI
-
getMaximumSize
public Dimension getMaximumSize(JComponent c)
- Overrides:
getMaximumSizein classComponentUI
-
getMinimumSize
public Dimension getMinimumSize(JComponent c)
- Overrides:
getMinimumSizein classComponentUI
-
getNextVisualPositionFrom
public int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException
- Specified by:
getNextVisualPositionFromin classTextUI- Throws:
BadLocationException
-
getRootView
public View getRootView(JTextComponent t)
- Specified by:
getRootViewin classTextUI
-
getToolTipText
public String getToolTipText(JTextComponent t, Point pt)
- Overrides:
getToolTipTextin classTextUI
-
viewToModel
public int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn)
- Specified by:
viewToModelin classTextUI
-
viewToModel
public int viewToModel(JTextComponent t, Point pt)
- Specified by:
viewToModelin classTextUI
-
getBaseline
public int getBaseline(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 classComponentUI- Returns:
- the baseline, or -2 if
getBaselinecould not be invoked on the delegate.
-
-