Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fenêtre d'options #53

Merged
merged 18 commits into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 128 additions & 5 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.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -21,15 +22,45 @@ public class Configuration {
private String appName = "zestwriter";
private String confFileName = "conf.properties";
private File confFile;
private StorageSaver offlineSaver;
private StorageSaver onlineSaver;
private LocalDirectoryFactory workspaceFactory;
private final Logger logger;

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;


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);
Expand Down Expand Up @@ -75,7 +106,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 @@ -164,4 +195,96 @@ public void loadWorkspace() throws IOException{

}


/*
* 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);
}
}
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je crois que cet import est une erreur. Tu peux le supprimer

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectivement, soit une erreur soit un mauvaise import.

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,7 @@ 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.replaceText(extract.getMarkdown());
SourceText.textProperty().addListener((observableValue, s, s2) -> {
tab.setText("! " + extract.getTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.function.Function;

import com.zestedesavoir.zestwriter.view.dialogs.AboutDialog;
import com.zestedesavoir.zestwriter.view.dialogs.OptionsDialog;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
Expand Down Expand Up @@ -608,4 +609,30 @@ private void uploadContents(){
logger.error(e.getMessage(), e);
}
}

@FXML private void HandleOptionsButtonAction(ActionEvent evnet){
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("fxml/OptionsDialog.fxml"));

try{
AnchorPane optionsDialog = loader.load();

Stage dialogStage = new Stage();
dialogStage.setTitle("Options");

Scene scene = new Scene(optionsDialog);
dialogStage.setScene(scene);
dialogStage.getIcons().add(new Image(MainApp.class.getResourceAsStream("static/icons/logo.png")));
dialogStage.setResizable(false);
dialogStage.initModality(Modality.APPLICATION_MODAL);

OptionsDialog optionsController = loader.getController();
optionsController.setMainApp(mainApp);
optionsController.setWindow(dialogStage);

dialogStage.show();
}catch(IOException e){
logger.error(e.getMessage(), e);
}
}
}
Loading