|
@@ -24,10 +24,10 @@ public class CalcSkin extends Application {
|
24
|
24
|
launch(args);
|
25
|
25
|
}
|
26
|
26
|
private static final String[][] template = {
|
27
|
|
- { "7", "8", "9", "/" },
|
28
|
|
- { "4", "5", "6", "*" },
|
29
|
|
- { "1", "2", "3", "-" },
|
30
|
|
- { "0", "c", "=", "+" }
|
|
27
|
+ { "7", "8", "9", "/", "x²" },
|
|
28
|
+ { "4", "5", "6", "*", "√x" },
|
|
29
|
+ { "1", "2", "3", "-", "x^" },
|
|
30
|
+ { "0", "c", "=", "+", "1/x" }
|
31
|
31
|
};
|
32
|
32
|
|
33
|
33
|
private final Map<String, Button> accelerators = new HashMap<>();
|
|
@@ -36,7 +36,7 @@ public class CalcSkin extends Application {
|
36
|
36
|
private DoubleProperty currentValue = new SimpleDoubleProperty();
|
37
|
37
|
private CalcEngine calcEngine = new CalcEngine();
|
38
|
38
|
|
39
|
|
- private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
|
|
39
|
+ private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE, SQUARE, SQUAREROOT, POWER, INVERSE }
|
40
|
40
|
|
41
|
41
|
private Op curOp = Op.NOOP;
|
42
|
42
|
private Op stackOp = Op.NOOP;
|
|
@@ -50,7 +50,7 @@ public class CalcSkin extends Application {
|
50
|
50
|
final TextField screen = createScreen();
|
51
|
51
|
final TilePane buttons = createButtons();
|
52
|
52
|
|
53
|
|
- stage.setTitle("Calc");
|
|
53
|
+ stage.setTitle("Calculator");
|
54
|
54
|
stage.initStyle(StageStyle.UTILITY);
|
55
|
55
|
stage.setResizable(false);
|
56
|
56
|
stage.setScene(new Scene(createLayout(screen, buttons)));
|
|
@@ -60,7 +60,7 @@ public class CalcSkin extends Application {
|
60
|
60
|
private VBox createLayout(TextField screen, TilePane buttons) {
|
61
|
61
|
final VBox layout = new VBox(20);
|
62
|
62
|
layout.setAlignment(Pos.CENTER);
|
63
|
|
- layout.setStyle("-fx-background-color: silver; -fx-padding: 20; -fx-font-size: 20;");
|
|
63
|
+ layout.setStyle("-fx-background-color: AQUAMARINE; -fx-padding: 20; -fx-font-size: 20;");
|
64
|
64
|
layout.getChildren().setAll(screen, buttons);
|
65
|
65
|
handleAccelerators(layout);
|
66
|
66
|
screen.prefWidthProperty().bind(buttons.widthProperty());
|
|
@@ -81,7 +81,7 @@ public class CalcSkin extends Application {
|
81
|
81
|
|
82
|
82
|
private TextField createScreen() {
|
83
|
83
|
final TextField screen = new TextField();
|
84
|
|
- screen.setStyle("-fx-background-color: aquamarine;");
|
|
84
|
+ screen.setStyle("-fx-background-color: HONEYDEW;");
|
85
|
85
|
screen.setAlignment(Pos.CENTER_RIGHT);
|
86
|
86
|
screen.setEditable(false);
|
87
|
87
|
screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
|
@@ -127,6 +127,10 @@ public class CalcSkin extends Application {
|
127
|
127
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
128
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
129
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
130
|
+ case "x²": triggerOp.set(Op.SQUARE); break;
|
|
131
|
+ case "√x": triggerOp.set(Op.SQUAREROOT); break;
|
|
132
|
+ case "x^": triggerOp.set(Op.POWER); break;
|
|
133
|
+ case "1/x": triggerOp.set(Op.INVERSE); break;
|
130
|
134
|
}
|
131
|
135
|
return triggerOp;
|
132
|
136
|
}
|
|
@@ -185,6 +189,10 @@ public class CalcSkin extends Application {
|
185
|
189
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
190
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
191
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
192
|
+ case SQUARE: currentValue.set(calcEngine.square(currentValue.get())); break;
|
|
193
|
+ case SQUAREROOT: currentValue.set(calcEngine.squareroot(currentValue.get())); break;
|
|
194
|
+ case POWER: currentValue.set(calcEngine.power(previousValue.get(), currentValue.get())); break;
|
|
195
|
+ case INVERSE: currentValue.set(calcEngine.inverse(currentValue.get())); break;
|
188
|
196
|
}
|
189
|
197
|
}
|
190
|
198
|
});
|