Package org.onemind.swingweb.templaterender.peerdelegate.javax.swing

Source Code of org.onemind.swingweb.templaterender.peerdelegate.javax.swing.JTreeRenderDelegate

/*
* Copyright (C) 2004 TiongHiang Lee
*
* This library 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 2.1 of the License, or (at your option) any later version.
*
* This library 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 library; if not,  write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* Email: thlee@onemindsoft.org
*/

package org.onemind.swingweb.templaterender.peerdelegate.javax.swing;

import java.awt.Component;
import javax.swing.JTree;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.onemind.awtbridge.peer.BridgePeer;
import org.onemind.awtbridge.render.BridgeRenderContext;
import org.onemind.awtbridge.render.RenderingException;
import org.onemind.swingweb.templaterender.peerdelegate.TemplateRenderDelegate;
/**
* The JTable render delegate
* @author TiongHiang Lee (thlee@onemindsoft.org)
*
*/
public class JTreeRenderDelegate extends JComponentRenderDelegate
{
    /** the instance **/
    public static TemplateRenderDelegate INSTANCE = new JTreeRenderDelegate();
    /**
     * Constructor
     */
    public JTreeRenderDelegate()
    {
        super();
    }

    /**
     * Render the cell
     * @param peer the peer
     * @param context the context
     * @param output the output object
     * @param row the row
     * @param col the column
     * @throws RenderingException if there's rendering problem
     */
    public void renderNode(BridgePeer peer, BridgeRenderContext context,
            Object output, TreePath path, String treePath) throws RenderingException
    {
        JTree tree = (JTree) peer.getComponentObject();
        TreeModel model = tree.getModel();  
        Component com = null;
        Object value = path.getLastPathComponent();
               
        boolean enableFlag = true;
        boolean edit = tree.isEditable();
        if (edit)
        {
            com = (Component)tree.getCellEditor().getTreeCellEditorComponent(tree, value, true, true, model.isLeaf(value), 0);           
        } else
        {
            com = (Component)tree.getCellRenderer().getTreeCellRendererComponent(tree, value, true, true, model.isLeaf(value), 0, true);           
        }
        BridgePeer childPeer = context.getContext().getPeer(com);
        if (childPeer == null)
        {
            tree.add(com);
            com.addNotify();
            childPeer = context.getContext().getPeer(com);
        }
        //setting the size?
       
        // masquerade the peer id
        if (edit)
        {
            String origId = childPeer.getId();
            String newId = peer.getId() + "_" + treePath;
            childPeer.setId(newId); //fake it
            try
            {
                context.renderOutput(com, output);
            } finally
            {
                childPeer.setId(origId); //set it back               
            }
        } else
        { //just render
            try
            {
                context.renderOutput(com, output);
            } finally
            {
                com.setEnabled(enableFlag);
            }
        }
    }
}
TOP

Related Classes of org.onemind.swingweb.templaterender.peerdelegate.javax.swing.JTreeRenderDelegate

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.