Skip to content

Commit 6815ce1

Browse files
Upgraded grab ui;
Added Icon themes system.
1 parent 2759579 commit 6815ce1

66 files changed

Lines changed: 1193 additions & 320 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies {
1919
implementation files(getToolsJar())
2020

2121
include('org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0') {
22-
exclude group: 'org.apache.logging.log4j', module: 'log4j-api'
22+
// exclude group: 'org.apache.logging.log4j', module: 'log4j-api'
2323
}
2424
include 'org.apache.logging.log4j:log4j-api:2.0-beta9'
2525
include 'com.google.code.gson:gson:2.8.9'
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.artur114.bytecodegrab.conf;
2+
3+
import com.artur114.bytecodegrab.main.AppBootstrap;
4+
import com.google.gson.Gson;
5+
6+
import java.io.IOException;
7+
import java.io.InputStreamReader;
8+
import java.io.OutputStreamWriter;
9+
import java.nio.charset.StandardCharsets;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
13+
14+
public class AppConfig {
15+
private static final Gson gson = new Gson();
16+
private final ConfigObject data;
17+
18+
private AppConfig(ConfigObject data) {
19+
this.data = data;
20+
}
21+
22+
public GrabConfig grabConfig() {
23+
return this.data.grabConfig;
24+
}
25+
26+
public void save() {
27+
saveConfig(this.data);
28+
}
29+
30+
public static AppConfig load() {
31+
Path path = configPath();
32+
if (!Files.exists(path)) {
33+
return new AppConfig(new ConfigObject());
34+
}
35+
try (InputStreamReader isr = new InputStreamReader(Files.newInputStream(path), StandardCharsets.UTF_8)) {
36+
ConfigObject config = gson.fromJson(isr, ConfigObject.class);
37+
if (config == null) return new AppConfig(new ConfigObject());
38+
return new AppConfig(config);
39+
} catch (IOException e) {
40+
e.printStackTrace(System.err);
41+
}
42+
43+
return new AppConfig(new ConfigObject());
44+
}
45+
46+
private static void saveConfig(ConfigObject config) {
47+
try (OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(configPath()), StandardCharsets.UTF_8)) {
48+
osw.write(gson.toJson(config));
49+
} catch (IOException e) {
50+
e.printStackTrace(System.err);
51+
}
52+
}
53+
54+
private static Path configPath() {
55+
String tempDir = System.getProperty("java.io.tmpdir");
56+
Path bcDir = Paths.get(tempDir, "ByteCodeGrabber");
57+
try {
58+
Files.createDirectories(bcDir);
59+
} catch (IOException ignored) {}
60+
return bcDir.resolve("main-data.json");
61+
}
62+
63+
private static class ConfigObject {
64+
public GrabConfig grabConfig = new GrabConfig();
65+
}
66+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.artur114.bytecodegrab.conf;
2+
3+
public class GrabConfig {
4+
public boolean checkBoxOPState = false;
5+
public boolean checkBoxState = false;
6+
public String lastSaveFolder = "";
7+
public int lastWriteFormat = 0;
8+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.artur114.bytecodegrab.jcomp;
2+
3+
import com.artur114.bytecodegrab.util.EnumAxis;
4+
5+
import javax.swing.*;
6+
import java.awt.*;
7+
import java.awt.event.ActionListener;
8+
import java.util.ArrayList;
9+
import java.util.Comparator;
10+
import java.util.List;
11+
import java.util.function.Consumer;
12+
13+
public class JButtonsPane extends JPanel {
14+
private final List<JButton> buttons = new ArrayList<>();
15+
public JButtonsPane(EnumAxis axis) {
16+
this.setLayout(new BoxLayout(this, axis.toBoxLayout()));
17+
}
18+
19+
public void addGlobalActionListener(ActionListener listener) {
20+
for (JButton button : this.buttons) {
21+
button.addActionListener(listener);
22+
}
23+
}
24+
25+
public void addSplitter(int size) {
26+
this.add(Box.createHorizontalStrut(size));
27+
}
28+
29+
public void add(JButton button) {
30+
if (this.buttons.contains(button)) {
31+
return;
32+
}
33+
this.buttons.add(button);
34+
this.add((Component) button);
35+
}
36+
37+
public JButton createButton(Icon icon) {
38+
JButton button = new JButton(icon);
39+
this.buttons.add(button);
40+
this.add(button);
41+
return button;
42+
}
43+
44+
public JButton createButton(String text) {
45+
JButton button = new JButton(text);
46+
this.buttons.add(button);
47+
this.add((Component) button);
48+
return button;
49+
}
50+
51+
public JButton createButton(String text, Icon icon) {
52+
JButton button = new JButton(text, icon);
53+
this.buttons.add(button);
54+
this.add((Component) button);
55+
return button;
56+
}
57+
58+
public JButton createButton(Icon icon, Consumer<JButton> conf) {
59+
JButton button = new JButton(icon);
60+
this.buttons.add(button);
61+
this.add((Component) button);
62+
conf.accept(button);
63+
return button;
64+
}
65+
66+
public JButton createButton(String text, Consumer<JButton> conf) {
67+
JButton button = new JButton(text);
68+
this.buttons.add(button);
69+
this.add((Component) button);
70+
conf.accept(button);
71+
return button;
72+
}
73+
74+
public JButton createButton(String text, Icon icon, Consumer<JButton> conf) {
75+
JButton button = new JButton(text, icon);
76+
this.buttons.add(button);
77+
this.add((Component) button);
78+
conf.accept(button);
79+
return button;
80+
}
81+
82+
83+
public void configure(Consumer<JButton> conf) {
84+
for (JButton button : this.buttons) {
85+
conf.accept(button);
86+
}
87+
}
88+
89+
public void sort(Comparator<? super JButton> comparator) {
90+
this.sort(comparator, false);
91+
}
92+
93+
public void sort(Comparator<? super JButton> comparator, boolean recompile) {
94+
this.buttons.sort(comparator);
95+
if (recompile) this.recompile();
96+
}
97+
98+
public void recompile() {
99+
for (Component component : this.getComponents()) {
100+
this.remove(component);
101+
}
102+
103+
for (JButton button : this.buttons) {
104+
this.add(button);
105+
}
106+
107+
this.revalidate();
108+
this.repaint();
109+
}
110+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.artur114.bytecodegrab.jcomp;
2+
3+
import javax.swing.*;
4+
import javax.swing.event.DocumentEvent;
5+
import javax.swing.event.DocumentListener;
6+
import java.awt.*;
7+
8+
public class JCTreeSearchPanel extends JPanel implements DocumentListener {
9+
private final JTextField search;
10+
private final JClassTree tree;
11+
12+
public JCTreeSearchPanel(JClassTree tree) {
13+
this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
14+
JTextField search = new JTextField();
15+
search.setFont(search.getFont().deriveFont(11f));
16+
search.getDocument().addDocumentListener(this);
17+
search.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory.createLineBorder(Color.LIGHT_GRAY)));
18+
this.add(Box.createHorizontalStrut(4));
19+
JLabel label = new JLabel("Search: ");
20+
label.setFont(label.getFont().deriveFont(11f));
21+
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));
22+
this.add(label);
23+
this.add(search);
24+
this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
25+
this.search = search;
26+
this.tree = tree;
27+
}
28+
29+
@Override
30+
public void insertUpdate(DocumentEvent e) {
31+
this.performSearch();
32+
}
33+
34+
@Override
35+
public void removeUpdate(DocumentEvent e) {
36+
this.performSearch();
37+
}
38+
39+
@Override
40+
public void changedUpdate(DocumentEvent e) {
41+
this.performSearch();
42+
}
43+
44+
private void performSearch() {
45+
String query = this.search.getText().trim();
46+
tree.searchBy(query);
47+
}
48+
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.artur114.bytecodegrab.jcomp;
22

