java.lang.Object
javax.swing.text.LayeredHighlighter.LayerPainter
de.grogra.pf.ui.autocomplete.impl.ChangeableHighlightPainter
- All Implemented Interfaces:
Serializable
,Highlighter.HighlightPainter
public class ChangeableHighlightPainter
extends LayeredHighlighter.LayerPainter
implements Serializable
An extension of
LayerPainter
that allows the user to
change several of its properties:
- Its color/fill style (can use a
GradientPaint
, for example). - Whether the edges of a painted highlight are rounded.
- Whether painted highlights have translucency.
- Version:
- 0.6
- Author:
- Robert Futrell
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a newChangeableHighlightPainter
that paints highlights with the text area's selection color (i.e., behaves exactly likejavax.swing.text.DefaultHighlighter.DefaultHighlightPainter
).ChangeableHighlightPainter
(Paint paint) Creates a new highlight painter using the specifiedPaint
without rounded edges.ChangeableHighlightPainter
(Paint paint, boolean rounded) Creates a new highlight painter.ChangeableHighlightPainter
(Paint paint, boolean rounded, float alpha) Creates a new highlight painter. -
Method Summary
Modifier and TypeMethodDescriptionfloat
getAlpha()
Returns the alpha value used in computing the translucency of these highlights.getPaint()
Returns thePaint
(usually ajava.awt.Color
) being used to paint highlights.boolean
Returns whether rounded edges are used when painting selections with this highlight painter.void
paint
(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) Paints a highlight.paintLayer
(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) Paints a portion of a highlight.void
setAlpha
(float alpha) Sets the alpha value used in rendering highlights.void
Sets thePaint
(usually ajava.awt.Color
) used to paint this highlight.void
setRoundedEdges
(boolean rounded) Sets whether rounded edges are used when painting this highlight.
-
Constructor Details
-
ChangeableHighlightPainter
public ChangeableHighlightPainter()Creates a newChangeableHighlightPainter
that paints highlights with the text area's selection color (i.e., behaves exactly likejavax.swing.text.DefaultHighlighter.DefaultHighlightPainter
). -
ChangeableHighlightPainter
Creates a new highlight painter using the specifiedPaint
without rounded edges.- Parameters:
paint
- ThePaint
(usually ajava.awt.Color
) with which to paint the highlights.
-
ChangeableHighlightPainter
Creates a new highlight painter.- Parameters:
paint
- ThePaint
(usually ajava.awt.Color
) with which to paint the highlights.rounded
- Whether to use rounded edges on the highlights.
-
ChangeableHighlightPainter
Creates a new highlight painter.- Parameters:
paint
- ThePaint
(usually ajava.awt.Color
) with which to paint the highlights.rounded
- Whether to use rounded edges on the highlights.alpha
- The alpha value to use when painting highlights. This value should be in the range0.0f
(completely transparent) through1.0f
(opaque).
-
-
Method Details
-
getAlpha
public float getAlpha()Returns the alpha value used in computing the translucency of these highlights. A value of1.0f
(the default) means that no translucency is used; there is no performance hit for this value. For all other values ([0.0f..1.0f)
), there will be a performance hit.- Returns:
- The alpha value.
- See Also:
-
getPaint
Returns thePaint
(usually ajava.awt.Color
) being used to paint highlights.- Returns:
- The
Paint
. - See Also:
-
getRoundedEdges
public boolean getRoundedEdges()Returns whether rounded edges are used when painting selections with this highlight painter.- Returns:
- Whether rounded edges are used.
- See Also:
-
paint
Paints a highlight.- Specified by:
paint
in interfaceHighlighter.HighlightPainter
- Parameters:
g
- the graphics contextoffs0
- the starting model offset >= 0offs1
- the ending model offset >= offs1bounds
- the bounding box for the highlightc
- the editor
-
paintLayer
public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) Paints a portion of a highlight.- Specified by:
paintLayer
in classLayeredHighlighter.LayerPainter
- Parameters:
g
- the graphics contextoffs0
- the starting model offset >= 0offs1
- the ending model offset >= offs1bounds
- the bounding box of the view, which is not necessarily the region to paint.c
- the editorview
- View painting for- Returns:
- region drawing occurred in
-
setAlpha
public void setAlpha(float alpha) Sets the alpha value used in rendering highlights. If this value is1.0f
(the default), the highlights are rendered completely opaque. This behavior matches that ofDefaultHighlightPainter
and imposes no performance hit. If this value is below1.0f
, it represents how opaque the highlight will be. There will be a small performance hit for values less than1.0f
.- Parameters:
alpha
- The new alpha value to use for transparency.- See Also:
-
setPaint
Sets thePaint
(usually ajava.awt.Color
) used to paint this highlight.- Parameters:
paint
- The newPaint
.- See Also:
-
setRoundedEdges
public void setRoundedEdges(boolean rounded) Sets whether rounded edges are used when painting this highlight.- Parameters:
rounded
- Whether rounded edges should be used.- See Also:
-