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 Video Library
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
View Events Video Library
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
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • JavaFX Gets Video Capabilities
  • The Challenges of a JavaFX Reboot
  • Calling JavaFX From Java?
  • Overview of JavaScript Event Calendars

Trending

  • Build Quicker With Zipper: Building a Ping Pong Ranking App Using TypeScript Functions
  • Implementing Stronger RBAC and Multitenancy in Kubernetes Using Istio
  • Understanding Europe's Cyber Resilience Act and What It Means for You
  • Best Practices for Developing Cloud Applications
  1. DZone
  2. Coding
  3. Java
  4. A JavaFX Script Calendar that Displays a Google Calendar Feed

A JavaFX Script Calendar that Displays a Google Calendar Feed

James Weaver user avatar by
James Weaver
·
Mar. 19, 08 · Interview
Like (0)
Save
Tweet
Share
14.50K Views

Join the DZone community and get the full member experience.

Join For Free

today i'd like to show you the humble beginnings of a javafx script calendar that displays a google calendar feed.  it is currently pointing to my google calendar, which i've sparsely populated with some sample data.  you can change the program to point to your google calendar if you choose.

i'll improve this calendar program over time, but wanted to demonstrate javafx script's ability to easily parse an xml stream over the internet.  you may also want to take a look at the compiled javafx script now speaks json post which demonstrates parsing json streams over the internet.  here's a screenshot of today's example, followed by the program's code:

calendarjfx


the code behind the user interface

obviously there are many improvements that i can make to this calendar, but here are the four source files that comprise this example in its current state:


calendarjfx.fx

/*
* calendarjfx.fx -
* the main program for a compiled javafx calendar program
*
* developed 2008 by james l. weaver (jim.weaver at lat-inc.com)
* to serve as a compiled javafx script example.
*/

import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.system;

frame {
var calmodel =
calendarmodel {}
title: "calendarjfx"
width: 600
height: 600
visible: true
content:
borderpanel {
top:
borderpanel {
left:
flowpanel {
content: [
button {
text: "<<"
action:
function():void {
calmodel.prevyear();
}
},
button {
text: "<"
action:
function():void {
calmodel.prevmonth();
}
}
]
}
center:
flowpanel {
content:
simplelabel {
text: bind "{calmodel.selectedmonthstr} {calmodel.selectedyearstr}"
font:
font {
size: 24
style: fontstyle.bold
}
}
}
right:
flowpanel {
content: [
button {
text: ">"
action:
function():void {
calmodel.nextmonth();
}
},
button {
text: ">>"
action:
function():void {
calmodel.nextyear();
}
}
]
}
bottom:
gridpanel {
// todo: internationalize days of the week
var days = ["sun", "mon", "tue",
"wed", "thu", "fri", "sat"]
rows: 1
columns: 7
cells:
for (day in days) {
simplelabel {
text: day
font:
font {
size: 18
style: fontstyle.bold
}
horizontalalignment:
horizontalalignment.center
}
}
}
}
center:
gridpanel {
vgap: 1
hgap: 1
rows: 6
columns: 7
cells:
for (idx in [1..42]) {
calendarcell {
calmodel: calmodel
dayofmonthstr: bind calmodel.getdayinmonthstrforcell(idx as integer);
cellgregcal: bind calmodel.getdateforcell(idx as integer);
}
}
}
}
onclose:
function():void {
system.exit(0);
}
}


calendarcell.fx

/*
* calendarjfx.fx -
* the main program for a compiled javafx calendar program
*
* developed 2008 by james l. weaver (jim.weaver at lat-inc.com)
* to serve as a compiled javafx script example.
*/

import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.system;

frame {
var calmodel =
calendarmodel {}
title: "calendarjfx"
width: 600
height: 600
visible: true
content:
borderpanel {
top:
borderpanel {
left:
flowpanel {
content: [
button {
text: "<<"
action:
function():void {
calmodel.prevyear();
}
},
button {
text: "<"
action:
function():void {
calmodel.prevmonth();
}
}
]
}
center:
flowpanel {
content:
simplelabel {
text: bind "{calmodel.selectedmonthstr} {calmodel.selectedyearstr}"
font:
font {
size: 24
style: fontstyle.bold
}
}
}
right:
flowpanel {
content: [
button {
text: ">"
action:
function():void {
calmodel.nextmonth();
}
},
button {
text: ">>"
action:
function():void {
calmodel.nextyear();
}
}
]
}
bottom:
gridpanel {
// todo: internationalize days of the week
var days = ["sun", "mon", "tue",
"wed", "thu", "fri", "sat"]
rows: 1
columns: 7
cells:
for (day in days) {
simplelabel {
text: day
font:
font {
size: 18
style: fontstyle.bold
}
horizontalalignment:
horizontalalignment.center
}
}
}
}
center:
gridpanel {
vgap: 1
hgap: 1
rows: 6
columns: 7
cells:
for (idx in [1..42]) {
calendarcell {
calmodel: calmodel
dayofmonthstr: bind calmodel.getdayinmonthstrforcell(idx as integer);
cellgregcal: bind calmodel.getdateforcell(idx as integer);
}
}
}
}
onclose:
function():void {
system.exit(0);
}
}



calendarmodel.fx

/*
* calendarmodel.fx -
* the model behind a compiled javafx calendar program
*
* developed 2008 by james l. weaver (jim.weaver at lat-inc.com)
* to serve as a compiled javafx script example.
*/

import javafx.xml.*;
import java.text.simpledateformat;
import java.lang.system;
import java.util.calendar;
import java.util.gregoriancalendar;

class calendarmodel {
attribute calendarfeeduri =
"http://www.google.com/calendar/feeds/james.l.weaver%40gmail.com/public/full";
attribute docbuilder =
documentbuilder {
namespaceaware:true
validating:true
ignoringcomments:false
};
attribute document =
docbuilder.parseuri(calendarfeeduri);
attribute calentries:calendarentry[];
attribute selectedgregcal:gregoriancalendar = new gregoriancalendar();
attribute utilgregcal:gregoriancalendar = new gregoriancalendar();
attribute selectedmonth:integer;
attribute selectedyear:integer;
attribute dayinmonthfmt = new simpledateformat("d");
attribute monthfmt = new simpledateformat("mmmm");
attribute yearfmt = new simpledateformat("yyyy");
attribute cellnumber:integer;
attribute selecteddayinmonthstr:string;
attribute selectedmonthstr:string;
attribute selectedyearstr:string;

postinit {
var calelements = document.getelementsbytagname("entry");
calentries = for (calelement in calelements)
calendarentry {
title: calelement.querystring("title")
starttimestr: calelement.querystring("when/@starttime")
endtimestr: calelement.querystring("when/@endtime")
location: calelement.querystring("where/@valuestring")
};
populatedateparts();
}

function prevmonth():void {
selectedgregcal.add(calendar.month, -1);
selectedmonth = selectedgregcal.get(calendar.month);
populatedateparts();
}

function nextmonth():void {
selectedgregcal.add(calendar.month, 1);
selectedmonth = selectedgregcal.get(calendar.month);
populatedateparts();
}

function prevyear():void {
selectedgregcal.add(calendar.year, -1);
selectedyear = selectedgregcal.get(calendar.year);
populatedateparts();
}

function nextyear():void {
selectedgregcal.add(calendar.year, 1);
selectedyear = selectedgregcal.get(calendar.year);
populatedateparts();
}

function populatedateparts():void {
var seldate = selectedgregcal.gettime();
selecteddayinmonthstr = dayinmonthfmt.format(seldate);
selectedmonthstr = monthfmt.format(seldate);
selectedyearstr = yearfmt.format(seldate);
}

function getdateforcell(cellnumber:integer):gregoriancalendar {
utilgregcal.set(calendar.year, selectedyear);
utilgregcal.set(calendar.month, selectedmonth);
utilgregcal.set(calendar.day_of_month, 1);
var firstdayoffset = utilgregcal.get(calendar.day_of_week);
utilgregcal.add(calendar.day_of_month, firstdayoffset * -1 + cellnumber);
return utilgregcal;
}

function getdayinmonthstrforcell(cellnumber:integer):string {
utilgregcal.set(calendar.year, selectedyear);
utilgregcal.set(calendar.month, selectedmonth);
utilgregcal.set(calendar.day_of_month, 1);
var firstdayoffset = utilgregcal.get(calendar.day_of_week);
utilgregcal.add(calendar.day_of_month, firstdayoffset * -1 + cellnumber);
dayinmonthfmt.format(utilgregcal.gettime());
}
}



calendarentry.fx

/*
* calendarentry.fx -
* a calendar entry, which is part of the model.
*
* developed 2008 by james l. weaver (jim.weaver at lat-inc.com)
* to serve as a compiled javafx script example.
*/

import java.lang.system;
import java.text.simpledateformat;
import java.util.locale;
import java.util.calendar;
import java.util.date;

class calendarentry {
private attribute sdf = new simpledateformat
("yyyy-mm-dd't'hh:mm:ss.sssz");
attribute title:string;
attribute starttime:calendar;
attribute endtime:calendar;
attribute starttimestr:string on replace {
//todo: accommodate all-day events
var d:date = sdf.parse("{starttimestr.substring(0, 26)}{starttimestr.substring(27)}");
var cal:calendar = calendar.getinstance();
cal.settime(d);
starttime = cal;
};
attribute endtimestr:string on replace {
var d:date = sdf.parse("{endtimestr.substring(0, 26)}{endtimestr.substring(27)}");
var cal:calendar = calendar.getinstance();
cal.settime(d);
endtime = cal;
};
attribute location:string;
}

enjoy, and as always, 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

Google Calendar JavaFX Script JavaFX

Opinions expressed by DZone contributors are their own.

Related

  • JavaFX Gets Video Capabilities
  • The Challenges of a JavaFX Reboot
  • Calling JavaFX From Java?
  • Overview of JavaScript Event Calendars

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

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: