Class PromptTextUI
java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.TextUI
org.jdesktop.swingx.plaf.PromptTextUI
- Direct Known Subclasses:
PromptTextAreaUI, PromptTextFieldUI
Abstract TextUI class that delegates most work to another
TextUI and additionally renders a prompt text as specified in the
JTextComponents client properties by PromptSupport.
Subclasses of this class must provide a prompt component used for rendering the prompt text.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classRepaint theTextComponentwhen it loses or gains the focus.protected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final TextUIDelegate the hard work to this object.(package private) static final PromptTextUI.FocusHandlerprotected JTextComponentThis component ist painted when rendering the prompt text. -
Constructor Summary
ConstructorsConstructorDescriptionPromptTextUI(TextUI delegate) Creates a newPromptTextUIwhich delegates most work to anotherTextUI. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(JComponent c, int x, int y) protected abstract JTextComponentCreates 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) booleangetAccessibleChild(JComponent c, int i) intintgetBaseline(JComponent c, int width, int height) Tries to callon the delegate via Reflection.invalid reference
ComponentUI#getBaseline(int, int)intgetNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) WhenshouldPaintPrompt(JTextComponent)returns true, the prompt component is retrieved by callinggetPromptComponent(JTextComponent)and it's preferred size is returned.Creates a label component, if none has already been created.getToolTipText(JTextComponent t, Point pt) inthashCode()voidCalls TextUI#installUI(JComponent) on the delegate and installs a focus listener oncwhich repaints the component when it gains or loses the focus.modelToView(JTextComponent t, int pos) modelToView(JTextComponent t, int pos, Position.Bias bias) Delegate whenshouldPaintPrompt(JTextComponent)returns false.voidpaint(Graphics g, JComponent c) Delegates painting whenshouldPaintPrompt(JTextComponent)returns false.protected voidbooleanReturns if the prompt or the text field should be painted, depending on the state oftxt.toString()voidDelegates, 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 TextUI
getToolTipText2D, modelToView2D, viewToModel2DMethods inherited from class ComponentUI
createUI, getBaselineResizeBehavior
-
Field Details
-
focusHandler
-
delegate
Delegate the hard work to this object. -
promptComponent
This component ist painted when rendering the prompt text.
-
-
Constructor Details
-
PromptTextUI
Creates a newPromptTextUIwhich delegates most work to anotherTextUI.- Parameters:
delegate-
-
-
Method Details
-
createPromptComponent
Creates a component which should be used to render the prompt text.- Returns:
-
installUI
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
Delegates, then uninstalls the focus listener.- Overrides:
uninstallUIin classComponentUI
-
getPromptComponent
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
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
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
-
shouldPaintPrompt
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
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
- Specified by:
modelToViewin classTextUI- Throws:
BadLocationException
-
contains
- Overrides:
containsin classComponentUI
-
damageRange
public void damageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias) - Specified by:
damageRangein classTextUI
-
damageRange
- Specified by:
damageRangein classTextUI
-
equals
-
getAccessibleChild
- Overrides:
getAccessibleChildin classComponentUI
-
getAccessibleChildrenCount
- Overrides:
getAccessibleChildrenCountin classComponentUI
-
getEditorKit
- Specified by:
getEditorKitin classTextUI
-
getMaximumSize
- Overrides:
getMaximumSizein classComponentUI
-
getMinimumSize
- 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
- Specified by:
getRootViewin classTextUI
-
getToolTipText
- Overrides:
getToolTipTextin classTextUI
-
hashCode
-
toString
-
viewToModel
- Specified by:
viewToModelin classTextUI
-
viewToModel
- Specified by:
viewToModelin classTextUI
-
getBaseline
Tries to callon the delegate via Reflection. Workaround to maintain compatibility with Java 5. Ideally we should also overrideinvalid reference
ComponentUI#getBaseline(int, int)ComponentUI.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.
-