-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gui): use another implementation for font dialog (#2310)
- Loading branch information
Showing
6 changed files
with
125 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
52 changes: 0 additions & 52 deletions
52
jadx-gui/src/main/java/jadx/gui/settings/ui/JPreferredFontChooser.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
jadx-gui/src/main/java/jadx/gui/settings/ui/font/FontChooserHack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package jadx.gui.settings.ui.font; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import javax.swing.JCheckBox; | ||
|
||
import org.drjekyll.fontchooser.FontChooser; | ||
import org.drjekyll.fontchooser.panes.FamilyPane; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class FontChooserHack { | ||
private static final Logger LOG = LoggerFactory.getLogger(FontChooserHack.class); | ||
|
||
public static void setOnlyMonospace(FontChooser fontChooser) { | ||
try { | ||
FamilyPane familyPane = (FamilyPane) getPrivateField(fontChooser, "familyPane"); | ||
JCheckBox monospacedCheckBox = (JCheckBox) getPrivateField(familyPane, "monospacedCheckBox"); | ||
monospacedCheckBox.setSelected(true); | ||
monospacedCheckBox.setEnabled(false); | ||
} catch (Throwable e) { | ||
LOG.debug("Failed to set only monospace check box", e); | ||
} | ||
} | ||
|
||
private static Object getPrivateField(Object obj, String fieldName) throws NoSuchFieldException, IllegalAccessException { | ||
Field f = obj.getClass().getDeclaredField(fieldName); | ||
f.setAccessible(true); | ||
return f.get(obj); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
jadx-gui/src/main/java/jadx/gui/settings/ui/font/JadxFontDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package jadx.gui.settings.ui.font; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.FlowLayout; | ||
import java.awt.Font; | ||
|
||
import javax.swing.BorderFactory; | ||
import javax.swing.JButton; | ||
import javax.swing.JDialog; | ||
import javax.swing.JPanel; | ||
import javax.swing.WindowConstants; | ||
|
||
import org.drjekyll.fontchooser.FontChooser; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import jadx.gui.settings.JadxSettings; | ||
import jadx.gui.settings.ui.JadxSettingsWindow; | ||
import jadx.gui.utils.NLS; | ||
|
||
public class JadxFontDialog extends JDialog { | ||
private static final long serialVersionUID = 7609857698785777587L; | ||
|
||
private final FontChooser fontChooser = new FontChooser(); | ||
private final JadxSettings settings; | ||
private boolean selected = false; | ||
|
||
public JadxFontDialog(JadxSettingsWindow settingsWindow, String title) { | ||
super(settingsWindow, title, true); | ||
settings = settingsWindow.getMainWindow().getSettings(); | ||
initComponents(); | ||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | ||
if (!settings.loadWindowPos(this)) { | ||
pack(); | ||
} | ||
} | ||
|
||
public @Nullable Font select(Font currentFont, boolean onlyMonospace) { | ||
fontChooser.setSelectedFont(currentFont); | ||
if (onlyMonospace) { | ||
FontChooserHack.setOnlyMonospace(fontChooser); | ||
} | ||
setVisible(true); | ||
Font selectedFont = fontChooser.getSelectedFont(); | ||
if (selected && !selectedFont.equals(currentFont)) { | ||
return selectedFont; | ||
} | ||
return null; | ||
} | ||
|
||
private void initComponents() { | ||
JPanel chooserPanel = new JPanel(); | ||
chooserPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); | ||
chooserPanel.setLayout(new BorderLayout(0, 10)); | ||
chooserPanel.add(fontChooser); | ||
|
||
JPanel controlPanel = new JPanel(); | ||
controlPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); | ||
controlPanel.setLayout(new FlowLayout(FlowLayout.TRAILING)); | ||
|
||
JButton okBtn = new JButton(); | ||
okBtn.setText(NLS.str("common_dialog.ok")); | ||
okBtn.setMnemonic('o'); | ||
okBtn.addActionListener(event -> { | ||
selected = true; | ||
dispose(); | ||
}); | ||
|
||
JButton cancelBtn = new JButton(); | ||
cancelBtn.setText(NLS.str("common_dialog.cancel")); | ||
cancelBtn.setMnemonic('c'); | ||
cancelBtn.addActionListener(event -> dispose()); | ||
|
||
controlPanel.add(okBtn); | ||
controlPanel.add(cancelBtn); | ||
|
||
add(chooserPanel); | ||
add(controlPanel, BorderLayout.PAGE_END); | ||
getRootPane().setDefaultButton(okBtn); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
settings.saveWindowPos(this); | ||
super.dispose(); | ||
} | ||
} |