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

📄 imageindex.java

📁 eclipse平台的CDT项目3.0版本的源代码
💻 JAVA
字号:
//Title:        Curriculum Development Tool
//Copyright:    Copyright (c) 2001
//Author:       David Bradford - dbrad@medstat.med.utah.edu
//Company:      Knowledge Weavers - http://medstat.med.utah.edu/kw/
//File:         projects/export/additions/ImageIndex.java
//Description:  Adds an image index to the project

package cdt.projects.export.additions;

import cdt.projects.tree.nodes.Node;
import cdt.projects.tree.nodes.Item;
import cdt.projects.tree.nodes.Hold;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

/**
 * This class is used to dynamically create an image index page.
 *
 * @version 1.0
 * @author David Bradford
 */
public class ImageIndex implements ExportModule, Serializable {
	/** This stores info about what images will be in this page. */
	private HashMap images = new HashMap();

	/**
	 * Creates the ImageIndex.
	 */
	public ImageIndex() {}

	/**
	 * Gets the code for the page.
	 *
	 * @return code the the image index.
	 */
	public String getPage() {
		StringBuffer sb = new StringBuffer();
		sb.append("<h1>Image Index</h1>\n");
		sb.append("<ul>\n");
		Node head = cdt.projects.Project.currentProject.getTree().getHead();
		Iterator iter = head.getChildren().iterator();
		while(iter.hasNext()) {
			Node child = (Node)iter.next();
			sb.append(getSubPage(child));
		}
		sb.append("</ul>\n");

		return sb.toString();
	}

	/**
	 * Gets the code for file in a node.
	 *
	 * @param n Node to look at.
	 * @return code for files in a Node.
	 */
	private String getSubPage(Node n) {
		StringBuffer sb = new StringBuffer();
		if(n instanceof Item) {
			Vector v = (Vector)images.get(n.getFile());
			if(v != null) {//NOTE: if you want page label for all pages add before this if
				sb.append("<li>"+n.getName()+"<br>\n<ul>\n");
				Enumeration enum = v.elements();
				while(enum.hasMoreElements()) {
					String imageName = (String)enum.nextElement();
					sb.append("<li><a href=\"pics/"+imageName+"\">"+imageName+"</a></li>\n");
				}
				sb.append("</ul>\n</li>");
			}
        } else if(n instanceof Hold) {
			StringBuffer sublists = new StringBuffer();
			Iterator iter = n.getChildren().iterator();
			while(iter.hasNext()) {
				Node child = (Node)iter.next();
				sublists.append(getSubPage(child));
			}
			if(!sublists.toString().equals("")) {
				sb.append("<li>"+n.getName()+"<br>\n<ul>\n"+sublists.toString()+"</ul>\n</li>\n");
			}
		}
		return sb.toString();
	}

	/**
	 * Adds information to the image index.
	 *
	 * @param title filename of the page picture is in.
	 * @param item filename of the picture.
	 */
	public void addInfo(String title, Object item) {
		Vector v = (Vector)images.get(title);
		if(v == null) {
			v = new Vector();
		}
		v.add(item);
		images.put(title, v);
	}

	/**
	 * Adds an image to the current projects image index.  This is just for ease of use.
	 *
	 * @param file file to add.
	 * @param adds image index to use.
	 */
	public static void addImage(String file, ExportModule adds) {
		cdt.projects.Project.currentProject.addAddition("Image Index");
		adds.addInfo(cdt.projects.Project.currentProject.getLastSelected(), file);
	}
}

⌨️ 快捷键说明

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