|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.wordpress.tipsforjava.swing.TextLineNumber
public class TextLineNumber extends JPanel
This class will display line numbers for a related text component. The text component must use the same line height for each line. TextLineNumber supports wrapped lines and will highlight the line number of the current line in the text component. This class was designed to be used as a component added to the row header of a JScrollPane.
| Field Summary | |
|---|---|
static float |
CENTER
|
private static int |
HEIGHT
|
static float |
LEFT
|
private static Border |
OUTER
|
static float |
RIGHT
|
private int |
borderGap
|
private JTextComponent |
component
|
private Color |
currentLineForeground
|
private float |
digitAlignment
|
private HashMap |
fonts
|
private int |
lastDigits
|
private int |
lastHeight
|
private int |
lastLine
|
private int |
minimumDisplayDigits
|
private boolean |
updateFont
|
| Fields inherited from class JPanel | |
|---|---|
| WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT |
| Fields inherited from class JComponent | |
|---|---|
| WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT |
| Constructor Summary | |
TextLineNumber(JTextComponent component)
Create a line number component for a text component. |
|
TextLineNumber(JTextComponent component, int minimumDisplayDigits)
Create a line number component for a text component. |
|
| Method Summary | |
|---|---|
void
|
caretUpdate(CaretEvent e)
|
void
|
changedUpdate(DocumentEvent e)
|
private void
|
documentChanged()
|
int
|
getBorderGap()
Gets the border gap |
Color
|
getCurrentLineForeground()
Gets the current line rendering Color |
float
|
getDigitAlignment()
Gets the digit alignment |
int
|
getMinimumDisplayDigits()
Gets the minimum display digits |
private int
|
getOffsetX(int availableWidth, int stringWidth)
|
private int
|
getOffsetY(int rowStartOffset, FontMetrics fontMetrics)
|
protected String
|
getTextLineNumber(int rowStartOffset)
|
boolean
|
getUpdateFont()
Gets the update font property |
void
|
insertUpdate(DocumentEvent e)
|
private boolean
|
isCurrentLine(int rowStartOffset)
|
void
|
paintComponent(Graphics g)
Draw the line numbers |
void
|
propertyChange(PropertyChangeEvent evt)
|
void
|
removeUpdate(DocumentEvent e)
|
void
|
setBorderGap(int borderGap)
The border gap is used in calculating the left and right insets of the border. |
void
|
setCurrentLineForeground(Color currentLineForeground)
The Color used to render the current line digits. |
void
|
setDigitAlignment(float digitAlignment)
Specify the horizontal alignment of the digits within the component. |
void
|
setMinimumDisplayDigits(int minimumDisplayDigits)
Specify the mimimum number of digits used to calculate the preferred width of the component. |
private void
|
setPreferredWidth()
Calculate the width needed to display the maximum line number |
void
|
setUpdateFont(boolean updateFont)
Set the update font property. |
| Field Detail |
|---|
public static final float CENTER
private static final int HEIGHT
public static final float LEFT
private static final Border OUTER
public static final float RIGHT
private int borderGap
private JTextComponent component
private Color currentLineForeground
private float digitAlignment
private HashMap fonts
private int lastDigits
private int lastHeight
private int lastLine
private int minimumDisplayDigits
private boolean updateFont
| Constructor Detail |
|---|
public TextLineNumber(JTextComponent component)
component - the related text component
public TextLineNumber(JTextComponent component, int minimumDisplayDigits)
component - the related text componentminimumDisplayDigits - the number of digits used to calculate
the minimum width of the component
| Method Detail |
|---|
de public public void caretUpdate(CaretEvent e)
de public public void changedUpdate(DocumentEvent e)
private void documentChanged()
public int getBorderGap()
public Color getCurrentLineForeground()
public float getDigitAlignment()
public int getMinimumDisplayDigits()
private int getOffsetX(int availableWidth, int stringWidth)
private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics)
protected String getTextLineNumber(int rowStartOffset)
public boolean getUpdateFont()
de public public void insertUpdate(DocumentEvent e)
private boolean isCurrentLine(int rowStartOffset)
de public public void paintComponent(Graphics g)
de public public void propertyChange(PropertyChangeEvent evt)
de public public void removeUpdate(DocumentEvent e)
public void setBorderGap(int borderGap)
borderGap - the gap in pixels
public void setCurrentLineForeground(Color currentLineForeground)
currentLineForeground - the Color used to render the current line
public void setDigitAlignment(float digitAlignment)
currentLineForeground - the Color used to render the current line
public void setMinimumDisplayDigits(int minimumDisplayDigits)
minimumDisplayDigits - the number digits used in the preferred
width calculation
private void setPreferredWidth()
public void setUpdateFont(boolean updateFont)
updateFont - when true update the Font and repaint the line
numbers, otherwise just repaint the line numbers.
Groovy Documentation