Gwt-focuspanel-widget
GWT-FocusPanelウィジェット
前書き
*FocusPanel* ウィジェットは、コンテンツをフォーカスできるシンプルなパネルを表し、マウスとキーボードのイベントをキャッチする機能を追加します。
クラス宣言
以下は com.google.gwt.user.client.ui.FocusPanel クラスの宣言です-
public class FocusPanel
extends SimplePanel
implements HasFocus, SourcesClickEvents,
SourcesMouseEvents, SourcesMouseWheelEvents,
HasAllMouseHandlers, HasClickHandlers,
HasDoubleClickHandlers, HasAllKeyHandlers,
HasAllFocusHandlers
クラスコンストラクター
Sr.No. | Constructor & Description |
---|---|
1 |
FocusPanel() 空のフォーカスパネルを作成します。 |
2 |
FocusPanel(Widget child) 指定された子ウィジェットで新しいフォーカスパネルを作成します。 |
クラスメソッド
Sr.No. | Function name & Description |
---|---|
1 |
HandlerRegistration addBlurHandler(BlurHandler handler) BlurEventハンドラーを追加します。 |
2 |
HandlerRegistration addClickHandler(ClickHandler handler) ClickEventハンドラーを追加します。 |
3 |
void addClickListener(ClickListener listener) 廃止予定です。 代わりにaddClickHandler(com.google.gwt.event.dom.client.ClickHandler)を使用してください |
4 |
HandlerRegistration addDoubleClickHandler (DoubleClickHandler handler) DoubleClickEventハンドラーを追加します。 |
5 |
HandlerRegistration addFocusHandler(FocusHandler handler) FocusEventハンドラーを追加します。 |
6 |
void addFocusListener (FocusListener listener) 廃止予定です。 代わりにaddFocusHandler(com.google.gwt.event.dom.client.FocusHandler)を使用してください |
7 |
void addKeyboardListener (KeyboardListener listener) 廃止予定です。 addKeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler)、addKeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler)、addKeyPressHandler(com.google.gwt.event.dom.dom.client.KeyPressHandlerを使用します)代わりに |
8 |
HandlerRegistration addKeyDownHandler (KeyDownHandler handler) KeyDownEventハンドラーを追加します。 |
9 |
HandlerRegistration addKeyPressHandler (KeyPressHandler handler) KeyPressEventハンドラーを追加します。 |
10 |
HandlerRegistration addKeyUpHandler (KeyUpHandler handler) KeyUpEventハンドラーを追加します。 |
11 |
HandlerRegistration addMouseDownHandler (MouseDownHandler handler) MouseDownEventハンドラーを追加します。 |
12 |
void addMouseListener(MouseListener listener) 廃止予定です。 addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler)、addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler)、addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandlerを使用します)、代わりにaddMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler)およびaddMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) |
13 |
HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) MouseMoveEventハンドラーを追加します。 |
14 |
HandlerRegistration addMouseOutHandler(MouseOutHandler handler) MouseOutEventハンドラーを追加します。 |
15 |
HandlerRegistration addMouseOverHandler(MouseOverHandler handler) MouseOverEventハンドラーを追加します。 |
16 |
HandlerRegistration addMouseUpHandler(MouseUpHandler handler) MouseUpEventハンドラーを追加します。 |
17 |
HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) MouseWheelEventハンドラーを追加します。 |
18 |
void addMouseWheelListener(MouseWheelListener listener) 廃止予定です。 代わりにaddMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler)を使用してください |
19 |
int getTabIndex() タブインデックス内のウィジェットの位置を取得します。 |
20 |
void removeClickListener(ClickListener listener) 廃止予定です。 代わりに、addClickHandler(com.google.gwt.event.dom.client.ClickHandler)によって返されたオブジェクトでHandlerRegistration.removeHandler()メソッドを使用します |
21 |
void removeFocusListener(FocusListener listener) 廃止予定です。 代わりに、addFocusHandler(com.google.gwt.event.dom.client.FocusHandler)によって返されたオブジェクトでHandlerRegistration.removeHandler()メソッドを使用します |
22 |
void removeKeyboardListener(KeyboardListener listener) 廃止予定です。 代わりに、add *Handlerメソッドによって返されたオブジェクトでHandlerRegistration.removeHandler()メソッドを使用します |
23 |
廃止予定です。 代わりに、add *Handlerメソッドによって返されたオブジェクトでHandlerRegistration.removeHandler()メソッドを使用します |
24 |
廃止予定です。 代わりに、addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler)によって返されたオブジェクトでHandlerRegistration.removeHandler()メソッドを使用します |
25 |
void setAccessKey(char key) ウィジェットの「アクセスキー」を設定します。 |
26 |
void setFocus(boolean focused) このウィジェットを明示的にフォーカス/フォーカス解除します。 |
27 |
void setTabIndex(int index) タブインデックスでのウィジェットの位置を設定します。 |
継承されるメソッド
このクラスは、次のクラスからメソッドを継承します-
- com.google.gwt.user.client.ui.UIObject
- com.google.gwt.user.client.ui.Widget
- com.google.gwt.user.client.ui.Panel
- com.google.gwt.user.client.ui.SimplePanel
- java.lang.Object
FocusPanelウィジェットの例
この例では、GWTでのFocusPanelウィジェットの使用方法を示す簡単な手順を紹介します。 次の手順に従って、_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;
}
以下は、変更された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>FocusPanel Widget Demonstration</h1>
<div id = "gwtContainer"></div>
</body>
</html>
FocusPanelウィジェットの使用法を示すJavaファイル src/com.finddevguides/HelloWorld.java の内容を見てみましょう。
package com.finddevguides.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
//Create text
HTML contents = new HTML("This is a FocusPanel."
+" Click on the panel and it will attain focus.");
//create focus panel with content
FocusPanel focusPanel = new FocusPanel(contents);
focusPanel.setSize("400px", "100px");
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(focusPanel);
//Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}
すべての変更が完了したら、link:/gwt/gwt_create_application [GWT-アプリケーションの作成]の章で行ったように、アプリケーションをコンパイルして開発モードで実行します。 すべてがあなたのアプリケーションでうまくいけば、これは次の結果を生成します-