org.jdesktop.swingx.plaf
Class PromptTextUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.TextUI
          extended by org.jdesktop.swingx.plaf.PromptTextUI
Direct Known Subclasses:
PromptTextAreaUI, PromptTextFieldUI

public abstract class PromptTextUI
extends TextUI

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.

Author:
Peter Weishapl

Nested Class Summary
protected  class PromptTextUI.PainterHighlighter
           
 
Field Summary
protected  TextUI delegate
          Delegate the hard work to this object.
protected  JTextComponent promptComponent
          This component ist painted when rendering the prompt text.
 
Constructor Summary
PromptTextUI(TextUI delegate)
          Creates a new PromptTextUI which delegates most work to another TextUI.
 
Method Summary
 boolean contains(JComponent c, int x, int y)
           
protected abstract  JTextComponent createPromptComponent()
          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 equals(Object obj)
           
 Accessible getAccessibleChild(JComponent c, int i)
           
 int getAccessibleChildrenCount(JComponent c)
           
 int getBaseline(JComponent c, int width, int height)
          Tries to call ComponentUI#getBaseline(int, int) on the delegate via Reflection.
 EditorKit getEditorKit(JTextComponent t)
           
 Dimension getMaximumSize(JComponent c)
           
 Dimension getMinimumSize(JComponent c)
           
 int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet)
           
 Dimension getPreferredSize(JComponent c)
          When shouldPaintPrompt(JTextComponent) returns true, the prompt component is retrieved by calling getPromptComponent(JTextComponent) and it's preferred size is returned.
 JTextComponent getPromptComponent(JTextComponent txt)
          Creates a label component, if none has already been created.
 View getRootView(JTextComponent t)
           
 String getToolTipText(JTextComponent t, Point pt)
           
 int hashCode()
           
 void installUI(JComponent c)
          Calls TextUI#installUI(JComponent) on the delegate and installs a focus listener on c which repaints the component when it gains or loses the focus.
 Rectangle modelToView(JTextComponent t, int pos)
          Calls #modelToView(JTextComponent, int, Bias) with Position.Bias.Forward.
 Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias)
          Delegate when shouldPaintPrompt(JTextComponent) returns false.
 void paint(Graphics g, JComponent c)
          Delegates painting when shouldPaintPrompt(JTextComponent) returns false.
protected  void paintPromptComponent(Graphics g, JTextComponent txt)
           
 boolean shouldPaintPrompt(JTextComponent txt)
          Returns if the prompt or the text field should be painted, depending on the state of txt.
 String toString()
           
 void uninstallUI(JComponent c)
          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)
           
 int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn)
           
 
Methods inherited from class javax.swing.plaf.ComponentUI
createUI, getBaselineResizeBehavior
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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 new PromptTextUI which delegates most work to another TextUI.

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 on c which repaints the component when it gains or loses the focus.

Overrides:
installUI in class ComponentUI

uninstallUI

public void uninstallUI(JComponent c)
Delegates, then uninstalls the focus listener.

Overrides:
uninstallUI in class ComponentUI

getPromptComponent

public JTextComponent getPromptComponent(JTextComponent txt)
Creates a label component, if none has already been created. Sets the prompt components properties to reflect the given JTextComponents properties and returns it.

Parameters:
txt -
Returns:
the adjusted prompt component

getPreferredSize

public Dimension getPreferredSize(JComponent c)
When shouldPaintPrompt(JTextComponent) returns true, the prompt component is retrieved by calling getPromptComponent(JTextComponent) and it's preferred size is returned. Otherwise supergetPreferredSize(JComponent) is called.

Overrides:
getPreferredSize in class ComponentUI

paint

public void paint(Graphics g,
                  JComponent c)
Delegates painting when shouldPaintPrompt(JTextComponent) returns false. Otherwise the prompt component is retrieved by calling getPromptComponent(JTextComponent) and painted. Then the caret of the given text component is painted.

Overrides:
paint in class ComponentUI

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 of txt.

Parameters:
txt -
Returns:
true when txt contains 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:
update in class ComponentUI

modelToView

public Rectangle modelToView(JTextComponent t,
                             int pos,
                             Position.Bias bias)
                      throws BadLocationException
Delegate when shouldPaintPrompt(JTextComponent) returns false. Otherwise get the prompt component's UI and delegate to it. This ensures that the Caret 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)

Specified by:
modelToView in class TextUI
Throws:
BadLocationException

modelToView

public Rectangle modelToView(JTextComponent t,
                             int pos)
                      throws BadLocationException
Calls #modelToView(JTextComponent, int, Bias) with Position.Bias.Forward.

Specified by:
modelToView in class TextUI
Throws:
BadLocationException

contains

public boolean contains(JComponent c,
                        int x,
                        int y)
Overrides:
contains in class ComponentUI

damageRange

public void damageRange(JTextComponent t,
                        int p0,
                        int p1,
                        Position.Bias firstBias,
                        Position.Bias secondBias)
Specified by:
damageRange in class TextUI

damageRange

public void damageRange(JTextComponent t,
                        int p0,
                        int p1)
Specified by:
damageRange in class TextUI

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getAccessibleChild

public Accessible getAccessibleChild(JComponent c,
                                     int i)
Overrides:
getAccessibleChild in class ComponentUI

getAccessibleChildrenCount

public int getAccessibleChildrenCount(JComponent c)
Overrides:
getAccessibleChildrenCount in class ComponentUI

getEditorKit

public EditorKit getEditorKit(JTextComponent t)
Specified by:
getEditorKit in class TextUI

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Overrides:
getMaximumSize in class ComponentUI

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Overrides:
getMinimumSize in class ComponentUI

getNextVisualPositionFrom

public int getNextVisualPositionFrom(JTextComponent t,
                                     int pos,
                                     Position.Bias b,
                                     int direction,
                                     Position.Bias[] biasRet)
                              throws BadLocationException
Specified by:
getNextVisualPositionFrom in class TextUI
Throws:
BadLocationException

getRootView

public View getRootView(JTextComponent t)
Specified by:
getRootView in class TextUI

getToolTipText

public String getToolTipText(JTextComponent t,
                             Point pt)
Overrides:
getToolTipText in class TextUI

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

viewToModel

public int viewToModel(JTextComponent t,
                       Point pt,
                       Position.Bias[] biasReturn)
Specified by:
viewToModel in class TextUI

viewToModel

public int viewToModel(JTextComponent t,
                       Point pt)
Specified by:
viewToModel in class TextUI

getBaseline

public int getBaseline(JComponent c,
                       int width,
                       int height)
Tries to call ComponentUI#getBaseline(int, int) on the delegate via Reflection. Workaround to maintain compatibility with Java 5. Ideally we should also override ComponentUI.getBaselineResizeBehavior(JComponent), but that's impossible since the Component.BaselineResizeBehavior class, which does not exist in Java 5, is involved.

Overrides:
getBaseline in class ComponentUI
Returns:
the baseline, or -2 if getBaseline could not be invoked on the delegate.


Copyright © 2012. All Rights Reserved.