Search in sources :

Example 1 with JDatePanelImpl

use of net.sourceforge.jdatepicker.impl.JDatePanelImpl in project sldeditor by robward-scisys.

the class FieldConfigTimePeriod method createUIPanel.

/**
 * Creates the ui panel.
 *
 * @param fieldPanel the field panel
 * @param panelData the panel
 * @param index the index
 * @param title the title
 * @return the int
 */
private void createUIPanel(FieldPanel fieldPanel, TimePeriodPanel panelData, int index, String title) {
    panelData.panel = new JPanel();
    panelData.panel.setLayout(null);
    int row = 0;
    panelData.dateRadioButton = new JRadioButton();
    panelData.dateRadioButton.setBounds(2, getRowY(row), 20, BasePanel.WIDGET_HEIGHT);
    panelData.dateRadioButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateFields(panelData);
        }
    });
    panelData.panel.add(panelData.dateRadioButton);
    panelData.buttonGroup.add(panelData.dateRadioButton);
    JDatePanelImpl datePanel = new JDatePanelImpl(panelData.dateModel);
    panelData.datePicker = new JDatePickerImpl(datePanel);
    int xPos = getXPos();
    panelData.datePicker.setBounds(xPos + BasePanel.WIDGET_X_START, getRowY(row), BasePanel.WIDGET_STANDARD_WIDTH, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(panelData.datePicker);
    panelData.dateModel.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    // Time picker
    SpinnerDateModel model = new SpinnerDateModel();
    Calendar calendar = Calendar.getInstance();
    model.setValue(calendar.getTime());
    panelData.timePicker = new JSpinner(model);
    panelData.timePicker.setBounds(panelData.datePicker.getX() + panelData.datePicker.getWidth() + 10, getRowY(row), (int) (BasePanel.WIDGET_STANDARD_WIDTH * 0.75), BasePanel.WIDGET_HEIGHT);
    panelData.timePicker.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    panelData.panel.add(panelData.timePicker);
    panelData.timeEditor = new JSpinner.DateEditor(panelData.timePicker, "HH:mm:ss");
    panelData.timePicker.setEditor(panelData.timeEditor);
    DateFormatter formatter = (DateFormatter) panelData.timeEditor.getTextField().getFormatter();
    formatter.setAllowsInvalid(false);
    formatter.setOverwriteMode(true);
    // 
    // Date
    // 
    row++;
    panelData.durationRadioButton = new JRadioButton();
    panelData.durationRadioButton.setBounds(2, getRowY(row), 20, BasePanel.WIDGET_HEIGHT);
    panelData.durationRadioButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateFields(panelData);
        }
    });
    panelData.panel.add(panelData.durationRadioButton);
    panelData.buttonGroup.add(panelData.durationRadioButton);
    panelData.dateCheckbox = new JCheckBox(Localisation.getString(FieldConfigBase.class, "FieldConfigTimePeriod.date"));
    panelData.dateCheckbox.setBounds(20, getRowY(row), 55, BasePanel.WIDGET_HEIGHT);
    panelData.dateCheckbox.setSelected(true);
    panelData.dateCheckbox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean enabled = panelData.dateCheckbox.isSelected();
            panelData.yearSpinner.setEnabled(enabled);
            panelData.monthSpinner.setEnabled(enabled);
            panelData.daySpinner.setEnabled(enabled);
        }
    });
    panelData.panel.add(panelData.dateCheckbox);
    int x = xPos + BasePanel.WIDGET_X_START - 10;
    // Year
    JLabel yearLbl = new JLabel(Localisation.getField(FieldConfigBase.class, "FieldConfigTimePeriod.year"));
    yearLbl.setHorizontalAlignment(SwingConstants.LEADING);
    yearLbl.setBounds(x, getRowY(row), 40, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(yearLbl);
    panelData.yearSpinner = new JSpinner();
    x = x + 40;
    int spinnerWidth = (int) (BasePanel.WIDGET_STANDARD_WIDTH * 0.4);
    panelData.yearSpinner.setBounds(x, getRowY(row), spinnerWidth, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(panelData.yearSpinner);
    panelData.yearSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    // Month
    x = x + spinnerWidth + 2;
    JLabel monthLbl = new JLabel(Localisation.getField(FieldConfigBase.class, "FieldConfigTimePeriod.month"));
    monthLbl.setHorizontalAlignment(SwingConstants.LEADING);
    monthLbl.setBounds(x, getRowY(row), 40, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(monthLbl);
    x = x + 40;
    panelData.monthSpinner = new JSpinner();
    panelData.monthSpinner.setBounds(x, getRowY(row), spinnerWidth, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(panelData.monthSpinner);
    panelData.monthSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    // Day
    x = x + spinnerWidth + 2;
    JLabel dayLbl = new JLabel(Localisation.getField(FieldConfigBase.class, "FieldConfigTimePeriod.day"));
    dayLbl.setHorizontalAlignment(SwingConstants.LEADING);
    dayLbl.setBounds(x, getRowY(row), 40, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(dayLbl);
    x = x + 40;
    panelData.daySpinner = new JSpinner();
    panelData.daySpinner.setBounds(x, getRowY(row), spinnerWidth, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(panelData.daySpinner);
    panelData.daySpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    // 
    // Time
    // 
    row++;
    panelData.timeCheckbox = new JCheckBox(Localisation.getString(FieldConfigBase.class, "FieldConfigTimePeriod.time"));
    panelData.timeCheckbox.setBounds(20, getRowY(row), 55, BasePanel.WIDGET_HEIGHT);
    panelData.timeCheckbox.setSelected(true);
    panelData.timeCheckbox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean enabled = panelData.timeCheckbox.isSelected();
            panelData.hourSpinner.setEnabled(enabled);
            panelData.minuteSpinner.setEnabled(enabled);
            panelData.secondSpinner.setEnabled(enabled);
        }
    });
    panelData.panel.add(panelData.timeCheckbox);
    x = xPos + BasePanel.WIDGET_X_START - 10;
    // Hours
    JLabel hoursLbl = new JLabel(Localisation.getField(FieldConfigBase.class, "FieldConfigTimePeriod.hours"));
    hoursLbl.setHorizontalAlignment(SwingConstants.LEADING);
    hoursLbl.setBounds(x, getRowY(row), 40, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(hoursLbl);
    panelData.hourSpinner = new JSpinner();
    x = x + 40;
    panelData.hourSpinner.setBounds(x, getRowY(row), spinnerWidth, BasePanel.WIDGET_HEIGHT);
    panelData.hourSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    panelData.panel.add(panelData.hourSpinner);
    // Minutes
    x = x + spinnerWidth + 2;
    JLabel minuteLbl = new JLabel(Localisation.getField(FieldConfigBase.class, "FieldConfigTimePeriod.minutes"));
    minuteLbl.setHorizontalAlignment(SwingConstants.LEADING);
    minuteLbl.setBounds(x, getRowY(row), 40, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(minuteLbl);
    x = x + 40;
    panelData.minuteSpinner = new JSpinner();
    panelData.minuteSpinner.setBounds(x, getRowY(row), spinnerWidth, BasePanel.WIDGET_HEIGHT);
    panelData.minuteSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    panelData.panel.add(panelData.minuteSpinner);
    // Seconds
    x = x + spinnerWidth + 2;
    JLabel secondLabel = new JLabel(Localisation.getField(FieldConfigBase.class, "FieldConfigTimePeriod.seconds"));
    secondLabel.setHorizontalAlignment(SwingConstants.LEADING);
    secondLabel.setBounds(x, getRowY(row), 40, BasePanel.WIDGET_HEIGHT);
    panelData.panel.add(secondLabel);
    x = x + 40;
    panelData.secondSpinner = new JSpinner();
    panelData.secondSpinner.setBounds(x, getRowY(row), spinnerWidth, BasePanel.WIDGET_HEIGHT);
    panelData.secondSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            valueUpdated();
        }
    });
    panelData.panel.add(panelData.secondSpinner);
    fieldPanel.add(panelData.panel);
    panelData.panel.setBounds(0, index * ((row * BasePanel.WIDGET_HEIGHT) + 50), BasePanel.FIELD_PANEL_WIDTH, (row + 2) * BasePanel.WIDGET_HEIGHT);
    Dimension preferredSize = new Dimension((int) panelData.panel.getPreferredSize().getWidth(), (row + 2) * BasePanel.WIDGET_HEIGHT);
    panelData.panel.setPreferredSize(preferredSize);
    panelData.panel.setBorder(BorderFactory.createTitledBorder(title));
}
Also used : JPanel(javax.swing.JPanel) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) Calendar(java.util.Calendar) JDatePanelImpl(net.sourceforge.jdatepicker.impl.JDatePanelImpl) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) SpinnerDateModel(javax.swing.SpinnerDateModel) JDatePickerImpl(net.sourceforge.jdatepicker.impl.JDatePickerImpl) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) DateFormatter(javax.swing.text.DateFormatter) JSpinner(javax.swing.JSpinner) ChangeListener(javax.swing.event.ChangeListener)

