忍者ブログ
[1]  [2]  [3
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

Urumaでのウィンドウの削除、表示、非表示なんか

Urumaでは画面のShellオブジェクトが自動的にshellって名前でインジェクションされるらしい。

つまり各画面のアクションに

public Shell shell;

でShellオブジェクトができるっと。

まずは画面の削除

shell.close();

次に画面の非表示

shell.setVIsible(false);

表示はtrueにするだけ。

shell.setVisible(treu);


コレを使えばサブウィンドウが表示されている間はメインウィンドウを表示したくないときなんかに使えます。

MenuAction.java

package gui.test;

import org.eclipse.swt.widgets.Shell;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;
import org.seasar.uruma.core.UrumaWindowManager;

@Component(name="menuAction")
public class MenuAction {
 public Shell shell;
 public UrumaWindowManager windowManager;
 

 @EventListener(id="button")
 public void button(){
  shell.setVisible(false);
  windowManager.openWindow("gui/test/subDisp.xml", true);
  shell.setVisible(true);
 }
}


subDisp.xml

<?xml version="1.0" encoding="UTF-8"?>
<template xmlns="http://uruma.sandbox.seasar.org">
 <window title="メインメニュー" background="white" width="800" height="600">
  <gridLayout numColumns="1" >
   <gridData horizontalAlignment="FILL" widthHint="150"/>
  </gridLayout>

  <text id="title"/>
  <button id="button" text="ボタン"/>
  <button id="close" text="閉じる"/>
 </window>
</template>


SubDispAction.java

package gui.test;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;
import org.seasar.uruma.annotation.Form;

@Component(name="subDispAction")
@Form(SubDispForm.class)
public class SubDispAction {
 public Shell shell;
 public SubDispForm subDispForm;

 public Text title;

 @EventListener(id="button")
 public void dispTitleValue() {
  title.setBackground(new Color(shell.getDisplay(), 255, 255, 80));
  title.setForeground(new Color(shell.getDisplay(), 255, 0, 0));
  MessageDialog.openInformation(shell, "TitleValue", subDispForm.getTitle());
 }

 @EventListener(id="close")
 public void subDispClose() {
  shell.close();
 }
}


これでサブウィンドウが表示されているときはメインメニューは非表示になって閉じるボタンが押下されるか×が押下されたらサブウィンドウが閉じて、メインメニューが表示されるようになります。

PR

ボタンを押したら背景色が変化するようにしてみる。

アクションにコンポーネントを記述する。

Urumaではウィジット・インジェクションって言ってるやつ

SubDispAction.java
package gui.test;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;
import org.seasar.uruma.annotation.Form;

@Component(name="subDispAction")
@Form(SubDispForm.class)
public class SubDispAction {
 public Shell shell;
 public SubDispForm subDispForm;

 public Text title;

 @EventListener(id="button")
 public void dispTitleValue() {
  title.setBackground(new Color(shell.getDisplay(), 255, 255, 80));
  MessageDialog.openInformation(shell, "TitleValue", subDispForm.getTitle());
 }
}


public Text title;がコンポーネントの記述(正確には違うんだろうが・・・。)

title.setBackground(Color color)で背景色を設定できる。

title.setForeground(Color color)で文字の色が設定できる。



この前の記事のフォームを使用しないでテキストフィールドを取得、セットする方法。

public Text title;

 @EventListener(id="button")
 public void dispTitleValue() {
  MessageDialog.openInformation(shell, "TitleValue", title.getText());
  title.setText("てすとだよ(=ω=)");
 }

これでボタンを押下したら入力した内容がダイアログに表示されて、OKを押下すると「てすとだよ(=ω=)」がテキストフィールドにセットされる。

実際フォームを使うのと使わないのどっちがいいんだろう・・・?

まぁフォームは使いまわしできるからそういうときはフォームを使用したほうがいいのかな??

テキストフィールドなどから値を取得するにはフォームを作成する。

フォームを作成しなくてもできるっぽいがそれはまた後日。

まずはフォームを作成。

XMLの名前+Formでフォームを作成する。

SubDispForm.java

package gui.test;

import org.seasar.uruma.annotation.ImportValue;

public class SubDispForm {
 @ImportValue(id="title")
 private String title;

 public String getTitle() {
  return title;
 }

 public void setTitle(String title) {
  this.title = title;
 }
}

@ImportValueでXMLのidと等しいものから値を取得することができる。

ちなみに@ImportValueは取得のみ、@ExportValueはセットのみ、@ImportExportValueは両方が可能になる。

値を持ってくるだけだから型がText型じゃなくてString型なんだろうなぁ。

上のはprivateになっているがpublicでも可。

その場合にはセッターとゲッターは必要ありません。(自動的にセット、ゲットしてくれるらしい。)

続いてアクション

package gui.test;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;
import org.seasar.uruma.annotation.Form;

@Component(name="subDispAction")
@Form(SubDispForm.class)
public class SubDispAction {
 public Shell shell;
 public SubDispForm subDispForm;

 @EventListener(id="button")
 public void dispTitleValue() {
  MessageDialog.openInformation(shell, "TitleValue", subDispForm.getTitle());
 }
}

@Formでどのフォームを使用するかを決定する。

2つ以上の記述は不可。

フォームとアクションは多:1の関係になる。

public SubDispForm subDispForm;でフォームを持ってきてsubDispForm.getTitle()でゲットできる。

フォームがpublic String titleの場合はsubDispFOrm.titleでゲットできる。


最後にapp.diconにアクションとフォームを設定する。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.3//EN"
 "http://www.seasar.org/dtd/components23.dtd">

<components>
 <component class="gui.test.MenuAction"/>
 <component class="gui.test.SubDispAction"/>
 <component class="gui.test.SubDispForm"/>
</components>


これで完成。

ボタンを押下したら別ウィンドウを表示させてみる。

まずは表示させるウィンドウのXMLを作成

SubDisp.xml

<?xml version="1.0" encoding="UTF-8"?>
<template xmlns="http://uruma.sandbox.seasar.org">
 <window title="メインメニュー" background="white" width="800" height="600">
  <gridLayout numColumns="1" >
   <gridData horizontalAlignment="FILL" widthHint="150"/>
  </gridLayout>

  <text id="title"/>
  <button id="button" text="ボタン"/>
 </window>
</template>


で表示させるためにEventListenerでボタンイベントを検出する。

MenuAction.java

package gui.test;

import org.eclipse.swt.widgets.Shell;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;
import org.seasar.uruma.core.UrumaWindowManager;

@Component(name="menuAction")
public class MenuAction {
 public Shell shell;
 public UrumaWindowManager windowManager;
 

 @EventListener(id="button")
 public void button(){
  windowManager.openWindow("gui/test/subDisp.xml", true);
 }
}


UrumaWindowManager#openWIndowで新規画面が表示されます。

ちなみに画面を閉じると標準出力にエラーが表示されるけど今は無視。

ボタンのイベントの取得

まずはMenu.xml

<?xml version="1.0" encoding="UTF-8"?>
<template xmlns="http://uruma.sandbox.seasar.org">
 <window title="メインメニュー" background="white" width="800" height="600" x="20" y="20">
  <gridLayout numColumns="1" >
   <gridData horizontalAlignment="FILL"/>
  </gridLayout>

  <composite>
   <rowLayout type="HORIZONTAL" spacing="5">
    <rowData height="24"/>
   </rowLayout>

   <button id="button" text="ボタン" />
  </composite>
 </window>
</template>


XMLの名前+Actionでアクションを作成

MenuAction.java

package gui.test;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;

@Component(name="menuAction")
public class MenuAction {
 public Shell shell;

 @EventListener(id="button")
 public void button(){
  MessageDialog.openInformation(shell, "タイトル", "メッセージ");
 }
}

@EventListenerでイベントを取得する
メソッド名がコンポーネントのid名と同じ場合は(id="~")は必要ないらしい。


app.diconにMenuActionを追加

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.3//EN"
 "http://www.seasar.org/dtd/components23.dtd">

<components>
 <component class="gui.test.MenuAction"/>
</components>


これでボタンをクリックするとダイアログが出ます。

カレンダー
03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
ブログ内検索
忍者ブログ [PR]

Graphics by Lame Tea / designed by 26℃