Skip to content

Commit

Permalink
Remvoed 3rd party filechooser and made LaF customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Oct 13, 2023
1 parent be28d59 commit 0954be4
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 26 deletions.
5 changes: 0 additions & 5 deletions runtime-decompiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@
<artifactId>rsyntaxtextarea</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>com.github.fracpete</groupId>
<artifactId>vfsjfilechooser2</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-install</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions runtime-decompiler/src/main/java/org/jrd/backend/data/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class Config {
private static final String DEPNDENCE_NUMBERS = "DEPNDENCE_NUMBERS";
private static final String ADDITIONAL_SOURCE_PATH = "ADDITIONAL_SOURCE_PATH";
private static final String ADDITIONAL_CLASS_PATH = "ADDITIONAL_CLASS_PATH";
private static final String LOOK_AND_FEEL_KEY = "LOOK_AND_FEEL";
//this is not persistent, is used for transfering detected value to compiler with other settings
private Optional<Integer> sourceTargetValue;
private FsAgent additionalClassPathAgent;
Expand Down Expand Up @@ -442,6 +443,19 @@ public String getAdditionalSP() {
return s.toString();
}

public String getLaF() {
Object s = configMap.get(LOOK_AND_FEEL_KEY);
if (s == null) {
s = null;
}
return (String) s;
}

public void setLaF(String fqn) throws IOException {
configMap.put(LOOK_AND_FEEL_KEY, fqn);
saveConfigFile();
}

public byte[] getAdditionalClassPathBytes(String fqn) {
if (additionalClassPathAgent == null) {
return new byte[0];
Expand Down
19 changes: 10 additions & 9 deletions runtime-decompiler/src/main/java/org/jrd/backend/data/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.jrd.frontend.frame.main.decompilerview.DecompilationController;
import org.jrd.frontend.frame.main.MainFrameView;

import javax.swing.UIManager;

public class Main {

public static void main(String[] allArgs) throws Exception {
Expand Down Expand Up @@ -40,16 +42,15 @@ public static void main(String[] allArgs) throws Exception {
}

public static void setLookAndFeel() {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(info.getClassName()) ||
Directories.isOsWindows() && "com.sun.java.swing.plaf.windows.WindowsLookAndFeel".equals(info.getClassName())) {
try {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
} catch (Exception e) {
Logger.getLogger().log(Logger.Level.DEBUG, e);
}
break;
try {
String laf = Config.getConfig().getLaF();
if (laf == null) {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} else {
UIManager.setLookAndFeel(laf);
}
} catch (Exception e) {
Logger.getLogger().log(Logger.Level.DEBUG, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jrd.frontend.frame.overwrite;

import com.googlecode.vfsjfilechooser2.VFSJFileChooser;

import io.github.mkoncek.classpathless.api.ClassIdentifier;
import io.github.mkoncek.classpathless.api.ClassesProvider;
import io.github.mkoncek.classpathless.api.ClasspathlessCompiler;
Expand Down Expand Up @@ -292,10 +290,10 @@ public OverwriteClassDialog(
saveBytemanAs = new JButton("Save copy as");
saveBytemanAs.addActionListener(a -> {
try {
VFSJFileChooser chooser = new VFSJFileChooser(Config.getConfig().getBytemanScriptFile(name).getParentFile());
chooser.setDialogType(VFSJFileChooser.DIALOG_TYPE.SAVE);
VFSJFileChooser.RETURN_TYPE selcted = chooser.showOpenDialog(OverwriteClassDialog.this);
if (selcted != VFSJFileChooser.RETURN_TYPE.APPROVE) {
JFileChooser chooser = new JFileChooser(Config.getConfig().getBytemanScriptFile(name).getParentFile());
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
int selcted = chooser.showOpenDialog(OverwriteClassDialog.this);
if (selcted != JFileChooser.APPROVE_OPTION) {
bytemanStatus.setText("not saving");
return;
}
Expand All @@ -308,10 +306,10 @@ public OverwriteClassDialog(
loadByteman = new JButton("Replace from file");
loadByteman.addActionListener(a -> {
try {
VFSJFileChooser chooser = new VFSJFileChooser(Config.getConfig().getBytemanScriptFile(name).getParentFile());
chooser.setDialogType(VFSJFileChooser.DIALOG_TYPE.OPEN);
VFSJFileChooser.RETURN_TYPE selcted = chooser.showOpenDialog(OverwriteClassDialog.this);
if (selcted != VFSJFileChooser.RETURN_TYPE.APPROVE) {
JFileChooser chooser = new JFileChooser(Config.getConfig().getBytemanScriptFile(name).getParentFile());
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
int selcted = chooser.showOpenDialog(OverwriteClassDialog.this);
if (selcted != JFileChooser.APPROVE_OPTION) {
bytemanStatus.setText("not loading");
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jrd.frontend.frame.settings;

import org.jrd.backend.core.Logger;
import org.jrd.backend.data.Config;
import org.jrd.frontend.frame.filesystem.NewFsVmView;
import org.jrd.frontend.frame.main.decompilerview.BytecodeDecompilerView;
Expand All @@ -9,16 +10,24 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.Enumeration;

public class MiscellaneousSettingsPanel extends JPanel implements ChangeReporter {
Expand All @@ -27,6 +36,7 @@ public class MiscellaneousSettingsPanel extends JPanel implements ChangeReporter
private final JCheckBox useJavapSignaturesCheckBox;
private final JCheckBox detectAutocompletionCheckBox;
private final JComboBox<Config.DepndenceNumbers> dependenceNumbers;
private final JComboBox<String> lookAndFeel;
private final JTextField srcPath;
private final JTextField classPath;
ButtonGroup additionalAgentPlace = new ButtonGroup();
Expand All @@ -37,7 +47,7 @@ public class MiscellaneousSettingsPanel extends JPanel implements ChangeReporter

public MiscellaneousSettingsPanel(
boolean initialUseJavapSignatures, Config.DepndenceNumbers initialConfigNumbers, String cp, String sp,
boolean detectAutocompletion, Config.AdditionalAgentAction additionalAgentAction
boolean detectAutocompletion, Config.AdditionalAgentAction additionalAgentAction, final JFrame parent
) {
miscSettingsLabel = new JLabel("Miscellaneous settings");
this.setName(miscSettingsLabel.getText());
Expand All @@ -51,7 +61,17 @@ public MiscellaneousSettingsPanel(
srcPath = new JTextField(sp);
classPath = new JTextField(cp);

lookAndFeel =
new JComboBox<>(Arrays.stream(UIManager.getInstalledLookAndFeels()).map(a -> a.getClassName()).toArray(String[]::new));
for (int x = 0; x < lookAndFeel.getModel().getSize(); x++) {
if (lookAndFeel.getItemAt(x).equals(UIManager.getLookAndFeel().getClass().getName())) {
lookAndFeel.setSelectedIndex(x);
}
}
lookAndFeel.addActionListener(new ChangeLafListener(parent));

initMainPanel(initialConfigNumbers, additionalAgentAction);

}

@SuppressWarnings({"ExecutableStatementCount", "JavaNCSS"}) // un-refactorable
Expand Down Expand Up @@ -155,6 +175,9 @@ private void initMainPanel(Config.DepndenceNumbers initialConfigNumbers, Config.
}
}
mainPanel.add(radioPanel, gbc);
gbc.gridwidth = 1;
gbc.gridy = 10;
mainPanel.add(lookAndFeel, gbc);
}

public boolean shouldUseJavapSignatures() {
Expand Down Expand Up @@ -192,4 +215,32 @@ public String getAdditionalSP() {
public Config.AdditionalAgentAction getAdditionalAgentAction() {
return Config.AdditionalAgentAction.fromString(additionalAgentPlace.getSelection().getActionCommand());
}

private final class ChangeLafListener implements ActionListener {
private final JFrame parent;

private ChangeLafListener(JFrame parent) {
this.parent = parent;
}

@Override
public void actionPerformed(ActionEvent a) {
try {
UIManager.setLookAndFeel(lookAndFeel.getSelectedItem().toString());
SwingUtilities.updateComponentTreeUI(parent);
Container configParent = MiscellaneousSettingsPanel.this.getParent();
while (true) {
if (configParent instanceof JDialog) {
SwingUtilities.updateComponentTreeUI(configParent);
break;
}
configParent = configParent.getParent();
}
Config.getConfig().setLaF(lookAndFeel.getSelectedItem().toString());
} catch (Exception e) {
Logger.getLogger().log(Logger.Level.DEBUG, e);
JOptionPane.showMessageDialog(MiscellaneousSettingsPanel.this, e.toString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void actionPerformed(ActionEvent actionEvent) {
nestedJarsSettingsPanel.setMinimumSize(new Dimension(200, 200));
miscSettingsPanel = new MiscellaneousSettingsPanel(
config.doUseJavapSignatures(), config.doDepndenceNumbers(), config.getAdditionalCP(), config.getAdditionalSP(),
config.doAutocompletion(), config.getAdditionalAgentAction()
config.doAutocompletion(), config.getAdditionalAgentAction(), mainFrameView
);

for (
Expand Down

0 comments on commit 0954be4

Please sign in to comment.