Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

StyledCellEditor.java

Go to the documentation of this file.
00001 /*
00002  * StyledCellEditor.java
00003  *
00004  * Copyright (C) 2005 Project SQUID, http://www.cs.helsinki.fi/group/squid/
00005  *
00006  * This file is part of Ikayaki.
00007  *
00008  * Ikayaki is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Ikayaki is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Ikayaki; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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         // get the component as made by the default editor
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         // apply custom style to the component
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         // get the component as made by the default editor
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         // apply custom style to the component
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 }

Generated on Fri May 6 16:00:32 2005 for Squid by  doxygen 1.4.1