Example 2 with JDatePanelImpl

use of net.sourceforge.jdatepicker.impl.JDatePanelImpl in project sldeditor by robward-scisys.

the class FieldConfigDate method createUI.

/**
 * Creates the ui.
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.config.FieldConfigBase#createUI()
     */
@Override
public void createUI() {
    if (datePicker == null) {
        int xPos = getXPos();
        FieldPanel fieldPanel = createFieldPanel(xPos, getLabel());
        JDatePanelImpl datePanel = new JDatePanelImpl(dateModel);
        datePicker = new JDatePickerImpl(datePanel);
        datePicker.setBounds(xPos + BasePanel.WIDGET_X_START, 0, BasePanel.WIDGET_STANDARD_WIDTH, BasePanel.WIDGET_HEIGHT);
        fieldPanel.add(datePicker);
        dateModel.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                valueUpdated();
            }
        });
        // Time picker
        SpinnerDateModel model = new SpinnerDateModel();
        Calendar calendar = Calendar.getInstance();
        model.setValue(calendar.getTime());
        timePicker = new JSpinner(model);
        timePicker.setBounds(datePicker.getX() + datePicker.getWidth() + 10, 0, BasePanel.WIDGET_STANDARD_WIDTH, BasePanel.WIDGET_HEIGHT);
        timePicker.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                valueUpdated();
            }
        });
        fieldPanel.add(timePicker);
        timeEditor = new JSpinner.DateEditor(timePicker, "HH:mm:ss");
        timePicker.setEditor(timeEditor);
        DateFormatter formatter = (DateFormatter) timeEditor.getTextField().getFormatter();
        formatter.setAllowsInvalid(false);
        formatter.setOverwriteMode(true);
        if (!isValueOnly()) {
            setAttributeSelectionPanel(fieldPanel.internalCreateAttrButton(Double.class, this, isRasterSymbol()));
        }
    }
}
Also used : Calendar(java.util.Calendar) JDatePanelImpl(net.sourceforge.jdatepicker.impl.JDatePanelImpl) SpinnerDateModel(javax.swing.SpinnerDateModel) JDatePickerImpl(net.sourceforge.jdatepicker.impl.JDatePickerImpl) ChangeEvent(javax.swing.event.ChangeEvent) DateFormatter(javax.swing.text.DateFormatter) JSpinner(javax.swing.JSpinner) ChangeListener(javax.swing.event.ChangeListener) FieldPanel(com.sldeditor.ui.widgets.FieldPanel)

Aggregations

Calendar (java.util.Calendar)2 JSpinner (javax.swing.JSpinner)2 SpinnerDateModel (javax.swing.SpinnerDateModel)2 ChangeEvent (javax.swing.event.ChangeEvent)2 ChangeListener (javax.swing.event.ChangeListener)2 DateFormatter (javax.swing.text.DateFormatter)2 JDatePanelImpl (net.sourceforge.jdatepicker.impl.JDatePanelImpl)2 JDatePickerImpl (net.sourceforge.jdatepicker.impl.JDatePickerImpl)2 FieldPanel (com.sldeditor.ui.widgets.FieldPanel)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JRadioButton (javax.swing.JRadioButton)1