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

📄 hold.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/tree/Hold.java
//Description:  A Node in a project tree that contains other nodes

package cdt.projects.tree.nodes;

import java.util.LinkedList;
import java.util.Iterator;
import java.io.File;
import java.io.OutputStream;

/**
 * this is the hold class.  It is for the project tree.  It is an item that holds other items.
 * so in the tree it is displayed as a folder.
 *
 * @version 1.1
 * @author David Bradford<BR>
 *         Brad Schaefer (<A HREF="mailto:schaefer@medstat.med.utah.edu">schaefer@medstat.med.utah.edu</a>)
 */
public class Hold extends Node {
	/** children of this node. */
	private LinkedList children;

	/**
	 * Create a hold.
	 *
	 * @param name name of this hold.
	 */
	public Hold(String name) {
		this(name, null);
	}

	/**
	 * create a hold.
	 *
	 * @param name name of this hold.
	 * @param parent parent of this hold.
	 */
	public Hold(String name, Node parent) {
		setName(name);
        if(null != parent) {
    		parent.addNodeInto(this);
        }
		children = new LinkedList();
	}


	/**
	 * Gets the children of this node.
	 *
	 * @return children of node.
	 */
	public LinkedList getChildren() {
		return children;
	}

	/**
	 * Just returns an empty string, because all the data in the hold in the children.
	 *
	 * @return empty string.
	 */
	public String getData() {
		return "";
	}

	/**
	 * No data to sent so this does nothing.
	 *
	 * @param s not used.
	 */
	public void setData(String s) {}

	/**
	 * Adds a node to the children in this node.
	 *
	 * @param into node to add.
	 */
	public void addNodeInto(Node into) {
		children.add(into);
		into.setParent(this);
	}

	/**
	 * makes a copy of this node.
	 *
	 * @return copy of this node.
	 */
	public Node copy() {
		Node n = new Hold(this.getName());
		n.setFile(this.getFile());
		Iterator iter = children.iterator();
		while(iter.hasNext()) {
			Node child = (Node)iter.next();
			n.addNodeInto(child.copy());
		}
		return n;
	}

	/**
	 * Nodes are always visible so this just returns true.
	 *
	 * @return true.
	 */
    public boolean isVisible() {
        return true;
    }

    /**
	 * Writes the project data to an OutputStream.
	 *
	 * @param out OutputStream to send project data to.
	 * @param dir Indicates the directory of the file this {@link cdt.projects.tree.nodes.Node Node} represents.
	 */
	public void writeProject(OutputStream out, String dir) {
		try {
			if(getFile().indexOf(" file=") != -1) {
				System.out.println(getName() +" has an incorrect filename '" +getFile()+ "'");
			}
			out.write((new String("<menu name=\"" +getName()+ "\" file=\"" +getFile()+ "\">\n")).getBytes());
			Iterator iter = children.iterator();
			while(iter.hasNext()) {
				Node n = (Node)iter.next();
				n.writeProject(out, dir+getFile()+(File.separatorChar));
			}
			out.write((new String("</menu>\n")).getBytes());
		} catch(Exception e) {
            e.printStackTrace();
			cdt.ErrorD.ErrorDlg.ErrorMsg("Error writing project -> " +getName());
		}
	}

	/**
	 * All Holds allow children so returns true.
	 *
	 * @return true.
	 */
	public boolean getAllowsChildren() {
		return true;
	}

	/**
	 * a node has been dropped into this one so add it as a child.
	 *
	 * @param n node to add.
	 */
	public void dropInto(Node n) {
		addNodeInto(n.copy());
	}
}

⌨️ 快捷键说明

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