Formatted
This commit is contained in:
parent
4ba1f6360c
commit
4d35129a67
@ -76,8 +76,7 @@ public class ChatWindow extends JFrame {
|
||||
setBounds(100, 100, 600, 800);
|
||||
setTitle("Envoy");
|
||||
setLocationRelativeTo(null);
|
||||
setIconImage(
|
||||
Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("envoy_logo.png")));
|
||||
setIconImage(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("envoy_logo.png")));
|
||||
|
||||
// Save chats when window closes
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@ -131,8 +130,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);
|
||||
}
|
||||
}
|
||||
@ -201,11 +199,7 @@ public class ChatWindow extends JFrame {
|
||||
final User user = selectedUserList.getSelectedValue();
|
||||
client.setRecipient(user);
|
||||
|
||||
currentChat = localDB.getChats()
|
||||
.stream()
|
||||
.filter(chat -> chat.getRecipient().getID() == user.getID())
|
||||
.findFirst()
|
||||
.get();
|
||||
currentChat = localDB.getChats().stream().filter(chat -> chat.getRecipient().getID() == user.getID()).findFirst().get();
|
||||
|
||||
// Set all unread messages in the chat to read
|
||||
readCurrentChat();
|
||||
@ -280,18 +274,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());
|
||||
|
||||
@ -341,8 +331,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();
|
||||
@ -352,8 +341,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();
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -16,8 +16,7 @@ import javax.swing.border.EmptyBorder;
|
||||
*/
|
||||
public class PrimaryTextArea extends JTextArea {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final long serialVersionUID = -5829028696155434913L;
|
||||
private int arcSize;
|
||||
|
||||
/**
|
||||
@ -31,8 +30,8 @@ public class PrimaryTextArea extends JTextArea {
|
||||
/**
|
||||
* Creates the text area
|
||||
*
|
||||
* @param arcSize
|
||||
* @param borderSpace - the insets of the border on all four sides
|
||||
* @param arcSize is the diameter of the arc at the four corners.
|
||||
* @param borderSpace is the insets of the border on all four sides.
|
||||
* @since Envoy 0.2-alpha
|
||||
*/
|
||||
public PrimaryTextArea(int arcSize, int borderSpace) {
|
||||
|
@ -101,8 +101,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();
|
||||
@ -200,20 +199,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 +215,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;
|
||||
@ -283,16 +240,14 @@ public class SettingsScreen extends JDialog {
|
||||
String s = JOptionPane.showInputDialog("Enter a name for the new theme");
|
||||
System.out.println(s);
|
||||
Settings.getInstance()
|
||||
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(),
|
||||
temporaryTheme.getCellColor(), temporaryTheme.getInteractableForegroundColor(),
|
||||
temporaryTheme.getInteractableBackgroundColor(), temporaryTheme.getMessageColorChat(),
|
||||
temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
|
||||
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(), temporaryTheme.getCellColor(),
|
||||
temporaryTheme.getInteractableForegroundColor(), temporaryTheme.getInteractableBackgroundColor(),
|
||||
temporaryTheme.getMessageColorChat(), temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
|
||||
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
|
||||
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
|
||||
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
|
||||
|
||||
temporaryTheme = new Theme("temporaryTheme",
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
|
||||
|
||||
createNewThemeButton.setEnabled(false);
|
||||
themes.addItem(themeArray[themeArray.length - 1]);
|
||||
@ -412,21 +367,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 +459,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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,22 +45,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