Java Code Examples for org.w3c.dom.html.HTMLElement#insertBefore()

The following examples show how to use org.w3c.dom.html.HTMLElement#insertBefore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WritePanel.java    From oim-fx with MIT License 5 votes vote down vote up
public void insertImage(String path, String id, String name, String value) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
			// HTMLBodyElementImpl htmlBodyElementImpl =
			// (HTMLBodyElementImpl) htmlBodyElement;
			// Element e = htmlBodyElementImpl.getOffsetParent();
			// htmlBodyElementImpl.insertBefore(newChild, refChild)
			// htmlDocument.
		}

		Element e = htmlDocument.createElement("img");
		e.setAttribute("id", id);
		e.setAttribute("name", name);
		e.setAttribute("value", value);
		e.setAttribute("src", path);

		// webEngine.get
		// webView.get

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}
		webPage.getClientInsertPositionOffset();
	}
}
 
Example 2
Source File: ChatWritePane.java    From oim-fx with MIT License 5 votes vote down vote up
public void insert(String text) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
		}

		Element e = htmlDocument.createElement("div");
		e.setTextContent(text);

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			// htmlBodyElement.
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}

		webPage.getClientInsertPositionOffset();

	}
}
 
Example 3
Source File: ChatWritePane.java    From oim-fx with MIT License 5 votes vote down vote up
public void insertImage(String path, String id, String name, String value) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
		}

		Element e = htmlDocument.createElement("img");
		e.setAttribute("id", id);
		e.setAttribute("name", name);
		e.setAttribute("value", value);
		e.setAttribute("src", path);

		// webEngine.get
		// webView.get

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}
		webPage.getClientInsertPositionOffset();
	}
}
 
Example 4
Source File: WritePanel.java    From oim-fx with MIT License 4 votes vote down vote up
public void insert(String text) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
			// HTMLBodyElementImpl htmlBodyElementImpl =
			// (HTMLBodyElementImpl) htmlBodyElement;
			// Element e = htmlBodyElementImpl.getOffsetParent();
			// htmlBodyElementImpl.insertBefore(newChild, refChild)
			// htmlDocument.
		}

		Element e = htmlDocument.createElement("div");
		e.setTextContent(text);

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			// htmlBodyElement.
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}

		webPage.getClientInsertPositionOffset();

		// webView.set
		// System.out.println(htmlDocument.);

		//
		// org.w3c.dom.Node n = htmlBodyElement.getLastChild();
		//
		//
		//
		// webPage.getClientInsertPositionOffset();
		// // htmlBodyElement.ge
		// // hd.appendChild(e);
		// htmlDocument.getp
		//
	}
}
 
Example 5
Source File: WritePane.java    From oim-fx with MIT License 4 votes vote down vote up
public void insert(String text) {
	Document doc = webPage.getDocument(webPage.getMainFrame());
	if (doc instanceof HTMLDocument) {
		HTMLDocument htmlDocument = (HTMLDocument) doc;
		HTMLElement htmlDocumentElement = (HTMLElement) htmlDocument.getDocumentElement();
		HTMLElement htmlBodyElement = (HTMLElement) htmlDocumentElement.getElementsByTagName("body").item(0);

		if (htmlBodyElement instanceof HTMLBodyElementImpl) {
			// HTMLBodyElementImpl htmlBodyElementImpl =
			// (HTMLBodyElementImpl) htmlBodyElement;
			// Element e = htmlBodyElementImpl.getOffsetParent();
			// htmlBodyElementImpl.insertBefore(newChild, refChild)
			// htmlDocument.
		}

		Element e = htmlDocument.createElement("div");
		e.setTextContent(text);

		int positionOffset = webPage.getClientInsertPositionOffset();
		int index = (positionOffset + 1);
		NodeList nodeList = htmlBodyElement.getChildNodes();
		int length = nodeList.getLength();
		if (index < 0) {
			htmlBodyElement.appendChild(e);
		} else if (index < length) {
			org.w3c.dom.Node node = nodeList.item(index);
			// htmlBodyElement.
			htmlBodyElement.insertBefore(e, node);
		} else {
			htmlBodyElement.appendChild(e);
		}

		webPage.getClientInsertPositionOffset();

		// webView.set
		// System.out.println(htmlDocument.);

		//
		// org.w3c.dom.Node n = htmlBodyElement.getLastChild();
		//
		//
		//
		// webPage.getClientInsertPositionOffset();
		// // htmlBodyElement.ge
		// // hd.appendChild(e);
		// htmlDocument.getp
		//
	}
}