`
orc_lh
  • 浏览: 9280 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

gwt jsni集成tinyMCE

阅读更多
gwt代码 TinyMCE类

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;


public class TinyMCE extends Composite {

	private TextArea ta;
	private String id;
	private AbstractTinyMCEConfiguration config;
	
	public TinyMCE(AbstractTinyMCEConfiguration config) {
		super();
		if (config == null) {
			GWT.log("The configuration cannot be null",	null);
			return;
		}
		this.config = config;
		initWidget(initTinyMCE());
		init(config);
	}
	
	public TinyMCE() {
		this(new DefaultTinyMCEConfiguration());
	}

	private VerticalPanel initTinyMCE() {
		int width = 65 ;
		int height = 30 ;
		VerticalPanel panel = new VerticalPanel();
		panel.setWidth("100%");

		id = HTMLPanel.createUniqueId();
		ta = new TextArea();
		ta.setCharacterWidth(width);
		ta.setVisibleLines(height);
		DOM.setElementAttribute(ta.getElement(), "id", id);
		DOM.setStyleAttribute(ta.getElement(), "width", "100%");
		DOM.setStyleAttribute(ta.getElement(), "height", "250px"); // delete
																	// line?
		panel.add(ta);
		return panel;
	}

	public String getID() {
		return id;
	}

	public void setText(String text) {
		ta.setText(text);
	}

	public String getText() {
		getTextData();
		return ta.getText();
	}


	protected native void focusMCE(String id) /*-{
		$wnd.tinyMCE.execCommand('mceFocus', true, id);
	}-*/;

	protected native void resetMCE() /*-{
		$wnd.tinyMCE.execCommand('mceResetDesignMode', true);
	}-*/;

	public void unload() {
		unloadMCE(id);
	}

	protected native void unloadMCE(String id) /*-{
		$wnd.tinyMCE.execCommand('mceRemoveControl', false, id);
	}-*/;

	protected native void updateContent(String id) /*-{
		$wnd.tinyMCE.selectedInstance = $wnd.tinyMCE.getInstanceById(id);
		$wnd.tinyMCE.setContent($wnd.document.getElementById(id).value);
	}-*/;

	protected native void getTextData() /*-{
		$wnd.tinyMCE.triggerSave();
	}-*/;

	protected native String encodeURIComponent(String text) /*-{
		return encodeURIComponent(text);
	}-*/;

	protected native void setTextAreaToTinyMCE(String id) /*-{
		$wnd.tinyMCE.execCommand('mceAddControl', true, id);
	}-*/;

	protected native void removeMCE(String id) /*-{
		$wnd.tinyMCE.execCommand('mceRemoveControl', true, id);
	}-*/;

	public String initMode(){
		return config.getMode();
	}
	
	protected native void init(AbstractTinyMCEConfiguration conf) /*-{
		$wnd.tinyMCE.init({
				// General options
				mode : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getMode()(),
				theme : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getTheme()(),
				elements : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getElements()(),
				skin : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getSkin()(),
				entity_encoding : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getEntityEncoding()(),
				plugins : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getPlugins()(),
	
				// Theme options
				// excluded buttons: ,fontselect,fontsizeselect,preview,image,help,|,forecolor,backcolor tablecontrols,|,,emotions,media,|,print
				theme_advanced_buttons1 : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedButtons1()(),
				theme_advanced_buttons2 : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedButtons2()(),
				theme_advanced_buttons3 : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedButtons3()(),
				//theme_advanced_buttons4 : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedButtons4()(),
				theme_advanced_toolbar_location : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedToolbarLocation()(),
				theme_advanced_toolbar_align : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedToolbarAlign()(),
				theme_advanced_statusbar_location : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedStatusbarLocation()(),
				theme_advanced_resizing : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getThemeAdvancedResizing()(),
	
				// Example content CSS (should be your site CSS)
				content_css : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getContentCss()(),
	
				// Drop lists for link/image/media/template dialogs
				template_external_list_url : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getTemplateExternalListUrl()(),
				external_link_list_url : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getExternalLinkListUrl()(),
				external_image_list_url : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getExternalImageListUrl()(),
				media_external_list_url : conf.@com.orclh.gwt.client.client.AbstractTinyMCEConfiguration::getMediaExternalListUrl()(),
	
				// Replace values for the template plugin
				template_replace_values : {
					username : "Some User",
					staffid : "991234"
				}
				
			});
	
	
	}-*/;

	public AbstractTinyMCEConfiguration getConfig() {
		return config;
	}
}


gwt代码 AbstractTinyMCEConfiguration类,里面的参数用于配置tinyMCE的功能键;
package com.orclh.gwt.client.client;


public abstract class AbstractTinyMCEConfiguration {

	private String mode = "textareas";
	private String theme = "advanced";
	private String elements = "";
	private String skin = "o2k7";
	private String entityEncoding = "raw";
	private String themeAdvancedToolbarLocation = "top";
	private String themeAdvancedToolbarAlign = "left";
	private String themeAdvancedStatusbarLocation = "bottom";
	private String themeAdvancedResizing = "true";
	private String contentCss = "http://www.e-germanos.gr/e-germanos/eshop/css/all.css";
	private String templateExternalListUrl = "editor_stuf/lists/template_list.js";
	private String externalLinkListUrl = "editor_stuf/lists/link_list.js";
	private String externalImageListUrl = "editor_stuf/lists/image_list.js";
	private String mediaExternalListUrl = "editor_stuf/lists/media_list.js";

	private String[] plugins = new String[] {"example","safari","pagebreak","style","layer","table","save","advhr","advimage","advlink","emotions","iespell","inlinepopups","insertdatetime","preview","media","searchreplace","print","contextmenu","paste","directionality","fullscreen","noneditable","visualchars","nonbreaking","xhtmlxtras","template"};

	private String[] themeAdvancedButtons1 = new String[] {"mymenubutton" , "newdocument" , "|", "bold", "italic", "underline", "strikethrough", "|", "justifyleft", "justifycenter", "justifyright", "justifyfull", "formatselect"};
	private String[] themeAdvancedButtons2 = new String[] {"cut", "copy", "paste", "pastetext", "pasteword", "|", "search,replace", "|", "bullist", "numlist", "|", "outdent", "indent", "blockquote", "|", "undo", "redo", "|", "link", "unlink", "anchor", "cleanup", "code", "|", "insertdate", "inserttime"};
	private String[] themeAdvancedButtons3 = new String[] {"hr", "removeformat", "visualaid", "|", "sub", "sup", "|", "charmap", "iespell", "advhr", "|", "ltr", "rtl", "|", "fullscreen"};
	private String[] themeAdvancedButtons4 = new String[] {"insertlayer", "moveforward", "movebackward", "absolute", "|", "styleprops", "|", "cite", "abbr", "acronym", "del", "ins", "attribs", "|", "visualchars", "nonbreaking", "template", "pagebreak"};

	public String getMode() {
		return mode;
	}
	public void setMode(String mode) {
		this.mode = mode;
	}
	public String getTheme() {
		return theme;
	}
	public void setTheme(String theme) {
		this.theme = theme;
	}
	public String getSkin() {
		return skin;
	}
	public void setSkin(String skin) {
		this.skin = skin;
	}
	public String getEntityEncoding() {
		return entityEncoding;
	}
	public void setEntityEncoding(String entity_encoding) {
		this.entityEncoding = entity_encoding;
	}
	public String getThemeAdvancedToolbarLocation() {
		return themeAdvancedToolbarLocation;
	}
	public void setThemeAdvancedToolbarLocation(String theme_advanced_toolbar_location) {
		this.themeAdvancedToolbarLocation = theme_advanced_toolbar_location;
	}
	public String getThemeAdvancedToolbarAlign() {
		return themeAdvancedToolbarAlign;
	}
	public void setThemeAdvancedToolbarAlign(String theme_advanced_toolbar_align) {
		this.themeAdvancedToolbarAlign = theme_advanced_toolbar_align;
	}
	public String getThemeAdvancedStatusbarLocation() {
		return themeAdvancedStatusbarLocation;
	}
	public void setThemeAdvancedStatusbarLocation(String theme_advanced_statusbar_location) {
		this.themeAdvancedStatusbarLocation = theme_advanced_statusbar_location;
	}
	public String getThemeAdvancedResizing() {
		return themeAdvancedResizing;
	}
	public void setThemeAdvancedResizing(String theme_advanced_resizing) {
		this.themeAdvancedResizing = theme_advanced_resizing;
	}
	public String getContentCss() {
		return contentCss;
	}
	public void setContentCss(String content_css) {
		this.contentCss = content_css;
	}
	public String getTemplateExternalListUrl() {
		return templateExternalListUrl;
	}
	public void setTemplateExternalListUrl(String template_external_list_url) {
		this.templateExternalListUrl = template_external_list_url;
	}
	public String getExternalLinkListUrl() {
		return externalLinkListUrl;
	}
	public void setExternalLinkListUrl(String external_link_list_url) {
		this.externalLinkListUrl = external_link_list_url;
	}
	public String getExternalImageListUrl() {
		return externalImageListUrl;
	}
	public void setExternalImageListUrl(String external_image_list_url) {
		this.externalImageListUrl = external_image_list_url;
	}
	public String getMediaExternalListUrl() {
		return mediaExternalListUrl;
	}
	public void setMediaExternalListUrl(String media_external_list_url) {
		this.mediaExternalListUrl = media_external_list_url;
	}

	public String getPlugins() {
		String plug = "";
		int c = 1;
		for (String p : plugins) {
			plug += p;
			if (c < plugins.length) {
				plug += ", ";
			}
		}
		return plug;
	}
	public void setPlugins(String[] plugins) {
		this.plugins = plugins;
	}
	public String getThemeAdvancedButtons1() {
		String button1 = "";
		int c = 1;
		for (String p : themeAdvancedButtons1) {
			button1 += p;
			if (c < themeAdvancedButtons1.length) {
				button1 += ", ";
			}
		}
		return button1;
	}
	public void setThemeAdvancedButtons1(String[] theme_advanced_buttons1) {
		this.themeAdvancedButtons1 = theme_advanced_buttons1;
	}
	public String getThemeAdvancedButtons2() {
		String button2 = "";
		int c = 1;
		for (String p : themeAdvancedButtons2) {
			button2 += p;
			if (c < themeAdvancedButtons2.length) {
				button2 += ", ";
			}
		}
		return button2;
	}
	public void setThemeAdvancedButtons2(String[] theme_advanced_buttons2) {
		this.themeAdvancedButtons2 = theme_advanced_buttons2;
	}
	public String getThemeAdvancedButtons3() {
		String button3 = "";
		int c = 1;
		for (String p : themeAdvancedButtons3) {
			button3 += p;
			if (c < themeAdvancedButtons3.length) {
				button3 += ", ";
			}
		}
		return button3;
	}
	public void setThemeAdvancedButtons3(String[] theme_advanced_buttons3) {
		this.themeAdvancedButtons3 = theme_advanced_buttons3;
	}
	public String getThemeAdvancedButtons4() {
		String button4 = "";
		int c = 1;
		for (String p : themeAdvancedButtons4) {
			button4 += p;
			if (c < themeAdvancedButtons4.length) {
				button4 += ", ";
			}
		}
		return button4;
	}
	public void setThemeAdvancedButtons4(String[] theme_advanced_buttons4) {
		this.themeAdvancedButtons4 = theme_advanced_buttons4;
	}
	public String getElements() {
		return elements;
	}
	public void setElements(String elements) {
		this.elements = elements;
	}

}


gwt代码 DefaultTinyMCEConfiguration tinyMCE默认配置类
public class DefaultTinyMCEConfiguration extends AbstractTinyMCEConfiguration {

}

目录结构:


  • 大小: 33.4 KB
分享到:
评论

相关推荐

    GWT-JSNI.pdf

    ### GWT-JSNI 关键知识点解析 #### 一、GWT与JSNI概述 - **GWT(Google Web Toolkit)**: 是一个开源框架,用于创建高性能的客户端应用程序。GWT 支持开发者使用 Java 编写前端代码,并将其编译成浏览器可以执行的...

    gwt-jsni:用于 GWT 项目的 JSNI 实用程序

    gwt-jsni 用于 GWT 项目的 JSNI 实用程序。 用法 将依赖项添加到您的 Maven POM: &lt; groupId&gt;com.bytebybyte.gwt&lt;/ groupId&gt; &lt; artifactId&gt;jsni &lt; version&gt;1.0.0 &lt; scope&gt;provided 和你的 .gwt.xml 文件: ...

    GWTGrailsTutorial 实面gwt和grails groovy集成

    在本文中,我们将深入探讨如何将Google Web Toolkit (GWT) 集成到Grails框架中,构建一个使用Groovy语言的Web应用程序。GWTGrails教程将引导你完成这个过程,首先确保你的系统已经准备好运行Grails和GWT。 ### 准备...

    spring集成gwt的办法

    本文将深入探讨如何将这两个强大的技术进行集成,以便利用Spring的强大功能来管理和控制GWT应用程序的后端逻辑。 **一、Spring框架简介** Spring是一个全面的Java企业级应用开发框架,它提供了依赖注入(Dependency...

    关于 JSNI 调用 Java 方法时的 Type Signatures 说明

    ### 关于 JSNI 调用 Java 方法时的 Type Signatures 说明 #### 一、Type Signatures 的概念与...掌握 Type Signatures 的规则和使用方法对于任何希望利用 JSNI 来扩展 GWT 应用程序功能的开发者来说都是必不可少的。

    GWT入门 GWT中文教程

    “GWT快速开发”这部分教程则专注于提高开发效率,可能包含了GWT的开发工具、IDE集成、代码生成、调试技巧等内容,让开发者能快速上手并高效地进行GWT项目开发。 “GWT入门”和“GWT中文教程”显然是针对初学者的,...

    angulargwt, 面向GWT的Angular 集成.zip

    angulargwt, 面向GWT的Angular 集成 AngularGWT在GWT中编写AngularJS控制器,过滤器,指令什么( 是)?这个库使作者能够编写组件或者完整的应用程序,用于 Java AngularJS中的。 这主要是在 Google中使用编译器铸件来...

    MyEclipse10集成GWT

    【MyEclipse10集成GWT】是一个关于在MyEclipse集成Google Web Toolkit (GWT)的教程。GWT是一款由Google开发的开源框架,它允许开发者使用Java语言编写前端Web应用,然后编译成优化过的JavaScript代码,使得开发者...

    gwtext编写的小系统

    GWText集成了EXT GWT的功能,提供了丰富的用户界面组件和强大的数据绑定机制,让开发者能够更高效地创建复杂的交互式前端界面。 GWT是Google开发的一个JavaScript生成工具,它允许开发者使用Java语言编写Web应用,...

    Spring2.5 and GWT 集成 --实现分页查询功能

    开发框架: gwt1.4.6 + spring2.5 + mysql5.0 开发工具: Eclipse3.4 Cypal Studio for GWT (Eclipse 的一个插件) 实现原理:通过GWT的RPC来调用Spring 传过来的服务器端数据 注意:需要的jar包 * gwt-user.jar ...

    GWT揭秘(书签整理版)

    4. JSNI 5. 在GWT中使用XML 6. GWT控件详解 7. 使用GWT控件 8. GWT-RPC 9. Ext GWT 10. (实战)俄罗斯方块游戏 11. (实战)费用申请审批流程 12. GWT与Flex整合 13. 图片缓存 CSS Sprite 14. 本地化 15. 其他高级功能

    gwt 练习 gwt学习

    GWT,全称为Google Web Toolkit,是一个开源的Java框架,用于构建高性能、可维护的富互联网应用程序(RIA)。GWT允许开发者使用Java语言编写客户端代码,然后通过编译器将其转换为优化过的JavaScript,以便在各种...

    gwt揭秘源代码

    4. **强大的开发环境**:GWT提供集成开发环境(IDE)插件,如Eclipse和IntelliJ IDEA,支持代码提示、调试和自动部署。 5. **丰富的UI组件**:GWT提供了丰富的Widget库,覆盖了常见的Web界面元素。 6. **跨浏览器...

    GWT安装和使用

    在这种情况下,GWT 支持 JavaScript Native Interface (JSNI),允许开发者直接在 Java 代码中嵌入 JavaScript 代码。这种机制为开发者提供了极大的灵活性,使其能够在需要时使用原生 JavaScript 功能。 #### 二、用...

    GWT

    3. **开发工具**:GWT提供了一个强大的集成开发环境(IDE)插件,如Eclipse,使得开发者可以享受到诸如代码提示、调试和重构等强大的功能。 4. **模块化**:GWT应用是模块化的,这使得代码组织更清晰,便于维护和...

    GWT通信机制初探

    总结来说,本文可能会涵盖GWT的通信机制,包括RequestBuilder和AsyncCallback的使用,以及如何将GXT与Spring框架集成,利用Spring的功能如依赖注入、服务代理、安全控制和数据持久化来增强GWT应用的功能和性能。...

    GWT快速开发(GWT) 是一个Java软件开发框架用于开发类似于Google Maps和Gmail的AJAX应用程序。GWT的设计参考Java AWT包设计,类命名规则、接口设计、事件监听等。你可以用Java编程语言开发你的界面,然后用GWT编译器将Java类转换成适合浏览器执行的...

    ### GWT快速开发知识点详解 #### 一、GWT简介 **Google Web Toolkit (GWT)** 是由Google推出的一款开源的Java开发框架,主要用于构建高度交互式的Web应用程序,特别是那些类似Google Maps和Gmail这样的AJAX应用。...

    Grails中集成GWT中文资料

    【Grails中集成GWT】知识点详解 在Web应用开发中,Grails是一个基于Groovy语言的开源框架,而Google Web Toolkit (GWT)则是一个用于构建和优化复杂JavaScript前端应用的开发工具。将这两者结合,可以让开发者利用...

    GWT开发环境JAVA

    Eclipse提供GWT插件,使得集成GWT变得简单。 3. **安装GWT插件**:在Eclipse中,通过Help &gt; Install New Software,选择GWT插件的更新站点进行安装。 4. **创建GWT项目**:在Eclipse中新建一个GWT项目,设置项目的...

Global site tag (gtag.js) - Google Analytics