Cleanup, fixed offline cache relay when starting in offline mode
This commit is contained in:
parent
5a718aa1c9
commit
8667409413
@ -127,7 +127,6 @@ public class Settings {
|
||||
* @param themeName the name to set
|
||||
* @since Envoy v0.2-alpha
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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.
|
||||
* @since Envoy v0.2-alpha
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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.
|
||||
* @since Envoy v0.3-alpha
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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 };
|
||||
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));
|
||||
|
||||
scrollPane.setViewportView(messageList);
|
||||
@ -164,14 +159,7 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
gbc_moveSelectionSettingsButton.insets = insets;
|
||||
|
||||
settingsButton.addActionListener((evt) -> {
|
||||
try {
|
||||
new SettingsScreen().setVisible(true);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "An error occured while opening the settings screen", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
settingsButton.addActionListener(evt -> new SettingsScreen().setVisible(true));
|
||||
contentPane.add(settingsButton, gbc_moveSelectionSettingsButton);
|
||||
|
||||
// Partner name display
|
||||
@ -260,35 +248,35 @@ public class ChatWindow extends JFrame {
|
||||
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
public void removeUpdate(DocumentEvent evt) {
|
||||
if (client.isOnline()) {
|
||||
try {
|
||||
if (!searchField.getText().isEmpty()) {
|
||||
if (searchField.getText().isEmpty()) {
|
||||
contactsModel.clear();
|
||||
revalidate();
|
||||
repaint();
|
||||
} else {
|
||||
try {
|
||||
client.sendEvent(new ContactSearchRequest(searchField.getText()));
|
||||
} else {
|
||||
contactsModel.clear();
|
||||
revalidate();
|
||||
repaint();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
public void insertUpdate(DocumentEvent evt) {
|
||||
if (client.isOnline()) {
|
||||
try {
|
||||
if (!searchField.getText().isEmpty()) { client.sendEvent(new ContactSearchRequest(searchField.getText())); }
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
client.sendEvent(new ContactSearchRequest(searchField.getText()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {}
|
||||
public void changedUpdate(DocumentEvent evt) {}
|
||||
});
|
||||
|
||||
GridBagConstraints gbc_cancelButton = new GridBagConstraints();
|
||||
@ -316,7 +304,6 @@ public class ChatWindow extends JFrame {
|
||||
searchPane.add(possibleContacts, gbc_possibleContacts);
|
||||
|
||||
// Contacts Header
|
||||
|
||||
GridBagConstraints gbc_contactsHeader = new GridBagConstraints();
|
||||
gbc_contactsHeader.fill = GridBagConstraints.BOTH;
|
||||
gbc_contactsHeader.gridx = 0;
|
||||
@ -400,6 +387,7 @@ public class ChatWindow extends JFrame {
|
||||
repaint();
|
||||
});
|
||||
|
||||
// Listen to contact search results
|
||||
EventBus.getInstance().register(ContactSearchResult.class, (evt) -> {
|
||||
contactsModel.clear();
|
||||
final java.util.List<User> contacts = (List<User>) evt.get();
|
||||
@ -409,8 +397,8 @@ public class ChatWindow extends JFrame {
|
||||
repaint();
|
||||
});
|
||||
|
||||
// Add new contacts to the contact list
|
||||
EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> {
|
||||
|
||||
User contact = (User) evt.get();
|
||||
|
||||
// Clearing the search field and the searchResultList
|
||||
|
@ -28,26 +28,20 @@ import envoy.event.EventBus;
|
||||
public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
||||
|
||||
@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();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
if (isSelected) {
|
||||
panel.setBackground(Color.DARK_GRAY);
|
||||
panel.setForeground(Color.RED);
|
||||
|
||||
} else {
|
||||
panel.setBackground(list.getBackground());
|
||||
panel.setForeground(list.getForeground());
|
||||
}
|
||||
|
||||
// TODO: Handle message attachments
|
||||
|
||||
final String text = value.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));
|
||||
JLabel display = new JLabel(String.format("<html><p style=\"color:%s\">%s</html>",
|
||||
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex(),
|
||||
user.getName()));
|
||||
display.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
display.setAlignmentY(Component.CENTER_ALIGNMENT);
|
||||
display.setFont(new Font("Arial", Font.PLAIN, 16));
|
||||
@ -63,7 +57,7 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
||||
add.setForeground(list.getForeground());
|
||||
|
||||
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(new SendEvent(contactsOperationEvent));
|
||||
});
|
||||
|
@ -163,7 +163,7 @@ public class Startup {
|
||||
chatWindow.initContent(client, localDb, writeProxy);
|
||||
|
||||
// Relay unread messages from cache
|
||||
if (cache != null) cache.relay();
|
||||
if (cache != null && client.isOnline()) cache.relay();
|
||||
|
||||
try {
|
||||
new StatusTrayIcon(chatWindow).show();
|
||||
|
Reference in New Issue
Block a user