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;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
@ -10,6 +8,7 @@ import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import envoy.client.event.EnvoyLogger;
|
||||
import envoy.schema.ObjectFactory;
|
||||
import envoy.schema.Sync;
|
||||
import envoy.schema.User;
|
||||
@ -30,7 +29,7 @@ public class Client {
|
||||
private Config config;
|
||||
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) {
|
||||
this.config = config;
|
||||
@ -63,9 +62,7 @@ public class Client {
|
||||
user.setID(-1);
|
||||
sendSync.getUsers().add(user);
|
||||
|
||||
Sync returnSendSync = post(
|
||||
String
|
||||
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
||||
Sync returnSendSync = post(String.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
||||
sendSync,
|
||||
Sync.class);
|
||||
return returnSendSync;
|
||||
@ -85,9 +82,7 @@ public class Client {
|
||||
user.setName(name);
|
||||
senderSync.getUsers().add(user);
|
||||
|
||||
Sync returnSenderSync = post(
|
||||
String
|
||||
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
||||
Sync returnSenderSync = post(String.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0),
|
||||
senderSync,
|
||||
Sync.class);
|
||||
|
||||
@ -134,7 +129,8 @@ public class Client {
|
||||
* their updated UserStatus to the client.) <br>
|
||||
*
|
||||
* @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
|
||||
* @since Envoy v0.1-alpha
|
||||
*/
|
||||
@ -151,10 +147,7 @@ public class Client {
|
||||
}
|
||||
|
||||
// Send sync
|
||||
return post(String
|
||||
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), userId),
|
||||
sync,
|
||||
Sync.class);
|
||||
return post(String.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.
|
||||
* @since Envoy v0.1-alpha
|
||||
*/
|
||||
public boolean isInitialized() {
|
||||
return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null;
|
||||
}
|
||||
public boolean isInitialized() { return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null; }
|
||||
|
||||
/**
|
||||
* @return the host name of the Envoy server
|
||||
|
@ -14,6 +14,7 @@ import java.util.logging.Logger;
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
|
||||
import envoy.client.event.EnvoyLogger;
|
||||
import envoy.client.event.EventBus;
|
||||
import envoy.client.event.MessageCreationEvent;
|
||||
import envoy.exception.EnvoyException;
|
||||
@ -44,7 +45,7 @@ public class LocalDB {
|
||||
private Sync sync = 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.
|
||||
|
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>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @param <T> the type of our Event
|
||||
* @since Envoy v0.2-alpha
|
||||
*/
|
||||
public interface Event<T> {
|
||||
|
@ -12,7 +12,6 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
@ -33,6 +32,7 @@ import envoy.client.Client;
|
||||
import envoy.client.Config;
|
||||
import envoy.client.LocalDB;
|
||||
import envoy.client.Settings;
|
||||
import envoy.client.event.EnvoyLogger;
|
||||
import envoy.schema.Message;
|
||||
import envoy.schema.Sync;
|
||||
import envoy.schema.User;
|
||||
@ -68,7 +68,7 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
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) {
|
||||
this.client = client;
|
||||
@ -132,8 +132,7 @@ public class ChatWindow extends JFrame {
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER
|
||||
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0)
|
||||
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
||||
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0) || (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
||||
postMessage(messageList);
|
||||
}
|
||||
}
|
||||
@ -180,10 +179,9 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
settingsButton.addActionListener((evt) -> {
|
||||
try {
|
||||
SettingsScreen.open();
|
||||
new SettingsScreen().setVisible(true);
|
||||
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
|
||||
} catch (Exception e) {
|
||||
SettingsScreen.open();
|
||||
logger.log(Level.WARNING, "An error occured while opening the settings screen", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -245,7 +243,6 @@ public class ChatWindow extends JFrame {
|
||||
contentPane.revalidate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (!client.hasRecipient()) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Please select a recipient!",
|
||||
"Cannot send message",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!messageEnterTextArea.getText().isEmpty()) try {
|
||||
|
||||
// Create and send message object
|
||||
final Message message = localDB.createMessage(messageEnterTextArea.getText(),
|
||||
currentChat.getRecipient().getID());
|
||||
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient().getID());
|
||||
currentChat.appendMessage(message);
|
||||
messageList.setModel(currentChat.getModel());
|
||||
|
||||
@ -348,8 +341,7 @@ public class ChatWindow extends JFrame {
|
||||
new Thread(() -> {
|
||||
|
||||
// Synchronize
|
||||
localDB.applySync(
|
||||
client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID())));
|
||||
localDB.applySync(client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID())));
|
||||
|
||||
// Process unread messages
|
||||
localDB.addUnreadMessagesToLocalDB();
|
||||
@ -359,8 +351,7 @@ public class ChatWindow extends JFrame {
|
||||
readCurrentChat();
|
||||
|
||||
// Update UI
|
||||
SwingUtilities
|
||||
.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
|
||||
SwingUtilities.invokeLater(() -> { updateUserStates(); contentPane.revalidate(); contentPane.repaint(); });
|
||||
}).start();
|
||||
}).start();
|
||||
}
|
||||
@ -377,4 +368,3 @@ public class ChatWindow extends JFrame {
|
||||
*/
|
||||
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 state = value.getMetadata().getState().toString();
|
||||
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());
|
||||
|
||||
// Getting the MessageColor in the Chat of the current theme
|
||||
String textColor = null;
|
||||
|
||||
textColor = toHex(
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat());
|
||||
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());
|
||||
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>",
|
||||
setText(String.format("<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
|
||||
dateColor,
|
||||
date,
|
||||
textColor,
|
||||
|
@ -11,6 +11,7 @@ import java.awt.Insets;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
@ -25,8 +26,8 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
||||
import envoy.client.LocalDB;
|
||||
import envoy.client.Settings;
|
||||
import envoy.client.event.EnvoyLogger;
|
||||
|
||||
/**
|
||||
* 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 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 static int space = 5;
|
||||
private Theme selectedTheme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
|
||||
private Theme temporaryTheme;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(LocalDB.class.getSimpleName());
|
||||
|
||||
private static SettingsScreen settingsScreen;
|
||||
private static final Logger logger = new EnvoyLogger(SettingsScreen.class.getSimpleName());
|
||||
|
||||
// TODO: Add a JPanel with all the Information necessary:
|
||||
// change (Picture,Username, Email, Password) and toggle(light/dark mode,
|
||||
// "ctrl+enter"/"enter"
|
||||
// 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.
|
||||
*
|
||||
* @since Envoy v0.1-alpha
|
||||
*/
|
||||
private SettingsScreen() {
|
||||
public SettingsScreen() {
|
||||
logger.info(Settings.getInstance().getCurrentTheme());
|
||||
|
||||
setBounds(10, 10, 450, 650);
|
||||
@ -101,8 +85,7 @@ public class SettingsScreen extends JDialog {
|
||||
|
||||
createNewThemeButton.setEnabled(false);
|
||||
|
||||
temporaryTheme = new Theme("temporaryTheme",
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
|
||||
// Content pane
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
@ -122,7 +105,7 @@ public class SettingsScreen extends JDialog {
|
||||
@SuppressWarnings("unchecked")
|
||||
final JList<String> selectedOption = (JList<String>) listSelectionEvent.getSource();
|
||||
final String option = selectedOption.getSelectedValue();
|
||||
System.out.println(option);
|
||||
logger.log(Level.FINEST, option);
|
||||
|
||||
switch (option) {
|
||||
case "Color Themes":
|
||||
@ -183,7 +166,7 @@ public class SettingsScreen extends JDialog {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
String selectedValue = (String) themes.getSelectedItem();
|
||||
System.out.println(selectedValue);
|
||||
logger.log(Level.FINEST, 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.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.getBackgroundColor(), "Background", 1);
|
||||
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 2);
|
||||
buildCustomizeElement(new JPanel(),
|
||||
new JButton(),
|
||||
new JTextPane(),
|
||||
@ -228,41 +199,11 @@ public class SettingsScreen extends JDialog {
|
||||
theme.getInteractableBackgroundColor(),
|
||||
"Interactable Background",
|
||||
4);
|
||||
buildCustomizeElement(new JPanel(),
|
||||
new JButton(),
|
||||
new JTextPane(),
|
||||
theme,
|
||||
theme.getMessageColorChat(),
|
||||
"Messages Chat",
|
||||
5);
|
||||
buildCustomizeElement(new JPanel(),
|
||||
new JButton(),
|
||||
new JTextPane(),
|
||||
theme,
|
||||
theme.getDateColorChat(),
|
||||
"Date Chat",
|
||||
6);
|
||||
buildCustomizeElement(new JPanel(),
|
||||
new JButton(),
|
||||
new JTextPane(),
|
||||
theme,
|
||||
theme.getSelectionColor(),
|
||||
"Selection",
|
||||
7);
|
||||
buildCustomizeElement(new JPanel(),
|
||||
new JButton(),
|
||||
new JTextPane(),
|
||||
theme,
|
||||
theme.getTypingMessageColor(),
|
||||
"Typing Message",
|
||||
8);
|
||||
buildCustomizeElement(new JPanel(),
|
||||
new JButton(),
|
||||
new JTextPane(),
|
||||
theme,
|
||||
theme.getUserNameColor(),
|
||||
"User Names",
|
||||
9);
|
||||
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", 5);
|
||||
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", 6);
|
||||
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 7);
|
||||
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", 8);
|
||||
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", 9);
|
||||
|
||||
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
|
||||
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
|
||||
@ -281,18 +222,16 @@ public class SettingsScreen extends JDialog {
|
||||
createNewThemeButton.addActionListener((evt) -> {
|
||||
try {
|
||||
String s = JOptionPane.showInputDialog("Enter a name for the new theme");
|
||||
System.out.println(s);
|
||||
logger.log(Level.FINEST, s);
|
||||
Settings.getInstance()
|
||||
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(),
|
||||
temporaryTheme.getCellColor(), temporaryTheme.getInteractableForegroundColor(),
|
||||
temporaryTheme.getInteractableBackgroundColor(), temporaryTheme.getMessageColorChat(),
|
||||
temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
|
||||
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(), temporaryTheme.getCellColor(),
|
||||
temporaryTheme.getInteractableForegroundColor(), temporaryTheme.getInteractableBackgroundColor(),
|
||||
temporaryTheme.getMessageColorChat(), temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
|
||||
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
|
||||
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
||||
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
|
||||
|
||||
temporaryTheme = new Theme("temporaryTheme",
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
|
||||
createNewThemeButton.setEnabled(false);
|
||||
themes.addItem(themeArray[themeArray.length - 1]);
|
||||
@ -355,7 +294,7 @@ public class SettingsScreen extends JDialog {
|
||||
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
|
||||
|
||||
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
|
||||
System.out.println(selectedTheme.getThemeName());
|
||||
logger.log(Level.FINER, selectedTheme.getThemeName());
|
||||
|
||||
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
||||
updateColorVariables(Settings.getInstance().getCurrentTheme());
|
||||
@ -365,13 +304,17 @@ public class SettingsScreen extends JDialog {
|
||||
revalidate();
|
||||
repaint();
|
||||
} catch (Exception e) {
|
||||
logger.info("Something went wrong when changing the setting");
|
||||
settingsScreen.dispose();
|
||||
logger.warning("Something went wrong when changing the setting");
|
||||
JOptionPane.showMessageDialog(this, "Something went wrong when changing the setting");
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
|
||||
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setModal(true);
|
||||
}
|
||||
|
||||
private void changeSettingsScreenColors(String key) {
|
||||
@ -412,21 +355,12 @@ public class SettingsScreen extends JDialog {
|
||||
temporaryTheme = new Theme("temporaryTheme",
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(),
|
||||
Settings.getInstance()
|
||||
.getThemes()
|
||||
.get(Settings.getInstance().getCurrentTheme())
|
||||
.getInteractableForegroundColor(),
|
||||
Settings.getInstance()
|
||||
.getThemes()
|
||||
.get(Settings.getInstance().getCurrentTheme())
|
||||
.getInteractableBackgroundColor(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableForegroundColor(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(),
|
||||
Settings.getInstance()
|
||||
.getThemes()
|
||||
.get(Settings.getInstance().getCurrentTheme())
|
||||
.getTypingMessageColor(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getTypingMessageColor(),
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
||||
|
||||
colorsPanel.removeAll();
|
||||
@ -513,8 +447,7 @@ public class SettingsScreen extends JDialog {
|
||||
|
||||
private void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); }
|
||||
|
||||
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color,
|
||||
String name, int yIndex) {
|
||||
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color, String name, int yIndex) {
|
||||
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
|
||||
textPane.setBackground(theme.getBackgroundColor());
|
||||
textPane.setForeground(theme.getUserNameColor());
|
||||
@ -528,15 +461,11 @@ public class SettingsScreen extends JDialog {
|
||||
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.
|
||||
logger.log(Level.FINEST, String.valueOf(color.getRGB()));
|
||||
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;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import envoy.client.Client;
|
||||
import envoy.client.Config;
|
||||
import envoy.client.LocalDB;
|
||||
import envoy.client.Settings;
|
||||
import envoy.client.event.EnvoyLogger;
|
||||
import envoy.exception.EnvoyException;
|
||||
|
||||
/**
|
||||
@ -28,7 +29,7 @@ import envoy.exception.EnvoyException;
|
||||
*/
|
||||
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) {
|
||||
logger.setLevel(Level.ALL);
|
||||
|
@ -75,14 +75,10 @@ public class StatusTrayIcon implements EventHandler {
|
||||
focusTarget.addWindowFocusListener(new WindowAdapter() {
|
||||
|
||||
@Override
|
||||
public void windowGainedFocus(WindowEvent e) {
|
||||
displayMessages = false;
|
||||
}
|
||||
public void windowGainedFocus(WindowEvent e) { displayMessages = false; }
|
||||
|
||||
@Override
|
||||
public void windowLostFocus(WindowEvent e) {
|
||||
displayMessages = true;
|
||||
}
|
||||
public void windowLostFocus(WindowEvent e) { displayMessages = true; }
|
||||
});
|
||||
|
||||
// Start processing message events
|
||||
|
@ -26,9 +26,8 @@ public class Theme implements Serializable {
|
||||
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) {
|
||||
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;
|
||||
|
||||
@ -44,9 +43,8 @@ public class Theme implements Serializable {
|
||||
}
|
||||
|
||||
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);
|
||||
this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor, other.interactableForegroundColor,
|
||||
other.messageColorChat, other.dateColorChat, other.selectionColor, other.typingMessageColor, other.userNameColor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,8 +12,8 @@ import envoy.schema.User;
|
||||
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>
|
||||
* File: <strong>UserListRenderer.java</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;
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<? extends User> list, User value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
if (isSelected) {
|
||||
@ -45,22 +44,15 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
|
||||
|
||||
// Getting the UserNameColor of the current theme
|
||||
String textColor = null;
|
||||
textColor = toHex(
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
||||
textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
|
||||
switch (status) {
|
||||
case ONLINE:
|
||||
setText(String.format(
|
||||
"<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
|
||||
status,
|
||||
textColor,
|
||||
name));
|
||||
setText(String
|
||||
.format("<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>", status, textColor, name));
|
||||
break;
|
||||
case OFFLINE:
|
||||
setText(String.format(
|
||||
"<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
|
||||
status,
|
||||
textColor,
|
||||
name));
|
||||
setText(String
|
||||
.format("<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>", status, textColor, name));
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
|
Reference in New Issue
Block a user