Package org.exbin.bined.swing.basic
Class DefaultCodeAreaPainter
- java.lang.Object
-
- org.exbin.bined.swing.basic.DefaultCodeAreaPainter
-
- All Implemented Interfaces:
BasicColorsCapableCodeAreaPainter
,CodeAreaPainter
@ParametersAreNonnullByDefault public class DefaultCodeAreaPainter extends java.lang.Object implements CodeAreaPainter, BasicColorsCapableCodeAreaPainter
Code area component default painter.
-
-
Field Summary
Fields Modifier and Type Field Description protected CodeAreaCore
codeArea
-
Constructor Summary
Constructors Constructor Description DefaultCodeAreaPainter(CodeAreaCore codeArea)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attach()
Attaches painter to code area.java.util.Optional<org.exbin.bined.basic.CodeAreaScrollPosition>
computeCenterOnScrollPosition(org.exbin.bined.CodeAreaCaretPosition caretPosition)
Returns scroll position so that provided caret position is visible in the center of the scrolled area.org.exbin.bined.CodeAreaCaretPosition
computeMovePosition(org.exbin.bined.CodeAreaCaretPosition position, org.exbin.bined.basic.MovementDirection direction)
Computes position for movement action.org.exbin.bined.basic.PositionScrollVisibility
computePositionScrollVisibility(org.exbin.bined.CodeAreaCaretPosition caretPosition)
Returns state of the visibility of given caret position within current scrolling window.java.util.Optional<org.exbin.bined.basic.CodeAreaScrollPosition>
computeRevealScrollPosition(org.exbin.bined.CodeAreaCaretPosition caretPosition)
Returns scroll position so that provided caret position is visible in scrolled area.org.exbin.bined.basic.CodeAreaScrollPosition
computeScrolling(org.exbin.bined.basic.CodeAreaScrollPosition startPosition, org.exbin.bined.basic.ScrollingDirection direction)
Computes scrolling position for given shift action.void
detach()
Detaches painter to code area.protected void
drawCenteredChars(java.awt.Graphics g, char[] drawnChars, int charOffset, int length, int cellWidth, int positionX, int positionY)
Draws characters centering it to cells of the same width.protected void
drawShiftedChars(java.awt.Graphics g, char[] drawnChars, int charOffset, int length, int positionX, int positionY)
void
fontChanged(java.awt.Graphics g)
BasicCodeAreaColorsProfile
getBasicColors()
Returns basic profile for colors.int
getBytesPerRow()
java.awt.Rectangle
getCursorPositionRect(long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)
Returns cursor rectangle.protected int
getCharactersPerRow()
int
getMouseCursorShape(int positionX, int positionY)
Returns type of cursor for given painter relative position.java.awt.Color
getPositionBackgroundColor(long rowDataPosition, int byteOnRow, int charOnRow, org.exbin.bined.CodeAreaSection section)
Returns background color for particular code.java.awt.Point
getPositionPoint(long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)
Returns relative cursor position in code area or null if cursor is not visible.java.awt.Color
getPositionTextColor(long rowDataPosition, int byteOnRow, int charOnRow, org.exbin.bined.CodeAreaSection section)
Returns background color for particular code.org.exbin.bined.basic.BasicCodeAreaZone
getPositionZone(int positionX, int positionY)
Returns zone type for given position.int
getRowHeight()
boolean
isInitialized()
Returns true if painter was initialized.org.exbin.bined.CodeAreaCaretPosition
mousePositionToClosestCaretPosition(int positionX, int positionY, org.exbin.bined.CaretOverlapMode overflowMode)
Returns closest caret position for provided component relative mouse position.void
paintBackground(java.awt.Graphics g)
Paints main area background.void
paintComponent(java.awt.Graphics g)
Paints the main component.void
paintCursor(java.awt.Graphics g)
Paints cursor symbol.void
paintHeader(java.awt.Graphics g)
void
paintMainArea(java.awt.Graphics g)
Paints main data section of the component.void
paintOutsideArea(java.awt.Graphics g)
void
paintRowBackground(java.awt.Graphics g, long rowDataPosition, int rowPositionX, int rowPositionY)
Paints row background.void
paintRowPosition(java.awt.Graphics g)
void
paintRows(java.awt.Graphics g)
void
paintRowText(java.awt.Graphics g, long rowDataPosition, int rowPositionX, int rowPositionY)
Paints row text.void
rebuildColors()
Calls rebuild of the colors profile.void
recomputeCharPositions()
void
reset()
Resets complete painter state for new painting.void
resetCaret()
Resets caret state.void
resetColors()
Rebuilds colors after UIManager change.void
resetFont()
Resets painter font state for new painting.void
resetLayout()
Updates painter layout state for new painting.void
scrollPositionChanged()
Notify scroll position was changed outside of scrolling.void
scrollPositionModified()
Notify scroll position was modified.void
setBasicColors(BasicCodeAreaColorsProfile colorsProfile)
Sets basic profile for colors.protected void
updateCache()
protected void
updateRectToCursorPosition(java.awt.Rectangle rect, long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)
void
updateScrollBars()
Performs update of scrollbars after change in data size or position.
-
-
-
Field Detail
-
codeArea
@Nonnull protected final CodeAreaCore codeArea
-
-
Constructor Detail
-
DefaultCodeAreaPainter
public DefaultCodeAreaPainter(CodeAreaCore codeArea)
-
-
Method Detail
-
attach
public void attach()
Description copied from interface:CodeAreaPainter
Attaches painter to code area.- Specified by:
attach
in interfaceCodeAreaPainter
-
detach
public void detach()
Description copied from interface:CodeAreaPainter
Detaches painter to code area.- Specified by:
detach
in interfaceCodeAreaPainter
-
reset
public void reset()
Description copied from interface:CodeAreaPainter
Resets complete painter state for new painting.- Specified by:
reset
in interfaceCodeAreaPainter
-
resetColors
public void resetColors()
Description copied from interface:CodeAreaPainter
Rebuilds colors after UIManager change.- Specified by:
resetColors
in interfaceCodeAreaPainter
-
resetFont
public void resetFont()
Description copied from interface:CodeAreaPainter
Resets painter font state for new painting.- Specified by:
resetFont
in interfaceCodeAreaPainter
-
resetLayout
public void resetLayout()
Description copied from interface:CodeAreaPainter
Updates painter layout state for new painting.- Specified by:
resetLayout
in interfaceCodeAreaPainter
-
resetCaret
public void resetCaret()
Description copied from interface:CodeAreaPainter
Resets caret state.- Specified by:
resetCaret
in interfaceCodeAreaPainter
-
rebuildColors
public void rebuildColors()
Description copied from interface:CodeAreaPainter
Calls rebuild of the colors profile.- Specified by:
rebuildColors
in interfaceCodeAreaPainter
-
recomputeCharPositions
public void recomputeCharPositions()
-
fontChanged
public void fontChanged(java.awt.Graphics g)
-
isInitialized
public boolean isInitialized()
Description copied from interface:CodeAreaPainter
Returns true if painter was initialized.- Specified by:
isInitialized
in interfaceCodeAreaPainter
- Returns:
- true if initialized
-
paintComponent
public void paintComponent(java.awt.Graphics g)
Description copied from interface:CodeAreaPainter
Paints the main component.- Specified by:
paintComponent
in interfaceCodeAreaPainter
- Parameters:
g
- graphics
-
updateCache
protected void updateCache()
-
paintOutsideArea
public void paintOutsideArea(java.awt.Graphics g)
-
paintHeader
public void paintHeader(java.awt.Graphics g)
-
paintRowPosition
public void paintRowPosition(java.awt.Graphics g)
-
paintMainArea
public void paintMainArea(java.awt.Graphics g)
Description copied from interface:CodeAreaPainter
Paints main data section of the component.- Specified by:
paintMainArea
in interfaceCodeAreaPainter
- Parameters:
g
- graphics
-
paintBackground
public void paintBackground(java.awt.Graphics g)
Paints main area background.- Parameters:
g
- graphics
-
paintRows
public void paintRows(java.awt.Graphics g)
-
paintRowBackground
public void paintRowBackground(java.awt.Graphics g, long rowDataPosition, int rowPositionX, int rowPositionY)
Paints row background.- Parameters:
g
- graphicsrowDataPosition
- row data positionrowPositionX
- row position XrowPositionY
- row position Y
-
getPositionBackgroundColor
@Nullable public java.awt.Color getPositionBackgroundColor(long rowDataPosition, int byteOnRow, int charOnRow, org.exbin.bined.CodeAreaSection section)
Returns background color for particular code.- Parameters:
rowDataPosition
- row data positionbyteOnRow
- byte on current rowcharOnRow
- character on current rowsection
- current section- Returns:
- color or null for default color
-
computePositionScrollVisibility
@Nonnull public org.exbin.bined.basic.PositionScrollVisibility computePositionScrollVisibility(org.exbin.bined.CodeAreaCaretPosition caretPosition)
Description copied from interface:CodeAreaPainter
Returns state of the visibility of given caret position within current scrolling window.- Specified by:
computePositionScrollVisibility
in interfaceCodeAreaPainter
- Parameters:
caretPosition
- caret position- Returns:
- visibility state
-
computeRevealScrollPosition
@Nonnull public java.util.Optional<org.exbin.bined.basic.CodeAreaScrollPosition> computeRevealScrollPosition(org.exbin.bined.CodeAreaCaretPosition caretPosition)
Description copied from interface:CodeAreaPainter
Returns scroll position so that provided caret position is visible in scrolled area. Performs minimal scrolling and tries to preserve current vertical / horizontal scrolling if possible. If given position cannot be fully shown, top left corner is preferred.- Specified by:
computeRevealScrollPosition
in interfaceCodeAreaPainter
- Parameters:
caretPosition
- caret position- Returns:
- scroll position or null if caret position is already visible / scrolled to the best fit
-
computeCenterOnScrollPosition
@Nonnull public java.util.Optional<org.exbin.bined.basic.CodeAreaScrollPosition> computeCenterOnScrollPosition(org.exbin.bined.CodeAreaCaretPosition caretPosition)
Description copied from interface:CodeAreaPainter
Returns scroll position so that provided caret position is visible in the center of the scrolled area. Attempts to center as much as possible while preserving scrolling limits.- Specified by:
computeCenterOnScrollPosition
in interfaceCodeAreaPainter
- Parameters:
caretPosition
- caret position- Returns:
- scroll position or null if desired scroll position is the same as current scroll position.
-
paintRowText
public void paintRowText(java.awt.Graphics g, long rowDataPosition, int rowPositionX, int rowPositionY)
Paints row text.- Parameters:
g
- graphicsrowDataPosition
- row data positionrowPositionX
- row position XrowPositionY
- row position Y
-
getPositionTextColor
@Nullable public java.awt.Color getPositionTextColor(long rowDataPosition, int byteOnRow, int charOnRow, org.exbin.bined.CodeAreaSection section)
Returns background color for particular code.- Parameters:
rowDataPosition
- row data positionbyteOnRow
- byte on current rowcharOnRow
- character on current rowsection
- current section- Returns:
- color or null for default color
-
paintCursor
public void paintCursor(java.awt.Graphics g)
Description copied from interface:CodeAreaPainter
Paints cursor symbol.- Specified by:
paintCursor
in interfaceCodeAreaPainter
- Parameters:
g
- graphics
-
mousePositionToClosestCaretPosition
@Nonnull public org.exbin.bined.CodeAreaCaretPosition mousePositionToClosestCaretPosition(int positionX, int positionY, org.exbin.bined.CaretOverlapMode overflowMode)
Description copied from interface:CodeAreaPainter
Returns closest caret position for provided component relative mouse position.- Specified by:
mousePositionToClosestCaretPosition
in interfaceCodeAreaPainter
- Parameters:
positionX
- component relative position XpositionY
- component relative position YoverflowMode
- overflow mode- Returns:
- closest caret position
-
computeMovePosition
@Nonnull public org.exbin.bined.CodeAreaCaretPosition computeMovePosition(org.exbin.bined.CodeAreaCaretPosition position, org.exbin.bined.basic.MovementDirection direction)
Description copied from interface:CodeAreaPainter
Computes position for movement action.- Specified by:
computeMovePosition
in interfaceCodeAreaPainter
- Parameters:
position
- source positiondirection
- movement direction- Returns:
- target position
-
computeScrolling
@Nonnull public org.exbin.bined.basic.CodeAreaScrollPosition computeScrolling(org.exbin.bined.basic.CodeAreaScrollPosition startPosition, org.exbin.bined.basic.ScrollingDirection direction)
Description copied from interface:CodeAreaPainter
Computes scrolling position for given shift action.- Specified by:
computeScrolling
in interfaceCodeAreaPainter
- Parameters:
startPosition
- start positiondirection
- scrolling direction- Returns:
- target position
-
getPositionPoint
@Nullable public java.awt.Point getPositionPoint(long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)
Returns relative cursor position in code area or null if cursor is not visible.- Parameters:
dataPosition
- data positioncodeOffset
- code offsetsection
- section- Returns:
- cursor position or null
-
getMouseCursorShape
public int getMouseCursorShape(int positionX, int positionY)
Description copied from interface:CodeAreaPainter
Returns type of cursor for given painter relative position.- Specified by:
getMouseCursorShape
in interfaceCodeAreaPainter
- Parameters:
positionX
- component relative position XpositionY
- component relative position Y- Returns:
- java.awt.Cursor cursor type value
-
getPositionZone
@Nonnull public org.exbin.bined.basic.BasicCodeAreaZone getPositionZone(int positionX, int positionY)
Description copied from interface:CodeAreaPainter
Returns zone type for given position.- Specified by:
getPositionZone
in interfaceCodeAreaPainter
- Parameters:
positionX
- x-coordinatepositionY
- y-coordinate- Returns:
- specific zone in component
-
getBasicColors
@Nonnull public BasicCodeAreaColorsProfile getBasicColors()
Description copied from interface:BasicColorsCapableCodeAreaPainter
Returns basic profile for colors.- Specified by:
getBasicColors
in interfaceBasicColorsCapableCodeAreaPainter
- Returns:
- colors profile
-
setBasicColors
public void setBasicColors(BasicCodeAreaColorsProfile colorsProfile)
Description copied from interface:BasicColorsCapableCodeAreaPainter
Sets basic profile for colors.- Specified by:
setBasicColors
in interfaceBasicColorsCapableCodeAreaPainter
- Parameters:
colorsProfile
- colors profile
-
drawCenteredChars
protected void drawCenteredChars(java.awt.Graphics g, char[] drawnChars, int charOffset, int length, int cellWidth, int positionX, int positionY)
Draws characters centering it to cells of the same width.- Parameters:
g
- graphicsdrawnChars
- array of charscharOffset
- index of target character in arraylength
- number of characters to drawcellWidth
- width of cell to center intopositionX
- X position of drawing area startpositionY
- Y position of drawing area start
-
drawShiftedChars
protected void drawShiftedChars(java.awt.Graphics g, char[] drawnChars, int charOffset, int length, int positionX, int positionY)
-
getCursorPositionRect
@Nonnull public java.awt.Rectangle getCursorPositionRect(long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)
Returns cursor rectangle.- Parameters:
dataPosition
- data positioncodeOffset
- code offsetsection
- section- Returns:
- cursor rectangle or empty rectangle
-
updateRectToCursorPosition
protected void updateRectToCursorPosition(java.awt.Rectangle rect, long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)
-
updateScrollBars
public void updateScrollBars()
Description copied from interface:CodeAreaPainter
Performs update of scrollbars after change in data size or position.- Specified by:
updateScrollBars
in interfaceCodeAreaPainter
-
scrollPositionModified
public void scrollPositionModified()
Description copied from interface:CodeAreaPainter
Notify scroll position was modified. This is to assist detection of scrolling from outside compare to scrolling by scrollbar controls.- Specified by:
scrollPositionModified
in interfaceCodeAreaPainter
-
scrollPositionChanged
public void scrollPositionChanged()
Description copied from interface:CodeAreaPainter
Notify scroll position was changed outside of scrolling.- Specified by:
scrollPositionChanged
in interfaceCodeAreaPainter
-
getCharactersPerRow
protected int getCharactersPerRow()
-
getBytesPerRow
public int getBytesPerRow()
-
getRowHeight
public int getRowHeight()
-
-