|
@@ -12,7 +12,6 @@ import javafx.scene.input.KeyEvent;
|
12
|
12
|
import javafx.scene.layout.*;
|
13
|
13
|
import javafx.stage.Stage;
|
14
|
14
|
import javafx.stage.StageStyle;
|
15
|
|
-import rocks.zipcode.calcskin.CalcEngine;
|
16
|
15
|
|
17
|
16
|
import java.util.HashMap;
|
18
|
17
|
import java.util.Map;
|
|
@@ -24,10 +23,12 @@ public class CalcSkin extends Application {
|
24
|
23
|
launch(args);
|
25
|
24
|
}
|
26
|
25
|
private static final String[][] template = {
|
|
26
|
+ {"sqrt","exp","log","c"},
|
27
|
27
|
{ "7", "8", "9", "/" },
|
28
|
28
|
{ "4", "5", "6", "*" },
|
29
|
29
|
{ "1", "2", "3", "-" },
|
30
|
|
- { "0", "c", "=", "+" }
|
|
30
|
+ {"0","avg", "=", "+" }
|
|
31
|
+
|
31
|
32
|
};
|
32
|
33
|
|
33
|
34
|
private final Map<String, Button> accelerators = new HashMap<>();
|
|
@@ -36,7 +37,7 @@ public class CalcSkin extends Application {
|
36
|
37
|
private DoubleProperty currentValue = new SimpleDoubleProperty();
|
37
|
38
|
private CalcEngine calcEngine = new CalcEngine();
|
38
|
39
|
|
39
|
|
- private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
|
|
40
|
+ private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE, ROOT, AVERAGE, EXPONENT, LOG}
|
40
|
41
|
|
41
|
42
|
private Op curOp = Op.NOOP;
|
42
|
43
|
private Op stackOp = Op.NOOP;
|
|
@@ -50,7 +51,7 @@ public class CalcSkin extends Application {
|
50
|
51
|
final TextField screen = createScreen();
|
51
|
52
|
final TilePane buttons = createButtons();
|
52
|
53
|
|
53
|
|
- stage.setTitle("Calc");
|
|
54
|
+ stage.setTitle("<> Calculator <>");
|
54
|
55
|
stage.initStyle(StageStyle.UTILITY);
|
55
|
56
|
stage.setResizable(false);
|
56
|
57
|
stage.setScene(new Scene(createLayout(screen, buttons)));
|
|
@@ -58,7 +59,7 @@ public class CalcSkin extends Application {
|
58
|
59
|
}
|
59
|
60
|
|
60
|
61
|
private VBox createLayout(TextField screen, TilePane buttons) {
|
61
|
|
- final VBox layout = new VBox(20);
|
|
62
|
+ final VBox layout = new VBox(30);
|
62
|
63
|
layout.setAlignment(Pos.CENTER);
|
63
|
64
|
layout.setStyle("-fx-background-color: silver; -fx-padding: 20; -fx-font-size: 20;");
|
64
|
65
|
layout.getChildren().setAll(screen, buttons);
|
|
@@ -82,7 +83,7 @@ public class CalcSkin extends Application {
|
82
|
83
|
private TextField createScreen() {
|
83
|
84
|
final TextField screen = new TextField();
|
84
|
85
|
screen.setStyle("-fx-background-color: aquamarine;");
|
85
|
|
- screen.setAlignment(Pos.CENTER_RIGHT);
|
|
86
|
+ screen.setAlignment(Pos.CENTER_LEFT);
|
86
|
87
|
screen.setEditable(false);
|
87
|
88
|
screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
88
|
89
|
return screen;
|
|
@@ -127,6 +128,10 @@ public class CalcSkin extends Application {
|
127
|
128
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
129
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
130
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
131
|
+ case "Sqrt": triggerOp.set(Op.ROOT); break;
|
|
132
|
+ case "log": triggerOp.set(Op.LOG); break;
|
|
133
|
+ case "exp": triggerOp.set(Op.EXPONENT); break;
|
|
134
|
+
|
130
|
135
|
}
|
131
|
136
|
return triggerOp;
|
132
|
137
|
}
|
|
@@ -185,6 +190,10 @@ public class CalcSkin extends Application {
|
185
|
190
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
191
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
192
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
193
|
+ case ROOT: currentValue.set(calcEngine.sqrt(previousValue.get())); break;
|
|
194
|
+ case AVERAGE: currentValue.set(calcEngine.average(previousValue.get(), currentValue.get())); break;
|
|
195
|
+ case EXPONENT: currentValue.set(calcEngine.exponent(previousValue.get())); break;
|
|
196
|
+ case LOG: currentValue.set(calcEngine.log(previousValue.get())); break;
|
188
|
197
|
}
|
189
|
198
|
}
|
190
|
199
|
});
|