Skip to content

Commit bbf9df8

Browse files
committed
Initial Commit
0 parents  commit bbf9df8

File tree

5 files changed

+188
-0
lines changed

5 files changed

+188
-0
lines changed

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
*.class
2+
3+
4+
# Mobile Tools for Java (J2ME)
5+
6+
.mtj
7+
.tmp/
8+
9+
10+
# Package Files
11+
12+
*.jar
13+
14+
*.war
15+
16+
*.ear
17+
18+
19+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
20+
21+
hs_err_pid
22+
23+
bin
24+
sysProps.xml
25+
26+
27+
.DS_STORE
28+
build
29+
dist
30+
out
31+
META-INF
32+
.idea

SmartChart.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="sfxlib" level="project" />
11+
</component>
12+
</module>

manifest.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
API: 0.1
2+
Name: SmartChart
3+
Description: SmartChart plugin
4+
Version: 1.0.0
5+
# Please generate your own unique UUID and replace it below
6+
Plugin ID: e5a40031-6713-47fb-8757-900eb1027769
7+
Controls:
8+
-
9+
Class: edu.nr.SmartChart

smartchart.png

4.88 KB
Loading

src/edu/nr/SmartChart.java

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package edu.nr;
2+
3+
import dashfx.lib.controls.Category;
4+
import dashfx.lib.controls.Control;
5+
import dashfx.lib.controls.Designable;
6+
import dashfx.lib.data.DataCoreProvider;
7+
import dashfx.lib.data.SmartValue;
8+
import dashfx.lib.data.SupportedTypes;
9+
import javafx.beans.property.SimpleStringProperty;
10+
import javafx.beans.property.StringProperty;
11+
import javafx.beans.value.ChangeListener;
12+
import javafx.beans.value.ObservableValue;
13+
import javafx.event.ActionEvent;
14+
import javafx.event.EventHandler;
15+
import javafx.geometry.Pos;
16+
import javafx.scene.Node;
17+
import javafx.scene.chart.LineChart;
18+
import javafx.scene.chart.NumberAxis;
19+
import javafx.scene.control.Button;
20+
import javafx.scene.layout.GridPane;
21+
22+
@Designable(value="SmartChart", image = "/smartchart.png", description="Uses built-in graph and manual list storing. Includes a reset button (wow!)")
23+
@SupportedTypes({dashfx.lib.data.SmartValueTypes.Number})
24+
@Category("General")
25+
public class SmartChart
26+
extends GridPane
27+
implements Control, ChangeListener<Object>
28+
{
29+
StringProperty name = new SimpleStringProperty();
30+
31+
@Designable(value="Name", description="The name the control binds to")
32+
public StringProperty nameProperty()
33+
{
34+
return this.name;
35+
}
36+
37+
public String getName()
38+
{
39+
return this.name.getValue();
40+
}
41+
42+
public void setName(String value)
43+
{
44+
this.name.setValue(value);
45+
}
46+
47+
ChartImpl chartImpl;
48+
49+
public SmartChart()
50+
{
51+
setAlignment(Pos.CENTER);
52+
53+
chartImpl = new ChartImpl();
54+
add(chartImpl, 0, 0, 3, 1);
55+
56+
Button resetButton = new Button("Reset Graph");
57+
resetButton.setOnAction(new EventHandler<ActionEvent>()
58+
{
59+
@Override
60+
public void handle(ActionEvent event)
61+
{
62+
chartImpl.reset();
63+
}
64+
});
65+
add(resetButton, 0, 1, 3, 1);
66+
}
67+
68+
public void registered(final DataCoreProvider provider)
69+
{
70+
if (getName() != null) {
71+
provider.getObservable(getName()).addListener(this);
72+
}
73+
this.name.addListener(new ChangeListener<String>()
74+
{
75+
public void changed(ObservableValue<? extends String> ov, String t, String t1)
76+
{
77+
if (t != null) {
78+
provider.getObservable(t).removeListener(SmartChart.this);
79+
}
80+
provider.getObservable(t1).addListener(SmartChart.this);
81+
}
82+
});
83+
}
84+
85+
public void changed(ObservableValue<? extends Object> ov, Object old, Object t1)
86+
{
87+
SmartValue sv = (SmartValue)ov;
88+
double x = sv.getData().asNumber().doubleValue();
89+
90+
chartImpl.addValue(Double.valueOf(x));
91+
}
92+
93+
public Node getUi()
94+
{
95+
return this;
96+
}
97+
}
98+
99+
class ChartImpl extends LineChart<Number, Number>
100+
{
101+
private Series series = new Series();
102+
private long startTimeMillis;
103+
104+
public ChartImpl()
105+
{
106+
super(new NumberAxis(), new NumberAxis());
107+
setAnimated(false);
108+
((NumberAxis)getXAxis()).setForceZeroInRange(false);
109+
((NumberAxis)getYAxis()).setForceZeroInRange(false);
110+
setLegendVisible(false);
111+
getData().add(this.series);
112+
}
113+
114+
public void addValue(double x)
115+
{
116+
if(this.series.getData().size() == 0)
117+
{
118+
startTimeMillis = System.currentTimeMillis();
119+
}
120+
121+
double currentTime = (System.currentTimeMillis() - startTimeMillis)/1000d;
122+
123+
124+
this.series.getData().add(new Data(currentTime, x));
125+
if (this.series.getData().size() > 500) {
126+
this.series.getData().remove(0);
127+
}
128+
}
129+
130+
public void reset()
131+
{
132+
this.series.getData().clear();
133+
}
134+
}
135+

0 commit comments

Comments
 (0)