153 lines
5.0 KiB
Java
153 lines
5.0 KiB
Java
package envoy.client.ui.settings;
|
|
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.Insets;
|
|
import java.awt.event.ActionListener;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JTextPane;
|
|
|
|
import envoy.client.Settings;
|
|
import envoy.client.SettingsItem;
|
|
import envoy.client.ui.PrimaryToggleSwitch;
|
|
import envoy.client.ui.Theme;
|
|
import envoy.client.util.EnvoyLog;
|
|
|
|
/**
|
|
* Displays GUI components that allow general settings regarding the client.<br>
|
|
* <br>
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>General.java</strong><br>
|
|
* Created: <strong>21 Dec 2019</strong><br>
|
|
*
|
|
* @author Maximilian Käfer
|
|
* @since Envoy v0.3-alpha
|
|
*/
|
|
public class General extends SettingsPanel {
|
|
|
|
private Theme theme;
|
|
private boolean onCloseState = Settings.getInstance().getCurrentOnCloseMode();
|
|
private boolean enterToSend = Settings.getInstance().isEnterToSend();
|
|
|
|
private static final Logger logger = EnvoyLog.getLogger(General.class.getSimpleName());
|
|
private static final long serialVersionUID = -7470848775130754239L;
|
|
|
|
/**
|
|
* This is the constructor for the General class. Here the user can set general
|
|
* settings for the client.
|
|
*
|
|
* @since Envoy 0.3-alpha
|
|
*/
|
|
public General() {
|
|
theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
|
|
|
setBackground(theme.getCellColor());
|
|
|
|
GridBagLayout gbl_general = new GridBagLayout();
|
|
gbl_general.columnWidths = new int[] { 1, 1 };
|
|
gbl_general.rowHeights = new int[] { 1, 1, 1, 1, 1 };
|
|
gbl_general.columnWeights = new double[] { 1.0, 0.1 };
|
|
gbl_general.rowWeights = new double[] { 0.02, 0.0005, 0.02, 0.0005, 1.0 };
|
|
|
|
setLayout(gbl_general);
|
|
|
|
createSettingElement(0,
|
|
(SettingsItem<Boolean>) Settings.getInstance().getItems().get("onCloseMode"));
|
|
|
|
createSettingElement(2,
|
|
(SettingsItem<Boolean>) Settings.getInstance().getItems().get("enterToSend"));
|
|
}
|
|
|
|
// TODO: Move ON / OFF text to PrimaryToggleswitch
|
|
|
|
/**
|
|
* This method changes the on close mode of the client.
|
|
*
|
|
* @param state This is the integer that defines weather the toggleSwitch is on
|
|
* or off.
|
|
* @since Envoy v0.3-alpha
|
|
*/
|
|
public void changeOnClose(boolean state) {
|
|
this.onCloseState = state;
|
|
|
|
//onCloseModeStatePane.setText(state ? "ON" : "OFF");
|
|
revalidate();
|
|
repaint();
|
|
}
|
|
|
|
/**
|
|
* This method changes the enter to send a message setting.
|
|
*
|
|
* @param state This is the integer that defines weather the toggleSwitch is on
|
|
* or off.
|
|
* @since Envoy v0.3-alpha
|
|
*/
|
|
public void changeEnterToSend(boolean state) {
|
|
this.enterToSend = state;
|
|
|
|
//enterToSendStatePane.setText(state ? "ON" : "OFF");
|
|
revalidate();
|
|
repaint();
|
|
}
|
|
|
|
private void createSettingElement(int gridy, SettingsItem<Boolean> settingsItem) {
|
|
JTextPane stateText = new JTextPane();
|
|
JTextPane descriptionText = new JTextPane();
|
|
|
|
PrimaryToggleSwitch toggleSwitch = new PrimaryToggleSwitch(settingsItem);
|
|
|
|
GridBagConstraints gbc_toggleSwitch = new GridBagConstraints();
|
|
gbc_toggleSwitch.gridx = 1;
|
|
gbc_toggleSwitch.gridy = gridy;
|
|
|
|
add(toggleSwitch, gbc_toggleSwitch);
|
|
|
|
stateText.setText(settingsItem.get() ? "ON" : "OFF");
|
|
stateText.setBackground(theme.getCellColor());
|
|
stateText.setForeground(theme.getUserNameColor());
|
|
stateText.setEditable(false);
|
|
|
|
GridBagConstraints gbc_stateText = new GridBagConstraints();
|
|
gbc_stateText.anchor = GridBagConstraints.NORTH;
|
|
gbc_stateText.gridx = 1;
|
|
gbc_stateText.gridy = gridy + 1;
|
|
|
|
add(stateText, gbc_stateText);
|
|
|
|
descriptionText.setText(settingsItem.getDescription());
|
|
descriptionText.setBackground(theme.getBackgroundColor());
|
|
descriptionText.setForeground(theme.getBackgroundColor().invert());
|
|
descriptionText.setEditable(false);
|
|
|
|
GridBagConstraints gbc_descriptionText = new GridBagConstraints();
|
|
gbc_descriptionText.fill = GridBagConstraints.BOTH;
|
|
gbc_descriptionText.gridx = 0;
|
|
gbc_descriptionText.gridy = gridy;
|
|
gbc_descriptionText.gridheight = 2;
|
|
gbc_descriptionText.insets = new Insets(5, 5, 5, 5);
|
|
|
|
add(descriptionText, gbc_descriptionText);
|
|
}
|
|
|
|
@Override
|
|
public ActionListener getOkButtonAction() {
|
|
return (evt) -> {
|
|
if (onCloseState != Settings.getInstance().getCurrentOnCloseMode()) try {
|
|
Settings.getInstance().setCurrentOnCloseMode(onCloseState);
|
|
JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
|
|
} catch (Exception e) {
|
|
logger.log(Level.WARNING, "Close mode could not be changed! ", e);
|
|
}
|
|
|
|
if (enterToSend != Settings.getInstance().isEnterToSend()) try {
|
|
Settings.getInstance().setEnterToSend(enterToSend);
|
|
JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
|
|
} catch (Exception e) {
|
|
logger.log(Level.WARNING, "Enter to send mode could not be changed! ", e);
|
|
}
|
|
};
|
|
}
|
|
} |