Fixes #121 (first displayed theme is current theme)
Additionally removed okButton from SettingsScreen
This commit is contained in:
parent
e4eaf7239c
commit
f08a7a6f5e
@ -110,7 +110,7 @@ public class ComponentList<E> extends JPanel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the current selection.
|
* Removes the current selection.
|
||||||
*
|
*
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public void clearSelection() {
|
public void clearSelection() {
|
||||||
@ -173,7 +173,7 @@ public class ComponentList<E> extends JPanel {
|
|||||||
* @throws java.util.NoSuchElementException if no selection is present
|
* @throws java.util.NoSuchElementException if no selection is present
|
||||||
* @since Envoy v0.1-beta
|
* @since Envoy v0.1-beta
|
||||||
*/
|
*/
|
||||||
public int getSingleSelection() { return selection.iterator().next(); }
|
public int getSingleSelection() { return selection.stream().findAny().get(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return an arbitrary selected element
|
* @return an arbitrary selected element
|
||||||
@ -235,7 +235,7 @@ public class ComponentList<E> extends JPanel {
|
|||||||
/**
|
/**
|
||||||
* Sets a new selection mode. The current selection will be cleared during this
|
* Sets a new selection mode. The current selection will be cleared during this
|
||||||
* action.
|
* action.
|
||||||
*
|
*
|
||||||
* @param selectionMode the selection mode to set
|
* @param selectionMode the selection mode to set
|
||||||
* @return this component list
|
* @return this component list
|
||||||
* @since Envoy v0.1-beta
|
* @since Envoy v0.1-beta
|
||||||
|
@ -1,93 +1,89 @@
|
|||||||
package envoy.client.ui.settings;
|
package envoy.client.ui.settings;
|
||||||
|
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ActionListener;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JTextPane;
|
||||||
import javax.swing.JTextPane;
|
|
||||||
|
import envoy.client.data.Settings;
|
||||||
import envoy.client.data.Settings;
|
import envoy.client.data.SettingsItem;
|
||||||
import envoy.client.data.SettingsItem;
|
import envoy.client.ui.Theme;
|
||||||
import envoy.client.ui.Theme;
|
import envoy.util.EnvoyLog;
|
||||||
import envoy.util.EnvoyLog;
|
|
||||||
|
/**
|
||||||
/**
|
* Displays GUI components that allow general settings regarding the client.<br>
|
||||||
* Displays GUI components that allow general settings regarding the client.<br>
|
* <br>
|
||||||
* <br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* File: <strong>GeneralSettingsPanel.java</strong><br>
|
||||||
* File: <strong>GeneralSettingsPanel.java</strong><br>
|
* Created: <strong>21 Dec 2019</strong><br>
|
||||||
* Created: <strong>21 Dec 2019</strong><br>
|
*
|
||||||
*
|
* @author Maximilian Käfer
|
||||||
* @author Maximilian Käfer
|
* @since Envoy v0.3-alpha
|
||||||
* @since Envoy v0.3-alpha
|
*/
|
||||||
*/
|
public class GeneralSettingsPanel extends SettingsPanel {
|
||||||
public class GeneralSettingsPanel extends SettingsPanel {
|
|
||||||
|
private Theme theme;
|
||||||
private Theme theme;
|
|
||||||
|
private static final String[] items = { "onCloseMode", "enterToSend" };
|
||||||
private static final String[] items = { "onCloseMode", "enterToSend" };
|
private static final Logger logger = EnvoyLog.getLogger(GeneralSettingsPanel.class);
|
||||||
private static final Logger logger = EnvoyLog.getLogger(GeneralSettingsPanel.class);
|
private static final long serialVersionUID = -7470848775130754239L;
|
||||||
private static final long serialVersionUID = -7470848775130754239L;
|
|
||||||
|
/**
|
||||||
/**
|
* This is the constructor for the General class. Here the user can set general
|
||||||
* This is the constructor for the General class. Here the user can set general
|
* settings for the client.
|
||||||
* settings for the client.
|
*
|
||||||
*
|
* @param parent the {@link SettingsScreen} as a part of which this
|
||||||
* @param parent the {@link SettingsScreen} as a part of which this
|
* {@link SettingsPanel} is displayed
|
||||||
* {@link SettingsPanel} is displayed
|
* @since Envoy v0.3-alpha
|
||||||
* @since Envoy v0.3-alpha
|
*/
|
||||||
*/
|
public GeneralSettingsPanel(SettingsScreen parent) {
|
||||||
public GeneralSettingsPanel(SettingsScreen parent) {
|
super(parent);
|
||||||
super(parent);
|
theme = Settings.getInstance().getCurrentTheme();
|
||||||
theme = Settings.getInstance().getCurrentTheme();
|
|
||||||
|
setBackground(theme.getCellColor());
|
||||||
setBackground(theme.getCellColor());
|
|
||||||
|
GridBagLayout gbl_general = new GridBagLayout();
|
||||||
GridBagLayout gbl_general = new GridBagLayout();
|
gbl_general.columnWidths = new int[] { 1, 1 };
|
||||||
gbl_general.columnWidths = new int[] { 1, 1 };
|
gbl_general.rowHeights = new int[] { 1, 1, 1 };
|
||||||
gbl_general.rowHeights = new int[] { 1, 1, 1 };
|
gbl_general.columnWeights = new double[] { 1.0, 0.1 };
|
||||||
gbl_general.columnWeights = new double[] { 1.0, 0.1 };
|
gbl_general.rowWeights = new double[] { 0.02, 0.02, 1.0 };
|
||||||
gbl_general.rowWeights = new double[] { 0.02, 0.02, 1.0 };
|
|
||||||
|
setLayout(gbl_general);
|
||||||
setLayout(gbl_general);
|
|
||||||
|
for (int i = 0; i < items.length; i++)
|
||||||
for (int i = 0; i < items.length; i++)
|
try {
|
||||||
try {
|
createSettingElement(i, Settings.getInstance().getItems().get(items[i]));
|
||||||
createSettingElement(i, Settings.getInstance().getItems().get(items[i]));
|
} catch (SecurityException | ReflectiveOperationException e) {
|
||||||
} catch (SecurityException | ReflectiveOperationException e) {
|
logger.log(Level.WARNING, "Could not create settings item", e);
|
||||||
logger.log(Level.WARNING, "Could not create settings item", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void createSettingElement(int gridy, SettingsItem<?> settingsItem) throws SecurityException, ReflectiveOperationException {
|
||||||
private void createSettingElement(int gridy, SettingsItem<?> settingsItem) throws SecurityException, ReflectiveOperationException {
|
JTextPane descriptionText = new JTextPane();
|
||||||
JTextPane descriptionText = new JTextPane();
|
|
||||||
|
JComponent settingComponent = settingsItem.getComponent();
|
||||||
JComponent settingComponent = settingsItem.getComponent();
|
|
||||||
|
GridBagConstraints gbc_toggleSwitch = new GridBagConstraints();
|
||||||
GridBagConstraints gbc_toggleSwitch = new GridBagConstraints();
|
gbc_toggleSwitch.gridx = 1;
|
||||||
gbc_toggleSwitch.gridx = 1;
|
gbc_toggleSwitch.gridy = gridy;
|
||||||
gbc_toggleSwitch.gridy = gridy;
|
|
||||||
|
add(settingComponent, gbc_toggleSwitch);
|
||||||
add(settingComponent, gbc_toggleSwitch);
|
|
||||||
|
descriptionText.setText(settingsItem.getDescription());
|
||||||
descriptionText.setText(settingsItem.getDescription());
|
descriptionText.setBackground(theme.getBackgroundColor());
|
||||||
descriptionText.setBackground(theme.getBackgroundColor());
|
descriptionText.setForeground(theme.getBackgroundColor().invert());
|
||||||
descriptionText.setForeground(theme.getBackgroundColor().invert());
|
descriptionText.setEditable(false);
|
||||||
descriptionText.setEditable(false);
|
|
||||||
|
GridBagConstraints gbc_descriptionText = new GridBagConstraints();
|
||||||
GridBagConstraints gbc_descriptionText = new GridBagConstraints();
|
gbc_descriptionText.fill = GridBagConstraints.BOTH;
|
||||||
gbc_descriptionText.fill = GridBagConstraints.BOTH;
|
gbc_descriptionText.gridx = 0;
|
||||||
gbc_descriptionText.gridx = 0;
|
gbc_descriptionText.gridy = gridy;
|
||||||
gbc_descriptionText.gridy = gridy;
|
gbc_descriptionText.insets = new Insets(5, 5, 5, 5);
|
||||||
gbc_descriptionText.insets = new Insets(5, 5, 5, 5);
|
|
||||||
|
add(descriptionText, gbc_descriptionText);
|
||||||
add(descriptionText, gbc_descriptionText);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionListener getOkButtonAction() { return evt -> {}; }
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package envoy.client.ui.settings;
|
package envoy.client.ui.settings;
|
||||||
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,16 +22,9 @@ public abstract class SettingsPanel extends JPanel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a {@link SettingsPanel}.
|
* Initializes a {@link SettingsPanel}.
|
||||||
*
|
*
|
||||||
* @param parent the {@link SettingsScreen} as a part of which this
|
* @param parent the {@link SettingsScreen} as a part of which this
|
||||||
* {@link SettingsPanel} is displayed
|
* {@link SettingsPanel} is displayed
|
||||||
*/
|
*/
|
||||||
public SettingsPanel(SettingsScreen parent) { this.parent = parent; }
|
public SettingsPanel(SettingsScreen parent) { this.parent = parent; }
|
||||||
|
|
||||||
/**
|
|
||||||
* @return an {@link ActionListener} that should be invoked when the OK button
|
|
||||||
* is pressed in the {@link SettingsScreen}
|
|
||||||
* @since Envoy v0.2-alpha
|
|
||||||
*/
|
|
||||||
public abstract ActionListener getOkButtonAction();
|
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ public class SettingsScreen extends JDialog {
|
|||||||
|
|
||||||
// OK and cancel buttons
|
// OK and cancel buttons
|
||||||
private final JPanel buttonPane = new JPanel();
|
private final JPanel buttonPane = new JPanel();
|
||||||
private final PrimaryButton okButton = new PrimaryButton("Save");
|
|
||||||
private final PrimaryButton cancelButton = new PrimaryButton("Cancel");
|
private final PrimaryButton cancelButton = new PrimaryButton("Cancel");
|
||||||
|
|
||||||
private final Insets insets = new Insets(5, 5, 5, 5);
|
private final Insets insets = new Insets(5, 5, 5, 5);
|
||||||
@ -138,21 +137,6 @@ public class SettingsScreen extends JDialog {
|
|||||||
|
|
||||||
cancelButton.addActionListener((evt) -> { dispose(); });
|
cancelButton.addActionListener((evt) -> { dispose(); });
|
||||||
}
|
}
|
||||||
{
|
|
||||||
okButton.setActionCommand("OK");
|
|
||||||
okButton.setBorderPainted(false);
|
|
||||||
GridBagConstraints gbc_okButton = new GridBagConstraints();
|
|
||||||
gbc_okButton.anchor = GridBagConstraints.NORTHEAST;
|
|
||||||
gbc_okButton.fill = GridBagConstraints.EAST;
|
|
||||||
gbc_okButton.insets = insets;
|
|
||||||
gbc_okButton.gridx = 2;
|
|
||||||
gbc_okButton.gridy = 0;
|
|
||||||
buttonPane.add(okButton, gbc_okButton);
|
|
||||||
getRootPane().setDefaultButton(okButton);
|
|
||||||
|
|
||||||
// Invoke settings panel action on button press
|
|
||||||
okButton.addActionListener((evt) -> { if (settingsPanel != null) settingsPanel.getOkButtonAction().actionPerformed(evt); });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply current theme
|
// Apply current theme
|
||||||
@ -179,10 +163,6 @@ public class SettingsScreen extends JDialog {
|
|||||||
cancelButton.setBackground(theme.getInteractableBackgroundColor());
|
cancelButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
cancelButton.setForeground(theme.getInteractableForegroundColor());
|
cancelButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
|
||||||
// okButton
|
|
||||||
okButton.setBackground(theme.getInteractableBackgroundColor());
|
|
||||||
okButton.setForeground(theme.getInteractableForegroundColor());
|
|
||||||
|
|
||||||
// options
|
// options
|
||||||
options.setSelectionForeground(theme.getUserNameColor());
|
options.setSelectionForeground(theme.getUserNameColor());
|
||||||
options.setSelectionBackground(theme.getSelectionColor());
|
options.setSelectionBackground(theme.getSelectionColor());
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package envoy.client.ui.settings;
|
package envoy.client.ui.settings;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -11,6 +10,7 @@ import envoy.client.data.Settings;
|
|||||||
import envoy.client.event.ThemeChangeEvent;
|
import envoy.client.event.ThemeChangeEvent;
|
||||||
import envoy.client.ui.Color;
|
import envoy.client.ui.Color;
|
||||||
import envoy.client.ui.Theme;
|
import envoy.client.ui.Theme;
|
||||||
|
import envoy.client.ui.primary.PrimaryButton;
|
||||||
import envoy.event.EventBus;
|
import envoy.event.EventBus;
|
||||||
import envoy.util.EnvoyLog;
|
import envoy.util.EnvoyLog;
|
||||||
|
|
||||||
@ -30,13 +30,13 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
|
|
||||||
private JPanel colorsPanel = new JPanel();
|
private JPanel colorsPanel = new JPanel();
|
||||||
|
|
||||||
private DefaultComboBoxModel<String> themesModel = new DefaultComboBoxModel<>(
|
private DefaultComboBoxModel<String> themesModel;
|
||||||
Settings.getInstance().getThemes().keySet().toArray(new String[0]));
|
private JComboBox<String> themes;
|
||||||
private JComboBox<String> themes = new JComboBox<>(themesModel);
|
|
||||||
private Theme temporaryTheme;
|
private Theme temporaryTheme;
|
||||||
private boolean themeChanged;
|
private PrimaryButton createThemeButton = new PrimaryButton("Create Theme");
|
||||||
|
|
||||||
private final Insets insets = new Insets(5, 5, 5, 5);
|
private boolean themeChanged;
|
||||||
|
private final Insets insets = new Insets(5, 5, 5, 5);
|
||||||
|
|
||||||
private static final Logger logger = EnvoyLog.getLogger(ThemeCustomizationPanel.class);
|
private static final Logger logger = EnvoyLog.getLogger(ThemeCustomizationPanel.class);
|
||||||
private static final long serialVersionUID = -8697897390666456624L;
|
private static final long serialVersionUID = -8697897390666456624L;
|
||||||
@ -54,12 +54,22 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
super(parent);
|
super(parent);
|
||||||
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getCurrentTheme());
|
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
|
var themeNames = Settings.getInstance().getThemes().keySet().toArray(new String[0]);
|
||||||
|
String currentThemeName = Settings.getInstance().getCurrentThemeName();
|
||||||
|
for (int i = 0; i < themeNames.length; i++)
|
||||||
|
if (currentThemeName.equals(themeNames[i])) {
|
||||||
|
themeNames[i] = themeNames[0];
|
||||||
|
themeNames[0] = currentThemeName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
themesModel = new DefaultComboBoxModel<>(themeNames);
|
||||||
|
themes = new JComboBox<>(themesModel);
|
||||||
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, 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, 0.01 };
|
||||||
|
|
||||||
setLayout(gbl_themeLayout);
|
setLayout(gbl_themeLayout);
|
||||||
|
|
||||||
@ -95,6 +105,37 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
gbc_colorsPanel.insets = insets;
|
gbc_colorsPanel.insets = insets;
|
||||||
|
|
||||||
add(colorsPanel, gbc_colorsPanel);
|
add(colorsPanel, gbc_colorsPanel);
|
||||||
|
|
||||||
|
createThemeButton.addActionListener((evt) -> {
|
||||||
|
if (themeChanged) {
|
||||||
|
new NewThemeScreen(parent, name -> {
|
||||||
|
// Create new theme
|
||||||
|
logger.log(Level.FINEST, name);
|
||||||
|
Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme));
|
||||||
|
|
||||||
|
// Add new theme name to combo box
|
||||||
|
themesModel.addElement(name);
|
||||||
|
|
||||||
|
// Select new theme name
|
||||||
|
themes.setSelectedIndex(themesModel.getSize() - 1);
|
||||||
|
}, name -> {
|
||||||
|
// Modify theme
|
||||||
|
Settings.getInstance().getThemes().replace(name, new Theme(name, temporaryTheme));
|
||||||
|
if (themes.getSelectedItem().equals(name))
|
||||||
|
EventBus.getInstance().dispatch(new ThemeChangeEvent(Settings.getInstance().getTheme(name)));
|
||||||
|
else themes.setSelectedItem(name);
|
||||||
|
}).setVisible(true);
|
||||||
|
themeChanged = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
GridBagConstraints gbc_createThemeButton = new GridBagConstraints();
|
||||||
|
gbc_createThemeButton.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_createThemeButton.gridx = 0;
|
||||||
|
gbc_createThemeButton.gridy = 2;
|
||||||
|
gbc_createThemeButton.anchor = GridBagConstraints.CENTER;
|
||||||
|
gbc_createThemeButton.insets = insets;
|
||||||
|
add(createThemeButton, gbc_createThemeButton);
|
||||||
|
|
||||||
colorsPanel.setBackground(theme.getCellColor());
|
colorsPanel.setBackground(theme.getCellColor());
|
||||||
|
|
||||||
// Apply theme upon selection
|
// Apply theme upon selection
|
||||||
@ -120,37 +161,15 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionListener getOkButtonAction() {
|
|
||||||
return (evt) -> {
|
|
||||||
if (themeChanged) {
|
|
||||||
new NewThemeScreen(parent, name -> {
|
|
||||||
// Create new theme
|
|
||||||
logger.log(Level.FINEST, name);
|
|
||||||
Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme));
|
|
||||||
|
|
||||||
// Add new theme name to combo box
|
|
||||||
themesModel.addElement(name);
|
|
||||||
|
|
||||||
// Select new theme name
|
|
||||||
themes.setSelectedIndex(themesModel.getSize() - 1);
|
|
||||||
}, name -> {
|
|
||||||
// Modify theme
|
|
||||||
Settings.getInstance().getThemes().replace(name, new Theme(name, temporaryTheme));
|
|
||||||
if (themes.getSelectedItem().equals(name))
|
|
||||||
EventBus.getInstance().dispatch(new ThemeChangeEvent(Settings.getInstance().getTheme(name)));
|
|
||||||
else themes.setSelectedItem(name);
|
|
||||||
}).setVisible(true);
|
|
||||||
themeChanged = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyTheme(Theme theme) {
|
private void applyTheme(Theme theme) {
|
||||||
// themeContent
|
// themeContent
|
||||||
setForeground(theme.getUserNameColor());
|
setForeground(theme.getUserNameColor());
|
||||||
setBackground(theme.getCellColor());
|
setBackground(theme.getCellColor());
|
||||||
|
|
||||||
|
// createThemeButton
|
||||||
|
createThemeButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
createThemeButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
|
|
||||||
// themes
|
// themes
|
||||||
themes.setBackground(theme.getInteractableBackgroundColor());
|
themes.setBackground(theme.getInteractableBackgroundColor());
|
||||||
themes.setForeground(theme.getInteractableForegroundColor());
|
themes.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
Reference in New Issue
Block a user