From 8267fa4d0d708778662d7a585b846e440bd8c6bc Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 14 Dec 2019 14:58:07 +0100 Subject: [PATCH] Implemented a (not working) own version of a logger and reformatted code --- src/main/java/envoy/client/Client.java | 21 +-- src/main/java/envoy/client/Config.java | 6 +- src/main/java/envoy/client/LocalDB.java | 3 +- src/main/java/envoy/client/Settings.java | 10 +- .../java/envoy/client/event/EnvoyLogger.java | 103 +++++++++++++ src/main/java/envoy/client/event/Event.java | 1 + src/main/java/envoy/client/ui/ChatWindow.java | 32 ++-- .../envoy/client/ui/MessageListRenderer.java | 12 +- .../java/envoy/client/ui/SettingsScreen.java | 145 +++++------------- src/main/java/envoy/client/ui/Startup.java | 3 +- .../java/envoy/client/ui/StatusTrayIcon.java | 8 +- src/main/java/envoy/client/ui/Theme.java | 12 +- .../envoy/client/ui/UserListRenderer.java | 24 +-- 13 files changed, 189 insertions(+), 191 deletions(-) create mode 100644 src/main/java/envoy/client/event/EnvoyLogger.java diff --git a/src/main/java/envoy/client/Client.java b/src/main/java/envoy/client/Client.java index 8f96739..bd1555a 100644 --- a/src/main/java/envoy/client/Client.java +++ b/src/main/java/envoy/client/Client.java @@ -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.)
* * @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); } /** diff --git a/src/main/java/envoy/client/Config.java b/src/main/java/envoy/client/Config.java index bbd3b72..e9f2a18 100644 --- a/src/main/java/envoy/client/Config.java +++ b/src/main/java/envoy/client/Config.java @@ -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 @@ -114,7 +112,7 @@ public class Config { /** * Changes the default local database. * Exclusively intended for development purposes. - * + * * @param localDB the file containing the local database * @since Envoy v0.1-alpha **/ diff --git a/src/main/java/envoy/client/LocalDB.java b/src/main/java/envoy/client/LocalDB.java index f061b28..51e2eb1 100644 --- a/src/main/java/envoy/client/LocalDB.java +++ b/src/main/java/envoy/client/LocalDB.java @@ -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. diff --git a/src/main/java/envoy/client/Settings.java b/src/main/java/envoy/client/Settings.java index 91f696f..fe5d769 100644 --- a/src/main/java/envoy/client/Settings.java +++ b/src/main/java/envoy/client/Settings.java @@ -73,9 +73,9 @@ public class Settings { // Load themes from theme file try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(themeFile))) { Object obj = in.readObject(); - if(obj instanceof HashMap) themes = (Map) obj; + if (obj instanceof HashMap) themes = (Map) obj; } catch (IOException | ClassNotFoundException e) { - themes = new HashMap<>(); + themes = new HashMap<>(); currentTheme = "dark"; e.printStackTrace(); } @@ -95,15 +95,15 @@ public class Settings { * @throws IOException * @since Envoy v0.2-alpha */ - public void save() throws IOException{ + 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))) { + try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(themeFile))) { out.writeObject(themes); } } diff --git a/src/main/java/envoy/client/event/EnvoyLogger.java b/src/main/java/envoy/client/event/EnvoyLogger.java new file mode 100644 index 0000000..33e17ac --- /dev/null +++ b/src/main/java/envoy/client/event/EnvoyLogger.java @@ -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: envoy-client
+ * File: EnvoyLogger.java
+ * Created: 14 Dec 2019
+ * + * @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; + } +} diff --git a/src/main/java/envoy/client/event/Event.java b/src/main/java/envoy/client/event/Event.java index 9db2477..36e0466 100644 --- a/src/main/java/envoy/client/event/Event.java +++ b/src/main/java/envoy/client/event/Event.java @@ -6,6 +6,7 @@ package envoy.client.event; * Created: 04.12.2019
* * @author Kai S. K. Engelbart + * @param the type of our Event * @since Envoy v0.2-alpha */ public interface Event { diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 6867f5e..cafd790 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -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(); - changeChatWindowColors(Settings.getInstance().getCurrentTheme()); - } catch (Exception e) { - SettingsScreen.open(); + new SettingsScreen().setVisible(true); + changeChatWindowColors(Settings.getInstance().getCurrentTheme()); + } catch (Exception e) { logger.log(Level.WARNING, "An error occured while opening the settings screen", e); e.printStackTrace(); } @@ -235,7 +233,7 @@ public class ChatWindow extends JFrame { gbc_userList.insets = new Insets(space, space, space, space); changeChatWindowColors(Settings.getInstance().getCurrentTheme()); - + contentPane.add(userList, gbc_userList); contentPane.revalidate(); @@ -244,7 +242,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 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); } } } - diff --git a/src/main/java/envoy/client/ui/MessageListRenderer.java b/src/main/java/envoy/client/ui/MessageListRenderer.java index 2e6b65f..9be79c5 100644 --- a/src/main/java/envoy/client/ui/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/MessageListRenderer.java @@ -42,22 +42,18 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer

