2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
2008-02-28 20:16:52 -05:00
|
|
|
import java.util.Collection;
|
2007-12-23 14:28:04 -05:00
|
|
|
|
2008-04-20 12:03:19 -04:00
|
|
|
import javax.swing.AbstractAction;
|
2007-12-23 14:28:04 -05:00
|
|
|
import javax.swing.BorderFactory;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JTextField;
|
2008-04-20 12:03:19 -04:00
|
|
|
import javax.swing.KeyStroke;
|
2007-12-23 14:28:04 -05:00
|
|
|
import javax.swing.border.Border;
|
|
|
|
|
2008-02-28 20:16:52 -05:00
|
|
|
import net.sourceforge.tuned.ui.SelectButton.Entry;
|
|
|
|
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
public class TextFieldWithSelect<T> extends JPanel {
|
|
|
|
|
|
|
|
private SelectButton<T> selectButton;
|
|
|
|
|
|
|
|
private JTextField textfield = new JTextField();
|
2008-03-24 11:41:10 -04:00
|
|
|
private Color borderColor = new Color(0xA4A4A4);
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
|
2008-02-28 20:16:52 -05:00
|
|
|
public TextFieldWithSelect(Collection<Entry<T>> options) {
|
2007-12-23 14:28:04 -05:00
|
|
|
setLayout(new BorderLayout(0, 0));
|
|
|
|
|
2008-02-28 20:16:52 -05:00
|
|
|
selectButton = new SelectButton<T>(options);
|
2007-12-23 14:28:04 -05:00
|
|
|
selectButton.addActionListener(textFieldFocusOnClick);
|
|
|
|
|
|
|
|
Border lineBorder = BorderFactory.createLineBorder(borderColor, 1);
|
|
|
|
Border matteBorder = BorderFactory.createMatteBorder(1, 0, 1, 1, borderColor);
|
|
|
|
Border emptyBorder = BorderFactory.createEmptyBorder(0, 3, 0, 3);
|
|
|
|
|
|
|
|
selectButton.setBorder(lineBorder);
|
|
|
|
textfield.setBorder(BorderFactory.createCompoundBorder(matteBorder, emptyBorder));
|
|
|
|
|
|
|
|
textfield.setColumns(20);
|
|
|
|
add(textfield, BorderLayout.CENTER);
|
|
|
|
add(selectButton, BorderLayout.WEST);
|
2008-04-20 12:03:19 -04:00
|
|
|
|
|
|
|
TunedUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("shift UP"), new SpinClientAction(-1));
|
|
|
|
TunedUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("shift DOWN"), new SpinClientAction(1));
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public JTextField getTextField() {
|
|
|
|
return textfield;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SelectButton<T> getSelectButton() {
|
|
|
|
return selectButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public T getSelectedValue() {
|
2008-02-28 20:16:52 -05:00
|
|
|
return selectButton.getSelectedEntry();
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void clearTextSelection() {
|
|
|
|
int length = textfield.getText().length();
|
|
|
|
textfield.select(length, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final ActionListener textFieldFocusOnClick = new ActionListener() {
|
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
textfield.requestFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-04-20 12:03:19 -04:00
|
|
|
|
|
|
|
private class SpinClientAction extends AbstractAction {
|
|
|
|
|
|
|
|
private int spin;
|
|
|
|
|
|
|
|
|
|
|
|
public SpinClientAction(int spin) {
|
|
|
|
this.spin = spin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
selectButton.spinValue(spin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|