Cleanup, fixed offline cache relay when starting in offline mode
This commit is contained in:
parent
577ee6364d
commit
48e1d791c6
@ -127,7 +127,6 @@ public class Settings {
|
|||||||
* @param themeName the name to set
|
* @param themeName the name to set
|
||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void setCurrentTheme(String themeName) { ((SettingsItem<String>) items.get("currentTheme")).set(themeName); }
|
public void setCurrentTheme(String themeName) { ((SettingsItem<String>) items.get("currentTheme")).set(themeName); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,7 +145,6 @@ public class Settings {
|
|||||||
* conjunction with the {@code Control} key.
|
* conjunction with the {@code Control} key.
|
||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void setEnterToSend(boolean enterToSend) { ((SettingsItem<Boolean>) items.get("enterToSend")).set(enterToSend); }
|
public void setEnterToSend(boolean enterToSend) { ((SettingsItem<Boolean>) items.get("enterToSend")).set(enterToSend); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +159,6 @@ public class Settings {
|
|||||||
* @param currentOnCloseMode the on close mode that should be set.
|
* @param currentOnCloseMode the on close mode that should be set.
|
||||||
* @since Envoy v0.3-alpha
|
* @since Envoy v0.3-alpha
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void setCurrentOnCloseMode(boolean currentOnCloseMode) { ((SettingsItem<Boolean>) items.get("onCloseMode")).set(currentOnCloseMode); }
|
public void setCurrentOnCloseMode(boolean currentOnCloseMode) { ((SettingsItem<Boolean>) items.get("onCloseMode")).set(currentOnCloseMode); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,11 +103,6 @@ public class ChatWindow extends JFrame {
|
|||||||
gbl_contentPane.rowWeights = new double[] { 0.03, 0.001, 1.0, 0.005 };
|
gbl_contentPane.rowWeights = new double[] { 0.03, 0.001, 1.0, 0.005 };
|
||||||
contentPane.setLayout(gbl_contentPane);
|
contentPane.setLayout(gbl_contentPane);
|
||||||
|
|
||||||
// TODO: messageList.setFocusTraversalKeysEnabled(false);
|
|
||||||
// messageList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
|
|
||||||
|
|
||||||
// messageList.setFont(new Font("Arial", Font.PLAIN, 17));
|
|
||||||
// messageList.setFixedCellHeight(60);
|
|
||||||
messageList.setBorder(new EmptyBorder(space, space, space, space));
|
messageList.setBorder(new EmptyBorder(space, space, space, space));
|
||||||
|
|
||||||
scrollPane.setViewportView(messageList);
|
scrollPane.setViewportView(messageList);
|
||||||
@ -164,14 +159,7 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
gbc_moveSelectionSettingsButton.insets = insets;
|
gbc_moveSelectionSettingsButton.insets = insets;
|
||||||
|
|
||||||
settingsButton.addActionListener((evt) -> {
|
settingsButton.addActionListener(evt -> new SettingsScreen().setVisible(true));
|
||||||
try {
|
|
||||||
new SettingsScreen().setVisible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.log(Level.WARNING, "An error occured while opening the settings screen", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
contentPane.add(settingsButton, gbc_moveSelectionSettingsButton);
|
contentPane.add(settingsButton, gbc_moveSelectionSettingsButton);
|
||||||
|
|
||||||
// Partner name display
|
// Partner name display
|
||||||
@ -260,35 +248,35 @@ public class ChatWindow extends JFrame {
|
|||||||
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent evt) {
|
||||||
if (client.isOnline()) {
|
if (client.isOnline()) {
|
||||||
try {
|
if (searchField.getText().isEmpty()) {
|
||||||
if (!searchField.getText().isEmpty()) {
|
contactsModel.clear();
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
client.sendEvent(new ContactSearchRequest(searchField.getText()));
|
client.sendEvent(new ContactSearchRequest(searchField.getText()));
|
||||||
} else {
|
} catch (IOException e) {
|
||||||
contactsModel.clear();
|
e.printStackTrace();
|
||||||
revalidate();
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertUpdate(DocumentEvent e) {
|
public void insertUpdate(DocumentEvent evt) {
|
||||||
if (client.isOnline()) {
|
if (client.isOnline()) {
|
||||||
try {
|
try {
|
||||||
if (!searchField.getText().isEmpty()) { client.sendEvent(new ContactSearchRequest(searchField.getText())); }
|
client.sendEvent(new ContactSearchRequest(searchField.getText()));
|
||||||
} catch (IOException e1) {
|
} catch (IOException e) {
|
||||||
e1.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void changedUpdate(DocumentEvent e) {}
|
public void changedUpdate(DocumentEvent evt) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
GridBagConstraints gbc_cancelButton = new GridBagConstraints();
|
GridBagConstraints gbc_cancelButton = new GridBagConstraints();
|
||||||
@ -316,7 +304,6 @@ public class ChatWindow extends JFrame {
|
|||||||
searchPane.add(possibleContacts, gbc_possibleContacts);
|
searchPane.add(possibleContacts, gbc_possibleContacts);
|
||||||
|
|
||||||
// Contacts Header
|
// Contacts Header
|
||||||
|
|
||||||
GridBagConstraints gbc_contactsHeader = new GridBagConstraints();
|
GridBagConstraints gbc_contactsHeader = new GridBagConstraints();
|
||||||
gbc_contactsHeader.fill = GridBagConstraints.BOTH;
|
gbc_contactsHeader.fill = GridBagConstraints.BOTH;
|
||||||
gbc_contactsHeader.gridx = 0;
|
gbc_contactsHeader.gridx = 0;
|
||||||
@ -400,6 +387,7 @@ public class ChatWindow extends JFrame {
|
|||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listen to contact search results
|
||||||
EventBus.getInstance().register(ContactSearchResult.class, (evt) -> {
|
EventBus.getInstance().register(ContactSearchResult.class, (evt) -> {
|
||||||
contactsModel.clear();
|
contactsModel.clear();
|
||||||
final java.util.List<User> contacts = (List<User>) evt.get();
|
final java.util.List<User> contacts = (List<User>) evt.get();
|
||||||
@ -409,8 +397,8 @@ public class ChatWindow extends JFrame {
|
|||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add new contacts to the contact list
|
||||||
EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> {
|
EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> {
|
||||||
|
|
||||||
User contact = (User) evt.get();
|
User contact = (User) evt.get();
|
||||||
|
|
||||||
// Clearing the search field and the searchResultList
|
// Clearing the search field and the searchResultList
|
||||||
|
@ -28,26 +28,20 @@ import envoy.event.EventBus;
|
|||||||
public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JComponent getListCellComponent(ComponentList<? extends User> list, User value, boolean isSelected) {
|
public JComponent getListCellComponent(ComponentList<? extends User> list, User user, boolean isSelected) {
|
||||||
final JPanel panel = new JPanel();
|
final JPanel panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
panel.setBackground(Color.DARK_GRAY);
|
panel.setBackground(Color.DARK_GRAY);
|
||||||
panel.setForeground(Color.RED);
|
panel.setForeground(Color.RED);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
panel.setBackground(list.getBackground());
|
panel.setBackground(list.getBackground());
|
||||||
panel.setForeground(list.getForeground());
|
panel.setForeground(list.getForeground());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle message attachments
|
JLabel display = new JLabel(String.format("<html><p style=\"color:%s\">%s</html>",
|
||||||
|
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex(),
|
||||||
final String text = value.getName();
|
user.getName()));
|
||||||
|
|
||||||
// Getting the UserColor in the Chat of the current theme
|
|
||||||
String textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex();
|
|
||||||
|
|
||||||
JLabel display = new JLabel(String.format("<html><p style=\"color:%s\">%s</html>", textColor, text));
|
|
||||||
display.setAlignmentX(Component.LEFT_ALIGNMENT);
|
display.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
display.setAlignmentY(Component.CENTER_ALIGNMENT);
|
display.setAlignmentY(Component.CENTER_ALIGNMENT);
|
||||||
display.setFont(new Font("Arial", Font.PLAIN, 16));
|
display.setFont(new Font("Arial", Font.PLAIN, 16));
|
||||||
@ -63,7 +57,7 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
|||||||
add.setForeground(list.getForeground());
|
add.setForeground(list.getForeground());
|
||||||
|
|
||||||
add.addActionListener(evt -> {
|
add.addActionListener(evt -> {
|
||||||
ContactOperationEvent contactsOperationEvent = new ContactOperationEvent(value, ContactOperationEvent.Operation.ADD);
|
ContactOperationEvent contactsOperationEvent = new ContactOperationEvent(user, ContactOperationEvent.Operation.ADD);
|
||||||
EventBus.getInstance().dispatch(contactsOperationEvent);
|
EventBus.getInstance().dispatch(contactsOperationEvent);
|
||||||
EventBus.getInstance().dispatch(new SendEvent(contactsOperationEvent));
|
EventBus.getInstance().dispatch(new SendEvent(contactsOperationEvent));
|
||||||
});
|
});
|
||||||
|
@ -163,7 +163,7 @@ public class Startup {
|
|||||||
chatWindow.initContent(client, localDb, writeProxy);
|
chatWindow.initContent(client, localDb, writeProxy);
|
||||||
|
|
||||||
// Relay unread messages from cache
|
// Relay unread messages from cache
|
||||||
if (cache != null) cache.relay();
|
if (cache != null && client.isOnline()) cache.relay();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new StatusTrayIcon(chatWindow).show();
|
new StatusTrayIcon(chatWindow).show();
|
||||||
|
Reference in New Issue
Block a user