亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? macro.java

?? 具有不同語法高亮的編輯器實例
?? JAVA
字號:
/*
 * 09/16/2004
 *
 * Macro.java - A macro as recorded/played back by an RTextArea.
 * Copyright (C) 2004 Robert Futrell
 * email@address.com
 * www.website.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.fife.ui.rtextarea;

import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource;

import org.fife.io.UnicodeReader;


/**
 * A macro as recorded/played back by an <code>RTextArea</code>.
 *
 * @author Robert Futrell
 * @version 0.1
 */
public class Macro {

	private String name;
	private ArrayList macroRecords;

	private static final String ROOT_ELEMENT			= "macro";
	private static final String MACRO_NAME				= "macroName";
	private static final String ACTION					= "action";
	private static final String ID					= "id";

	private static final String UNTITLED_MACRO_NAME		= "<Untitled>";


/*****************************************************************************/


	/**
	 * Constructor.
	 */
	public Macro() {
		this(UNTITLED_MACRO_NAME);
	}


/*****************************************************************************/


	/**
	 * Loads a macro from a file on disk.
	 *
	 * @param file The file from which to load the macro.
	 * @throws java.io.EOFException If an EOF is reached unexpectedly (i.e.,
	 *                              the file is corrupt).
	 * @throws FileNotFoundException If the specified file does not exist, is
	 *                               a directory instead of a regular file, or
	 *                               otherwise cannot be opened.
	 * @throws IOException If an I/O exception occurs while reading the file.
	 * @see #saveToFile
	 */
	public Macro(File file) throws EOFException, FileNotFoundException,
								IOException {

		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = null;
		Document doc = null;
		try {
			db = dbf.newDocumentBuilder();
			//InputSource is = new InputSource(new FileReader(file));
			InputSource is = new InputSource(new UnicodeReader(
								new FileInputStream(file), "UTF-8"));
			is.setEncoding("UTF-8");
			doc = db.parse(is);//db.parse(file);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}

		macroRecords = new ArrayList();

		// Traverse the XML tree.
		boolean parsedOK = initializeFromXMLFile(doc);
		if (parsedOK==false) {
			name = null;
			macroRecords.clear();
			macroRecords = null;
			throw new IOException("Error parsing XML!");
		}

	}


/*****************************************************************************/


	/**
	 * Constructor.
	 *
	 * @param name The name of the macro.
	 */
	public Macro(String name) {
		this(name, null);
	}


/*****************************************************************************/


	/**
	 * Constructor.
	 *
	 * @param name The name of the macro.
	 * @param records The initial records of the macro.
	 */
	public Macro(String name, List records) {
		
		this.name = name;

		if (records!=null) {
			macroRecords = new ArrayList(records.size());
			Iterator i = records.iterator();
			while (i.hasNext()) {
				MacroRecord record = (MacroRecord)i.next();
				macroRecords.add(record);
			}
		}
		else {
			macroRecords = new ArrayList(10);
		}
	
	}


/*****************************************************************************/


	/**
	 * Adds a macro record to this macro.
	 *
	 * @param record The record to add.  If <code>null</code>, nothing happens.
	 * @see #getMacroRecords
	 */
	public void addMacroRecord(MacroRecord record) {
		if (record!=null)
			macroRecords.add(record);
	}


/*****************************************************************************/


	/**
	 * Returns the macro records that make up this macro.
	 *
	 * @return The macro records.
	 * @see #addMacroRecord
	 */
	public List getMacroRecords() {
		return macroRecords;
	}


/*****************************************************************************/


	/**
	 * Returns the name of this macro.
	 *
	 * @return The macro's name.
	 * @see #setName
	 */
	public String getName() {
		return name;
	}


/*****************************************************************************/


	/**
	 * Used in parsing an XML document containing a macro.  This method
	 * initializes this macro with the data contained in the passed-in node.
	 *
	 * @param node The root node of the parsed XML document.
	 * @return <code>true</code> if the macro initialization went okay;
	 *         <code>false</code> if an error occured.
	 */
	private boolean initializeFromXMLFile(Node node) {

		/*
		 * This method expects the XML document to be in the following format:
		 *
		 * <?xml version="1.0" encoding="UTF-8" ?>
		 * <macro>
		 *    <macroName>test</macroName>
		 *    <action id="default-typed">abcdefg</action>
		 *    [<action id=...>...</action>]
		 *    ...
		 * </macro>
		 *
		 */

		if (node==null)
			return false;

		int type = node.getNodeType();
		switch (type) {

			// Handle document nodes.
			case Node.DOCUMENT_NODE:
				boolean rc = initializeFromXMLFile(((Document)node).getDocumentElement());
				if (rc==false)
					return false;
				break;

			// Handle element nodes.
			case Node.ELEMENT_NODE:
				String nodeName = node.getNodeName();
				if (nodeName.equals(MACRO_NAME)) {
					NodeList childNodes = node.getChildNodes();
					if (childNodes==null)
						return false;
					if (childNodes.getLength()==0) {
						// Don't error out, just be "unnamed."
						name = UNTITLED_MACRO_NAME;
					}
					else {
						node = childNodes.item(0);
						if (node.getNodeType()!=Node.TEXT_NODE)
							return false;
						name = node.getNodeValue().trim();
					}
					System.err.println("Macro name==" + name);
				}

				else if (nodeName.equals(ROOT_ELEMENT)) {
					System.err.println("Beginning macro parsing!");
					NodeList childNodes = node.getChildNodes();
					if (childNodes!=null) {
						int length = childNodes.getLength();
						System.err.println("... num child nodes: " + length);
						for (int i=0; i<length; i++) {
							rc = initializeFromXMLFile(childNodes.item(i));
							if (rc==false)
								return false;
						}
					}
					System.err.println("Done with macro parsing!");
				}

				else if (nodeName.equals(ACTION)) {
					NamedNodeMap attributes = node.getAttributes();
					if (attributes==null || attributes.getLength()!=1)
						return false;
					Node node2 = attributes.item(0);
					MacroRecord macroRecord = new MacroRecord();
					if (node2.getNodeType()!=Node.ATTRIBUTE_NODE) {
						System.err.println("not an attribute type...");
						return false;
					}
					if (!node2.getNodeName().equals(ID)) {
						System.err.println("'id' expected but not found...");
						return false;
					}
					macroRecord.id = node2.getNodeValue();
					NodeList childNodes = node.getChildNodes();
					int length = childNodes.getLength();
					if (length==0) { // Could be empty "" command.
						System.err.println("... empty actionCommand");
						macroRecord.actionCommand = "";
						System.err.println("... adding action: " + macroRecord);
						macroRecords.add(macroRecord);
						break;
					}
					else if (length!=1) {
						System.err.println("childNodes invalid - " + childNodes);
						return false;
					}
					node = childNodes.item(0);
					if (node.getNodeType()!=Node.TEXT_NODE) {
						System.err.println("Not a text node...");
						return false;
					}
					macroRecord.actionCommand = node.getNodeValue();
					System.err.println("... adding action: " + macroRecord);
					macroRecords.add(macroRecord);
				}
				break;

			case Node.TEXT_NODE:
				System.err.println("... Throwaway whitespace node: '" + node.getNodeValue() + "'");
				break;

			// An error occured?
			default:
				System.err.println("... ERROR!!!");
				return false;

		}

		// Everything went okay.
		return true;

	}


/*****************************************************************************/


	/**
	 * Saves this macro to a text file.  This file can later be read in by
	 * the constructor taking a <code>File</code> parameter; this is the
	 * mechanism for saving macros.
	 *
	 * @param fileName The name of the file in which to save the macro.
	 * @throws IOException If an error occurs while generating the XML for the
	 *                     output file.
	 */
	public void saveToFile(String fileName) throws IOException {

		/*
		 * This method writes the XML document in the following format:
		 *
		 * <?xml version="1.0" encoding="UTF-8" ?>
		 * <macro>
		 *    <macroName>test</macroName>
		 *    <action id="default-typed">abcdefg</action>
		 *    [<action id=...>...</action>]
		 *    ...
		 * </macro>
		 *
		 */

		try {
			DocumentBuilder db = DocumentBuilderFactory.newInstance().
											newDocumentBuilder();
			DOMImplementation impl = db.getDOMImplementation();

			Document doc = impl.createDocument(null, ROOT_ELEMENT, null);
			Element rootElement = doc.getDocumentElement();

			// Write the name of the macro.
			Element nameElement = doc.createElement(MACRO_NAME);
			rootElement.appendChild(nameElement);

			// Write all actions (the meat) in the macro.
			int numActions = macroRecords.size();
			for (int i=0; i<numActions; i++) {
				MacroRecord record = (MacroRecord)macroRecords.get(i);
				Element actionElement = doc.createElementNS(null, ACTION);
				actionElement.setAttributeNS(null, ID, record.id);
				if (record.actionCommand!=null &&
					!record.actionCommand.equals("")) {
					// Remove illegal characters.  I'm no XML expert, but
					// I'm not sure what I'm doing wrong.  If we don't
					// strip out chars with Unicode value < 32, our
					// generator will insert '&#<value>', which will cause
					// our parser to barf when reading the macro back in
					// (it says "Invalid XML character").  But why doesn't
					// our generator tell us the character is invalid too?
					String command = record.actionCommand;
					for (int j=0; j<command.length(); j++) {
						if (command.charAt(j)<32) {
							command = command.substring(0,j);
							if (j<command.length()-1)
								command += command.substring(j+1);
						}
					}
					Node n = doc.createTextNode(command);
					actionElement.appendChild(n);
				}
				rootElement.appendChild(actionElement);
			}

			// Dump the XML out to the file.
			StreamResult result = new StreamResult(new File(fileName));
			DOMSource source = new DOMSource(doc);
			TransformerFactory transFac = TransformerFactory.newInstance();
			Transformer transformer = transFac.newTransformer();
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
			transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
			transformer.transform(source, result);

		} catch (Exception e) {
			throw new IOException("Error generating XML!");
		}

	}


/*****************************************************************************/


	/**
	 * Sets the name of this macro.
	 *
	 * @param name The new name for the macro.
	 * @see #getName
	 */
	public void setName(String name) {
		this.name = name;
	}


/*****************************************************************************/
/**************************** INNER CLASSES **********************************/
/*****************************************************************************/


	/**
	 * A "record" of a macro is a single action in the macro (corresponding to
	 * a key type and some action in the editor, such as a letter inserted into
	 * the document, scrolling one page down, selecting the current line,
	 * etc.).
	 */
	static class MacroRecord {

		public String id;
		public String actionCommand;

		public MacroRecord() {
			this(null, null);
		}

		public MacroRecord(String id, String actionCommand) {
			this.id = id;
			this.actionCommand = actionCommand;
		}

	}


/*****************************************************************************/

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本一区二区三区久久久久久久久不| 欧美精品久久一区二区三区| 精品一区二区三区在线播放 | 免费国产亚洲视频| 亚洲国产欧美一区二区三区丁香婷| 中文字幕欧美区| 亚洲国产高清在线| 1024成人网色www| 亚洲视频一二三| 亚洲黄色尤物视频| 午夜精品久久一牛影视| 免费看黄色91| 国产成人综合自拍| 97国产精品videossex| 91同城在线观看| 欧美三级蜜桃2在线观看| 欧美日韩美女一区二区| 日本一区二区成人| 国产日韩av一区| 亚洲久本草在线中文字幕| 亚洲国产视频在线| 激情综合色综合久久| 国产传媒日韩欧美成人| 91免费视频观看| 欧美精品一级二级| 国产日韩综合av| 亚洲精品免费电影| 久久不见久久见免费视频1| 成人免费高清在线观看| 欧美日韩一区二区欧美激情| 欧美一区二区啪啪| 成人欧美一区二区三区小说 | 日韩一区二区三区四区| 国产校园另类小说区| 亚洲美女区一区| 美女爽到高潮91| 色视频成人在线观看免| 日韩欧美国产一区在线观看| 亚洲欧洲一区二区三区| 日本不卡在线视频| 日本精品免费观看高清观看| 精品久久人人做人人爱| 亚洲免费av观看| 国产精品资源网| 欧美日本不卡视频| 17c精品麻豆一区二区免费| 久久99精品国产麻豆不卡| 色中色一区二区| 国产日本一区二区| 蜜臀av一区二区在线观看| 色老汉av一区二区三区| 国产欧美精品一区二区色综合朱莉| 亚洲午夜一区二区| 成av人片一区二区| 久久久精品国产99久久精品芒果| 亚洲动漫第一页| 91日韩精品一区| 久久精品男人的天堂| 日本欧美一区二区| 99久久综合狠狠综合久久| 26uuu精品一区二区三区四区在线| 亚洲一区二区视频在线观看| 成人国产精品免费| 欧美极品另类videosde| 激情偷乱视频一区二区三区| 91精品在线免费观看| 夜夜嗨av一区二区三区网页| 粉嫩av亚洲一区二区图片| 精品少妇一区二区| 精品一区精品二区高清| 精品福利二区三区| 久久精品国产久精国产爱| 欧美肥妇bbw| 日韩vs国产vs欧美| 91精品福利在线一区二区三区| 国产综合色视频| 精品国产乱码久久久久久久 | 国产日韩欧美精品一区| 免费在线观看一区二区三区| 欧美精品一卡两卡| 蜜臀国产一区二区三区在线播放 | 欧美一级二级三级蜜桃| 蜜臀av性久久久久蜜臀aⅴ四虎| 精品视频在线看| 亚洲va韩国va欧美va| 欧美体内she精高潮| 亚洲成人av中文| 欧美一级日韩免费不卡| 久久国产剧场电影| 国产欧美一区在线| 91丨九色丨国产丨porny| 一区二区在线观看免费| 欧美日韩一区中文字幕| 全国精品久久少妇| 亚洲国产精品传媒在线观看| 成人免费看的视频| 亚洲高清不卡在线观看| 日韩午夜av电影| 国产成人午夜99999| 亚洲品质自拍视频| 69久久夜色精品国产69蝌蚪网| 蜜臀久久久久久久| 国产欧美日韩在线| 欧美午夜不卡在线观看免费| 日本不卡一区二区| 中文字幕在线视频一区| 欧美日本一区二区| 精品亚洲成a人在线观看| 成人欧美一区二区三区视频网页| 欧美色男人天堂| 国产成人精品免费视频网站| 一区二区免费看| 国产亚洲综合av| 欧美视频精品在线| 国产精品综合在线视频| 亚洲国产一二三| 中文字幕欧美区| 91精品国产福利| 91久久国产综合久久| 国精品**一区二区三区在线蜜桃| 亚洲精品国产品国语在线app| 欧美va日韩va| 欧美日韩精品免费| 不卡一区在线观看| 久久精品国产99国产| 亚洲综合精品自拍| 中文在线一区二区| 欧美电影免费观看完整版| 在线免费av一区| 成人福利在线看| 极品少妇xxxx精品少妇偷拍| 亚洲超碰精品一区二区| 亚洲视频精选在线| 国产日韩av一区二区| 欧美va亚洲va在线观看蝴蝶网| 欧美在线一区二区三区| eeuss鲁片一区二区三区在线看| 日本不卡一区二区三区高清视频| 亚洲男同1069视频| 中文字幕在线观看不卡视频| 久久久99精品久久| 精品国精品国产| 日韩女优电影在线观看| 欧美日本韩国一区二区三区视频 | 亚洲第一福利视频在线| 亚洲视频一区二区免费在线观看| 国产日韩欧美一区二区三区综合| 日韩精品一区二区三区在线观看| 欧美激情一区三区| 久久精品欧美一区二区三区不卡| 精品人在线二区三区| 91精品国产福利在线观看 | 午夜一区二区三区在线观看| 亚洲综合色自拍一区| 亚洲精选免费视频| 亚洲一区二区三区不卡国产欧美| 亚洲激情男女视频| 亚洲一区视频在线观看视频| 一区二区三区四区高清精品免费观看| 国产精品国产馆在线真实露脸| 中文字幕精品三区| 亚洲欧洲性图库| 亚洲永久精品国产| 图片区小说区国产精品视频| 日本欧美久久久久免费播放网| 美女视频黄频大全不卡视频在线播放| 午夜精品久久久| 毛片不卡一区二区| 国产麻豆一精品一av一免费| 成人激情综合网站| 一本色道久久综合亚洲91| 欧美日韩一区在线观看| 日韩免费视频一区二区| 久久精品亚洲精品国产欧美kt∨| 国产精品嫩草影院av蜜臀| 亚洲天堂av老司机| 亚洲大尺度视频在线观看| 蜜臀久久99精品久久久久久9| 国产综合色产在线精品| www.日韩av| 欧美电影在哪看比较好| 国产欧美日韩在线观看| 亚洲综合激情网| 国产一区二区三区免费观看| 99riav一区二区三区| 欧美精品丝袜中出| 欧美激情中文字幕| 午夜精品久久久久久久99樱桃| 精品一区二区免费看| www..com久久爱| 91精品国产色综合久久不卡蜜臀 | a在线欧美一区| 欧美精选在线播放| 国产欧美在线观看一区| 亚洲国产成人91porn| 国产91富婆露脸刺激对白| 在线亚洲人成电影网站色www| 精品成人一区二区| 亚洲一卡二卡三卡四卡无卡久久 | 石原莉奈在线亚洲三区|