Java Code Examples for javax.swing.JSpinner.DateEditor

The following examples show how to use javax.swing.JSpinner.DateEditor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dsworkbench   Source File: ClockFrame.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form ClockFrame
 */
ClockFrame() {
    initComponents();
    jSpinner1.setValue(new Date(System.currentTimeMillis()));
    ((DateEditor) jSpinner1.getEditor()).getFormat().applyPattern("dd.MM.yy HH:mm:ss.SSS");
    tThread = new TimerThread(this);
    tThread.start();

    jCheckBox1.setSelected(GlobalOptions.getProperties().getBoolean("clock.alwaysOnTop"));

    setAlwaysOnTop(jCheckBox1.isSelected());
    cp = new ColoredProgressBar(0, 1000);
    jPanel1.add(cp, BorderLayout.CENTER);

    jComboBox1.setModel(new DefaultComboBoxModel(new String[]{"Alarm", "Homer", "LetsGo", "NHL", "Roadrunner", "Schwing", "Sirene", "StarTrek1", "StarTrek2"}));
    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.clock_tool", GlobalOptions.getHelpBroker().getHelpSet());
    }
    restoreTimers();
    // </editor-fold>
}
 
Example 2
Source Project: nmonvisualizer   Source File: LineChartAnnotationDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
    // for xAxisTime
    if (useXAxisValue.isSelected()) {
        annotation.setText(((DateEditor) xAxisTime.getEditor()).getFormat().format(xAxisTime.getValue()));
    }
}
 
Example 3
Source Project: nmonvisualizer   Source File: IOStatPostParser.java    License: Apache License 2.0 5 votes vote down vote up
protected void addComponents(JPanel content, GridBagConstraints labelConstraints,
        GridBagConstraints fieldConstraints) {

    date = new JSpinner(new SpinnerDateModel(new Date(TimeHelper.today()), null, null, Calendar.DAY_OF_WEEK));
    date.setEditor(new DateEditor(date, "MMM dd yyyy"));

    JLabel dateLabel = new JLabel("Date:");
    dateLabel.setFont(Styles.LABEL);
    dateLabel.setHorizontalAlignment(SwingConstants.TRAILING);

    content.add(dateLabel, labelConstraints);
    content.add(date, fieldConstraints);
}
 
Example 4
Source Project: nmonvisualizer   Source File: AbsoluteTimeIntervalPanel.java    License: Apache License 2.0 4 votes vote down vote up
AbsoluteTimeIntervalPanel(NMONVisualizerGui gui) {
    super(gui);

    setLayout(new BorderLayout());

    add.addActionListener(addInterval);

    // start and end text boxes with labels, followed by a Add button
    startLabel = new JLabel("Start:");
    startLabel.setHorizontalAlignment(SwingConstants.TRAILING);
    startLabel.setFont(Styles.LABEL);

    start = new JSpinner(new SpinnerDateModel(new Date(getDefaultStartTime()), null, null, Calendar.MINUTE));
    start.setEditor(new DateEditor(start, Styles.DATE_FORMAT_STRING_WITH_YEAR));
    start.addChangeListener(intervalUpdater);

    endLabel = new JLabel("End:");
    endLabel.setHorizontalAlignment(SwingConstants.TRAILING);
    endLabel.setFont(Styles.LABEL);

    end = new JSpinner(new SpinnerDateModel(new Date(getDefaultEndTime()), null, null, Calendar.MINUTE));
    end.setEditor(new DateEditor(end, Styles.DATE_FORMAT_STRING_WITH_YEAR));
    end.addChangeListener(intervalUpdater);

    JPanel namePanel = new JPanel();

    namePanel.add(nameLabel);
    namePanel.add(name);

    JPanel startPanel = new JPanel();

    startPanel.add(startLabel);
    startPanel.add(start);

    JPanel endPanel = new JPanel();

    endPanel.add(endLabel);
    endPanel.add(end);

    JPanel buttonsPanel = new JPanel();

    buttonsPanel.add(add);
    buttonsPanel.add(endToStart);
    buttonsPanel.add(reset);

    JPanel dataPanel = new JPanel();
    dataPanel.setLayout(new GridBagLayout());

    GridBagConstraints labelConstraints = new GridBagConstraints();
    GridBagConstraints fieldConstraints = new GridBagConstraints();

    labelConstraints.gridx = 0;
    fieldConstraints.gridx = 1;

    labelConstraints.gridy = 0;
    fieldConstraints.gridy = 0;

    labelConstraints.insets = new Insets(0, 0, 0, 5);
    fieldConstraints.insets = new Insets(5, 0, 0, 5);

    labelConstraints.fill = GridBagConstraints.HORIZONTAL;
    fieldConstraints.fill = GridBagConstraints.HORIZONTAL;

    dataPanel.add(startLabel, labelConstraints);
    dataPanel.add(start, fieldConstraints);

    ++labelConstraints.gridy;
    ++fieldConstraints.gridy;

    dataPanel.add(endLabel, labelConstraints);
    dataPanel.add(end, fieldConstraints);

    add(namePanel, BorderLayout.PAGE_START);
    add(dataPanel, BorderLayout.CENTER);
    add(buttonsPanel, BorderLayout.PAGE_END);
}
 
Example 5
Source Project: nmonvisualizer   Source File: AbsoluteTimeIntervalPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
TimeZone getTimeZone() {
    DateEditor de = (DateEditor) start.getEditor();
    return de.getFormat().getTimeZone();
}
 