3+
import com.artur114.bytecodegrab.util.ArrayListenBuss;
4+
import com.artur114.bytecodegrab.util.IListenBuss;
5+
import com.artur114.bytecodegrab.util.IListener;
6+
37
import java.awt.*;
48

59
public class JCardContainer {
10+
private final IListenBuss<IListener<String>, String> cardChangeListenBuss = new ArrayListenBuss<>();
611
private final Container container;
712
private final CardLayout card;
813
private String showedCard;
@@ -14,17 +19,20 @@ public JCardContainer(Container container, CardLayout card) {
1419
}
1520

1621
public JCardContainer(Container container) {
17-
this.card = (CardLayout) container.getLayout();
18-
this.container = container;
22+
this(container, (CardLayout) container.getLayout());
23+
}
24+
25+
public void addCardChangeListener(IListener<String> listener) {
26+
this.cardChangeListenBuss.registerListener(listener);
1927
}
2028

2129
public void show(String card) {
2230
this.card.show(this.container, card);
23-
31+
this.cardChangeListenBuss.listen(card);
2432
this.showedCard = card;
2533
}
2634

2735
public boolean isShowed(String card) {
28-
return card.equals(showedCard);
36+
return card.equals(this.showedCard);
2937
}
3038
}

src/main/java/com/artur114/bytecodegrab/jcomp/JClassTree.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import java.awt.*;
1313
import java.awt.event.MouseAdapter;
1414
import java.awt.event.MouseEvent;
15-
import java.awt.event.MouseListener;
16-
import java.awt.event.MouseMotionListener;
1715
import java.util.List;
1816
import java.util.*;
1917

