Apply suggestions by @kske
This commit is contained in:
parent
3c8c544cbd
commit
1d191858fe
@ -1,12 +1,10 @@
|
|||||||
package envoy.client.event;
|
package envoy.client.event;
|
||||||
|
|
||||||
import envoy.data.User;
|
|
||||||
import envoy.data.User.UserStatus;
|
import envoy.data.User.UserStatus;
|
||||||
import envoy.event.Event;
|
import envoy.event.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conveys the action that the currently logged in {@link User} has changed his
|
* Signifies a manual status change of the client user.
|
||||||
* status (manually).
|
|
||||||
*
|
*
|
||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @since Envoy Client v0.3-beta
|
* @since Envoy Client v0.3-beta
|
||||||
@ -16,7 +14,7 @@ public class OwnStatusChange extends Event<UserStatus> {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param value the new user status of the currently logged in user
|
* @param value the new user status of the client user
|
||||||
* @since Envoy Client v0.3-beta
|
* @since Envoy Client v0.3-beta
|
||||||
*/
|
*/
|
||||||
public OwnStatusChange(UserStatus value) { super(value); }
|
public OwnStatusChange(UserStatus value) { super(value); }
|
||||||
|
@ -22,8 +22,18 @@ public final class ShutdownHelper {
|
|||||||
*
|
*
|
||||||
* @since Envoy Client v0.2-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public static void exit() {
|
public static void exit() { exit(false); }
|
||||||
if (Settings.getInstance().isHideOnClose() && StatusTrayIcon.isSupported()) Context.getInstance().getStage().setIconified(true);
|
|
||||||
|
/**
|
||||||
|
* Exits Envoy immediately if {@code force = true},
|
||||||
|
* else it can exit or minimize Envoy, depending on the current state of
|
||||||
|
* {@link Settings#isHideOnClose()} and {@link StatusTrayIcon#isSupported()}.
|
||||||
|
*
|
||||||
|
* @param force whether to close in any case.
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
|
*/
|
||||||
|
public static void exit(boolean force) {
|
||||||
|
if (!force && Settings.getInstance().isHideOnClose() && StatusTrayIcon.isSupported()) Context.getInstance().getStage().setIconified(true);
|
||||||
else {
|
else {
|
||||||
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
@ -6,6 +6,7 @@ import java.awt.TrayIcon.MessageType;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import envoy.client.event.OwnStatusChange;
|
||||||
import envoy.client.helper.ShutdownHelper;
|
import envoy.client.helper.ShutdownHelper;
|
||||||
import envoy.client.util.*;
|
import envoy.client.util.*;
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
@ -56,27 +57,28 @@ public final class StatusTrayIcon implements EventListener {
|
|||||||
|
|
||||||
// Adding the exit menu item
|
// Adding the exit menu item
|
||||||
final var exitMenuItem = new MenuItem("Exit");
|
final var exitMenuItem = new MenuItem("Exit");
|
||||||
exitMenuItem.addActionListener(evt -> ShutdownHelper.exit());
|
exitMenuItem.addActionListener(evt -> ShutdownHelper.exit(true));
|
||||||
popup.add(exitMenuItem);
|
popup.add(exitMenuItem);
|
||||||
|
|
||||||
// Adding the logout menu item
|
// Adding the logout menu item
|
||||||
final var logoutMenuItem = new MenuItem("Logout");
|
final var logoutMenuItem = new MenuItem("Logout");
|
||||||
logoutMenuItem.addActionListener(evt -> { hide(); UserUtil.logout(); });
|
logoutMenuItem.addActionListener(evt -> { hide(); Platform.runLater(UserUtil::logout); });
|
||||||
popup.add(exitMenuItem);
|
popup.add(logoutMenuItem);
|
||||||
|
|
||||||
// Adding the status change items
|
// Adding the status change items
|
||||||
final var statusSubMenu = new Menu("Change status");
|
final var statusSubMenu = new Menu("Change status");
|
||||||
for (final var status : UserStatus.values()) {
|
for (final var status : UserStatus.values()) {
|
||||||
final var statusMenuItem = new MenuItem(status.toString().toLowerCase());
|
final var statusMenuItem = new MenuItem(status.toString().toLowerCase());
|
||||||
statusMenuItem.addActionListener(evt -> UserUtil.changeStatus(status));
|
statusMenuItem.addActionListener(evt -> Platform.runLater(() -> UserUtil.changeStatus(status)));
|
||||||
statusSubMenu.add(statusMenuItem);
|
statusSubMenu.add(statusMenuItem);
|
||||||
}
|
}
|
||||||
popup.add(statusSubMenu);
|
popup.add(statusSubMenu);
|
||||||
|
|
||||||
trayIcon.setPopupMenu(popup);
|
trayIcon.setPopupMenu(popup);
|
||||||
|
|
||||||
// Only display messages if the stage is not focused
|
// Only display messages if the stage is not focused and the current user status
|
||||||
stage.focusedProperty().addListener((ov, onHidden, onShown) -> displayMessages = !ov.getValue());
|
// is not BUSY (if BUSY, displayMessages will be false)
|
||||||
|
stage.focusedProperty().addListener((ov, wasFocused, isFocused) -> displayMessages = !displayMessages && wasFocused ? false : !isFocused);
|
||||||
|
|
||||||
// Show the window if the user clicks on the icon
|
// Show the window if the user clicks on the icon
|
||||||
trayIcon.addActionListener(evt -> Platform.runLater(() -> { stage.setIconified(false); stage.toFront(); stage.requestFocus(); }));
|
trayIcon.addActionListener(evt -> Platform.runLater(() -> { stage.setIconified(false); stage.toFront(); stage.requestFocus(); }));
|
||||||
@ -103,6 +105,9 @@ public final class StatusTrayIcon implements EventListener {
|
|||||||
*/
|
*/
|
||||||
public void hide() { SystemTray.getSystemTray().remove(trayIcon); }
|
public void hide() { SystemTray.getSystemTray().remove(trayIcon); }
|
||||||
|
|
||||||
|
@Event
|
||||||
|
private void onOwnStatusChange(OwnStatusChange statusChange) { displayMessages = !statusChange.get().equals(UserStatus.BUSY); }
|
||||||
|
|
||||||
@Event
|
@Event
|
||||||
private void onMessage(Message message) {
|
private void onMessage(Message message) {
|
||||||
if (displayMessages) trayIcon
|
if (displayMessages) trayIcon
|
||||||
|
@ -74,7 +74,7 @@ public final class ChatSceneCommands {
|
|||||||
alert.setContentText("Please provide an existing status");
|
alert.setContentText("Please provide an existing status");
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
}).setDescription("Changes your status to the given status.").setNumberOfArguments(1).setDefaults("OFFLINE").build("status");
|
}).setDescription("Changes your status to the given status.").setNumberOfArguments(1).setDefaults("").build("status");
|
||||||
|
|
||||||
// Selection of a new message initialization
|
// Selection of a new message initialization
|
||||||
messageDependantAction("s",
|
messageDependantAction("s",
|
||||||
|
@ -194,7 +194,6 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
settingsButton.setAlignment(Pos.BOTTOM_RIGHT);
|
settingsButton.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
HBox.setHgrow(spaceBetweenUserAndSettingsButton, Priority.ALWAYS);
|
HBox.setHgrow(spaceBetweenUserAndSettingsButton, Priority.ALWAYS);
|
||||||
generateOwnStatusControl();
|
generateOwnStatusControl();
|
||||||
System.out.println(ownContactControl.getChildren());
|
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
final var online = client.isOnline();
|
final var online = client.isOnline();
|
||||||
@ -270,9 +269,6 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Event(eventType = OwnStatusChange.class, priority = 50)
|
|
||||||
private void onOwnStatusChange() { generateOwnStatusControl(); }
|
|
||||||
|
|
||||||
@Event
|
@Event
|
||||||
private void onContactOperation(ContactOperation operation) {
|
private void onContactOperation(ContactOperation operation) {
|
||||||
final var contact = operation.get();
|
final var contact = operation.get();
|
||||||
@ -379,6 +375,7 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43));
|
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43));
|
||||||
} else {
|
} else {
|
||||||
topBarStatusLabel.setText(currentChat.getRecipient().getContacts().size() + " members");
|
topBarStatusLabel.setText(currentChat.getRecipient().getContacts().size() + " members");
|
||||||
|
topBarStatusLabel.getStyleClass().clear();
|
||||||
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
|
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
|
||||||
}
|
}
|
||||||
final var clip = new Rectangle();
|
final var clip = new Rectangle();
|
||||||
@ -719,6 +716,7 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
attachmentView.setVisible(visible);
|
attachmentView.setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Event(eventType = OwnStatusChange.class, priority = 50)
|
||||||
private void generateOwnStatusControl() {
|
private void generateOwnStatusControl() {
|
||||||
final var ownUserControl = new ContactControl(localDB.getUser());
|
final var ownUserControl = new ContactControl(localDB.getUser());
|
||||||
ownUserControl.setAlignment(Pos.CENTER_LEFT);
|
ownUserControl.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
@ -59,11 +59,7 @@ public final class GeneralSettingsPane extends SettingsPane {
|
|||||||
statusComboBox.getItems().setAll(UserStatus.values());
|
statusComboBox.getItems().setAll(UserStatus.values());
|
||||||
statusComboBox.setValue(context.getLocalDB().getUser().getStatus());
|
statusComboBox.setValue(context.getLocalDB().getUser().getStatus());
|
||||||
statusComboBox.setTooltip(new Tooltip("Change your current status"));
|
statusComboBox.setTooltip(new Tooltip("Change your current status"));
|
||||||
statusComboBox.setOnAction(e -> {
|
statusComboBox.setOnAction(e -> UserUtil.changeStatus(statusComboBox.getValue()));
|
||||||
final var status = statusComboBox.getValue();
|
|
||||||
if (status == null) return;
|
|
||||||
else UserUtil.changeStatus(status);
|
|
||||||
});
|
|
||||||
getChildren().add(statusComboBox);
|
getChildren().add(statusComboBox);
|
||||||
|
|
||||||
final var logoutButton = new Button("Logout");
|
final var logoutButton = new Button("Logout");
|
||||||
|
Reference in New Issue
Block a user