|
@@ -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,9 +23,9 @@ public class CalcSkin extends Application {
|
24
|
23
|
launch(args);
|
25
|
24
|
}
|
26
|
25
|
private static final String[][] template = {
|
27
|
|
- { "7", "8", "9", "/" },
|
28
|
|
- { "4", "5", "6", "*" },
|
29
|
|
- { "1", "2", "3", "-" },
|
|
26
|
+ { "7", "8", "9", "/", "x^2" },
|
|
27
|
+ { "4", "5", "6", "*", "rt" },
|
|
28
|
+ { "1", "2", "3", "-", "x^y" },
|
30
|
29
|
{ "0", "c", "=", "+" }
|
31
|
30
|
};
|
32
|
31
|
|
|
@@ -36,7 +35,7 @@ public class CalcSkin extends Application {
|
36
|
35
|
private DoubleProperty currentValue = new SimpleDoubleProperty();
|
37
|
36
|
private CalcEngine calcEngine = new CalcEngine();
|
38
|
37
|
|
39
|
|
- private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
|
|
38
|
+ private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE, SQUARE, ROOT, EXPO }
|
40
|
39
|
|
41
|
40
|
private Op curOp = Op.NOOP;
|
42
|
41
|
private Op stackOp = Op.NOOP;
|
|
@@ -60,7 +59,7 @@ public class CalcSkin extends Application {
|
60
|
59
|
private VBox createLayout(TextField screen, TilePane buttons) {
|
61
|
60
|
final VBox layout = new VBox(20);
|
62
|
61
|
layout.setAlignment(Pos.CENTER);
|
63
|
|
- layout.setStyle("-fx-background-color: silver; -fx-padding: 20; -fx-font-size: 20;");
|
|
62
|
+ layout.setStyle("-fx-background-color: green; -fx-padding: 20; -fx-font-size: 20;");
|
64
|
63
|
layout.getChildren().setAll(screen, buttons);
|
65
|
64
|
handleAccelerators(layout);
|
66
|
65
|
screen.prefWidthProperty().bind(buttons.widthProperty());
|
|
@@ -81,7 +80,7 @@ public class CalcSkin extends Application {
|
81
|
80
|
|
82
|
81
|
private TextField createScreen() {
|
83
|
82
|
final TextField screen = new TextField();
|
84
|
|
- screen.setStyle("-fx-background-color: aquamarine;");
|
|
83
|
+ screen.setStyle("-fx-background-color: black;");
|
85
|
84
|
screen.setAlignment(Pos.CENTER_RIGHT);
|
86
|
85
|
screen.setEditable(false);
|
87
|
86
|
screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
|
@@ -127,12 +126,15 @@ public class CalcSkin extends Application {
|
127
|
126
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
127
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
128
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
129
|
+ case "x^2": triggerOp.set(Op.SQUARE); break;
|
|
130
|
+ case "rt": triggerOp.set(Op.ROOT); break;
|
|
131
|
+ case "x^y": triggerOp.set(Op.EXPO); break;
|
130
|
132
|
}
|
131
|
133
|
return triggerOp;
|
132
|
134
|
}
|
133
|
135
|
|
134
|
136
|
private void makeOperandButton(Button button, final ObjectProperty<Op> triggerOp) {
|
135
|
|
- button.setStyle("-fx-base: lightgray;");
|
|
137
|
+ button.setStyle("-fx-base: lightblue;");
|
136
|
138
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
137
|
139
|
@Override
|
138
|
140
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -143,7 +145,7 @@ public class CalcSkin extends Application {
|
143
|
145
|
|
144
|
146
|
private Button makeStandardButton(String s) {
|
145
|
147
|
Button button = new Button(s);
|
146
|
|
- button.setStyle("-fx-base: beige;");
|
|
148
|
+ button.setStyle("-fx-base: pink;");
|
147
|
149
|
accelerators.put(s, button);
|
148
|
150
|
button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
149
|
151
|
return button;
|
|
@@ -166,7 +168,7 @@ public class CalcSkin extends Application {
|
166
|
168
|
}
|
167
|
169
|
|
168
|
170
|
private void makeClearButton(Button button) {
|
169
|
|
- button.setStyle("-fx-base: mistyrose;");
|
|
171
|
+ button.setStyle("-fx-base: orange;");
|
170
|
172
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
171
|
173
|
@Override
|
172
|
174
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -176,7 +178,7 @@ public class CalcSkin extends Application {
|
176
|
178
|
}
|
177
|
179
|
|
178
|
180
|
private void makeEqualsButton(Button button) {
|
179
|
|
- button.setStyle("-fx-base: ghostwhite;");
|
|
181
|
+ button.setStyle("-fx-base: violet;");
|
180
|
182
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
181
|
183
|
@Override
|
182
|
184
|
public void handle(ActionEvent actionEvent) {
|
|
@@ -185,6 +187,9 @@ public class CalcSkin extends Application {
|
185
|
187
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
188
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
189
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
190
|
+ case ROOT: currentValue.set(calcEngine.root( currentValue.get())); break;
|
|
191
|
+ case SQUARE: currentValue.set(calcEngine.square( currentValue.get())); break;
|
|
192
|
+ case EXPO: currentValue.set(calcEngine.expo(previousValue.get(), currentValue.get())); break;
|
188
|
193
|
}
|
189
|
194
|
}
|
190
|
195
|
});
|