User Friendly Settings
* Removed CreateNewButton button and added it's functionality to the save button. * Revised theme dropDown style. fixes #64
This commit is contained in:
parent
f31f252613
commit
b1dbe58f2c
@ -31,12 +31,12 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
|
|
||||||
private static final long serialVersionUID = -8697897390666456624L;
|
private static final long serialVersionUID = -8697897390666456624L;
|
||||||
|
|
||||||
private JPanel colorsPanel = new JPanel();
|
private JPanel colorsPanel = new JPanel();
|
||||||
private JButton createNewThemeButton = new JButton("Create New Theme");
|
|
||||||
|
|
||||||
private String[] themeArray = Settings.getInstance().getThemes().keySet().toArray(new String[0]);
|
private String[] themeArray = Settings.getInstance().getThemes().keySet().toArray(new String[0]);
|
||||||
private JComboBox<String> themes = new JComboBox<>(themeArray);
|
private JComboBox<String> themes = new JComboBox<>(themeArray);
|
||||||
private Theme temporaryTheme, selectedTheme;
|
private Theme temporaryTheme, selectedTheme;
|
||||||
|
private boolean themeChanged = false;
|
||||||
|
|
||||||
private final Insets insets = new Insets(5, 5, 5, 5);
|
private final Insets insets = new Insets(5, 5, 5, 5);
|
||||||
|
|
||||||
@ -50,14 +50,15 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public ThemeCustomizationPanel() {
|
public ThemeCustomizationPanel() {
|
||||||
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
temporaryTheme = new Theme("temporaryTheme",
|
||||||
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||||
|
|
||||||
GridBagLayout gbl_themeLayout = new GridBagLayout();
|
GridBagLayout gbl_themeLayout = new GridBagLayout();
|
||||||
|
|
||||||
gbl_themeLayout.columnWidths = new int[] { 1, 1 };
|
gbl_themeLayout.columnWidths = new int[] { 1, 1 };
|
||||||
gbl_themeLayout.rowHeights = new int[] { 1, 1 };
|
gbl_themeLayout.rowHeights = new int[] { 1, 1 };
|
||||||
gbl_themeLayout.columnWeights = new double[] { 1.0, 1.0 };
|
gbl_themeLayout.columnWeights = new double[] { 1.0, 1.0 };
|
||||||
gbl_themeLayout.rowWeights = new double[] { 0.01, 1.0 };
|
gbl_themeLayout.rowWeights = new double[] { 0.01, 1.0 };
|
||||||
|
|
||||||
setLayout(gbl_themeLayout);
|
setLayout(gbl_themeLayout);
|
||||||
|
|
||||||
@ -74,70 +75,41 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
GridBagConstraints gbc_themes = new GridBagConstraints();
|
GridBagConstraints gbc_themes = new GridBagConstraints();
|
||||||
gbc_themes.fill = GridBagConstraints.HORIZONTAL;
|
gbc_themes.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_themes.gridx = 0;
|
gbc_themes.gridwidth = 2;
|
||||||
gbc_themes.gridy = 0;
|
gbc_themes.gridx = 0;
|
||||||
gbc_themes.anchor = GridBagConstraints.NORTHWEST;
|
gbc_themes.gridy = 0;
|
||||||
gbc_themes.insets = insets;
|
gbc_themes.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
gbc_themes.insets = new Insets(10, 10, 20, 10);
|
||||||
|
|
||||||
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();
|
GridBagLayout gbl_colorCustomizations = new GridBagLayout();
|
||||||
|
|
||||||
gbl_colorCustomizations.columnWidths = new int[] { 1, 1 };
|
gbl_colorCustomizations.columnWidths = new int[] { 1, 1 };
|
||||||
gbl_colorCustomizations.rowHeights = new int[] { 1, 1, 1, 1, 1, 1, 1, 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.columnWeights = new double[] { 1, 1 };
|
||||||
gbl_colorCustomizations.rowWeights = new double[] { 1, 1, 1, 1, 1, 1, 1, 1};
|
gbl_colorCustomizations.rowWeights = new double[] { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||||
|
|
||||||
colorsPanel.setLayout(gbl_colorCustomizations);
|
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);
|
||||||
|
|
||||||
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
|
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
|
||||||
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
|
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_colorsPanel.gridx = 0;
|
gbc_colorsPanel.gridx = 0;
|
||||||
gbc_colorsPanel.gridy = 1;
|
gbc_colorsPanel.gridy = 1;
|
||||||
gbc_colorsPanel.gridwidth = 2;
|
gbc_colorsPanel.gridwidth = 2;
|
||||||
gbc_colorsPanel.anchor = GridBagConstraints.NORTHWEST;
|
gbc_colorsPanel.anchor = GridBagConstraints.NORTHWEST;
|
||||||
gbc_colorsPanel.insets = insets;
|
gbc_colorsPanel.insets = insets;
|
||||||
|
|
||||||
add(colorsPanel, gbc_colorsPanel);
|
add(colorsPanel, gbc_colorsPanel);
|
||||||
|
|
||||||
createNewThemeButton.setEnabled(false);
|
|
||||||
createNewThemeButton.setBackground(theme.getInteractableBackgroundColor());
|
|
||||||
createNewThemeButton.setForeground(theme.getInteractableForegroundColor());
|
|
||||||
colorsPanel.setBackground(theme.getCellColor());
|
colorsPanel.setBackground(theme.getCellColor());
|
||||||
|
|
||||||
createNewThemeButton.addActionListener((evt) -> {
|
|
||||||
try {
|
|
||||||
String name = JOptionPane.showInputDialog("Enter a name for the new theme");
|
|
||||||
logger.log(Level.FINEST, name);
|
|
||||||
Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme));
|
|
||||||
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
|
||||||
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(name).getThemeName();
|
|
||||||
|
|
||||||
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
|
||||||
|
|
||||||
createNewThemeButton.setEnabled(false);
|
|
||||||
themes.addItem(themeArray[themeArray.length - 1]);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("New theme couldn't be created! " + e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
|
|
||||||
gbc_createNewTheme.gridx = 0;
|
|
||||||
gbc_createNewTheme.gridy = 10;
|
|
||||||
|
|
||||||
colorsPanel.add(createNewThemeButton, gbc_createNewTheme);
|
|
||||||
|
|
||||||
// Apply current theme
|
// Apply current theme
|
||||||
applyTheme(theme);
|
applyTheme(theme);
|
||||||
|
|
||||||
@ -148,6 +120,27 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
@Override
|
@Override
|
||||||
public ActionListener getOkButtonAction() {
|
public ActionListener getOkButtonAction() {
|
||||||
return (evt) -> {
|
return (evt) -> {
|
||||||
|
if (themeChanged) {
|
||||||
|
try {
|
||||||
|
String name = JOptionPane.showInputDialog("Enter a name for the new theme");
|
||||||
|
logger.log(Level.FINEST, name);
|
||||||
|
Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme));
|
||||||
|
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
||||||
|
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(name).getThemeName();
|
||||||
|
|
||||||
|
temporaryTheme = new Theme("temporaryTheme",
|
||||||
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||||
|
|
||||||
|
themes.addItem(themeArray[themeArray.length - 1]);
|
||||||
|
themes.setSelectedIndex(themeArray.length - 1);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.info("New theme couldn't be created! " + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
themeChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
|
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
|
||||||
logger.log(Level.FINER, "Setting theme: " + selectedTheme.getThemeName());
|
logger.log(Level.FINER, "Setting theme: " + selectedTheme.getThemeName());
|
||||||
|
|
||||||
@ -166,11 +159,8 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
setBackground(theme.getCellColor());
|
setBackground(theme.getCellColor());
|
||||||
|
|
||||||
// themes
|
// themes
|
||||||
themes.setBackground(theme.getBackgroundColor());
|
themes.setBackground(theme.getInteractableBackgroundColor());
|
||||||
themes.setForeground(getInvertedColor(theme.getBackgroundColor()));
|
themes.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
|
||||||
createNewThemeButton.setBackground(theme.getInteractableBackgroundColor());
|
|
||||||
createNewThemeButton.setForeground(theme.getInteractableForegroundColor());
|
|
||||||
colorsPanel.setBackground(theme.getCellColor());
|
colorsPanel.setBackground(theme.getCellColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,20 +170,15 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
colorsPanel.removeAll();
|
colorsPanel.removeAll();
|
||||||
|
|
||||||
buildCustomizeElements(theme);
|
buildCustomizeElements(theme);
|
||||||
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
||||||
|
|
||||||
GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
|
|
||||||
gbc_createNewTheme.gridx = 0;
|
|
||||||
gbc_createNewTheme.gridy = 10;
|
|
||||||
|
|
||||||
colorsPanel.add(createNewThemeButton, gbc_createNewTheme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildCustomizeElements(Theme theme) {
|
private void buildCustomizeElements(Theme theme) {
|
||||||
buildCustomizeElement(theme, theme.getBackgroundColor(), "Background", "backgroundColor", 1);
|
buildCustomizeElement(theme, theme.getBackgroundColor(), "Background", "backgroundColor", 1);
|
||||||
buildCustomizeElement(theme, theme.getCellColor(), "Cells", "cellColor", 2);
|
buildCustomizeElement(theme, theme.getCellColor(), "Cells", "cellColor", 2);
|
||||||
buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", "interactableForegroundColor", 3);
|
buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground",
|
||||||
buildCustomizeElement(theme, theme.getInteractableBackgroundColor(), "Interactable Background", "interactableBackgroundColor", 4);
|
"interactableForegroundColor", 3);
|
||||||
|
buildCustomizeElement(theme, theme.getInteractableBackgroundColor(), "Interactable Background",
|
||||||
|
"interactableBackgroundColor", 4);
|
||||||
buildCustomizeElement(theme, theme.getMessageColorChat(), "Messages Chat", "messageColorChat", 5);
|
buildCustomizeElement(theme, theme.getMessageColorChat(), "Messages Chat", "messageColorChat", 5);
|
||||||
buildCustomizeElement(theme, theme.getDateColorChat(), "Date Chat", "dateColorCat", 6);
|
buildCustomizeElement(theme, theme.getDateColorChat(), "Date Chat", "dateColorCat", 6);
|
||||||
buildCustomizeElement(theme, theme.getSelectionColor(), "Selection", "selectionColor", 7);
|
buildCustomizeElement(theme, theme.getSelectionColor(), "Selection", "selectionColor", 7);
|
||||||
@ -202,8 +187,8 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildCustomizeElement(Theme theme, Color color, String name, String colorName, int gridy) {
|
private void buildCustomizeElement(Theme theme, Color color, String name, String colorName, int gridy) {
|
||||||
JButton button = new JButton();
|
JButton button = new JButton();
|
||||||
JTextPane textPane = new JTextPane();
|
JTextPane textPane = new JTextPane();
|
||||||
|
|
||||||
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
|
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
|
||||||
textPane.setBackground(theme.getBackgroundColor());
|
textPane.setBackground(theme.getBackgroundColor());
|
||||||
@ -222,7 +207,7 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
// TODO: When Theme changed in same settings screen, color variable doesn't
|
// TODO: When Theme changed in same settings screen, color variable doesn't
|
||||||
// update
|
// update
|
||||||
temporaryTheme.setColor(colorName, newColor);
|
temporaryTheme.setColor(colorName, newColor);
|
||||||
createNewThemeButton.setEnabled(true);
|
themeChanged = true;
|
||||||
}
|
}
|
||||||
button.setBackground(newColor);
|
button.setBackground(newColor);
|
||||||
|
|
||||||
@ -233,24 +218,25 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
GridBagConstraints gbc_textPane = new GridBagConstraints();
|
GridBagConstraints gbc_textPane = new GridBagConstraints();
|
||||||
gbc_textPane.fill = GridBagConstraints.BOTH;
|
gbc_textPane.fill = GridBagConstraints.BOTH;
|
||||||
gbc_textPane.gridx = 0;
|
gbc_textPane.gridx = 0;
|
||||||
gbc_textPane.gridy = gridy;
|
gbc_textPane.gridy = gridy;
|
||||||
gbc_textPane.anchor = GridBagConstraints.CENTER;
|
gbc_textPane.anchor = GridBagConstraints.CENTER;
|
||||||
gbc_textPane.insets = insets;
|
gbc_textPane.insets = insets;
|
||||||
|
|
||||||
colorsPanel.add(textPane, gbc_textPane);
|
colorsPanel.add(textPane, gbc_textPane);
|
||||||
|
|
||||||
|
|
||||||
GridBagConstraints gbc_button = new GridBagConstraints();
|
GridBagConstraints gbc_button = new GridBagConstraints();
|
||||||
gbc_button.fill = GridBagConstraints.BOTH;
|
gbc_button.fill = GridBagConstraints.BOTH;
|
||||||
gbc_button.gridx = 1;
|
gbc_button.gridx = 1;
|
||||||
gbc_button.gridy = gridy;
|
gbc_button.gridy = gridy;
|
||||||
gbc_button.anchor = GridBagConstraints.CENTER;
|
gbc_button.anchor = GridBagConstraints.CENTER;
|
||||||
gbc_button.insets = insets;
|
gbc_button.insets = insets;
|
||||||
|
|
||||||
colorsPanel.add(button, gbc_button);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user