Added better dependency injection mechanism and purified LoginScene
one thing could for whatever reason not be avoided: Even though the processors of the caches inside WriteProxy are initialized, they somehow get "de-initialized" and have to be initialized again...
This commit is contained in:
@ -29,7 +29,9 @@ import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.stage.FileChooser;
|
||||
@ -39,13 +41,16 @@ 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.event.*;
|
||||
import envoy.client.event.BackEvent;
|
||||
import envoy.client.event.MessageCreationEvent;
|
||||
import envoy.client.event.SendEvent;
|
||||
import envoy.client.net.Client;
|
||||
import envoy.client.net.WriteProxy;
|
||||
import envoy.client.ui.*;
|
||||
import envoy.client.ui.listcell.*;
|
||||
import envoy.client.ui.listcell.ChatControl;
|
||||
import envoy.client.ui.listcell.ListCellFactory;
|
||||
import envoy.client.ui.listcell.MessageListCell;
|
||||
import envoy.client.util.ReflectionUtil;
|
||||
import envoy.constant.Tabs;
|
||||
import envoy.data.*;
|
||||
import envoy.data.Attachment.AttachmentType;
|
||||
import envoy.event.*;
|
||||
@ -122,42 +127,41 @@ 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;
|
||||
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 Chat currentChat;
|
||||
private AudioRecorder recorder;
|
||||
private boolean recording;
|
||||
private Attachment pendingAttachment;
|
||||
private boolean postingPermanentlyDisabled;
|
||||
|
||||
private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap();
|
||||
private Chat currentChat;
|
||||
private FilteredList<Chat> chats;
|
||||
private boolean recording;
|
||||
private Attachment pendingAttachment;
|
||||
private boolean postingPermanentlyDisabled;
|
||||
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* Initializes the appearance of certain visual components.
|
||||
*
|
||||
@ -181,24 +185,28 @@ public final class ChatScene implements Restorable {
|
||||
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 {
|
||||
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 (final IOException e2) {
|
||||
logger.log(Level.SEVERE, "An error occurred when attempting to load tabs: ", e2);
|
||||
}
|
||||
else {
|
||||
contactSearchTab.setContent(createOfflineNote());
|
||||
groupCreationTab.setContent(createOfflineNote());
|
||||
}
|
||||
});
|
||||
|
||||
//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();
|
||||
@ -284,15 +292,15 @@ public final class ChatScene implements Restorable {
|
||||
|
||||
eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { newGroupButton.setDisable(!e.get()); }));
|
||||
}
|
||||
|
||||
|
||||
private AnchorPane createOfflineNote() {
|
||||
AnchorPane anc = new AnchorPane();
|
||||
VBox vBox = new VBox();
|
||||
final var anc = new AnchorPane();
|
||||
final var vBox = new VBox();
|
||||
vBox.setAlignment(Pos.TOP_CENTER);
|
||||
vBox.setPrefWidth(316);
|
||||
Label label = new Label("You have to be online!");
|
||||
final var label = new Label("You have to be online!");
|
||||
label.setPadding(new Insets(50, 0, 5, 0));
|
||||
Button button = new Button("OK");
|
||||
final var button = new Button("OK");
|
||||
button.setOnAction(e -> eventBus.dispatch(new BackEvent()));
|
||||
vBox.getChildren().add(label);
|
||||
vBox.getChildren().add(button);
|
||||
@ -317,34 +325,6 @@ 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(); }
|
||||
|
||||
@ -423,10 +403,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.
|
||||
@ -434,15 +411,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() {
|
||||
|
Reference in New Issue
Block a user