Package org.fife.ui.rtextarea
Class ChangeableHighlightPainter
- java.lang.Object
-
- javax.swing.text.LayeredHighlighter.LayerPainter
-
- org.fife.ui.rtextarea.ChangeableHighlightPainter
-
- All Implemented Interfaces:
java.io.Serializable
,javax.swing.text.Highlighter.HighlightPainter
- Direct Known Subclasses:
SmartHighlightPainter
,SquiggleUnderlineHighlightPainter
public class ChangeableHighlightPainter extends javax.swing.text.LayeredHighlighter.LayerPainter implements java.io.Serializable
An extension ofLayerPainter
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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private float
alpha
The alpha value used in computing translucency.private java.awt.AlphaComposite
alphaComposite
The alpha composite used to render with translucency.private static int
ARCHEIGHT
private static int
ARCWIDTH
private java.awt.Paint
paint
ThePaint
/Color
of this highlight.private boolean
roundedEdges
Whether selections have rounded edges.
-
Constructor Summary
Constructors Constructor Description ChangeableHighlightPainter()
Creates a newChangeableHighlightPainter
that paints highlights with the text area's selection color (i.e., behaves exactly likejavax.swing.text.DefaultHighlighter.DefaultHighlightPainter
).ChangeableHighlightPainter(java.awt.Paint paint)
Creates a new highlight painter using the specifiedPaint
without rounded edges.ChangeableHighlightPainter(java.awt.Paint paint, boolean rounded)
Creates a new highlight painter.ChangeableHighlightPainter(java.awt.Paint paint, boolean rounded, float alpha)
Creates a new highlight painter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description float
getAlpha()
Returns the alpha value used in computing the translucency of these highlights.private java.awt.AlphaComposite
getAlphaComposite()
Returns the alpha composite to use when rendering highlights with this painter.java.awt.Paint
getPaint()
Returns thePaint
(usually ajava.awt.Color
) being used to paint highlights.boolean
getRoundedEdges()
Returns whether rounded edges are used when painting selections with this highlight painter.void
paint(java.awt.Graphics g, int offs0, int offs1, java.awt.Shape bounds, javax.swing.text.JTextComponent c)
Paints a highlight.java.awt.Shape
paintLayer(java.awt.Graphics g, int offs0, int offs1, java.awt.Shape bounds, javax.swing.text.JTextComponent c, javax.swing.text.View view)
Paints a portion of a highlight.private void
readObject(java.io.ObjectInputStream s)
Deserializes a painter.void
setAlpha(float alpha)
Sets the alpha value used in rendering highlights.void
setPaint(java.awt.Paint paint)
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.private void
writeObject(java.io.ObjectOutputStream s)
Serializes this painter.
-
-
-
Field Detail
-
paint
private java.awt.Paint paint
ThePaint
/Color
of this highlight.
-
roundedEdges
private boolean roundedEdges
Whether selections have rounded edges.
-
alphaComposite
private transient java.awt.AlphaComposite alphaComposite
The alpha composite used to render with translucency.
-
alpha
private float alpha
The alpha value used in computing translucency. This should stay in the range0.0f
(completely invisible) to1.0f
(completely opaque).
-
ARCWIDTH
private static final int ARCWIDTH
- See Also:
- Constant Field Values
-
ARCHEIGHT
private static final int ARCHEIGHT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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
public ChangeableHighlightPainter(java.awt.Paint paint)
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
public ChangeableHighlightPainter(java.awt.Paint paint, boolean rounded)
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
public ChangeableHighlightPainter(java.awt.Paint paint, boolean rounded, float alpha)
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 Detail
-
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:
setAlpha(float)
-
getAlphaComposite
private java.awt.AlphaComposite getAlphaComposite()
Returns the alpha composite to use when rendering highlights with this painter.- Returns:
- The alpha composite.
-
getPaint
public java.awt.Paint getPaint()
Returns thePaint
(usually ajava.awt.Color
) being used to paint highlights.- Returns:
- The
Paint
. - See Also:
setPaint(java.awt.Paint)
-
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:
setRoundedEdges(boolean)
-
paint
public void paint(java.awt.Graphics g, int offs0, int offs1, java.awt.Shape bounds, javax.swing.text.JTextComponent c)
Paints a highlight.- Specified by:
paint
in interfacejavax.swing.text.Highlighter.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 java.awt.Shape paintLayer(java.awt.Graphics g, int offs0, int offs1, java.awt.Shape bounds, javax.swing.text.JTextComponent c, javax.swing.text.View view)
Paints a portion of a highlight.- Specified by:
paintLayer
in classjavax.swing.text.LayeredHighlighter.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
-
readObject
private void readObject(java.io.ObjectInputStream s) throws java.lang.ClassNotFoundException, java.io.IOException
Deserializes a painter.- Parameters:
s
- The stream to read from.- Throws:
java.lang.ClassNotFoundException
- If something bad happens.java.io.IOException
- If an IO error occurs.
-
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:
getAlpha()
-
setPaint
public void setPaint(java.awt.Paint paint)
Sets thePaint
(usually ajava.awt.Color
) used to paint this highlight.- Parameters:
paint
- The newPaint
.- See Also:
getPaint()
-
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:
getRoundedEdges()
-
writeObject
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
Serializes this painter.- Parameters:
s
- The stream to write to.- Throws:
java.io.IOException
- If an IO error occurs.
-
-