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

📄 menutemplateskin.java

📁 jsp + xml实现treeview
💻 JAVA
字号:
/*
 * ====================================================================
 * The JSP Tree Software License, Version 1.1
 *
 * (this license is derived and fully compatible with the Apache Software
 * License - see http://www.apache.org/LICENSE.txt)
 *
 * Copyright (c) 2002-2005 jsptree.sourceforge.net . All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by
 *        jsptree.sourceforge.net (http://jsptree.sourceforge.net/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The name "JSP Tree" must not be used to endorse or promote
 *    products derived from this software without prior written permission.
 *    For written permission, please contact modano@users.sourceforge.net .
 *
 * 5. Products derived from this software may not be called "JSP Tree",
 *    nor may "JSP Tree" appear in their name, without prior written
 *    permission of jsptree.sourceforge.net.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 */

package net.sf.jsptree.skin;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import net.sf.jsptree.WebWriter;
import net.sf.jsptree.component.JSPTreeComponent;
import net.sf.jsptree.component.JSPTreeNode;
import net.sf.jsptree.template.NodeTemplate;
import net.sf.jsptree.template.NodeTemplateImpl;
import net.sf.jsptree.tree.TreeNode;

/**
 * @author Vladislav Kamensky
 */
public class MenuTemplateSkin extends AbstractSkin {

    public void paint(NodeInfo p_nodeInfo) throws IOException {

        WebWriter a_writer = p_nodeInfo.getWebWriter();

        TreeNode a_treeNode = p_nodeInfo.getNode();

        JSPTreeComponent a_comp = p_nodeInfo.getComponent();

        int a_startAtDepth = a_comp.getStartAtDepth();
        String a_imagePath = a_comp.getImgsPath();

        if (a_treeNode.getDepth() < a_startAtDepth) {
            p_nodeInfo.setOpened();
            return;
        }

        a_writer.println("<table cellspacing=0 cellpadding=0 border=0><tr>");

        NodeTemplate a_shift1 = selectLeftShiftTemplate(p_nodeInfo, a_comp);

        for (int i = a_startAtDepth; i < a_treeNode.getDepth(); i++) {
            a_writer.println(a_shift1.getHTML("${imagePath}", a_imagePath));
        }

        NodeTemplate a_node = selectNodeTemplate(p_nodeInfo, a_comp);

        Map a_tags = new HashMap();

        if (a_treeNode.hasChildren()) {
            a_tags.put("${href}", getStateManagerURL(p_nodeInfo));
        }

        a_tags.put("${imagePath}", a_imagePath);
        a_tags.put("${label_href}", getHref(p_nodeInfo));
        a_tags.put("${node_label}", ((JSPTreeNode) a_treeNode.getData()).getLabel());

        addTags(((JSPTreeNode) a_treeNode.getData()).getValues(), a_tags);

        a_writer.print(a_node.getHTML(a_tags));

        a_writer.println("</tr>");
        a_writer.println("</table>");
        a_writer.flush();
    }

    protected String getHref(NodeInfo p_nodeInfo) throws IOException {
        TreeNode treeNode = p_nodeInfo.getNode();
        JSPTreeComponent comp = p_nodeInfo.getComponent();
        StringBuffer a_href = new StringBuffer(super.getHref(p_nodeInfo));
        if (((JSPTreeNode) treeNode.getData()).isContextRelative()) {
            a_href.append("sNode-");
            a_href.append(comp.getName());
            a_href.append("=");
            a_href.append(((JSPTreeNode) treeNode.getData()).getId());
        }
        return comp.encodeRedirectURL(a_href.toString());
    }

    protected NodeTemplate selectNodeTemplate(NodeInfo p_nodeInfo, JSPTreeComponent p_comp) {
        TreeNode treeNode = p_nodeInfo.getNode();
        if (treeNode.hasChildren()) {
            if (p_nodeInfo.isOpened()) {
                if (p_nodeInfo.isSelected()) {
                    return p_comp.getTemplate(NodeTemplateImpl.OPENED_SELECTED_NODE);
                } else {
                    return p_comp.getTemplate(NodeTemplateImpl.OPENED_NODE);
                }
            } else {
                if (p_nodeInfo.isSelected()) {
                    return p_comp.getTemplate(NodeTemplateImpl.CLOSED_SELECTED_NODE);
                } else {
                    return p_comp.getTemplate(NodeTemplateImpl.CLOSED_NODE);
                }
            }
        } else {
            if (p_nodeInfo.isSelected()) {
                return p_comp.getTemplate(NodeTemplateImpl.LEAF_SELECTED);
            } else {
                return p_comp.getTemplate(NodeTemplateImpl.LEAF);
            }
        }
    }

    protected NodeTemplate selectLeftShiftTemplate(NodeInfo p_nodeInfo, JSPTreeComponent p_comp) {
        return p_comp.getTemplate(NodeTemplateImpl.LEFT_SHIFT);
    }

    public String getType() {
        return MENU_SKIN;
    }

    public String[] getTemplateNames() {
        return NodeTemplateImpl.MENU_TEMPLATES;
    }

}

⌨️ 快捷键说明

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