%s

%s :%s", + setText(String.format("

%s

%s :%s", dateColor, date, textColor, diff --git a/src/main/java/envoy/client/ui/SettingsScreen.java b/src/main/java/envoy/client/ui/SettingsScreen.java index bd80c2e..c9fea6c 100644 --- a/src/main/java/envoy/client/ui/SettingsScreen.java +++ b/src/main/java/envoy/client/ui/SettingsScreen.java @@ -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 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 Theme selectedTheme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); + private Theme temporaryTheme; - private boolean colorChanged = false; - 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.
- * - * @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 selectedOption = (JList) 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; } diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index edd5aa2..33e5c78 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -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); diff --git a/src/main/java/envoy/client/ui/StatusTrayIcon.java b/src/main/java/envoy/client/ui/StatusTrayIcon.java index 01cc8d7..fee9a7c 100644 --- a/src/main/java/envoy/client/ui/StatusTrayIcon.java +++ b/src/main/java/envoy/client/ui/StatusTrayIcon.java @@ -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 diff --git a/src/main/java/envoy/client/ui/Theme.java b/src/main/java/envoy/client/ui/Theme.java index a0ef259..7de0ea9 100644 --- a/src/main/java/envoy/client/ui/Theme.java +++ b/src/main/java/envoy/client/ui/Theme.java @@ -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; @@ -42,11 +41,10 @@ public class Theme implements Serializable { 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); + this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor, other.interactableForegroundColor, + other.messageColorChat, other.dateColorChat, other.selectionColor, other.typingMessageColor, other.userNameColor); } /** diff --git a/src/main/java/envoy/client/ui/UserListRenderer.java b/src/main/java/envoy/client/ui/UserListRenderer.java index c730e74..1ee3f84 100644 --- a/src/main/java/envoy/client/ui/UserListRenderer.java +++ b/src/main/java/envoy/client/ui/UserListRenderer.java @@ -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.
+ *
* Project: envoy-client
* File: UserListRenderer.java
* Created: 12 Oct 2019
@@ -26,7 +26,6 @@ public class UserListRenderer extends JLabel implements ListCellRenderer { private static final long serialVersionUID = 5164417379767181198L; - @SuppressWarnings("incomplete-switch") @Override public Component getListCellRendererComponent(JList list, User value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected) { @@ -44,23 +43,16 @@ public class UserListRenderer extends JLabel implements ListCellRenderer { 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()); + String textColor = null; + textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor()); switch (status) { case ONLINE: - setText(String.format( - "

%s

%s", - status, - textColor, - name)); + setText(String + .format("

%s

%s", status, textColor, name)); break; case OFFLINE: - setText(String.format( - "

%s

%s", - status, - textColor, - name)); + setText(String + .format("

%s

%s", status, textColor, name)); break; } return this;