From 725f61bf1bd6a0b3698d84ac46dcf4fb80692ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 8 May 2025 21:21:29 +0200 Subject: [PATCH] AdvancedSettings dialog - use GridBagLayout. Color settings cannot click fix. --- .../flash/gui/AdvancedSettingsDialog.java | 73 +++++++++++++------ .../gui/ConfigurationColorSelection.java | 6 +- .../decompiler/flash/gui/FocusablePanel.java | 2 +- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java index eb9bdd4f1..19dd0cd2e 100644 --- a/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/AdvancedSettingsDialog.java @@ -30,13 +30,14 @@ import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; import java.awt.RenderingHints; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; @@ -57,7 +58,6 @@ import java.util.ResourceBundle; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; -import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -71,8 +71,6 @@ import javax.swing.JTextField; import javax.swing.SpringLayout; import javax.swing.UIManager; import javax.swing.WindowConstants; -import javax.swing.border.BevelBorder; -import javax.swing.border.Border; import javax.swing.table.DefaultTableModel; import org.pushingpixels.substance.api.ColorSchemeAssociationKind; import org.pushingpixels.substance.api.ComponentState; @@ -348,7 +346,11 @@ public class AdvancedSettingsDialog extends AppDialog { } for (String cat : categorized.keySet()) { - JPanel configPanel = new JPanel(new SpringLayout()); + JPanel configPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = -1; + gbc.insets = new Insets(2, 2, 2, 2); int itemCount = 0; List names = new ArrayList<>(categorized.get(cat).keySet()); @@ -431,7 +433,10 @@ public class AdvancedSettingsDialog extends AppDialog { JLabel l = new JLabel(locNameHtml, JLabel.TRAILING); titleToNameMap.put(locName, name); l.setToolTipText(description); - configPanel.add(l); + gbc.gridx = 0; + gbc.gridy++; + gbc.anchor = GridBagConstraints.LINE_END; + configPanel.add(l, gbc); Component c = null; @@ -447,25 +452,41 @@ public class AdvancedSettingsDialog extends AppDialog { ConfigurationFile confFile = field.getAnnotation(ConfigurationFile.class); ConfigurationDirectory confDirectory = field.getAnnotation(ConfigurationDirectory.class); - JTextField tf = new JTextField(); Object val = item.get(); if (val == null) { val = ""; } - if (itemType == Calendar.class) { - tf.setText(new SimpleDateFormat().format(((Calendar) val).getTime())); - } else { - tf.setText(val.toString()); - } - tf.setToolTipText(description); - tf.setMaximumSize(new Dimension(Integer.MAX_VALUE, tf.getPreferredSize().height)); - - c = tf; + int minW; + int maxW; + if (confFile != null) { c = new ConfigurationFileSelection(item, confFile, val.toString(), description); - } - if (confDirectory != null) { + minW = 300; + maxW = 300; + } else if (confDirectory != null) { c = new ConfigurationDirectorySelection(item, val.toString(), description); + minW = 300; + maxW = 300; + } else { + JTextField tf = new JTextField(); + if (itemType == Calendar.class) { + tf.setText(new SimpleDateFormat().format(((Calendar) val).getTime())); + } else { + tf.setText(val.toString()); + } + tf.setToolTipText(description); + + c = tf; + minW = 100; + maxW = 400; + } + + if (c.getPreferredSize().width > maxW) { + Dimension dim = new Dimension(maxW, c.getPreferredSize().height); + c.setPreferredSize(dim); + } else { + Dimension dim = new Dimension(minW, c.getPreferredSize().height); + c.setPreferredSize(dim); } } else if (itemType == Boolean.class) { JCheckBox cb = new JCheckBox(); @@ -512,7 +533,10 @@ public class AdvancedSettingsDialog extends AppDialog { toLabelComponent = ((ConfigurationDirectorySelection) toLabelComponent).getTextField(); } l.setLabelFor(toLabelComponent); - configPanel.add(c); + gbc.gridx++; + gbc.anchor = GridBagConstraints.LINE_START; + //gbc.fill = GridBagConstraints.HORIZONTAL; + configPanel.add(c, gbc); } catch (IllegalArgumentException | IllegalAccessException ex) { // Reflection exceptions. This should never happen throw new Error(ex.getMessage()); @@ -520,13 +544,20 @@ public class AdvancedSettingsDialog extends AppDialog { itemCount++; } + + gbc.gridy++; + gbc.gridx = 0; + gbc.gridwidth = 2; + gbc.weighty = 1; + configPanel.add(new JPanel(), gbc); categoryCounts.put(cat, itemCount); - SpringUtilities.makeCompactGrid(configPanel, + /*SpringUtilities.makeCompactGrid(configPanel, itemCount, 2, //rows, cols 6, 6, //initX, initY 6, 6); //xPad, yPad + */ if (resourceBundle.containsKey("config.group.tip." + cat)) { String tip = resourceBundle.getString("config.group.tip." + cat); String[] urls = new String[0]; diff --git a/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java b/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java index 47a01e7f2..cef50fe60 100644 --- a/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java +++ b/src/com/jpexs/decompiler/flash/gui/ConfigurationColorSelection.java @@ -38,7 +38,7 @@ public class ConfigurationColorSelection extends FocusablePanel { public ConfigurationColorSelection(ConfigurationItem item, Color value, String description) { setLayout(new FlowLayout(FlowLayout.LEFT)); colorPanel = new JPanel(); - colorPanel.setToolTipText(description); + setToolTipText(description); colorPanel.setSize(16, 16); colorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); JLabel colorLabel = new JLabel(); @@ -59,7 +59,7 @@ public class ConfigurationColorSelection extends FocusablePanel { public void mouseClicked(MouseEvent e) { } - }); + }); addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -70,9 +70,7 @@ public class ConfigurationColorSelection extends FocusablePanel { } }); colorLabel.setText(colorToHex(value)); - colorLabel.setToolTipText(description); - add(colorPanel); add(colorLabel); } diff --git a/src/com/jpexs/decompiler/flash/gui/FocusablePanel.java b/src/com/jpexs/decompiler/flash/gui/FocusablePanel.java index b923b19b2..7e09126f3 100644 --- a/src/com/jpexs/decompiler/flash/gui/FocusablePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/FocusablePanel.java @@ -46,7 +46,7 @@ import org.pushingpixels.substance.internal.utils.SubstanceSizeUtils; */ public class FocusablePanel extends JPanel { - private List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); private static final Set pressedModifiers = new HashSet<>();