Example 6
Source Project: nmonvisualizer   Source File: RelativeTimeIntervalPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
TimeZone getTimeZone() {
    DateEditor de = (DateEditor) base.getEditor();
    return de.getFormat().getTimeZone();
}
 
Example 7
Source Project: nmonvisualizer   Source File: RelativeTimeIntervalPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    // all but timeZone fired by IntervalDocumentListeners
    if ("interval".equals(evt.getPropertyName())) {
        if (evt.getNewValue() == null) {
            startLabel.setFont(Styles.LABEL_ERROR);
            endLabel.setFont(Styles.LABEL_ERROR);

            startLabel.setForeground(Styles.ERROR_COLOR);
            endLabel.setForeground(Styles.ERROR_COLOR);

            start.setForeground(Styles.ERROR_COLOR);
            end.setForeground(Styles.ERROR_COLOR);
            days.setForeground(Styles.ERROR_COLOR);
        }
        else {
            startLabel.setFont(Styles.LABEL);
            endLabel.setFont(Styles.LABEL);

            startLabel.setForeground(Styles.DEFAULT_COLOR);
            endLabel.setForeground(Styles.DEFAULT_COLOR);

            start.setForeground(Styles.DEFAULT_COLOR);
            end.setForeground(Styles.DEFAULT_COLOR);
            days.setForeground(Styles.DEFAULT_COLOR);
        }
    }
    else if ("start".equals(evt.getPropertyName())) {
        startAbsolute.setText(FORMAT.format(new Date((Long) evt.getNewValue())));
    }
    else if ("end".equals(evt.getPropertyName())) {
        endAbsolute.setText(FORMAT.format(new Date((Long) evt.getNewValue())));
    }
    else if ("timeZone".equals(evt.getPropertyName())) {
        TimeZone timeZone = (TimeZone) evt.getNewValue();

        DateEditor de = (DateEditor) base.getEditor();
        de.getFormat().setTimeZone(timeZone);

        // hack to get the spinner to fire a state change and update the displayed value
        // toggle the calendar field back to its original value
        ((SpinnerDateModel) base.getModel()).setCalendarField(Calendar.MINUTE);
        ((SpinnerDateModel) base.getModel()).setCalendarField(Calendar.SECOND);

        FORMAT.setTimeZone(timeZone);
        startAbsolute.setText(FORMAT.format(new Date(getStartTime())));
        endAbsolute.setText((FORMAT.format(new Date(getEndTime()))));
    }
}
 
Example 8
Source Project: nmonvisualizer   Source File: BulkIntervalPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
TimeZone getTimeZone() {
    DateEditor de = (DateEditor) start.getEditor();
    return de.getFormat().getTimeZone();
}
 
Example 9
Source Project: nmonvisualizer   Source File: BulkIntervalPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if ("timeZone".equals(evt.getPropertyName())) {
        TimeZone timeZone = (TimeZone) evt.getNewValue();

        DateEditor de = (DateEditor) start.getEditor();
        de.getFormat().setTimeZone(timeZone);

        // hack to get the spinner to fire a state change and update the displayed value
        // toggle the calendar field back to its original value
        ((SpinnerDateModel) start.getModel()).setCalendarField(Calendar.MINUTE);
        ((SpinnerDateModel) start.getModel()).setCalendarField(Calendar.SECOND);

        FORMAT.setTimeZone(timeZone);
        end.setText(FORMAT.format(getEndTime()));
    }
    else if ("values".equals(evt.getPropertyName())) {
        long[] updatedValues = (long[]) evt.getNewValue();

        boolean validDuration = true;

        // 0 days, then duration must be valid & non-zero
        if (updatedValues[1] == 0) {
            // duration
            if (updatedValues[0] < 1) {
                validDuration = false;
            }
        }

        if (validDuration) {
            durationLabel.setFont(Styles.LABEL);
            durationLabel.setForeground(Styles.DEFAULT_COLOR);

            duration.setForeground(Styles.DEFAULT_COLOR);
            days.setForeground(Styles.DEFAULT_COLOR);
        }
        else {
            durationLabel.setFont(Styles.LABEL_ERROR);
            durationLabel.setForeground(Styles.ERROR_COLOR);

            duration.setForeground(Styles.ERROR_COLOR);
            days.setForeground(Styles.ERROR_COLOR);
        }

        // repeat
        if (updatedValues[2] == 0) {
            repeatLabel.setFont(Styles.LABEL_ERROR);
            repeatLabel.setForeground(Styles.ERROR_COLOR);

            repeat.setForeground(Styles.ERROR_COLOR);

            offset.setEnabled(false);
        }
        else {
            repeatLabel.setFont(Styles.LABEL);
            repeatLabel.setForeground(Styles.DEFAULT_COLOR);

            repeat.setForeground(Styles.DEFAULT_COLOR);

            if (updatedValues[2] == 1) {
                // repeating once => no offset
                offset.setEnabled(false);
            }
            else {
                offset.setEnabled(true);
            }
        }

        // offset: -1 => invalid
        if (updatedValues[3] < 0) {
            offsetLabel.setFont(Styles.LABEL_ERROR);
            offsetLabel.setForeground(Styles.ERROR_COLOR);

            offset.setForeground(Styles.ERROR_COLOR);
        }
        else {
            offsetLabel.setFont(Styles.LABEL);
            offsetLabel.setForeground(Styles.DEFAULT_COLOR);

            offset.setForeground(Styles.DEFAULT_COLOR);
        }

        // end time
        if (updatedValues[4] != -1) {
            end.setText(FORMAT.format(updatedValues[4]));
        }
    }
}