Fixed UI Alignment of theme customization components

Fixes #39
This commit is contained in:
DieGurke 2019-12-21 11:17:23 +01:00
parent a8406cb033
commit 474480abb6

View File

@ -82,9 +82,19 @@ public class ThemeCustomizationPanel extends SettingsPanel {
add(themes, gbc_themes); add(themes, gbc_themes);
colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS)); // colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS));
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
GridBagLayout gbl_colorCustomizations = new GridBagLayout();
gbl_colorCustomizations.columnWidths = new int[] { 1, 1 };
gbl_colorCustomizations.rowHeights = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1};
gbl_colorCustomizations.columnWeights = new double[] { 1.0, 1.0 };
gbl_colorCustomizations.rowWeights = new double[] { 1, 1, 1, 1, 1, 1, 1, 1};
colorsPanel.setLayout(gbl_colorCustomizations);
Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
buildCustomizeElements(theme); buildCustomizeElements(theme);
@ -170,6 +180,7 @@ public class ThemeCustomizationPanel extends SettingsPanel {
colorsPanel.removeAll(); colorsPanel.removeAll();
buildCustomizeElements(theme); buildCustomizeElements(theme);
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
GridBagConstraints gbc_createNewTheme = new GridBagConstraints(); GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
gbc_createNewTheme.gridx = 0; gbc_createNewTheme.gridx = 0;
@ -179,19 +190,18 @@ public class ThemeCustomizationPanel extends SettingsPanel {
} }
private void buildCustomizeElements(Theme theme) { private void buildCustomizeElements(Theme theme) {
buildCustomizeElement(theme, theme.getBackgroundColor(), "Background", "backgroundColor"); buildCustomizeElement(theme, theme.getBackgroundColor(), "Background", "backgroundColor", 1);
buildCustomizeElement(theme, theme.getCellColor(), "Cells", "cellColor"); buildCustomizeElement(theme, theme.getCellColor(), "Cells", "cellColor", 2);
buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", "interactableForegroundColor"); buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", "interactableForegroundColor", 3);
buildCustomizeElement(theme, theme.getInteractableBackgroundColor(), "Interactable Background", "interactableBackgroundColor"); buildCustomizeElement(theme, theme.getInteractableBackgroundColor(), "Interactable Background", "interactableBackgroundColor", 4);
buildCustomizeElement(theme, theme.getMessageColorChat(), "Messages Chat", "messageColorChat"); buildCustomizeElement(theme, theme.getMessageColorChat(), "Messages Chat", "messageColorChat", 5);
buildCustomizeElement(theme, theme.getDateColorChat(), "Date Chat", "dateColorCat"); buildCustomizeElement(theme, theme.getDateColorChat(), "Date Chat", "dateColorCat", 6);
buildCustomizeElement(theme, theme.getSelectionColor(), "Selection", "selectionColor"); buildCustomizeElement(theme, theme.getSelectionColor(), "Selection", "selectionColor", 7);
buildCustomizeElement(theme, theme.getTypingMessageColor(), "Typing Message", "typingMessageColor"); buildCustomizeElement(theme, theme.getTypingMessageColor(), "Typing Message", "typingMessageColor", 8);
buildCustomizeElement(theme, theme.getUserNameColor(), "User Names", "userNameColor"); buildCustomizeElement(theme, theme.getUserNameColor(), "User Names", "userNameColor", 9);
} }
private void buildCustomizeElement(Theme theme, Color color, String name, String colorName) { private void buildCustomizeElement(Theme theme, Color color, String name, String colorName, int gridy) {
JPanel panel = new JPanel();
JButton button = new JButton(); JButton button = new JButton();
JTextPane textPane = new JTextPane(); JTextPane textPane = new JTextPane();
@ -222,12 +232,24 @@ public class ThemeCustomizationPanel extends SettingsPanel {
} }
}); });
panel.add(textPane); GridBagConstraints gbc_textPane = new GridBagConstraints();
panel.add(button); gbc_textPane.fill = GridBagConstraints.BOTH;
panel.setBackground(theme.getCellColor()); gbc_textPane.gridx = 0;
panel.setAlignmentX(Component.LEFT_ALIGNMENT); gbc_textPane.gridy = gridy;
gbc_textPane.anchor = GridBagConstraints.CENTER;
gbc_textPane.insets = insets;
colorsPanel.add(panel); colorsPanel.add(textPane, gbc_textPane);
GridBagConstraints gbc_button = new GridBagConstraints();
gbc_button.fill = GridBagConstraints.BOTH;
gbc_button.gridx = 1;
gbc_button.gridy = gridy;
gbc_button.anchor = GridBagConstraints.CENTER;
gbc_button.insets = insets;
colorsPanel.add(button, gbc_button);
} }
private Color getInvertedColor(Color color) { return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); } private Color getInvertedColor(Color color) { return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); }