Settings Dialogues

This commit is contained in:
Konloch 2021-07-19 05:23:57 -07:00
parent b678d98949
commit 0eb9622634
4 changed files with 47 additions and 27 deletions

View File

@ -126,8 +126,14 @@ public class MainViewerGUI extends JFrame
//all of the settings main menu components
public final JMenu rstaTheme = new TranslatedJMenu("Text Area Theme", Translation.TEXT_AREA_THEME);
public final JMenuItem rstaThemeSettings = new TranslatedJMenuItem("Text Area Theme", Translation.TEXT_AREA_THEME);
public SettingsDialogue rstaThemeSettingsDialogue;
public final JMenu lafTheme = new TranslatedJMenu("Window Theme", Translation.WINDOW_THEME);
public final JMenuItem lafThemeSettings = new TranslatedJMenuItem("Window Theme", Translation.WINDOW_THEME);
public SettingsDialogue lafThemeSettingsDialogue;
public final JMenu language = new TranslatedJMenu("Language", Translation.LANGUAGE);
public final JMenuItem languageSettings = new TranslatedJMenuItem("Language", Translation.LANGUAGE);
public SettingsDialogue languageSettingsDialogue;
public final JMenu fontSize = new TranslatedJMenu("Font Size", Translation.FONT_SIZE);
public final JSpinner fontSpinner = new JSpinner();
public final Map<RSTATheme, JRadioButtonMenuItem> rstaThemes = new HashMap<>();
@ -437,6 +443,9 @@ public class MainViewerGUI extends JFrame
rstaThemes.put(t, item);
rstaTheme.add(item);
}
rstaThemeSettingsDialogue = new SettingsDialogue(rstaTheme, new JPanel());
rstaThemeSettings.addActionListener((e)-> rstaThemeSettingsDialogue.showDialogue());
ButtonGroup lafGroup = new ButtonGroup();
for (LAFTheme theme : LAFTheme.values())
@ -469,6 +478,9 @@ public class MainViewerGUI extends JFrame
lafThemes.put(theme, item);
lafTheme.add(item);
}
lafThemeSettingsDialogue = new SettingsDialogue(lafTheme, new JPanel());
lafThemeSettings.addActionListener((e)-> lafThemeSettingsDialogue.showDialogue());
ButtonGroup languageGroup = new ButtonGroup();
for (Language l : Language.values())
@ -489,9 +501,12 @@ public class MainViewerGUI extends JFrame
language.add(item);
}
visualSettings.add(lafTheme);
visualSettings.add(rstaTheme);
visualSettings.add(language);
languageSettingsDialogue = new SettingsDialogue(language, new JPanel());
languageSettings.addActionListener((e)-> languageSettingsDialogue.showDialogue());
visualSettings.add(useNewSettingsDialogue ? lafThemeSettings : lafTheme);
visualSettings.add(useNewSettingsDialogue ? rstaThemeSettings : rstaTheme);
visualSettings.add(useNewSettingsDialogue ? languageSettings : language);
visualSettings.add(fontSize);
visualSettings.add(showFileInTabTitle);
visualSettings.add(simplifyNameInTabTitle);
@ -514,9 +529,7 @@ public class MainViewerGUI extends JFrame
procyonSettingsSecondaryMenu.add(retainPointlessSwitches);
procyonSettingsSecondaryMenu.add(retainRedunantCasts);
procyonSettingsSecondaryMenu.add(unicodeOutputEnabled);
procyonSettingsDialogue = new SettingsDialogue(
procyonSettingsSecondaryMenu,
new JPanel());
procyonSettingsDialogue = new SettingsDialogue(procyonSettingsSecondaryMenu, new JPanel());
procyonSettings.addActionListener((e)-> procyonSettingsDialogue.showDialogue());
//CFR SETTINGS
@ -565,9 +578,7 @@ public class MainViewerGUI extends JFrame
cfrSettingsSecondaryMenu.add(recoveryTypehInts);
cfrSettingsSecondaryMenu.add(forceTurningIFs);
cfrSettingsSecondaryMenu.add(forLoopAGGCapture);
cfrSettingsDialogue = new SettingsDialogue(
cfrSettingsSecondaryMenu,
new JPanel());
cfrSettingsDialogue = new SettingsDialogue(cfrSettingsSecondaryMenu, new JPanel());
cfrSettings.addActionListener((e)-> cfrSettingsDialogue.showDialogue());
//FERNFLOWER SETTINGS
@ -591,18 +602,14 @@ public class MainViewerGUI extends JFrame
fernFlowerSettingsSecondaryMenu.add(udv);
fernFlowerSettingsSecondaryMenu.add(fdi);
fernFlowerSettingsSecondaryMenu.add(asc);
fernFlowerSettingsDialogue = new SettingsDialogue(
fernFlowerSettingsSecondaryMenu,
new JPanel());
fernFlowerSettingsDialogue = new SettingsDialogue(fernFlowerSettingsSecondaryMenu, new JPanel());
fernFlowerSettings.addActionListener((e)-> fernFlowerSettingsDialogue.showDialogue());
//CFIDE SETTINGS
settingsMainMenu.add(useNewSettingsDialogue ? bytecodeDecompilerSettings : bytecodeDecompilerSettingsSecondaryMenu);
bytecodeDecompilerSettingsSecondaryMenu.add(debugHelpers);
bytecodeDecompilerSettingsSecondaryMenu.add(appendBracketsToLabels);
bytecodeDecompilerSettingsDialogue = new SettingsDialogue(
bytecodeDecompilerSettingsSecondaryMenu,
new JPanel());
bytecodeDecompilerSettingsDialogue = new SettingsDialogue(bytecodeDecompilerSettingsSecondaryMenu, new JPanel());
bytecodeDecompilerSettings.addActionListener((e)-> bytecodeDecompilerSettingsDialogue.showDialogue());
deleteForeignOutdatedLibs.addActionListener(arg0 -> showForeignLibraryWarning());

