Package org.geoforge.guillc.button

Source Code of org.geoforge.guillc.button.BtnChoiceColorAbs

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  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 Lesser General Public License for more details.
*
*  You should have received a copy of the GNU Lesser General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.geoforge.guillc.button;

//import dummy.GfrColorChooser;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JColorChooser;


/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/

abstract public class BtnChoiceColorAbs extends BtnAbs implements
  ActionListener
{

    final static private String _STR_TIP = "Click to change color selection";
   
    public Color getChoice() { return super.getBackground(); }


    protected BtnChoiceColorAbs(
                    ActionListener[] alrs,
                    Color col,
                    int intW,
                    int intH)
    {
        super();
       
        // override superclass
        super.setContentAreaFilled(true);

        if (alrs != null)
        {
            for (int i=0; i<alrs.length; i++)
            {
              if (alrs[i] == null)
                      continue;

              super.addActionListener(alrs[i]);
            }
        }

        super.setToolTipText(BtnChoiceColorAbs._STR_TIP);

        super.setBackground(col);


        Dimension dim = new Dimension(intW, intH);
        this.setSize(dim.width, dim.height);
        this.setMinimumSize(dim);
        this.setMaximumSize(dim);
        this.setPreferredSize(dim);
    }

    static private Component _s_getTopParent_(Component cmpChild)
    {
        Component cmpCur = cmpChild.getParent();

        if (cmpCur == null)
        {
            if (cmpChild instanceof JButton)
                return null;
           
            return cmpChild;
        }

        return BtnChoiceColorAbs._s_getTopParent_(cmpCur);
    }

    @Override
    public void actionPerformed(ActionEvent arg0)
    {
        Component cmpRoot = BtnChoiceColorAbs._s_getTopParent_(this);

        JColorChooser chooser = new JColorChooser();
       
        Color col = chooser.showDialog(
            cmpRoot, "Choose color", getBackground());

        if (col != null)
            setBackground(col);

    }

    @Override
    public void destroy()
    {
        super.destroy();
    }

    @Override
    public boolean init()
    {
        if (! super.init())
            return false;
       
        super.addActionListener(this);
       
  return true;
    }

    @Override
    public void mouseExited(MouseEvent evtMouse) // overwrite superclass's method
    {
        setBorderPainted(false);
    }
   
    @Override
    public void setEnabled(boolean bln)
    {
       super.setEnabled(bln);
    }
}
TOP

Related Classes of org.geoforge.guillc.button.BtnChoiceColorAbs

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.