Skip to content

Commit 5d14ab9

Browse files
committed
Integration of JGrapher with JMCAS.
1 parent 01b4297 commit 5d14ab9

File tree

4 files changed

+225
-78
lines changed

4 files changed

+225
-78
lines changed

src/CasController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import javafx.application.Platform;
2+
import javafx.event.ActionEvent;
13
import javafx.scene.control.Label;
24
import javafx.scene.control.TextField;
35
import javafx.scene.input.KeyEvent;
@@ -39,6 +41,11 @@ public void textFieldInput(KeyEvent keyEvent) {
3941
System.out.println(input.textProperty().get());
4042
}
4143

44+
public void launchJGrapher(ActionEvent actionEvent) {
45+
System.out.println(actionEvent);
46+
Platform.runLater(() -> JGrapher.main(new String[]{"processing.awt.PGraphicsJava2D"}));
47+
}
48+
4249
void error(String msg) {
4350
String str = "...";
4451
this.addition.setText(str);

src/JGrapher.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import javafx.embed.swt.FXCanvas;
12
import jmc.cas.*;
23
import jmc.extras.Element;
34
import jmc.graph.Graph;
@@ -34,18 +35,21 @@ public class JGrapher extends PApplet {
3435
private VBox suppliedVarWrapper;
3536
private TextInput modelInput;
3637
private boolean casEnabled = true;
38+
private static String defaultRenderer = "processing.javafx.PGraphicsFX2D";
39+
private static String renderer = defaultRenderer;
3740

3841
public static void main(String args[]) {
3942
System.out.println("Welcome to JGrapher, an extensive graphing/calculation system using original CAS and UI library. \n" +
4043
"Copyright (c) 2018, Jiachen Ren. \n" +
4144
"MIT license applies. \n");
45+
if (args != null && args.length > 0) renderer = args[0];
4246
String sketch = Thread.currentThread().getStackTrace()[1].getClassName();
43-
Thread proc = new Thread(() -> PApplet.main(sketch));
44-
proc.start();
47+
PApplet.main(sketch);
4548
}
4649

4750
public void settings() {
48-
size(1100, 780, FX2D);
51+
size(1100, 780, renderer);
52+
if (!renderer.equals(defaultRenderer)) pixelDensity(2);
4953
}
5054

5155
private static void enableCoreDump() {

src/cas.fxml

Lines changed: 206 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,85 +10,220 @@
1010
<?import javafx.scene.control.TextField?>
1111
<?import javafx.scene.layout.ColumnConstraints?>
1212
<?import javafx.scene.layout.GridPane?>
13+
<?import javafx.scene.layout.HBox?>
1314
<?import javafx.scene.layout.RowConstraints?>
1415
<?import javafx.scene.layout.VBox?>
1516
<?import javafx.scene.text.Font?>
1617

1718
<!--<?import ui.SelectableLabel?>-->
1819

19-
<GridPane alignment="CENTER" minHeight="400.0" minWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="CasController">
20+
<GridPane alignment="CENTER" minHeight="400.0" minWidth="400.0" xmlns="http://javafx.com/javafx/8"
21+
xmlns:fx="http://javafx.com/fxml/1" fx:controller="CasController">
2022
<columnConstraints>
21-
<ColumnConstraints />
23+
<ColumnConstraints/>
2224
</columnConstraints>
2325
<rowConstraints>
24-
<RowConstraints />
26+
<RowConstraints/>
27+
<RowConstraints/>
2528
</rowConstraints>
26-
<children>
27-
<VBox nodeOrientation="LEFT_TO_RIGHT" spacing="10.0" GridPane.hgrow="ALWAYS">
28-
<padding>
29-
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
30-
</padding>
31-
<opaqueInsets>
32-
<Insets />
33-
</opaqueInsets>
34-
<children>
35-
<Label text="JMC CAS Experimental" />
36-
<TextField fx:id="input" onKeyTyped="#textFieldInput" promptText="Enter Expression">
37-
<VBox.margin>
38-
<Insets />
39-
</VBox.margin>
40-
</TextField>
41-
<GridPane hgap="5.0">
42-
<columnConstraints>
43-
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
44-
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
45-
</columnConstraints>
46-
<rowConstraints>
47-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
48-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
49-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
50-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
51-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
52-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
53-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
54-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
55-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
56-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
57-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
58-
</rowConstraints>
59-
<children>
60-
61-
62-
<!--<SelectableLabel text="Selectable"/>-->
63-
<Label fx:id="addition" text="Addition Form" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" />
64-
<Label fx:id="exponential" text="Exponential Form" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />
65-
<Label fx:id="simplified" text="Simplified" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="4" />
66-
<Label fx:id="beautified" text="Beautified" textFill="#20a822" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="5">
67-
<font>
68-
<Font name="System Bold" size="13.0" />
69-
</font>
70-
</Label>
71-
<Label text="Additional Only Form:" />
72-
<Label text="Exponential Form:" GridPane.rowIndex="1" />
73-
<Label text="Simplified:" GridPane.rowIndex="4" />
74-
<Label text="Beautified:" GridPane.rowIndex="5" />
75-
<Label text="# Nodes:" GridPane.rowIndex="2" />
76-
<Label fx:id="nodesBefore" text="# nodes" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
77-
<Label text="Complexity:" GridPane.rowIndex="3" />
78-
<Label fx:id="complexityBefore" text="complexity" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="3" />
79-
<Label text="# Nodes (Simplified):" GridPane.rowIndex="6" />
80-
<Label fx:id="nodesAfter" text="nodes (after)" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="6" />
81-
<Label text="Complexity (Simplified):" GridPane.rowIndex="7" />
82-
<Label fx:id="complexityAfter" text="complexity (after)" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="7" />
83-
<Label text="Error Message:" GridPane.rowIndex="8" />
84-
<Label fx:id="errMsg" text="&quot;&quot;" textFill="#f80909" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="8" />
85-
<Label text="Raw Value:" GridPane.rowIndex="9" />
86-
<Label fx:id="val" text="val" textFill="#0c49ff" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="9" />
87-
<Label text="Variables:" GridPane.rowIndex="10" />
88-
<Label fx:id="vars" text="vars" visible="false" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="10" />
89-
</children>
90-
</GridPane>
91-
</children>
92-
</VBox>
93-
</children>
29+
<children>
30+
<VBox nodeOrientation="LEFT_TO_RIGHT" spacing="10.0" GridPane.hgrow="ALWAYS">
31+
<padding>
32+
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
33+
</padding>
34+
<opaqueInsets>
35+
<Insets/>
36+
</opaqueInsets>
37+
<children>
38+
<GridPane>
39+
<columnConstraints>
40+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
41+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
42+
</columnConstraints>
43+
<rowConstraints>
44+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
45+
</rowConstraints>
46+
<children>
47+
<Label text="JMC CAS Experimental">
48+
<font>
49+
<Font name="Ubuntu Mono derivative Powerline Bold" size="17.0"/>
50+
</font>
51+
<GridPane.margin>
52+
<Insets bottom="5.0" left="5.0" top="5.0"/>
53+
</GridPane.margin>
54+
</Label>
55+
<Button mnemonicParsing="false" onAction="#launchJGrapher" text="Launch JGrapher"
56+
GridPane.columnIndex="1"
57+
GridPane.halignment="RIGHT">
58+
<GridPane.margin>
59+
<Insets bottom="5.0" right="5.0" top="5.0"/>
60+
</GridPane.margin>
61+
</Button>
62+
</children>
63+
<VBox.margin>
64+
<Insets top="5.0"/>
65+
</VBox.margin>
66+
<padding>
67+
<Insets bottom="5.0" top="5.0"/>
68+
</padding>
69+
</GridPane>
70+
<TextField fx:id="input" onKeyTyped="#textFieldInput" promptText="Enter Expression">
71+
<VBox.margin>
72+
<Insets left="5.0" right="5.0"/>
73+
</VBox.margin>
74+
<font>
75+
<Font name="Verdana" size="13.0"/>
76+
</font>
77+
</TextField>
78+
<GridPane hgap="5.0">
79+
<columnConstraints>
80+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
81+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
82+
</columnConstraints>
83+
<rowConstraints>
84+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
85+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
86+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
87+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
88+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
89+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
90+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
91+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
92+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
93+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
94+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
95+
</rowConstraints>
96+
<children>
97+
98+
99+
<!--<SelectableLabel text="Selectable"/>-->
100+
<Label fx:id="addition" text="Addition Form" visible="false" GridPane.columnIndex="1"
101+
GridPane.halignment="RIGHT">
102+
<font>
103+
<Font name="Wawati SC Regular" size="13.0"/>
104+
</font>
105+
</Label>
106+
<Label fx:id="exponential" text="Exponential Form" visible="false" GridPane.columnIndex="1"
107+
GridPane.halignment="RIGHT" GridPane.rowIndex="1">
108+
<font>
109+
<Font name="Wawati SC Regular" size="13.0"/>
110+
</font>
111+
</Label>
112+
<Label fx:id="simplified" text="Simplified" visible="false" GridPane.columnIndex="1"
113+
GridPane.halignment="RIGHT" GridPane.rowIndex="4">
114+
<font>
115+
<Font name="Wawati SC Regular" size="13.0"/>
116+
</font>
117+
</Label>
118+
<Label fx:id="beautified" text="Beautified" textFill="#20a822" visible="false"
119+
GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="5">
120+
<font>
121+
<Font name="Wawati SC Regular" size="13.0"/>
122+
</font>
123+
</Label>
124+
<Label text="Additional Only Form:">
125+
<font>
126+
<Font name="Wawati SC Regular" size="13.0"/>
127+
</font>
128+
</Label>
129+
<Label text="Exponential Form:" GridPane.rowIndex="1">
130+
<font>
131+
<Font name="Wawati SC Regular" size="13.0"/>
132+
</font>
133+
</Label>
134+
<Label text="Simplified:" GridPane.rowIndex="4">
135+
<font>
136+
<Font name="Wawati SC Regular" size="13.0"/>
137+
</font>
138+
</Label>
139+
<Label text="Beautified:" GridPane.rowIndex="5">
140+
<font>
141+
<Font name="Wawati SC Regular" size="13.0"/>
142+
</font>
143+
</Label>
144+
<Label text="# Nodes:" GridPane.rowIndex="2">
145+
<font>
146+
<Font name="Wawati SC Regular" size="13.0"/>
147+
</font>
148+
</Label>
149+
<Label fx:id="nodesBefore" text="# nodes" visible="false" GridPane.columnIndex="1"
150+
GridPane.halignment="RIGHT" GridPane.rowIndex="2">
151+
<font>
152+
<Font name="Wawati SC Regular" size="13.0"/>
153+
</font>
154+
</Label>
155+
<Label text="Complexity:" GridPane.rowIndex="3">
156+
<font>
157+
<Font name="Wawati SC Regular" size="13.0"/>
158+
</font>
159+
</Label>
160+
<Label fx:id="complexityBefore" text="complexity" visible="false" GridPane.columnIndex="1"
161+
GridPane.halignment="RIGHT" GridPane.rowIndex="3">
162+
<font>
163+
<Font name="Wawati SC Regular" size="13.0"/>
164+
</font>
165+
</Label>
166+
<Label text="# Nodes (Simplified):" GridPane.rowIndex="6">
167+
<font>
168+
<Font name="Wawati SC Regular" size="13.0"/>
169+
</font>
170+
</Label>
171+
<Label fx:id="nodesAfter" text="nodes (after)" visible="false" GridPane.columnIndex="1"
172+
GridPane.halignment="RIGHT" GridPane.rowIndex="6">
173+
<font>
174+
<Font name="Wawati SC Regular" size="13.0"/>
175+
</font>
176+
</Label>
177+
<Label text="Complexity (Simplified):" GridPane.rowIndex="7">
178+
<font>
179+
<Font name="Wawati SC Regular" size="13.0"/>
180+
</font>
181+
</Label>
182+
<Label fx:id="complexityAfter" text="complexity (after)" visible="false"
183+
GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="7">
184+
<font>
185+
<Font name="Wawati SC Regular" size="13.0"/>
186+
</font>
187+
</Label>
188+
<Label text="Error Message:" GridPane.rowIndex="8">
189+
<font>
190+
<Font name="Wawati SC Regular" size="13.0"/>
191+
</font>
192+
</Label>
193+
<Label fx:id="errMsg" text="&quot;&quot;" textFill="#f80909" visible="false"
194+
GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="8">
195+
<font>
196+
<Font name="Wawati SC Regular" size="13.0"/>
197+
</font>
198+
</Label>
199+
<Label text="Raw Value:" GridPane.rowIndex="9">
200+
<font>
201+
<Font name="Wawati SC Regular" size="13.0"/>
202+
</font>
203+
</Label>
204+
<Label fx:id="val" text="val" textFill="#0c49ff" visible="false" GridPane.columnIndex="1"
205+
GridPane.halignment="RIGHT" GridPane.rowIndex="9">
206+
<font>
207+
<Font name="Wawati SC Regular" size="13.0"/>
208+
</font>
209+
</Label>
210+
<Label text="Variables:" GridPane.rowIndex="10">
211+
<font>
212+
<Font name="Wawati SC Regular" size="13.0"/>
213+
</font>
214+
</Label>
215+
<Label fx:id="vars" text="vars" visible="false" GridPane.columnIndex="1"
216+
GridPane.halignment="RIGHT" GridPane.rowIndex="10">
217+
<font>
218+
<Font name="Wawati SC Regular" size="13.0"/>
219+
</font>
220+
</Label>
221+
</children>
222+
<padding>
223+
<Insets left="5.0" right="5.0"/>
224+
</padding>
225+
</GridPane>
226+
</children>
227+
</VBox>
228+
</children>
94229
</GridPane>

src/ui/SelectableLabel.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
package ui; /**
2-
* Created by Jiachen on 3/12/18.
3-
* JavaFX label is not selectable! Here's workaround found on StackOverflow...
4-
*/
1+
package ui;
52

63
import javafx.scene.control.TextArea;
74
import javafx.scene.layout.StackPane;
85
import javafx.scene.text.Text;
96

7+
/**
8+
* Created by Jiachen on 3/12/18.
9+
* JavaFX label is not selectable! Here's workaround found on StackOverflow...
10+
*/
1011
public class SelectableLabel extends TextArea {
1112

1213
public SelectableLabel() {

0 commit comments

Comments
 (0)