View File

@ -1,5 +1,7 @@
package the.bytecode.club.bytecodeviewer.gui.components;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Method;
@ -7,9 +9,7 @@ import java.lang.reflect.Method;
import static javax.swing.JOptionPane.*;
/**
* All this does is fix the bug with parentComponents being minimized.
* The bug is the JOptionPane location ends up 0,0 instead of centered.
* The fix is to center the frame manually before showing.
* Extends the JOptionPane
*
* @author Konloch
* @author James Gosling
@ -145,7 +145,7 @@ public class BetterJOptionPane
return value;
}
public static void showJPanelDialogue(Component parentComponent, JScrollPane panel, int minimumHeight)
public static void showJPanelDialogue(Component parentComponent, JScrollPane panel, int minimumHeight, OnCreate onCreate)
throws HeadlessException
{
//create a new option pane with a empty text and just 'ok'
@ -157,6 +157,9 @@ public class BetterJOptionPane
int newHeight = Math.min(minimumHeight, d.getHeight());
d.setMinimumSize(new Dimension(d.getWidth(), newHeight));
d.setSize(new Dimension(d.getWidth(), newHeight));
if(onCreate != null)
onCreate.onCreate(d);
});
}
@ -172,6 +175,12 @@ public class BetterJOptionPane
createDialog.setAccessible(true);
dialog = (JDialog) createDialog.invoke(pane, parentComponent, title, style);
//check if the dialogue is in a poor location, attempt to correct
if(dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1)
dialog.setLocationRelativeTo(null); //TODO check if BytecodeViewer.viewer is better on multi monitor for this edgecase
else
dialog.setLocationRelativeTo(BytecodeViewer.viewer);
onCreate.onCreate(dialog);
}
catch(Exception e)
@ -179,10 +188,6 @@ public class BetterJOptionPane
e.printStackTrace();
}
//check if the dialogue is in a poor location, attempt to correct
if(dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1)
dialog.setLocationRelativeTo(null);
dialog.show();
dialog.dispose();

View File

@ -32,7 +32,8 @@ import static the.bytecode.club.bytecodeviewer.Configuration.useNewSettingsDialo
public class SettingsDialogue extends JScrollPane
{
public static final List<SettingsDialogue> dialogues = new ArrayList<>();
public static final List<JComponent> components = new ArrayList<>();
public static final List<JDialog> dialogues = new ArrayList<>();
private final List<JMenuItem> options = new ArrayList<>();
private final JMenu menu;
private final JPanel display;
@ -60,7 +61,7 @@ public class SettingsDialogue extends JScrollPane
buildPanel();
dialogues.add(this);
components.add(this);
}
private void buildPanel()
@ -72,7 +73,7 @@ public class SettingsDialogue extends JScrollPane
public void showDialogue()
{
BetterJOptionPane.showJPanelDialogue(null, this, 460);
BetterJOptionPane.showJPanelDialogue(null, this, 460, dialogues::add);
}
@Override

View File

@ -9,6 +9,7 @@ import the.bytecode.club.bytecodeviewer.gui.components.VisibleComponent;
import the.bytecode.club.bytecodeviewer.translation.Translation;
import javax.swing.*;
import java.awt.*;
/**
* @author Konloch
@ -103,7 +104,13 @@ public enum LAFTheme
if(BytecodeViewer.viewer != null)
{
BytecodeViewer.viewer.uiComponents.forEach(VisibleComponent::setDefaultIcon);
SettingsDialogue.dialogues.forEach(SwingUtilities::updateComponentTreeUI);
//update all of the setting dialogue components
SettingsDialogue.components.forEach(SwingUtilities::updateComponentTreeUI);
//TODO instead of hiding this should update/rebuild the dialogue
//hide any existing jDialogues
SettingsDialogue.dialogues.forEach(Dialog::dispose);
}
}