Search in sources :

Example 76 with FocusEvent

use of java.awt.event.FocusEvent in project knime-core by knime.

the class DefaultAlphaColorPanel method buildChooser.

/**
 * {@inheritDoc}
 */
@Override
protected void buildChooser() {
    super.setLayout(new BorderLayout());
    m_slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 255);
    m_slider.setMajorTickSpacing(85);
    m_slider.setMinorTickSpacing(17);
    m_slider.setPaintTicks(true);
    m_slider.setPaintLabels(true);
    m_spinner = new JSpinner(new SpinnerNumberModel(255, 0, 255, 5));
    JPanel spinnerPanel = new JPanel(new FlowLayout());
    spinnerPanel.add(m_spinner);
    super.add(new JLabel("Alpha "), BorderLayout.WEST);
    super.add(m_slider, BorderLayout.CENTER);
    super.add(spinnerPanel, BorderLayout.EAST);
    super.add(new JLabel("\n(Alpha composition is " + "expensive in cases when operations performed are not " + "hardware-accelerated.)"), BorderLayout.SOUTH);
    m_slider.addChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            setAlpha(m_slider.getValue());
        }
    });
    m_spinner.addChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            try {
                m_spinner.commitEdit();
                setAlpha((Integer) m_spinner.getValue());
            } catch (ParseException pe) {
                setAlpha(255);
            }
        }
    });
    m_slider.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(final FocusEvent fe) {
            getAlpha();
        }
    });
    m_spinner.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(final FocusEvent fe) {
            getAlpha();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) FocusAdapter(java.awt.event.FocusAdapter) FlowLayout(java.awt.FlowLayout) JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BorderLayout(java.awt.BorderLayout) ChangeEvent(javax.swing.event.ChangeEvent) JSlider(javax.swing.JSlider) JSpinner(javax.swing.JSpinner) ChangeListener(javax.swing.event.ChangeListener) ParseException(java.text.ParseException)

Example 77 with FocusEvent

use of java.awt.event.FocusEvent in project knime-core by knime.

the class LimitRowsPanel method getSkipPanel.

private Container getSkipPanel() {
    m_skipLines = new JCheckBox("Skip the first");
    m_skipNumber = new JTextField();
    m_skipNumber.setColumns(6);
    m_skipNumber.setPreferredSize(new Dimension(125, 25));
    m_skipNumber.setMaximumSize(new Dimension(125, 25));
    m_skipLines.setSelected(false);
    m_skipNumber.setEnabled(false);
    // make sure we always have a valid value. Reject invalid characters.
    m_skipNumber.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(final DocumentEvent e) {
            checkAndFixSkipCount();
        }

        @Override
        public void insertUpdate(final DocumentEvent e) {
            checkAndFixSkipCount();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            checkAndFixSkipCount();
        }
    });
    m_skipNumber.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(final FocusEvent e) {
            if (m_skipNumber.getText().trim().length() == 0) {
                // can't handle no empty strings.
                m_lastValidSkips = "0";
                m_skipNumber.setText(m_lastValidSkips);
            }
        }

        @Override
        public void focusGained(final FocusEvent e) {
        }
    });
    m_skipLines.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            // en/disable the textfield
            m_skipNumber.setEnabled(m_skipLines.isSelected());
            // also - if the textfield is enabled and empty set a value
            if (m_skipNumber.isEnabled()) {
                if ((m_skipNumber.getText() == null) || (m_skipNumber.getText().trim().length() == 0)) {
                    // set a valid value, so we can safely assume that if there is a value in there it's always valid.
                    m_skipNumber.setText("0");
                    m_lastValidSkips = "0";
                }
            }
        }
    });
    Box result = Box.createHorizontalBox();
    result.add(m_skipLines);
    result.add(Box.createHorizontalStrut(3));
    result.add(m_skipNumber);
    result.add(Box.createHorizontalStrut(3));
    result.add(new JLabel("lines from the beginning of the file."));
    result.add(Box.createHorizontalGlue());
    return result;
}
Also used : JCheckBox(javax.swing.JCheckBox) DocumentListener(javax.swing.event.DocumentListener) ChangeEvent(javax.swing.event.ChangeEvent) JLabel(javax.swing.JLabel) ChangeListener(javax.swing.event.ChangeListener) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 78 with FocusEvent

use of java.awt.event.FocusEvent in project knime-core by knime.

the class FixedWidthFRNodeDialog method createColPropertyPanel.

