Search in sources :

Example 1 with DateTimeChangeListener

use of com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener in project sldeditor by robward-scisys.

the class DateTimePanel method createUI.

/**
 * Creates the UI.
 *
 * @param xPos the x pos
 * @param indentWidth the indent width
 * @param yOffset the y offset
 * @param fieldPanel the field panel
 */
public void createUI(int xPos, int indentWidth, int yOffset, JPanel fieldPanel) {
    if (dateTimePicker == null) {
        DatePickerSettings dateModel = new DatePickerSettings();
        dateModel.setAllowEmptyDates(false);
        dateModel.setFormatForDatesCommonEra(DateTimeFormatter.ofPattern("dd MMM yyyy"));
        TimePickerSettings timeModel = new TimePickerSettings();
        timeModel.setAllowEmptyTimes(false);
        timeModel.setDisplaySpinnerButtons(true);
        timeModel.setDisplayToggleTimeMenuButton(false);
        timeModel.setFormatForDisplayTime(PickerUtilities.createFormatterFromPatternString("HH:mm:ss.SSS", timeModel.getLocale()));
        dateTimePicker = new DateTimePicker(dateModel, timeModel);
        int x = xPos + indentWidth;
        dateTimePicker.setBounds(x, yOffset, DATEPICKER_WIDTH, BasePanel.WIDGET_HEIGHT);
        fieldPanel.add(dateTimePicker);
        offsetSign = new JComboBox<>(offsetStrings);
        int y = BasePanel.WIDGET_HEIGHT + yOffset;
        offsetSign.setBounds(x, y, OFFSET_SIGN_WIDTH, BasePanel.WIDGET_HEIGHT);
        offsetSign.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
        fieldPanel.add(offsetSign);
        SpinnerNumberModel hourModel = new SpinnerNumberModel();
        hourModel.setStepSize(1);
        hourModel.setMinimum(0);
        hourModel.setMaximum(23);
        hourSpinner = new JSpinner(hourModel);
        hourSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
        fieldPanel.add(hourSpinner);
        x += OFFSET_SIGN_WIDTH + 2;
        hourSpinner.setBounds(x, y, OFFSET_HOURS_WIDTH, BasePanel.WIDGET_HEIGHT);
        SpinnerNumberModel secondModel = new SpinnerNumberModel();
        secondModel.setStepSize(1);
        secondModel.setMinimum(0);
        secondModel.setMaximum(59);
        minuteSpinner = new JSpinner(secondModel);
        fieldPanel.add(minuteSpinner);
        minuteSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
        x += OFFSET_HOURS_WIDTH + 2;
        minuteSpinner.setBounds(x, y, OFFSET_MINUTES_WIDTH, BasePanel.WIDGET_HEIGHT);
        dateTimePicker.addDateTimeChangeListener(new DateTimeChangeListener() {

            @Override
            public void dateOrTimeChanged(DateTimeChangeEvent event) {
                if (callback != null) {
                    callback.dateTimeValueUpdated();
                }
            }
        });
    }
}
Also used : DateTimeChangeListener(com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) ActionEvent(java.awt.event.ActionEvent) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) DateTimeChangeEvent(com.github.lgooddatepicker.zinternaltools.DateTimeChangeEvent) SpinnerNumberModel(javax.swing.SpinnerNumberModel) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) DateTimeChangeEvent(com.github.lgooddatepicker.zinternaltools.DateTimeChangeEvent) JSpinner(javax.swing.JSpinner) DateTimeChangeListener(com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Aggregations

DatePickerSettings (com.github.lgooddatepicker.components.DatePickerSettings)1 DateTimePicker (com.github.lgooddatepicker.components.DateTimePicker)1 TimePickerSettings (com.github.lgooddatepicker.components.TimePickerSettings)1 DateTimeChangeListener (com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener)1 DateTimeChangeEvent (com.github.lgooddatepicker.zinternaltools.DateTimeChangeEvent)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JSpinner (javax.swing.JSpinner)1 SpinnerNumberModel (javax.swing.SpinnerNumberModel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1