Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
7e8435cc
J
jadx
项目概览
Quincy379
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e8435cc
编写于
12月 06, 2018
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(gui): fill background before draw line numbers (#404)
上级
6d59f771
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
40 addition
and
22 deletion
+40
-22
jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
+40
-22
未找到文件。
jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
浏览文件 @
7e8435cc
...
@@ -20,8 +20,13 @@ import java.util.Map;
...
@@ -20,8 +20,13 @@ import java.util.Map;
import
org.fife.ui.rsyntaxtextarea.SyntaxScheme
;
import
org.fife.ui.rsyntaxtextarea.SyntaxScheme
;
import
org.fife.ui.rsyntaxtextarea.Token
;
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
{
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
long
serialVersionUID
=
-
4978268673635308190L
;
private
static
final
int
NUM_HEIGHT
=
Integer
.
MAX_VALUE
-
1000000
;
private
static
final
int
NUM_HEIGHT
=
Integer
.
MAX_VALUE
-
1000000
;
...
@@ -92,30 +97,42 @@ public class LineNumbers extends JPanel implements CaretListener {
...
@@ -92,30 +97,42 @@ public class LineNumbers extends JPanel implements CaretListener {
@Override
@Override
public
void
paintComponent
(
Graphics
g
)
{
public
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
super
.
paintComponent
(
g
);
g
.
setFont
(
codeArea
.
getFont
());
applyRenderHints
(
g
);
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
();
Insets
insets
=
getInsets
();
int
availableWidth
=
getSize
()
.
width
-
insets
.
left
-
insets
.
right
;
int
availableWidth
=
size
.
width
-
insets
.
left
-
insets
.
right
;
Rectangle
clip
=
g
.
getClipBounds
();
Rectangle
clip
=
g
.
getClipBounds
();
int
rowStartOffset
=
codeArea
.
viewToModel
(
new
Point
(
0
,
clip
.
y
));
int
rowStartOffset
=
codeArea
.
viewToModel
(
new
Point
(
0
,
clip
.
y
));
int
endOffset
=
codeArea
.
viewToModel
(
new
Point
(
0
,
clip
.
y
+
clip
.
height
));
int
endOffset
=
codeArea
.
viewToModel
(
new
Point
(
0
,
clip
.
y
+
clip
.
height
));
while
(
rowStartOffset
<=
endOffset
)
{
while
(
rowStartOffset
<=
endOffset
)
{
try
{
try
{
String
lineNumber
=
getTextLineNumber
(
rowStartOffset
);
if
(
lineNumber
!=
null
)
{
if
(
isCurrentLine
(
rowStartOffset
))
{
if
(
isCurrentLine
(
rowStartOffset
))
{
g
.
setColor
(
currentColor
);
g
.
setColor
(
currentColor
);
}
else
{
}
else
{
g
.
setColor
(
numberColor
);
g
.
setColor
(
numberColor
);
}
}
String
lineNumber
=
getTextLineNumber
(
rowStartOffset
);
int
stringWidth
=
fontMetrics
.
stringWidth
(
lineNumber
);
int
stringWidth
=
fontMetrics
.
stringWidth
(
lineNumber
);
int
x
=
availableWidth
-
stringWidth
+
insets
.
left
;
int
x
=
availableWidth
-
stringWidth
+
insets
.
left
;
int
y
=
getOffsetY
(
rowStartOffset
,
fontMetrics
);
int
y
=
getOffsetY
(
rowStartOffset
,
fontMetrics
);
g
.
drawString
(
lineNumber
,
x
,
y
);
g
.
drawString
(
lineNumber
,
x
,
y
);
}
rowStartOffset
=
Utilities
.
getRowEnd
(
codeArea
,
rowStartOffset
)
+
1
;
rowStartOffset
=
Utilities
.
getRowEnd
(
codeArea
,
rowStartOffset
)
+
1
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Line numbers draw error"
,
e
);
}
break
;
break
;
}
}
}
}
...
@@ -140,23 +157,24 @@ public class LineNumbers extends JPanel implements CaretListener {
...
@@ -140,23 +157,24 @@ public class LineNumbers extends JPanel implements CaretListener {
return
root
.
getElementIndex
(
rowStartOffset
)
==
root
.
getElementIndex
(
caretPosition
);
return
root
.
getElementIndex
(
rowStartOffset
)
==
root
.
getElementIndex
(
caretPosition
);
}
}
@Nullable
protected
String
getTextLineNumber
(
int
rowStartOffset
)
{
protected
String
getTextLineNumber
(
int
rowStartOffset
)
{
Element
root
=
codeArea
.
getDocument
().
getDefaultRootElement
();
Element
root
=
codeArea
.
getDocument
().
getDefaultRootElement
();
int
index
=
root
.
getElementIndex
(
rowStartOffset
);
int
index
=
root
.
getElementIndex
(
rowStartOffset
);
Element
line
=
root
.
getElement
(
index
);
Element
line
=
root
.
getElement
(
index
);
if
(
line
.
getStartOffset
()
==
rowStartOffset
)
{
if
(
line
.
getStartOffset
()
!=
rowStartOffset
)
{
return
null
;
}
int
lineNumber
=
index
+
1
;
int
lineNumber
=
index
+
1
;
if
(
useSourceLines
)
{
if
(
useSourceLines
)
{
Integer
sourceLine
=
codeArea
.
getSourceLine
(
lineNumber
);
Integer
sourceLine
=
codeArea
.
getSourceLine
(
lineNumber
);
if
(
sourceLine
!=
null
)
{
if
(
sourceLine
==
null
)
{
return
null
;
}
return
String
.
valueOf
(
sourceLine
);
return
String
.
valueOf
(
sourceLine
);
}
}
}
else
{
return
String
.
valueOf
(
lineNumber
);
return
String
.
valueOf
(
lineNumber
);
}
}
}
return
""
;
}
private
int
getOffsetY
(
int
rowStartOffset
,
FontMetrics
fontMetrics
)
throws
BadLocationException
{
private
int
getOffsetY
(
int
rowStartOffset
,
FontMetrics
fontMetrics
)
throws
BadLocationException
{
Rectangle
r
=
codeArea
.
modelToView
(
rowStartOffset
);
Rectangle
r
=
codeArea
.
modelToView
(
rowStartOffset
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录