`
orc_lh
  • 浏览: 9029 次
  • 性别: 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.pdf GWT-JSNI.pdfGWT-JSNI.pdf

    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 文件: ...

    angulargwt, 面向GWT的Angular 集成.zip

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

    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. 其他高级功能

    GWTGrailsTutorial 实面gwt和grails groovy集成

    A tutorial showing how do develop a Grails application with a GWT UI. Prepare your system The first step is to set up your system for running Grails and the GWT. You will also need to create a new ...

    gwt 练习 gwt学习

    gwt 练习gwt 练习gwt 练习gwt 练习

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

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

    GWT入门 GWT中文教程

    EXT-GWT2.0.1+API+DOC gwtdesigner Gwt-Ext基础-中级-进阶 GWT快速开发 GWT入门 GWT中文教程

    GWT工具GWT工具GWT工具GWT工具GWT工具GWT工具

    fwefwefwGWT工具GWT工具GWT工具GWT工具GWT工具GWT工具

    gwt入门-gwt从这里开始

    gwt 入门,是你开始学习gwt的大道 安装之后的目录结构为: C:\程序开发\Java\gwt-windows-1.4.59 doc(文档目录,开发文档和Java API文档) samples(示例代码目录,非常有名的KitchenSink示例代码即在此目录中)...

    用Maven创建GWT_SmartGWT项目

    用Maven创建GWT_SmartGWT项目,从而可利用Maven进行管理,以及持续集成。

    MyEclipse10集成GWT

    MyEclipse10集成GWT,网上例子比较少,现在大家提供方便!

    GWT(Google Web Toolkit)

    GWT(Google Web Toolkit) 是 Google 最近推出的一个开发 Ajax 应用的框架,它支持用 Java 开发和调试 Ajax 应用,本文... 如果你觉得GWT提供的API不能满足需求,你可以利用JSNI将Javascript语句直接嵌入至Java代码中。

    Gwt中文手册,GWt入门

    Gwt中文手册,GWt入门Gwt中文手册,GWt入门Gwt中文手册,GWt入门

    spring集成gwt的办法

    NULL 博文链接:https://mydownload.iteye.com/blog/1289377

    GWT安装和使用

    GWT(Google Web Toolkit) 是 Google 最近推出的一个开发 Ajax 应用的框架,它支持用 Java 开发和调试 Ajax 应用,本文主要介绍如何利用 GWT 进行 Ajax 的开发。 Ajax技术是当前开发web应用的非常热门的技术,也是Web...

    GWT开发者手册 GWT

    很好的资源,在这边分享下,提供给想要寻找GWT资源的兄弟姐妹们 如果哪位兄弟有好的资源不要忘了分享啊

    Grails中集成GWT中文资料

    详细说明Garils项目中集成GWT配置使用情况!

    GWT eclipse4.4离线插件

    GWT的eclipse4.4离线开发插件,国内现在没有

Global site tag (gtag.js) - Google Analytics