@@ -361,11 +359,10 @@ public static PackageInfo merge(PackageInfo info, PackageInfo childInfo) {
361359
}
362360

363361
private static class ClassTreeCellRenderer extends DefaultTreeCellRenderer {
364-
private final Icon packageIcon = Icons.resizeIcon(Icons.icon("folder.png"), 20, 20);
365-
private final Icon classIcon = Icons.resizeIcon(Icons.icon("java_class.png"), 20, 20);
366-
private final Icon classIconU = Icons.resizeIcon(Icons.icon("java_class_u.png"), 20, 20);
367-
private final Icon packageIconD = Icons.resizeIcon(Icons.icon("folder_d.png"), 20, 20);
368-
private final Icon classIconD = Icons.resizeIcon(Icons.icon("java_class_d.png"), 20, 20);
362+
private final Icon packageIcon = Icons.iconQuad("folder", 20);
363+
private final Icon classIcon = Icons.iconQuad("java_class", 20);
364+
private final Icon packageIconD = Icons.iconQuadD("folder", 20);
365+
private final Icon classIconD = Icons.iconQuadD("java_class", 20);
369366

370367

371368
@Override
@@ -375,11 +372,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
375372
Object userObj = node.getUserObject();
376373
if (userObj instanceof ClassInfo) {
377374
this.setDisabledIcon(classIconD);
378-
if (((ClassInfo) userObj).fullName.startsWith("!")) {
379-
this.setIcon(classIconU);
380-
} else {
381-
this.setIcon(classIcon);
382-
}
375+
this.setIcon(classIcon);
383376
} else {
384377
this.setDisabledIcon(packageIconD);
385378
this.setIcon(packageIcon);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.artur114.bytecodegrab.jcomp;
2+
3+
import javax.swing.*;
4+
import java.util.concurrent.Callable;
5+
6+
public class JDynLabel extends JLabel {
7+
private Callable<String> label;
8+
9+
public JDynLabel(String text, Icon icon, int horizontalAlignment) {
10+
super(text, icon, horizontalAlignment);
11+
}
12+
13+
public JDynLabel(String text, int horizontalAlignment) {
14+
super(text, horizontalAlignment);
15+
}
16+
17+
public JDynLabel(String text) {
18+
super(text);
19+
}
20+
21+
public JDynLabel(Icon image, int horizontalAlignment) {
22+
super(image, horizontalAlignment);
23+
}
24+
25+
public JDynLabel(Icon image) {
26+
super(image);
27+
}
28+
29+
public JDynLabel(Callable<String> label) {
30+
this.label = label;
31+
32+
try {
33+
this.setText(this.label.call());
34+
} catch (Exception ignored) {}
35+
}
36+
37+
public JDynLabel() {}
38+
39+
public void setDynText(Callable<String> label) {
40+
this.label = label;
41+
}
42+
43+
public void update() {
44+
try {
45+
this.setText(this.label.call());
46+
} catch (Exception ignored) {}
47+
}
48+
49+
@Override
50+
public void revalidate() {
51+
try {
52+
this.setText(this.label.call());
53+
} catch (Exception ignored) {}
54+
55+
super.revalidate();
56+
}
57+
}

0 commit comments

Comments
 (0)