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 CodeAreaCorecodeArea
-
Constructor Summary
Constructors Constructor Description DefaultCodeAreaPainter(CodeAreaCore codeArea)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattach()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.CodeAreaCaretPositioncomputeMovePosition(org.exbin.bined.CodeAreaCaretPosition position, org.exbin.bined.basic.MovementDirection direction)Computes position for movement action.org.exbin.bined.basic.PositionScrollVisibilitycomputePositionScrollVisibility(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.CodeAreaScrollPositioncomputeScrolling(org.exbin.bined.basic.CodeAreaScrollPosition startPosition, org.exbin.bined.basic.ScrollingDirection direction)Computes scrolling position for given shift action.voiddetach()Detaches painter to code area.protected voiddrawCenteredChars(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 voiddrawShiftedChars(java.awt.Graphics g, char[] drawnChars, int charOffset, int length, int positionX, int positionY)voidfontChanged(java.awt.Graphics g)BasicCodeAreaColorsProfilegetBasicColors()Returns basic profile for colors.intgetBytesPerRow()java.awt.RectanglegetCursorPositionRect(long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)Returns cursor rectangle.protected intgetCharactersPerRow()intgetMouseCursorShape(int positionX, int positionY)Returns type of cursor for given painter relative position.java.awt.ColorgetPositionBackgroundColor(long rowDataPosition, int byteOnRow, int charOnRow, org.exbin.bined.CodeAreaSection section)Returns background color for particular code.java.awt.PointgetPositionPoint(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.ColorgetPositionTextColor(long rowDataPosition, int byteOnRow, int charOnRow, org.exbin.bined.CodeAreaSection section)Returns background color for particular code.org.exbin.bined.basic.BasicCodeAreaZonegetPositionZone(int positionX, int positionY)Returns zone type for given position.intgetRowHeight()booleanisInitialized()Returns true if painter was initialized.org.exbin.bined.CodeAreaCaretPositionmousePositionToClosestCaretPosition(int positionX, int positionY, org.exbin.bined.CaretOverlapMode overflowMode)Returns closest caret position for provided component relative mouse position.voidpaintBackground(java.awt.Graphics g)Paints main area background.voidpaintComponent(java.awt.Graphics g)Paints the main component.voidpaintCursor(java.awt.Graphics g)Paints cursor symbol.voidpaintHeader(java.awt.Graphics g)voidpaintMainArea(java.awt.Graphics g)Paints main data section of the component.voidpaintOutsideArea(java.awt.Graphics g)voidpaintRowBackground(java.awt.Graphics g, long rowDataPosition, int rowPositionX, int rowPositionY)Paints row background.voidpaintRowPosition(java.awt.Graphics g)voidpaintRows(java.awt.Graphics g)voidpaintRowText(java.awt.Graphics g, long rowDataPosition, int rowPositionX, int rowPositionY)Paints row text.voidrebuildColors()Calls rebuild of the colors profile.voidrecomputeCharPositions()voidreset()Resets complete painter state for new painting.voidresetCaret()Resets caret state.voidresetColors()Rebuilds colors after UIManager change.voidresetFont()Resets painter font state for new painting.voidresetLayout()Updates painter layout state for new painting.voidscrollPositionChanged()Notify scroll position was changed outside of scrolling.voidscrollPositionModified()Notify scroll position was modified.voidsetBasicColors(BasicCodeAreaColorsProfile colorsProfile)Sets basic profile for colors.protected voidupdateCache()protected voidupdateRectToCursorPosition(java.awt.Rectangle rect, long dataPosition, int codeOffset, org.exbin.bined.CodeAreaSection section)voidupdateScrollBars()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:CodeAreaPainterAttaches painter to code area.- Specified by:
attachin interfaceCodeAreaPainter
-
detach
public void detach()
Description copied from interface:CodeAreaPainterDetaches painter to code area.- Specified by:
detachin interfaceCodeAreaPainter
-
reset
public void reset()
Description copied from interface:CodeAreaPainterResets complete painter state for new painting.- Specified by:
resetin interfaceCodeAreaPainter
-
resetColors
public void resetColors()
Description copied from interface:CodeAreaPainterRebuilds colors after UIManager change.- Specified by:
resetColorsin interfaceCodeAreaPainter
-
resetFont
public void resetFont()
Description copied from interface:CodeAreaPainterResets painter font state for new painting.- Specified by:
resetFontin interfaceCodeAreaPainter
-
resetLayout
public void resetLayout()
Description copied from interface:CodeAreaPainterUpdates painter layout state for new painting.- Specified by:
resetLayoutin interfaceCodeAreaPainter
-
resetCaret
public void resetCaret()
Description copied from interface:CodeAreaPainterResets caret state.- Specified by:
resetCaretin interfaceCodeAreaPainter
-
rebuildColors
public void rebuildColors()
Description copied from interface:CodeAreaPainterCalls rebuild of the colors profile.- Specified by:
rebuildColorsin interfaceCodeAreaPainter
-
recomputeCharPositions
public void recomputeCharPositions()
-
fontChanged
public void fontChanged(java.awt.Graphics g)
-
isInitialized
public boolean isInitialized()
Description copied from interface:CodeAreaPainterReturns true if painter was initialized.- Specified by:
isInitializedin interfaceCodeAreaPainter- Returns:
- true if initialized
-
paintComponent
public void paintComponent(java.awt.Graphics g)
Description copied from interface:CodeAreaPainterPaints the main component.- Specified by:
paintComponentin 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:CodeAreaPainterPaints main data section of the component.- Specified by:
paintMainAreain 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:CodeAreaPainterReturns state of the visibility of given caret position within current scrolling window.- Specified by:
computePositionScrollVisibilityin 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:CodeAreaPainterReturns 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:
computeRevealScrollPositionin 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:CodeAreaPainterReturns 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:
computeCenterOnScrollPositionin 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:CodeAreaPainterPaints cursor symbol.- Specified by:
paintCursorin 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:CodeAreaPainterReturns closest caret position for provided component relative mouse position.- Specified by:
mousePositionToClosestCaretPositionin 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:CodeAreaPainterComputes position for movement action.- Specified by:
computeMovePositionin 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:CodeAreaPainterComputes scrolling position for given shift action.- Specified by:
computeScrollingin 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:CodeAreaPainterReturns type of cursor for given painter relative position.- Specified by:
getMouseCursorShapein 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:CodeAreaPainterReturns zone type for given position.- Specified by:
getPositionZonein interfaceCodeAreaPainter- Parameters:
positionX- x-coordinatepositionY- y-coordinate- Returns:
- specific zone in component
-
getBasicColors
@Nonnull public BasicCodeAreaColorsProfile getBasicColors()
Description copied from interface:BasicColorsCapableCodeAreaPainterReturns basic profile for colors.- Specified by:
getBasicColorsin interfaceBasicColorsCapableCodeAreaPainter- Returns:
- colors profile
-
setBasicColors
public void setBasicColors(BasicCodeAreaColorsProfile colorsProfile)
Description copied from interface:BasicColorsCapableCodeAreaPainterSets basic profile for colors.- Specified by:
setBasicColorsin 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:CodeAreaPainterPerforms update of scrollbars after change in data size or position.- Specified by:
updateScrollBarsin interfaceCodeAreaPainter
-
scrollPositionModified
public void scrollPositionModified()
Description copied from interface:CodeAreaPainterNotify scroll position was modified. This is to assist detection of scrolling from outside compare to scrolling by scrollbar controls.- Specified by:
scrollPositionModifiedin interfaceCodeAreaPainter
-
scrollPositionChanged
public void scrollPositionChanged()
Description copied from interface:CodeAreaPainterNotify scroll position was changed outside of scrolling.- Specified by:
scrollPositionChangedin interfaceCodeAreaPainter
-
getCharactersPerRow
protected int getCharactersPerRow()
-
getBytesPerRow
public int getBytesPerRow()
-
getRowHeight
public int getRowHeight()
-
-