├── settings.gradle
├── src
├── ios
│ ├── assets
│ │ ├── Icon-76.png
│ │ ├── Icon-60@2x.png
│ │ ├── Icon-60@3x.png
│ │ ├── Icon-76@2x.png
│ │ ├── Icon-Small.png
│ │ ├── iTunesArtwork
│ │ ├── Icon-Small-40.png
│ │ ├── Icon-Small@2x.png
│ │ ├── Icon-Small@3x.png
│ │ ├── iTunesArtwork@2x
│ │ ├── Icon-Small-40@2x.png
│ │ ├── Icon-Small-40@3x.png
│ │ ├── Default@2x~iphone.png
│ │ ├── Default-portrait~ipad.png
│ │ ├── Default-568h@2x~iphone.png
│ │ ├── Default-landscape~ipad.png
│ │ ├── Default-landscape@2x~ipad.png
│ │ ├── Default-portrait@2x~ipad.png
│ │ ├── Default-375w-667h@2x~iphone.png
│ │ ├── Default-414w-736h@3x~iphone.png
│ │ └── Default-414w-736h-landscape@3x~iphone.png
│ └── Default-Info.plist
├── main
│ ├── resources
│ │ └── com
│ │ │ └── adr
│ │ │ └── hellocalc
│ │ │ ├── styles
│ │ │ ├── main.properties
│ │ │ ├── maindark.properties
│ │ │ ├── RobotoMono-Bold.ttf
│ │ │ ├── RobotoMono-Light.ttf
│ │ │ ├── main.css
│ │ │ └── maindark.css
│ │ │ ├── images
│ │ │ └── icon.png
│ │ │ └── scripts
│ │ │ ├── basic.js
│ │ │ ├── scientific.js
│ │ │ ├── basic_keyboard.js
│ │ │ ├── mathcalc.js
│ │ │ ├── scientific_keyboard.js
│ │ │ ├── mathcalc_keyboard.js
│ │ │ └── mathcalc_keyboard_1.js
│ └── java
│ │ └── com
│ │ └── adr
│ │ └── hellocalc
│ │ ├── Script.java
│ │ ├── EventConsumer.java
│ │ ├── ObserverFunc.java
│ │ ├── VisitorButton.java
│ │ ├── Display.java
│ │ ├── ObservableStatus.java
│ │ ├── ButtonCommand.java
│ │ ├── CalcDefinition.java
│ │ ├── ObservableFunc.java
│ │ ├── CalcBtnBuilder.java
│ │ ├── ScriptWebEngine.java
│ │ ├── ScrollableLatexList.java
│ │ ├── ScriptRhino.java
│ │ ├── BasicEditor.java
│ │ ├── ResizableLatex.java
│ │ ├── ButtonAnimation.java
│ │ ├── ScrollableEditor.java
│ │ ├── Loading.java
│ │ ├── LatexDisplay.java
│ │ ├── Main.java
│ │ └── KeyboardNumbers.java
├── android
│ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-ldpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ └── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ ├── AndroidManifest.xml
│ └── icon.svg
└── test
│ └── java
│ └── com
│ └── adr
│ └── hellocalc
│ └── test
│ └── DSLTest.java
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradlew.bat
├── gradlew
└── LICENSE
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'hellocalc'
2 |
--------------------------------------------------------------------------------
/src/ios/assets/Icon-76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-76.png
--------------------------------------------------------------------------------
/src/ios/assets/Icon-60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-60@2x.png
--------------------------------------------------------------------------------
/src/ios/assets/Icon-60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-60@3x.png
--------------------------------------------------------------------------------
/src/ios/assets/Icon-76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-76@2x.png
--------------------------------------------------------------------------------
/src/ios/assets/Icon-Small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-Small.png
--------------------------------------------------------------------------------
/src/ios/assets/iTunesArtwork:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/iTunesArtwork
--------------------------------------------------------------------------------
/src/ios/assets/Icon-Small-40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-Small-40.png
--------------------------------------------------------------------------------
/src/ios/assets/Icon-Small@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-Small@2x.png
--------------------------------------------------------------------------------
/src/ios/assets/Icon-Small@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-Small@3x.png
--------------------------------------------------------------------------------
/src/ios/assets/iTunesArtwork@2x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/iTunesArtwork@2x
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # build application files
2 | target/
3 | /nbproject/
4 | /.gradle/
5 | /.nb-gradle/
6 | /build/
7 | /private/
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/src/ios/assets/Icon-Small-40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-Small-40@2x.png
--------------------------------------------------------------------------------
/src/ios/assets/Icon-Small-40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Icon-Small-40@3x.png
--------------------------------------------------------------------------------
/src/ios/assets/Default@2x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default@2x~iphone.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-portrait~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-portrait~ipad.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-568h@2x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-568h@2x~iphone.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-landscape~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-landscape~ipad.png
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/styles/main.properties:
--------------------------------------------------------------------------------
1 | result-color = black
2 | error-color = red
3 | expression-color = darkblue
4 |
5 |
--------------------------------------------------------------------------------
/src/android/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/android/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/android/res/mipmap-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/android/res/mipmap-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/android/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/android/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/android/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/android/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/android/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/android/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-landscape@2x~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-landscape@2x~ipad.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-portrait@2x~ipad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-portrait@2x~ipad.png
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/styles/maindark.properties:
--------------------------------------------------------------------------------
1 | result-color = #ffffff
2 | error-color = #ff4040
3 | expression-color = #60c8ff
4 |
--------------------------------------------------------------------------------
/src/android/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/android/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-375w-667h@2x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-375w-667h@2x~iphone.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-414w-736h@3x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-414w-736h@3x~iphone.png
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/main/resources/com/adr/hellocalc/images/icon.png
--------------------------------------------------------------------------------
/src/ios/assets/Default-414w-736h-landscape@3x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/ios/assets/Default-414w-736h-landscape@3x~iphone.png
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/styles/RobotoMono-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/main/resources/com/adr/hellocalc/styles/RobotoMono-Bold.ttf
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/styles/RobotoMono-Light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adrianromero/hellocalc/HEAD/src/main/resources/com/adr/hellocalc/styles/RobotoMono-Light.ttf
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
6 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/Script.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | /**
21 | *
22 | * @author adrian
23 | */
24 | public interface Script {
25 | public void init();
26 | public Object exec(String script);
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/EventConsumer.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | /**
21 | *
22 | * @author adrian
23 | */
24 | @FunctionalInterface
25 | public interface EventConsumer {
26 | public void handle(T t);
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ObserverFunc.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | /**
21 | *
22 | * @author adrian
23 | */
24 | @FunctionalInterface
25 | public interface ObserverFunc {
26 | public void notify(T model);
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/VisitorButton.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import javafx.scene.control.Button;
21 |
22 | /**
23 | *
24 | * @author adrian
25 | */
26 | @FunctionalInterface
27 | public interface VisitorButton {
28 | public void visit(Button b);
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/Display.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import javafx.scene.Node;
21 |
22 | /**
23 | *
24 | * @author adrian
25 | */
26 | public interface Display {
27 |
28 | public void updateResult(Script calc, Object result);
29 | public Node getNode();
30 | }
31 |
--------------------------------------------------------------------------------
/src/android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ObservableStatus.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | /**
21 | *
22 | * @author adrian
23 | */
24 | public class ObservableStatus extends ObservableFunc {
25 | private int status;
26 |
27 | public ObservableStatus(int status) {
28 | this.status = status;
29 | }
30 |
31 | public int getStatus() {
32 | return status;
33 | }
34 |
35 | public void setStatus(int status) {
36 | if (this.status == status) {
37 | return;
38 | }
39 | this.status = status;
40 | notify(status);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/scripts/basic.js:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | (function () {
19 |
20 | // system namespace
21 | calculator = {};
22 |
23 | // Calculator functions
24 | calculator.reset = function () {
25 | ANS = 0;
26 | return "";
27 | };
28 | calculator.mode = function() {
29 | return [];
30 | }
31 | calculator.latex = function() {
32 | return [];
33 | }
34 | calculator.eval = function (expression) {
35 | if (expression === undefined) {
36 | return;
37 | }
38 | return ANS = expression;
39 | };
40 |
41 | calculator.reset();
42 |
43 | }());
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ButtonCommand.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import javafx.event.ActionEvent;
21 | import javafx.event.EventHandler;
22 |
23 | /**
24 | *
25 | * @author adrian
26 | */
27 | public class ButtonCommand {
28 | private final String label;
29 | private final EventHandler command;
30 |
31 | public ButtonCommand(String label, EventHandler command) {
32 | this.label = label;
33 | this.command = command;
34 | }
35 |
36 | public String getLabel() {
37 | return label;
38 | }
39 |
40 | public EventHandler getCommand() {
41 | return command;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/CalcDefinition.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | /**
21 | *
22 | * @author adrian
23 | */
24 | public class CalcDefinition {
25 | private final String name;
26 | private final String keyboard;
27 | private final String[] resources;
28 |
29 | public CalcDefinition(String name, String keyboard, String[] resources) {
30 | this.name = name;
31 | this.keyboard = keyboard;
32 | this.resources = resources;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public String getKeyboard() {
40 | return keyboard;
41 | }
42 |
43 | public String[] getResources() {
44 | return resources;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ObservableFunc.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | /**
24 | *
25 | * @author adrian
26 | */
27 | public class ObservableFunc {
28 |
29 | private final List> observers = new LinkedList<>();
30 |
31 | public void addObserver(ObserverFunc obs) {
32 | if (obs == null) {
33 | throw new IllegalArgumentException();
34 | }
35 | if (observers.contains(obs)) {
36 | return;
37 | }
38 | observers.add(obs);
39 | }
40 |
41 | public void removeObserver(ObserverFunc obs) {
42 | if (obs == null) {
43 | throw new IllegalArgumentException();
44 | }
45 | observers.remove(obs);
46 | }
47 |
48 | public void notify(T data) {
49 | for (ObserverFunc obs : observers) {
50 | obs.notify(data);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/CalcBtnBuilder.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import javafx.scene.control.Button;
21 |
22 | /**
23 | *
24 | * @author adrian
25 | */
26 | public class CalcBtnBuilder {
27 |
28 | public CalcButton createCalcButton() {
29 | return new CalcButton();
30 | }
31 |
32 | public static class CalcButton {
33 |
34 | private final Button btn;
35 |
36 | private CalcButton() {
37 | btn = new Button();
38 | btn.getStyleClass().add("buttonkeyboard");
39 | btn.setFocusTraversable(false);
40 | btn.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
41 | ButtonAnimation.addPressedCircle(btn);
42 | }
43 |
44 | public CalcButton addClasses(String... classes) {
45 | btn.getStyleClass().addAll(classes);
46 | return this;
47 | }
48 |
49 | public CalcButton addVisitor(VisitorButton visitor) {
50 | visitor.visit(btn);
51 | return this;
52 | }
53 |
54 | public Button build() {
55 | return btn;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | HelloCalc (Calculator)
2 | ======================
3 |
4 | HelloCalc is a programable calculator for Android created with JavaFX.
5 |
6 | 
7 |
8 | Examples
9 | ========
10 |
11 | Expressions evaluation
12 | ----------------------
13 | 
14 | 
15 |
16 | Complex calculation
17 | -------------------
18 | 
19 | 
20 |
21 | Matrix calculation
22 | ------------------
23 | 
24 | 
25 |
26 | Function definitions
27 | --------------------
28 | 
29 | 
30 | 
31 | 
32 |
33 | Compilation
34 | ===========
35 |
36 | Generates a debug Android apk containing the HelloCalc application.
37 |
38 | ```
39 | ./gradlew android
40 | ```
41 |
42 | Acknowledgments
43 | ===============
44 |
45 | HelloCalc just glues all the following projects together into one single application. All credit goes to these projects.
46 |
47 | * [Mathjs](https://github.com/josdejong/mathjs) Copyright (C) 2013-2016 Jos de Jong wjosdejong@gmail.com. Apache License, Version 2.0.
48 | * [Mozilla Rhino](https://github.com/mozilla/rhino) Copyright (C) 2005-2016 Mozilla Developer Network and individual contributors. Mozilla Public License Version 2.0.
49 | * [JLatexMathFX](https://github.com/bitstormGER/jlatexmathfx) GNU General Public License, version 2. This library is a port to JavaFX of [JLatexMath](https://github.com/opencollab/jlatexmath).
50 | * [JavaFXPorts](http://gluonhq.com/labs/javafxports/)
51 | * [Roboto Fonts](https://fonts.google.com/specimen/Roboto) Apache License, Version 2.0.
52 |
53 | License
54 | =======
55 |
56 | Licensed under the GNU General Public License, Version 3.
57 |
--------------------------------------------------------------------------------
/src/ios/Default-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleIdentifier
6 | com.adr.hellogluon.Main
7 | CFBundleVersion
8 | 1.0
9 | CFBundleExecutable
10 | hellogluon
11 | CFBundleIconFiles
12 |
13 | Icon-60
14 | Icon-76
15 | Icon-Small-40
16 | Icon-Small
17 |
18 | CFBundleIconFiles~ipad
19 |
20 | Icon-76
21 | Icon-Small-40
22 | Icon-Small
23 |
24 | CFBundleName
25 | hellogluon
26 | CFBundlePackageType
27 | APPL
28 | LSRequiresIPhoneOS
29 |
30 | UISupportedInterfaceOrientations
31 |
32 | UIInterfaceOrientationPortrait
33 | UIInterfaceOrientationLandscapeLeft
34 | UIInterfaceOrientationLandscapeRight
35 | UIInterfaceOrientationPortraitUpsideDown
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationLandscapeLeft
41 | UIInterfaceOrientationLandscapeRight
42 | UIInterfaceOrientationPortraitUpsideDown
43 |
44 | UIRequiredDeviceCapabilities
45 |
46 | armv7
47 |
48 | UIDeviceFamily
49 |
50 | 1
51 | 2
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ScriptWebEngine.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import javafx.scene.web.WebEngine;
23 | import javafx.scene.web.WebView;
24 | import netscape.javascript.JSException;
25 | import netscape.javascript.JSObject;
26 |
27 | /**
28 | *
29 | * @author adrian
30 | */
31 | public class ScriptWebEngine implements Script {
32 |
33 | private WebView browser;
34 | private WebEngine webEngine;
35 |
36 | @Override
37 | public void init() {
38 | browser = new WebView();
39 | webEngine = browser.getEngine();
40 | }
41 |
42 | @Override
43 | public Object exec(String script) {
44 | try {
45 | Object result = webEngine.executeScript(script);
46 | if (result.equals("undefined")) {
47 | return null;
48 | } else if (result instanceof JSObject) {
49 | JSObject jsresult = (JSObject) result;
50 | Object length = jsresult.getMember("length");
51 | if (length instanceof Integer) {
52 | // It is an array
53 | Integer ilength = (Integer) length;
54 | List lresult = new ArrayList<>(ilength);
55 | for (int i = 0; i < ilength; i++) {
56 | lresult.add(jsresult.getSlot(i));
57 | }
58 | return lresult;
59 | } else {
60 | return result;
61 | }
62 | } else {
63 | return result;
64 | }
65 | } catch (JSException ex) {
66 | return ex; // do not throw it, just return it
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/com/adr/hellocalc/test/DSLTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.adr.hellocalc.test;
7 |
8 | import java.util.NoSuchElementException;
9 | import java.util.Scanner;
10 | import org.junit.After;
11 | import org.junit.AfterClass;
12 | import org.junit.Assert;
13 | import org.junit.Before;
14 | import org.junit.BeforeClass;
15 | import org.junit.Test;
16 |
17 | /**
18 | *
19 | * @author adrian
20 | */
21 | public class DSLTest {
22 |
23 | public DSLTest() {
24 | }
25 |
26 | @BeforeClass
27 | public static void setUpClass() {
28 | }
29 |
30 | @AfterClass
31 | public static void tearDownClass() {
32 | }
33 |
34 | @Before
35 | public void setUp() {
36 | }
37 |
38 | @After
39 | public void tearDown() {
40 | }
41 |
42 | @Test
43 | public void scanLiterals() {
44 | String rx;
45 | Scanner scanner;
46 |
47 | rx = "[^\"\\s]+|\"(\\\\.|[^\\\\\"])*\"";
48 | scanner = new Scanner("P 160, SomethingElse \"A string \\\"literal\" end"); // does not check \" outside a literal
49 | System.out.println("-->");
50 | System.out.println(scanner.findInLine(rx)); // => P
51 | System.out.println(scanner.findInLine(rx)); // => 160
52 | System.out.println(scanner.findInLine(rx)); // => SomethingElse
53 | System.out.println(scanner.findInLine(rx)); // => "A string literal"
54 | System.out.println(scanner.findInLine(rx)); // => end
55 |
56 | rx = "[^\"\\s\\,]+|\"(\\\\.|[^\\\\\"])*\""; // This is the good expression: separator spaces and commas.
57 | scanner = new Scanner("P 160,SomethingElse \"A string \\\"literal\" end\nNew line"); // does not check \" outside a literal
58 | System.out.println("-->");
59 | System.out.println(scanner.findInLine(rx)); // => P
60 | System.out.println(scanner.findInLine(rx)); // => 160
61 | System.out.println(scanner.findInLine(rx)); // => SomethingElse
62 | System.out.println(scanner.findInLine(rx)); // => "A string literal"
63 | System.out.println(scanner.findInLine(rx)); // => end
64 | System.out.println(scanner.findInLine(rx)); // => null
65 |
66 | System.out.println("nextline -> " + scanner.nextLine());
67 | System.out.println(scanner.findInLine(rx)); // => New
68 | System.out.println(scanner.findInLine(rx)); // => line
69 | System.out.println(scanner.findInLine(rx)); // => null
70 |
71 | try {
72 | System.out.println("nextline -> " + scanner.nextLine()); // throws Exception
73 | Assert.fail();
74 | } catch (NoSuchElementException ex) {
75 | System.out.println("End of file");
76 | }
77 |
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/styles/main.css:
--------------------------------------------------------------------------------
1 | /*
2 | HelloCalc (Calculator) is a JavaFX calculator
3 | Copyright (C) 2016 Adrián Romero Corchado.
4 |
5 | This file is part of HelloCalc
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | .root {
21 | button-color: lightgray;
22 | }
23 |
24 | .scroll-pane > .viewport {
25 | -fx-background-color: transparent;
26 | }
27 |
28 | .buttonkeyboard {
29 | -fx-font-size: 22px;
30 | -fx-font-family: 'ROBOTO MONO LIGHT';
31 | -fx-text-fill: #505050;
32 | -fx-background-color: button-color;
33 | -fx-background-radius: 0px;
34 | -fx-background-insets: 0px;
35 | -fx-padding: 5 0 5 0;
36 | -fx-alignment: center;
37 | -fx-pref-height: 40;
38 | -fx-min-height: 40;
39 | -fx-max-height: 40;
40 | }
41 |
42 | .buttonkeyboard:armed {
43 | -fx-background-color: derive(button-color, 30%);
44 | }
45 |
46 | .functionkeyboard {
47 | button-color: derive(orange, 40%);
48 | }
49 |
50 | .function2keyboard {
51 | button-color: derive(red, 80%);
52 | }
53 |
54 | .execkeyboard {
55 | button-color: #6098ff;
56 | }
57 |
58 | .graykeyboard {
59 | button-color: #c0c0c0;
60 | -fx-font-size: 23px;
61 | }
62 |
63 | .textkeyboard {
64 | -fx-font-size: 18px;
65 | }
66 |
67 | .modekeyboard {
68 | -fx-font-family: 'ROBOTO MONO BOLD';
69 | -fx-font-size: 12px;
70 | -fx-pref-height: -1;
71 | -fx-min-height: -1;
72 | -fx-max-height: -1;
73 | button-color: darkgray;
74 | -fx-text-fill: white;
75 | -fx-padding: 2 0 2 0;
76 | }
77 | .modekeyboardselected {
78 | button-color: #404040;
79 | }
80 |
81 | .displayresult {
82 | /* No font syling - Font is managed in code */
83 | -fx-fill: #303030;
84 | }
85 | .displayerror {
86 | -fx-fill: #ff5050;
87 | }
88 |
89 | .calcindicator {
90 | -fx-font-size: 18;
91 | -fx-font-family: 'ROBOTO MONO BOLD';
92 | }
93 |
94 | .displayedit {
95 | /* No font syling - Font is managed in code */
96 | -fx-fill: #909090;
97 | }
98 |
99 | .loading-gears {
100 | -fx-fill: #404040;
101 | }
102 |
103 | .loading-rect {
104 | -fx-fill: #e0e0e0;
105 | -fx-stroke: #e0e0e0;
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ScrollableLatexList.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import java.util.HashSet;
21 | import java.util.Set;
22 | import java.util.logging.Logger;
23 | import javafx.beans.value.ChangeListener;
24 | import javafx.beans.value.ObservableValue;
25 | import javafx.geometry.Insets;
26 | import javafx.scene.control.ScrollPane;
27 | import javafx.scene.layout.Background;
28 | import javafx.scene.layout.Border;
29 | import javafx.scene.layout.VBox;
30 |
31 | /**
32 | *
33 | * @author adrian
34 | */
35 | public class ScrollableLatexList extends ScrollPane {
36 |
37 | private static final Logger LOG = Logger.getLogger(ScrollableLatexList.class.getName());
38 |
39 | private final VBox view;
40 | private final Set latexs = new HashSet<>();
41 |
42 | public ScrollableLatexList() {
43 |
44 | view = new VBox();
45 | setContent(view);
46 |
47 | // this.setAlignment(Pos.TOP_RIGHT);
48 | setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
49 | setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
50 | setFocusTraversable(false);
51 | setPannable(true);
52 | setBackground(Background.EMPTY);
53 | setBorder(Border.EMPTY);
54 | setPadding(new Insets(0.0));
55 | setFitToHeight(true);
56 | widthProperty().addListener(new ChangeListener() {
57 | @Override
58 | public void changed(ObservableValue extends Number> observable, Number oldValue, Number newValue) {
59 | adjustEditorSize(newValue.doubleValue());
60 | }
61 | });
62 | }
63 |
64 | public void clearLatex() {
65 | view.getChildren().removeAll(latexs);
66 | latexs.clear();
67 | setHvalue(getHmin());
68 | }
69 |
70 | public void addLatex(ResizableLatex latex) {
71 | latexs.add(latex);
72 | view.getChildren().add(latex);
73 | latex.adjustEditorSize(getWidth());
74 | setHvalue(getHmin());
75 | }
76 |
77 | private void adjustEditorSize(double width) {
78 | for(ResizableLatex latex: latexs) {
79 | latex.adjustEditorSize(width);
80 | }
81 | setHvalue(getHmin());
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/styles/maindark.css:
--------------------------------------------------------------------------------
1 | /*
2 | HelloCalc (Calculator) is a JavaFX calculator
3 | Copyright (C) 2016 Adrián Romero Corchado.
4 |
5 | This file is part of HelloCalc
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 | */
20 | .root {
21 | button-color: lightgray;
22 | }
23 |
24 | .rootpane {
25 | -fx-background-color: black;
26 | }
27 |
28 | .scroll-pane > .viewport {
29 | -fx-background-color: transparent;
30 | }
31 |
32 | .buttonkeyboard {
33 | -fx-font-size: 22px;
34 | -fx-font-family: 'ROBOTO MONO LIGHT';
35 | -fx-text-fill: #f0f0f0;
36 | -fx-background-color: button-color, black;
37 | -fx-background-radius: 5px 5px 5px 5px, 8px 8px 16px 16px;
38 | -fx-background-insets: 2px, 3px;
39 | -fx-padding: 5 0 5 0;
40 | -fx-alignment: center;
41 | -fx-pref-height: 40;
42 | -fx-min-height: 40;
43 | -fx-max-height: 40;
44 | }
45 |
46 | .buttonkeyboard:armed {
47 | -fx-background-color: button-color, #404040;
48 | }
49 |
50 | .functionkeyboard {
51 | button-color: derive(orange, 40%);
52 | }
53 |
54 | .function2keyboard {
55 | button-color: derive(red, 80%);
56 | }
57 |
58 | .execkeyboard {
59 | button-color: #6098ff;
60 | }
61 |
62 | .graykeyboard {
63 | button-color: #909090;
64 | -fx-font-size: 23px;
65 | }
66 |
67 | .textkeyboard {
68 | -fx-font-size: 18px;
69 | }
70 |
71 | .modekeyboard {
72 | -fx-font-family: 'ROBOTO MONO BOLD';
73 | -fx-font-size: 12px;
74 | -fx-pref-height: -1;
75 | -fx-min-height: -1;
76 | -fx-max-height: -1;
77 | button-color: darkgray;
78 | -fx-text-fill: white;
79 | -fx-padding: 2 0 2 0;
80 | }
81 | .modekeyboardselected {
82 | -fx-background-color: button-color, #404040;
83 | }
84 |
85 | .displayresult {
86 | /* No font syling - Font is managed in code */
87 | -fx-fill: #303030;
88 | }
89 | .displayerror {
90 | -fx-fill: #ff5050;
91 | }
92 |
93 | .calcindicator {
94 | -fx-fill: #d0d0d0;
95 | -fx-font-size: 18;
96 | -fx-font-family: 'ROBOTO MONO BOLD';
97 | }
98 |
99 | .displayedit {
100 | /* No font syling - Font is managed in code */
101 | -fx-fill: #f0f0f0;
102 | }
103 |
104 | .loading-gears {
105 | -fx-fill: #e0e0e0;
106 | }
107 |
108 | .loading-rect {
109 | -fx-fill: transparent;
110 | -fx-stroke: #e0e0e0;
111 | }
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ScriptRhino.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.io.ObjectInputStream;
23 | import java.io.ObjectOutputStream;
24 | import java.io.OutputStream;
25 | import java.util.concurrent.locks.ReentrantLock;
26 | import org.mozilla.javascript.Context;
27 | import org.mozilla.javascript.Scriptable;
28 | import org.mozilla.javascript.ScriptableObject;
29 | import org.mozilla.javascript.Undefined;
30 |
31 | /**
32 | *
33 | * @author adrian
34 | */
35 | public class ScriptRhino implements Script {
36 |
37 | private final ReentrantLock lock = new ReentrantLock();
38 | private Scriptable scope;
39 |
40 | @Override
41 | public void init() {
42 | lock.lock();
43 | try {
44 | Context cx = Context.enter();
45 | cx.setOptimizationLevel(-1); // allways interpretive mode
46 | scope = cx.initStandardObjects();
47 | } finally {
48 | Context.exit();
49 | lock.unlock();
50 | }
51 | }
52 |
53 | @Override
54 | public Object exec(String script) {
55 | lock.lock();
56 | try {
57 | Context cx = Context.enter();
58 | cx.setOptimizationLevel(-1); // always interpretive mode
59 | Object result = cx.evaluateString(scope, script, "", 1, null);
60 | if (result instanceof Undefined) {
61 | return null;
62 | } else {
63 | return result;
64 | }
65 | } catch (Exception e) {
66 | return e;
67 | } finally {
68 | Context.exit();
69 | lock.unlock();
70 | }
71 | }
72 |
73 | public void init(InputStream in) throws IOException {
74 | lock.lock();
75 | try (ObjectInputStream objin = new ObjectInputStream(in)) {
76 | scope = (Scriptable) objin.readObject();
77 | } catch (ClassNotFoundException ex) {
78 | throw new IOException(ex);
79 | } finally {
80 | lock.unlock();
81 | }
82 | }
83 |
84 | public void save(OutputStream out) throws IOException {
85 | lock.lock();
86 | try (ObjectOutputStream objout = new ObjectOutputStream(out)) {
87 | objout.writeObject(scope);
88 | } finally {
89 | lock.unlock();
90 | }
91 | }
92 |
93 | public void putScopeObject(String name, Object obj) {
94 | lock.lock();
95 | try {
96 | Context cx = Context.enter();
97 | cx.setOptimizationLevel(-1); // always interpretive mode
98 | ScriptableObject.putProperty(scope, name, Context.javaToJS(obj, scope));
99 | } finally {
100 | Context.exit();
101 | lock.unlock();
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/BasicEditor.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import java.util.Deque;
21 | import java.util.LinkedList;
22 | import javafx.animation.FadeTransition;
23 | import javafx.animation.Interpolator;
24 | import javafx.animation.ParallelTransition;
25 | import javafx.animation.Transition;
26 | import javafx.animation.TranslateTransition;
27 | import javafx.event.ActionEvent;
28 | import javafx.event.EventHandler;
29 | import javafx.scene.Node;
30 | import javafx.util.Duration;
31 |
32 | /**
33 | *
34 | * @author adrian
35 | */
36 | public class BasicEditor {
37 |
38 | private final ScrollableEditor text;
39 | private final Deque textqueue = new LinkedList<>();
40 | private final Deque backtextqueue = new LinkedList<>();
41 |
42 | private final Transition cleartransition;
43 |
44 | public BasicEditor() {
45 | text = new ScrollableEditor(32.0, 18.0);
46 |
47 | FadeTransition ft2 = new FadeTransition(Duration.millis(300));
48 | ft2.setFromValue(1.0);
49 | ft2.setToValue(0.0);
50 |
51 | TranslateTransition tr2 = new TranslateTransition(Duration.millis(300));
52 | tr2.setFromY(0.0);
53 | tr2.setToY(-35.0);
54 | tr2.setInterpolator(Interpolator.EASE_OUT);
55 |
56 | cleartransition = new ParallelTransition(text.getNode(), ft2, tr2);
57 | cleartransition.setOnFinished(new EventHandler() {
58 | @Override
59 | public void handle(ActionEvent event) {
60 | text.setText(getExpression());
61 | text.getNode().setOpacity(1.0);
62 | text.getNode().setTranslateY(0.0);
63 | }
64 | });
65 | }
66 |
67 | public void addCommand(String str) {
68 | if ("".equals(str)) { // Delete all entries.
69 | if (!textqueue.isEmpty()) {
70 | backtextqueue.clear();
71 | backtextqueue.addAll(textqueue);
72 | }
73 | textqueue.clear();
74 | cleartransition.playFromStart();
75 | } else if ("".equals(str)) { // Delete last entry
76 | textqueue.pollLast();
77 | text.setText(getExpression());
78 | } else if ("".equals(str)) { // Revert
79 | Deque swaptextqueue = new LinkedList<>(textqueue);
80 | textqueue.clear();
81 | textqueue.addAll(backtextqueue);
82 | backtextqueue.clear();
83 | backtextqueue.addAll(swaptextqueue);
84 | text.setText(getExpression());
85 | } else {
86 | textqueue.add(str);
87 | text.setText(getExpression());
88 | }
89 | }
90 |
91 | public String getExpression() {
92 | StringBuilder b = new StringBuilder();
93 | for (String part : textqueue) {
94 | b.append(part);
95 | }
96 | return b.toString();
97 | }
98 |
99 | public Node getNode() {
100 | return text.getNode();
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/scripts/scientific.js:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | (function () {
19 |
20 | // system namespace
21 | calculator = {};
22 |
23 | // constants
24 | e = Math.E;
25 | pi = Math.PI;
26 |
27 | // functions
28 | sqrt = function (x) {
29 | return Math.sqrt(x);
30 | };
31 | pow = function (x, y) {
32 | return Math.pow(x, y);
33 | };
34 | log = function (x) {
35 | return Math.log10(x);
36 | };
37 | ln = function (x) {
38 | return Math.log(x);
39 | };
40 | pow10 = function (x) {
41 | return Math.pow(10.0, x);
42 | };
43 | exp = function (x) {
44 | return Math.exp(x);
45 | };
46 | var fmemo = [];
47 | var ffac = function (n) {
48 | if (n <= 1)
49 | return 1;
50 | if (fmemo[n] > 0)
51 | return fmemo[n];
52 | return fmemo[n] = ffac(n - 1) * n;
53 | };
54 | fac = function (n) {
55 | return ffac(Math.floor(n));
56 | };
57 |
58 | // radians to labels switch
59 | calculator.radiansmode = 'RAD';
60 | calculator.radiansmodenext = 'DEG';
61 | calculator.radiansfactor = 1.0;
62 | calculator.radiansfactorswitch = function () {
63 | if ('RAD' === calculator.radiansmode) {
64 | calculator.radiansmode = 'DEG';
65 | calculator.radiansfactor = Math.PI / 180.0;
66 | calculator.radiansmodenext = 'RAD';
67 | } else {
68 | calculator.radiansmode = 'RAD';
69 | calculator.radiansfactor = 1.0;
70 | calculator.radiansmodenext = 'DEG';
71 | }
72 | };
73 | calculator.mode = function () {
74 | return [calculator.radiansmode];
75 | };
76 | calculator.latex = function() {
77 | return [];
78 | }
79 | // Trigonometric functions with adjustments
80 | sin = function (x) {
81 | var result = Math.sin(x * calculator.radiansfactor);
82 | return (result > -1E-12 && result < 1E-12) ? 0.0 : result;
83 | };
84 | cos = function (x) {
85 | var result = Math.cos(x * calculator.radiansfactor);
86 | return (result > -1E-12 && result < 1E-12) ? 0.0 : result;
87 | };
88 | tan = function (x) {
89 | var result = Math.tan(x * calculator.radiansfactor);
90 | if (result > -1E-12 && result < 1E-12) {
91 | return 0.0;
92 | } else if (result > 1E12) {
93 | return 1 / 0;
94 | } else if (result < -1E12) {
95 | return -1 / 0;
96 | } else {
97 | return result;
98 | }
99 | };
100 | asin = function (x) {
101 | return Math.asin(x) / calculator.radiansfactor;
102 | };
103 | acos = function (x) {
104 | return Math.acos(x) / calculator.radiansfactor;
105 | };
106 | atan = function (x) {
107 | return Math.atan(x) / calculator.radiansfactor;
108 | };
109 |
110 | // Calculator functions
111 | calculator.reset = function () {
112 | ANS = 0;
113 | return "";
114 | };
115 | calculator.eval = function (expression) {
116 | if (expression === undefined) {
117 | return;
118 | }
119 | return ANS = expression;
120 | };
121 |
122 | calculator.reset();
123 | }());
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/scripts/basic_keyboard.js:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | /* global KEYBOARDBUILDER, CALCBUTTONBUILDER */
20 | (function () {
21 | var keyboard = KEYBOARDBUILDER.createKeyboard(5, 4);
22 |
23 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("7"))).addClasses("graykeyboard").build());
24 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("8"))).addClasses("graykeyboard").build());
25 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("9"))).addClasses("graykeyboard").build());
26 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("DEL", ""))).addClasses("functionkeyboard", "textkeyboard").build());
27 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("AC", "calculator.reset();", ""))).addClasses("functionkeyboard", "textkeyboard").build());
28 |
29 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("4"))).addClasses("graykeyboard").build());
30 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("5"))).addClasses("graykeyboard").build());
31 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("6"))).addClasses("graykeyboard").build());
32 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("*"))).build());
33 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("/"))).build());
34 |
35 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("1"))).addClasses("graykeyboard").build());
36 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("2"))).addClasses("graykeyboard").build());
37 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("3"))).addClasses("graykeyboard").build());
38 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("+"))).build());
39 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("-"))).build());
40 |
41 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("0"))).addClasses("graykeyboard").build());
42 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("."))).addClasses("graykeyboard").build());
43 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("ANS"))).addClasses("graykeyboard").build());
44 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("ENTER", "calculator.eval(%%%%%%)", ""))).addClasses("execkeyboard", "textkeyboard").build(), 2);
45 |
46 | }());
47 |
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/scripts/mathcalc.js:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | /* global math */
20 | (function () {
21 |
22 | var scope = {};
23 |
24 | // system namespace
25 | calculator = {};//
26 | // radians to labels switch
27 | calculator.radiansmode = "RAD";
28 | calculator.radiansmodenext = "DEG";
29 | calculator.radiansfactor = 1.0;
30 | calculator.radiansfactorswitch = function () {
31 | if ("RAD" === calculator.radiansmode) {
32 | calculator.radiansmode = "DEG";
33 | calculator.radiansfactor = Math.PI / 180.0;
34 | calculator.radiansmodenext = "RAD";
35 | } else {
36 | calculator.radiansmode = "RAD";
37 | calculator.radiansfactor = 1.0;
38 | calculator.radiansmodenext = "DEG";
39 | }
40 | };
41 | calculator.mode = function () {
42 | return [calculator.radiansmode];
43 | };
44 | calculator.latex = function () {
45 | return calculator.latexmodel;
46 | };
47 | calculator.reset = function () {
48 | calculator.latexmodel = [];
49 | calculator.EXP = null;
50 | ANS = scope.ANS = 0;
51 | return "";
52 | };
53 | calculator.eval = function (strexpression) {
54 | if (strexpression === "") {
55 | return;
56 | }
57 |
58 | calculator.latexmodel = [];
59 | calculator.EXP = strexpression;
60 |
61 | var exp = math.parse(strexpression);
62 | var result = exp.eval(scope);
63 | calculator.latexmodel = [exp.toTex()];
64 |
65 | ANS = scope.ANS = result;
66 | return math.parse(math.format(result, 10)).toTex();
67 | };
68 |
69 | var funcs = {};
70 | // create trigonometric functions replacing the input depending on angle config
71 | ["sin", "cos", "tan", "sec", "cot", "csc"].forEach(function (name) {
72 | var fn = math[name]; // the original function
73 | var fnNumber = function (x) {
74 | var result = fn(x * calculator.radiansfactor);
75 | if (result > -1E-12 && result < 1E-12) {
76 | return 0.0;
77 | } else if (result > 1E12) {
78 | return 1 / 0;
79 | } else if (result < -1E12) {
80 | return -1 / 0;
81 | } else {
82 | return result;
83 | }
84 | };
85 | // create a typed-function which check the input types
86 | funcs[name] = math.typed(name, {
87 | "number": fnNumber,
88 | "Array | Matrix": function (x) {
89 | return math.map(x, fnNumber);
90 | }
91 | });
92 | });
93 | // create trigonometric functions replacing the output depending on angle config
94 | ["asin", "acos", "atan", "atan2", "acot", "acsc", "asec"].forEach(function (name) {
95 | var fn = math[name]; // the original function
96 | var fnNumber = function (x) {
97 | var result = fn(x);
98 | if (typeof result === "number") {
99 | return result / calculator.radiansfactor;
100 | } else {
101 | return result;
102 | }
103 | };
104 | // create a typed-function which check the input types
105 | funcs[name] = math.typed(name, {
106 | "number": fnNumber,
107 | "Array | Matrix": function (x) {
108 | return math.map(x, fnNumber);
109 | }
110 | });
111 | });
112 | // import all replacements into math.js, override existing trigonometric functions
113 | math.import(funcs, {override: true});
114 |
115 | //initialization of engine
116 | calculator.reset();
117 | math.parse("sqrt(pi/2)*sin(3)+e^2").eval();
118 | return;
119 |
120 | }());
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ResizableLatex.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | package com.adr.hellocalc;
20 |
21 | import java.util.logging.Level;
22 | import java.util.logging.Logger;
23 | import javafx.geometry.HPos;
24 | import javafx.scene.canvas.Canvas;
25 | import javafx.scene.paint.Color;
26 | import javafx.scene.paint.Paint;
27 | import org.scilab.forge.jlatexmath.ParseException;
28 | import org.scilab.forge.jlatexmath.TeXConstants;
29 | import org.scilab.forge.jlatexmath.TeXFormula;
30 | import org.scilab.forge.jlatexmath.TeXIcon;
31 |
32 | /**
33 | *
34 | * @author adrian
35 | */
36 | public class ResizableLatex extends Canvas {
37 |
38 | private static final Logger LOG = Logger.getLogger(ResizableLatex.class.getName());
39 |
40 | private final double minsize;
41 | private final double maxsize;
42 | private final HPos alignment;
43 |
44 | private String latex = null;
45 | private Paint color = Color.BLACK;
46 | private double currentwidth = 100.0;
47 |
48 | public ResizableLatex(double minsize, double maxsize) {
49 | this(minsize, maxsize, HPos.LEFT);
50 | }
51 |
52 | public ResizableLatex(double minsize, double maxsize, HPos alignment) {
53 | this.minsize = minsize;
54 | this.maxsize = maxsize;
55 | this.alignment = alignment;
56 | }
57 |
58 |
59 | public void setLatex(String latex) {
60 | setLatex(latex, Color.BLACK);
61 | }
62 |
63 | public void setLatex(String latex, Paint color) {
64 | this.latex = latex;
65 | this.color = color;
66 | adjustEditorSize(currentwidth);
67 | }
68 |
69 | public void adjustEditorSize(double newwidth) {
70 |
71 | currentwidth = newwidth;
72 | if (latex == null || latex.isEmpty()) {
73 | clearCanvas();
74 | } else {
75 | try {
76 | TeXFormula teXFormula = new TeXFormula(latex.replaceAll("~", "\\ ")); // The replaceAll is an awful and dirty hack to print properly complex numbers: 1 + 4i
77 |
78 | TeXIcon teXIcon = teXFormula.createTeXIcon(TeXConstants.STYLE_DISPLAY, maxsize);
79 | double height = teXIcon.getTrueIconHeight() + 10.0;
80 | double width = teXIcon.getTrueIconWidth() + 10.0;
81 | double size = maxsize;
82 |
83 | while (width > currentwidth && size > minsize) {
84 | size -= 0.1;
85 | teXIcon = teXFormula.createTeXIcon(TeXConstants.STYLE_DISPLAY, size);
86 | height = teXIcon.getTrueIconHeight() + 10.0;
87 | width = teXIcon.getTrueIconWidth() + 10.0;
88 | }
89 | setHeight(height);
90 | switch (alignment) {
91 | case RIGHT:
92 | setWidth(currentwidth);
93 | teXIcon.paintInCanvas(this, (int) (currentwidth - width) + 5, 5, color, Color.TRANSPARENT);
94 | break;
95 | case CENTER:
96 | setWidth(currentwidth);
97 | teXIcon.paintInCanvas(this, (int) ((currentwidth - width) / 2) - 5, 5, color, Color.TRANSPARENT);
98 | break;
99 | default:
100 | setWidth(width);
101 | teXIcon.paintInCanvas(this, 5, 5, color, Color.TRANSPARENT);
102 | break;
103 | }
104 | } catch (ParseException ex) {
105 | LOG.log(Level.WARNING, "Cannot parse LaTex formula." + latex, ex);
106 | clearCanvas();
107 | }
108 | }
109 | }
110 |
111 | private void clearCanvas() {
112 | setHeight(0.0);
113 | setWidth(0.0);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ButtonAnimation.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 |
21 | import javafx.animation.Animation;
22 | import javafx.animation.FadeTransition;
23 | import javafx.animation.Interpolator;
24 | import javafx.animation.ParallelTransition;
25 | import javafx.animation.ScaleTransition;
26 | import javafx.event.EventHandler;
27 | import javafx.geometry.Point2D;
28 | import javafx.scene.Parent;
29 | import javafx.scene.control.Control;
30 | import javafx.scene.input.MouseEvent;
31 | import javafx.scene.layout.AnchorPane;
32 | import javafx.scene.paint.Color;
33 | import javafx.scene.paint.Paint;
34 | import javafx.scene.shape.Circle;
35 | import javafx.util.Duration;
36 |
37 | /**
38 | *
39 | * @author adrian
40 | */
41 | public class ButtonAnimation {
42 |
43 | public static void addPressedCircle(Control n) {
44 | addPressedCircle(n, Color.gray(1.0, 0.25), Color.gray(1.0, 0.7));
45 | }
46 |
47 | public static void addPressedCircle(Control n, Paint p, Paint s) {
48 | n.addEventFilter(MouseEvent.MOUSE_PRESSED, ev1 -> {
49 | Point2D point = new Point2D(n.getWidth() / 2.0, n.getHeight() / 2.0);
50 | Parent root = n;
51 | while(!(root instanceof AnchorPane)) {
52 | point = root.localToParent(point);
53 | root = root.getParent();
54 | }
55 | AnchorPane rootanchor = (AnchorPane) root;
56 |
57 | Circle c = new Circle(point.getX(), point.getY(), 10.0, p);
58 | c.setStroke(s);
59 | c.setStrokeWidth(0.15);
60 | c.setMouseTransparent(true);
61 | rootanchor.getChildren().add(c);
62 |
63 | Mutable continueTillEnd = new Mutable<>();
64 | continueTillEnd.value = false;
65 |
66 | // exit transition
67 | FadeTransition outtransition = new FadeTransition(Duration.millis(500), c);
68 | outtransition.setFromValue(1.0);
69 | outtransition.setToValue(0.0);
70 | outtransition.setInterpolator(Interpolator.EASE_IN);
71 | outtransition.setOnFinished(ev -> {
72 | rootanchor.getChildren().remove(c);
73 | });
74 |
75 | // enter transtion
76 | FadeTransition enterfade = new FadeTransition(Duration.millis(400));
77 | enterfade.setFromValue(0.5);
78 | enterfade.setToValue(1.0);
79 | enterfade.setInterpolator(Interpolator.EASE_OUT);
80 | ScaleTransition enterscale = new ScaleTransition(Duration.millis(400));
81 | enterscale.setFromX(0.5);
82 | enterscale.setFromY(0.5);
83 | enterscale.setToX(6.0);
84 | enterscale.setToY(6.0);
85 | enterscale.setInterpolator(Interpolator.EASE_OUT);
86 | ParallelTransition entertransition = new ParallelTransition(c, enterfade, enterscale);
87 | entertransition.setOnFinished(ev4 -> {
88 | if (continueTillEnd.value) {
89 | outtransition.play();
90 | }
91 | });
92 | entertransition.play();
93 |
94 | Mutable> exit = new Mutable<>();
95 | exit.value = (ev2) -> {
96 | if (entertransition.getStatus() == Animation.Status.RUNNING) {
97 | continueTillEnd.value = true;
98 | } else {
99 | outtransition.play();
100 | }
101 | n.removeEventFilter(MouseEvent.MOUSE_RELEASED, exit.value);
102 | };
103 |
104 | n.addEventFilter(MouseEvent.MOUSE_RELEASED, exit.value);
105 | });
106 | }
107 |
108 | private static class Mutable {
109 | public T value;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/ScrollableEditor.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import javafx.application.Platform;
21 | import javafx.beans.value.ChangeListener;
22 | import javafx.beans.value.ObservableValue;
23 | import javafx.geometry.Insets;
24 | import javafx.scene.Node;
25 | import javafx.scene.control.ScrollPane;
26 | import javafx.scene.layout.Background;
27 | import javafx.scene.layout.Border;
28 | import javafx.scene.layout.VBox;
29 | import javafx.scene.text.Font;
30 | import javafx.scene.text.Text;
31 |
32 | /**
33 | *
34 | * @author adrian
35 | */
36 | public class ScrollableEditor {
37 |
38 | private static final String FONT_NAME = "ROBOTO MONO BOLD";
39 |
40 | private final ScrollPane container;
41 | private final VBox box;
42 | private final double maxfontsize;
43 | private final double minfontsize;
44 |
45 | private String text = null;
46 |
47 | public ScrollableEditor(double maxfontsize, double minfontsize) {
48 |
49 | this.box = new VBox();
50 | this.container = new ScrollPane(this.box);
51 | this.maxfontsize = maxfontsize;
52 | this.minfontsize = minfontsize;
53 | // this.setAlignment(Pos.TOP_RIGHT);
54 | container.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
55 | container.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
56 | container.setFocusTraversable(false);
57 | container.setPannable(true);
58 | container.setBackground(Background.EMPTY);
59 | container.setBorder(Border.EMPTY);
60 | container.setPadding(new Insets(0.0));
61 | container.setFitToHeight(true);
62 | container.setPrefHeight(60.0);
63 | container.widthProperty().addListener(new ChangeListener() {
64 | @Override
65 | public void changed(ObservableValue extends Number> observable, Number oldValue, Number newValue) {
66 | setText(text);
67 | }
68 | });
69 | }
70 |
71 | public Node getNode() {
72 | return container;
73 | }
74 |
75 | public String getText() {
76 | return text;
77 | }
78 |
79 | public void setText(String text) {
80 | this.text = text;
81 | box.getChildren().clear();
82 | Text t1 = createText();
83 | box.getChildren().add(t1);
84 |
85 | printTextSize(t1, text, container.getWidth(), maxfontsize, minfontsize);
86 | splitText(box, t1, container.getWidth(), minfontsize);
87 | Platform.runLater(new Runnable() {
88 | @Override
89 | public void run() {
90 | container.setVvalue(container.getVmax());
91 | }
92 | });
93 | }
94 |
95 | private static Text createText() {
96 | Text t = new Text();
97 | t.getStyleClass().add("displayedit");
98 | return t;
99 | }
100 |
101 | private static void splitText(VBox parent, Text text, final double maxwidth, double minFontSize) {
102 | StringBuilder b = new StringBuilder();
103 | while (text.getLayoutBounds().getWidth() > maxwidth) {
104 | String s = text.getText();
105 | b.insert(0, s.charAt(s.length() - 1));
106 | text.setText(s.substring(0, s.length() - 1));
107 | }
108 | if (b.length() > 0) {
109 | Text t1 = createText();
110 | t1.setFont(new Font(FONT_NAME, minFontSize));
111 | t1.setText(b.toString());
112 | parent.getChildren().add(t1);
113 | splitText(parent, t1, maxwidth, minFontSize);
114 | }
115 | }
116 |
117 | private static void printTextSize(final Text text, final String t, final double maxwidth, double maxFontSize, double minFontSize) {
118 | double actualSize = maxFontSize;
119 | text.setFont(new Font(FONT_NAME, actualSize));
120 | text.setText(t);
121 | while (text.getLayoutBounds().getWidth() > maxwidth && maxFontSize > minFontSize) {
122 | maxFontSize -= 0.1;
123 | text.setFont(new Font(FONT_NAME, maxFontSize));
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/Loading.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import javafx.animation.Animation;
21 | import javafx.animation.FadeTransition;
22 | import javafx.animation.Interpolator;
23 | import javafx.animation.RotateTransition;
24 | import javafx.scene.Group;
25 | import javafx.scene.Node;
26 | import javafx.scene.shape.Rectangle;
27 | import javafx.scene.shape.SVGPath;
28 | import javafx.util.Duration;
29 |
30 | /**
31 | *
32 | * @author adrian
33 | */
34 | public class Loading {
35 |
36 | private final static String GEARPATH = "M436.25,181.438c-1.529-2.002-3.524-3.193-5.995-3.571l-52.249-7.992c-2.854-9.137-6.756-18.461-11.704-27.98 c3.422-4.758,8.559-11.466,15.41-20.129c6.851-8.661,11.703-14.987,14.561-18.986c1.523-2.094,2.279-4.281,2.279-6.567 c0-2.663-0.66-4.755-1.998-6.28c-6.848-9.708-22.552-25.885-47.106-48.536c-2.275-1.903-4.661-2.854-7.132-2.854 c-2.857,0-5.14,0.855-6.854,2.567l-40.539,30.549c-7.806-3.999-16.371-7.52-25.693-10.565l-7.994-52.529 c-0.191-2.474-1.287-4.521-3.285-6.139C255.95,0.806,253.623,0,250.954,0h-63.38c-5.52,0-8.947,2.663-10.278,7.993 c-2.475,9.513-5.236,27.214-8.28,53.1c-8.947,2.86-17.607,6.476-25.981,10.853l-39.399-30.549 c-2.474-1.903-4.948-2.854-7.422-2.854c-4.187,0-13.179,6.804-26.979,20.413c-13.8,13.612-23.169,23.841-28.122,30.69 c-1.714,2.474-2.568,4.664-2.568,6.567c0,2.286,0.95,4.57,2.853,6.851c12.751,15.42,22.936,28.549,30.55,39.403 c-4.759,8.754-8.47,17.511-11.132,26.265l-53.105,7.992c-2.093,0.382-3.9,1.621-5.424,3.715C0.76,182.531,0,184.722,0,187.002 v63.383c0,2.478,0.76,4.709,2.284,6.708c1.524,1.998,3.521,3.195,5.996,3.572l52.25,7.71c2.663,9.325,6.564,18.743,11.704,28.257 c-3.424,4.761-8.563,11.468-15.415,20.129c-6.851,8.665-11.709,14.989-14.561,18.986c-1.525,2.102-2.285,4.285-2.285,6.57 c0,2.471,0.666,4.658,1.997,6.561c7.423,10.284,23.125,26.272,47.109,47.969c2.095,2.094,4.475,3.138,7.137,3.138 c2.857,0,5.236-0.852,7.138-2.563l40.259-30.553c7.808,3.997,16.371,7.519,25.697,10.568l7.993,52.529 c0.193,2.471,1.287,4.518,3.283,6.14c1.997,1.622,4.331,2.423,6.995,2.423h63.38c5.53,0,8.952-2.662,10.287-7.994 c2.471-9.514,5.229-27.213,8.274-53.098c8.946-2.858,17.607-6.476,25.981-10.855l39.402,30.84c2.663,1.712,5.141,2.563,7.42,2.563 c4.186,0,13.131-6.752,26.833-20.27c13.709-13.511,23.13-23.79,28.264-30.837c1.711-1.902,2.569-4.09,2.569-6.561 c0-2.478-0.947-4.862-2.857-7.139c-13.698-16.754-23.883-29.882-30.546-39.402c3.806-7.043,7.519-15.701,11.136-25.98l52.817-7.988 c2.279-0.383,4.189-1.622,5.708-3.716c1.523-2.098,2.279-4.288,2.279-6.571v-63.376 C438.533,185.671,437.777,183.438,436.25,181.438z M270.946,270.939c-14.271,14.277-31.497,21.416-51.676,21.416 c-20.177,0-37.401-7.139-51.678-21.416c-14.272-14.271-21.411-31.498-21.411-51.673c0-20.177,7.135-37.401,21.411-51.678 c14.277-14.272,31.504-21.411,51.678-21.411c20.179,0,37.406,7.139,51.676,21.411c14.274,14.277,21.413,31.501,21.413,51.678 C292.359,239.441,285.221,256.669,270.946,270.939z";
37 |
38 | private final Group container;
39 | private final FadeTransition st;
40 | private final RotateTransition rt;
41 | private final RotateTransition rt2;
42 |
43 | public Loading() {
44 |
45 | Rectangle rect = new Rectangle(100.0, 100.0);
46 | rect.setStrokeWidth(1.0);
47 | rect.getStyleClass().add("loading-rect");
48 | rect.setArcHeight(50.0);
49 | rect.setArcWidth(50.0);
50 | rect.setMouseTransparent(true);
51 |
52 | SVGPath gear1 = new SVGPath();
53 | gear1.setContent(GEARPATH);
54 | gear1.setLayoutX(-182.0);
55 | gear1.setLayoutY(-182.0);
56 | gear1.setScaleX(0.1);
57 | gear1.setScaleY(0.1);
58 | gear1.getStyleClass().add("loading-gears");
59 | gear1.setMouseTransparent(true);
60 | rt = new RotateTransition(Duration.millis(3000), gear1);
61 | rt.setFromAngle(0.0);
62 | rt.setToAngle(360.0);
63 | rt.setCycleCount(Animation.INDEFINITE);
64 | rt.setInterpolator(Interpolator.LINEAR);
65 |
66 | SVGPath gear2 = new SVGPath();
67 | gear2.setContent(GEARPATH);
68 | gear2.setLayoutX(-154.0);
69 | gear2.setLayoutY(-154.0);
70 | gear2.setScaleX(0.08);
71 | gear2.setScaleY(0.08);
72 | gear2.getStyleClass().add("loading-gears");
73 | gear2.setMouseTransparent(true);
74 | rt2 = new RotateTransition(Duration.millis(2400), gear2); // 2400 = 3000 * 0.08 / 0.1
75 | rt2.setFromAngle(360.0);
76 | rt2.setToAngle(0.0);
77 | rt2.setCycleCount(Animation.INDEFINITE);
78 | rt2.setInterpolator(Interpolator.LINEAR);
79 |
80 | container = new Group(rect, gear1, gear2);
81 | container.setOpacity(0.0);
82 | container.setMouseTransparent(true);
83 | st = new FadeTransition(Duration.millis(200), container);
84 | st.setFromValue(0.0);
85 | st.setToValue(1.0);
86 | st.setInterpolator(Interpolator.EASE_OUT);
87 |
88 | st.setOnFinished(e -> {
89 | if (st.getRate() < 0) {
90 | rt.stop();
91 | rt2.stop();
92 | }
93 | });
94 | }
95 |
96 | public Node getNode() {
97 | return container;
98 | }
99 |
100 | public void start() {
101 | st.setRate(1.0);
102 | st.play();
103 | rt.play();
104 | rt2.play();
105 | }
106 |
107 | public void stop() {
108 | st.setRate(-1.0);
109 | st.play();
110 | rt.play();
111 | rt2.play();
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/LatexDisplay.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import java.text.DecimalFormat;
21 | import java.text.DecimalFormatSymbols;
22 | import java.text.NumberFormat;
23 | import java.util.List;
24 | import java.util.Locale;
25 | import java.util.Properties;
26 | import java.util.logging.Logger;
27 | import javafx.animation.FadeTransition;
28 | import javafx.animation.Interpolator;
29 | import javafx.animation.ParallelTransition;
30 | import javafx.animation.Transition;
31 | import javafx.animation.TranslateTransition;
32 | import javafx.geometry.HPos;
33 | import javafx.geometry.Insets;
34 | import javafx.scene.Node;
35 | import javafx.scene.layout.HBox;
36 | import javafx.scene.layout.Priority;
37 | import javafx.scene.layout.VBox;
38 | import javafx.scene.paint.Color;
39 | import javafx.scene.paint.Paint;
40 | import javafx.scene.text.Text;
41 | import javafx.scene.text.TextFlow;
42 | import javafx.util.Duration;
43 |
44 | /**
45 | *
46 | * @author adrian
47 | */
48 | public class LatexDisplay implements Display {
49 |
50 | private static final Logger LOG = Logger.getLogger(LatexDisplay.class.getName());
51 |
52 | private final ScrollableLatexList maindisplay;
53 | private final VBox viewdisplay;
54 | private final ResizableLatex latexresult;
55 | private final Text mode0;
56 | private final Transition displaytransition;
57 |
58 | private final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
59 | private final NumberFormat simpleFormat = new DecimalFormat("0.#########", symbols);
60 | private final NumberFormat expFormat = new DecimalFormat("0.#########E00", symbols);
61 |
62 | public LatexDisplay() {
63 |
64 | mode0 = new Text();
65 | mode0.getStyleClass().add("calcindicator");
66 | HBox indicatorsbox = new HBox(new TextFlow(mode0));
67 | indicatorsbox.setPadding(new Insets(5, 5, 5, 5));
68 | VBox.setVgrow(indicatorsbox, Priority.NEVER);
69 |
70 | maindisplay = new ScrollableLatexList();
71 | maindisplay.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
72 | VBox.setVgrow(maindisplay, Priority.SOMETIMES);
73 |
74 | latexresult = new ResizableLatex(1.0, 3.0, HPos.RIGHT);
75 |
76 | ScrollableLatexList viewresult = new ScrollableLatexList();
77 | VBox.setVgrow(viewresult, Priority.NEVER);
78 | viewresult.addLatex(latexresult);
79 |
80 | viewdisplay = new VBox(indicatorsbox, maindisplay, viewresult);
81 |
82 | // Transition
83 | FadeTransition ft2 = new FadeTransition(Duration.millis(150));
84 | ft2.setFromValue(0.0);
85 | ft2.setToValue(1.0);
86 | TranslateTransition tr2 = new TranslateTransition(Duration.millis(150));
87 | tr2.setFromY(35.0);
88 | tr2.setToY(0.0);
89 | tr2.setInterpolator(Interpolator.EASE_OUT);
90 | displaytransition = new ParallelTransition(viewresult, ft2, tr2);
91 | }
92 |
93 |
94 | @Override
95 | public void updateResult(Script calc, Object result) {
96 | // if result is undefined the it means there has not been any result
97 | // So no need to update the display for the results just the modes.
98 | if (result != null) {
99 |
100 | Properties styling = (Properties) viewdisplay.getScene().getProperties().get("styling");
101 | formatLatexResult(latexresult, result, Color.valueOf(styling.getProperty("result-color", "BLACK")), Color.valueOf(styling.getProperty("error-color", "RED")));
102 |
103 | displaytransition.playFromStart();
104 |
105 | Object latex = calc.exec("calculator.latex()");
106 | if (latex instanceof List) {
107 | List listlatex = (List) latex;
108 | maindisplay.clearLatex();
109 | for (Object l: listlatex) {
110 | ResizableLatex nlatex = new ResizableLatex(1.0, 2.5);
111 | maindisplay.addLatex(nlatex);
112 | nlatex.setLatex(formatLatex(l), Color.valueOf(styling.getProperty("expression-color", "DARKBLUE")));
113 | }
114 | maindisplay.setVvalue(maindisplay.getVmin());
115 | } else {
116 | LOG.warning("Calculator function calculator.latex() must return an array.");
117 | }
118 | }
119 | // Mode
120 | Object mode = calc.exec("calculator.mode()");
121 | if (mode instanceof List) {
122 | List listmode = (List) mode;
123 | if (listmode.size() > 0) {
124 | setTextResult(mode0, listmode.get(0).toString());
125 | }
126 | } else {
127 | LOG.warning("Calculator function calculator.mode() must return an array.");
128 | }
129 | }
130 |
131 | @Override
132 | public Node getNode() {
133 | return viewdisplay;
134 | }
135 |
136 | private void setTextResult(Text t, String result) {
137 | t.setText(result);
138 | t.getStyleClass().removeAll("displayerror", "displayresult");
139 | t.getStyleClass().add("displayresult");
140 | }
141 |
142 | private String formatLatex(Object obj) {
143 | if (obj.equals("")) {
144 | return null;
145 | } else if (obj instanceof Throwable) {
146 | return "SYNTAX\\\\ ERROR";
147 | } else {
148 | return obj.toString();
149 | }
150 | }
151 |
152 | private void formatLatexResult(ResizableLatex t, Object obj, Paint resultpaint, Paint errorpaint) {
153 | if (obj.equals("")) {
154 | t.setLatex(null, resultpaint);
155 | } else if (obj instanceof Number) {
156 | double d = ((Number) obj).doubleValue();
157 | if (Double.isInfinite(d)) {
158 | t.setLatex("INFINITY", errorpaint);
159 | } else if (Double.isNaN(d)) {
160 | t.setLatex("NOT\\ A\\ NUMBER", errorpaint);
161 | } else if (d == Double.MAX_VALUE || d == Double.MIN_VALUE) {
162 | t.setLatex("OVERFLOW", errorpaint);
163 | } else if (d == 0.0) {
164 | t.setLatex("=" + simpleFormat.format(d), resultpaint);
165 | } else if (d < -9999999999.0 || d > 9999999999.0 || (d >= -0.0000000001 && d <= 0.0000000001)) {
166 | String expresult = expFormat.format(d);
167 | t.setLatex("=" + (expresult.contains("E-") ? expresult : expresult.replace("E", "E+")), resultpaint);
168 | } else {
169 | t.setLatex("=" + simpleFormat.format(d), resultpaint);
170 | }
171 | } else if (obj instanceof Throwable) {
172 | t.setLatex("SYNTAX\\ ERROR", errorpaint);
173 | } else {
174 | t.setLatex("=" + obj.toString(), resultpaint);
175 | }
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/scripts/scientific_keyboard.js:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | /* global KEYBOARDBUILDER, CALCBUTTONBUILDER */
20 | (function () {
21 | var keyboard = KEYBOARDBUILDER.createKeyboard(6, 6);
22 |
23 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
24 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("calculator.radiansfactorswitch()")))
25 | .addVisitor(KEYBOARDBUILDER.createLabeler("calculator.radiansmodenext"))
26 | .addClasses("functionkeyboard", "textkeyboard").build());
27 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
28 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("sin", "sin("),
29 | KEYBOARDBUILDER.createCommand("sin\u207B\u00B9", "asin(")))
30 | .addClasses("textkeyboard").build());
31 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
32 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("cos", "cos("),
33 | KEYBOARDBUILDER.createCommand("cos\u207B\u00B9", "acos(")))
34 | .addClasses("textkeyboard").build());
35 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
36 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("tan", "tan("),
37 | KEYBOARDBUILDER.createCommand("tan\u207B\u00B9", "atan(")))
38 | .addClasses("textkeyboard").build());
39 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
40 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("log", "log("),
41 | KEYBOARDBUILDER.createCommand("10\u207F", "pow10(")))
42 | .addClasses("textkeyboard").build());
43 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
44 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("ln", "ln("),
45 | KEYBOARDBUILDER.createCommand("e\u207F", "exp(")))
46 | .addClasses("textkeyboard").build());
47 |
48 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("("))).addClasses("textkeyboard").build());
49 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand(","))).addClasses("textkeyboard").build());
50 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand(")"))).addClasses("textkeyboard").build());
51 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("\u221Ax", "sqrt("))).addClasses("textkeyboard").build());
52 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("x\u207F", "pow("))).addClasses("textkeyboard").build());
53 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("x!", "fac("))).addClasses("textkeyboard").build());
54 |
55 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("INV", "INV"))).addClasses("functionkeyboard", "textkeyboard").build());
56 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("7"))).addClasses("graykeyboard").build());
57 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("8"))).addClasses("graykeyboard").build());
58 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("9"))).addClasses("graykeyboard").build());
59 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("DEL", ""))).addClasses("functionkeyboard", "textkeyboard").build());
60 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("AC", "calculator.reset();", ""))).addClasses("functionkeyboard", "textkeyboard").build());
61 |
62 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("e"))).addClasses("textkeyboard").build());
63 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("4"))).addClasses("graykeyboard").build());
64 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("5"))).addClasses("graykeyboard").build());
65 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("6"))).addClasses("graykeyboard").build());
66 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("*"))).build());
67 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("/"))).build());
68 |
69 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("\u03C0", "pi"))).addClasses("textkeyboard").build());
70 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("1"))).addClasses("graykeyboard").build());
71 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("2"))).addClasses("graykeyboard").build());
72 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("3"))).addClasses("graykeyboard").build());
73 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("+"))).build());
74 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("-"))).build());
75 |
76 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("ANS"))).addClasses("textkeyboard").build());
77 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("0"))).addClasses("graykeyboard").build());
78 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("."))).addClasses("graykeyboard").build());
79 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("EXX", "E"))).addClasses("graykeyboard", "textkeyboard").build());
80 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("ENTER", "calculator.eval(%%%%%%)", ""))).addClasses("execkeyboard", "textkeyboard").build(), 2);
81 |
82 | }());
83 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/Main.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.util.Properties;
23 | import java.util.concurrent.ForkJoinPool;
24 | import java.util.logging.Level;
25 | import java.util.logging.Logger;
26 | import javafx.application.Application;
27 | import javafx.application.Platform;
28 | import javafx.geometry.Rectangle2D;
29 | import javafx.scene.Scene;
30 | import javafx.scene.image.Image;
31 | import javafx.scene.input.KeyCode;
32 | import javafx.scene.input.KeyEvent;
33 | import javafx.scene.layout.AnchorPane;
34 | import javafx.scene.layout.Priority;
35 | import javafx.scene.layout.StackPane;
36 | import javafx.scene.layout.VBox;
37 | import javafx.scene.text.Font;
38 | import javafx.stage.Screen;
39 | import javafx.stage.Stage;
40 |
41 | public class Main extends Application {
42 |
43 | @Override
44 | public void start(Stage primaryStage) {
45 |
46 | // Load fonts
47 | Font.loadFont(Main.class.getResource("/com/adr/hellocalc/styles/RobotoMono-Bold.ttf").toExternalForm(), 14.0);
48 | Font.loadFont(Main.class.getResource("/com/adr/hellocalc/styles/RobotoMono-Light.ttf").toExternalForm(), 14.0);
49 |
50 | primaryStage.setTitle("Calculator");
51 |
52 | String name = "mathcalc";
53 | String keyboard = "local:mathcalc_keyboard";
54 | String[] resources = new String[]{"/com/adr/hellocalc/scripts/math.min.js", "local:mathcalc"};
55 | // String keyboard = "local:scientific_keyboard";
56 | // String[] resources = new String[]{"local:scientific"};
57 | // String keyboard = "local:basic_keyboard";
58 | // String[] resources = new String[]{"local:basic"};
59 |
60 | // String style = "/com/adr/hellocalc/styles/main";
61 | String style = "/com/adr/hellocalc/styles/maindark";
62 |
63 | Script calculator = new ScriptRhino();
64 | // Script calculator = new ScriptWebEngine();
65 |
66 | Display display = new LatexDisplay();
67 |
68 | KeyboardNumbers keyboardcalc = new KeyboardNumbers();
69 | ScriptRhino keyboardscript = new ScriptRhino();
70 | keyboardscript.init();
71 | keyboardscript.putScopeObject("KEYBOARDBUILDER", keyboardcalc.createKeyboardBuilder());
72 | keyboardscript.putScopeObject("CALCBUTTONBUILDER", new CalcBtnBuilder());
73 | loadResources(keyboardscript, keyboard);
74 |
75 | keyboardcalc.setOnExec(script -> {
76 | ForkJoinPool.commonPool().execute(() -> {
77 | Object result = calculator.exec(script);
78 | Platform.runLater(() -> {
79 | display.updateResult(calculator, result);
80 | keyboardcalc.updateView(calculator);
81 | });
82 | });
83 | });
84 |
85 | Loading loading = new Loading();
86 | StackPane containerdisplay = new StackPane(display.getNode(), loading.getNode());
87 | VBox.setVgrow(containerdisplay, Priority.ALWAYS);
88 |
89 | VBox root = new VBox(containerdisplay, keyboardcalc.getNode());
90 |
91 | root.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
92 |
93 | AnchorPane.setRightAnchor(root, 0.0);
94 | AnchorPane.setLeftAnchor(root, 0.0);
95 | AnchorPane.setTopAnchor(root, 0.0);
96 | AnchorPane.setBottomAnchor(root, 0.0);
97 |
98 | AnchorPane anchorroot = new AnchorPane(root);
99 | anchorroot.getStyleClass().add("rootpane");
100 |
101 | double width;
102 | double height;
103 |
104 | if ("android".equals(System.getProperty("javafx.platform"))) {
105 | Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
106 | width = visualBounds.getWidth();
107 | height = visualBounds.getHeight();
108 | } else {
109 | width = 400.0;
110 | height = 580.0;
111 | }
112 | Scene scene = new Scene(anchorroot, width, height);
113 | scene.addEventHandler(KeyEvent.KEY_RELEASED, e -> {
114 | if (KeyCode.ESCAPE.equals(e.getCode())) {
115 | primaryStage.close();
116 | }
117 | });
118 |
119 | scene.getStylesheets().add(getClass().getResource(style + ".css").toExternalForm());
120 | Properties styling = new Properties();
121 | try {
122 | styling.load(getClass().getResourceAsStream(style + ".properties"));
123 | } catch (IOException ex) {
124 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
125 | }
126 | scene.getProperties().put("styling", styling);
127 | primaryStage.getIcons()
128 | .add(new Image(Main.class.getResourceAsStream("/com/adr/hellocalc/images/icon.png")));
129 | primaryStage.setScene(scene);
130 |
131 | primaryStage.show();
132 |
133 | loading.start();
134 | ForkJoinPool.commonPool().execute(() -> {
135 | calculator.init();
136 | loadResources(calculator, resources);
137 | // File path;
138 | // try {
139 | // path = PlatformFactory.getPlatform().getPrivateStorage();
140 | // } catch (IOException ex) {
141 | // path = new File(System.getProperty("java.io.tmpdir"));
142 | // }
143 | // File f = new File(path, name + ".ser");
144 | //
145 | // try {
146 | // calculator.init(new FileInputStream(f));
147 | // } catch (IOException ex) {
148 | // calculator.init();
149 | // loadResources(calculator, resources);
150 | // try {
151 | // calculator.save(new FileOutputStream(f));
152 | // } catch (IOException ex1) {
153 | // Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex1);
154 | // }
155 | // }
156 |
157 | Platform.runLater(() -> {
158 | display.updateResult(calculator, null);
159 | keyboardcalc.updateView(calculator);
160 | loading.stop();
161 | });
162 | });
163 | }
164 |
165 | public static void main(String[] args) {
166 | launch(args);
167 | }
168 |
169 | private static void loadResources(Script sc, String resource) {
170 | Object result = sc.exec(resourceToString(getAbsoluteResource(resource)));
171 | if (result instanceof Exception) {
172 | throw new RuntimeException((Exception) result);
173 | }
174 | }
175 |
176 | private static void loadResources(Script sc, String[] resources) {
177 | for (String res : resources) {
178 | loadResources(sc, res);
179 | }
180 | }
181 |
182 | private static String getAbsoluteResource(String resource) {
183 | if (resource.startsWith("local:")) {
184 | return "/com/adr/hellocalc/scripts/" + resource.substring(6) + ".js";
185 | } else {
186 | return resource;
187 | }
188 | }
189 |
190 | static String resourceToString(String resource) {
191 | try (InputStream is = Main.class.getResourceAsStream(resource)) {
192 | java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
193 | return s.hasNext() ? s.next() : "";
194 | } catch (IOException ex) {
195 | throw new RuntimeException(ex);
196 | }
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/src/main/resources/com/adr/hellocalc/scripts/mathcalc_keyboard.js:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 |
19 | /* global KEYBOARDBUILDER, CALCBUTTONBUILDER */
20 | (function () {
21 |
22 | var keyboard = KEYBOARDBUILDER.createKeyboard(6, 6);
23 |
24 | // keyboard.addSpan(2);
25 | // keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("MATH", "0"))).addClasses("modekeyboard", "modekeyboardselected").build());
26 | // keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("CONFIG", "1"))).addClasses("modekeyboard").build());
27 | // keyboard.addSpan(2);
28 |
29 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
30 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("calculator.radiansfactorswitch()")))
31 | .addVisitor(KEYBOARDBUILDER.createLabeler("calculator.radiansmodenext"))
32 | .addClasses("function2keyboard", "textkeyboard").build());
33 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
34 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("sin", "sin("),
35 | KEYBOARDBUILDER.createCommand("asin", "asin(")))
36 | .addClasses("textkeyboard").build());
37 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
38 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("cos", "cos("),
39 | KEYBOARDBUILDER.createCommand("acos", "acos(")))
40 | .addClasses("textkeyboard").build());
41 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton()
42 | .addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("tan", "tan("),
43 | KEYBOARDBUILDER.createCommand("atan", "atan(")))
44 | .addClasses("textkeyboard").build());
45 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(
46 | KEYBOARDBUILDER.createCommand("log", "log("),
47 | KEYBOARDBUILDER.createCommand("e\u207F", "exp(")))
48 | .addClasses("textkeyboard").build());
49 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("ANS"))).addClasses("textkeyboard").build());
50 |
51 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("("), KEYBOARDBUILDER.createCommand("["))).addClasses("textkeyboard").build());
52 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand(","))).addClasses("textkeyboard").build());
53 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand(")"), KEYBOARDBUILDER.createCommand("]"))).addClasses("textkeyboard").build());
54 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("REV", ""))).addClasses("functionkeyboard", "textkeyboard").build());
55 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("DEL", ""))).addClasses("functionkeyboard", "textkeyboard").build());
56 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("AC", "calculator.reset();", ""))).addClasses("functionkeyboard", "textkeyboard").build());
57 |
58 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("i"), KEYBOARDBUILDER.createCommand("x"))).addClasses("textkeyboard").build());
59 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("7"))).addClasses("graykeyboard").build());
60 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("8"))).addClasses("graykeyboard").build());
61 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("9"))).addClasses("graykeyboard").build());
62 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("\u221Ax", "sqrt("))).addClasses("textkeyboard").build());
63 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("x\u207F", "^"))).addClasses("textkeyboard").build());
64 |
65 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("e"), KEYBOARDBUILDER.createCommand("f"))).addClasses("textkeyboard").build());
66 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("4"))).addClasses("graykeyboard").build());
67 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("5"))).addClasses("graykeyboard").build());
68 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("6"))).addClasses("graykeyboard").build());
69 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("*"))).build());
70 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("/"))).build());
71 |
72 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("\u03C0", "pi"), KEYBOARDBUILDER.createCommand("="))).addClasses("textkeyboard").build());
73 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("1"))).addClasses("graykeyboard").build());
74 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("2"))).addClasses("graykeyboard").build());
75 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("3"))).addClasses("graykeyboard").build());
76 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("+"))).build());
77 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("-"))).build());
78 |
79 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("INV", "INV"))).addClasses("function2keyboard", "textkeyboard").build());
80 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("0"))).addClasses("graykeyboard").build());
81 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("."))).addClasses("graykeyboard").build());
82 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("EXX", "E"))).addClasses("graykeyboard", "textkeyboard").build());
83 | keyboard.addButton(CALCBUTTONBUILDER.createCalcButton().addVisitor(KEYBOARDBUILDER.createCommander(KEYBOARDBUILDER.createCommand("ENTER", "calculator.eval(\"%%%%%%\")", ""))).addClasses("execkeyboard", "textkeyboard").build(), 2);
84 | }());
85 |
--------------------------------------------------------------------------------
/src/main/java/com/adr/hellocalc/KeyboardNumbers.java:
--------------------------------------------------------------------------------
1 | // HelloCalc (Calculator) is a JavaFX calculator
2 | // Copyright (C) 2016 Adrián Romero Corchado.
3 | //
4 | // This file is part of HelloCalc
5 | //
6 | // This program is free software: you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation, either version 3 of the License, or
9 | // (at your option) any later version.
10 | //
11 | // This program is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // You should have received a copy of the GNU General Public License
17 | // along with this program. If not, see .
18 | package com.adr.hellocalc;
19 |
20 | import javafx.event.ActionEvent;
21 | import javafx.event.EventHandler;
22 | import javafx.geometry.Insets;
23 | import javafx.scene.Node;
24 | import javafx.scene.control.Button;
25 | import javafx.scene.layout.ColumnConstraints;
26 | import javafx.scene.layout.GridPane;
27 | import javafx.scene.layout.RowConstraints;
28 | import javafx.scene.layout.StackPane;
29 | import javafx.scene.layout.VBox;
30 |
31 | /**
32 | *
33 | * @author adrian
34 | */
35 | public class KeyboardNumbers {
36 |
37 | private final BasicEditor editor;
38 | private final VBox container;
39 | private final StackPane keyboardcontainer;
40 |
41 | private final ObservableStatus status = new ObservableStatus(0);
42 | private final ObservableFunc