📄 treeview.jsp
字号:
<%@ page import="java.util.Vector,java.lang.StringBuffer;" %>
<%!
class NodeList{
Vector v;
int length=0;
public NodeList(){
v=new Vector();
}
public void add(Node node){
v.add(node);
length++;
}
public void add(String text){
add(new Node(text));
}
public Node item(int index){
return (Node)v.get(index);
}
}
class Node{
public String text;
public String href;
public String target="";
public String toolTip;
public NodeList childNodes;
public String imageUrl="";
public int length=0;
public Node(){
childNodes = new NodeList();
}
public Node(String text){
this(text,"");
}
public Node(String text,String href){
this(text,href,"");
}
public Node(String text,String href,String toolTip){
this();
this.text=text;
this.href=href;
this.toolTip=toolTip;
}
public void add(Node node){
childNodes.add(node);
length++;
}
public void add(String text){
add(new Node(text));
}
}
class TreeView{
private String folder="images";
private String color="navy";
private NodeList nodes;
private String target="";
public int length=0;
private StringBuffer buf;
public TreeView(){
nodes=new NodeList();
buf = new StringBuffer();
}
public void setImagesUrl(String url){
this.folder = url;
}
public void add(Node node){
nodes.add(node);
length++;
}
public void add(String text){
add(new Node(text));
}
public Node createNode(String text){
return (new Node(text));
}
public Node createNode(String text,String href,String toolTip){
return (new Node(text,href,toolTip));
}
private void print(String text){
buf.append(text);
}
public String getTree(){
print("<script>function toggle(id,p){var myChild = document.getElementById(id);if(myChild.style.display!='block'){myChild.style.display='block';document.getElementById(p).className='folderOpen';}else{myChild.style.display='none';document.getElementById(p).className='folder';}}</script>");
print("<style>ul.tree{display:none;margin-left:17px;}li.folder{list-style-image: url("+ folder +"/plus.gif);}li.folderOpen{list-style-image: url("+ folder +"/minus.gif);}li.file{list-style-image: url("+ folder +"/dot.gif);}a.treeview{color:"+ color +";font-family:verdana;font-size:8pt;}a.treeview:link {text-decoration:none;}a.treeview:visited{text-decoration:none;}a.treeview:hover {text-decoration:underline;}</style>");
loopThru(nodes,"0");
return buf.toString();
}
private void loopThru(NodeList nodeList, String parent){
boolean hasChild;
String style;
if(parent!="0"){
print("<ul class=tree id=\"N" + parent + "\">");
}else{
print("<ul id=\"N" + parent + "\">");
}
for (int i=0;i<nodeList.length;i++){
Node node = nodeList.item(i);
if(node.childNodes.length>0){
hasChild=true;
}else{
hasChild=false;
}
if(node.imageUrl==""){
style="";
}else{
style="style='list-style-image: url("+ node.imageUrl +");'";
}
if(hasChild){
print("<li "+ style +" class=folder id='P" + parent + i + "'><a class=treeview href=\"javascript:toggle('N" + parent + "_" + i + "','P" + parent + i + "')\">" + node.text + "</a>");
}else{
if(node.target==""){
node.target=target;
}
print("<li "+ style +" class=file><a class=treeview href='" + node.href + "' target='" + node.target + "' title=\"" + node.toolTip + "\">" + node.text + "</a>");
}
if(hasChild){
loopThru(node.childNodes,parent + "_" + i);
}
print("</li>");
}
print("</ul>");
}
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -