Skip to content

Instantly share code, notes, and snippets.

@bluepapa32
Created February 27, 2010 01:28
Show Gist options
  • Save bluepapa32/316381 to your computer and use it in GitHub Desktop.
Save bluepapa32/316381 to your computer and use it in GitHub Desktop.
Calendar.fx
import java.util.Calendar;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Stack;
import javafx.scene.layout.Tile;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
var year = 2009;
var month = 8;
var cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.SUNDAY);
cal.set(year, month, 1);
cal.add(Calendar.DATE, Calendar.SUNDAY - cal.get(Calendar.DAY_OF_WEEK) - 1);
var days: Node[] = for (i in [0..<42]) {
cal.add(Calendar.DATE, 1);
var m = cal.get(Calendar.MONTH);
var dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
Stack {
content: [
Rectangle {
width: 30 height: 25
stroke: Color.BLACK
strokeWidth: 0.5
fill: Color.LIGHTGRAY
},
Text {
content: "{cal.get(Calendar.DATE)}";
fill: if (m != month) {
Color.GRAY
} else if (dayOfWeek == Calendar.SUNDAY) {
Color.RED
} else if (dayOfWeek == Calendar.SATURDAY) {
Color.BLUE
} else {
Color.BLACK
}
}
]
}
}
var yobi = for (d in ["Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" ]) {
Stack {
content: [
Rectangle {
width: 30 height: 25
stroke: Color.BLACK
strokeWidth: 0.5
fill: Color.DARKGRAY
},
Text {
content: "{d}"
fill: Color.WHITE
}
]
}
}
Stage {
scene: Scene {
content: Tile {
columns: 7
tileWidth: 30
tileHeight: 25
hgap:0 vgap: 0
content: [ yobi, days ]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment