|
@@ -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", "/", "x2" },
|
|
28
|
+ { "4", "5", "6", "*", "√x"},
|
|
29
|
+ { "1", "2", "3", "-", "1/x" },
|
|
30
|
+ { "0", "c", "=", "+", "x^y"}
|
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, ROOT, INVERSE, EXPO }
|
40
|
40
|
|
41
|
41
|
private Op curOp = Op.NOOP;
|
42
|
42
|
private Op stackOp = Op.NOOP;
|
|
@@ -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: orange; -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: red;");
|
85
|
85
|
screen.setAlignment(Pos.CENTER_RIGHT);
|
86
|
86
|
screen.setEditable(false);
|
87
|
87
|
screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
|
@@ -114,12 +114,15 @@ public class CalcSkin extends Application {
|
114
|
114
|
makeClearButton(button);
|
115
|
115
|
} else if ("=".equals(s)) {
|
116
|
116
|
makeEqualsButton(button);
|
|
117
|
+ } else if ("x2".equals(s)) {
|
|
118
|
+
|
117
|
119
|
}
|
118
|
120
|
}
|
119
|
121
|
|
120
|
122
|
return button;
|
121
|
123
|
}
|
122
|
124
|
|
|
125
|
+
|
123
|
126
|
private ObjectProperty<Op> determineOperand(String s) {
|
124
|
127
|
final ObjectProperty<Op> triggerOp = new SimpleObjectProperty<>(Op.NOOP);
|
125
|
128
|
switch (s) {
|
|
@@ -127,12 +130,17 @@ public class CalcSkin extends Application {
|
127
|
130
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
131
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
132
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
133
|
+ case "x2":triggerOp.set(Op.SQUARE); break;
|
|
134
|
+ case "√x":triggerOp.set(Op.ROOT); break;
|
|
135
|
+ case "1/x":triggerOp.set(Op.INVERSE); break;
|
|
136
|
+ case "x^y":triggerOp.set(Op.EXPO); break;
|
|
137
|
+
|
130
|
138
|
}
|
131
|
139
|
return triggerOp;
|
132
|
140
|
}
|
133
|
141
|
|
134
|
142
|
private void makeOperandButton(Button button, final ObjectProperty<Op> triggerOp) {
|
135
|
|
- button.setStyle("-fx-base: lightgray;");
|
|
143
|
+ button.setStyle("-fx-base: #fdff00;");
|
136
|
144
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
137
|
145
|
@Override
|
138
|
146
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -143,7 +151,7 @@ public class CalcSkin extends Application {
|
143
|
151
|
|
144
|
152
|
private Button makeStandardButton(String s) {
|
145
|
153
|
Button button = new Button(s);
|
146
|
|
- button.setStyle("-fx-base: beige;");
|
|
154
|
+ button.setStyle("-fx-base: #b88cf5;");
|
147
|
155
|
accelerators.put(s, button);
|
148
|
156
|
button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
149
|
157
|
return button;
|
|
@@ -166,7 +174,7 @@ public class CalcSkin extends Application {
|
166
|
174
|
}
|
167
|
175
|
|
168
|
176
|
private void makeClearButton(Button button) {
|
169
|
|
- button.setStyle("-fx-base: mistyrose;");
|
|
177
|
+ button.setStyle("-fx-base: rgba(169,255,131,1);");
|
170
|
178
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
171
|
179
|
@Override
|
172
|
180
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -175,8 +183,10 @@ public class CalcSkin extends Application {
|
175
|
183
|
});
|
176
|
184
|
}
|
177
|
185
|
|
|
186
|
+
|
|
187
|
+
|
178
|
188
|
private void makeEqualsButton(Button button) {
|
179
|
|
- button.setStyle("-fx-base: ghostwhite;");
|
|
189
|
+ button.setStyle("-fx-base: #ff03e8;");
|
180
|
190
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
181
|
191
|
@Override
|
182
|
192
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -185,6 +195,10 @@ public class CalcSkin extends Application {
|
185
|
195
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
196
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
197
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
198
|
+ //case SQUARE: currentValue.set(calcEngine.square(currentValue.get())); break;
|
|
199
|
+ case ROOT: currentValue.set(calcEngine.squareRoot(currentValue.get())); break;
|
|
200
|
+ case INVERSE: currentValue.set(calcEngine.inverse(currentValue.get())); break;
|
|
201
|
+ case EXPO: currentValue.set(calcEngine.exponent(previousValue.get(), currentValue.get())); break;
|
188
|
202
|
}
|
189
|
203
|
}
|
190
|
204
|
});
|