Skip to content

Commit

Permalink
Fenêtre d'options (#53)
Browse files Browse the repository at this point in the history
* Add Options pane

* Update options pane

* Update Options pane (view)

* Add basic field in Configuration

* Apply Configuration for editor

* Corrects an error

* Add Authentification support

* Add Font selector

* Prepare for ControlFX

* Add ControlFX

* Correct font in editor

* Prepare for new LoginService

* simplify LoginService

* Finalize Authentification module
  • Loading branch information
WinXaito authored and firm1 committed Apr 20, 2016
1 parent cb968e2 commit 255ad24
Show file tree
Hide file tree
Showing 13 changed files with 931 additions and 68 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ dependencies {
'org.slf4j:slf4j-log4j12:1.7.12',
'org.fxmisc.richtext:richtextfx:0.6.10',
'de.jensd:fontawesomefx:8.9',
'org.zeroturnaround:zt-zip:1.9'
'org.zeroturnaround:zt-zip:1.9',
'org.controlsfx:controlsfx:8.40.10'
}

test {
Expand Down
48 changes: 46 additions & 2 deletions src/main/java/com/zestedesavoir/zestwriter/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.Optional;

import com.zestedesavoir.zestwriter.model.Content;
import com.zestedesavoir.zestwriter.model.Textual;
Expand All @@ -10,14 +11,19 @@
import com.zestedesavoir.zestwriter.view.MdTextController;
import com.zestedesavoir.zestwriter.view.MenuController;

import com.zestedesavoir.zestwriter.view.task.LoginService;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import javafx.concurrent.Service;
import javafx.concurrent.Worker;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Tab;
Expand All @@ -27,6 +33,7 @@
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,6 +48,7 @@ public class MainApp extends Application {
private Configuration config;
private StringBuilder key = new StringBuilder();
private Logger logger;
private MenuController menuController;
public static String[] args;

public MainApp() {
Expand Down Expand Up @@ -101,6 +109,7 @@ public void start(Stage primaryStage) {

initRootLayout();
showWriter();
initConnection();
}

public void initRootLayout() {
Expand All @@ -110,8 +119,8 @@ public void initRootLayout() {
loader.setLocation(MainApp.class.getResource("fxml/Root.fxml"));
rootLayout = loader.load();

MenuController controller = loader.getController();
controller.setMainApp(this);
menuController = loader.getController();
menuController.setMainApp(this);

scene = new Scene(rootLayout);
primaryStage.setScene(scene);
Expand Down Expand Up @@ -140,6 +149,41 @@ public void showWriter() {
}
}

public void initConnection(){
if(!config.getAuthentificationUsername().isEmpty() && !config.getAuthentificationPassword().isEmpty()){
LoginService loginTask = new LoginService(config.getAuthentificationUsername(), config.getAuthentificationPassword(), zdsutils, config);

menuController.getMenuDownload().setDisable(true);
menuController.gethBottomBox().getChildren().addAll(menuController.getLabelField());
menuController.getLabelField().textProperty().bind(loginTask.messageProperty());

loginTask.stateProperty().addListener((ObservableValue<? extends Worker.State> observableValue, Worker.State oldValue, Worker.State newValue) -> {
Alert alert = new Alert(Alert.AlertType.NONE);
alert.setTitle("Connexion");
alert.setHeaderText("Etat de connexion");

Stage dialog = (Stage)alert.getDialogPane().getScene().getWindow();
dialog.getIcons().add(new Image(getClass().getResourceAsStream("static/icons/logo.png")));

switch(newValue){
case FAILED:
case CANCELLED:
alert.setAlertType(Alert.AlertType.ERROR);
alert.setContentText("Désolé mais vous n'avez pas été authentifié sur le serveur de Zeste de Savoir.");

alert.showAndWait();
menuController.getMenuDownload().setDisable(false);
break;
case SUCCEEDED:
menuController.getMenuDownload().setDisable(false);
break;
}
});

loginTask.start();
}
}

private void loadCombinason() {
scene.addEventFilter(KeyEvent.KEY_PRESSED, t -> {
String codeStr = t.getCode().toString();
Expand Down
146 changes: 136 additions & 10 deletions src/main/java/com/zestedesavoir/zestwriter/utils/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;

import org.apache.commons.lang.math.NumberUtils;
import org.apache.http.client.fluent.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,17 +25,46 @@ public class Configuration {
private String appName = "zestwriter";
private String confFileName = "conf.properties";
private File confFile;
private final static String WORKSPACE_KEY = "data.workspace";
private final static String SMART_EDITOR_KEY = "editor.smart";
private final static String SERVER_PROTOCOL_KEY = "server.protocol";
private final static String SERVER_HOST_KEY = "server.host";
private final static String SERVER_PORT_KEY = "server.port";
private StorageSaver offlineSaver;
private StorageSaver onlineSaver;
private LocalDirectoryFactory workspaceFactory;
private final Logger logger;
private Properties props;

private final static String WORKSPACE_KEY = "data.workspace";
private final static String SMART_EDITOR_KEY = "editor.smart";
private final static String SERVER_PROTOCOL_KEY = "server.protocol";
private final static String SERVER_HOST_KEY = "server.host";
private final static String SERVER_PORT_KEY = "server.port";


public enum Options{
EditorFont("options.editor.font", "Arial"),
EditorFontSize("options.editor.fontSize", "14"),
DisplayTheme("options.display.theme", "Standard"),
AuthentificationUsername("options.authentification.username", ""),
AuthentificationPassword("options.authentification.password", ""),
AdvancedServerProtocol("options.advanced.protocol", "https"),
AdvancedServerHost("options.advanced.host", "zestedesavoir.com"),
AdvancedServerPort("options.advanced.port", "80");

private String key;
private String defaultValue;

Options(String key, String defaultValue){
this.key = key;
this.defaultValue = defaultValue;
}

public String getKey(){
return key;
}

public String getDefaultValue(){
return defaultValue;
}
}

public Configuration(String homeDir) {
logger = LoggerFactory.getLogger(Configuration.class);
String confDirPath = homeDir+File.separator+"."+this.appName;
Expand Down Expand Up @@ -79,7 +109,7 @@ public Configuration(String homeDir) {
}
}

private void saveConfFile() {
public void saveConfFile() {
try {
conf.store(new FileOutputStream(confFile), "");
logger.info("Fichier de configuration enregistré");
Expand Down Expand Up @@ -172,10 +202,6 @@ public void loadWorkspace() throws IOException{

}

public Properties getProps() {
return props;
}

public String getLastRelease() {
String projecUrlRelease = "https://api.github.com/repos/firm1/zest-writer/releases/latest";

Expand All @@ -192,7 +218,107 @@ public String getLastRelease() {
e.printStackTrace();
}
return null;
}

/*
* Zest-Writer options
*/
public String getEditorFont(){
if(conf.containsKey(Options.EditorFont.getKey()))
return conf.getProperty(Options.EditorFont.getKey());
else
return Options.EditorFont.getDefaultValue();
}

public void setEditorFont(String font){
conf.setProperty(Options.EditorFont.getKey(), font);
}

public double getEditorFontsize(){
if(conf.containsKey(Options.EditorFontSize.getKey())){
if(NumberUtils.isNumber(conf.getProperty(Options.EditorFontSize.getKey())))
return Double.parseDouble(conf.getProperty(Options.EditorFontSize.getKey()));
else
return Double.parseDouble(Options.EditorFontSize.getDefaultValue());
}else{
return Double.parseDouble(Options.EditorFontSize.getDefaultValue());
}
}
public void setEditorFontSize(String fontSize){
conf.setProperty(Options.EditorFontSize.getKey(), fontSize);
}

public String getDisplayTheme(){
if(conf.containsKey(Options.DisplayTheme.getKey()))
return conf.getProperty(Options.DisplayTheme.getKey());
else
return Options.DisplayTheme.getDefaultValue();
}
public void setDisplayTheme(String displayTheme){
conf.setProperty(Options.DisplayTheme.getKey(), displayTheme);
}

public String getAuthentificationUsername(){
if(conf.containsKey(Options.AuthentificationUsername.getKey()))
return conf.getProperty(Options.AuthentificationUsername.getKey());
else
return Options.AuthentificationUsername.getDefaultValue();
}
public void setAuthentificationUsername(String username){
conf.setProperty(Options.AuthentificationUsername.getKey(), username);
}

public String getAuthentificationPassword(){
if(conf.containsKey(Options.AuthentificationPassword.getKey()))
return conf.getProperty(Options.AuthentificationPassword.getKey());
else
return Options.AuthentificationPassword.getDefaultValue();
}

public void setAuthentificationPassword(String password){
conf.setProperty(Options.AuthentificationPassword.getKey(), password);
}

public String getAdvancedServerProtocol(){
if(conf.containsKey(Options.AdvancedServerProtocol.getKey()))
return conf.getProperty(Options.AdvancedServerProtocol.getKey());
else
return Options.AdvancedServerProtocol.getDefaultValue();
}

public void setAdvancedServerProtocol(String protocol){
conf.setProperty(Options.AdvancedServerProtocol.getKey(), protocol);
}

public String getAdvancedServerHost(){
if(conf.containsKey(Options.AdvancedServerHost.getKey()))
return conf.getProperty(Options.AdvancedServerHost.getKey());
else
return Options.AdvancedServerHost.getDefaultValue();
}

public void setAdvancedServerHost(String host){
conf.setProperty(Options.AdvancedServerHost.getKey(), host);
}

public String getAdvancedServerPort(){
if(conf.containsKey(Options.AdvancedServerPort.getKey()))
return conf.getProperty(Options.AdvancedServerPort.getKey());
else
return Options.AdvancedServerPort.getDefaultValue();
}

public void setAdvancedServerPort(String port){
conf.setProperty(Options.AdvancedServerPort.getKey(), port);
}

public void resetAuthentification(){
setAuthentificationUsername("");
setAuthentificationPassword("");
saveConfFile();
}

public Properties getProps() {
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.List;
import java.util.Optional;

import com.zestedesavoir.zestwriter.utils.Configuration;
import com.ziclix.python.sql.pipe.Source;
import javafx.scene.text.Font;
import org.apache.commons.lang.StringEscapeUtils;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.StyleClassedTextArea;
Expand Down Expand Up @@ -52,6 +55,8 @@
import javafx.util.Pair;

public class MdConvertController {
private MainApp mainApp;
private Configuration config;
private MdTextController mdBox;
private Tab tab;
private Textual extract;
Expand Down Expand Up @@ -283,6 +288,8 @@ public void redo() {
}

public void setMdBox(MdTextController mdBox, Textual extract, Tab tab) throws IOException {
this.mainApp = mdBox.getMainApp();
this.config = mainApp.getConfig();
this.mdBox = mdBox;
this.tab = tab;
this.extract = extract;
Expand All @@ -291,6 +298,8 @@ public void setMdBox(MdTextController mdBox, Textual extract, Tab tab) throws IO
loader.setLocation(MainApp.class.getResource("fxml/Editor.fxml"));
SplitPane writer = loader.load();

SourceText.setFont(new Font(config.getEditorFont(), config.getEditorFontsize()));
SourceText.setStyle("-fx-font-family: \"" + config.getEditorFont() + "\";");
SourceText.replaceText(extract.getMarkdown());
SourceText.textProperty().addListener((observableValue, s, s2) -> {
tab.setText("! " + extract.getTitle());
Expand Down

0 comments on commit 255ad24

Please sign in to comment.