Revised requested changes besides 2 (please change by yourself)

This commit is contained in:
DieGurke 2019-12-07 17:58:59 +01:00
parent c078c33d8b
commit bafadca4cb
6 changed files with 180 additions and 35 deletions

View File

@ -121,14 +121,12 @@ public class Config {
public void setLocalDB(File localDB) { this.localDB = localDB; }
/**
*
* @return the current time (milliseconds) that is waited between Syncs
* @since Envoy v0.1-alpha
*/
public int getSyncTimeout() { return syncTimeout; }
/**
*
* @param syncTimeout sets the time (milliseconds) during which Sync waits
* @since Envoy v0.1-alpha
*/

View File

@ -89,6 +89,12 @@ public class Settings {
Color.black, Color.black));
}
/**
* updates prefs when save button is clicked
*
* @throws IOException
* @since Envoy v0.2-alpha
*/
public void save() throws IOException{
prefs.put("username", getUsername());
prefs.put("email", getEmail());
@ -102,13 +108,29 @@ public class Settings {
}
}
/**
* adds new theme to the theme map and sets current theme to the new theme.
*
* @param theme
* @since Envoy v0.2-alpha
*/
public void addNewThemeToMap(Theme theme) {
settings.getThemes().put(theme.getThemeName(), theme);
currentTheme = theme.getThemeName();
}
/**
* @return {@link currentTheme}
* @since Envoy v0.2-alpha
*/
public String getCurrentTheme() { return currentTheme; }
/**
* Sets the currentTheme
*
* @param themeName
* @since Envoy v0.2-alpha
*/
public void setCurrentTheme(String themeName) { currentTheme = themeName; }
/**
@ -151,7 +173,17 @@ public class Settings {
*/
public void setEnterToSend(boolean enterToSend) { this.enterToSend = enterToSend; }
/**
* @return {@link themes} map
* @since Envoy v0.2-alpha
*/
public Map<String, Theme> getThemes() { return themes; }
/**
* Sets {@link themes}
*
* @param themes
* @since Envoy v0.2-alpha
*/
public void setThemes(Map<String, Theme> themes) { this.themes = themes; }
}

View File

@ -1,6 +1,5 @@
package envoy.client.ui;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Font;
import java.awt.GridBagConstraints;
@ -136,6 +135,7 @@ public class ChatWindow extends JFrame {
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0)
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
postMessage(messageList);
}
}
});
// Checks for changed Message
@ -245,6 +245,7 @@ public class ChatWindow extends JFrame {
contentPane.revalidate();
}
/**
* Used to immediately reload the ChatWindow when settings were changed.
*
@ -282,19 +283,22 @@ public class ChatWindow extends JFrame {
userList.setSelectionBackground(theme.getSelectionColor());
userList.setForeground(theme.getUserNameColor());
userList.setBackground(theme.getCellColor());
}
private void postMessage(JList<Message> messageList) {
if (!client.hasRecipient()) {
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(this,
"Please select a recipient!",
"Cannot send message",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!messageEnterTextArea.getText().isEmpty()) try {
// Create and send message object
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient());
final Message message = localDB.createMessage(messageEnterTextArea.getText(),
currentChat.getRecipient().getID());
currentChat.appendMessage(message);
messageList.setModel(currentChat.getModel());
@ -344,7 +348,8 @@ public class ChatWindow extends JFrame {
new Thread(() -> {
// Synchronize
localDB.applySync(client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID())));
localDB.applySync(
client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID())));
// Process unread messages
localDB.addUnreadMessagesToLocalDB();
@ -354,7 +359,8 @@ public class ChatWindow extends JFrame {
readCurrentChat();
// Update UI
SwingUtilities.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
SwingUtilities
.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
}).start();
}).start();
}
@ -371,3 +377,4 @@ public class ChatWindow extends JFrame {
*/
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
}

View File

