monthSpinner.setCircular(true);
monthSpinner.getStyles().put("sizeToContent", true);
monthSpinner.getSpinnerSelectionListeners().add(new SpinnerSelectionListener() {
public void selectedIndexChanged(Spinner spinner, int previousSelectedIndex) {
Calendar calendar = (Calendar)getComponent();
calendar.setMonth((Integer)spinner.getSelectedItem());
}
});
// Year spinner
yearSpinner = new Spinner();
yearSpinner.setSpinnerData(new NumericSpinnerData(0, Short.MAX_VALUE));
yearSpinner.getSpinnerSelectionListeners().add(new SpinnerSelectionListener() {
public void selectedIndexChanged(Spinner spinner, int previousSelectedIndex) {
Calendar calendar = (Calendar)getComponent();
calendar.setYear((Integer)spinner.getSelectedItem());
}
});
// Attach a listener to consume mouse clicks
ComponentMouseButtonListener spinnerMouseButtonListener = new ComponentMouseButtonListener() {
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
return false;
}
public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
return false;
}
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
return true;
}
};
monthSpinner.getComponentMouseButtonListeners().add(spinnerMouseButtonListener);
yearSpinner.getComponentMouseButtonListeners().add(spinnerMouseButtonListener);
TablePane.Row row;
// Add the month/year flow pane
FlowPane monthYearFlowPane = new FlowPane();
monthYearFlowPane.getStyles().put("padding", 3);
monthYearFlowPane.getStyles().put("horizontalAlignment", HorizontalAlignment.JUSTIFY);
monthYearFlowPane.add(monthSpinner);
monthYearFlowPane.add(yearSpinner);
row = new TablePane.Row();
row.add(monthYearFlowPane);
tablePane.getRows().add(row);
TablePane.setColumnSpan(monthYearFlowPane, 7);
// Add the day labels
row = new TablePane.Row();
for (int i = 0; i < 7; i++) {
Label label = new Label();
label.getStyles().put("fontBold", true);
label.getStyles().put("padding", new Insets(2, 2, 4, 2));
label.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
row.add(label);
}
tablePane.getRows().add(row);
// Add the buttons
dateButtonGroup = new Button.Group();
dateButtonGroup.getGroupListeners().add(new Button.GroupListener() {
public void selectionChanged(Group group, Button previousSelection) {
Calendar calendar = (Calendar)getComponent();
Button selection = group.getSelection();
if (selection == null) {
CalendarDate selectedDate = calendar.getSelectedDate();
// If no date was selected, or the selection changed as a
// result of the user toggling the date button (as opposed
// to changing the month or year), clear the selection
if (selectedDate == null
|| (selectedDate.getYear() == yearSpinner.getSelectedIndex()
&& selectedDate.getMonth() == monthSpinner.getSelectedIndex())) {
calendar.setSelectedDate((CalendarDate)null);
}
} else {
calendar.setSelectedDate((CalendarDate)selection.getButtonData());
}
}
});
for (int j = 0; j < 6; j++) {