Gwt-richtextarea-widget
GWT-RichTextAreaウィジェット
前書き
*RichTextArea* ウィジェットは、複雑なスタイル設定と書式設定を可能にするリッチテキストエディターを表します。 一部のブラウザーはリッチテキスト編集をサポートせず、一部のブラウザーは機能の限られたサブセットのみをサポートするため、getBasicFormatter()およびgetExtendedFormatter()を介してアクセスされる2つのフォーマッターインターフェイスがあります。
リッチテキスト編集をまったくサポートしないブラウザーはこれらの両方に対してnullを返し、基本的な機能のみをサポートするブラウザーは後者のgetExtendedFormatter()に対してnullを返します。
クラス宣言
以下は com.google.gwt.user.client.ui.RichTextArea クラスの宣言です-
public class RichTextArea
extends FocusWidget
implements HasHTML, HasInitializeHandlers, HasSafeHtml
CSSスタイルルール
次のデフォルトのCSSスタイルルールがすべてのTextBoxウィジェットに適用されます。 要件に応じて上書きできます。
.gwt-RichTextArea {}
クラスコンストラクター
Sr.No. | Constructor & Description |
---|---|
1 |
RichTextArea() スタイルシートなしで新しい空のRichTextAreaオブジェクトを作成します。 |
クラスメソッド
Sr.No. | Function name & Description |
---|---|
1 |
HandlerRegistration addInitializeHandler(InitializeHandler handler) InitializeEventハンドラーを追加します。 |
2 |
RichTextArea.BasicFormatter getBasicFormatter() 廃止予定です。 代わりにgetFormatter()を使用してください。 |
3 |
RichTextArea.ExtendedFormatter getExtendedFormatter() 廃止予定です。 代わりにgetFormatter()を使用してください。 |
4 |
RichTextArea.Formatter getFormatter() リッチテキスト形式のインターフェイスを取得します。 |
5 |
java.lang.String getHTML() このオブジェクトのコンテンツをHTMLとして取得します。 |
6 |
java.lang.String getText() このオブジェクトのテキストを取得します。 |
7 |
boolean isEnabled() このウィジェットが有効かどうかを取得します。 |
8 |
protected void onAttach() このメソッドは、ウィジェットがブラウザのドキュメントに添付されたときに呼び出されます。 |
9 |
protected void onDetach() このメソッドは、ウィジェットがブラウザのドキュメントから切り離されるときに呼び出されます。 |
10 |
void setEnabled(boolean enabled) このウィジェットを有効にするかどうかを設定します。 |
11 |
void setFocus(boolean focused) このウィジェットを明示的にフォーカス/フォーカス解除します。 |
12 |
void setHTML(java.lang.String safeHtml) このオブジェクトのコンテンツを安全なHTML経由で設定します。 |
13 |
void setHTML(java.lang.String html) このオブジェクトのコンテンツをHTML経由で設定します。 |
14 |
void setText(java.lang.String text) このオブジェクトのテキストを設定します。 |
継承されるメソッド
このクラスは、次のクラスからメソッドを継承します-
- com.google.gwt.user.client.ui.UIObject
- com.google.gwt.user.client.ui.Widget
- com.google.gwt.user.client.ui.FocusWidget
- java.lang.Object
RichTextBoxウィジェットの例
この例では、GWTでのRichTextBoxウィジェットの使用法を示す簡単な手順を紹介します。 次の手順に従って、_GWTで作成したGWTアプリケーションを更新します-アプリケーションの作成_の章-
Step | Description |
---|---|
1 | Create a project with a name HelloWorld under a package com.finddevguides as explained in the GWT - Create Application chapter. |
2 | Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorldl and HelloWorld.java as explained below. Keep rest of the files unchanged. |
3 | Compile and run the application to verify the result of the implemented logic. |
以下は、変更されたモジュール記述子 src/com.finddevguides/HelloWorld.gwt.xml の内容です。
<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name = 'com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class = 'com.finddevguides.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path = 'client'/>
<source path = 'shared'/>
</module>
以下は、変更されたスタイルシートファイル war/HelloWorld.css の内容です。
body {
text-align: center;
font-family: verdana, sans-serif;
}
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
.gwt-RichTextArea {
padding:10px;
}
以下は、変更されたHTMLホストファイル war/HelloWorldl の内容です。
<html>
<head>
<title>Hello World</title>
<link rel = "stylesheet" href = "HelloWorld.css"/>
<script language = "javascript" src = "helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>RichTextArea Widget Demonstration</h1>
<div id = "gwtContainer"></div>
</body>
</html>
TextBoxウィジェットの使用方法を示すJavaファイル src/com.finddevguides/HelloWorld.java の内容を見てみましょう。
package com.finddevguides.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
//create RichTextArea elements
RichTextArea richTextArea = new RichTextArea();
richTextArea.setHeight("200");
richTextArea.setWidth("200");
//add text to text area
richTextArea.setHTML("<b>Hello World!</b> <br/> <br/>" +
"<i>Be Happy!</i> </br> <br/> <u>Stay Cool!</u>");
//Add text boxes to the root panel.
VerticalPanel panel = new VerticalPanel();
panel.add(richTextArea);
RootPanel.get("gwtContainer").add(panel);
}
}
すべての変更が完了したら、link:/gwt/gwt_create_application [GWT-アプリケーションの作成]の章で行ったように、アプリケーションをコンパイルして開発モードで実行します。 すべてがあなたのアプリケーションでうまくいけば、これは次の結果を生成します-