@ -11,6 +11,7 @@ import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Arrays;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
@ -24,6 +25,7 @@ import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import envoy.client.LocalDB;
import envoy.client.Settings;
/**
@ -64,6 +66,8 @@ public class SettingsScreen extends JDialog {
private boolean colorChanged = false;
private Theme temporaryTheme;
private static final Logger logger = Logger.getLogger(LocalDB.class.getSimpleName());
private static SettingsScreen settingsScreen;
// TODO: Add a JPanel with all the Information necessary:
@ -89,8 +93,7 @@ public class SettingsScreen extends JDialog {
* @since Envoy v0.1-alpha
*/
private SettingsScreen() {
System.out.println(Settings.getInstance().getCurrentTheme());
logger.info(Settings.getInstance().getCurrentTheme());
setBounds(10, 10, 450, 650);
getContentPane().setLayout(new BorderLayout());
@ -98,7 +101,8 @@ public class SettingsScreen extends JDialog {
createNewThemeButton.setEnabled(false);
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
// Content pane
GridBagLayout gbl_contentPanel = new GridBagLayout();
@ -147,13 +151,10 @@ public class SettingsScreen extends JDialog {
gbc_optionsList.insets = new Insets(space, space, space, space);
optionsListModel.addElement("Color Themes");
options.setModel(optionsListModel);
contentPanel.add(options, gbc_optionsList);
// Theme content
gbc_themeContent = new GridBagConstraints();
gbc_themeContent.fill = GridBagConstraints.BOTH;
gbc_themeContent.gridx = 1;
@ -206,7 +207,13 @@ public class SettingsScreen extends JDialog {
theme.getBackgroundColor(),
"Background",
1);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 2);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getCellColor(),
"Cells",
2);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
@ -221,11 +228,41 @@ public class SettingsScreen extends JDialog {
theme.getInteractableBackgroundColor(),
"Interactable Background",
4);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", 5);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", 6);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 7);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", 8);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", 9);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getMessageColorChat(),
"Messages Chat",
5);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getDateColorChat(),
"Date Chat",
6);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getSelectionColor(),
"Selection",
7);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getTypingMessageColor(),
"Typing Message",
8);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getUserNameColor(),
"User Names",
9);
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
@ -246,14 +283,16 @@ public class SettingsScreen extends JDialog {
String s = JOptionPane.showInputDialog("Enter a name for the new theme");
System.out.println(s);
Settings.getInstance()
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(), temporaryTheme.getCellColor(),
temporaryTheme.getInteractableForegroundColor(), temporaryTheme.getInteractableBackgroundColor(),
temporaryTheme.getMessageColorChat(), temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(),
temporaryTheme.getCellColor(), temporaryTheme.getInteractableForegroundColor(),
temporaryTheme.getInteractableBackgroundColor(), temporaryTheme.getMessageColorChat(),
temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
createNewThemeButton.setEnabled(false);
themes.addItem(themeArray[themeArray.length - 1]);
@ -264,7 +303,7 @@ public class SettingsScreen extends JDialog {
// TODO: Create new Theme
} catch (Exception e) {
System.err.println("New theme couldn't be created! " + e);
logger.info("New theme couldn't be created! " + e);
e.printStackTrace();
}
});
@ -326,7 +365,7 @@ public class SettingsScreen extends JDialog {
revalidate();
repaint();
} catch (Exception e) {
System.err.println("Something went wrong when changing the setting");
logger.info("Something went wrong when changing the setting");
settingsScreen.dispose();
}
});
@ -373,12 +412,21 @@ public class SettingsScreen extends JDialog {
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableForegroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getInteractableForegroundColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getInteractableBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getTypingMessageColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getTypingMessageColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
colorsPanel.removeAll();
@ -465,7 +513,8 @@ public class SettingsScreen extends JDialog {
private void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); }
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color, String name, int yIndex) {
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color,
String name, int yIndex) {
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
textPane.setBackground(theme.getBackgroundColor());
textPane.setForeground(theme.getUserNameColor());
@ -497,7 +546,7 @@ public class SettingsScreen extends JDialog {
}
} catch (Exception e) {
System.err.println("An error occured while opening Color Chooser: " + e);
logger.info("An error occured while opening Color Chooser: " + e);
e.printStackTrace();
}
});

View File

@ -4,7 +4,6 @@ import java.awt.Color;
import java.io.Serializable;
/**
*
* Project: <strong>envoy-client</strong><br>
* File: <strong>Theme.java</strong><br>
* Created: <strong>23 Nov 2019</strong><br>
@ -50,26 +49,70 @@ public class Theme implements Serializable {
other.typingMessageColor, other.userNameColor);
}
/**
* @return name of the theme
* @since Envoy v0.2-alpha
*/
public String getThemeName() { return themeName; }
/**
* @return interactableForegroundColor
* @since Envoy v0.2-alpha
*/
public Color getInteractableForegroundColor() { return interactableForegroundColor; }
/**
* @return messageColorChat
* @since Envoy v0.2-alpha
*/
public Color getMessageColorChat() { return messageColorChat; }
/**
* @return dateColorChat
* @since Envoy v0.2-alpha
*/
public Color getDateColorChat() { return dateColorChat; }
/**
* @return selectionColor
* @since Envoy v0.2-alpha
*/
public Color getSelectionColor() { return selectionColor; }
/**
* @return typingMessageColor
* @since Envoy v0.2-alpha
*/
public Color getTypingMessageColor() { return typingMessageColor; }
/**
* @return backgroundColor
* @since Envoy v0.2-alpha
*/
public Color getBackgroundColor() { return backgroundColor; }
/**
* @return cellColor
* @since Envoy v0.2-alpha
*/
public Color getCellColor() { return cellColor; }
/**
* @return interactableBackgroundColor
* @since Envoy v0.2-alpha
*/
public Color getInteractableBackgroundColor() { return interactableBackgroundColor; }
/**
* @return userNameColor
* @since Envoy v0.2-alpha
*/
public Color getUserNameColor() { return userNameColor; }
/**
* @return a color array containing all colors of this theme
* @since Envoy v0.2-alpha
*/
public Color[] getAllColors() {
Color[] c = new Color[9];
c[0] = backgroundColor;
@ -85,6 +128,24 @@ public class Theme implements Serializable {
return c;
}
/**
* Sets the a specific {@link Color} in this theme to a new {@link Color}
*
* @param index - index of the color </br>
* 0 = backgroundColor </br>
* 1 = cellColor </br>
* 2 = interactableForegroundColor </br>
* 3 = interactableBackgroundColor </br>
* 4 = messageColorChat </br>
* 5 = dateColorChat </br>
* 6 = selectionColor </br>
* 7 = typingMessageColor </br>
* 8 = userNameColor </br>
* </br>
*
* @param newColor - new {@link Color} to be set
* @since Envoy 0.2-alpha
*/
public void setColor(int index, Color newColor) {
switch (index) {
case 0:
@ -114,7 +175,6 @@ public class Theme implements Serializable {
case 8:
this.userNameColor = newColor;
break;
}
}

View File

@ -45,7 +45,6 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
// Getting the UserNameColor of the current theme
String textColor = null;
textColor = toHex(
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
switch (status) {