⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmradiobuttoncelleditor.java

📁 梦界家园程序开发基底框架
💻 JAVA
字号:
package jm.framework.gui.module.editer ;

import java.awt.Color;
import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.table.TableCellEditor;
import javax.swing.tree.TreeCellEditor;

import jm.framework.gui.module.JMItemCode;
import jm.framework.gui.module.JMRadioButton;
import jm.util.JMVList;
import jm.util.JMUtility;
import jm.util.JMVal;

public class JMRadioButtonCellEditor
    extends AbstractCellEditor implements TableCellEditor , TreeCellEditor
{
    /**
	 *
	 */
	private static final long serialVersionUID = -36457805505151383L;
	public static final String CLASS_NAME = "JMRadioButtonCellEditor" ;
    JPanel bkg = new JPanel () ;
    private JMRadioButton checkbox = null ;
    private JMVList oval = null ;
    private boolean bshowtex = false ;
    private Color oselBackColor = null ;
    //private boolean click = false;

    /**
     * CheckBoxCellEditor
     * @param val JMVList val[0]:uncheck,val[1]:check
     * @param selBackColor Color
     * @param showtext boolean
     */
    public JMRadioButtonCellEditor ( JMVList val , Color selBackColor , boolean showtext )
    {
        super () ;
        try
        {
            checkbox = new JMRadioButton () ;
            checkbox.setOpaque ( true ) ;
            bshowtex = showtext ;
            oval = val ;
            oselBackColor = selBackColor ;

            jbInit () ;
        }
        catch ( Exception ex )
        {
            ex.printStackTrace () ;
        }
    }

    public JMRadioButton getCellJMCheckBox ()
    {
        return checkbox ;
    }

    public Component getTableCellEditorComponent (
        JTable table ,
        Object value ,
        boolean isSelected ,
        int row , int column )
    {
        try
        {
            JMVal cellval = (JMVal)value;

            if ( bshowtex ) checkbox.setText ( ""+cellval ) ;
            if (cellval.equals((oval.get(0))))
            {
                checkbox.setSelected ( false ) ;
            }
            else
            {
                checkbox.setSelected ( true ) ;
            }
            getCellEditorValue ();
            return bkg ;
        }
        catch ( Exception e )
        {
            return null ;
        }
    }

    /**
     * 僄僨傿僞偺乽弶婜抣乿傪愝掕偟傑偡丅偙傟偵傛傝僄僨傿僞偱 stopEditing 偑屇傃弌偝傟丄偦偺偲偒偵僄僨傿僞偑曇廤拞偺応崌偼丄曇廤偝傟偨抣偑堦晹徚幐偡傞偙偲偑偁傝傑偡丅
     * 僋儔僀傾儞僩偺 Component 奒憌偵捛壛偡傞昁梫偺偁傞僐儞億乕僱儞僩傪曉偟傑偡丅偙偺僐儞億乕僱儞僩偑僋儔僀傾儞僩偺奒憌偵慻傒崬傑傟傞偲丄儐乕僓擖椡傪昤夋偍傛傃庴怣偱偒傑偡丅
     * @param tree JTree 僄僨傿僞偵曇廤傪梫媮偟偰偄傞 JTree丅偙偺僷儔儊乕僞偼 null 傕壜
     * @param value Object 曇廤偝傟傞僙儖抣
     * @param isSelected boolean 僙儖偑儗儞僟儕儞僌偲側傝慖戰晹偑僴僀儔僀僩偝傟偰偄傞応崌偼 true
     * @param expanded boolean 僲乕僪偑揥奐偝傟偰偄傞応崌偼 true
     * @param leaf boolean 僲乕僪偑梩僲乕僪偺応崌偼 true
     * @param row int 曇廤拞偺僲乕僪偺峴僀儞僨僢僋僗
     * @return Component 曇廤偺偨傔偺僐儞億乕僱儞僩
     */
    public Component getTreeCellEditorComponent ( JTree tree ,
                                                  Object value ,
                                                  boolean isSelected ,
                                                  boolean expanded ,
                                                  boolean leaf ,
                                                  int row )
    {
        JMVal cellval = (JMVal)value;
        if ( bshowtex ) checkbox.setText ( "" + value ) ;
        if (cellval.equals((oval.get(0))))
        {
            checkbox.setSelected ( false ) ;
        }
        else
        {
            checkbox.setSelected ( true ) ;
        }
        getCellEditorValue ();
        return bkg ;
    }

    /**
     * Returns the value contained in the editor.
     *
     * @return the value contained in the editor
     * @todo Implement this javax.swing.CellEditor method
     */
    public Object getCellEditorValue ()
    {
        if ( oval != null && oval.size () == 2 )
        {
            if ( checkbox.isSelected () )
            {
                return oval.get ( 1 ) ;
            }
            return oval.get ( 0 ) ;
        }
        return new JMVal(JMUtility.changNvl( "" + checkbox.getText () )) ;
    }

    private void jbInit ()
        throws Exception
    {
        if ( oselBackColor != null )
        {
            checkbox.setBackground ( oselBackColor ) ;
            bkg.setBackground ( oselBackColor ) ;
        }

        checkbox.addActionListener ( new java.awt.event.ActionListener ()
        {
            public void actionPerformed ( java.awt.event.ActionEvent e )
            {
//                click = true;
                checkbox.setFont ( JMItemCode.FT_TABLE_SELECT ) ;
                if ( bshowtex ) checkbox.setText ( "" + getCellEditorValue () ) ;
            }
        } ) ;
        bkg.add ( checkbox ) ;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -