📄 foldertemplateskin.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.List;
import java.util.Map;
import org.apache.log4j.Logger;
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 FolderTemplateSkin extends AbstractSkin {
private static Logger LOG = Logger.getLogger(FolderTemplateSkin.class);
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();
List m_depthVector = p_nodeInfo.getDepthVector();
String a_images = a_comp.getImgsPath();
int a_startAtDepth = a_comp.getStartAtDepth();
String a_imagePath = a_comp.getImgsPath();
if (a_treeNode.getDepth() < a_startAtDepth) {
p_nodeInfo.setOpened();
return;
}
if (p_nodeInfo.isLastChild()) {
m_depthVector.remove(new Integer(a_treeNode.getDepth()));
} else {
if (!m_depthVector.contains(new Integer(a_treeNode.getDepth()))) {
m_depthVector.add(new Integer(a_treeNode.getDepth()));
}
}
a_writer.println("<table cellspacing=0 cellpadding=0 border=0><tr>");
for (int i = a_startAtDepth; i < a_treeNode.getDepth(); i++) {
if (i > a_startAtDepth)
a_writer.println("<td " + "width=\"16\"><img src=\"" + a_images + "pixel.gif\" border=\"0\" alt=\"\" width=\"16\" height=\"1\"></td>");
if (m_depthVector.contains(new Integer(i))) {
a_writer.println("<td " + "width=\"9\" background=\"" + a_images + "vertical-sign.gif\"><img src=\"" + a_images + "pixel.gif\" border=\"0\" alt=\"\" width=\"9\" height=\"1\"></td>");
} else {
a_writer.println("<td " + "width=\"9\"><img src=\"" + a_images + "pixel.gif\" border=\"0\" alt=\"\" width=\"9\" height=\"1\"></td>");
}
}
if (a_treeNode.getDepth() > a_startAtDepth) {
a_writer.println("<td " + "width=\"16\"><img src=\"" + a_images + "pixel.gif\" border=\"0\" alt=\"\" width=\"16\" height=\"1\"></td>");
}
NodeTemplate a_node = null;
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 NodeTemplate selectNodeTemplate(NodeInfo p_nodeInfo, JSPTreeComponent p_comp) {
TreeNode treeNode = p_nodeInfo.getNode();
boolean a_lastChild = p_nodeInfo.isLastChild();
if (treeNode.hasChildren()) {
if (p_nodeInfo.isOpened()) {
if (p_nodeInfo.isSelected()) {
if (a_lastChild) {
return p_comp.getTemplate(NodeTemplateImpl.OPENED_SELECTED_NODE_LAST_CHILD);
} else {
return p_comp.getTemplate(NodeTemplateImpl.OPENED_SELECTED_NODE);
}
} else {
if (a_lastChild) {
return p_comp.getTemplate(NodeTemplateImpl.OPENED_NODE_LAST_CHILD);
} else {
return p_comp.getTemplate(NodeTemplateImpl.OPENED_NODE);
}
}
} else {
if (p_nodeInfo.isSelected()) {
if (a_lastChild) {
return p_comp.getTemplate(NodeTemplateImpl.CLOSED_SELECTED_NODE_LAST_CHILD);
} else {
return p_comp.getTemplate(NodeTemplateImpl.CLOSED_SELECTED_NODE);
}
} else {
if (a_lastChild) {
return p_comp.getTemplate(NodeTemplateImpl.CLOSED_NODE_LAST_CHILD);
} else {
return p_comp.getTemplate(NodeTemplateImpl.CLOSED_NODE);
}
}
}
} else {
if (p_nodeInfo.isSelected()) {
if (a_lastChild) {
return p_comp.getTemplate(NodeTemplateImpl.LEAF_SELECTED_LAST_CHILD);
} else {
return p_comp.getTemplate(NodeTemplateImpl.LEAF_SELECTED);
}
} else {
if (a_lastChild) {
return p_comp.getTemplate(NodeTemplateImpl.LEAF_LAST_CHILD);
} else {
return p_comp.getTemplate(NodeTemplateImpl.LEAF);
}
}
}
}
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());
}
public String getType() {
return FOLDER_SKIN;
}
public String[] getTemplateNames() {
return NodeTemplateImpl.FOLDER_TEMPLATES;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -