Skip to content

Commit

Permalink
freeze sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
loziniak committed Jan 5, 2018
1 parent ae5e3e6 commit 0faa326
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pl/robotix/cinx/wallet/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void changePercentsProportionally(WalletEntry slider, double percentChan
double x = (100.0 - previousPercent - percentChange) / (100.0 - previousPercent);

sliders.forEach((currency, otherSlider) -> {
if (!currency.equals(slider.getCurrency())) {
if (!currency.equals(slider.getCurrency()) && !otherSlider.freeze.get()) {
otherSlider.setPercent(otherSlider.getPercent() * x);
if (otherSlider.getPercent() != 100.0) {
otherSlider.enable();
Expand Down
1 change: 1 addition & 0 deletions src/pl/robotix/cinx/wallet/WalletEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class WalletEntry {
final DoubleProperty percent = new SimpleDoubleProperty();
final DoubleBinding percentChange;
final BooleanProperty enabled = new SimpleBooleanProperty(true);
final BooleanProperty freeze = new SimpleBooleanProperty(false);

public WalletEntry(Currency c, double walletUSD, double originalPrice) {
this.currency = c;
Expand Down
6 changes: 6 additions & 0 deletions src/pl/robotix/cinx/wallet/WalletSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.beans.binding.When;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.input.MouseEvent;
Expand All @@ -31,13 +32,16 @@ public class WalletSlider extends VBox {

private final Label percentChange = new Label(String.format("%+.1f", 0.0));

private final CheckBox freeze = new CheckBox();

public WalletSlider(WalletEntry s) {
super();
currency = s.getCurrency();

getChildren().add(new Text(s.getCurrency().symbol));
getChildren().add(percentChange);
getChildren().add(slider);
getChildren().add(freeze);

slider.setOrientation(VERTICAL);
slider.setMin(0.0);
Expand All @@ -55,6 +59,8 @@ public WalletSlider(WalletEntry s) {
.then(Color.BLUE)
.otherwise(Color.GREY)));

s.freeze.bind(freeze.selectedProperty());

s.enabled.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
boolean enabled = newValue;
if (enabled) {
Expand Down

0 comments on commit 0faa326

Please sign in to comment.