DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Java
  4. Trigger Happy - Sequence Triggers in Compiled JavaFX Script

Trigger Happy - Sequence Triggers in Compiled JavaFX Script

James Weaver user avatar by
James Weaver
·
Feb. 11, 08 · Interview
Like (0)
Save
Tweet
Share
7.26K Views

Join the DZone community and get the full member experience.

Join For Free

in the binding to a sequence in compiled javafx script article, we bound a listbox to a sequence in the model. this binding causes the listbox to stay in sync with the sequence. the example in today's article builds on the previous one, introducing the concept of sequence triggers . here's a screenshot of the program, followed by the source code. i'll follow up with a brief discussion.

sequencetriggers_2

/*
* sequencetriggers.fx
*
* developed 2008 by james l. weaver (jim.weaver at lat-inc.com)
* to serve as a javafx script example of using sequence triggers
*/
import javafx.ui.*;
import java.lang.system;

class model {
attribute entries:string[] = ["red", "green", "blue", "yellow", "purple"]
on replace [indx] (oldvalue) {
system.out.println("replaced {oldvalue} at {indx} with {entries[indx]}");
}
on insert [indx] (newvalue) {
system.out.println("inserted {newvalue} at {indx}");
}
on delete [indx] (oldvalue) {
system.out.println("deleted {oldvalue} from {indx}");
};
attribute selectedindex:number = 0 on replace {
system.out.println("selectedindex={selectedindex}");
};
attribute enteredtext:string;
}

frame {
var mdl = model {}
title: "sequence triggers"
width: 400
height: 200
background: color.white
visible: true
content:
borderpanel {
center:
flowpanel {
content:
listbox {
cells: bind for (entry in mdl.entries)
listcell {
text: entry
}
selection: bind mdl.selectedindex with inverse
fixedcellwidth: 100
visiblerowcount: 4
}
}
bottom:
flowpanel {
content: [
textfield {
value: bind mdl.enteredtext with inverse
columns: 10
},
button {
text: "insert"
defaultbutton: true
enabled: bind mdl.enteredtext.trim() <> ""
action:
function():void {
insert mdl.enteredtext before mdl.entries[mdl.selectedindex.intvalue()];
mdl.enteredtext = "";
system.out.println("sizeof entries={sizeof mdl.entries}");
}
},
button {
text: "replace"
enabled: bind mdl.enteredtext.trim() <> ""
action:
function():void {
mdl.entries[mdl.selectedindex.intvalue()] = mdl.enteredtext;
mdl.enteredtext = "";
}
},
button {
text: "delete"
enabled: bind mdl.selectedindex >= 0
action:
function():void {
delete mdl.entries[mdl.selectedindex.intvalue()];
}
}
]
}
}
}

sequence triggers

triggers can be created that execute when certain operations happen to a sequence. these operations are:

  • inserting an element
  • replacing an element
  • deleting an element

the program example above demonstrates the use of each of these triggers by printing a message to the console when they execute. notice the distinction between the replace trigger that applies to elements of a sequence, and the replace trigger that applies to variables (as shown in the selectedindex attribute declaration).

have fun with this example, and please post a comment if you have any questions.

regards,
jim weaver
javafx script: dynamic java scripting for rich internet/client-side applications

immediate ebook (pdf) download available at the book's apress site

JavaFX Script JavaFX

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 10 Things to Know When Using SHACL With GraphDB
  • What To Know Before Implementing IIoT
  • A Beginner's Guide to Infrastructure as Code
  • DevOps vs Agile: Which Approach Will Win the Battle for Efficiency?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: