Merge branch 'develop' into b/icons_theme_change

This commit is contained in:
2020-09-02 11:21:36 +02:00
committed by DieGurke
20 changed files with 619 additions and 527 deletions

View File

@ -4,34 +4,23 @@ import static envoy.data.Message.MessageStatus.RECEIVED;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.*;
import javafx.animation.RotateTransition;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.*;
import javafx.collections.transformation.FilteredList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.fxml.*;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.image.*;
import javafx.scene.input.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.FileChooser;
@ -39,15 +28,12 @@ import javafx.util.Duration;
import envoy.client.data.*;
import envoy.client.data.audio.AudioRecorder;
import envoy.client.data.commands.SystemCommandBuilder;
import envoy.client.data.commands.SystemCommandsMap;
import envoy.client.data.commands.*;
import envoy.client.event.*;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
import envoy.client.net.*;
import envoy.client.ui.*;
import envoy.client.ui.listcell.*;
import envoy.client.util.ReflectionUtil;
import envoy.constant.Tabs;
import envoy.data.*;
import envoy.data.Attachment.AttachmentType;
import envoy.event.*;
@ -95,6 +81,9 @@ public final class ChatScene implements Restorable {
@FXML
private Button newGroupButton;
@FXML
private Button newContactButton;
@FXML
private TextArea messageTextArea;
@ -124,42 +113,45 @@ public final class ChatScene implements Restorable {
@FXML
private TextArea contactSearch;
@FXML
private VBox contactOperations;
@FXML
private TabPane tabPane;
@FXML
private Tab contactSearchTab;
@FXML
private Tab groupCreationTab;
private LocalDB localDB;
private Client client;
private WriteProxy writeProxy;
private SceneContext sceneContext;
@FXML
private HBox contactSpecificOnlineOperations;
private Chat currentChat;
private AudioRecorder recorder;
private boolean recording;
private Attachment pendingAttachment;
private boolean postingPermanentlyDisabled;
private boolean isCustomAttachmentImage = false;
private Chat currentChat;
private FilteredList<Chat> chats;
private boolean recording;
private Attachment pendingAttachment;
private boolean postingPermanentlyDisabled;
private boolean isCustomAttachmentImage = false;
private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap();
private final LocalDB localDB = context.getLocalDB();
private final Client client = context.getClient();
private final WriteProxy writeProxy = context.getWriteProxy();
private final SceneContext sceneContext = context.getSceneContext();
private final AudioRecorder recorder = new AudioRecorder();
private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap();
private final Tooltip onlyIfOnlineTooltip = new Tooltip("You need to be online to do this");
private static final Settings settings = Settings.getInstance();
private static final EventBus eventBus = EventBus.getInstance();
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
private static Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20);
private static Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20);
private static final int MAX_MESSAGE_LENGTH = 255;
private static final int DEFAULT_ICON_SIZE = 16;
private FilteredList<Chat> chats;
private static final Settings settings = Settings.getInstance();
private static final EventBus eventBus = EventBus.getInstance();
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
private static final Context context = Context.getInstance();
private static final int MAX_MESSAGE_LENGTH = 255;
private static final int DEFAULT_ICON_SIZE = 16;
/**
* Initializes the appearance of certain visual components.
@ -178,30 +170,41 @@ public final class ChatScene implements Restorable {
attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE);
messageSearchButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("search", DEFAULT_ICON_SIZE)));
clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43));
final Rectangle clip = new Rectangle();
onlyIfOnlineTooltip.setShowDelay(Duration.millis(250));
final var clip = new Rectangle();
clip.setWidth(43);
clip.setHeight(43);
clip.setArcHeight(43);
clip.setArcWidth(43);
clientProfilePic.setClip(clip);
chatList.setItems(chats = new FilteredList<>(FXCollections.observableList(localDB.getChats())));
contactLabel.setText(localDB.getUser().getName());
initializeSystemCommandsMap();
Platform.runLater(() -> {
if(client.isOnline()) {
try {
contactSearchTab.setContent(FXMLLoader.load(new File("src/main/resources/fxml/ContactSearchTab.fxml").toURI().toURL()));
groupCreationTab.setContent(FXMLLoader.load(new File("src/main/resources/fxml/GroupCreationTab.fxml").toURI().toURL()));
} catch (IOException e2) {
logger.log(Level.SEVERE, "An error occurred when attempting to load tabs: ", e2);
}
} else {
contactSearchTab.setContent(createOfflineNote());
groupCreationTab.setContent(createOfflineNote());
final var online = client.isOnline();
// no check will be performed in case it has already been disabled - a negative
// GroupCreationResult might have been returned
if (!newGroupButton.isDisabled()) newGroupButton.setDisable(!online);
newContactButton.setDisable(!online);
if (online) try {
Tooltip.uninstall(contactSpecificOnlineOperations, onlyIfOnlineTooltip);
contactSearchTab.setContent(new FXMLLoader().load(getClass().getResourceAsStream("/fxml/ContactSearchTab.fxml")));
groupCreationTab.setContent(new FXMLLoader().load(getClass().getResourceAsStream("/fxml/GroupCreationTab.fxml")));
} catch (final IOException e2) {
logger.log(Level.SEVERE, "An error occurred when attempting to load tabs: ", e2);
}
else {
Tooltip.install(contactSpecificOnlineOperations, onlyIfOnlineTooltip);
updateInfoLabel("You are offline", "info-label-warning");
}
});
//Listen to backEvents
eventBus.register(BackEvent.class, e -> tabPane.getSelectionModel().select(Tabs.CONTACT_LIST));
// Listen to backEvents
eventBus.register(BackEvent.class, e -> tabPane.getSelectionModel().select(Tabs.CONTACT_LIST.ordinal()));
// Listen to received messages
eventBus.register(MessageCreationEvent.class, e -> {
final var message = e.get();
@ -301,22 +304,6 @@ public final class ChatScene implements Restorable {
else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
});
}
private AnchorPane createOfflineNote() {
AnchorPane anc = new AnchorPane();
VBox vBox = new VBox();
vBox.setAlignment(Pos.TOP_CENTER);
vBox.setPrefWidth(316);
Label label = new Label("You have to be online!");
label.setPadding(new Insets(50, 0, 5, 0));
Button button = new Button("OK");
button.setOnAction(e -> eventBus.dispatch(new BackEvent()));
vBox.getChildren().add(label);
vBox.getChildren().add(button);
anc.getChildren().add(vBox);
anc.setId("note-background");
return anc;
}
/**
* Initializes all {@code SystemCommands} used in {@code ChatScene}.
@ -334,38 +321,8 @@ public final class ChatScene implements Restorable {
messageTextAreaCommands.add("DABR", builder.build());
}
/**
* Initializes all necessary data via dependency injection-
*
* @param sceneContext the scene context used to load other scenes
* @param localDB the local database form which chats and users are loaded
* @param client the client used to request ID generators
* @param writeProxy the write proxy used to send messages and other data to
* the server
* @since Envoy Client v0.1-beta
*/
public void initializeData(SceneContext sceneContext, LocalDB localDB, Client client, WriteProxy writeProxy) {
this.sceneContext = sceneContext;
this.localDB = localDB;
this.client = client;
this.writeProxy = writeProxy;
chats = new FilteredList<>(FXCollections.observableList(localDB.getChats()));
chatList.setItems(chats);
contactLabel.setText(localDB.getUser().getName());
MessageControl.setLocalDB(localDB);
MessageControl.setSceneContext(sceneContext);
if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info");
recorder = new AudioRecorder();
initializeSystemCommandsMap();
}
@Override
public void onRestore() {
updateRemainingCharsLabel();
}
public void onRestore() { updateRemainingCharsLabel(); }
/**
* Actions to perform when the list of contacts has been clicked.
@ -442,10 +399,7 @@ public final class ChatScene implements Restorable {
* @since Envoy Client v0.1-beta
*/
@FXML
private void settingsButtonClicked() {
sceneContext.load(SceneContext.SceneInfo.SETTINGS_SCENE);
sceneContext.<SettingsScene>getController().initializeData(sceneContext, client);
}
private void settingsButtonClicked() { sceneContext.load(SceneContext.SceneInfo.SETTINGS_SCENE); }
/**
* Actions to perform when the "Add Contact" - Button has been clicked.
@ -453,15 +407,10 @@ public final class ChatScene implements Restorable {
* @since Envoy Client v0.1-beta
*/
@FXML
private void addContactButtonClicked() {
tabPane.getSelectionModel().select(Tabs.CONTACT_SEARCH);
}
private void addContactButtonClicked() { tabPane.getSelectionModel().select(Tabs.CONTACT_SEARCH.ordinal()); }
@FXML
private void groupCreationButtonClicked() {
eventBus.dispatch(new LoadGroupCreationEvent(localDB));
tabPane.getSelectionModel().select(Tabs.GROUP_CREATION);
}
private void groupCreationButtonClicked() { tabPane.getSelectionModel().select(Tabs.GROUP_CREATION.ordinal()); }
@FXML
private void voiceButtonClicked() {
@ -624,7 +573,7 @@ public final class ChatScene implements Restorable {
if (!infoLabel.getText().equals(noMoreMessaging))
// Informing the user that he is a f*cking moron and should use Envoy online
// because he ran out of messageIDs to use
updateInfoLabel(noMoreMessaging, "infoLabel-error");
updateInfoLabel(noMoreMessaging, "info-label-error");
}
}
@ -669,7 +618,7 @@ public final class ChatScene implements Restorable {
postButton.setDisable(true);
messageTextArea.setDisable(true);
messageTextArea.clear();
updateInfoLabel("You need to go online to send more messages", "infoLabel-error");
updateInfoLabel("You need to go online to send more messages", "info-label-error");
return;
}
final var text = messageTextArea.getText().strip();