|
@@ -27,7 +27,8 @@ public class CalcSkin extends Application {
|
27
|
27
|
{ "7", "8", "9", "/" },
|
28
|
28
|
{ "4", "5", "6", "*" },
|
29
|
29
|
{ "1", "2", "3", "-" },
|
30
|
|
- { "0", "c", "=", "+" }
|
|
30
|
+ { "0", "c", "=", "+" },
|
|
31
|
+ {"sin", "cos","tan"}
|
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 , SIN , COS, TAN}
|
40
|
41
|
|
41
|
42
|
private Op curOp = Op.NOOP;
|
42
|
43
|
private Op stackOp = Op.NOOP;
|
|
@@ -60,7 +61,7 @@ public class CalcSkin extends Application {
|
60
|
61
|
private VBox createLayout(TextField screen, TilePane buttons) {
|
61
|
62
|
final VBox layout = new VBox(20);
|
62
|
63
|
layout.setAlignment(Pos.CENTER);
|
63
|
|
- layout.setStyle("-fx-background-color: silver; -fx-padding: 20; -fx-font-size: 20;");
|
|
64
|
+ layout.setStyle("-fx-background-color: #ff7020; -fx-padding: 20; -fx-font-size: 20;");
|
64
|
65
|
layout.getChildren().setAll(screen, buttons);
|
65
|
66
|
handleAccelerators(layout);
|
66
|
67
|
screen.prefWidthProperty().bind(buttons.widthProperty());
|
|
@@ -81,7 +82,7 @@ public class CalcSkin extends Application {
|
81
|
82
|
|
82
|
83
|
private TextField createScreen() {
|
83
|
84
|
final TextField screen = new TextField();
|
84
|
|
- screen.setStyle("-fx-background-color: aquamarine;");
|
|
85
|
+ screen.setStyle("-fx-background-color: #b6ffda;");
|
85
|
86
|
screen.setAlignment(Pos.CENTER_RIGHT);
|
86
|
87
|
screen.setEditable(false);
|
87
|
88
|
screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
|
@@ -127,12 +128,15 @@ 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 "sin": triggerOp.set(Op.SIN); break;
|
|
132
|
+ case "cos": triggerOp.set(Op.COS); break;
|
|
133
|
+ case "tan": triggerOp.set(Op.TAN); break;
|
130
|
134
|
}
|
131
|
135
|
return triggerOp;
|
132
|
136
|
}
|
133
|
137
|
|
134
|
138
|
private void makeOperandButton(Button button, final ObjectProperty<Op> triggerOp) {
|
135
|
|
- button.setStyle("-fx-base: lightgray;");
|
|
139
|
+ button.setStyle("-fx-base: yellow;");
|
136
|
140
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
137
|
141
|
@Override
|
138
|
142
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -143,7 +147,7 @@ public class CalcSkin extends Application {
|
143
|
147
|
|
144
|
148
|
private Button makeStandardButton(String s) {
|
145
|
149
|
Button button = new Button(s);
|
146
|
|
- button.setStyle("-fx-base: beige;");
|
|
150
|
+ button.setStyle("-fx-base: pink;");
|
147
|
151
|
accelerators.put(s, button);
|
148
|
152
|
button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
149
|
153
|
return button;
|
|
@@ -166,7 +170,7 @@ public class CalcSkin extends Application {
|
166
|
170
|
}
|
167
|
171
|
|
168
|
172
|
private void makeClearButton(Button button) {
|
169
|
|
- button.setStyle("-fx-base: mistyrose;");
|
|
173
|
+ button.setStyle("-fx-base: black;");
|
170
|
174
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
171
|
175
|
@Override
|
172
|
176
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -185,6 +189,9 @@ 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 SIN: currentValue.set(calcEngine.sin(currentValue.get())); break;
|
|
193
|
+ case COS: currentValue.set(calcEngine.cos(currentValue.get())); break;
|
|
194
|
+ case TAN: currentValue.set(calcEngine.tan(currentValue.get())); break;
|
188
|
195
|
}
|
189
|
196
|
}
|
190
|
197
|
});
|