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
Abstract
TextUI
class that delegates most work to another
TextUI
and additionally renders a prompt text as specified in the
JTextComponent
s client properties by PromptSupport
.
Subclasses of this class must provide a prompt component used for rendering the prompt text.
- Author:
- Peter Weishapl petw@gmx.net
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final TextUI
Delegate the hard work to this object.protected JTextComponent
This component ist painted when rendering the prompt text. -
Constructor Summary
ConstructorsConstructorDescriptionPromptTextUI
(TextUI delegate) Creates a newPromptTextUI
which delegates most work to anotherTextUI
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(JComponent c, int x, int y) protected abstract JTextComponent
Creates a component which should be used to render the prompt text.void
damageRange
(JTextComponent t, int p0, int p1) void
damageRange
(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias) boolean
getAccessibleChild
(JComponent c, int i) int
int
getBaseline
(JComponent c, int width, int height) Tries to callJComponent#getBaseline(int, int)
on the delegate via Reflection.int
getNextVisualPositionFrom
(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.int
hashCode()
void
Calls TextUI#installUI(JComponent) on the delegate and installs a focus listener onc
which repaints the component when it gains or loses the focus.modelToView
(JTextComponent t, int pos) Deprecated.modelToView
(JTextComponent t, int pos, Position.Bias bias) Deprecated.modelToView2D
(JTextComponent t, int pos) modelToView2D
(JTextComponent t, int pos, Position.Bias bias) Delegate whenshouldPaintPrompt(JTextComponent)
returns false.void
paint
(Graphics g, JComponent c) Delegates painting whenshouldPaintPrompt(JTextComponent)
returns false.protected void
boolean
Returns if the prompt or the text field should be painted, depending on the state oftxt
.toString()
void
Delegates, then uninstalls the focus listener.void
update
(Graphics g, JComponent c) Calls super.update(Graphics, JComponent)
, which in turn calls the paint method of this object.int
viewToModel
(JTextComponent t, Point pt) Deprecated.int
viewToModel
(JTextComponent t, Point pt, Position.Bias[] biasReturn) Deprecated.int
viewToModel2D
(JTextComponent t, Point2D pt, Position.Bias[] biasReturn) Methods inherited from class javax.swing.plaf.TextUI
getToolTipText
Methods inherited from class javax.swing.plaf.ComponentUI
createUI, getBaselineResizeBehavior
-
Field Details
-
delegate
Delegate the hard work to this object. -
promptComponent
This component ist painted when rendering the prompt text.
-
-
Constructor Details
-
PromptTextUI
Creates a newPromptTextUI
which delegates most work to anotherTextUI
.- Parameters:
delegate
- TextUI
-
-
Method Details
-
createPromptComponent
Creates a component which should be used to render the prompt text.- Returns:
- JTextComponent
-
installUI
Calls TextUI#installUI(JComponent) on the delegate and installs a focus listener onc
which repaints the component when it gains or loses the focus.- Overrides:
installUI
in classComponentUI
-
uninstallUI
Delegates, then uninstalls the focus listener.- Overrides:
uninstallUI
in classComponentUI
-
getPromptComponent
Creates a label component, if none has already been created. Sets the prompt components properties to reflect the givenJTextComponent
s properties and returns it.- Parameters:
txt
- JTextComponent- 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:
getPreferredSize
in 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:
paint
in classComponentUI
-
paintPromptComponent
-
shouldPaintPrompt
Returns if the prompt or the text field should be painted, depending on the state oftxt
.- Parameters:
txt
- JTextComponent- Returns:
- true when
txt
contains not text, otherwise false
-
update
Calls super.update(Graphics, JComponent)
, which in turn calls the paint method of this object.- Overrides:
update
in classComponentUI
-
modelToView
@Deprecated public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException Deprecated.- Specified by:
modelToView
in classTextUI
- Throws:
BadLocationException
-
modelToView2D
public Rectangle2D modelToView2D(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 theCaret
is 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)- Overrides:
modelToView2D
in classTextUI
- Throws:
BadLocationException
-
modelToView2D
- Throws:
BadLocationException
-
modelToView
Deprecated.- Specified by:
modelToView
in classTextUI
- Throws:
BadLocationException
-
contains
- Overrides:
contains
in classComponentUI
-
damageRange
public void damageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias) - Specified by:
damageRange
in classTextUI
-
damageRange
- Specified by:
damageRange
in classTextUI
-
equals
-
getAccessibleChild
- Overrides:
getAccessibleChild
in classComponentUI
-
getAccessibleChildrenCount
- Overrides:
getAccessibleChildrenCount
in classComponentUI
-
getEditorKit
- Specified by:
getEditorKit
in classTextUI
-
getMaximumSize
- Overrides:
getMaximumSize
in classComponentUI
-
getMinimumSize
- Overrides:
getMinimumSize
in classComponentUI
-
getNextVisualPositionFrom
public int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException - Specified by:
getNextVisualPositionFrom
in classTextUI
- Throws:
BadLocationException
-
getRootView
- Specified by:
getRootView
in classTextUI
-
getToolTipText2D
- Overrides:
getToolTipText2D
in classTextUI
-
hashCode
public int hashCode() -
toString
-
viewToModel2D
- Overrides:
viewToModel2D
in classTextUI
-
viewToModel
Deprecated.- Specified by:
viewToModel
in classTextUI
-
viewToModel
Deprecated.- Specified by:
viewToModel
in classTextUI
-
getBaseline
Tries to callJComponent#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.BaselineResizeBehavior
class, which does not exist in Java 5, is involved.- Overrides:
getBaseline
in classComponentUI
- Returns:
- the baseline, or -2 if
getBaseline
could not be invoked on the delegate.
-