public class StyledComboBoxEditor extends JTextPane implements ComboBoxEditor {
public List<ActionListener> listeners = new ArrayList<ActionListener>();
public DefaultStyledDocument defaultStyledDocument;
public static Style STYLE_DEFAULT = null;
public static Style STYLE_GRAY = null;
public StyledComboBoxEditor() {
this.setDocument(this.getStyledDocument());
this.setBorder(UIManager.getBorder("ComboBox.editorBorder"));
StyledComboBoxEditor.STYLE_DEFAULT = this.getStyledDocument().addStyle("DEFAULT", null);
StyledComboBoxEditor.STYLE_GRAY = this.getStyledDocument().addStyle("GRAY", null);
StyleConstants.setForeground(StyledComboBoxEditor.STYLE_GRAY, Color.GRAY);
}
public DefaultStyledDocument getStyledDocument() {
if (this.defaultStyledDocument == null) {
this.defaultStyledDocument = new DefaultStyledDocument() {
public void insertString(int offset, String s, AttributeSet attributeSet) throws BadLocationException {
if (s.equals("\n") || s.equals("\r") || s.equals("\r\n")) {
return;
}
if (s.equals("\t")) {
transferFocus();
return;
}
super.insertString(offset, s, attributeSet);
}
};
}
return this.defaultStyledDocument;
}
public void addActionListener(ActionListener l) {
this.listeners.add(l);
}
public void removeActionListener(ActionListener l) {
this.listeners.remove(l);
}
public Component getEditorComponent() {
return this;
}
public Object getItem() {
return this.getText();
}
public void selectAll() {
super.selectAll();
this.requestFocus();
}
public void setItem(Object anObject) {
if (anObject == null) {
this.setText("");
return;
}
this.setText(anObject.toString());
}
}