Skip to content

Commit

Permalink
add scientific buttons commands
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-chwedczuk committed Nov 20, 2024
1 parent 7aea842 commit 859176c
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,89 @@ public class ScientificCalculatorViewModel {

// --- SCIENTIFIC FUNCTIONS ---

public final InputViewModel scientificNotationOnOffButton = newInputViewModel()
.withText("F-E")
.withCommand(Command.CommandFE)
.withEnabled(radixProperty.isEqualTo(RadixType.Decimal))
.build();

public final InputViewModel dmsButton = newInputViewModel()
.withText("dms")
.withCommand(Command.CommandDMS)
.withEnabled(radixProperty.isEqualTo(RadixType.Decimal))
.build();

public final InputViewModel sineButton = newInputViewModel()
.withText("sine")
.withCommand(Command.CommandSIN)
.withEnabled(radixProperty.isEqualTo(RadixType.Decimal))
.build();

public final InputViewModel cosineButton = newInputViewModel()
.withText("cos")
.withCommand(Command.CommandCOS)
.withEnabled(radixProperty.isEqualTo(RadixType.Decimal))
.build();

public final InputViewModel tangentButton = newInputViewModel()
.withText("tan")
.withCommand(Command.CommandTAN)
.withEnabled(radixProperty.isEqualTo(RadixType.Decimal))
.build();

// --

public final InputViewModel openBracketButton = newInputViewModel()
.withText("(")
.withCommand(Command.CommandOPENP)
.build();

public final InputViewModel enterExponentButton = newInputViewModel()
.withText("Exp")
.withCommand(Command.CommandEXP)
.withEnabled(radixProperty.isEqualTo(RadixType.Decimal))
.build();

public final InputViewModel powerButton = newInputViewModel()
.withText("x^y")
.withCommand(Command.CommandPWR)
.build();

public final InputViewModel cubeButton = newInputViewModel()
.withText("x^3")
.withCommand(Command.CommandCUB)
.build();

public final InputViewModel squareButton = newInputViewModel()
.withText("x^2")
.withCommand(Command.CommandSQR)
.build();

// --

public final InputViewModel closeBracketButton = newInputViewModel()
.withText(")")
.withCommand(Command.CommandCLOSEP)
.build();

public final InputViewModel lnButton = newInputViewModel()
.withText("ln")
.withCommand(Command.CommandLN)
.build();

public final InputViewModel logButton = newInputViewModel()
.withText("log")
.withCommand(Command.CommandLOG)
.build();

public final InputViewModel factorialButton = newInputViewModel()
.withText("n!")
.withCommand(Command.CommandFAC)
.build();

public final InputViewModel reciprocalButton = newInputViewModel()
.withText("1/x")
.withCommand(Command.CommandREC)
.build();

public ScientificCalculatorViewModel() {
Expand Down
62 changes: 62 additions & 0 deletions gui/src/main/java/mscalc/gui/views/scientific/ScientificView.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,55 @@ public ScientificView() {

// Scientific block

@FXML
private Button bScientificNotation;

@FXML
private Button bDegreesMinutesSeconds;

@FXML
private Button bSine;

@FXML
private Button bCosine;

@FXML
private Button bTangent;

// --

@FXML
private Button bOpenBracket;

@FXML
private Button bEnterScientific;

@FXML
private Button bPower;

@FXML
private Button bCube;

@FXML
private Button bSquare;

// --

@FXML
private Button bCloseBracket;

@FXML
private Button bNaturalLog;

@FXML
private Button b10Logarithm;

@FXML
private Button bFactorial;

@FXML
private Button bOneOverX;

public void install(Scene scene) {
display.textProperty().bind(viewModel.displayProperty);

Expand Down Expand Up @@ -245,7 +291,23 @@ public void install(Scene scene) {
bindButton(bMemorySet, viewModel.memoryStoreButton);
bindButton(bMemoryAdd, viewModel.memoryAddButton);

bindButton(bScientificNotation, viewModel.scientificNotationOnOffButton);
bindButton(bDegreesMinutesSeconds, viewModel.dmsButton);
bindButton(bSine, viewModel.sineButton);
bindButton(bCosine, viewModel.cosineButton);
bindButton(bTangent, viewModel.tangentButton);

bindButton(bOpenBracket, viewModel.openBracketButton);
bindButton(bEnterScientific, viewModel.enterExponentButton);
bindButton(bPower, viewModel.powerButton);
bindButton(bCube, viewModel.cubeButton);
bindButton(bSquare, viewModel.squareButton);

bindButton(bCloseBracket, viewModel.closeBracketButton);
bindButton(bNaturalLog, viewModel.lnButton);
bindButton(b10Logarithm, viewModel.logButton);
bindButton(bFactorial, viewModel.factorialButton);
bindButton(bOneOverX, viewModel.reciprocalButton);

try {
scene.setOnKeyPressed(this::onKeyPressed);
Expand Down

0 comments on commit 859176c

Please sign in to comment.