mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-30 12:04:39 -04:00
Add app preferences UI
This commit is contained in:
parent
0136ea2884
commit
f23a1b8fa6
7 changed files with 181 additions and 31 deletions
|
@ -90,12 +90,9 @@ public class BitsquareApp extends Application {
|
|||
User persistedUser = (User) persistence.read(user);
|
||||
user.applyPersistedUser(persistedUser);
|
||||
|
||||
applicationPreferences.applyPersistedSettings((ApplicationPreferences) persistence
|
||||
.read(applicationPreferences.getClass().getName()));
|
||||
accountSettings.applyPersistedAccountSettings((AccountSettings) persistence
|
||||
.read(accountSettings.getClass().getName()));
|
||||
|
||||
|
||||
// load the main view and create the main scene
|
||||
|
||||
ViewLoader.setInjector(injector);
|
||||
|
|
|
@ -18,22 +18,45 @@
|
|||
package io.bitsquare.gui.main.preferences.application;
|
||||
|
||||
import io.bitsquare.gui.UIModel;
|
||||
import io.bitsquare.preferences.ApplicationPreferences;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class ApplicationPreferencesModel extends UIModel {
|
||||
private static final Logger log = LoggerFactory.getLogger(ApplicationPreferencesModel.class);
|
||||
|
||||
private final ApplicationPreferences applicationPreferences;
|
||||
|
||||
final ObservableList<String> btcDenominations;
|
||||
final BooleanProperty useAnimations = new SimpleBooleanProperty();
|
||||
final BooleanProperty useEffects = new SimpleBooleanProperty();
|
||||
final StringProperty btcDenomination = new SimpleStringProperty();
|
||||
|
||||
private ChangeListener<Boolean> useAnimationsListener;
|
||||
private ChangeListener<Boolean> useEffectsListener;
|
||||
private ChangeListener<String> btcDenominationListener;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
ApplicationPreferencesModel() {
|
||||
ApplicationPreferencesModel(ApplicationPreferences applicationPreferences) {
|
||||
this.applicationPreferences = applicationPreferences;
|
||||
|
||||
btcDenominations = FXCollections.observableArrayList(applicationPreferences.getBtcDenominations());
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,18 +68,36 @@ class ApplicationPreferencesModel extends UIModel {
|
|||
public void initialize() {
|
||||
|
||||
super.initialize();
|
||||
|
||||
useAnimationsListener = (ov, oldValue, newValue) -> applicationPreferences
|
||||
.setUseAnimations(newValue);
|
||||
useEffectsListener = (ov, oldValue, newValue) -> applicationPreferences
|
||||
.setUseEffects(newValue);
|
||||
btcDenominationListener = (ov, oldValue, newValue) -> applicationPreferences
|
||||
.setBtcDenomination(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
super.activate();
|
||||
|
||||
useAnimations.set(applicationPreferences.getUseAnimations());
|
||||
useEffects.set(applicationPreferences.getUseEffects());
|
||||
btcDenomination.set(applicationPreferences.getBtcDenomination());
|
||||
|
||||
useAnimations.addListener(useAnimationsListener);
|
||||
useEffects.addListener(useEffectsListener);
|
||||
btcDenomination.addListener(btcDenominationListener);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
super.deactivate();
|
||||
|
||||
useAnimations.removeListener(useAnimationsListener);
|
||||
useEffects.removeListener(useEffectsListener);
|
||||
btcDenomination.removeListener(btcDenominationListener);
|
||||
}
|
||||
|
||||
@SuppressWarnings("EmptyMethod")
|
||||
|
@ -66,19 +107,5 @@ class ApplicationPreferencesModel extends UIModel {
|
|||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,10 @@ import io.bitsquare.gui.PresentationModel;
|
|||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -65,6 +69,22 @@ public class ApplicationPreferencesPM extends PresentationModel<ApplicationPrefe
|
|||
super.terminate();
|
||||
}
|
||||
|
||||
public ObservableList<String> getBtcDenominationItems() {
|
||||
return model.btcDenominations;
|
||||
}
|
||||
|
||||
BooleanProperty useAnimations() {
|
||||
return model.useAnimations;
|
||||
}
|
||||
|
||||
BooleanProperty useEffects() {
|
||||
return model.useEffects;
|
||||
}
|
||||
|
||||
StringProperty btcDenomination() {
|
||||
return model.btcDenomination;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Methods
|
||||
|
|
|
@ -18,11 +18,53 @@
|
|||
-->
|
||||
|
||||
|
||||
<?import io.bitsquare.gui.components.TitledGroupBg?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.main.preferences.application.ApplicationPreferencesViewCB"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
<GridPane fx:id="root" fx:controller="io.bitsquare.gui.main.preferences.application.ApplicationPreferencesViewCB"
|
||||
hgap="5.0" vgap="5.0"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
|
||||
<Label text="app"/>
|
||||
</AnchorPane>
|
||||
<padding>
|
||||
<Insets bottom="-10.0" left="25.0" top="30.0" right="25"/>
|
||||
</padding>
|
||||
|
||||
<TitledGroupBg text="General application preferences" GridPane.rowSpan="8"/>
|
||||
|
||||
<Label text="Bitcoin denomination" GridPane.rowIndex="0">
|
||||
<GridPane.margin>
|
||||
<Insets top="10"/>
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<ComboBox fx:id="btcDenominationComboBox" promptText="Select bitcoin denomination"
|
||||
onAction="#onSelectBtcDenomination"
|
||||
GridPane.rowIndex="0" GridPane.columnIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets top="10"/>
|
||||
</GridPane.margin>
|
||||
</ComboBox>
|
||||
|
||||
<Label text="Use animations:" GridPane.rowIndex="1"/>
|
||||
<CheckBox fx:id="useAnimationsCheckBox"
|
||||
GridPane.columnIndex="1" GridPane.rowIndex="1"/>
|
||||
|
||||
<Label text="Use effects:" GridPane.rowIndex="2"/>
|
||||
<CheckBox fx:id="useEffectsCheckBox"
|
||||
GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||
|
||||
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" halignment="RIGHT" minWidth="200.0"/>
|
||||
<ColumnConstraints hgrow="ALWAYS" minWidth="300.0"/>
|
||||
</columnConstraints>
|
||||
|
||||
<rowConstraints>
|
||||
<RowConstraints vgrow="NEVER"/>
|
||||
<RowConstraints vgrow="NEVER"/>
|
||||
<RowConstraints vgrow="NEVER"/>
|
||||
</rowConstraints>
|
||||
|
||||
</GridPane>
|
||||
|
|
|
@ -25,6 +25,9 @@ import java.util.ResourceBundle;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -35,6 +38,11 @@ public class ApplicationPreferencesViewCB extends CachedViewCB<ApplicationPrefer
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(ApplicationPreferencesViewCB.class);
|
||||
|
||||
|
||||
@FXML ComboBox<String> btcDenominationComboBox;
|
||||
@FXML CheckBox useAnimationsCheckBox, useEffectsCheckBox;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -51,7 +59,6 @@ public class ApplicationPreferencesViewCB extends CachedViewCB<ApplicationPrefer
|
|||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
|
||||
super.initialize(url, rb);
|
||||
}
|
||||
|
||||
|
@ -59,6 +66,11 @@ public class ApplicationPreferencesViewCB extends CachedViewCB<ApplicationPrefer
|
|||
public void activate() {
|
||||
super.activate();
|
||||
|
||||
btcDenominationComboBox.setItems(presentationModel.getBtcDenominationItems());
|
||||
btcDenominationComboBox.getSelectionModel().select(presentationModel.btcDenomination().get());
|
||||
useAnimationsCheckBox.selectedProperty().bindBidirectional(presentationModel.useAnimations());
|
||||
useEffectsCheckBox.selectedProperty().bindBidirectional(presentationModel.useEffects());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,4 +83,15 @@ public class ApplicationPreferencesViewCB extends CachedViewCB<ApplicationPrefer
|
|||
public void terminate() {
|
||||
super.terminate();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// UI Handlers
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@FXML
|
||||
void onSelectBtcDenomination() {
|
||||
presentationModel.btcDenomination().set(btcDenominationComboBox.getSelectionModel().getSelectedItem());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,11 +18,9 @@
|
|||
-->
|
||||
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.main.preferences.network.NetworkPreferencesViewCB"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
|
||||
<Label text="net"/>
|
||||
</AnchorPane>
|
||||
|
||||
|
|
|
@ -17,17 +17,31 @@
|
|||
|
||||
package io.bitsquare.preferences;
|
||||
|
||||
import io.bitsquare.persistence.Persistence;
|
||||
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ApplicationPreferences implements Serializable {
|
||||
private static final long serialVersionUID = 7995048077355006861L;
|
||||
private static final Logger log = LoggerFactory.getLogger(ApplicationPreferences.class);
|
||||
|
||||
private List<String> btcDenominations = Arrays.asList(MonetaryFormat.CODE_BTC, MonetaryFormat.CODE_MBTC);
|
||||
|
||||
|
||||
// Needed for persistence as Property objects are transient (not serializable)
|
||||
// Will be probably removed when we have another persistence solution in place
|
||||
|
@ -38,13 +52,18 @@ public class ApplicationPreferences implements Serializable {
|
|||
final transient StringProperty btcDenomination = new SimpleStringProperty(btcDenominationString);
|
||||
final transient BooleanProperty useAnimations = new SimpleBooleanProperty(useAnimationsBoolean);
|
||||
final transient BooleanProperty useEffects = new SimpleBooleanProperty(useEffectsBoolean);
|
||||
private Persistence persistence;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public ApplicationPreferences() {
|
||||
@Inject
|
||||
public ApplicationPreferences(Persistence persistence) {
|
||||
this.persistence = persistence;
|
||||
|
||||
applyPersistedSettings();
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,18 +71,39 @@ public class ApplicationPreferences implements Serializable {
|
|||
// Public API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void applyPersistedSettings(ApplicationPreferences persistedSettings) {
|
||||
if (persistedSettings != null) {
|
||||
setBtcDenomination(persistedSettings.getBtcDenominationString());
|
||||
setUseAnimations(persistedSettings.getUseAnimationsBooleanBoolean());
|
||||
setUseEffects(persistedSettings.getUseEffectsBoolean());
|
||||
public void applyPersistedSettings() {
|
||||
Object data = persistence.read(this, "btcDenomination");
|
||||
if (data instanceof String) {
|
||||
btcDenominationString = (String) data;
|
||||
this.btcDenomination.set(btcDenominationString);
|
||||
log.debug(data.toString());
|
||||
}
|
||||
|
||||
data = persistence.read(this, "useEffects");
|
||||
if (data instanceof Boolean) {
|
||||
useEffectsBoolean = (Boolean) data;
|
||||
this.useEffects.set(useEffectsBoolean);
|
||||
|
||||
log.debug(data.toString());
|
||||
}
|
||||
|
||||
data = persistence.read(this, "useAnimations");
|
||||
if (data instanceof Boolean) {
|
||||
useAnimationsBoolean = (Boolean) data;
|
||||
this.useAnimations.set(useAnimationsBoolean);
|
||||
log.debug(data.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setters/Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public List<String> getBtcDenominations() {
|
||||
return btcDenominations;
|
||||
}
|
||||
|
||||
// btcDenomination
|
||||
public String getBtcDenomination() {
|
||||
return btcDenomination.get();
|
||||
|
@ -74,6 +114,7 @@ public class ApplicationPreferences implements Serializable {
|
|||
}
|
||||
|
||||
public void setBtcDenomination(String btcDenomination) {
|
||||
persistence.write(this, "btcDenomination", btcDenomination);
|
||||
btcDenominationString = btcDenomination;
|
||||
this.btcDenomination.set(btcDenomination);
|
||||
}
|
||||
|
@ -94,6 +135,7 @@ public class ApplicationPreferences implements Serializable {
|
|||
}
|
||||
|
||||
public void setUseAnimations(boolean useAnimations) {
|
||||
persistence.write(this, "useAnimations", useAnimations);
|
||||
useAnimationsBoolean = useAnimations;
|
||||
this.useAnimations.set(useAnimations);
|
||||
}
|
||||
|
@ -113,6 +155,7 @@ public class ApplicationPreferences implements Serializable {
|
|||
}
|
||||
|
||||
public void setUseEffects(boolean useEffects) {
|
||||
persistence.write(this, "useEffects", useEffects);
|
||||
useEffectsBoolean = useEffects;
|
||||
this.useEffects.set(useEffects);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue