Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.Calendar


            return consumed;
        }
    };

    public CalendarButtonSkin() {
        calendar = new Calendar();

        calendarPopup = new Window();
        calendarPopup.getComponentMouseButtonListeners().add(calendarPopupMouseButtonListener);
        calendarPopup.getComponentKeyListeners().add(calendarPopupKeyListener);
        calendarPopup.getWindowStateListeners().add(calendarPopupWindowStateListener);
View Full Code Here


    implements CalendarListener, CalendarSelectionListener {
    @Override
    public void install(Component component) {
        super.install(component);

        Calendar calendar = (Calendar)component;
        calendar.getCalendarListeners().add(this);
        calendar.getCalendarSelectionListeners().add(this);
    }
View Full Code Here

        monthSpinner.getStyles().put("sizeToContent", true);

        monthSpinner.getSpinnerSelectionListeners().add(new SpinnerSelectionListener() {
            @Override
            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() {
            @Override
            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.Adapter() {
            @Override
            public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
                return true;
            }
        };

        monthSpinner.getComponentMouseButtonListeners().add(spinnerMouseButtonListener);
        yearSpinner.getComponentMouseButtonListeners().add(spinnerMouseButtonListener);

        // Add the month/year table pane
        TablePane monthYearTablePane = new TablePane();
        monthYearTablePane.getStyles().put("padding", 3);
        monthYearTablePane.getStyles().put("horizontalSpacing", 4);

        monthYearTablePane.getColumns().add(new TablePane.Column(1, true));
        monthYearTablePane.getColumns().add(new TablePane.Column(-1));

        TablePane.Row monthYearRow = new TablePane.Row(-1);
        monthYearTablePane.getRows().add(monthYearRow);
        monthYearRow.add(monthSpinner);
        monthYearRow.add(yearSpinner);

        TablePane.Row calendarRow = new TablePane.Row();
        calendarRow.add(monthYearTablePane);
        calendarTablePane.getRows().add(calendarRow);

        TablePane.setColumnSpan(monthYearTablePane, 7);

        // Add the day labels
        calendarRow = new TablePane.Row();

        Font labelFont = theme.getFont();
        labelFont = labelFont.deriveFont(Font.BOLD);

        for (int i = 0; i < 7; i++) {
            Label label = new Label();
            label.getStyles().put("font", labelFont);
            label.getStyles().put("padding", new Insets(2, 2, 4, 2));
            label.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
            calendarRow.add(label);
        }

        calendarTablePane.getRows().add(calendarRow);

        // Add the buttons
        dateButtonGroup = new ButtonGroup();
        dateButtonGroup.getButtonGroupListeners().add(new ButtonGroupListener.Adapter() {
            @Override
            public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
                Calendar calendar = (Calendar)getComponent();

                Button selection = buttonGroup.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.year == yearSpinner.getSelectedIndex()
                            && selectedDate.month == monthSpinner.getSelectedIndex())) {
                        calendar.setSelectedDate((CalendarDate)null);
                    }
                } else {
                    calendar.setSelectedDate((CalendarDate)selection.getButtonData());
                }
            }
        });

        for (int j = 0; j < 6; j++) {
View Full Code Here

    @Override
    public void install(Component component) {
        super.install(component);

        Calendar calendar = (Calendar)component;
        calendar.add(calendarTablePane);

        yearSpinner.setSelectedIndex(calendar.getYear());
        monthSpinner.setSelectedIndex(calendar.getMonth());
        updateLabels();
        updateCalendar();
    }
View Full Code Here

    }

    private void updateLabels() {
        TablePane.Row row = calendarTablePane.getRows().get(1);

        Calendar calendar = (Calendar)getComponent();
        Locale locale = calendar.getLocale();
        GregorianCalendar gregorianCalendar = new GregorianCalendar(locale);
        SimpleDateFormat monthFormat = new SimpleDateFormat("E", locale);
        int firstDayOfWeek = gregorianCalendar.getFirstDayOfWeek();

        for (int i = 0; i < 7; i++) {
View Full Code Here

            label.setText(text);
        }
    }

    private void updateCalendar() {
        Calendar calendar = (Calendar)getComponent();
        int month = calendar.getMonth();
        int year = calendar.getYear();

        Filter<CalendarDate> disabledDateFilter = calendar.getDisabledDateFilter();

        monthSpinner.setSelectedIndex(month);
        yearSpinner.setSelectedIndex(year);

        // Determine the first and last days of the month
        Locale locale = calendar.getLocale();
        GregorianCalendar gregorianCalendar = new GregorianCalendar(locale);
        gregorianCalendar.set(year, month, 1);
        int firstIndex = gregorianCalendar.get(java.util.Calendar.DAY_OF_WEEK)
            - gregorianCalendar.getFirstDayOfWeek();
        int lastIndex = firstIndex + gregorianCalendar.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);

        // Determine the last day of last month
        gregorianCalendar.add(java.util.Calendar.MONTH, -1);
        int daysLastMonth = gregorianCalendar.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);

        for (int j = 0; j < 6; j++) {
            for (int i = 0; i < 7; i++) {
                month = calendar.getMonth();
                year = calendar.getYear();

                int k = j * 7 + i;

                DateButton dateButton = dateButtons[j][i];

                int day;
                boolean enabled = false;
                if (k < firstIndex) {
                    month--;
                    if (month < 0) {
                        month = 11;
                        year--;
                    }

                    day = daysLastMonth - (firstIndex - k);
                } else if (k >= lastIndex) {
                    month++;
                    if (month > 11) {
                        month = 0;
                        year++;
                    }

                    day = k - lastIndex;
                } else {
                    day = k - firstIndex;
                    enabled = true;
                }

                CalendarDate buttonData = new CalendarDate(year, month, day);
                dateButton.setButtonData(buttonData);
                dateButton.setEnabled(enabled
                    && (disabledDateFilter == null
                        || !disabledDateFilter.include(buttonData)));
            }
        }

        // Show/hide last row
        calendarTablePane.getRows().get(7).setVisible(dateButtons[5][0].isEnabled());

        today = new CalendarDate();
        updateSelection(calendar.getSelectedDate());
    }
