Formatting
This commit is contained in:
parent
abe36d999a
commit
141b2371cc
@ -28,7 +28,7 @@ public class Settings {
|
|||||||
private boolean enterToSend = true;
|
private boolean enterToSend = true;
|
||||||
private Map<String, Theme> themes;
|
private Map<String, Theme> themes;
|
||||||
private String currentTheme;
|
private String currentTheme;
|
||||||
private int currentOnCloseMode;
|
private int currentOnCloseMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required to save the settings.
|
* Required to save the settings.
|
||||||
@ -66,7 +66,7 @@ public class Settings {
|
|||||||
setEnterToSend(prefs.getBoolean("enterToSend", true));
|
setEnterToSend(prefs.getBoolean("enterToSend", true));
|
||||||
setCurrentTheme(prefs.get("theme", "dark"));
|
setCurrentTheme(prefs.get("theme", "dark"));
|
||||||
setCurrentOnCloseMode(prefs.getInt("onCloseMode", 1));
|
setCurrentOnCloseMode(prefs.getInt("onCloseMode", 1));
|
||||||
|
|
||||||
// Load themes from theme file
|
// Load themes from theme file
|
||||||
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(themeFile))) {
|
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(themeFile))) {
|
||||||
Object obj = in.readObject();
|
Object obj = in.readObject();
|
||||||
@ -158,18 +158,18 @@ public class Settings {
|
|||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public void setThemes(Map<String, Theme> themes) { this.themes = themes; }
|
public void setThemes(Map<String, Theme> themes) { this.themes = themes; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current on close mode.
|
* @return the current on close mode.
|
||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public int getCurrentOnCloseMode () {return currentOnCloseMode;}
|
public int getCurrentOnCloseMode() { return currentOnCloseMode; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current on close mode.
|
* Sets the current on close mode.
|
||||||
*
|
*
|
||||||
* @param currentOnCloseMode the on close mode that should be set.
|
* @param currentOnCloseMode the on close mode that should be set.
|
||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public void setCurrentOnCloseMode(int currentOnCloseMode) {this.currentOnCloseMode = currentOnCloseMode;}
|
public void setCurrentOnCloseMode(int currentOnCloseMode) { this.currentOnCloseMode = currentOnCloseMode; }
|
||||||
}
|
}
|
@ -8,16 +8,19 @@ package envoy.client.event;
|
|||||||
* @author Maximilian Käfer
|
* @author Maximilian Käfer
|
||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public class OnCloseChangeEvent implements Event<Integer>{
|
public class OnCloseChangeEvent implements Event<Integer> {
|
||||||
|
|
||||||
private Integer closeMode;
|
private Integer closeMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param closeMode This is the on close mode for the client, that should be set.
|
* @param closeMode This is the on close mode for the client, that should be
|
||||||
* </br> 0 = ExitOnClose </br> 1 = HideOnClose
|
* set.
|
||||||
|
* </br>
|
||||||
|
* 0 = ExitOnClose </br>
|
||||||
|
* 1 = HideOnClose
|
||||||
* @since Envoy 0.3-alpha
|
* @since Envoy 0.3-alpha
|
||||||
*/
|
*/
|
||||||
public OnCloseChangeEvent(int closeMode) {this.closeMode = closeMode;}
|
public OnCloseChangeEvent(int closeMode) { this.closeMode = closeMode; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer get() { return closeMode; }
|
public Integer get() { return closeMode; }
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -9,13 +9,12 @@ import javax.swing.*;
|
|||||||
import envoy.client.Settings;
|
import envoy.client.Settings;
|
||||||
import envoy.client.event.Event;
|
import envoy.client.event.Event;
|
||||||
import envoy.client.event.EventBus;
|
import envoy.client.event.EventBus;
|
||||||
import envoy.client.event.EventHandler;
|
|
||||||
import envoy.client.event.OnCloseChangeEvent;
|
|
||||||
import envoy.client.ui.settings.ThemeCustomizationPanel;
|
|
||||||
import envoy.client.util.EnvoyLog;
|
import envoy.client.util.EnvoyLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Component can be used to toggle between two options. e.g. on and off </br></br>
|
* This Component can be used to toggle between two options. e.g. on and off
|
||||||
|
* </br>
|
||||||
|
* </br>
|
||||||
*
|
*
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
* File: <strong>PrimaryToggleSwitch.java</strong><br>
|
* File: <strong>PrimaryToggleSwitch.java</strong><br>
|
||||||
@ -24,20 +23,21 @@ import envoy.client.util.EnvoyLog;
|
|||||||
* @author Maximilian Käfer
|
* @author Maximilian Käfer
|
||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public class PrimaryToggleSwitch extends JPanel{
|
public class PrimaryToggleSwitch extends JPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = -721155303106833184L;
|
private static final long serialVersionUID = -721155303106833184L;
|
||||||
private boolean initialState;
|
JButton b = new JButton("");
|
||||||
JButton b = new JButton("");
|
private boolean currentState;
|
||||||
private boolean currentState;
|
private int variable;
|
||||||
private int variable;
|
private static final Logger logger = EnvoyLog.getLogger(PrimaryToggleSwitch.class.getSimpleName());
|
||||||
private static final Logger logger = EnvoyLog.getLogger(PrimaryToggleSwitch.class.getSimpleName());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the constructor for the PrimaryToggleSwitch.
|
* This is the constructor for the PrimaryToggleSwitch.
|
||||||
*
|
*
|
||||||
* @param initialState The state the toggleSwitch is standardly set to. </br> true: off </br> false: on
|
* @param initialState The state the toggleSwitch is standardly set to. </br>
|
||||||
* @param eventName the path of the event class
|
* true: off </br>
|
||||||
|
* false: on
|
||||||
|
* @param eventName the path of the event class
|
||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "rawtypes", "unused" })
|
@SuppressWarnings({ "rawtypes", "unused" })
|
||||||
@ -45,38 +45,36 @@ public class PrimaryToggleSwitch extends JPanel{
|
|||||||
super();
|
super();
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
this.initialState = initialState;
|
|
||||||
|
|
||||||
setPreferredSize(new Dimension(50, 25));
|
setPreferredSize(new Dimension(50, 25));
|
||||||
setMinimumSize(new Dimension(50, 25));
|
setMinimumSize(new Dimension(50, 25));
|
||||||
setMaximumSize(new Dimension(50, 25));
|
setMaximumSize(new Dimension(50, 25));
|
||||||
|
|
||||||
b.setPreferredSize(new Dimension(25, 25));
|
b.setPreferredSize(new Dimension(25, 25));
|
||||||
b.setMinimumSize(new Dimension(25, 25));
|
b.setMinimumSize(new Dimension(25, 25));
|
||||||
b.setMaximumSize(new Dimension(25, 25));
|
b.setMaximumSize(new Dimension(25, 25));
|
||||||
|
|
||||||
b.setBackground(Settings.getInstance().getThemes()
|
b.setBackground(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor());
|
||||||
.get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor());
|
|
||||||
|
|
||||||
GridBagLayout gbl_toggleSwitch = new GridBagLayout();
|
GridBagLayout gbl_toggleSwitch = new GridBagLayout();
|
||||||
gbl_toggleSwitch.columnWidths = new int[] { 1, 1 };
|
gbl_toggleSwitch.columnWidths = new int[] { 1, 1 };
|
||||||
gbl_toggleSwitch.rowHeights = new int[] { 1};
|
gbl_toggleSwitch.rowHeights = new int[] { 1 };
|
||||||
gbl_toggleSwitch.columnWeights = new double[] { 1.0, 1.0 };
|
gbl_toggleSwitch.columnWeights = new double[] { 1.0, 1.0 };
|
||||||
gbl_toggleSwitch.rowWeights = new double[] {1.0 };
|
gbl_toggleSwitch.rowWeights = new double[] { 1.0 };
|
||||||
|
|
||||||
setLayout(gbl_toggleSwitch);
|
setLayout(gbl_toggleSwitch);
|
||||||
|
|
||||||
setState(initialState);
|
setState(initialState);
|
||||||
|
|
||||||
b.addActionListener((evt) -> {
|
b.addActionListener((evt) -> {
|
||||||
try {
|
try {
|
||||||
Class<?> c = Class.forName(eventName);
|
Class<?> c = Class.forName(eventName);
|
||||||
Class[] types = {int.class};
|
Class[] types = { int.class };
|
||||||
Constructor constructor = c.getConstructor(types);
|
Constructor constructor = c.getConstructor(types);
|
||||||
|
|
||||||
Object[] parameters = {variable};
|
Object[] parameters = { variable };
|
||||||
Object instanceOfC = constructor.newInstance(parameters);
|
Object instanceOfC = constructor.newInstance(parameters);
|
||||||
|
|
||||||
EventBus.getInstance().dispatch((Event<?>) constructor.newInstance(parameters));
|
EventBus.getInstance().dispatch((Event<?>) constructor.newInstance(parameters));
|
||||||
setState(!currentState);
|
setState(!currentState);
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
@ -86,42 +84,45 @@ public class PrimaryToggleSwitch extends JPanel{
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
g.setColor(Color.LIGHT_GRAY);
|
g.setColor(Color.LIGHT_GRAY);
|
||||||
g.fillRect(0, 0, 50, 25);
|
g.fillRect(0, 0, 50, 25);
|
||||||
g.setColor(Color.GREEN);
|
g.setColor(Color.GREEN);
|
||||||
g.fillRect(0, 0, 25, 25);
|
g.fillRect(0, 0, 25, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets the state of the {@link PrimaryToggleSwitch}.
|
* This method sets the state of the {@link PrimaryToggleSwitch}.
|
||||||
*
|
*
|
||||||
* @param state This is the state of the {@link PrimaryToggleSwitch}, that should be set. </br> true: off </br> false: on
|
* @param state This is the state of the {@link PrimaryToggleSwitch}, that
|
||||||
|
* should be set. </br>
|
||||||
|
* true: off </br>
|
||||||
|
* false: on
|
||||||
* @since Envoy 0.3-alpha
|
* @since Envoy 0.3-alpha
|
||||||
*/
|
*/
|
||||||
public void setState (boolean state){
|
public void setState(boolean state) {
|
||||||
if(state) {
|
if (state) {
|
||||||
GridBagConstraints gbc_toggleButton = new GridBagConstraints();
|
GridBagConstraints gbc_toggleButton = new GridBagConstraints();
|
||||||
gbc_toggleButton.anchor = GridBagConstraints.WEST;
|
gbc_toggleButton.anchor = GridBagConstraints.WEST;
|
||||||
gbc_toggleButton.gridx = 0;
|
gbc_toggleButton.gridx = 0;
|
||||||
gbc_toggleButton.gridy = 0;
|
gbc_toggleButton.gridy = 0;
|
||||||
|
|
||||||
add(b, gbc_toggleButton);
|
|
||||||
currentState = true;
|
|
||||||
variable = 1;
|
|
||||||
}else {
|
|
||||||
GridBagConstraints gbc_toggleButton = new GridBagConstraints();
|
|
||||||
gbc_toggleButton.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_toggleButton.gridx = 1;
|
|
||||||
gbc_toggleButton.gridy = 0;
|
|
||||||
|
|
||||||
add(b, gbc_toggleButton);
|
add(b, gbc_toggleButton);
|
||||||
currentState = false;
|
currentState = true;
|
||||||
variable = 0;
|
variable = 1;
|
||||||
|
} else {
|
||||||
|
GridBagConstraints gbc_toggleButton = new GridBagConstraints();
|
||||||
|
gbc_toggleButton.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_toggleButton.gridx = 1;
|
||||||
|
gbc_toggleButton.gridy = 0;
|
||||||
|
|
||||||
|
add(b, gbc_toggleButton);
|
||||||
|
currentState = false;
|
||||||
|
variable = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,12 +132,12 @@ public class Startup {
|
|||||||
new StatusTrayIcon(chatWindow).show();
|
new StatusTrayIcon(chatWindow).show();
|
||||||
|
|
||||||
// If the tray icon is supported, hide the chat window on close
|
// If the tray icon is supported, hide the chat window on close
|
||||||
if(Settings.getInstance().getCurrentOnCloseMode() == 1) {
|
if (Settings.getInstance().getCurrentOnCloseMode() == 1) {
|
||||||
chatWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
chatWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||||
}else {
|
} else {
|
||||||
chatWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
chatWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (EnvoyException e) {
|
} catch (EnvoyException e) {
|
||||||
logger.warning("The StatusTrayIcon is not supported on this platform!");
|
logger.warning("The StatusTrayIcon is not supported on this platform!");
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ 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.awt.event.ActionListener;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
@ -14,7 +12,6 @@ import javax.swing.JTextPane;
|
|||||||
import envoy.client.Settings;
|
import envoy.client.Settings;
|
||||||
import envoy.client.event.EventBus;
|
import envoy.client.event.EventBus;
|
||||||
import envoy.client.event.OnCloseChangeEvent;
|
import envoy.client.event.OnCloseChangeEvent;
|
||||||
import envoy.client.event.ThemeChangeEvent;
|
|
||||||
import envoy.client.ui.PrimaryToggleSwitch;
|
import envoy.client.ui.PrimaryToggleSwitch;
|
||||||
import envoy.client.ui.Theme;
|
import envoy.client.ui.Theme;
|
||||||
import envoy.client.util.EnvoyLog;
|
import envoy.client.util.EnvoyLog;
|
||||||
@ -31,98 +28,101 @@ import envoy.client.util.EnvoyLog;
|
|||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public class General extends SettingsPanel {
|
public class General extends SettingsPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7470848775130754239L;
|
private static final long serialVersionUID = -7470848775130754239L;
|
||||||
private static final Logger logger = EnvoyLog.getLogger(General.class.getSimpleName());
|
private static final Logger logger = EnvoyLog.getLogger(General.class.getSimpleName());
|
||||||
|
|
||||||
private int state;
|
private int state;
|
||||||
|
|
||||||
PrimaryToggleSwitch toggleSwitch;
|
PrimaryToggleSwitch toggleSwitch;
|
||||||
JTextPane onCloseModeText = new JTextPane();
|
JTextPane onCloseModeText = new JTextPane();
|
||||||
JTextPane onCloseModeState = new JTextPane();
|
JTextPane onCloseModeState = new JTextPane();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the constructor for the General class. Here the user can set general settings for the client.
|
* This is the constructor for the General class. Here the user can set general
|
||||||
|
* settings for the client.
|
||||||
|
*
|
||||||
* @since Envoy 0.3-alpha
|
* @since Envoy 0.3-alpha
|
||||||
*/
|
*/
|
||||||
public General() {
|
public General() {
|
||||||
Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
state = Settings.getInstance().getCurrentOnCloseMode();
|
state = Settings.getInstance().getCurrentOnCloseMode();
|
||||||
if(state == 1) {
|
if (state == 1) {
|
||||||
toggleSwitch = new PrimaryToggleSwitch(false,"envoy.client.event.OnCloseChangeEvent");
|
toggleSwitch = new PrimaryToggleSwitch(false, "envoy.client.event.OnCloseChangeEvent");
|
||||||
}else {
|
} else {
|
||||||
toggleSwitch = new PrimaryToggleSwitch(true,"envoy.client.event.OnCloseChangeEvent");
|
toggleSwitch = new PrimaryToggleSwitch(true, "envoy.client.event.OnCloseChangeEvent");
|
||||||
}
|
}
|
||||||
|
|
||||||
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.0005, 1.0 };
|
gbl_general.rowWeights = new double[] { 0.02, 0.0005, 1.0 };
|
||||||
|
|
||||||
setLayout(gbl_general);
|
setLayout(gbl_general);
|
||||||
|
|
||||||
GridBagConstraints gbc_toggleSwitch = new GridBagConstraints();
|
GridBagConstraints gbc_toggleSwitch = new GridBagConstraints();
|
||||||
gbc_toggleSwitch.gridx = 1;
|
gbc_toggleSwitch.gridx = 1;
|
||||||
gbc_toggleSwitch.gridy = 0;
|
gbc_toggleSwitch.gridy = 0;
|
||||||
|
|
||||||
add(toggleSwitch, gbc_toggleSwitch);
|
add(toggleSwitch, gbc_toggleSwitch);
|
||||||
|
|
||||||
if(state == 0) {
|
if (state == 0) {
|
||||||
onCloseModeState.setText("OFF");
|
onCloseModeState.setText("OFF");
|
||||||
}else {
|
} else {
|
||||||
onCloseModeState.setText("ON");
|
onCloseModeState.setText("ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
onCloseModeState.setBackground(theme.getCellColor());
|
onCloseModeState.setBackground(theme.getCellColor());
|
||||||
onCloseModeState.setForeground(theme.getUserNameColor());
|
onCloseModeState.setForeground(theme.getUserNameColor());
|
||||||
|
|
||||||
GridBagConstraints gbc_onCloseModeState = new GridBagConstraints();
|
GridBagConstraints gbc_onCloseModeState = new GridBagConstraints();
|
||||||
gbc_onCloseModeState.anchor = GridBagConstraints.NORTH;
|
gbc_onCloseModeState.anchor = GridBagConstraints.NORTH;
|
||||||
gbc_onCloseModeState.gridx = 1;
|
gbc_onCloseModeState.gridx = 1;
|
||||||
gbc_onCloseModeState.gridy = 1;
|
gbc_onCloseModeState.gridy = 1;
|
||||||
|
|
||||||
add(onCloseModeState, gbc_onCloseModeState);
|
add(onCloseModeState, gbc_onCloseModeState);
|
||||||
|
|
||||||
onCloseModeText.setText("Client runs in the background, when window is closed");
|
onCloseModeText.setText("Client runs in the background, when window is closed");
|
||||||
onCloseModeText.setBackground(theme.getBackgroundColor());
|
onCloseModeText.setBackground(theme.getBackgroundColor());
|
||||||
//TODO: Change to inverted color.
|
// TODO: Change to inverted color.
|
||||||
onCloseModeText.setForeground(theme.getUserNameColor());
|
onCloseModeText.setForeground(theme.getUserNameColor());
|
||||||
|
|
||||||
GridBagConstraints gbc_onCloseModeText = new GridBagConstraints();
|
GridBagConstraints gbc_onCloseModeText = new GridBagConstraints();
|
||||||
gbc_onCloseModeText.fill = GridBagConstraints.BOTH;
|
gbc_onCloseModeText.fill = GridBagConstraints.BOTH;
|
||||||
gbc_onCloseModeText.gridx = 0;
|
gbc_onCloseModeText.gridx = 0;
|
||||||
gbc_onCloseModeText.gridy = 0;
|
gbc_onCloseModeText.gridy = 0;
|
||||||
gbc_onCloseModeText.gridheight = 2;
|
gbc_onCloseModeText.gridheight = 2;
|
||||||
gbc_onCloseModeText.insets = new Insets(5, 5, 5, 5);
|
gbc_onCloseModeText.insets = new Insets(5, 5, 5, 5);
|
||||||
|
|
||||||
add(onCloseModeText, gbc_onCloseModeText);
|
add(onCloseModeText, gbc_onCloseModeText);
|
||||||
|
|
||||||
EventBus.getInstance().register(OnCloseChangeEvent.class, (evt) -> changeOnClose(((OnCloseChangeEvent) evt).get()));
|
EventBus.getInstance().register(OnCloseChangeEvent.class, (evt) -> changeOnClose(((OnCloseChangeEvent) evt).get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method changes the on close mode of the client.
|
* 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.
|
* @param state This is the integer that defines weather the toggleSwitch is on
|
||||||
|
* or off.
|
||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
public void changeOnClose(int state) {
|
public void changeOnClose(int state) {
|
||||||
System.out.println(state);
|
System.out.println(state);
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
|
||||||
if(state == 0) {
|
if (state == 0) {
|
||||||
onCloseModeState.setText("OFF");
|
onCloseModeState.setText("OFF");
|
||||||
}else {
|
} else {
|
||||||
onCloseModeState.setText("ON");
|
onCloseModeState.setText("ON");
|
||||||
}
|
}
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionListener getOkButtonAction() {
|
public ActionListener getOkButtonAction() {
|
||||||
return (evt) -> {
|
return (evt) -> {
|
||||||
@ -130,7 +130,7 @@ public class General extends SettingsPanel {
|
|||||||
try {
|
try {
|
||||||
Settings.getInstance().setCurrentOnCloseMode(state);
|
Settings.getInstance().setCurrentOnCloseMode(state);
|
||||||
JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
|
JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info("Close mode could not be changed! " + e);
|
logger.info("Close mode could not be changed! " + e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,10 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
|
|
||||||
private JPanel colorsPanel = new JPanel();
|
private JPanel colorsPanel = new JPanel();
|
||||||
|
|
||||||
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 boolean themeChanged = false;
|
||||||
|
|
||||||
private final Insets insets = new Insets(5, 5, 5, 5);
|
private final Insets insets = new Insets(5, 5, 5, 5);
|
||||||
|
|
||||||
@ -51,15 +51,14 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public ThemeCustomizationPanel() {
|
public ThemeCustomizationPanel() {
|
||||||
temporaryTheme = new Theme("temporaryTheme",
|
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||||
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);
|
||||||
|
|
||||||
@ -76,20 +75,20 @@ 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.gridwidth = 2;
|
gbc_themes.gridwidth = 2;
|
||||||
gbc_themes.gridx = 0;
|
gbc_themes.gridx = 0;
|
||||||
gbc_themes.gridy = 0;
|
gbc_themes.gridy = 0;
|
||||||
gbc_themes.anchor = GridBagConstraints.NORTHWEST;
|
gbc_themes.anchor = GridBagConstraints.NORTHWEST;
|
||||||
gbc_themes.insets = new Insets(10, 10, 20, 10);
|
gbc_themes.insets = new Insets(10, 10, 20, 10);
|
||||||
|
|
||||||
add(themes, gbc_themes);
|
add(themes, gbc_themes);
|
||||||
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, 1 };
|
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);
|
||||||
|
|
||||||
@ -97,12 +96,12 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
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);
|
||||||
colorsPanel.setBackground(theme.getCellColor());
|
colorsPanel.setBackground(theme.getCellColor());
|
||||||
@ -122,11 +121,10 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
String name = JOptionPane.showInputDialog("Enter a name for the new theme");
|
String name = JOptionPane.showInputDialog("Enter a name for the new theme");
|
||||||
logger.log(Level.FINEST, name);
|
logger.log(Level.FINEST, name);
|
||||||
Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme));
|
Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme));
|
||||||
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
||||||
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(name).getThemeName();
|
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(name).getThemeName();
|
||||||
|
|
||||||
temporaryTheme = new Theme("temporaryTheme",
|
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
|
||||||
|
|
||||||
themes.addItem(themeArray[themeArray.length - 1]);
|
themes.addItem(themeArray[themeArray.length - 1]);
|
||||||
themes.setSelectedIndex(themeArray.length - 1);
|
themes.setSelectedIndex(themeArray.length - 1);
|
||||||
@ -172,10 +170,8 @@ public class ThemeCustomizationPanel extends SettingsPanel {
|
|||||||
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",
|
buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", "interactableForegroundColor", 3);
|
||||||
"interactableForegroundColor", 3);
|
buildCustomizeElement(theme, theme.getInteractableBackgroundColor(), "Interactable Background", "interactableBackgroundColor", 4);
|
||||||
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);
|
||||||
@ -184,8 +180,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());
|
||||||
@ -215,25 +211,23 @@ 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) {
|
private Color getInvertedColor(Color color) { return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); }
|
||||||
return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user