Search in sources :

Example 1 with SpinnerListModel

use of javax.swing.SpinnerListModel in project keystore-explorer by kaikramer.

the class DDateTimeChooser method initComponents.

private void initComponents(Date date) {
    jcbMonth = new JComboBox<Object>(MONTH_NAMES);
    jcbMonth.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent evt) {
            update();
        }
    });
    jsYear = new JSpinner(new SpinnerListModel(YEARS));
    jsYear.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            update();
        }
    });
    jlDaysOfMonth = new JLabel[7][7];
    for (int i = 0; i < 7; i++) {
        jlDaysOfMonth[0][i] = new JLabel(DAY_NAMES[i], SwingConstants.RIGHT);
        jlDaysOfMonth[0][i].setOpaque(true);
        jlDaysOfMonth[0][i].setForeground(WEEK_DAY_FOREGROUND);
        jlDaysOfMonth[0][i].setBackground(WEEK_DAY_BACKGROUND);
        jlDaysOfMonth[0][i].setBorder(new EmptyBorder(0, 0, 0, 3));
    }
    for (int i = 1; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            jlDaysOfMonth[i][j] = new JLabel(EMPTY_DAY, SwingConstants.RIGHT);
            jlDaysOfMonth[i][j].setOpaque(true);
            jlDaysOfMonth[i][j].setForeground(DAY_FOREGROUND);
            jlDaysOfMonth[i][j].setBackground(DAY_BACKGROUND);
            jlDaysOfMonth[i][j].addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent evt) {
                    selectDay((JLabel) evt.getSource());
                }
            });
            jlDaysOfMonth[i][j].setBorder(new CompoundBorder(new MatteBorder(2, 0, 0, 0, Color.WHITE), new EmptyBorder(0, 0, 0, 3)));
        }
    }
    jpMonthYear = new JPanel();
    jpMonthYear.add(jcbMonth);
    jpMonthYear.add(jsYear);
    jpDaysOfMonth = new JPanel(new DayOfMonthGridLayout(7, 7));
    jpDaysOfMonth.setBackground(DAY_BACKGROUND);
    jpDaysOfMonth.setBorder(new CompoundBorder(BorderFactory.createLoweredBevelBorder(), new EmptyBorder(2, 2, 2, 2)));
    jpDaysOfMonth.setFocusable(true);
    jpDaysOfMonth.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent evt) {
            setSelectedDay(jlSelectedDayOfMonth);
        }

        @Override
        public void focusLost(FocusEvent evt) {
            setSelectedDay(jlSelectedDayOfMonth);
        }
    });
    jpDaysOfMonth.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent evt) {
            calendarKeyboardNavigation(evt);
        }
    });
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            jpDaysOfMonth.add(jlDaysOfMonth[i][j]);
        }
    }
    jsHour = new JSpinner(new SpinnerListModel(HOURS));
    jlTimeSeparator1 = new JLabel(":");
    jsMinute = new JSpinner(new SpinnerListModel(MINUTES));
    jlTimeSeparator2 = new JLabel(":");
    jsSecond = new JSpinner(new SpinnerListModel(SECONDS));
    jpTime = new JPanel(new FlowLayout(FlowLayout.CENTER));
    jpTime.add(jsHour);
    jpTime.add(jlTimeSeparator1);
    jpTime.add(jsMinute);
    jpTime.add(jlTimeSeparator2);
    jpTime.add(jsSecond);
    JPanel jpDateTime = new JPanel(new BorderLayout(0, 0));
    jpDateTime.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5))));
    jpDateTime.add(BorderLayout.NORTH, jpMonthYear);
    jpDateTime.add(BorderLayout.CENTER, jpDaysOfMonth);
    jpDateTime.add(BorderLayout.SOUTH, jpTime);
    jbOK = new JButton(res.getString("DDateTimeChooser.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });
    jbCancel = new JButton(res.getString("DDateTimeChooser.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jpButtons = PlatformUtil.createDialogButtonPanel(jbOK, jbCancel, false);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(BorderLayout.CENTER, jpDateTime);
    getContentPane().add(BorderLayout.SOUTH, jpButtons);
    if (date == null) {
        date = new Date();
    }
    populate(date);
    setResizable(false);
    getRootPane().setDefaultButton(jbOK);
    pack();
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) MatteBorder(javax.swing.border.MatteBorder) BorderLayout(java.awt.BorderLayout) ChangeListener(javax.swing.event.ChangeListener) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) AbstractAction(javax.swing.AbstractAction) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Date(java.util.Date) EtchedBorder(javax.swing.border.EtchedBorder) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) JSpinner(javax.swing.JSpinner) ItemListener(java.awt.event.ItemListener) SpinnerListModel(javax.swing.SpinnerListModel) FocusListener(java.awt.event.FocusListener)

Example 2 with SpinnerListModel

use of javax.swing.SpinnerListModel in project opennars by opennars.

the class CharacterEditor method buildModel.

protected void buildModel(char min, char max) {
    List<Character> characters = new ArrayList<Character>();
    for (char c = min; c <= max; c++) {
        characters.add(c);
    }
    spinner.setModel(new SpinnerListModel(characters));
}
Also used : ArrayList(java.util.ArrayList) SpinnerListModel(javax.swing.SpinnerListModel)

Aggregations

SpinnerListModel (javax.swing.SpinnerListModel)2 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JSpinner (javax.swing.JSpinner)1