This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/client/src/main/java/envoy/client/data/Context.java

95 lines
2.1 KiB
Java

package envoy.client.data;
import javafx.stage.Stage;
import envoy.client.net.*;
import envoy.client.ui.SceneContext;
/**
* Provides access to commonly used objects.
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public class Context {
private WriteProxy writeProxy;
private LocalDB localDB;
private Stage stage;
private SceneContext sceneContext;
private final Client client = new Client();
private static final Context instance = new Context();
private Context() {}
/**
* @return the instance of {@code Context} used throughout Envoy
* @since Envoy Client v0.2-beta
*/
public static Context getInstance() { return instance; }
/**
* Initializes the write proxy given that {@code localDB} is initialized.
*
* @since Envoy Client v0.2-beta
*/
public void initWriteProxy() {
if (localDB == null)
throw new IllegalStateException("The LocalDB has to be initialized!");
writeProxy = new WriteProxy(client, localDB);
}
/**
* @return the localDB
* @since Envoy Client v0.2-beta
*/
public LocalDB getLocalDB() { return localDB; }
/**
* @param localDB the localDB to set
* @since Envoy Client v0.2-beta
*/
public void setLocalDB(LocalDB localDB) { this.localDB = localDB; }
/**
* @return the sceneContext
* @since Envoy Client v0.2-beta
*/
public SceneContext getSceneContext() { return sceneContext; }
/**
* @param sceneContext the sceneContext to set. Additionally sets the stage.
* @since Envoy Client v0.2-beta
*/
public void setSceneContext(SceneContext sceneContext) {
this.sceneContext = sceneContext;
stage = sceneContext.getStage();
}
/**
* @return the client
* @since Envoy Client v0.2-beta
*/
public Client getClient() { return client; }
/**
* @return the writeProxy
* @since Envoy Client v0.2-beta
*/
public WriteProxy getWriteProxy() { return writeProxy; }
/**
* @return the stage
* @since Envoy Client v0.2-beta
*/
public Stage getStage() { return stage; }
/**
* @param stage the stage to set
* @since Envoy Client v0.2-beta
*/
public void setStage(Stage stage) { this.stage = stage; }
}