Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
7e8435cc
Commit
7e8435cc
authored
Dec 06, 2018
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(gui): fill background before draw line numbers (#404)
parent
6d59f771
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
22 deletions
+40
-22
LineNumbers.java
jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
+40
-22
No files found.
jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
View file @
7e8435cc
...
...
@@ -20,8 +20,13 @@ import java.util.Map;
import
org.fife.ui.rsyntaxtextarea.SyntaxScheme
;
import
org.fife.ui.rsyntaxtextarea.Token
;
import
org.jetbrains.annotations.Nullable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
LineNumbers
extends
JPanel
implements
CaretListener
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
LineNumbers
.
class
);
private
static
final
long
serialVersionUID
=
-
4978268673635308190L
;
private
static
final
int
NUM_HEIGHT
=
Integer
.
MAX_VALUE
-
1000000
;
...
...
@@ -92,30 +97,42 @@ public class LineNumbers extends JPanel implements CaretListener {
@Override
public
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
g
.
setFont
(
codeArea
.
getFont
());
applyRenderHints
(
g
);
FontMetrics
fontMetrics
=
codeArea
.
getFontMetrics
(
codeArea
.
getFont
());
Font
font
=
codeArea
.
getFont
();
font
=
font
.
deriveFont
(
font
.
getSize2D
()
-
1.0f
);
g
.
setFont
(
font
);
Dimension
size
=
getSize
();
g
.
setColor
(
codeArea
.
getBackground
());
g
.
fillRect
(
0
,
0
,
size
.
width
,
size
.
height
);
FontMetrics
fontMetrics
=
codeArea
.
getFontMetrics
(
font
);
Insets
insets
=
getInsets
();
int
availableWidth
=
getSize
()
.
width
-
insets
.
left
-
insets
.
right
;
int
availableWidth
=
size
.
width
-
insets
.
left
-
insets
.
right
;
Rectangle
clip
=
g
.
getClipBounds
();
int
rowStartOffset
=
codeArea
.
viewToModel
(
new
Point
(
0
,
clip
.
y
));
int
endOffset
=
codeArea
.
viewToModel
(
new
Point
(
0
,
clip
.
y
+
clip
.
height
));
while
(
rowStartOffset
<=
endOffset
)
{
try
{
if
(
isCurrentLine
(
rowStartOffset
))
{
g
.
setColor
(
currentColor
);
}
else
{
g
.
setColor
(
numberColor
);
}
String
lineNumber
=
getTextLineNumber
(
rowStartOffset
);
int
stringWidth
=
fontMetrics
.
stringWidth
(
lineNumber
);
int
x
=
availableWidth
-
stringWidth
+
insets
.
left
;
int
y
=
getOffsetY
(
rowStartOffset
,
fontMetrics
);
g
.
drawString
(
lineNumber
,
x
,
y
);
if
(
lineNumber
!=
null
)
{
if
(
isCurrentLine
(
rowStartOffset
))
{
g
.
setColor
(
currentColor
);
}
else
{
g
.
setColor
(
numberColor
);
}
int
stringWidth
=
fontMetrics
.
stringWidth
(
lineNumber
);
int
x
=
availableWidth
-
stringWidth
+
insets
.
left
;
int
y
=
getOffsetY
(
rowStartOffset
,
fontMetrics
);
g
.
drawString
(
lineNumber
,
x
,
y
);
}
rowStartOffset
=
Utilities
.
getRowEnd
(
codeArea
,
rowStartOffset
)
+
1
;
}
catch
(
Exception
e
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Line numbers draw error"
,
e
);
}
break
;
}
}
...
...
@@ -140,22 +157,23 @@ public class LineNumbers extends JPanel implements CaretListener {
return
root
.
getElementIndex
(
rowStartOffset
)
==
root
.
getElementIndex
(
caretPosition
);
}
@Nullable
protected
String
getTextLineNumber
(
int
rowStartOffset
)
{
Element
root
=
codeArea
.
getDocument
().
getDefaultRootElement
();
int
index
=
root
.
getElementIndex
(
rowStartOffset
);
Element
line
=
root
.
getElement
(
index
);
if
(
line
.
getStartOffset
()
==
rowStartOffset
)
{
int
lineNumber
=
index
+
1
;
if
(
useSourceLines
)
{
Integer
sourceLine
=
codeArea
.
getSourceLine
(
lineNumber
);
if
(
sourceLine
!=
null
)
{
return
String
.
valueOf
(
sourceLine
);
}
}
else
{
return
String
.
valueOf
(
lineNumber
);
if
(
line
.
getStartOffset
()
!=
rowStartOffset
)
{
return
null
;
}
int
lineNumber
=
index
+
1
;
if
(
useSourceLines
)
{
Integer
sourceLine
=
codeArea
.
getSourceLine
(
lineNumber
);
if
(
sourceLine
==
null
)
{
return
null
;
}
return
String
.
valueOf
(
sourceLine
);
}
return
""
;
return
String
.
valueOf
(
lineNumber
)
;
}
private
int
getOffsetY
(
int
rowStartOffset
,
FontMetrics
fontMetrics
)
throws
BadLocationException
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment