From 2a10ad6f3caa8822fb97a2efbdfd34129a20378e Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Sun, 22 Dec 2024 12:29:30 +0100 Subject: [PATCH] EditActionsDialog: layout improvements --- .../controllerbuddy/gui/EditActionsDialog.java | 18 ++++++++++++------ .../controllerbuddy/gui/GuiUtils.java | 15 +++++++++++++++ .../action/gui/KeystrokeEditorBuilder.java | 17 +++++++++-------- .../input/action/gui/StringEditorBuilder.java | 2 +- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/bwravencl/controllerbuddy/gui/EditActionsDialog.java b/src/main/java/de/bwravencl/controllerbuddy/gui/EditActionsDialog.java index e9180aa6..b3fb7b5d 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/gui/EditActionsDialog.java +++ b/src/main/java/de/bwravencl/controllerbuddy/gui/EditActionsDialog.java @@ -80,9 +80,12 @@ public final class EditActionsDialog extends JDialog { private static final Logger log = Logger.getLogger(EditActionsDialog.class.getName()); private static final int DIALOG_BOUNDS_WIDTH = 1000; - private static final int DIALOG_BOUNDS_HEIGHT = 600; + private static final int DIALOG_BOUNDS_HEIGHT = 650; private static final int DIALOG_BOUNDS_PARENT_OFFSET = 25; + private static final int ACTIONS_LIST_SCROLL_PANE_WIDTH = 200; + private static final double ACTIONS_LIST_WEIGHT_X = .2d; + private static final List> axisActionClasses; private static final List> buttonActionClasses; private static final List> cycleActionClasses; @@ -434,8 +437,10 @@ private void init() { addButton.setEnabled(selectedAvailableAction != null); }); updateAvailableActions(); - actionsPanel.add(new JScrollPane(availableActionsList), new GridBagConstraints(0, 1, 1, 5, .1d, 1d, - GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + + actionsPanel.add(GuiUtils.wrapComponentInScrollPane(availableActionsList, ACTIONS_LIST_SCROLL_PANE_WIDTH, null), + new GridBagConstraints(0, 1, 1, 5, ACTIONS_LIST_WEIGHT_X, 1d, GridBagConstraints.CENTER, + GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); actionsPanel.add(new JLabel(Main.strings.getString("ASSIGNED_ACTIONS_LABEL")), new GridBagConstraints(2, 0, 1, 1, 0d, 0d, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 25)); @@ -484,7 +489,7 @@ private void init() { new Insets(5, 5, 5, 5), 0, 10)); final var propertyNameLabel = new JLabel(Main.strings.getString(annotation.label())); - propertyNameLabel.setPreferredSize(new Dimension(175, 15)); + propertyNameLabel.setPreferredSize(new Dimension(155, 15)); propertyPanel.add(propertyNameLabel); try { @@ -523,8 +528,9 @@ private void init() { propertiesLabel.setVisible(anyPropertiesFound); propertiesScrollPane.setVisible(anyPropertiesFound); }); - actionsPanel.add(new JScrollPane(assignedActionsList), new GridBagConstraints(2, 1, 1, 5, .1d, 1d, - GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + actionsPanel.add(GuiUtils.wrapComponentInScrollPane(assignedActionsList, ACTIONS_LIST_SCROLL_PANE_WIDTH, null), + new GridBagConstraints(2, 1, 1, 5, ACTIONS_LIST_WEIGHT_X, 1d, GridBagConstraints.CENTER, + GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); final var okCancelButtonPanel = new JPanel(); okCancelButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); diff --git a/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java b/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java index 74f7e7fc..7915ac36 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java +++ b/src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java @@ -25,6 +25,7 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; +import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.Frame; @@ -46,6 +47,7 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; @SuppressWarnings({ "exports", "missing-explicit-ctor" }) public final class GuiUtils { @@ -197,6 +199,19 @@ public static void showMessageDialog(final Main main, @SuppressWarnings("exports JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon); } + public static JScrollPane wrapComponentInScrollPane(final java.awt.Component component, + final Integer preferredSizeWidth, final Integer preferredSizeHeight) { + final var scrollPane = new JScrollPane(component); + + final var currentPreferredSize = scrollPane.getPreferredSize(); + final var preferredSizeDimension = new Dimension( + preferredSizeWidth != null ? preferredSizeWidth : currentPreferredSize.width, + preferredSizeHeight != null ? preferredSizeHeight : currentPreferredSize.height); + scrollPane.setPreferredSize(preferredSizeDimension); + + return scrollPane; + } + static class FrameDragListener extends MouseAdapter { private final Main main; diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/KeystrokeEditorBuilder.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/KeystrokeEditorBuilder.java index cfdfd76a..62f976e5 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/KeystrokeEditorBuilder.java +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/KeystrokeEditorBuilder.java @@ -17,13 +17,13 @@ package de.bwravencl.controllerbuddy.input.action.gui; import de.bwravencl.controllerbuddy.gui.EditActionsDialog; +import de.bwravencl.controllerbuddy.gui.GuiUtils; import de.bwravencl.controllerbuddy.gui.Main; import de.bwravencl.controllerbuddy.input.KeyStroke; import de.bwravencl.controllerbuddy.input.ScanCode; import de.bwravencl.controllerbuddy.input.action.IAction; import java.awt.BorderLayout; import java.awt.Component; -import java.awt.Dimension; import java.io.Serial; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -42,7 +42,6 @@ import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.ListCellRenderer; import javax.swing.ListModel; @@ -52,6 +51,10 @@ public final class KeystrokeEditorBuilder extends EditorBuilder { private static final Logger log = Logger.getLogger(KeystrokeEditorBuilder.class.getName()); + + private static final int KEY_LIST_SCROLL_PANE_WIDTH = 105; + private static final int KEY_LIST_SCROLL_PANE_HEIGHT = 200; + private final JTextArea keyStrokeTextArea = new JTextArea(); private CheckboxJList modifierList; private CheckboxJList keyList; @@ -110,9 +113,8 @@ public void buildEditor(final JPanel parentPanel) { } }); - final var modifiersScrollPane = new JScrollPane(modifierList); - modifiersScrollPane.setPreferredSize(new Dimension(130, 200)); - modifiersPanel.add(modifiersScrollPane); + modifiersPanel.add(GuiUtils.wrapComponentInScrollPane(modifierList, KEY_LIST_SCROLL_PANE_WIDTH, + KEY_LIST_SCROLL_PANE_HEIGHT)); keystrokePanel.add(modifiersPanel, BorderLayout.WEST); final var keysPanel = new JPanel(); @@ -135,9 +137,8 @@ public void buildEditor(final JPanel parentPanel) { } }); - final var keysScrollPane = new JScrollPane(keyList); - keysScrollPane.setPreferredSize(new Dimension(130, 200)); - keysPanel.add(keysScrollPane); + keysPanel.add( + GuiUtils.wrapComponentInScrollPane(keyList, KEY_LIST_SCROLL_PANE_WIDTH, KEY_LIST_SCROLL_PANE_HEIGHT)); keystrokePanel.add(keysPanel, BorderLayout.EAST); keyStrokeTextArea.setLineWrap(true); diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/StringEditorBuilder.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/StringEditorBuilder.java index 59c8f096..35fb3e8e 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/StringEditorBuilder.java +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/StringEditorBuilder.java @@ -44,7 +44,7 @@ public StringEditorBuilder(final EditActionsDialog editActionsDialog, final IAct @Override public void buildEditor(final JPanel parentPanel) { - final var textField = new JTextField(23); + final var textField = new JTextField(17); textField.setText((String) initialValue); textField.setCaretPosition(0);