summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/upnfx/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/fhswf/in/inf/upnfx/view')
-rw-r--r--src/de/fhswf/in/inf/upnfx/view/MainView.fxml60
-rw-r--r--src/de/fhswf/in/inf/upnfx/view/MainViewController.java385
2 files changed, 445 insertions, 0 deletions
diff --git a/src/de/fhswf/in/inf/upnfx/view/MainView.fxml b/src/de/fhswf/in/inf/upnfx/view/MainView.fxml
new file mode 100644
index 0000000..a1a0349
--- /dev/null
+++ b/src/de/fhswf/in/inf/upnfx/view/MainView.fxml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.scene.control.*?>
+<?import java.lang.*?>
+<?import javafx.scene.layout.*?>
+<?import javafx.scene.layout.GridPane?>
+
+<AnchorPane xmlns="http://javafx.com/javafx/8.0.45" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.fhswf.in.inf.upnfx.view.MainViewController">
+ <children>
+ <GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
+ <children>
+ <TextField fx:id="txtField" alignment="CENTER_RIGHT" editable="false" GridPane.columnSpan="4" GridPane.halignment="CENTER" />
+ <Button fx:id="btnLn" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpLn" text="LN" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
+ <Button fx:id="btnSin" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpSin" text="SIN" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
+ <Button fx:id="btnCos" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpCos" text="COS" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
+ <Button fx:id="btnTan" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpTan" text="TAN" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleInvert" text="+/-" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
+ <Button fx:id="btn1DivX" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handle1DivX" text="1/X" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
+ <Button fx:id="btnPow" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpPow" text="Y^X" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
+ <Button fx:id="btnSqr" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpSqr" text="SQR" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleLstX" text="LstX" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
+ <Button fx:id="btnXY" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleXY" text="X&lt;&gt;Y" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleClr" text="CLR" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleClx" text="CLX" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber7" text="7" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber8" text="8" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber9" text="9" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
+ <Button fx:id="btnDiv" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpDiv" text="/" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber4" text="4" GridPane.halignment="CENTER" GridPane.rowIndex="5" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber5" text="5" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="5" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber6" text="6" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="5" />
+ <Button fx:id="btnMul" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpMult" text="*" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="5" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber1" text="1" GridPane.halignment="CENTER" GridPane.rowIndex="6" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber2" text="2" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="6" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber3" text="3" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="6" />
+ <Button fx:id="btnMinus" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpMinus" text="-" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="6" />
+ <Button fx:id="btnZero" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumber0" text="0" GridPane.halignment="CENTER" GridPane.rowIndex="7" />
+ <Button fx:id="btnComma" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleNumberComma" text="." GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="7" />
+ <Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleEnt" text="ENT" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="7" />
+ <Button fx:id="btnPlus" disable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleOpPlus" text="+" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="7" />
+ </children>
+ <rowConstraints>
+ <RowConstraints vgrow="ALWAYS" />
+ <RowConstraints vgrow="ALWAYS" />
+ <RowConstraints vgrow="ALWAYS" />
+ <RowConstraints vgrow="ALWAYS" />
+ <RowConstraints vgrow="ALWAYS" />
+ <RowConstraints vgrow="ALWAYS" />
+ <RowConstraints vgrow="ALWAYS" />
+ <RowConstraints vgrow="ALWAYS" />
+ </rowConstraints>
+ <columnConstraints>
+ <ColumnConstraints hgrow="ALWAYS" />
+ <ColumnConstraints hgrow="ALWAYS" />
+ <ColumnConstraints hgrow="ALWAYS" />
+ <ColumnConstraints hgrow="ALWAYS" />
+ </columnConstraints>
+ </GridPane>
+ </children>
+</AnchorPane>
diff --git a/src/de/fhswf/in/inf/upnfx/view/MainViewController.java b/src/de/fhswf/in/inf/upnfx/view/MainViewController.java
new file mode 100644
index 0000000..6a9a115
--- /dev/null
+++ b/src/de/fhswf/in/inf/upnfx/view/MainViewController.java
@@ -0,0 +1,385 @@
+/**
+ *
+ */
+package de.fhswf.in.inf.upnfx.view;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javafx.beans.property.SimpleStringProperty;
+import javafx.beans.property.StringProperty;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.TextField;
+import de.fhswf.in.inf.upnfx.util.Addition;
+import de.fhswf.in.inf.upnfx.util.BinaryTemplate;
+import de.fhswf.in.inf.upnfx.util.Division;
+import de.fhswf.in.inf.upnfx.util.Modulo;
+import de.fhswf.in.inf.upnfx.util.Multiplication;
+import de.fhswf.in.inf.upnfx.util.ObservableDoubleStack;
+import de.fhswf.in.inf.upnfx.util.Operator;
+import de.fhswf.in.inf.upnfx.util.Subtraction;
+import de.fhswf.in.inf.upnfx.util.UPN;
+import de.fhswf.in.inf.upnfx.util.UnaryTemplate;
+
+/**
+ * The controller for the MainView.fxml.
+ *
+ * @author Stefan Suhren
+ * @version 1.0
+ */
+public class MainViewController
+{
+ @FXML
+ private TextField txtField;
+
+ @FXML
+ private Button btnComma;
+
+ @FXML
+ private Button btnZero;
+
+ @FXML
+ private Button btnPlus;
+
+ @FXML
+ private Button btnMinus;
+
+ @FXML
+ private Button btnMul;
+
+ @FXML
+ private Button btnDiv;
+
+ @FXML
+ private Button btnLn;
+
+ @FXML
+ private Button btnSin;
+
+ @FXML
+ private Button btnCos;
+
+ @FXML
+ private Button btnTan;
+
+ @FXML
+ private Button btn1DivX;
+
+ @FXML
+ private Button btnPow;
+
+ @FXML
+ private Button btnSqr;
+
+ @FXML
+ private Button btnXY;
+
+ private UPN upnClass = new UPN();
+
+ private ObservableDoubleStack upnStack = upnClass.getStack();
+
+ private StringProperty newNumber = new SimpleStringProperty("");
+
+ private static Map<String, Operator> operators = new HashMap<>();
+
+ static
+ {
+ operators.put("+", new Addition());
+ operators.put("-", new Subtraction());
+ operators.put("*", new Multiplication());
+ operators.put("/", new Division());
+ operators.put("%", new Modulo());
+ operators.put("sin", new UnaryTemplate("sin"));
+ operators.put("cos", new UnaryTemplate("cos"));
+ operators.put("tan", new UnaryTemplate("tan"));
+ operators.put("log", new UnaryTemplate("log"));
+ operators.put("sqrt", new UnaryTemplate("sqrt"));
+ operators.put("pow", new BinaryTemplate("pow"));
+ }
+
+ @FXML
+ private void initialize()
+ {
+ txtField.textProperty().addListener(e -> {
+ btnComma.setDisable(!newNumber.isEmpty().get() && newNumber.get().contains("."));
+ btnZero.setDisable(!newNumber.isEmpty().get() && !newNumber.get().contains(".") && newNumber.get().contains("0"));
+ });
+
+ newNumber.addListener(e -> {
+ if(upnStack.isEmpty())
+ {
+ txtField.clear();
+ }
+ if(!newNumber.isEmpty().get())
+ {
+ txtField.setText(newNumber.get());
+
+ btnPlus.setDisable(upnStack.size() < 1);
+ btnMinus.setDisable(upnStack.size() < 1);
+ btnMul.setDisable(upnStack.size() < 1);
+ btnDiv.setDisable(upnStack.size() < 1);
+ btnPow.setDisable(upnStack.size() < 1);
+ btnXY.setDisable(upnStack.size() < 1);
+
+ btnLn.setDisable(upnStack.size() < 0);
+ btnSin.setDisable(upnStack.size() < 0);
+ btnCos.setDisable(upnStack.size() < 0);
+ btnTan.setDisable(upnStack.size() < 0);
+ btn1DivX.setDisable(upnStack.size() < 0);
+ btnSqr.setDisable(upnStack.size() < 0);
+ }
+ });
+
+ upnStack.sizeProperty().addListener(e -> {
+ txtField.clear();
+ if(upnStack.size() > 0)
+ {
+ txtField.setText(upnStack.peek().toString());
+ }
+
+ btnPlus.setDisable(upnStack.size() < 2);
+ btnMinus.setDisable(upnStack.size() < 2);
+ btnMul.setDisable(upnStack.size() < 2);
+ btnDiv.setDisable(upnStack.size() < 2);
+ btnPow.setDisable(upnStack.size() < 2);
+ btnXY.setDisable(upnStack.size() < 2);
+
+ btnLn.setDisable(upnStack.size() < 1);
+ btnSin.setDisable(upnStack.size() < 1);
+ btnCos.setDisable(upnStack.size() < 1);
+ btnTan.setDisable(upnStack.size() < 1);
+ btn1DivX.setDisable(upnStack.size() < 1);
+ btnSqr.setDisable(upnStack.size() < 1);
+
+ });
+ }
+
+ @FXML
+ private void handleInvert()
+ {
+ if (!newNumber.isEmpty().get())
+ {
+ if(newNumber.get().contains("-"))
+ {
+ newNumber.setValue(newNumber.get().replaceAll("-", ""));
+ }
+ else
+ {
+ newNumber.setValue("-".concat(newNumber.get()));
+ }
+ }
+ else
+ {
+ if(upnStack.size() > 0)
+ {
+ upnClass.addDouble(-1.0);
+ upnClass.calculate(operators.get("*"));
+ }
+ }
+ }
+
+ @FXML
+ private void handleClr()
+ {
+ newNumber.setValue("");
+ upnStack.clear();
+ }
+
+ @FXML
+ private void handleClx()
+ {
+ if (newNumber.isEmpty().get())
+ {
+ if(upnStack.size() > 0)
+ {
+ upnStack.pop();
+ }
+ }
+ else
+ {
+ newNumber.setValue("");
+ }
+ }
+
+ @FXML
+ private void handleLstX()
+ {
+ upnClass.setLastX();
+ }
+
+ @FXML
+ private void handleXY()
+ {
+ if(!newNumber.isEmpty().get())
+ {
+ handleEnt();
+ }
+
+ upnClass.swapXY();
+ }
+
+ @FXML
+ private void handleEnt()
+ {
+ if(!newNumber.isEmpty().get())
+ {
+ upnClass.addDouble(Double.parseDouble(newNumber.get().trim()));
+ newNumber.setValue("");
+ }
+ }
+
+ private void handleNumber(String number)
+ {
+ newNumber.set(newNumber.concat(number).get());
+ }
+
+ @FXML
+ private void handleNumber0()
+ {
+ handleNumber("0");
+ }
+
+ @FXML
+ private void handleNumberComma()
+ {
+ handleNumber(".");
+ }
+
+ @FXML
+ private void handleNumber1()
+ {
+ handleNumber("1");
+ }
+
+ @FXML
+ private void handleNumber2()
+ {
+ handleNumber("2");
+ }
+
+ @FXML
+ private void handleNumber3()
+ {
+ handleNumber("3");
+ }
+
+ @FXML
+ private void handleNumber4()
+ {
+ handleNumber("4");
+ }
+
+ @FXML
+ private void handleNumber5()
+ {
+ handleNumber("5");
+ }
+
+ @FXML
+ private void handleNumber6()
+ {
+ handleNumber("6");
+ }
+
+ @FXML
+ private void handleNumber7()
+ {
+ handleNumber("7");
+ }
+
+ @FXML
+ private void handleNumber8()
+ {
+ handleNumber("8");
+ }
+
+ @FXML
+ private void handleNumber9()
+ {
+ handleNumber("9");
+ }
+
+ @FXML
+ private void handle1DivX()
+ {
+ if (!newNumber.isEmpty().get())
+ {
+ handleEnt();
+ }
+ upnClass.addDouble(1.0);
+ handleXY();
+ upnClass.calculate(operators.get("/"));
+ }
+
+
+ private void handleOp(Operator operator)
+ {
+ if (!newNumber.isEmpty().get())
+ {
+ handleEnt();
+ }
+ upnClass.calculate(operator);
+ }
+
+ @FXML
+ private void handleOpPlus()
+ {
+ handleOp(operators.get("+"));
+ }
+
+ @FXML
+ private void handleOpMinus()
+ {
+ handleOp(operators.get("-"));
+ }
+
+ @FXML
+ private void handleOpMult()
+ {
+ handleOp(operators.get("*"));
+ }
+
+ @FXML
+ private void handleOpDiv()
+ {
+ handleOp(operators.get("/"));
+ }
+
+ @FXML
+ private void handleOpTan()
+ {
+ handleOp(operators.get("tan"));
+ }
+
+ @FXML
+ private void handleOpCos()
+ {
+ handleOp(operators.get("cos"));
+ }
+
+ @FXML
+ private void handleOpSin()
+ {
+ handleOp(operators.get("sin"));
+ }
+
+ @FXML
+ private void handleOpLn()
+ {
+ handleOp(operators.get("log"));
+ }
+
+ @FXML
+ private void handleOpSqr()
+ {
+ handleOp(operators.get("sqrt"));
+ }
+
+ @FXML
+ private void handleOpPow()
+ {
+ handleOp(operators.get("pow"));
+ }
+
+}