Package org.geoforge.guillc.panel

Source Code of org.geoforge.guillc.panel.PnlTreeCellRendererAbs

/*
*  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.panel;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.TreeCellRenderer;
import org.geoforge.java.awt.color.GfrColor;
import org.geoforge.guillc.label.LblNode;
import org.geoforge.guillc.treenode.GfrNodAbs;
import org.geoforge.guillc.treenode.GfrNodCtrFixFolderTopAbs;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
abstract public class PnlTreeCellRendererAbs extends JPanel implements
        TreeCellRenderer,
        IGfrHandlerLifeCycleObject
{
    final static private Font _FNT_TOP_ = new Font(
            Font.DIALOG, // "Default",
            Font.BOLD, 12);
   
    final static private Font _FNT_OTHER_ = new Font(
            Font.DIALOG, // "Default",
            Font.PLAIN, 12);
   
    protected LblNode _lbl = null;

    protected PnlTreeCellRendererAbs()
    {
        super();
       
        this._lbl = new LblNode();

    }

    @Override
    public void setBackground(Color color)
    {
        //if (color instanceof ColorUIResource)
          //  color = null;
       
        super.setBackground(color);
    }

    @Override
    public boolean init() {

        this.add(this._lbl);
       
        return true;
    }

    @Override
    public void destroy() {
    }
   
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value,
            boolean isSelected, boolean expanded, boolean leaf, int row,
            boolean hasFocus)
    {
        if (isSelected)
            super.setBackground(GfrColor.DARK_BLUE);
        else
            super.setBackground(GfrColor.white);
      
       
        String strValue = tree.convertValueToText(value, isSelected,
                expanded, leaf, row, hasFocus);
       
        setEnabled(tree.isEnabled());

     
        GfrNodAbs nod = (GfrNodAbs) value;
        ImageIcon iinCandidate = nod.getImageIcon();

        // managing style
        this._lbl.setSelected(isSelected);
       
        //this._lbl.setFont(tree.getFont());
        if ((nod instanceof GfrNodCtrFixFolderTopAbs))
            this._lbl.setFont(PnlTreeCellRendererAbs._FNT_TOP_);
        else
            this._lbl.setFont(PnlTreeCellRendererAbs._FNT_OTHER_);
       
       
        this._lbl.setText(
                //"<html><head></head><body>" +
                strValue
                //+ "</body></html>"
                );
       

        // managing icons
        if (leaf)
        {
          
            if (iinCandidate != null)
                this._lbl.setIcon(iinCandidate);
            else
                this._lbl.setIcon(UIManager.getIcon("Tree.leafIcon"));
        }
       
        else // folder
        {
         
            if (iinCandidate != null)
                this._lbl.setIcon(iinCandidate);
            else
                if (expanded)
                    this._lbl.setIcon(UIManager.getIcon("Tree.openIcon"));
                else
                    this._lbl.setIcon(UIManager.getIcon("Tree.closedIcon"));
        }

        return this;
    }

     @Override
    public void paint(Graphics g)
    {  
        super.paint(g);
    }

}
TOP

Related Classes of org.geoforge.guillc.panel.PnlTreeCellRendererAbs

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.