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

📄 basedata.java

📁 java 调用windows的api
💻 JAVA
字号:
package org.jawin.browser.data;

import javax.swing.tree.TreeNode;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.ImageIcon;
import org.jawin.browser.project.ProjectItem;
import org.jawin.browser.xml.Encoder;
import java.io.File;

/**
 * A base tree node class that supports the concepts of an Icon
 * and generating itself as XML
 *
 * <p>Title: Jawin Code Generation GUI</p>
 * <p>Description: GUI for exploring type libraries and generating Java code</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: Open Source Incentive</p>
 *
 * @author Josh Passenger
 * @version 1.0
 */

public abstract class BaseData implements TreeNode, Comparable
{
	protected Vector children = new Vector();
	protected BaseData parent = null;
	protected String name = null;
	protected ProjectItem projectItem = null;
	protected String projectName = null;
	protected String libraryFileName = null;
	protected String packageName = null;
	protected String saveDirectory = null;
	protected String javaEncoding = null;
	protected String helpFile = null;
	protected int helpReference = 0;

	public static final String INDENT = "\t";

	public BaseData(String newName, ProjectItem projectItem)
	{
		name = newName;

		if (projectItem != null)
		{
			projectName = projectItem.getName();
			libraryFileName = projectItem.getLibraryFileName();
			packageName = projectItem.getPackageName();
			saveDirectory = projectItem.getSaveDirectory();
			javaEncoding = projectItem.getJavaEncoding();
		}
	}

	public TreeNode getChildAt(int childIndex)
	{
		return (TreeNode) children.get(childIndex);
	}

	public BaseData getBaseDataAt(int childIndex)
	{
		return (BaseData) children.get(childIndex);
	}

	public int getChildCount()
	{
		return children.size();
	}

	public TreeNode getParent()
	{
		return (TreeNode) parent;
	}

	public void setParent(BaseData newParent)
	{
		parent = newParent;
	}

	public int getIndex(TreeNode node)
	{
		return children.indexOf(node);
	}

	public boolean getAllowsChildren()
	{
		return true;
	}

	public boolean isLeaf()
	{
		if (children.size() == 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	public Enumeration children()
	{
		return children.elements();
	}

	public void addChild(BaseData newChild)
	{
		children.add(newChild);
		newChild.setParent(this);
	}

	public void removeFromParent()
	{
		if (parent != null)
		{
			parent.removeChild(this);
			setParent(null);
		}
	}

	public void removeChild(BaseData child)
	{
		children.remove(child);
	}

	public String getName()
	{
		return name;
	}

	public void indent(int depth, StringBuffer buffer)
	{
		for (int i = 0; i < depth; i++)
		{
			buffer.append(INDENT);
		}
	}

	public void newline(StringBuffer buffer)
	{
		buffer.append("\n");
	}

	public String toString()
	{
		return name;
	}

	/**
	 * Abstract methods
	 */
	public abstract ImageIcon getIcon();
	public abstract void toXML(int depth, StringBuffer buffer);

	public int compareTo(Object o)
	{
		String thisToString = toString();
		String other = o.toString();
		return thisToString.compareTo(o);
	}

	/**
	 * Write out the project item as XML into the buffer
	 * to support trasnformation of the tree at any level
	 *
	 * @param buffer the buffer to transform to
	 */
	public void projectItemToXML(StringBuffer buffer)
	{
		addAttribute(buffer, "projectName", projectName);
		addAttribute(buffer, "libraryFileName", libraryFileName);
		addAttribute(buffer, "packageName", packageName);
		addAttribute(buffer, "saveDirectory", saveDirectory);
		addAttribute(buffer, "javaEncoding", javaEncoding);
	}

	public void addAttribute(StringBuffer buffer, String attributeName, String attributeValue)
	{
		buffer.append(" ");
		Encoder.encode(attributeName, buffer);
		buffer.append("=\"");
		Encoder.encode(attributeValue, buffer);
		buffer.append("\"");
	}

	public boolean helpAvailable()
	{
		if (helpFile != null)
		{
			if (fileExists(helpFile))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	private boolean fileExists(String fileName)
	{
		File f = new File(fileName);

		if (f.exists() && f.isFile())
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	public String getHelpFile()
	{
		return helpFile;
	}

	public int getHelpReference()
	{
		return helpReference;
	}

	public void sort()
	{
		for (int i = 0; i < getChildCount(); i++)
		{
			getBaseDataAt(i).sort();
		}
	}

	public void setName(String newName)
	{
		name = newName;
	}

}

⌨️ 快捷键说明

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