private JPanel createColPropertyPanel() {
    m_colTable = new JTable() {

        private final Color m_grey = new Color(125, 125, 125);

        // set font color according to included/excluded
        @Override
        public Component prepareRenderer(final TableCellRenderer renderer, final int row, final int column) {
            Component c = super.prepareRenderer(renderer, row, column);
            if (!(boolean) m_colPropModel.getValueAt(row, 4)) {
                c.setForeground(m_grey);
            } else {
                c.setForeground(Color.BLACK);
            }
            return c;
        }
    };
    m_colTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        // dis/enable remove button according to row selection
        @Override
        public void valueChanged(final ListSelectionEvent e) {
            updateEnables();
        }
    });
    m_colTable.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(final FocusEvent e) {
            // enable edit and remove button according to row selection
            m_colIdx = m_colTable.getSelectedRow();
            updateEnables();
        }

        @Override
        public void focusLost(final FocusEvent e) {
        // nothing
        }
    });
    updateColPropTable();
    JScrollPane st = new JScrollPane(m_colTable);
    st.setPreferredSize(new Dimension(getPanel().getPreferredSize().width, 150));
    m_edit = new JButton("Edit");
    m_edit.setToolTipText("Change settings of the selected column.");
    // add action listener
    m_edit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            onEdit(m_colTable.getSelectedRow());
        }
    });
    m_add = new JButton("Add");
    m_add.setToolTipText("Add a new column to the table.");
    // add action listener
    m_add.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            onAdd();
        }
    });
    m_remove = new JButton("Remove");
    m_remove.setToolTipText("Remove the selected column.");
    // add action listener
    m_remove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent event) {
            onRemove(m_colTable.getSelectedRows());
        }
    });
    JPanel listButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    listButtons.add(m_add);
    listButtons.add(m_edit);
    listButtons.add(m_remove);
    // group components nicely
    JPanel dlgPanel = new JPanel();
    dlgPanel.setLayout(new BoxLayout(dlgPanel, BoxLayout.Y_AXIS));
    dlgPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Column configuration"));
    dlgPanel.add(st);
    dlgPanel.add(listButtons);
    return dlgPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) TableCellRenderer(javax.swing.table.TableCellRenderer) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) BoxLayout(javax.swing.BoxLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) Component(java.awt.Component) FocusListener(java.awt.event.FocusListener)

Example 79 with FocusEvent

use of java.awt.event.FocusEvent in project n2a by frothga.

the class SettingsGeneral method addField.

public JPanel addField(final String key, String description, int width, String defaultValue) {
    JLabel label = new JLabel(description);
    String value = AppData.state.getOrDefault("General", key, defaultValue);
    final JTextField field = new JTextField(value, width);
    field.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            AppData.state.set("General", key, field.getText());
        }
    });
    field.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent e) {
            AppData.state.set("General", key, field.getText());
        }
    });
    return Lay.FL("H", label, field);
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent)

Example 80 with FocusEvent

use of java.awt.event.FocusEvent in project n2a by frothga.

the class Lay method tx.

public static JTextField tx(Object text, Object... args) {
    HintList hints = new HintList();
    for (Object arg : args) {
        if (arg instanceof String) {
            hints.addHints(parseHints((String) arg));
        }
    }
    final JTextField txt = new JTextField("" + text);
    if (hints.contains("selectall")) {
        txt.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(FocusEvent e) {
                txt.selectAll();
            }
        });
    }
    setHints(txt, hints);
    return txt;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusEvent (java.awt.event.FocusEvent)81 FocusListener (java.awt.event.FocusListener)38 FocusAdapter (java.awt.event.FocusAdapter)33 JLabel (javax.swing.JLabel)21 ActionEvent (java.awt.event.ActionEvent)18 ActionListener (java.awt.event.ActionListener)17 JPanel (javax.swing.JPanel)15 JTextField (javax.swing.JTextField)15 Dimension (java.awt.Dimension)14 JButton (javax.swing.JButton)10 KeyEvent (java.awt.event.KeyEvent)9 JCheckBox (javax.swing.JCheckBox)9 BoxLayout (javax.swing.BoxLayout)8 JComboBox (javax.swing.JComboBox)8 Border (javax.swing.border.Border)8 Component (java.awt.Component)7 GridBagConstraints (java.awt.GridBagConstraints)6 GridBagLayout (java.awt.GridBagLayout)6 Insets (java.awt.Insets)6 MouseEvent (java.awt.event.MouseEvent)6