Skip to content

Commit

Permalink
EditActionsDialog: layout improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bwRavencl committed Dec 22, 2024
1 parent 026fd3e commit 2a10ad6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<?>> axisActionClasses;
private static final List<Class<?>> buttonActionClasses;
private static final List<Class<?>> cycleActionClasses;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/de/bwravencl/controllerbuddy/gui/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 2a10ad6

Please sign in to comment.