Skip to main content

Sequence Triggers

11 replies [Last post]
kram
Offline
Joined: 2007-10-23
Points: 0

Can someone please tell me how I write a delete trigger on a sequence?

I cannot seem to get mine to work.

<br />
var nodesList:Node[] = [<br />
    Rectangle {<br />
        x: 0,<br />
        y: 0,<br />
        width: width,<br />
        height: height,<br />
        fill: Color.WHITE<br />
    }<br />
]<br />
on replace indx oldValue {<br />
    System.out.println("replaced {oldValue} at {indx} with {entries[indx]}");<br />
  }<br />
  on insert indx newValue {<br />
    System.out.println("inserted {newValue} at {indx}");<br />
  }<br />
  on delete indx oldValue {<br />
    System.out.println("deleted {oldValue} from {indx}");<br />
  };<br />

Thats the code I have,and I get compile errors. If someone could point me in the direction of some up-to-date doco, that would be great.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kram
Offline
Joined: 2007-10-23
Points: 0

Bah, Ive found it

[code]
Frame {
title: "My Mouse Testing App"
width: width
height: height
closeAction: function() {
java.lang.System.exit( 0 );
}
visible: true

stage: Stage {
content: [
Group {
content: bind nodesList;
onMouseClicked: function( e: MouseEvent ):Void {
var newCircle = MyCircle {
fill: Color.BLACK;
centerX: e.getX();
centerY: e.getY();
radius: 1;
};

[b] insert newCircle into nodesList;[/b]
newCircle.arrayIndex = sizeof nodesList - 1;
}
}
]
}
}
[/code]

The insert statement is causing it... but why is that?

alexsch
Offline
Joined: 2007-07-12
Points: 0

> The insert statement is causing it... but why is that?

It is probably an issue in compiler.
Please, create an issue on it: http://openjfx.java.sun.com/jira/secure/CreateIssue!default.jspa

kram
Offline
Joined: 2007-10-23
Points: 0

> > The insert statement is causing it... but why is
> that?
>
> It is probably an issue in compiler.
> Please, create an issue on it:
> http://openjfx.java.sun.com/jira/secure/CreateIssue!de
> fault.jspa

Nope its fine, you were right it was just an access issue! All fixed now!

alexsch
Offline
Joined: 2007-07-12
Points: 0

Here is a simple example:

[code]
import java.lang.System;

var seq = [1,2] on replace oldValues[lo..hi] = newValues{

for(val in oldValues[lo..hi]){
System.out.println("delete: {val}");
}

for(val in newValues){
System.out.println("insert: {val}");
}

}

System.out.println("[start]");
insert 0 into seq;
delete 2 from seq;

[/code]

kram
Offline
Joined: 2007-10-23
Points: 0

thank you Alex, so I guess the "on delete" and "on insert" where removed? there is certainly a lot of out dated doco out there...

alexsch
Offline
Joined: 2007-07-12
Points: 0

> So I guess the "on delete" and "on
> insert" where removed?

Yes. There is only [b]on replace [/b] trigger now which can handle all events.
> there is certainly a lot of
> out dated doco out there...

See JavaFX Script Documentation: http://openjfx.java.sun.com/current-build/doc/reference/triggers.html

kram
Offline
Joined: 2007-10-23
Points: 0

Im getting a compilation error:

D:\Dev\Projects\JavaFXApplicationMouseTest\src\javafxapplicationmousetest\Main.fx:38: cannot find symbol
symbol : method get$nodesList()
location: interface javafxapplicationmousetest.Main$Intf
var nodesList:Node[] = [
1 error
BUILD FAILED (total time: 1 second)

Here is the code:

[code]
var nodesList:Node[] = [
Rectangle { x: 0, y: 0, width: width, height: height, fill: Color.WHITE }
] on replace oldValues[lo..hi] = newValues{
java.lang.System.out.println("replaced");
for(val in oldValues[lo..hi]){
java.lang.System.out.println("delete: {val}");
}
};
[/code]

I dont know why this is happening, but when I remove the ":Node[]" it works, but the rest of my code fails (incompatible types errors).

How do I go about getting the latest build going? Maybe this is fixed in a new build, im only only the preview SDK

kram
Offline
Joined: 2007-10-23
Points: 0

Im back onto trying to fix this, does anyone have any ideas? I can post all the code for my mini-app if you need...

alexsch
Offline
Joined: 2007-07-12
Points: 0

This works in my IDE with JavaFX Preview release:

[code]
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;

var width = 20;
var height = 20;

var nodesList:Node[] = [
Rectangle { x: 0, y: 0, width: width, height: height, fill: Color.WHITE }
] on replace oldValues[lo..hi] = newValues{
java.lang.System.out.println("replaced");
for(val in oldValues[lo..hi]){
java.lang.System.out.println("delete: {val}");
}
};

delete nodesList[0];

Output:
replaced
replaced
delete: javafx.scene.geometry.Rectangle@93d6bc

[/code]

Could you post code that delete items from the list?

kram
Offline
Joined: 2007-10-23
Points: 0

Sure its:

[code]
class MyCircle extends Circle {
attribute arrayIndex: Integer;
attribute expandingRadiusTimeLine : Timeline = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames : [
KeyFrame { time : 0ms,
values : radius => 1 },
KeyFrame { time : 625ms,
values : radius => 26 tween Interpolator.LINEAR ,
action: function() {
delete nodesList[arrayIndex];
}

}
]
}
init {
expandingRadiusTimeLine.start();
}
}
[/code]

alexsch
Offline
Joined: 2007-07-12
Points: 0

It because the [b]nodesList[/b] variable is defined outside of MyCircle class.
Just define it as atribute of MyCircle class.