Merge pull request #83 from informatik-ag-ngl/f/themeNameCollision
Theme name collision
This commit is contained in:
		@@ -186,4 +186,11 @@ 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; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @param themeName the name of the {@link Theme} to get
 | 
				
			||||||
 | 
						 * @return the {@link Theme} with the specified name
 | 
				
			||||||
 | 
						 * @since Envoy v0.3-alpha
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public Theme getTheme(String themeName) { return themes.get(themeName); }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -79,6 +79,8 @@ public class Color extends java.awt.Color {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	private static final long serialVersionUID = -9166233199998257344L;
 | 
						private static final long serialVersionUID = -9166233199998257344L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public Color(java.awt.Color other) { this(other.getRGB()); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public Color(int rgb) { super(rgb); }
 | 
						public Color(int rgb) { super(rgb); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public Color(int rgba, boolean hasalpha) { super(rgba, hasalpha); }
 | 
						public Color(int rgba, boolean hasalpha) { super(rgba, hasalpha); }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,9 +37,12 @@ public class GeneralSettingsPanel extends SettingsPanel {
 | 
				
			|||||||
	 * 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.
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @since Envoy 0.3-alpha
 | 
						 * @param parent the {@link SettingsScreen} as a part of which this
 | 
				
			||||||
 | 
						 *               {@link SettingsPanel} is displayed
 | 
				
			||||||
 | 
						 * @since Envoy v0.3-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public GeneralSettingsPanel() {
 | 
						public GeneralSettingsPanel(SettingsScreen parent) {
 | 
				
			||||||
 | 
							super(parent);
 | 
				
			||||||
		theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
 | 
							theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		setBackground(theme.getCellColor());
 | 
							setBackground(theme.getCellColor());
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										226
									
								
								src/main/java/envoy/client/ui/settings/NewThemeScreen.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										226
									
								
								src/main/java/envoy/client/ui/settings/NewThemeScreen.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,226 @@
 | 
				
			|||||||
 | 
					package envoy.client.ui.settings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.awt.*;
 | 
				
			||||||
 | 
					import java.util.function.Consumer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.swing.JDialog;
 | 
				
			||||||
 | 
					import javax.swing.JPanel;
 | 
				
			||||||
 | 
					import javax.swing.JTextPane;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import envoy.client.Settings;
 | 
				
			||||||
 | 
					import envoy.client.ui.PrimaryButton;
 | 
				
			||||||
 | 
					import envoy.client.ui.PrimaryTextArea;
 | 
				
			||||||
 | 
					import envoy.client.ui.Theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Displays window where you can choose a name for the new {@link Theme}.
 | 
				
			||||||
 | 
					 * <br>
 | 
				
			||||||
 | 
					 * Project: <strong>envoy-client</strong><br>
 | 
				
			||||||
 | 
					 * File: <strong>NewThemeScreen.java</strong><br>
 | 
				
			||||||
 | 
					 * Created: <strong>26 Dec 2019</strong><br>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Maximilian Käfer
 | 
				
			||||||
 | 
					 * @since Envoy v0.3-alpha
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class NewThemeScreen extends JDialog {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final JPanel	standardPanel		= new JPanel();
 | 
				
			||||||
 | 
						private final JPanel	secondaryPanel		= new JPanel();
 | 
				
			||||||
 | 
						private JTextPane		text				= new JTextPane();
 | 
				
			||||||
 | 
						private PrimaryTextArea	nameEnterTextArea	= new PrimaryTextArea(4);
 | 
				
			||||||
 | 
						private PrimaryButton	confirmButton		= new PrimaryButton("Confirm");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private JTextPane		errorText	= new JTextPane();
 | 
				
			||||||
 | 
						private PrimaryButton	otherName	= new PrimaryButton("Other Name");
 | 
				
			||||||
 | 
						private PrimaryButton	overwrite	= new PrimaryButton("Overwrite");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final Consumer<String> newThemeAction, modifyThemeAction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static final long serialVersionUID = 2369985550946300976L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Creates a window, where you can choose a name for a new {@link Theme}. <br>
 | 
				
			||||||
 | 
						 * There are two versions of this Window. The first one is responsible for
 | 
				
			||||||
 | 
						 * choosing the name, the second one appears, if the name already exists.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param parent the dialog is launched with its location relative to this {@link SettingsScreen}
 | 
				
			||||||
 | 
						 * @param newThemeAction is executed when a new theme name is entered
 | 
				
			||||||
 | 
						 * @param modifyThemeAction is executed when an existing theme name is entered and confirmed
 | 
				
			||||||
 | 
						 * @since Envoy v0.3-alpha
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public NewThemeScreen(SettingsScreen parent, Consumer<String> newThemeAction, Consumer<String> modifyThemeAction) {
 | 
				
			||||||
 | 
							this.newThemeAction		= newThemeAction;
 | 
				
			||||||
 | 
							this.modifyThemeAction	= modifyThemeAction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							setLocationRelativeTo(parent);
 | 
				
			||||||
 | 
							setTitle("New Theme");
 | 
				
			||||||
 | 
							setModal(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							setDimensions(true);
 | 
				
			||||||
 | 
							setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							getContentPane().setLayout(new BorderLayout());
 | 
				
			||||||
 | 
							standardPanel.setBackground(theme.getBackgroundColor());
 | 
				
			||||||
 | 
							secondaryPanel.setBackground(theme.getBackgroundColor());
 | 
				
			||||||
 | 
							loadStandardContent(theme);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void setDimensions(boolean isStandard) {
 | 
				
			||||||
 | 
							Dimension size = isStandard ? new Dimension(300, 170) : new Dimension(300, 225);
 | 
				
			||||||
 | 
							setPreferredSize(size);
 | 
				
			||||||
 | 
							setMinimumSize(size);
 | 
				
			||||||
 | 
							setMaximumSize(size);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void loadStandardContent(Theme theme) {
 | 
				
			||||||
 | 
							getContentPane().removeAll();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// ContentPane
 | 
				
			||||||
 | 
							GridBagLayout gbl_contentPanel = new GridBagLayout();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							gbl_contentPanel.columnWidths	= new int[] { 1, 1 };
 | 
				
			||||||
 | 
							gbl_contentPanel.rowHeights		= new int[] { 1, 1, 1 };
 | 
				
			||||||
 | 
							gbl_contentPanel.columnWeights	= new double[] { 1, 1 };
 | 
				
			||||||
 | 
							gbl_contentPanel.rowWeights		= new double[] { 1, 1, 1 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							getContentPane().add(standardPanel, BorderLayout.CENTER);
 | 
				
			||||||
 | 
							standardPanel.setLayout(gbl_contentPanel);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// text.setFont(new Font());
 | 
				
			||||||
 | 
							text.setText("Please enter a name for the new Theme");
 | 
				
			||||||
 | 
							text.setAlignmentX(CENTER_ALIGNMENT);
 | 
				
			||||||
 | 
							text.setBackground(theme.getCellColor());
 | 
				
			||||||
 | 
							text.setForeground(theme.getUserNameColor());
 | 
				
			||||||
 | 
							text.setEditable(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_text = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_text.fill		= GridBagConstraints.HORIZONTAL;
 | 
				
			||||||
 | 
							gbc_text.gridx		= 0;
 | 
				
			||||||
 | 
							gbc_text.gridy		= 0;
 | 
				
			||||||
 | 
							gbc_text.gridwidth	= 2;
 | 
				
			||||||
 | 
							gbc_text.insets		= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							standardPanel.add(text, gbc_text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							nameEnterTextArea.setBackground(theme.getCellColor());
 | 
				
			||||||
 | 
							nameEnterTextArea.setForeground(theme.getTypingMessageColor());
 | 
				
			||||||
 | 
							nameEnterTextArea.setText("");
 | 
				
			||||||
 | 
							nameEnterTextArea.setEditable(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_input = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_input.fill		= GridBagConstraints.HORIZONTAL;
 | 
				
			||||||
 | 
							gbc_input.gridx		= 0;
 | 
				
			||||||
 | 
							gbc_input.gridy		= 1;
 | 
				
			||||||
 | 
							gbc_input.gridwidth	= 2;
 | 
				
			||||||
 | 
							gbc_input.insets	= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							standardPanel.add(nameEnterTextArea, gbc_input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							confirmButton.setBackground(theme.getInteractableBackgroundColor());
 | 
				
			||||||
 | 
							confirmButton.setForeground(theme.getInteractableForegroundColor());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_confirmButton = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_confirmButton.gridx		= 0;
 | 
				
			||||||
 | 
							gbc_confirmButton.gridy		= 2;
 | 
				
			||||||
 | 
							gbc_confirmButton.gridwidth	= 2;
 | 
				
			||||||
 | 
							gbc_confirmButton.insets	= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							standardPanel.add(confirmButton, gbc_confirmButton);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							confirmButton.addActionListener((evt) -> {
 | 
				
			||||||
 | 
								if (!nameEnterTextArea.getText().isEmpty()) if (Settings.getInstance().getThemes().containsKey(nameEnterTextArea.getText())) {
 | 
				
			||||||
 | 
									// load other panel
 | 
				
			||||||
 | 
									setDimensions(false);
 | 
				
			||||||
 | 
									loadSecondaryPage(theme);
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									newThemeAction.accept(nameEnterTextArea.getText());
 | 
				
			||||||
 | 
									dispose();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void loadSecondaryPage(Theme theme) {
 | 
				
			||||||
 | 
							// ContentPane
 | 
				
			||||||
 | 
							getContentPane().removeAll();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagLayout gbl_secondaryPanel = new GridBagLayout();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							gbl_secondaryPanel.columnWidths		= new int[] { 1, 1 };
 | 
				
			||||||
 | 
							gbl_secondaryPanel.rowHeights		= new int[] { 1, 1, 1, 1 };
 | 
				
			||||||
 | 
							gbl_secondaryPanel.columnWeights	= new double[] { 1, 1 };
 | 
				
			||||||
 | 
							gbl_secondaryPanel.rowWeights		= new double[] { 1, 1, 1, 1 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							getContentPane().add(secondaryPanel, BorderLayout.CENTER);
 | 
				
			||||||
 | 
							secondaryPanel.setLayout(gbl_secondaryPanel);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// text.setFont(new Font());
 | 
				
			||||||
 | 
							text.setText("Please enter a name for the new Theme");
 | 
				
			||||||
 | 
							text.setAlignmentX(CENTER_ALIGNMENT);
 | 
				
			||||||
 | 
							text.setBackground(theme.getCellColor());
 | 
				
			||||||
 | 
							text.setForeground(theme.getUserNameColor());
 | 
				
			||||||
 | 
							text.setEditable(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_text = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_text.fill		= GridBagConstraints.HORIZONTAL;
 | 
				
			||||||
 | 
							gbc_text.gridx		= 0;
 | 
				
			||||||
 | 
							gbc_text.gridy		= 0;
 | 
				
			||||||
 | 
							gbc_text.gridwidth	= 2;
 | 
				
			||||||
 | 
							gbc_text.insets		= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							secondaryPanel.add(text, gbc_text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							nameEnterTextArea.setBackground(theme.getCellColor());
 | 
				
			||||||
 | 
							nameEnterTextArea.setForeground(theme.getTypingMessageColor());
 | 
				
			||||||
 | 
							nameEnterTextArea.setEditable(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_input = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_input.fill		= GridBagConstraints.HORIZONTAL;
 | 
				
			||||||
 | 
							gbc_input.gridx		= 0;
 | 
				
			||||||
 | 
							gbc_input.gridy		= 1;
 | 
				
			||||||
 | 
							gbc_input.gridwidth	= 2;
 | 
				
			||||||
 | 
							gbc_input.insets	= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							secondaryPanel.add(nameEnterTextArea, gbc_input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							errorText.setText("The name does already exist. Choose another one or overwrite the old theme.");
 | 
				
			||||||
 | 
							errorText.setAlignmentX(CENTER_ALIGNMENT);
 | 
				
			||||||
 | 
							errorText.setBackground(theme.getCellColor());
 | 
				
			||||||
 | 
							errorText.setForeground(theme.getUserNameColor());
 | 
				
			||||||
 | 
							errorText.setEditable(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_errorText = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_errorText.fill		= GridBagConstraints.HORIZONTAL;
 | 
				
			||||||
 | 
							gbc_errorText.gridx		= 0;
 | 
				
			||||||
 | 
							gbc_errorText.gridy		= 2;
 | 
				
			||||||
 | 
							gbc_errorText.gridwidth	= 2;
 | 
				
			||||||
 | 
							gbc_errorText.insets	= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							secondaryPanel.add(errorText, gbc_errorText);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							otherName.setBackground(theme.getInteractableBackgroundColor());
 | 
				
			||||||
 | 
							otherName.setForeground(theme.getInteractableForegroundColor());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_otherName = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_otherName.gridx		= 0;
 | 
				
			||||||
 | 
							gbc_otherName.gridy		= 3;
 | 
				
			||||||
 | 
							gbc_otherName.insets	= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							secondaryPanel.add(otherName, gbc_otherName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							overwrite.setBackground(theme.getInteractableBackgroundColor());
 | 
				
			||||||
 | 
							overwrite.setForeground(theme.getInteractableForegroundColor());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GridBagConstraints gbc_overwrite = new GridBagConstraints();
 | 
				
			||||||
 | 
							gbc_overwrite.gridx		= 1;
 | 
				
			||||||
 | 
							gbc_overwrite.gridy		= 3;
 | 
				
			||||||
 | 
							gbc_overwrite.insets	= new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							secondaryPanel.add(overwrite, gbc_overwrite);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							otherName.addActionListener((evt) -> { setDimensions(true); loadStandardContent(theme); });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							overwrite.addActionListener((evt) -> { modifyThemeAction.accept(nameEnterTextArea.getText()); dispose(); });
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -18,8 +18,18 @@ import javax.swing.JPanel;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
public abstract class SettingsPanel extends JPanel {
 | 
					public abstract class SettingsPanel extends JPanel {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected final SettingsScreen parent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static final long serialVersionUID = -3069212622468626050L;
 | 
						private static final long serialVersionUID = -3069212622468626050L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Initializes a {@link SettingsPanel}.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param parent the {@link SettingsScreen} as a part of which this
 | 
				
			||||||
 | 
						 *               {@link SettingsPanel} is displayed
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public SettingsPanel(SettingsScreen parent) { this.parent = parent; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @return an {@link ActionListener} that should be invoked when the OK button
 | 
						 * @return an {@link ActionListener} that should be invoked when the OK button
 | 
				
			||||||
	 *         is pressed in the {@link SettingsScreen}
 | 
						 *         is pressed in the {@link SettingsScreen}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -93,7 +93,7 @@ public class SettingsScreen extends JDialog {
 | 
				
			|||||||
					if (settingsPanel != null) contentPanel.remove(settingsPanel);
 | 
										if (settingsPanel != null) contentPanel.remove(settingsPanel);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					try {
 | 
										try {
 | 
				
			||||||
						settingsPanel = panels.get(option).getDeclaredConstructor().newInstance();
 | 
											settingsPanel = panels.get(option).getDeclaredConstructor(getClass()).newInstance(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						// Add selected settings panel
 | 
											// Add selected settings panel
 | 
				
			||||||
						contentPanel.add(settingsPanel, gbc_panel);
 | 
											contentPanel.add(settingsPanel, gbc_panel);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,6 @@ import java.awt.*;
 | 
				
			|||||||
import java.awt.event.ActionListener;
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
import java.awt.event.ItemEvent;
 | 
					import java.awt.event.ItemEvent;
 | 
				
			||||||
import java.awt.event.ItemListener;
 | 
					import java.awt.event.ItemListener;
 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.logging.Level;
 | 
					import java.util.logging.Level;
 | 
				
			||||||
import java.util.logging.Logger;
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,10 +32,11 @@ 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 DefaultComboBoxModel<String>	themesModel	= new DefaultComboBoxModel<>(
 | 
				
			||||||
	private JComboBox<String>	themes			= new JComboBox<>(themeArray);
 | 
								Settings.getInstance().getThemes().keySet().toArray(new String[0]));
 | 
				
			||||||
	private Theme				temporaryTheme, selectedTheme;
 | 
						private JComboBox<String>				themes		= new JComboBox<>(themesModel);
 | 
				
			||||||
	private boolean				themeChanged	= false;
 | 
						private Theme							temporaryTheme;
 | 
				
			||||||
 | 
						private boolean							themeChanged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private final Insets insets = new Insets(5, 5, 5, 5);
 | 
						private final Insets insets = new Insets(5, 5, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,9 +48,12 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
	 * the current {@link Theme} and create new themes as part of the
 | 
						 * the current {@link Theme} and create new themes as part of the
 | 
				
			||||||
	 * {@link SettingsScreen}.
 | 
						 * {@link SettingsScreen}.
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param parent the {@link SettingsScreen} as a part of which this
 | 
				
			||||||
 | 
						 *               {@link SettingsPanel} is displayed
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public ThemeCustomizationPanel() {
 | 
						public ThemeCustomizationPanel(SettingsScreen parent) {
 | 
				
			||||||
 | 
							super(parent);
 | 
				
			||||||
		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();
 | 
				
			||||||
@@ -64,16 +67,6 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		themes.setSelectedItem(Settings.getInstance().getCurrentTheme());
 | 
							themes.setSelectedItem(Settings.getInstance().getCurrentTheme());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		themes.addItemListener(new ItemListener() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			@Override
 | 
					 | 
				
			||||||
			public void itemStateChanged(ItemEvent e) {
 | 
					 | 
				
			||||||
				String selectedValue = (String) themes.getSelectedItem();
 | 
					 | 
				
			||||||
				logger.log(Level.FINEST, selectedValue);
 | 
					 | 
				
			||||||
				selectedTheme = Settings.getInstance().getThemes().get(selectedValue);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		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;
 | 
				
			||||||
@@ -106,45 +99,54 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
		add(colorsPanel, gbc_colorsPanel);
 | 
							add(colorsPanel, gbc_colorsPanel);
 | 
				
			||||||
		colorsPanel.setBackground(theme.getCellColor());
 | 
							colorsPanel.setBackground(theme.getCellColor());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Apply theme upon selection
 | 
				
			||||||
 | 
							themes.addItemListener(new ItemListener() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								@Override
 | 
				
			||||||
 | 
								public void itemStateChanged(ItemEvent e) {
 | 
				
			||||||
 | 
									String selectedValue = (String) themes.getSelectedItem();
 | 
				
			||||||
 | 
									logger.log(Level.FINEST, "Selected theme: " + selectedValue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									final Theme currentTheme = Settings.getInstance().getTheme(selectedValue);
 | 
				
			||||||
 | 
									Settings.getInstance().setCurrentTheme(selectedValue);
 | 
				
			||||||
 | 
									EventBus.getInstance().dispatch(new ThemeChangeEvent(currentTheme));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Apply current theme
 | 
							// Apply current theme
 | 
				
			||||||
		applyTheme(theme);
 | 
							applyTheme(theme);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Respond to theme changes
 | 
							// Respond to theme changes
 | 
				
			||||||
		EventBus.getInstance().register(ThemeChangeEvent.class, (evt) -> applyTheme(((ThemeChangeEvent) evt).get()));
 | 
							EventBus.getInstance()
 | 
				
			||||||
 | 
								.register(ThemeChangeEvent.class,
 | 
				
			||||||
 | 
										(evt) -> {
 | 
				
			||||||
 | 
											final Theme currentTheme = ((ThemeChangeEvent) evt).get();
 | 
				
			||||||
 | 
											temporaryTheme = new Theme("temporaryTheme", currentTheme);
 | 
				
			||||||
 | 
											applyTheme(currentTheme);
 | 
				
			||||||
 | 
										});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public ActionListener getOkButtonAction() {
 | 
						public ActionListener getOkButtonAction() {
 | 
				
			||||||
		return (evt) -> {
 | 
							return (evt) -> {
 | 
				
			||||||
			if (themeChanged) {
 | 
								if (themeChanged) {
 | 
				
			||||||
				try {
 | 
									new NewThemeScreen(parent, (name) -> {
 | 
				
			||||||
					String name = JOptionPane.showInputDialog("Enter a name for the new theme");
 | 
										// Create 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[themeArray.length - 1]	= Settings.getInstance().getThemes().get(name).getThemeName();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
					temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
 | 
										// Add new theme name to combo box
 | 
				
			||||||
 | 
										themesModel.addElement(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					themes.addItem(themeArray[themeArray.length - 1]);
 | 
										// Select new theme name
 | 
				
			||||||
					themes.setSelectedIndex(themeArray.length - 1);
 | 
										themes.setSelectedIndex(themesModel.getSize() - 1);
 | 
				
			||||||
 | 
									}, (name) -> {
 | 
				
			||||||
				} catch (Exception e) {
 | 
										// Modify theme
 | 
				
			||||||
					logger.info("New theme couldn't be created! " + e);
 | 
										Settings.getInstance().getThemes().replace(name, new Theme(name, temporaryTheme));
 | 
				
			||||||
					e.printStackTrace();
 | 
										themes.setSelectedItem(name);
 | 
				
			||||||
				}
 | 
									}).setVisible(true);
 | 
				
			||||||
				themeChanged = false;
 | 
									themeChanged = false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					 | 
				
			||||||
			Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
 | 
					 | 
				
			||||||
			logger.log(Level.FINER, "Setting theme: " + selectedTheme.getThemeName());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			final Theme currentTheme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
 | 
					 | 
				
			||||||
			updateColorVariables(currentTheme);
 | 
					 | 
				
			||||||
			EventBus.getInstance().dispatch(new ThemeChangeEvent(currentTheme));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			revalidate();
 | 
					 | 
				
			||||||
			repaint();
 | 
					 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -157,13 +159,16 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
		themes.setBackground(theme.getInteractableBackgroundColor());
 | 
							themes.setBackground(theme.getInteractableBackgroundColor());
 | 
				
			||||||
		themes.setForeground(theme.getInteractableForegroundColor());
 | 
							themes.setForeground(theme.getInteractableForegroundColor());
 | 
				
			||||||
		colorsPanel.setBackground(theme.getCellColor());
 | 
							colorsPanel.setBackground(theme.getCellColor());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Color panel
 | 
				
			||||||
 | 
							updateColorVariables(theme);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							revalidate();
 | 
				
			||||||
 | 
							repaint();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private void updateColorVariables(Theme theme) {
 | 
						private void updateColorVariables(Theme theme) {
 | 
				
			||||||
		temporaryTheme = new Theme("temporaryTheme", theme);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		colorsPanel.removeAll();
 | 
							colorsPanel.removeAll();
 | 
				
			||||||
 | 
					 | 
				
			||||||
		buildCustomizeElements(theme);
 | 
							buildCustomizeElements(theme);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -173,7 +178,7 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
		buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", "interactableForegroundColor", 3);
 | 
							buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", "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", "dateColorChat", 6);
 | 
				
			||||||
		buildCustomizeElement(theme, theme.getSelectionColor(), "Selection", "selectionColor", 7);
 | 
							buildCustomizeElement(theme, theme.getSelectionColor(), "Selection", "selectionColor", 7);
 | 
				
			||||||
		buildCustomizeElement(theme, theme.getTypingMessageColor(), "Typing Message", "typingMessageColor", 8);
 | 
							buildCustomizeElement(theme, theme.getTypingMessageColor(), "Typing Message", "typingMessageColor", 8);
 | 
				
			||||||
		buildCustomizeElement(theme, theme.getUserNameColor(), "User Names", "userNameColor", 9);
 | 
							buildCustomizeElement(theme, theme.getUserNameColor(), "User Names", "userNameColor", 9);
 | 
				
			||||||
@@ -193,21 +198,15 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
		button.setPreferredSize(new Dimension(25, 25));
 | 
							button.setPreferredSize(new Dimension(25, 25));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		button.addActionListener((evt) -> {
 | 
							button.addActionListener((evt) -> {
 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
			java.awt.Color c = JColorChooser.showDialog(null, "Choose a color", color);
 | 
								java.awt.Color c = JColorChooser.showDialog(null, "Choose a color", color);
 | 
				
			||||||
				Color newColor = new Color(c.getRGB());
 | 
								if (c != null) {
 | 
				
			||||||
				if (newColor.getRGB() != color.getRGB()) {
 | 
									Color newColor = new Color(c);
 | 
				
			||||||
					logger.log(Level.FINEST, "New Color: " + String.valueOf(color.getRGB()));
 | 
									if (!color.equals(newColor)) {
 | 
				
			||||||
					// TODO: When Theme changed in same settings screen, color variable doesn't
 | 
										logger.log(Level.FINEST, "New Color: " + newColor);
 | 
				
			||||||
					// update
 | 
					 | 
				
			||||||
					temporaryTheme.setColor(colorName, newColor);
 | 
										temporaryTheme.setColor(colorName, newColor);
 | 
				
			||||||
					themeChanged = true;
 | 
										themeChanged = true;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				button.setBackground(newColor);
 | 
									button.setBackground(newColor);
 | 
				
			||||||
 | 
					 | 
				
			||||||
			} catch (Exception e) {
 | 
					 | 
				
			||||||
				logger.info("An error occured while opening Color Chooser: " + e);
 | 
					 | 
				
			||||||
				e.printStackTrace();
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user