View Full Code Here

        today = new CalendarDate();
        updateSelection(calendar.getSelectedDate());
    }

    private void updateSelection(CalendarDate selectedDate) {
        Calendar calendar = (Calendar)getComponent();
        Button selection = dateButtonGroup.getSelection();

        if (selectedDate == null) {
            if (selection != null) {
                selection.setSelected(false);
            }
        } else {
            int year = selectedDate.year;
            int month = selectedDate.month;

            if (year == calendar.getYear()
                && month == calendar.getMonth()) {
                int day = selectedDate.day;

                // Update the button group
                int cellIndex = getCellIndex(year, month, day, calendar.getLocale());
                int rowIndex = cellIndex / 7;
                int columnIndex = cellIndex % 7;

                TablePane.Row row = calendarTablePane.getRows().get(rowIndex + 2);
                DateButton dateButton = (DateButton)row.get(columnIndex);
View Full Code Here

        @Override
        public void mouseOver(Component component) {
            super.mouseOver(component);

            Calendar calendar = (Calendar)TerraCalendarSkin.this.getComponent();

            if (calendar.containsFocus()) {
                component.requestFocus();
            }
        }
View Full Code Here

                || keyCode == Keyboard.KeyCode.DOWN
                || keyCode == Keyboard.KeyCode.LEFT
                || keyCode == Keyboard.KeyCode.RIGHT) {
                CalendarDate date = (CalendarDate)dateButton.getButtonData();

                Calendar calendar = (Calendar)TerraCalendarSkin.this.getComponent();
                int cellIndex = getCellIndex(date.year, date.month, date.day, calendar.getLocale());
                int rowIndex = cellIndex / 7;
                int columnIndex = cellIndex % 7;

                Component nextButton;
                switch (keyCode) {
View Full Code Here

    }

    public class MonthSpinnerItemRenderer extends SpinnerItemRenderer {
        @Override
        public void render(Object item, Spinner spinner) {
            Calendar calendar = (Calendar)getComponent();

            // Since we're only rendering the month, the year and day do not matter here
            CalendarDate date = new CalendarDate(2000, (Integer)item, 0);

            SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM", calendar.getLocale());
            item = monthFormat.format(date.toCalendar().getTime());

            super.render(item, spinner);
        }
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.Calendar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.