Merge pull request #67 from informatik-ag-ngl/f/UserFriendlySettings
User Friendly Settings
This commit is contained in:
		@@ -33,11 +33,11 @@ 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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -51,7 +51,8 @@ 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();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -76,23 +77,22 @@ 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.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	= insets;
 | 
							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.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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -105,37 +105,8 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
		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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -146,6 +117,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());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -164,11 +156,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());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -178,20 +167,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);
 | 
				
			||||||
@@ -220,7 +204,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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -239,7 +223,6 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		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;
 | 
				
			||||||
@@ -250,5 +233,7 @@ public class ThemeCustomizationPanel extends SettingsPanel {
 | 
				
			|||||||
		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