commit
a387ec518e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/target/
|
/target/
|
||||||
/localDB/
|
/localDB/
|
||||||
|
/themes.ser
|
||||||
|
@ -134,8 +134,8 @@ public class Client {
|
|||||||
* their updated UserStatus to the client.) <br>
|
* their updated UserStatus to the client.) <br>
|
||||||
*
|
*
|
||||||
* @param userId the id of the {@link Client} who sends the {@link Sync}
|
* @param userId the id of the {@link Client} who sends the {@link Sync}
|
||||||
* @param sync the {@link Sync} to send
|
* @param sync the sync object (yet to be converted from java class to sync.xml)
|
||||||
* @return a sync
|
* @return a returnSync.xml file
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public Sync sendSync(long userId, Sync sync) {
|
public Sync sendSync(long userId, Sync sync) {
|
||||||
|
@ -63,6 +63,7 @@ public class Config {
|
|||||||
case "--localDB":
|
case "--localDB":
|
||||||
case "-db":
|
case "-db":
|
||||||
localDB = new File(args[++i]);
|
localDB = new File(args[++i]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +120,16 @@ public class Config {
|
|||||||
**/
|
**/
|
||||||
public void setLocalDB(File localDB) { this.localDB = localDB; }
|
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; }
|
public int getSyncTimeout() { return syncTimeout; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param syncTimeout sets the time (milliseconds) during which Sync waits
|
||||||
|
* @since Envoy v0.1-alpha
|
||||||
|
*/
|
||||||
public void setSyncTimeout(int syncTimeout) { this.syncTimeout = syncTimeout; }
|
public void setSyncTimeout(int syncTimeout) { this.syncTimeout = syncTimeout; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -112,14 +112,14 @@ public class LocalDB {
|
|||||||
* Creates a {@link Message} object serializable to XML.
|
* Creates a {@link Message} object serializable to XML.
|
||||||
*
|
*
|
||||||
* @param textContent The content (text) of the message
|
* @param textContent The content (text) of the message
|
||||||
* @param recipient The recipient of the message
|
* @param recipientID The recipient of the message
|
||||||
* @return prepared {@link Message} object
|
* @return prepared {@link Message} object
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public Message createMessage(String textContent, User recipient) {
|
public Message createMessage(String textContent, long recipientID) {
|
||||||
Message.Metadata metaData = objectFactory.createMessageMetadata();
|
Message.Metadata metaData = objectFactory.createMessageMetadata();
|
||||||
metaData.setSender(sender.getID());
|
metaData.setSender(sender.getID());
|
||||||
metaData.setRecipient(recipient.getID());
|
metaData.setRecipient(recipientID);
|
||||||
metaData.setState(MessageState.WAITING);
|
metaData.setState(MessageState.WAITING);
|
||||||
metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString()));
|
metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString()));
|
||||||
|
|
||||||
|
189
src/main/java/envoy/client/Settings.java
Normal file
189
src/main/java/envoy/client/Settings.java
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
package envoy.client;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
import envoy.client.ui.Theme;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: <strong>envoy-client</strong><br>
|
||||||
|
* File: <strong>Settings.java</strong><br>
|
||||||
|
* Created: <strong>11 Nov 2019</strong><br>
|
||||||
|
*
|
||||||
|
* @author Leon Hofmeister
|
||||||
|
* @author Maximilian Käfer
|
||||||
|
* @author Kai S. K. Engelbart
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public class Settings {
|
||||||
|
|
||||||
|
// Actual settings accessible by the rest of the application
|
||||||
|
private String username;
|
||||||
|
private String email;
|
||||||
|
private boolean enterToSend = true;
|
||||||
|
private Map<String, Theme> themes;
|
||||||
|
private String currentTheme;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required to save the settings.
|
||||||
|
*/
|
||||||
|
private Preferences prefs = Preferences.userNodeForPackage(Settings.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User-defined themes are stored inside this file.
|
||||||
|
*/
|
||||||
|
private File themeFile = new File("themes.ser");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton instance of this class.
|
||||||
|
*/
|
||||||
|
private static Settings settings = new Settings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The way to instantiate the settings.
|
||||||
|
* Is set to private to deny other instances of that object.
|
||||||
|
*
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
private Settings() { load(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to ensure that there is only one instance of Settings.
|
||||||
|
*
|
||||||
|
* @return the instance of Settings
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public static Settings getInstance() { return settings; }
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void load() {
|
||||||
|
setUsername(prefs.get("username", ""));
|
||||||
|
setEmail(prefs.get("email", ""));
|
||||||
|
setEnterToSend(prefs.getBoolean("enterToSend", true));
|
||||||
|
setCurrentTheme(prefs.get("theme", "dark"));
|
||||||
|
|
||||||
|
// Load themes from theme file
|
||||||
|
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(themeFile))) {
|
||||||
|
Object obj = in.readObject();
|
||||||
|
if(obj instanceof HashMap) themes = (Map<String, Theme>) obj;
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
themes = new HashMap<>();
|
||||||
|
currentTheme = "dark";
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load standard themes not defined in the themes file
|
||||||
|
themes.put("dark",
|
||||||
|
new Theme("dark", Color.black, Color.darkGray, Color.white, Color.blue, Color.white, Color.orange, Color.blue, Color.white,
|
||||||
|
Color.white));
|
||||||
|
themes.put("light",
|
||||||
|
new Theme("light", new Color(235, 235, 235), Color.white, Color.white, Color.darkGray, Color.black, Color.orange, Color.darkGray,
|
||||||
|
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());
|
||||||
|
prefs.put("theme", currentTheme);
|
||||||
|
prefs.putBoolean("enterToSend", isEnterToSend());
|
||||||
|
|
||||||
|
// Save themes to theme file
|
||||||
|
themeFile.createNewFile();
|
||||||
|
try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(themeFile))) {
|
||||||
|
out.writeObject(themes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the user name
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public String getUsername() { return username; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param username the user name to set
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public void setUsername(String username) { this.username = username; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the email associated with that user.
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public String getEmail() { return email; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param email the email to set
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public void setEmail(String email) { this.email = email; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true, if "enter" suffices to send a message, else it has to be "ctrl"
|
||||||
|
* + "enter"
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public boolean isEnterToSend() { return enterToSend; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change mode of posting a message via Keystroke.
|
||||||
|
*
|
||||||
|
* @param enterToSend if true, "enter" suffices to send a message, <br>
|
||||||
|
* else it has to be "ctrl" + "enter"
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
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; }
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.ComponentOrientation;
|
import java.awt.ComponentOrientation;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
@ -33,6 +32,7 @@ import envoy.client.Chat;
|
|||||||
import envoy.client.Client;
|
import envoy.client.Client;
|
||||||
import envoy.client.Config;
|
import envoy.client.Config;
|
||||||
import envoy.client.LocalDB;
|
import envoy.client.LocalDB;
|
||||||
|
import envoy.client.Settings;
|
||||||
import envoy.schema.Message;
|
import envoy.schema.Message;
|
||||||
import envoy.schema.Sync;
|
import envoy.schema.Sync;
|
||||||
import envoy.schema.User;
|
import envoy.schema.User;
|
||||||
@ -51,15 +51,22 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 6865098428255463649L;
|
private static final long serialVersionUID = 6865098428255463649L;
|
||||||
|
|
||||||
private JPanel contentPane = new JPanel();
|
// user specific objects
|
||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
private LocalDB localDB;
|
private LocalDB localDB;
|
||||||
|
// GUI components
|
||||||
|
private JPanel contentPane = new JPanel();
|
||||||
|
private JTextArea messageEnterTextArea = new JTextArea();
|
||||||
private JList<User> userList = new JList<>();
|
private JList<User> userList = new JList<>();
|
||||||
private Chat currentChat;
|
private Chat currentChat;
|
||||||
|
private JList<Message> messageList = new JList<>();
|
||||||
|
private JScrollPane scrollPane = new JScrollPane();
|
||||||
|
private JTextPane textPane = new JTextPane();
|
||||||
|
// private JCheckBox jCbChangeMode;
|
||||||
|
private JButton postButton = new JButton("Post");
|
||||||
|
private JButton settingsButton = new JButton("Settings");
|
||||||
|
|
||||||
private JTextArea messageEnterTextArea;
|
private static int space = 4;
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ChatWindow.class.getSimpleName());
|
private static final Logger logger = Logger.getLogger(ChatWindow.class.getSimpleName());
|
||||||
|
|
||||||
@ -80,6 +87,7 @@ public class ChatWindow extends JFrame {
|
|||||||
public void windowClosing(WindowEvent evt) {
|
public void windowClosing(WindowEvent evt) {
|
||||||
try {
|
try {
|
||||||
localDB.saveToLocalDB();
|
localDB.saveToLocalDB();
|
||||||
|
Settings.getInstance().save();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
logger.log(Level.WARNING, "Unable to save the messages", e1);
|
logger.log(Level.WARNING, "Unable to save the messages", e1);
|
||||||
@ -87,9 +95,7 @@ public class ChatWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
contentPane.setBackground(new Color(0, 0, 0));
|
contentPane.setBorder(new EmptyBorder(space, space, space, space));
|
||||||
contentPane.setForeground(Color.white);
|
|
||||||
contentPane.setBorder(new EmptyBorder(0, 5, 0, 0));
|
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||||
gbl_contentPane.columnWidths = new int[] { 1, 1, 1 };
|
gbl_contentPane.columnWidths = new int[] { 1, 1, 1 };
|
||||||
@ -98,25 +104,16 @@ public class ChatWindow extends JFrame {
|
|||||||
gbl_contentPane.rowWeights = new double[] { 0.05, 1.0, 0.07 };
|
gbl_contentPane.rowWeights = new double[] { 0.05, 1.0, 0.07 };
|
||||||
contentPane.setLayout(gbl_contentPane);
|
contentPane.setLayout(gbl_contentPane);
|
||||||
|
|
||||||
JList<Message> messageList = new JList<>();
|
|
||||||
messageList.setCellRenderer(new MessageListRenderer());
|
messageList.setCellRenderer(new MessageListRenderer());
|
||||||
|
|
||||||
messageList.setFocusTraversalKeysEnabled(false);
|
messageList.setFocusTraversalKeysEnabled(false);
|
||||||
messageList.setSelectionForeground(new Color(255, 255, 255));
|
|
||||||
messageList.setSelectionBackground(new Color(102, 0, 153));
|
|
||||||
messageList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
|
messageList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
|
||||||
messageList.setForeground(new Color(255, 255, 255));
|
|
||||||
messageList.setBackground(new Color(51, 51, 51));
|
|
||||||
|
|
||||||
DefaultListModel<Message> messageListModel = new DefaultListModel<>();
|
DefaultListModel<Message> messageListModel = new DefaultListModel<>();
|
||||||
messageList.setModel(messageListModel);
|
messageList.setModel(messageListModel);
|
||||||
messageList.setFont(new Font("Arial", Font.PLAIN, 17));
|
messageList.setFont(new Font("Arial", Font.PLAIN, 17));
|
||||||
messageList.setFixedCellHeight(60);
|
messageList.setFixedCellHeight(60);
|
||||||
messageList.setBorder(new EmptyBorder(5, 5, 5, 5));
|
messageList.setBorder(new EmptyBorder(space, space, space, space));
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane();
|
|
||||||
scrollPane.setForeground(new Color(0, 0, 0));
|
|
||||||
scrollPane.setBackground(new Color(51, 51, 51));
|
|
||||||
scrollPane.setViewportView(messageList);
|
scrollPane.setViewportView(messageList);
|
||||||
scrollPane.setBorder(null);
|
scrollPane.setBorder(null);
|
||||||
|
|
||||||
@ -126,61 +123,51 @@ public class ChatWindow extends JFrame {
|
|||||||
gbc_scrollPane.gridx = 1;
|
gbc_scrollPane.gridx = 1;
|
||||||
gbc_scrollPane.gridy = 1;
|
gbc_scrollPane.gridy = 1;
|
||||||
|
|
||||||
gbc_scrollPane.insets = new Insets(0, 10, 10, 10);
|
gbc_scrollPane.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
contentPane.add(scrollPane, gbc_scrollPane);
|
contentPane.add(scrollPane, gbc_scrollPane);
|
||||||
|
|
||||||
// Message enter field
|
// Message enter field
|
||||||
messageEnterTextArea = new JTextArea();
|
|
||||||
messageEnterTextArea.addKeyListener(new KeyAdapter() {
|
messageEnterTextArea.addKeyListener(new KeyAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER
|
if (e.getKeyCode() == KeyEvent.VK_ENTER
|
||||||
&& ((SettingsScreen.enterToSend && e.getModifiersEx() == 0) || (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK)))
|
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0)
|
||||||
|
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
||||||
postMessage(messageList);
|
postMessage(messageList);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Checks for changed Message
|
// Checks for changed Message
|
||||||
messageEnterTextArea.setWrapStyleWord(true);
|
messageEnterTextArea.setWrapStyleWord(true);
|
||||||
messageEnterTextArea.setCaretColor(new Color(255, 255, 255));
|
|
||||||
messageEnterTextArea.setForeground(new Color(255, 255, 255));
|
|
||||||
messageEnterTextArea.setBackground(new Color(51, 51, 51));
|
|
||||||
messageEnterTextArea.setLineWrap(true);
|
messageEnterTextArea.setLineWrap(true);
|
||||||
messageEnterTextArea.setBorder(null);
|
messageEnterTextArea.setBorder(null);
|
||||||
messageEnterTextArea.setFont(new Font("Arial", Font.PLAIN, 17));
|
messageEnterTextArea.setFont(new Font("Arial", Font.PLAIN, 17));
|
||||||
messageEnterTextArea.setBorder(new EmptyBorder(5, 5, 5, 5));
|
messageEnterTextArea.setBorder(new EmptyBorder(space, space, space, space));
|
||||||
|
|
||||||
GridBagConstraints gbc_messageEnterTextfield = new GridBagConstraints();
|
GridBagConstraints gbc_messageEnterTextfield = new GridBagConstraints();
|
||||||
gbc_messageEnterTextfield.fill = GridBagConstraints.BOTH;
|
gbc_messageEnterTextfield.fill = GridBagConstraints.BOTH;
|
||||||
gbc_messageEnterTextfield.gridx = 1;
|
gbc_messageEnterTextfield.gridx = 1;
|
||||||
gbc_messageEnterTextfield.gridy = 2;
|
gbc_messageEnterTextfield.gridy = 2;
|
||||||
|
|
||||||
gbc_messageEnterTextfield.insets = new Insets(10, 10, 10, 10);
|
gbc_messageEnterTextfield.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
contentPane.add(messageEnterTextArea, gbc_messageEnterTextfield);
|
contentPane.add(messageEnterTextArea, gbc_messageEnterTextfield);
|
||||||
|
|
||||||
// Post Button
|
// Post Button
|
||||||
JButton postButton = new JButton("Post");
|
|
||||||
postButton.setForeground(new Color(255, 255, 255));
|
|
||||||
postButton.setBackground(new Color(102, 51, 153));
|
|
||||||
postButton.setBorderPainted(false);
|
postButton.setBorderPainted(false);
|
||||||
|
|
||||||
GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints();
|
GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints();
|
||||||
|
|
||||||
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
|
gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH;
|
||||||
gbc_moveSelectionPostButton.gridx = 2;
|
gbc_moveSelectionPostButton.gridx = 2;
|
||||||
gbc_moveSelectionPostButton.gridy = 2;
|
gbc_moveSelectionPostButton.gridy = 2;
|
||||||
|
|
||||||
gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10);
|
gbc_moveSelectionPostButton.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
postButton.addActionListener((evt) -> { postMessage(messageList); });
|
postButton.addActionListener((evt) -> { postMessage(messageList); });
|
||||||
contentPane.add(postButton, gbc_moveSelectionPostButton);
|
contentPane.add(postButton, gbc_moveSelectionPostButton);
|
||||||
|
|
||||||
// Settings Button
|
// Settings Button
|
||||||
JButton settingsButton = new JButton("Settings");
|
|
||||||
settingsButton.setForeground(new Color(255, 255, 255));
|
|
||||||
settingsButton.setBackground(new Color(102, 51, 153));
|
|
||||||
settingsButton.setBorderPainted(false);
|
settingsButton.setBorderPainted(false);
|
||||||
|
|
||||||
GridBagConstraints gbc_moveSelectionSettingsButton = new GridBagConstraints();
|
GridBagConstraints gbc_moveSelectionSettingsButton = new GridBagConstraints();
|
||||||
@ -189,11 +176,12 @@ public class ChatWindow extends JFrame {
|
|||||||
gbc_moveSelectionSettingsButton.gridx = 2;
|
gbc_moveSelectionSettingsButton.gridx = 2;
|
||||||
gbc_moveSelectionSettingsButton.gridy = 0;
|
gbc_moveSelectionSettingsButton.gridy = 0;
|
||||||
|
|
||||||
gbc_moveSelectionSettingsButton.insets = new Insets(10, 10, 10, 10);
|
gbc_moveSelectionSettingsButton.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
settingsButton.addActionListener((evt) -> {
|
settingsButton.addActionListener((evt) -> {
|
||||||
try {
|
try {
|
||||||
SettingsScreen.open(localDB.getUser().getName());
|
SettingsScreen.open();
|
||||||
|
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SettingsScreen.open();
|
SettingsScreen.open();
|
||||||
logger.log(Level.WARNING, "An error occured while opening the settings screen", e);
|
logger.log(Level.WARNING, "An error occured while opening the settings screen", e);
|
||||||
@ -203,18 +191,15 @@ public class ChatWindow extends JFrame {
|
|||||||
contentPane.add(settingsButton, gbc_moveSelectionSettingsButton);
|
contentPane.add(settingsButton, gbc_moveSelectionSettingsButton);
|
||||||
|
|
||||||
// Partner name display
|
// Partner name display
|
||||||
JTextPane textPane = new JTextPane();
|
|
||||||
textPane.setBackground(new Color(0, 0, 0));
|
|
||||||
textPane.setForeground(new Color(255, 255, 255));
|
|
||||||
|
|
||||||
textPane.setFont(new Font("Arial", Font.PLAIN, 20));
|
textPane.setFont(new Font("Arial", Font.PLAIN, 20));
|
||||||
|
textPane.setEditable(false);
|
||||||
|
|
||||||
GridBagConstraints gbc_partnerName = new GridBagConstraints();
|
GridBagConstraints gbc_partnerName = new GridBagConstraints();
|
||||||
gbc_partnerName.fill = GridBagConstraints.HORIZONTAL;
|
gbc_partnerName.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_partnerName.gridx = 1;
|
gbc_partnerName.gridx = 1;
|
||||||
gbc_partnerName.gridy = 0;
|
gbc_partnerName.gridy = 0;
|
||||||
|
|
||||||
gbc_partnerName.insets = new Insets(0, 10, 0, 10);
|
gbc_partnerName.insets = new Insets(space, space, space, space);
|
||||||
contentPane.add(textPane, gbc_partnerName);
|
contentPane.add(textPane, gbc_partnerName);
|
||||||
|
|
||||||
userList.setCellRenderer(new UserListRenderer());
|
userList.setCellRenderer(new UserListRenderer());
|
||||||
@ -232,7 +217,6 @@ public class ChatWindow extends JFrame {
|
|||||||
readCurrentChat();
|
readCurrentChat();
|
||||||
|
|
||||||
client.setRecipient(user);
|
client.setRecipient(user);
|
||||||
|
|
||||||
textPane.setText(currentChat.getRecipient().getName());
|
textPane.setText(currentChat.getRecipient().getName());
|
||||||
|
|
||||||
messageList.setModel(currentChat.getModel());
|
messageList.setModel(currentChat.getModel());
|
||||||
@ -240,19 +224,17 @@ public class ChatWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
userList.setSelectionForeground(new Color(255, 255, 255));
|
|
||||||
userList.setSelectionBackground(new Color(102, 0, 153));
|
|
||||||
userList.setForeground(new Color(255, 255, 255));
|
|
||||||
userList.setBackground(new Color(51, 51, 51));
|
|
||||||
userList.setFont(new Font("Arial", Font.PLAIN, 17));
|
userList.setFont(new Font("Arial", Font.PLAIN, 17));
|
||||||
userList.setBorder(new EmptyBorder(5, 5, 5, 5));
|
userList.setBorder(new EmptyBorder(space, space, space, space));
|
||||||
|
|
||||||
GridBagConstraints gbc_userList = new GridBagConstraints();
|
GridBagConstraints gbc_userList = new GridBagConstraints();
|
||||||
gbc_userList.fill = GridBagConstraints.VERTICAL;
|
gbc_userList.fill = GridBagConstraints.VERTICAL;
|
||||||
gbc_userList.gridx = 0;
|
gbc_userList.gridx = 0;
|
||||||
gbc_userList.gridy = 1;
|
gbc_userList.gridy = 1;
|
||||||
gbc_userList.anchor = GridBagConstraints.PAGE_START;
|
gbc_userList.anchor = GridBagConstraints.PAGE_START;
|
||||||
gbc_userList.insets = new Insets(0, 0, 10, 0);
|
gbc_userList.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
|
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
contentPane.add(userList, gbc_userList);
|
contentPane.add(userList, gbc_userList);
|
||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
@ -263,16 +245,60 @@ public class ChatWindow extends JFrame {
|
|||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to immediately reload the ChatWindow when settings were changed.
|
||||||
|
*
|
||||||
|
* @since Envoy v0.1-alpha
|
||||||
|
*/
|
||||||
|
public void changeChatWindowColors(String key) {
|
||||||
|
Theme theme = Settings.getInstance().getThemes().get(key);
|
||||||
|
|
||||||
|
// contentPane
|
||||||
|
contentPane.setBackground(theme.getBackgroundColor());
|
||||||
|
contentPane.setForeground(theme.getUserNameColor());
|
||||||
|
// messageList
|
||||||
|
messageList.setSelectionForeground(theme.getUserNameColor());
|
||||||
|
messageList.setSelectionBackground(theme.getSelectionColor());
|
||||||
|
messageList.setForeground(theme.getMessageColorChat());
|
||||||
|
messageList.setBackground(theme.getCellColor());
|
||||||
|
// scrollPane
|
||||||
|
scrollPane.setForeground(theme.getBackgroundColor());
|
||||||
|
scrollPane.setBackground(theme.getCellColor());
|
||||||
|
// messageEnterTextArea
|
||||||
|
messageEnterTextArea.setCaretColor(theme.getTypingMessageColor());
|
||||||
|
messageEnterTextArea.setForeground(theme.getTypingMessageColor());
|
||||||
|
messageEnterTextArea.setBackground(theme.getCellColor());
|
||||||
|
// postButton
|
||||||
|
postButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
postButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
|
// settingsButton
|
||||||
|
settingsButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
settingsButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
|
// textPane
|
||||||
|
textPane.setBackground(theme.getBackgroundColor());
|
||||||
|
textPane.setForeground(theme.getUserNameColor());
|
||||||
|
// userList
|
||||||
|
userList.setSelectionForeground(theme.getUserNameColor());
|
||||||
|
userList.setSelectionBackground(theme.getSelectionColor());
|
||||||
|
userList.setForeground(theme.getUserNameColor());
|
||||||
|
userList.setBackground(theme.getCellColor());
|
||||||
|
}
|
||||||
|
|
||||||
private void postMessage(JList<Message> messageList) {
|
private void postMessage(JList<Message> messageList) {
|
||||||
if (!client.hasRecipient()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!messageEnterTextArea.getText().isEmpty()) try {
|
if (!messageEnterTextArea.getText().isEmpty()) try {
|
||||||
|
|
||||||
// Create and send message object
|
// 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);
|
currentChat.appendMessage(message);
|
||||||
messageList.setModel(currentChat.getModel());
|
messageList.setModel(currentChat.getModel());
|
||||||
|
|
||||||
@ -322,7 +348,8 @@ public class ChatWindow extends JFrame {
|
|||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
|
||||||
// Synchronize
|
// 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
|
// Process unread messages
|
||||||
localDB.addUnreadMessagesToLocalDB();
|
localDB.addUnreadMessagesToLocalDB();
|
||||||
@ -332,7 +359,8 @@ public class ChatWindow extends JFrame {
|
|||||||
readCurrentChat();
|
readCurrentChat();
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
SwingUtilities.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
|
SwingUtilities
|
||||||
|
.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
|
||||||
}).start();
|
}).start();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
@ -349,3 +377,4 @@ public class ChatWindow extends JFrame {
|
|||||||
*/
|
*/
|
||||||
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
|
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ import javax.swing.JLabel;
|
|||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.ListCellRenderer;
|
import javax.swing.ListCellRenderer;
|
||||||
|
|
||||||
|
import envoy.client.Settings;
|
||||||
import envoy.schema.Message;
|
import envoy.schema.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,10 +42,35 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess
|
|||||||
final String text = value.getContent().get(0).getText();
|
final String text = value.getContent().get(0).getText();
|
||||||
final String state = value.getMetadata().getState().toString();
|
final String state = value.getMetadata().getState().toString();
|
||||||
final String date = value.getMetadata().getDate() == null ? ""
|
final String date = value.getMetadata().getDate() == null ? ""
|
||||||
: new SimpleDateFormat("dd.MM.yyyy HH:mm ").format(value.getMetadata().getDate().toGregorianCalendar().getTime());
|
: new SimpleDateFormat("dd.MM.yyyy HH:mm ")
|
||||||
|
.format(value.getMetadata().getDate().toGregorianCalendar().getTime());
|
||||||
|
|
||||||
setText(String
|
// Getting the MessageColor in the Chat of the current theme
|
||||||
.format("<html><p style=\"color:#d2d235\"><b><small>%s</b></small><br><p style=\"color:white\">%s :%s</html>", date, text, state));
|
String textColor = null;
|
||||||
|
|
||||||
|
textColor = toHex(
|
||||||
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat());
|
||||||
|
|
||||||
|
// Getting the DateColor in the Chat of the current theme
|
||||||
|
String dateColor = null;
|
||||||
|
dateColor = toHex(
|
||||||
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat());
|
||||||
|
|
||||||
|
setText(String.format(
|
||||||
|
"<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
|
||||||
|
dateColor,
|
||||||
|
date,
|
||||||
|
textColor,
|
||||||
|
text,
|
||||||
|
state));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toHex(Color c) {
|
||||||
|
int r = c.getRed();
|
||||||
|
int g = c.getGreen();
|
||||||
|
int b = c.getBlue();
|
||||||
|
String hex = String.format("#%02x%02x%02x", r, g, b);
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,153 +2,561 @@ package envoy.client.ui;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
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;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JColorChooser;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.JTextPane;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
|
||||||
|
import envoy.client.LocalDB;
|
||||||
|
import envoy.client.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This class provides the GUI to change the user specific settings.
|
||||||
|
*
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
* File: <strong>SettingsScreen.java</strong><br>
|
* File: <strong>SettingsScreen.java</strong><br>
|
||||||
* Created: <strong>31 Oct 2019</strong><br>
|
* Created: <strong>31 Oct 2019</strong><br>
|
||||||
*
|
*
|
||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
|
* @author Maximilian Käfer
|
||||||
|
* @author Kai S. K. Engelbart
|
||||||
*/
|
*/
|
||||||
public class SettingsScreen extends JDialog {
|
public class SettingsScreen extends JDialog {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4476913491263077107L;
|
private static final long serialVersionUID = -4476913491263077107L;
|
||||||
private final JPanel contentPanel = new JPanel();
|
private final JPanel contentPanel = new JPanel();
|
||||||
public static boolean enterToSend = true;
|
|
||||||
|
private DefaultListModel<String> optionsListModel = new DefaultListModel<>();
|
||||||
|
private final JList<String> options = new JList<String>();
|
||||||
|
private JPanel buttonPane = new JPanel();
|
||||||
|
|
||||||
|
private JPanel themeContent = new JPanel();
|
||||||
|
private String[] themeArray = Settings.getInstance().getThemes().keySet().toArray(new String[0]);
|
||||||
|
private JComboBox<String> themes = new JComboBox<String>(themeArray);
|
||||||
|
|
||||||
|
private GridBagConstraints gbc_themeContent = new GridBagConstraints();
|
||||||
|
|
||||||
|
private Theme selectedTheme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
|
private JButton createNewThemeButton = new JButton("Create New Theme");
|
||||||
|
|
||||||
|
private JPanel colorsPanel = new JPanel();
|
||||||
|
private JButton okButton = new JButton("Save");
|
||||||
|
private JButton cancelButton = new JButton("Cancel");
|
||||||
|
private static int space = 5;
|
||||||
|
|
||||||
|
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:
|
// TODO: Add a JPanel with all the Information necessary:
|
||||||
// change (Picture,Username, Email, Password) and toggle(light/dark mode,
|
// change (Picture,Username, Email, Password) and toggle(light/dark mode,
|
||||||
// "ctrl+enter"/"enter"
|
// "ctrl+enter"/"enter"
|
||||||
// to send a message directly)
|
// to send a message directly)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the Settings screen.
|
* Opens the settings screen.<br>
|
||||||
* Only suited for Dev/Error mode.
|
|
||||||
* Avoid usage.
|
|
||||||
*
|
*
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public static void open() { open(new SettingsScreen()); }
|
public static void open() {
|
||||||
|
settingsScreen = new SettingsScreen();
|
||||||
/**
|
settingsScreen.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
* Opens the Settings screen.<br>
|
settingsScreen.setModal(true);
|
||||||
* Use preferably since everyone is already initialised.<br>
|
settingsScreen.setVisible(true);
|
||||||
* It personalises the screen more.
|
|
||||||
*
|
|
||||||
* @param username The name of the User
|
|
||||||
* @since Envoy v0.1-alpha
|
|
||||||
*/
|
|
||||||
public static void open(String username) {// , String Email) {AUSKLAMMERN, WENN ANMELDUNG PER
|
|
||||||
// EMAIL IMPLEMENTIERT IST!
|
|
||||||
open(new SettingsScreen(username));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void open(SettingsScreen dialog) {
|
|
||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
||||||
dialog.setModal(true);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the Settings screen.<br>
|
* Builds the settings screen.
|
||||||
* Use only as Dev/Error Mode.<br>
|
|
||||||
* Avoid usage.
|
|
||||||
*
|
*
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public SettingsScreen() {
|
private SettingsScreen() {
|
||||||
setBackground(Color.BLACK);
|
logger.info(Settings.getInstance().getCurrentTheme());
|
||||||
setBounds(100, 100, 450, 300);
|
|
||||||
|
setBounds(10, 10, 450, 650);
|
||||||
getContentPane().setLayout(new BorderLayout());
|
getContentPane().setLayout(new BorderLayout());
|
||||||
contentPanel.setBackground(Color.BLACK);
|
{
|
||||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
||||||
|
createNewThemeButton.setEnabled(false);
|
||||||
|
|
||||||
|
temporaryTheme = new Theme("temporaryTheme",
|
||||||
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||||
|
|
||||||
|
// Content pane
|
||||||
|
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||||
|
|
||||||
|
gbl_contentPanel.columnWidths = new int[] { 1, 1 };
|
||||||
|
gbl_contentPanel.rowHeights = new int[] { 1 };
|
||||||
|
gbl_contentPanel.columnWeights = new double[] { 0.05, 1.0 };
|
||||||
|
gbl_contentPanel.rowWeights = new double[] { 1.0 };
|
||||||
|
|
||||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||||
contentPanel.setLayout(new BorderLayout(0, 0));
|
contentPanel.setLayout(gbl_contentPanel);
|
||||||
{
|
|
||||||
JPanel buttonPane = new JPanel();
|
options.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
buttonPane.setBackground(Color.BLACK);
|
|
||||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
options.addListSelectionListener((listSelectionEvent) -> {
|
||||||
buttonPane.setLayout(new BorderLayout(0, 0));
|
if (!listSelectionEvent.getValueIsAdjusting()) {
|
||||||
{
|
@SuppressWarnings("unchecked")
|
||||||
JButton okButton = new JButton("Save");
|
final JList<String> selectedOption = (JList<String>) listSelectionEvent.getSource();
|
||||||
okButton.setActionCommand("OK");
|
final String option = selectedOption.getSelectedValue();
|
||||||
buttonPane.add(okButton, BorderLayout.EAST);
|
System.out.println(option);
|
||||||
getRootPane().setDefaultButton(okButton);
|
|
||||||
okButton.addActionListener((evt) -> {
|
switch (option) {
|
||||||
// Hier später die Daten abspeichern, wenn Datenmodell implementiert ist
|
case "Color Themes":
|
||||||
dispose();
|
setContent(themeContent, gbc_themeContent);
|
||||||
});
|
getContentPane().repaint();
|
||||||
|
getContentPane().revalidate();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
options.setFont(new Font("Arial", Font.PLAIN, 14));
|
||||||
|
|
||||||
|
Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
|
options.setSelectionForeground(theme.getUserNameColor());
|
||||||
|
options.setSelectionBackground(theme.getSelectionColor());
|
||||||
|
options.setForeground(theme.getUserNameColor());
|
||||||
|
options.setBackground(theme.getCellColor());
|
||||||
|
|
||||||
|
GridBagConstraints gbc_optionsList = new GridBagConstraints();
|
||||||
|
gbc_optionsList.fill = GridBagConstraints.BOTH;
|
||||||
|
gbc_optionsList.gridx = 0;
|
||||||
|
gbc_optionsList.gridy = 0;
|
||||||
|
gbc_optionsList.anchor = GridBagConstraints.PAGE_START;
|
||||||
|
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;
|
||||||
|
gbc_themeContent.gridy = 0;
|
||||||
|
gbc_themeContent.anchor = GridBagConstraints.PAGE_START;
|
||||||
|
gbc_themeContent.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
|
GridBagLayout gbl_themeLayout = new GridBagLayout();
|
||||||
|
|
||||||
|
themeContent.setForeground(theme.getUserNameColor());
|
||||||
|
themeContent.setBackground(theme.getCellColor());
|
||||||
|
|
||||||
|
gbl_themeLayout.columnWidths = new int[] { 1, 1 };
|
||||||
|
gbl_themeLayout.rowHeights = new int[] { 1, 1 };
|
||||||
|
gbl_themeLayout.columnWeights = new double[] { 1.0, 1.0 };
|
||||||
|
gbl_themeLayout.rowWeights = new double[] { 0.01, 1.0 };
|
||||||
|
|
||||||
|
themeContent.setLayout(gbl_themeLayout);
|
||||||
|
|
||||||
|
themes.setBackground(theme.getUserNameColor());
|
||||||
|
themes.setForeground(theme.getBackgroundColor());
|
||||||
|
themes.setSelectedItem(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
|
themes.addItemListener(new ItemListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
String selectedValue = (String) themes.getSelectedItem();
|
||||||
|
System.out.println(selectedValue);
|
||||||
|
selectedTheme = Settings.getInstance().getThemes().get(selectedValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
GridBagConstraints gbc_themes = new GridBagConstraints();
|
||||||
|
gbc_themes.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_themes.gridx = 0;
|
||||||
|
gbc_themes.gridy = 0;
|
||||||
|
gbc_themes.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
gbc_themes.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
|
themeContent.add(themes, gbc_themes);
|
||||||
|
|
||||||
|
colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS));
|
||||||
|
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
|
|
||||||
|
buildCustomizeElement(new JPanel(),
|
||||||
|
new JButton(),
|
||||||
|
new JTextPane(),
|
||||||
|
theme,
|
||||||
|
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.getInteractableForegroundColor(),
|
||||||
|
"Interactable Foreground",
|
||||||
|
3);
|
||||||
|
buildCustomizeElement(new JPanel(),
|
||||||
|
new JButton(),
|
||||||
|
new JTextPane(),
|
||||||
|
theme,
|
||||||
|
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);
|
||||||
|
|
||||||
|
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
|
||||||
|
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_colorsPanel.gridx = 0;
|
||||||
|
gbc_colorsPanel.gridy = 1;
|
||||||
|
gbc_colorsPanel.gridwidth = 2;
|
||||||
|
gbc_colorsPanel.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
gbc_colorsPanel.insets = new Insets(space, 0, 0, 0);
|
||||||
|
|
||||||
|
themeContent.add(colorsPanel, gbc_colorsPanel);
|
||||||
|
|
||||||
|
createNewThemeButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
|
createNewThemeButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
colorsPanel.setBackground(theme.getCellColor());
|
||||||
|
|
||||||
|
createNewThemeButton.addActionListener((evt) -> {
|
||||||
|
try {
|
||||||
|
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(),
|
||||||
|
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()));
|
||||||
|
|
||||||
|
createNewThemeButton.setEnabled(false);
|
||||||
|
themes.addItem(themeArray[themeArray.length - 1]);
|
||||||
|
|
||||||
|
contentPanel.revalidate();
|
||||||
|
contentPanel.repaint();
|
||||||
|
|
||||||
|
// TODO: Create new Theme
|
||||||
|
|
||||||
|
} 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);
|
||||||
|
|
||||||
|
// ButtonPane-------------------------------------------------------
|
||||||
|
GridBagLayout gbl_buttonPane = new GridBagLayout();
|
||||||
|
gbl_buttonPane.columnWidths = new int[] { 100, 250, 100, 0 };
|
||||||
|
gbl_buttonPane.rowHeights = new int[] { 25, 0 };
|
||||||
|
gbl_buttonPane.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
|
||||||
|
gbl_buttonPane.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
|
||||||
|
|
||||||
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||||
|
buttonPane.setLayout(gbl_buttonPane);
|
||||||
{
|
{
|
||||||
JButton cancelButton = new JButton("Cancel");
|
|
||||||
cancelButton.setActionCommand("Cancel");
|
cancelButton.setActionCommand("Cancel");
|
||||||
buttonPane.add(cancelButton, BorderLayout.WEST);
|
cancelButton.setBorderPainted(false);
|
||||||
|
GridBagConstraints gbc_cancelButton = new GridBagConstraints();
|
||||||
|
gbc_cancelButton.anchor = GridBagConstraints.NORTHWEST;
|
||||||
|
gbc_cancelButton.insets = new Insets(space, space, space, space);
|
||||||
|
gbc_cancelButton.gridx = 0;
|
||||||
|
gbc_cancelButton.gridy = 0;
|
||||||
|
buttonPane.add(cancelButton, gbc_cancelButton);
|
||||||
|
|
||||||
cancelButton.addActionListener((evt) -> { dispose(); });
|
cancelButton.addActionListener((evt) -> { dispose(); });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds the Settings screen.<br>
|
|
||||||
* Use preferreably since everyone is already initialised.<br>
|
|
||||||
* It personalises the screen more.
|
|
||||||
*
|
|
||||||
* @param Username The name of the User
|
|
||||||
* @since Envoy v0.1-alpha
|
|
||||||
*/
|
|
||||||
public SettingsScreen(String Username) {// , String Email, String hashedPwd) {AUSKLAMMERN, WENN ANMELDUNG PER EMAIL
|
|
||||||
// IMPLEMENTIERT IST!
|
|
||||||
setBackground(Color.BLACK);
|
|
||||||
setBounds(100, 100, 450, 300);
|
|
||||||
getContentPane().setLayout(new BorderLayout());
|
|
||||||
contentPanel.setBackground(Color.BLACK);
|
|
||||||
contentPanel.setLayout(new FlowLayout());
|
|
||||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
||||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
|
||||||
{
|
{
|
||||||
JPanel buttonPane = new JPanel();
|
|
||||||
buttonPane.setBackground(Color.BLACK);
|
|
||||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
||||||
buttonPane.setLayout(new BorderLayout(0, 0));
|
|
||||||
{
|
|
||||||
JButton okButton = new JButton("Save");
|
|
||||||
okButton.setActionCommand("OK");
|
okButton.setActionCommand("OK");
|
||||||
buttonPane.add(okButton, BorderLayout.EAST);
|
okButton.setBorderPainted(false);
|
||||||
|
GridBagConstraints gbc_okButton = new GridBagConstraints();
|
||||||
|
gbc_okButton.anchor = GridBagConstraints.NORTHEAST;
|
||||||
|
gbc_okButton.fill = GridBagConstraints.EAST;
|
||||||
|
gbc_okButton.insets = new Insets(space, space, space, space);
|
||||||
|
gbc_okButton.gridx = 2;
|
||||||
|
gbc_okButton.gridy = 0;
|
||||||
|
buttonPane.add(okButton, gbc_okButton);
|
||||||
getRootPane().setDefaultButton(okButton);
|
getRootPane().setDefaultButton(okButton);
|
||||||
okButton.addActionListener((evt) -> {
|
okButton.addActionListener((evt) -> {
|
||||||
// Hier später die Daten abspeichern, wenn Datenmodell implementiert ist
|
try {
|
||||||
dispose();
|
Settings.getInstance().setUsername(Settings.getInstance().getUsername());// still temporary
|
||||||
|
|
||||||
|
Settings.getInstance().setEmail(Settings.getInstance().getEmail());// still temporary value
|
||||||
|
|
||||||
|
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
|
||||||
|
|
||||||
|
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
|
||||||
|
System.out.println(selectedTheme.getThemeName());
|
||||||
|
|
||||||
|
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
||||||
|
updateColorVariables(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
|
Settings.getInstance().save();
|
||||||
|
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.info("Something went wrong when changing the setting");
|
||||||
|
settingsScreen.dispose();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
{
|
|
||||||
JButton cancelButton = new JButton("Cancel");
|
|
||||||
cancelButton.setActionCommand("Cancel");
|
|
||||||
buttonPane.add(cancelButton, BorderLayout.WEST);
|
|
||||||
|
|
||||||
cancelButton.addActionListener((evt) -> { dispose(); });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void changeSettingsScreenColors(String key) {
|
||||||
* @return true if Enter should be used to send a message instead of ctrl+enter
|
Theme theme = Settings.getInstance().getThemes().get(key);
|
||||||
* @since Envoy v0.1-alpha
|
// whole JDialog
|
||||||
*/
|
setBackground(theme.getBackgroundColor());
|
||||||
public static boolean isEnterToSend() { return enterToSend; }
|
// contentPanel
|
||||||
|
contentPanel.setBackground(theme.getBackgroundColor());
|
||||||
|
// buttonPane
|
||||||
|
buttonPane.setBackground(theme.getCellColor());
|
||||||
|
// cancelButton
|
||||||
|
cancelButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
|
cancelButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
// okButton
|
||||||
|
okButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
|
okButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
// options
|
||||||
|
options.setSelectionForeground(theme.getUserNameColor());
|
||||||
|
options.setSelectionBackground(theme.getSelectionColor());
|
||||||
|
options.setForeground(theme.getUserNameColor());
|
||||||
|
options.setBackground(theme.getCellColor());
|
||||||
|
// themeContent
|
||||||
|
themeContent.setForeground(theme.getUserNameColor());
|
||||||
|
themeContent.setBackground(theme.getCellColor());
|
||||||
|
// themes
|
||||||
|
themes.setBackground(theme.getUserNameColor());
|
||||||
|
themes.setForeground(theme.getBackgroundColor());
|
||||||
|
|
||||||
|
createNewThemeButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
|
createNewThemeButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
|
colorsPanel.setBackground(theme.getCellColor());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateColorVariables(String key) {
|
||||||
|
Theme theme = Settings.getInstance().getThemes().get(key);
|
||||||
|
|
||||||
|
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()).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()).getUserNameColor());
|
||||||
|
|
||||||
|
colorsPanel.removeAll();
|
||||||
|
|
||||||
|
buildCustomizeElement(new JPanel(),
|
||||||
|
|
||||||
|
new JButton(),
|
||||||
|
new JTextPane(),
|
||||||
|
theme,
|
||||||
|
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.getInteractableForegroundColor(),
|
||||||
|
"Interactable Foreground",
|
||||||
|
3);
|
||||||
|
buildCustomizeElement(new JPanel(),
|
||||||
|
|
||||||
|
new JButton(),
|
||||||
|
new JTextPane(),
|
||||||
|
theme,
|
||||||
|
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);
|
||||||
|
|
||||||
|
GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
|
||||||
|
gbc_createNewTheme.gridx = 0;
|
||||||
|
gbc_createNewTheme.gridy = 10;
|
||||||
|
|
||||||
|
colorsPanel.add(createNewThemeButton, gbc_createNewTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
|
||||||
|
textPane.setBackground(theme.getBackgroundColor());
|
||||||
|
textPane.setForeground(theme.getUserNameColor());
|
||||||
|
textPane.setText(name);
|
||||||
|
textPane.setEditable(false);
|
||||||
|
|
||||||
|
button.setBackground(color);
|
||||||
|
button.setPreferredSize(new Dimension(25, 25));
|
||||||
|
|
||||||
|
button.addActionListener((evt) -> {
|
||||||
|
try {
|
||||||
|
Color newColor = JColorChooser.showDialog(null, "Choose a color", color);
|
||||||
|
if (newColor.getRGB() != color.getRGB()) {
|
||||||
|
System.out.println("New Color");
|
||||||
|
System.out.println(color.getRGB());
|
||||||
|
// TODO: When Theme changed in same settings screen, color variable doesnt
|
||||||
|
// update.
|
||||||
|
Color[] colorsArray = temporaryTheme.getAllColors();
|
||||||
|
for (int i = 0; i < colorsArray.length; i++) {
|
||||||
|
if (color.getRGB() == colorsArray[i].getRGB()) {
|
||||||
|
temporaryTheme.setColor(i, newColor);
|
||||||
|
colorChanged = true;
|
||||||
|
createNewThemeButton.setEnabled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
button.setBackground(newColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.info("An error occured while opening Color Chooser: " + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
panel.add(textPane);
|
||||||
|
panel.add(button);
|
||||||
|
panel.setBackground(theme.getCellColor());
|
||||||
|
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
|
|
||||||
|
colorsPanel.add(panel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param enterForSend <br>
|
|
||||||
* toggles whether a message should be sent via
|
|
||||||
* <br>
|
|
||||||
* buttonpress "enter" or "ctrl"+"enter"
|
|
||||||
* @since Envoy v0.1-alpha
|
|
||||||
*/
|
|
||||||
public static void setEnterToSend(boolean enterForSend) { enterToSend = enterForSend; }
|
|
||||||
// TODO: Should be changed to private, but later to avoid warnings
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import javax.swing.JOptionPane;
|
|||||||
import envoy.client.Client;
|
import envoy.client.Client;
|
||||||
import envoy.client.Config;
|
import envoy.client.Config;
|
||||||
import envoy.client.LocalDB;
|
import envoy.client.LocalDB;
|
||||||
|
import envoy.client.Settings;
|
||||||
import envoy.exception.EnvoyException;
|
import envoy.exception.EnvoyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,6 +23,7 @@ import envoy.exception.EnvoyException;
|
|||||||
*
|
*
|
||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @author Maximilian Käfer
|
* @author Maximilian Käfer
|
||||||
|
* @author Kai S. K. Engelbart
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public class Startup {
|
public class Startup {
|
||||||
@ -68,6 +70,7 @@ public class Startup {
|
|||||||
"Local DB error",
|
"Local DB error",
|
||||||
JOptionPane.WARNING_MESSAGE);
|
JOptionPane.WARNING_MESSAGE);
|
||||||
}
|
}
|
||||||
|
Settings.getInstance().setUsername(userName);
|
||||||
|
|
||||||
EventQueue.invokeLater(() -> {
|
EventQueue.invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
|
181
src/main/java/envoy/client/ui/Theme.java
Normal file
181
src/main/java/envoy/client/ui/Theme.java
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
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>
|
||||||
|
*
|
||||||
|
* @author Maximilian Käfer
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public class Theme implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 141727847527060352L;
|
||||||
|
|
||||||
|
private String themeName;
|
||||||
|
private Color backgroundColor;
|
||||||
|
private Color cellColor;
|
||||||
|
private Color interactableBackgroundColor;
|
||||||
|
private Color userNameColor;
|
||||||
|
private Color interactableForegroundColor;
|
||||||
|
private Color messageColorChat;
|
||||||
|
private Color dateColorChat;
|
||||||
|
private Color selectionColor;
|
||||||
|
private Color typingMessageColor;
|
||||||
|
|
||||||
|
public Theme(String themeName, Color backgroundColor, Color cellColor, Color interactableForegroundColor,
|
||||||
|
Color interactableBackgroundColor, Color messageColorChat, Color dateColorChat, Color selectionColor,
|
||||||
|
Color typingMessageColor, Color userNameColor) {
|
||||||
|
|
||||||
|
this.themeName = themeName;
|
||||||
|
|
||||||
|
this.backgroundColor = backgroundColor;
|
||||||
|
this.cellColor = cellColor;
|
||||||
|
this.interactableForegroundColor = interactableForegroundColor;
|
||||||
|
this.interactableBackgroundColor = interactableBackgroundColor;
|
||||||
|
this.messageColorChat = messageColorChat;
|
||||||
|
this.dateColorChat = dateColorChat;
|
||||||
|
this.selectionColor = selectionColor;
|
||||||
|
this.typingMessageColor = typingMessageColor;
|
||||||
|
this.userNameColor = userNameColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Theme(String name, Theme other) {
|
||||||
|
this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor,
|
||||||
|
other.interactableForegroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor,
|
||||||
|
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;
|
||||||
|
c[1] = cellColor;
|
||||||
|
c[2] = interactableForegroundColor;
|
||||||
|
c[3] = interactableBackgroundColor;
|
||||||
|
c[4] = messageColorChat;
|
||||||
|
c[5] = dateColorChat;
|
||||||
|
c[6] = selectionColor;
|
||||||
|
c[7] = typingMessageColor;
|
||||||
|
c[8] = userNameColor;
|
||||||
|
|
||||||
|
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:
|
||||||
|
this.backgroundColor = newColor;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
this.cellColor = newColor;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
this.interactableForegroundColor = newColor;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
this.interactableBackgroundColor = newColor;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
this.messageColorChat = newColor;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
this.dateColorChat = newColor;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
this.selectionColor = newColor;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
this.typingMessageColor = newColor;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
this.userNameColor = newColor;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,11 +1,13 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.ListCellRenderer;
|
import javax.swing.ListCellRenderer;
|
||||||
|
|
||||||
|
import envoy.client.Settings;
|
||||||
import envoy.schema.User;
|
import envoy.schema.User;
|
||||||
import envoy.schema.User.UserStatus;
|
import envoy.schema.User.UserStatus;
|
||||||
|
|
||||||
@ -41,16 +43,34 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
|
|||||||
final String name = value.getName();
|
final String name = value.getName();
|
||||||
final UserStatus status = value.getStatus();
|
final UserStatus status = value.getStatus();
|
||||||
|
|
||||||
|
// Getting the UserNameColor of the current theme
|
||||||
|
String textColor = null;
|
||||||
|
textColor = toHex(
|
||||||
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case ONLINE:
|
case ONLINE:
|
||||||
setText(String
|
setText(String.format(
|
||||||
.format("<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:white\">%s</html>", status, name));
|
"<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
|
||||||
|
status,
|
||||||
|
textColor,
|
||||||
|
name));
|
||||||
break;
|
break;
|
||||||
case OFFLINE:
|
case OFFLINE:
|
||||||
setText(String
|
setText(String.format(
|
||||||
.format("<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:white\">%s</html>", status, name));
|
"<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
|
||||||
|
status,
|
||||||
|
textColor,
|
||||||
|
name));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toHex(Color c) {
|
||||||
|
int r = c.getRed();
|
||||||
|
int g = c.getGreen();
|
||||||
|
int b = c.getBlue();
|
||||||
|
String hex = String.format("#%02x%02x%02x", r, g, b);
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user