00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package ikayaki.gui;
00024
00025 import javax.swing.*;
00026 import java.awt.*;
00027
00034 public class StyledCellEditor extends DefaultCellEditor {
00035
00041 public StyledCellEditor(final JTextField textField) {
00042 super(textField);
00043 }
00044
00050 public StyledCellEditor(final JCheckBox checkBox) {
00051 super(checkBox);
00052 }
00053
00059 public StyledCellEditor(final JComboBox comboBox) {
00060 super(comboBox);
00061 }
00062
00066 @Override public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected,
00067 boolean expanded, boolean leaf, int row) {
00068
00069 if (!(value instanceof StyledWrapper)) {
00070 return super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
00071 }
00072 StyledWrapper wrapper = (StyledWrapper) value;
00073 Component comp = super.getTreeCellEditorComponent(tree, wrapper.value, isSelected, expanded, leaf, row);
00074
00075
00076 if (comp instanceof JTextField) {
00077 JTextField textField = (JTextField) comp;
00078 textField.setHorizontalAlignment(wrapper.horizontalAlignment);
00079 if (wrapper.foreground != null) textField.setForeground(wrapper.foreground);
00080 if (wrapper.font != null) textField.setFont(wrapper.font);
00081
00082 } else if (comp instanceof JCheckBox) {
00083 JCheckBox checkBox = (JCheckBox) comp;
00084 checkBox.setHorizontalAlignment(wrapper.horizontalAlignment);
00085 if (wrapper.foreground != null) checkBox.setForeground(wrapper.foreground);
00086 if (wrapper.font != null) checkBox.setFont(wrapper.font);
00087
00088 } else if (comp instanceof JComboBox) {
00089 JComboBox comboBox = (JComboBox) comp;
00090 if (wrapper.foreground != null) comboBox.setForeground(wrapper.foreground);
00091 if (wrapper.font != null) comboBox.setFont(wrapper.font);
00092 }
00093 return comp;
00094 }
00095
00099 @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
00100 int column) {
00101
00102 if (!(value instanceof StyledWrapper)) {
00103 return super.getTableCellEditorComponent(table, value, isSelected, row, column);
00104 }
00105 StyledWrapper wrapper = (StyledWrapper) value;
00106 Component comp = super.getTableCellEditorComponent(table, wrapper.value, isSelected, row, column);
00107
00108
00109 if (comp instanceof JTextField) {
00110 JTextField textField = (JTextField) comp;
00111 textField.setHorizontalAlignment(wrapper.horizontalAlignment);
00112 if (wrapper.foreground != null) textField.setForeground(wrapper.foreground);
00113 if (wrapper.font != null) textField.setFont(wrapper.font);
00114
00115 } else if (comp instanceof JCheckBox) {
00116 JCheckBox checkBox = (JCheckBox) comp;
00117 checkBox.setHorizontalAlignment(wrapper.horizontalAlignment);
00118 if (wrapper.foreground != null) checkBox.setForeground(wrapper.foreground);
00119 if (wrapper.font != null) checkBox.setFont(wrapper.font);
00120
00121 } else if (comp instanceof JComboBox) {
00122 JComboBox comboBox = (JComboBox) comp;
00123 if (wrapper.foreground != null) comboBox.setForeground(wrapper.foreground);
00124 if (wrapper.font != null) comboBox.setFont(wrapper.font);
00125 }
00126 return comp;
00127 }
00128 }