Implemented a (not working) own version of a logger
and reformatted code
This commit is contained in:
parent
30dc9838ea
commit
cac42e2d83
@ -1,7 +1,5 @@
|
|||||||
package envoy.client;
|
package envoy.client;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.ws.rs.client.ClientBuilder;
|
import javax.ws.rs.client.ClientBuilder;
|
||||||
import javax.ws.rs.client.Entity;
|
import javax.ws.rs.client.Entity;
|
||||||
import javax.ws.rs.client.WebTarget;
|
import javax.ws.rs.client.WebTarget;
|
||||||
@ -10,6 +8,7 @@ import javax.xml.bind.JAXBContext;
|
|||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
|
|
||||||
|
import envoy.client.event.EnvoyLogger;
|
||||||
import envoy.schema.ObjectFactory;
|
import envoy.schema.ObjectFactory;
|
||||||
import envoy.schema.Sync;
|
import envoy.schema.Sync;
|
||||||
import envoy.schema.User;
|
import envoy.schema.User;
|
||||||
@ -30,7 +29,7 @@ public class Client {
|
|||||||
private Config config;
|
private Config config;
|
||||||
private User sender, recipient;
|
private User sender, recipient;
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(Client.class.getSimpleName());
|
private static final EnvoyLogger logger = new EnvoyLogger(Client.class.getSimpleName());
|
||||||
|
|
||||||
public Client(Config config, String username) {
|
public Client(Config config, String username) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@ -63,9 +62,7 @@ public class Client {
|
|||||||
user.setID(-1);
|
user.setID(-1);
|
||||||
sendSync.getUsers().add(user);
|
sendSync.getUsers().add(user);
|
||||||
|
|
||||||
Sync returnSendSync = post(
|
Sync returnSendSync = post(String.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
||||||
String
|
|
||||||
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
|
||||||
sendSync,
|
sendSync,
|
||||||
Sync.class);
|
Sync.class);
|
||||||
return returnSendSync;
|
return returnSendSync;
|
||||||
@ -85,9 +82,7 @@ public class Client {
|
|||||||
user.setName(name);
|
user.setName(name);
|
||||||
senderSync.getUsers().add(user);
|
senderSync.getUsers().add(user);
|
||||||
|
|
||||||
Sync returnSenderSync = post(
|
Sync returnSenderSync = post(String.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
||||||
String
|
|
||||||
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
|
||||||
senderSync,
|
senderSync,
|
||||||
Sync.class);
|
Sync.class);
|
||||||
|
|
||||||
@ -134,7 +129,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 sync object (yet to be converted from java class to sync.xml)
|
* @param sync the sync object (yet to be converted from java class to
|
||||||
|
* sync.xml)
|
||||||
* @return a returnSync.xml file
|
* @return a returnSync.xml file
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
@ -151,10 +147,7 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send sync
|
// Send sync
|
||||||
return post(String
|
return post(String.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), userId), sync, Sync.class);
|
||||||
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), userId),
|
|
||||||
sync,
|
|
||||||
Sync.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,9 +71,7 @@ public class Config {
|
|||||||
* @return {@code true} if server, port and localDB directory are known.
|
* @return {@code true} if server, port and localDB directory are known.
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() { return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null; }
|
||||||
return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the host name of the Envoy server
|
* @return the host name of the Envoy server
|
||||||
@ -114,7 +112,7 @@ public class Config {
|
|||||||
/**
|
/**
|
||||||
* Changes the default local database.
|
* Changes the default local database.
|
||||||
* Exclusively intended for development purposes.
|
* Exclusively intended for development purposes.
|
||||||
*
|
*
|
||||||
* @param localDB the file containing the local database
|
* @param localDB the file containing the local database
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
**/
|
**/
|
||||||
|
@ -14,6 +14,7 @@ import java.util.logging.Logger;
|
|||||||
import javax.xml.datatype.DatatypeConfigurationException;
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
import javax.xml.datatype.DatatypeFactory;
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
|
|
||||||
|
import envoy.client.event.EnvoyLogger;
|
||||||
import envoy.client.event.EventBus;
|
import envoy.client.event.EventBus;
|
||||||
import envoy.client.event.MessageCreationEvent;
|
import envoy.client.event.MessageCreationEvent;
|
||||||
import envoy.exception.EnvoyException;
|
import envoy.exception.EnvoyException;
|
||||||
@ -44,7 +45,7 @@ public class LocalDB {
|
|||||||
private Sync sync = objectFactory.createSync();
|
private Sync sync = objectFactory.createSync();
|
||||||
private Sync readMessages = objectFactory.createSync();
|
private Sync readMessages = objectFactory.createSync();
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(LocalDB.class.getSimpleName());
|
private static final Logger logger = new EnvoyLogger(LocalDB.class.getSimpleName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an empty local database.
|
* Constructs an empty local database.
|
||||||
|
@ -73,9 +73,9 @@ public class Settings {
|
|||||||
// Load themes from theme file
|
// Load themes from theme file
|
||||||
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(themeFile))) {
|
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(themeFile))) {
|
||||||
Object obj = in.readObject();
|
Object obj = in.readObject();
|
||||||
if(obj instanceof HashMap) themes = (Map<String, Theme>) obj;
|
if (obj instanceof HashMap) themes = (Map<String, Theme>) obj;
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
themes = new HashMap<>();
|
themes = new HashMap<>();
|
||||||
currentTheme = "dark";
|
currentTheme = "dark";
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -95,15 +95,15 @@ public class Settings {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public void save() throws IOException{
|
public void save() throws IOException {
|
||||||
prefs.put("username", getUsername());
|
prefs.put("username", getUsername());
|
||||||
prefs.put("email", getEmail());
|
prefs.put("email", getEmail());
|
||||||
prefs.put("theme", currentTheme);
|
prefs.put("theme", currentTheme);
|
||||||
prefs.putBoolean("enterToSend", isEnterToSend());
|
prefs.putBoolean("enterToSend", isEnterToSend());
|
||||||
|
|
||||||
// Save themes to theme file
|
// Save themes to theme file
|
||||||
themeFile.createNewFile();
|
themeFile.createNewFile();
|
||||||
try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(themeFile))) {
|
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(themeFile))) {
|
||||||
out.writeObject(themes);
|
out.writeObject(themes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
103
src/main/java/envoy/client/event/EnvoyLogger.java
Normal file
103
src/main/java/envoy/client/event/EnvoyLogger.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package envoy.client.event;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.ConsoleHandler;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Handler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: <strong>envoy-client</strong><br>
|
||||||
|
* File: <strong>EnvoyLogger.java</strong><br>
|
||||||
|
* Created: <strong>14 Dec 2019</strong><br>
|
||||||
|
*
|
||||||
|
* @author Leon Hofmeister
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public class EnvoyLogger extends Logger {
|
||||||
|
|
||||||
|
private Logger logger;
|
||||||
|
private int fileLevel = 800;
|
||||||
|
|
||||||
|
private Handler handler = new Handler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(LogRecord arg0) {
|
||||||
|
ConsoleHandler ch;
|
||||||
|
FileHandler fh;
|
||||||
|
SimpleFormatter formatter = new SimpleFormatter();
|
||||||
|
if (arg0.getLevel().intValue() >= fileLevel) {// Case if level >= info
|
||||||
|
try {
|
||||||
|
fh = new FileHandler("Envoy_user.log");
|
||||||
|
logger.addHandler(fh);
|
||||||
|
formatter.formatMessage(arg0);
|
||||||
|
fh.setFormatter(formatter);
|
||||||
|
} catch (SecurityException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ch = new ConsoleHandler();
|
||||||
|
logger.addHandler(ch);
|
||||||
|
formatter.formatMessage(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SecurityException {}
|
||||||
|
};
|
||||||
|
|
||||||
|
public EnvoyLogger(String name) {
|
||||||
|
super(name, null);
|
||||||
|
logger.addHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a message. If the problem severity is above the FileLevel-barrier, then
|
||||||
|
* the log entry will be written to a file. Regardless of problem severity,
|
||||||
|
* everything will be printed to the console.
|
||||||
|
*
|
||||||
|
* @param level the problem severity
|
||||||
|
* @param msg the message to be written in the log
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void log(Level level, String msg) {
|
||||||
|
LogRecord lr = new LogRecord(level, msg);
|
||||||
|
logger.log(lr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a message. If the problem severity is above the {@code FileLevel}
|
||||||
|
* barrier, then the log entry will be written to a file.
|
||||||
|
* Regardless of problem severity, everything will be printed to the console.
|
||||||
|
*
|
||||||
|
* @param logRecord the LogRecord (Level and String) to be treated by the
|
||||||
|
* Logger.
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void log(LogRecord logRecord) { logger.log(logRecord); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the fileLevel: The current barrier for writing logs to a file. It can
|
||||||
|
* range from 100-1000 in steps of one hundred with 1000 being
|
||||||
|
* Level.SEVERE
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public int getFileLevel() { return fileLevel; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fileLevel the severity above which on logRecords will be written in a
|
||||||
|
* file instead of the console
|
||||||
|
* @since Envoy v0.2-alpha
|
||||||
|
*/
|
||||||
|
public void setFileLevel(int fileLevel) {
|
||||||
|
if (fileLevel <= 10) fileLevel *= 100;
|
||||||
|
this.fileLevel = fileLevel;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ package envoy.client.event;
|
|||||||
* Created: <strong>04.12.2019</strong><br>
|
* Created: <strong>04.12.2019</strong><br>
|
||||||
*
|
*
|
||||||
* @author Kai S. K. Engelbart
|
* @author Kai S. K. Engelbart
|
||||||
|
* @param <T> the type of our Event
|
||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public interface Event<T> {
|
public interface Event<T> {
|
||||||
|
@ -12,7 +12,6 @@ import java.awt.event.WindowAdapter;
|
|||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.swing.DefaultListModel;
|
import javax.swing.DefaultListModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@ -33,6 +32,7 @@ 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.client.Settings;
|
||||||
|
import envoy.client.event.EnvoyLogger;
|
||||||
import envoy.schema.Message;
|
import envoy.schema.Message;
|
||||||
import envoy.schema.Sync;
|
import envoy.schema.Sync;
|
||||||
import envoy.schema.User;
|
import envoy.schema.User;
|
||||||
@ -68,7 +68,7 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
private static int space = 4;
|
private static int space = 4;
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ChatWindow.class.getSimpleName());
|
private static final EnvoyLogger logger = new EnvoyLogger(ChatWindow.class.getSimpleName());
|
||||||
|
|
||||||
public ChatWindow(Client client, LocalDB localDB) {
|
public ChatWindow(Client client, LocalDB localDB) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@ -132,8 +132,7 @@ public class ChatWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER
|
if (e.getKeyCode() == KeyEvent.VK_ENTER
|
||||||
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0)
|
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0) || (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
||||||
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
|
||||||
postMessage(messageList);
|
postMessage(messageList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,10 +179,9 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
settingsButton.addActionListener((evt) -> {
|
settingsButton.addActionListener((evt) -> {
|
||||||
try {
|
try {
|
||||||
SettingsScreen.open();
|
new SettingsScreen().setVisible(true);
|
||||||
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
|
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
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);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -235,7 +233,7 @@ public class ChatWindow extends JFrame {
|
|||||||
gbc_userList.insets = new Insets(space, space, space, space);
|
gbc_userList.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
|
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
contentPane.add(userList, gbc_userList);
|
contentPane.add(userList, gbc_userList);
|
||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
|
|
||||||
@ -244,7 +242,6 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to immediately reload the ChatWindow when settings were changed.
|
* Used to immediately reload the ChatWindow when settings were changed.
|
||||||
@ -287,18 +284,14 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
private void postMessage(JList<Message> messageList) {
|
private void postMessage(JList<Message> messageList) {
|
||||||
if (!client.hasRecipient()) {
|
if (!client.hasRecipient()) {
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
|
||||||
"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(),
|
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient().getID());
|
||||||
currentChat.getRecipient().getID());
|
|
||||||
currentChat.appendMessage(message);
|
currentChat.appendMessage(message);
|
||||||
messageList.setModel(currentChat.getModel());
|
messageList.setModel(currentChat.getModel());
|
||||||
|
|
||||||
@ -348,8 +341,7 @@ public class ChatWindow extends JFrame {
|
|||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
|
||||||
// Synchronize
|
// Synchronize
|
||||||
localDB.applySync(
|
localDB.applySync(client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID())));
|
||||||
client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID())));
|
|
||||||
|
|
||||||
// Process unread messages
|
// Process unread messages
|
||||||
localDB.addUnreadMessagesToLocalDB();
|
localDB.addUnreadMessagesToLocalDB();
|
||||||
@ -359,8 +351,7 @@ public class ChatWindow extends JFrame {
|
|||||||
readCurrentChat();
|
readCurrentChat();
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
SwingUtilities
|
SwingUtilities.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
|
||||||
.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
|
|
||||||
}).start();
|
}).start();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
@ -377,4 +368,3 @@ public class ChatWindow extends JFrame {
|
|||||||
*/
|
*/
|
||||||
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
|
private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,22 +42,18 @@ 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 ")
|
: new SimpleDateFormat("dd.MM.yyyy HH:mm ").format(value.getMetadata().getDate().toGregorianCalendar().getTime());
|
||||||
.format(value.getMetadata().getDate().toGregorianCalendar().getTime());
|
|
||||||
|
|
||||||
// Getting the MessageColor in the Chat of the current theme
|
// Getting the MessageColor in the Chat of the current theme
|
||||||
String textColor = null;
|
String textColor = null;
|
||||||
|
|
||||||
textColor = toHex(
|
textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat());
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat());
|
|
||||||
|
|
||||||
// Getting the DateColor in the Chat of the current theme
|
// Getting the DateColor in the Chat of the current theme
|
||||||
String dateColor = null;
|
String dateColor = null;
|
||||||
dateColor = toHex(
|
dateColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat());
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat());
|
|
||||||
|
|
||||||
setText(String.format(
|
setText(String.format("<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
|
||||||
"<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
|
|
||||||
dateColor,
|
dateColor,
|
||||||
date,
|
date,
|
||||||
textColor,
|
textColor,
|
||||||
|
@ -11,6 +11,7 @@ import java.awt.Insets;
|
|||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
import java.awt.event.ItemListener;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
@ -25,8 +26,8 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JTextPane;
|
import javax.swing.JTextPane;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
|
|
||||||
import envoy.client.LocalDB;
|
|
||||||
import envoy.client.Settings;
|
import envoy.client.Settings;
|
||||||
|
import envoy.client.event.EnvoyLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides the GUI to change the user specific settings.
|
* This class provides the GUI to change the user specific settings.
|
||||||
@ -54,45 +55,28 @@ public class SettingsScreen extends JDialog {
|
|||||||
|
|
||||||
private GridBagConstraints gbc_themeContent = new GridBagConstraints();
|
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 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 static int space = 5;
|
||||||
|
private Theme selectedTheme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
||||||
|
private Theme temporaryTheme;
|
||||||
|
|
||||||
private boolean colorChanged = false;
|
private static final Logger logger = new EnvoyLogger(SettingsScreen.class.getSimpleName());
|
||||||
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)
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the settings screen.<br>
|
|
||||||
*
|
|
||||||
* @since Envoy v0.1-alpha
|
|
||||||
*/
|
|
||||||
public static void open() {
|
|
||||||
settingsScreen = new SettingsScreen();
|
|
||||||
settingsScreen.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
||||||
settingsScreen.setModal(true);
|
|
||||||
settingsScreen.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the settings screen.
|
* Builds the settings screen.
|
||||||
*
|
*
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
private SettingsScreen() {
|
public SettingsScreen() {
|
||||||
logger.info(Settings.getInstance().getCurrentTheme());
|
logger.info(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
setBounds(10, 10, 450, 650);
|
setBounds(10, 10, 450, 650);
|
||||||
@ -101,8 +85,7 @@ public class SettingsScreen extends JDialog {
|
|||||||
|
|
||||||
createNewThemeButton.setEnabled(false);
|
createNewThemeButton.setEnabled(false);
|
||||||
|
|
||||||
temporaryTheme = new Theme("temporaryTheme",
|
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
|
||||||
|
|
||||||
// Content pane
|
// Content pane
|
||||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||||
@ -122,7 +105,7 @@ public class SettingsScreen extends JDialog {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final JList<String> selectedOption = (JList<String>) listSelectionEvent.getSource();
|
final JList<String> selectedOption = (JList<String>) listSelectionEvent.getSource();
|
||||||
final String option = selectedOption.getSelectedValue();
|
final String option = selectedOption.getSelectedValue();
|
||||||
System.out.println(option);
|
logger.log(Level.FINEST, option);
|
||||||
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case "Color Themes":
|
case "Color Themes":
|
||||||
@ -183,7 +166,7 @@ public class SettingsScreen extends JDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
String selectedValue = (String) themes.getSelectedItem();
|
String selectedValue = (String) themes.getSelectedItem();
|
||||||
System.out.println(selectedValue);
|
logger.log(Level.FINEST, selectedValue);
|
||||||
selectedTheme = Settings.getInstance().getThemes().get(selectedValue);
|
selectedTheme = Settings.getInstance().getThemes().get(selectedValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -200,20 +183,8 @@ public class SettingsScreen extends JDialog {
|
|||||||
colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS));
|
colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS));
|
||||||
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
|
|
||||||
buildCustomizeElement(new JPanel(),
|
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getBackgroundColor(), "Background", 1);
|
||||||
new JButton(),
|
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 2);
|
||||||
new JTextPane(),
|
|
||||||
theme,
|
|
||||||
theme.getBackgroundColor(),
|
|
||||||
"Background",
|
|
||||||
1);
|
|
||||||
buildCustomizeElement(new JPanel(),
|
|
||||||
new JButton(),
|
|
||||||
new JTextPane(),
|
|
||||||
theme,
|
|
||||||
theme.getCellColor(),
|
|
||||||
"Cells",
|
|
||||||
2);
|
|
||||||
buildCustomizeElement(new JPanel(),
|
buildCustomizeElement(new JPanel(),
|
||||||
new JButton(),
|
new JButton(),
|
||||||
new JTextPane(),
|
new JTextPane(),
|
||||||
@ -228,41 +199,11 @@ public class SettingsScreen extends JDialog {
|
|||||||
theme.getInteractableBackgroundColor(),
|
theme.getInteractableBackgroundColor(),
|
||||||
"Interactable Background",
|
"Interactable Background",
|
||||||
4);
|
4);
|
||||||
buildCustomizeElement(new JPanel(),
|
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", 5);
|
||||||
new JButton(),
|
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", 6);
|
||||||
new JTextPane(),
|
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 7);
|
||||||
theme,
|
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", 8);
|
||||||
theme.getMessageColorChat(),
|
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", 9);
|
||||||
"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();
|
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
|
||||||
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
|
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
|
||||||
@ -281,18 +222,16 @@ public class SettingsScreen extends JDialog {
|
|||||||
createNewThemeButton.addActionListener((evt) -> {
|
createNewThemeButton.addActionListener((evt) -> {
|
||||||
try {
|
try {
|
||||||
String s = JOptionPane.showInputDialog("Enter a name for the new theme");
|
String s = JOptionPane.showInputDialog("Enter a name for the new theme");
|
||||||
System.out.println(s);
|
logger.log(Level.FINEST, s);
|
||||||
Settings.getInstance()
|
Settings.getInstance()
|
||||||
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(),
|
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(), temporaryTheme.getCellColor(),
|
||||||
temporaryTheme.getCellColor(), temporaryTheme.getInteractableForegroundColor(),
|
temporaryTheme.getInteractableForegroundColor(), temporaryTheme.getInteractableBackgroundColor(),
|
||||||
temporaryTheme.getInteractableBackgroundColor(), temporaryTheme.getMessageColorChat(),
|
temporaryTheme.getMessageColorChat(), temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
|
||||||
temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
|
|
||||||
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
|
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
|
||||||
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
||||||
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
|
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
|
||||||
|
|
||||||
temporaryTheme = new Theme("temporaryTheme",
|
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
|
||||||
|
|
||||||
createNewThemeButton.setEnabled(false);
|
createNewThemeButton.setEnabled(false);
|
||||||
themes.addItem(themeArray[themeArray.length - 1]);
|
themes.addItem(themeArray[themeArray.length - 1]);
|
||||||
@ -355,7 +294,7 @@ public class SettingsScreen extends JDialog {
|
|||||||
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
|
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
|
||||||
|
|
||||||
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
|
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
|
||||||
System.out.println(selectedTheme.getThemeName());
|
logger.log(Level.FINER, selectedTheme.getThemeName());
|
||||||
|
|
||||||
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
||||||
updateColorVariables(Settings.getInstance().getCurrentTheme());
|
updateColorVariables(Settings.getInstance().getCurrentTheme());
|
||||||
@ -365,13 +304,17 @@ public class SettingsScreen extends JDialog {
|
|||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.info("Something went wrong when changing the setting");
|
logger.warning("Something went wrong when changing the setting");
|
||||||
settingsScreen.dispose();
|
JOptionPane.showMessageDialog(this, "Something went wrong when changing the setting");
|
||||||
|
dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
||||||
|
|
||||||
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
setModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeSettingsScreenColors(String key) {
|
private void changeSettingsScreenColors(String key) {
|
||||||
@ -412,21 +355,12 @@ public class SettingsScreen extends JDialog {
|
|||||||
temporaryTheme = new Theme("temporaryTheme",
|
temporaryTheme = new Theme("temporaryTheme",
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(),
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(),
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(),
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(),
|
||||||
Settings.getInstance()
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableForegroundColor(),
|
||||||
.getThemes()
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor(),
|
||||||
.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()).getMessageColorChat(),
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(),
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(),
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(),
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(),
|
||||||
Settings.getInstance()
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getTypingMessageColor(),
|
||||||
.getThemes()
|
|
||||||
.get(Settings.getInstance().getCurrentTheme())
|
|
||||||
.getTypingMessageColor(),
|
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
||||||
|
|
||||||
colorsPanel.removeAll();
|
colorsPanel.removeAll();
|
||||||
@ -513,8 +447,7 @@ public class SettingsScreen extends JDialog {
|
|||||||
|
|
||||||
private void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); }
|
private void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); }
|
||||||
|
|
||||||
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color,
|
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color, String name, int yIndex) {
|
||||||
String name, int yIndex) {
|
|
||||||
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
|
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
|
||||||
textPane.setBackground(theme.getBackgroundColor());
|
textPane.setBackground(theme.getBackgroundColor());
|
||||||
textPane.setForeground(theme.getUserNameColor());
|
textPane.setForeground(theme.getUserNameColor());
|
||||||
@ -528,15 +461,11 @@ public class SettingsScreen extends JDialog {
|
|||||||
try {
|
try {
|
||||||
Color newColor = JColorChooser.showDialog(null, "Choose a color", color);
|
Color newColor = JColorChooser.showDialog(null, "Choose a color", color);
|
||||||
if (newColor.getRGB() != color.getRGB()) {
|
if (newColor.getRGB() != color.getRGB()) {
|
||||||
System.out.println("New Color");
|
logger.log(Level.FINEST, String.valueOf(color.getRGB()));
|
||||||
System.out.println(color.getRGB());
|
|
||||||
// TODO: When Theme changed in same settings screen, color variable doesnt
|
|
||||||
// update.
|
|
||||||
Color[] colorsArray = temporaryTheme.getAllColors();
|
Color[] colorsArray = temporaryTheme.getAllColors();
|
||||||
for (int i = 0; i < colorsArray.length; i++) {
|
for (int i = 0; i < colorsArray.length; i++) {
|
||||||
if (color.getRGB() == colorsArray[i].getRGB()) {
|
if (color.getRGB() == colorsArray[i].getRGB()) {
|
||||||
temporaryTheme.setColor(i, newColor);
|
temporaryTheme.setColor(i, newColor);
|
||||||
colorChanged = true;
|
|
||||||
createNewThemeButton.setEnabled(true);
|
createNewThemeButton.setEnabled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ 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.client.Settings;
|
||||||
|
import envoy.client.event.EnvoyLogger;
|
||||||
import envoy.exception.EnvoyException;
|
import envoy.exception.EnvoyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +29,7 @@ import envoy.exception.EnvoyException;
|
|||||||
*/
|
*/
|
||||||
public class Startup {
|
public class Startup {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(Startup.class.getSimpleName());
|
private static final Logger logger = new EnvoyLogger(Startup.class.getSimpleName());
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
logger.setLevel(Level.ALL);
|
logger.setLevel(Level.ALL);
|
||||||
|
@ -75,14 +75,10 @@ public class StatusTrayIcon implements EventHandler {
|
|||||||
focusTarget.addWindowFocusListener(new WindowAdapter() {
|
focusTarget.addWindowFocusListener(new WindowAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowGainedFocus(WindowEvent e) {
|
public void windowGainedFocus(WindowEvent e) { displayMessages = false; }
|
||||||
displayMessages = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowLostFocus(WindowEvent e) {
|
public void windowLostFocus(WindowEvent e) { displayMessages = true; }
|
||||||
displayMessages = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start processing message events
|
// Start processing message events
|
||||||
|
@ -26,9 +26,8 @@ public class Theme implements Serializable {
|
|||||||
private Color selectionColor;
|
private Color selectionColor;
|
||||||
private Color typingMessageColor;
|
private Color typingMessageColor;
|
||||||
|
|
||||||
public Theme(String themeName, Color backgroundColor, Color cellColor, Color interactableForegroundColor,
|
public Theme(String themeName, Color backgroundColor, Color cellColor, Color interactableForegroundColor, Color interactableBackgroundColor,
|
||||||
Color interactableBackgroundColor, Color messageColorChat, Color dateColorChat, Color selectionColor,
|
Color messageColorChat, Color dateColorChat, Color selectionColor, Color typingMessageColor, Color userNameColor) {
|
||||||
Color typingMessageColor, Color userNameColor) {
|
|
||||||
|
|
||||||
this.themeName = themeName;
|
this.themeName = themeName;
|
||||||
|
|
||||||
@ -42,11 +41,10 @@ public class Theme implements Serializable {
|
|||||||
this.typingMessageColor = typingMessageColor;
|
this.typingMessageColor = typingMessageColor;
|
||||||
this.userNameColor = userNameColor;
|
this.userNameColor = userNameColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Theme(String name, Theme other) {
|
public Theme(String name, Theme other) {
|
||||||
this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor,
|
this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor, other.interactableForegroundColor,
|
||||||
other.interactableForegroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor,
|
other.messageColorChat, other.dateColorChat, other.selectionColor, other.typingMessageColor, other.userNameColor);
|
||||||
other.typingMessageColor, other.userNameColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,8 +12,8 @@ import envoy.schema.User;
|
|||||||
import envoy.schema.User.UserStatus;
|
import envoy.schema.User.UserStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how the {@code UserList} is displayed.
|
* Defines how the {@code UserList} is displayed.<br>
|
||||||
*
|
* <br>
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
* File: <strong>UserListRenderer.java</strong><br>
|
* File: <strong>UserListRenderer.java</strong><br>
|
||||||
* Created: <strong>12 Oct 2019</strong><br>
|
* Created: <strong>12 Oct 2019</strong><br>
|
||||||
@ -26,7 +26,6 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 5164417379767181198L;
|
private static final long serialVersionUID = 5164417379767181198L;
|
||||||
|
|
||||||
@SuppressWarnings("incomplete-switch")
|
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList<? extends User> list, User value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList<? extends User> list, User value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
@ -44,23 +43,16 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
|
|||||||
final UserStatus status = value.getStatus();
|
final UserStatus status = value.getStatus();
|
||||||
|
|
||||||
// Getting the UserNameColor of the current theme
|
// Getting the UserNameColor of the current theme
|
||||||
String textColor = null;
|
String textColor = null;
|
||||||
textColor = toHex(
|
textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
||||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case ONLINE:
|
case ONLINE:
|
||||||
setText(String.format(
|
setText(String
|
||||||
"<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
|
.format("<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>", status, textColor, name));
|
||||||
status,
|
|
||||||
textColor,
|
|
||||||
name));
|
|
||||||
break;
|
break;
|
||||||
case OFFLINE:
|
case OFFLINE:
|
||||||
setText(String.format(
|
setText(String
|
||||||
"<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
|
.format("<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>", status, textColor, name));
|
||||||
status,
|
|
||||||
textColor,
|
|
||||||
name));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
Reference in New Issue
Block a user