-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUISourceCode.java
More file actions
138 lines (115 loc) · 5.24 KB
/
UISourceCode.java
File metadata and controls
138 lines (115 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import java.io.*;
import java.util.*;
import javafx.beans.value.*;
import javafx.geometry.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.text.*;
import javafx.stage.Stage;
public class UISourceCode {
private static TextFlow assemblyDisplay;
private static ScrollPane assemblyScrollPane;
private static Text assemblyText;
private static double fontSize = 1.0;
private static SplitPane layout;
private static int previousSourceLine = -1;
private static List<Text> sourceCode = new ArrayList<>();
private static TextFlow sourceCodeDisplay;
private static int sourceCodeLines = 0;
private static ScrollPane sourceCodeScrollPane;
public static Node parseSourceCode(List<String> code) {
assemblyDisplay = new TextFlow();
assemblyScrollPane = new ScrollPane();
layout = new SplitPane();
sourceCodeDisplay = new TextFlow();
sourceCodeLines = 0;
sourceCodeScrollPane = new ScrollPane();
previousSourceLine = -1;
for (String line : code) {
Text sourceLine = new Text(Integer.toString(sourceCodeLines+1) + " " + line + "\n");
sourceLine.setFont(Font.font("Monospace", FontWeight.NORMAL, 14));
sourceLine.setUserData(new Integer(sourceCodeLines+1));
sourceCodeDisplay.getChildren().add(sourceLine);
sourceCode.add(sourceLine);
++sourceCodeLines;
}
assemblyScrollPane.setMinHeight(70);
assemblyScrollPane.setContent(assemblyDisplay);
sourceCodeScrollPane.setContent(sourceCodeDisplay);
layout.getItems().addAll(assemblyScrollPane, sourceCodeScrollPane);
layout.setOrientation(Orientation.VERTICAL);
layout.setDividerPositions(0.1f, 0.9f);
return layout;
}
public static Node buildSC(Scene scene, int sourceLine, String assembly) {
for (Text text : sourceCode) text.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
if (sourceCodeLines > 0 && sourceLine > 0 && sourceLine < sourceCodeLines) {
if (previousSourceLine >= 0) {
((Text)UIUtils.getByUserData(sourceCodeDisplay, previousSourceLine)).
setFont(Font.font("Monospace", FontWeight.NORMAL,
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
((Text)UIUtils.getByUserData(sourceCodeDisplay, previousSourceLine)).setFill(Color.BLACK);
}
((Text)UIUtils.getByUserData(sourceCodeDisplay, sourceLine)).
setFont(Font.font("Monospace", FontWeight.BOLD,
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
((Text)UIUtils.getByUserData(sourceCodeDisplay, sourceLine)).setFill(Color.ORANGE);
previousSourceLine = sourceLine;
}
// scene size change listeners
scene.widthProperty().addListener(new ChangeListener<Number>() {
@Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) {
for (Text text : sourceCode) {
text.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
assemblyText.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
});
scene.heightProperty().addListener(new ChangeListener<Number>() {
@Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
for (Text text : sourceCode) {
text.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
assemblyText.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
});
if (assembly != null) {
assemblyDisplay.getChildren().clear();
assemblyText = new Text(assembly);
assemblyText.setFont(Font.font("Monospace", FontWeight.NORMAL,
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
assemblyDisplay.getChildren().add(assemblyText);
}
return layout;
}
public static void increaseFontSize(Scene scene) {
if (fontSize < 5.0) fontSize += 0.1;
for (Text text : sourceCode) {
text.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
if (assemblyText != null) assemblyText.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
public static void decreaseFontSize(Scene scene) {
if (fontSize > 0.1) fontSize -= 0.1;
for (Text text : sourceCode) {
text.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
if (assemblyText != null) assemblyText.setFont(new Font("Monospace",
UIUtils.calculateFontSize(fontSize, scene.getWidth(), scene.getHeight())));
}
public static void toggleAssemblyWindow(boolean visible) {
assemblyScrollPane.setVisible(visible);
if (!visible) assemblyScrollPane.setMinHeight(0);
else assemblyScrollPane.setMinHeight(70);
}
}