All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jaxx.runtime.swing.editor.BooleanCellEditor Maven / Gradle / Ivy

There is a newer version: 3.0-alpha-6
Show newest version
/*
 * #%L
 * JAXX :: Runtime
 * %%
 * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * .
 * #L%
 */
package jaxx.runtime.swing.editor;

import java.awt.Component;
import javax.swing.AbstractCellEditor;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import org.jdesktop.swingx.JXTable;

/**
 * @author Tony Chemit - [email protected]
 * @since 1.5
 */
public class BooleanCellEditor extends AbstractCellEditor implements TableCellRenderer, TableCellEditor {

    private static final long serialVersionUID = 1L;

    protected TableCellRenderer rendererDelegate;
    protected TableCellEditor editorDelegate;

    protected Icon icon;

    public BooleanCellEditor(TableCellRenderer delegate) {
        this(delegate, null);
    }

    public BooleanCellEditor(TableCellRenderer delegate, Icon icon) {
        this.rendererDelegate = delegate;
        this.editorDelegate = new JXTable.BooleanEditor();
        this.icon = icon;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        JComponent rendered = (JComponent) rendererDelegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (rendered instanceof JCheckBox) {
            JCheckBox checkBox = (JCheckBox)rendered;
            checkBox.setHorizontalAlignment(JLabel.CENTER);
            checkBox.setVerticalTextPosition(JLabel.TOP);
            checkBox.setBorderPainted(true);
            checkBox.setIcon(icon);
        }
        return rendered;
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        return editorDelegate.getTableCellEditorComponent(table, value, isSelected, row, column);
    }

    @Override
    public Object getCellEditorValue() {
        return editorDelegate.getCellEditorValue();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy