Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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
336d6ce1
Commit
336d6ce1
authored
Apr 23, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(gui): use same font loader as code viewer (#584)
parent
f283ef43
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
53 deletions
+103
-53
JadxSettings.java
jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
+11
-15
JadxSettingsWindow.java
...i/src/main/java/jadx/gui/settings/JadxSettingsWindow.java
+2
-1
MainWindow.java
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
+2
-8
FontUtils.java
jadx-gui/src/main/java/jadx/gui/utils/FontUtils.java
+88
-0
Utils.java
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
+0
-29
No files found.
jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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"
));
...
...
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