Search in sources :

Example 1 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class ComponentInspectorSkin method updateCalendarDateControl.

private void updateCalendarDateControl(Dictionary<String, Object> dictionary, String key) {
    CalendarButton calendarButton = (CalendarButton) controls.get(key);
    if (calendarButton != null) {
        CalendarDate value = (CalendarDate) dictionary.get(key);
        calendarButton.setSelectedDate(value);
    }
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton)

Example 2 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class ComponentInspectorSkin method addCalendarDateControl.

private static Component addCalendarDateControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    CalendarDate calendarDate = (CalendarDate) dictionary.get(key);
    CalendarButton calendarButton = new CalendarButton();
    calendarButton.setMinimumWidth(75);
    calendarButton.setSelectedDate(calendarDate);
    section.add(calendarButton);
    Form.setLabel(calendarButton, key);
    calendarButton.getCalendarButtonSelectionListeners().add(new CalendarButtonSelectionListener() {

        @Override
        public void selectedDateChanged(CalendarButton calendarButtonArgument, CalendarDate previousSelectedDate) {
            try {
                dictionary.put(key, calendarButtonArgument.getSelectedDate());
            } catch (Exception exception) {
                displayErrorMessage(exception, calendarButtonArgument.getWindow());
                dictionary.put(key, previousSelectedDate);
            }
        }
    });
    return calendarButton;
}
Also used : CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton) CalendarButtonSelectionListener(org.apache.pivot.wtk.CalendarButtonSelectionListener)

Example 3 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class CalendarButtonDataRenderer method render.

@Override
public void render(final Object data, final Button button, boolean highlight) {
    Object dataMutable = data;
    CalendarButton calendarButton = (CalendarButton) button;
    Locale locale = calendarButton.getLocale();
    if (dataMutable == null) {
        dataMutable = "";
    } else {
        if (dataMutable instanceof CalendarDate) {
            CalendarDate date = (CalendarDate) dataMutable;
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
            dataMutable = dateFormat.format(date.toCalendar().getTime());
        }
    }
    super.render(dataMutable, button, highlight);
}
Also used : Locale(java.util.Locale) CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton) DateFormat(java.text.DateFormat)

Example 4 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class CalendarButtonSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    CalendarButton calendarButton = (CalendarButton) component;
    calendarButton.getCalendarButtonListeners().add(this);
    calendarButton.getCalendarButtonSelectionListeners().add(this);
    calendar.setLocale(calendarButton.getLocale());
}
Also used : CalendarButton(org.apache.pivot.wtk.CalendarButton)

Example 5 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class CalendarTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(CalendarTest.class, "calendar_test.bxml");
    bxmlSerializer.bind(this, CalendarTest.class);
    Filter<CalendarDate> todayFilter = new Filter<CalendarDate>() {

        @Override
        public boolean include(CalendarDate date) {
            CalendarDate today = new CalendarDate();
            return (!date.equals(today));
        }
    };
    calendar.setDisabledDateFilter(todayFilter);
    calendarButton.getCalendarButtonListeners().add(new CalendarButtonListener() {

        @Override
        public void yearChanged(CalendarButton calendarButtonArgument, int previousYear) {
            disable();
        }

        @Override
        public void monthChanged(CalendarButton calendarButtonArgument, int previousMonth) {
            disable();
        }

        private void disable() {
            calendarButton.setDisabledDateFilter(new Filter<CalendarDate>() {

                @Override
                public boolean include(CalendarDate date) {
                    return true;
                }
            });
            Task<Void> task = new Task<Void>() {

                @Override
                public Void execute() {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException exception) {
                    // ignore exception
                    }
                    return null;
                }
            };
            System.out.println("STARTING TASK");
            task.execute(new TaskAdapter<>(new TaskListener<Void>() {

                @Override
                public void taskExecuted(Task<Void> taskArgument) {
                    System.out.println("EXECUTED");
                    calendarButton.setDisabledDateFilter(null);
                }

                @Override
                public void executeFailed(Task<Void> taskArgument) {
                    System.out.println("FAILED");
                    calendarButton.setDisabledDateFilter(null);
                }
            }));
        }
    });
    window.open(display);
}
Also used : Task(org.apache.pivot.util.concurrent.Task) CalendarDate(org.apache.pivot.util.CalendarDate) Filter(org.apache.pivot.util.Filter) TaskAdapter(org.apache.pivot.wtk.TaskAdapter) CalendarButton(org.apache.pivot.wtk.CalendarButton) CalendarButtonListener(org.apache.pivot.wtk.CalendarButtonListener) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

CalendarButton (org.apache.pivot.wtk.CalendarButton)12 Button (org.apache.pivot.wtk.Button)6 GradientPaint (java.awt.GradientPaint)5 CalendarDate (org.apache.pivot.util.CalendarDate)5 Point (org.apache.pivot.wtk.Point)5 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 CalendarButtonSelectionListener (org.apache.pivot.wtk.CalendarButtonSelectionListener)2 ListButton (org.apache.pivot.wtk.ListButton)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 Locale (java.util.Locale)1 ArrayList (org.apache.pivot.collections.ArrayList)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 Filter (org.apache.pivot.util.Filter)1