Package clips.directory.editors.workTypes

Source Code of clips.directory.editors.workTypes.TableColorEditorWorkTypes

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package clips.directory.editors.workTypes;

import cli_fmw.main.MainWindow;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

/**
*
* @author lacoste
*/
public class TableColorEditorWorkTypes extends AbstractCellEditor
                         implements TableCellEditor,
                                    ActionListener {
    Color currentColor;
    JButton button;
    JColorChooser colorChooser;
    JDialog dialog;
    protected static final String EDIT = "edit";
    public TableColorEditorWorkTypes() {
        button = new JButton();
        button.setActionCommand(EDIT);
        button.addActionListener(this);
        button.setBorderPainted(false);
        
        colorChooser = new JColorChooser();
        dialog = JColorChooser.createDialog(MainWindow.mainWindow, "Выберите цвет", true, colorChooser, this, null);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if (EDIT.equals(e.getActionCommand())) {           
            button.setBackground(currentColor);
            colorChooser.setColor(currentColor);
            dialog.setVisible(true);
            fireEditingStopped();
        }
        else {
            currentColor = colorChooser.getColor();
        }
    }
    
    @Override
    public Object getCellEditorValue() {
        return currentColor;
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        currentColor = (Color)value;
        return button;
    }
}
TOP

Related Classes of clips.directory.editors.workTypes.TableColorEditorWorkTypes

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.