Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
336d6ce1
J
jadx
项目概览
keyescgm
/
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,发现更多精彩内容 >>
提交
336d6ce1
编写于
4月 23, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(gui): use same font loader as code viewer (#584)
上级
f283ef43
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
103 addition
and
53 deletion
+103
-53
jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
+11
-15
jadx-gui/src/main/java/jadx/gui/settings/JadxSettingsWindow.java
...i/src/main/java/jadx/gui/settings/JadxSettingsWindow.java
+2
-1
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
+2
-8
jadx-gui/src/main/java/jadx/gui/utils/FontUtils.java
jadx-gui/src/main/java/jadx/gui/utils/FontUtils.java
+88
-0
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
+0
-29
未找到文件。
jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
浏览文件 @
336d6ce1
package
jadx.gui.settings
;
package
jadx.gui.settings
;
import
java.awt.Font
;
import
java.awt.*
;
import
java.awt.GraphicsDevice
;
import
java.awt.GraphicsEnvironment
;
import
java.awt.Window
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -23,9 +20,9 @@ import org.slf4j.LoggerFactory;
...
@@ -23,9 +20,9 @@ import org.slf4j.LoggerFactory;
import
jadx.api.JadxArgs
;
import
jadx.api.JadxArgs
;
import
jadx.cli.JadxCLIArgs
;
import
jadx.cli.JadxCLIArgs
;
import
jadx.gui.ui.codearea.EditorTheme
;
import
jadx.gui.ui.codearea.EditorTheme
;
import
jadx.gui.utils.FontUtils
;
import
jadx.gui.utils.LangLocale
;
import
jadx.gui.utils.LangLocale
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.Utils
;
public
class
JadxSettings
extends
JadxCLIArgs
{
public
class
JadxSettings
extends
JadxCLIArgs
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
JadxSettings
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
JadxSettings
.
class
);
...
@@ -295,22 +292,21 @@ public class JadxSettings extends JadxCLIArgs {
...
@@ -295,22 +292,21 @@ public class JadxSettings extends JadxCLIArgs {
if
(
fontStr
.
isEmpty
())
{
if
(
fontStr
.
isEmpty
())
{
return
DEFAULT_FONT
;
return
DEFAULT_FONT
;
}
}
return
Font
.
decode
(
fontStr
);
try
{
return
FontUtils
.
loadByStr
(
fontStr
);
}
catch
(
Exception
e
)
{
LOG
.
warn
(
"Failed to load font: {}, reset to default"
,
fontStr
,
e
);
setFont
(
DEFAULT_FONT
);
return
DEFAULT_FONT
;
}
}
}
public
void
setFont
(
@Nullable
Font
font
)
{
public
void
setFont
(
@Nullable
Font
font
)
{
if
(
font
==
null
)
{
if
(
font
==
null
)
{
this
.
fontStr
=
""
;
this
.
fontStr
=
""
;
return
;
}
else
{
}
this
.
fontStr
=
FontUtils
.
convertToStr
(
font
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
font
.
getFontName
());
String
fontStyleName
=
Utils
.
getFontStyleName
(
font
.
getStyle
()).
replaceAll
(
" "
,
""
);
if
(!
fontStyleName
.
isEmpty
())
{
sb
.
append
(
'-'
).
append
(
fontStyleName
.
toUpperCase
());
}
}
sb
.
append
(
'-'
).
append
(
font
.
getSize
());
this
.
fontStr
=
sb
.
toString
();
}
}
public
String
getEditorThemePath
()
{
public
String
getEditorThemePath
()
{
...
...
jadx-gui/src/main/java/jadx/gui/settings/JadxSettingsWindow.java
浏览文件 @
336d6ce1
...
@@ -14,6 +14,7 @@ import say.swing.JFontChooser;
...
@@ -14,6 +14,7 @@ import say.swing.JFontChooser;
import
jadx.gui.ui.MainWindow
;
import
jadx.gui.ui.MainWindow
;
import
jadx.gui.ui.codearea.EditorTheme
;
import
jadx.gui.ui.codearea.EditorTheme
;
import
jadx.gui.utils.FontUtils
;
import
jadx.gui.utils.LangLocale
;
import
jadx.gui.utils.LangLocale
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.Utils
;
import
jadx.gui.utils.Utils
;
...
@@ -267,7 +268,7 @@ public class JadxSettingsWindow extends JDialog {
...
@@ -267,7 +268,7 @@ public class JadxSettingsWindow extends JDialog {
private
String
getFontLabelStr
()
{
private
String
getFontLabelStr
()
{
Font
font
=
settings
.
getFont
();
Font
font
=
settings
.
getFont
();
String
fontStyleName
=
Utils
.
getFontStyleName
(
font
.
getStyle
());
String
fontStyleName
=
FontUtils
.
convertFontStyleToString
(
font
.
getStyle
());
return
NLS
.
str
(
"preferences.font"
)
+
": "
+
font
.
getFontName
()
+
' '
+
fontStyleName
+
' '
+
font
.
getSize
();
return
NLS
.
str
(
"preferences.font"
)
+
": "
+
font
.
getFontName
()
+
' '
+
fontStyleName
+
' '
+
font
.
getSize
();
}
}
...
...
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
浏览文件 @
336d6ce1
...
@@ -90,6 +90,7 @@ import jadx.gui.update.JadxUpdate;
...
@@ -90,6 +90,7 @@ import jadx.gui.update.JadxUpdate;
import
jadx.gui.update.JadxUpdate.IUpdateCallback
;
import
jadx.gui.update.JadxUpdate.IUpdateCallback
;
import
jadx.gui.update.data.Release
;
import
jadx.gui.update.data.Release
;
import
jadx.gui.utils.CacheObject
;
import
jadx.gui.utils.CacheObject
;
import
jadx.gui.utils.FontUtils
;
import
jadx.gui.utils.JumpPosition
;
import
jadx.gui.utils.JumpPosition
;
import
jadx.gui.utils.Link
;
import
jadx.gui.utils.Link
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.NLS
;
...
@@ -154,7 +155,7 @@ public class MainWindow extends JFrame {
...
@@ -154,7 +155,7 @@ public class MainWindow extends JFrame {
this
.
cacheObject
=
new
CacheObject
();
this
.
cacheObject
=
new
CacheObject
();
resetCache
();
resetCache
();
registerBundledFonts
();
FontUtils
.
registerBundledFonts
();
initUI
();
initUI
();
initMenuAndToolbar
();
initMenuAndToolbar
();
Utils
.
setWindowIcons
(
this
);
Utils
.
setWindowIcons
(
this
);
...
@@ -931,13 +932,6 @@ public class MainWindow extends JFrame {
...
@@ -931,13 +932,6 @@ public class MainWindow extends JFrame {
setSize
((
int
)
(
w
*
WINDOW_RATIO
),
(
int
)
(
h
*
WINDOW_RATIO
));
setSize
((
int
)
(
w
*
WINDOW_RATIO
),
(
int
)
(
h
*
WINDOW_RATIO
));
}
}
public
static
void
registerBundledFonts
()
{
GraphicsEnvironment
grEnv
=
GraphicsEnvironment
.
getLocalGraphicsEnvironment
();
if
(
Utils
.
FONT_HACK
!=
null
)
{
grEnv
.
registerFont
(
Utils
.
FONT_HACK
);
}
}
private
void
setEditorTheme
(
String
editorThemePath
)
{
private
void
setEditorTheme
(
String
editorThemePath
)
{
try
{
try
{
editorTheme
=
Theme
.
load
(
getClass
().
getResourceAsStream
(
editorThemePath
));
editorTheme
=
Theme
.
load
(
getClass
().
getResourceAsStream
(
editorThemePath
));
...
...
jadx-gui/src/main/java/jadx/gui/utils/FontUtils.java
0 → 100644
浏览文件 @
336d6ce1
package
jadx.gui.utils
;
import
java.awt.*
;
import
java.io.InputStream
;
import
javax.swing.text.StyleContext
;
import
org.jetbrains.annotations.Nullable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
public
class
FontUtils
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
FontUtils
.
class
);
public
static
final
Font
FONT_HACK
=
openFontTTF
(
"Hack-Regular"
);
public
static
void
registerBundledFonts
()
{
GraphicsEnvironment
grEnv
=
GraphicsEnvironment
.
getLocalGraphicsEnvironment
();
if
(
FontUtils
.
FONT_HACK
!=
null
)
{
grEnv
.
registerFont
(
FontUtils
.
FONT_HACK
);
}
}
public
static
Font
loadByStr
(
String
fontDesc
)
{
String
[]
parts
=
fontDesc
.
split
(
"-"
);
if
(
parts
.
length
!=
3
)
{
throw
new
JadxRuntimeException
(
"Unsupported font description format: "
+
fontDesc
);
}
String
name
=
parts
[
0
];
int
style
=
parseFontStyle
(
parts
[
1
]);
int
size
=
Integer
.
parseInt
(
parts
[
2
]);
StyleContext
sc
=
StyleContext
.
getDefaultStyleContext
();
Font
font
=
sc
.
getFont
(
name
,
style
,
size
);
if
(
font
==
null
)
{
throw
new
JadxRuntimeException
(
"Font not found: "
+
fontDesc
);
}
return
font
;
}
public
static
String
convertToStr
(
Font
font
)
{
return
font
.
getFontName
()
+
'-'
+
convertFontStyleToString
(
font
.
getStyle
())
+
'-'
+
font
.
getSize
();
}
public
static
String
convertFontStyleToString
(
int
style
)
{
if
(
style
==
0
)
{
return
"plain"
;
}
StringBuilder
sb
=
new
StringBuilder
();
if
((
style
&
Font
.
BOLD
)
!=
0
)
{
sb
.
append
(
"bold"
);
}
if
((
style
&
Font
.
ITALIC
)
!=
0
)
{
sb
.
append
(
" italic"
);
}
return
sb
.
toString
().
trim
();
}
private
static
int
parseFontStyle
(
String
str
)
{
int
style
=
0
;
if
(
str
.
contains
(
"bold"
))
{
style
|=
Font
.
BOLD
;
}
if
(
str
.
contains
(
"italic"
))
{
style
|=
Font
.
ITALIC
;
}
return
style
;
}
@Nullable
public
static
Font
openFontTTF
(
String
name
)
{
String
fontPath
=
"/fonts/"
+
name
+
".ttf"
;
try
(
InputStream
is
=
Utils
.
class
.
getResourceAsStream
(
fontPath
))
{
Font
font
=
Font
.
createFont
(
Font
.
TRUETYPE_FONT
,
is
);
return
font
.
deriveFont
(
12
f
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Failed load font by path: {}"
,
fontPath
,
e
);
return
null
;
}
}
private
FontUtils
()
{
}
}
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
浏览文件 @
336d6ce1
...
@@ -28,8 +28,6 @@ public class Utils {
...
@@ -28,8 +28,6 @@ public class Utils {
private
static
final
ImageIcon
ICON_ABSTRACT
=
openIcon
(
"abstract_co"
);
private
static
final
ImageIcon
ICON_ABSTRACT
=
openIcon
(
"abstract_co"
);
private
static
final
ImageIcon
ICON_NATIVE
=
openIcon
(
"native_co"
);
private
static
final
ImageIcon
ICON_NATIVE
=
openIcon
(
"native_co"
);
public
static
final
Font
FONT_HACK
=
openFontTTF
(
"Hack-Regular"
);
/**
/**
* The minimum about of memory in bytes we are trying to keep free, otherwise the application may run out of heap
* The minimum about of memory in bytes we are trying to keep free, otherwise the application may run out of heap
* which ends up in a Java garbage collector running "amok" (CPU utilization 100% for each core and the UI is
* which ends up in a Java garbage collector running "amok" (CPU utilization 100% for each core and the UI is
...
@@ -60,18 +58,6 @@ public class Utils {
...
@@ -60,18 +58,6 @@ public class Utils {
return
Toolkit
.
getDefaultToolkit
().
createImage
(
resource
);
return
Toolkit
.
getDefaultToolkit
().
createImage
(
resource
);
}
}
@Nullable
public
static
Font
openFontTTF
(
String
name
)
{
String
fontPath
=
"/fonts/"
+
name
+
".ttf"
;
try
(
InputStream
is
=
Utils
.
class
.
getResourceAsStream
(
fontPath
))
{
Font
font
=
Font
.
createFont
(
Font
.
TRUETYPE_FONT
,
is
);
return
font
.
deriveFont
(
12
f
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Failed load font by path: {}"
,
fontPath
,
e
);
return
null
;
}
}
public
static
void
addKeyBinding
(
JComponent
comp
,
KeyStroke
key
,
String
id
,
Action
action
)
{
public
static
void
addKeyBinding
(
JComponent
comp
,
KeyStroke
key
,
String
id
,
Action
action
)
{
comp
.
getInputMap
().
put
(
key
,
id
);
comp
.
getInputMap
().
put
(
key
,
id
);
comp
.
getActionMap
().
put
(
id
,
action
);
comp
.
getActionMap
().
put
(
id
,
action
);
...
@@ -180,21 +166,6 @@ public class Utils {
...
@@ -180,21 +166,6 @@ public class Utils {
}
}
}
}
@NotNull
public
static
String
getFontStyleName
(
int
style
)
{
if
(
style
==
0
)
{
return
"plain"
;
}
StringBuilder
sb
=
new
StringBuilder
();
if
((
style
&
Font
.
BOLD
)
!=
0
)
{
sb
.
append
(
"bold"
);
}
if
((
style
&
Font
.
ITALIC
)
!=
0
)
{
sb
.
append
(
" italic"
);
}
return
sb
.
toString
().
trim
();
}
public
static
void
setWindowIcons
(
Window
window
)
{
public
static
void
setWindowIcons
(
Window
window
)
{
List
<
Image
>
icons
=
new
ArrayList
<>();
List
<
Image
>
icons
=
new
ArrayList
<>();
icons
.
add
(
Utils
.
openImage
(
"/logos/jadx-logo-16px.png"
));
icons
.
add
(
Utils
.
openImage
(
"/logos/jadx-logo-16px.png"
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录