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();
}
});
}
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;
}
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;
}
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);
}
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;
}
Aggregations