「AsWing」というプロジェクトは、Java SwingらしいFlash ActionScript向けのオープンソースのGUIフレームワークです。GUIコンポーネントのほか、多数のユーティリティクラスが含まれています。AsWingはActionScript2/3に対応することができます。ボタン、チェックボックス、スライダ、プログレスバー、コンボボックス等、GUIを仕上げるのに十分なコンポーネントが提供されています。利用方法がJavaのSwingに似ていることも特徴で、FlashアプリケーションのUIを簡単に作成することが可能です。
AsWingの主な利点と独自性について、AsWing開発の先頭に立つiiley Chen氏は以下のようにコメントしている。
主な利点は変化しやすく動的なUIを純粋にActionScriptのコーディングだけで構築できるということです。AsWingの中核部分は単に ActionScriptのクラスなので扱い易く管理し易いのです。もしJava Swingの経験があれば、そのスキルはほとんどが活用できるでしょう。
さらに、AsWingは専門的なColorMixiersやJLabelButton、Form、Folder、そしてGridListといった特別なコンポーネントを含む40以上もの近代的なUIコンポーネントを提供しています。.
加えて、よく出来たMVCパターンによってデータの更新を簡単にUI画面に反映できます。Flexにデータ・バインディングがあるように、AsWingにも様々なデータ・モデルがあり自動的に更新があったことを画面に通知します。
(AsWingに)含まれているSkinBuilder?(スキン・ビルダ)ツールは開発者がコンポーネントの画像やFlashのシンボルを用意するだけで完全に独自のスキンを作成するのに役立ちます。さらに、GuiBuilderはUIのレイアウト設計を補助し、後でActionScriptのソース・コードを生成することが出来ます。
Finally最後に、AsWingは重たくありません。他のアプリケーション・フレームワークも兼ねているUIフレームワークとは異なり、純粋にUIのためのものです。AsWingを好きなアプリケーション・フレームワークと組み合わせることが出来ます。
以下はAsWingの「Hello,world」アプリケーションのソースコードです。
- package{
- import flash.display.Sprite;
- import org.aswing.*;
- public class HelloWorld extends Sprite{
- public function HelloWorld(){
- AsWingManager.initAsStandard(this);
- JOptionPane.showMessageDialog(”Title”, “Hello World!”);
- }
- }
- }
以下はAsWingのサイトに公開されているVoteダイアログサンプル実行結果とソースです。
ソースコード:
- package example
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import org.aswing.ASColor;
- import org.aswing.AbstractButton;
- import org.aswing.BorderLayout;
- import org.aswing.BoxLayout;
- import org.aswing.ButtonGroup;
- import org.aswing.FlowLayout;
- import org.aswing.GridLayout;
- import org.aswing.Insets;
- import org.aswing.JButton;
- import org.aswing.JFrame;
- import org.aswing.JLabel;
- import org.aswing.JOptionPane;
- import org.aswing.JPanel;
- import org.aswing.JRadioButton;
- import org.aswing.SoftBoxLayout;
- import org.aswing.border.EmptyBorder;
- import org.aswing.border.LineBorder;
- import org.aswing.event.AWEvent;
- import org.aswing.geom.IntDimension;
- public class VoteDialog extends Sprite
- {
- private static var defaultMessageCommand : String = "default";
- private static var yesNoCommand : String = "yesno";
- private static var yeahNahCommand : String = "yeahnah";
- private static var yncCommand : String = "ync";
- private var frame : JFrame;
- private var label : JLabel;
- private var voteButton : JButton;
- private var selectName : String;
- public function VoteDialog(){
- super();
- createUI();
- }
- private function createUI() : void{
- frame = new JFrame( this, "VoteDialog" );
- frame.setContentPane( createCenterPane() );
- frame.pack();
- // frame.setSize(new IntDimension( 200, 120 ) );
- frame.show();
- }
- private function createCenterPane() : JPanel{
- var pane : JPanel = new JPanel(new BorderLayout());
- var title : JLabel = new JLabel("Click the \"Vote\" button"
- + " once you have selected a candidate.");
- label = new JLabel("Vote now!");
- label.setBorder(new EmptyBorder(null, new Insets(10, 10, 10, 10)));
- var choicePanel : JPanel = createSimpleDialogBox();
- choicePanel.setBorder(new EmptyBorder(null, new Insets(20, 20, 5, 20)));
- pane.append(title, BorderLayout.NORTH);
- pane.append(label, BorderLayout.SOUTH);
- pane.append(choicePanel, BorderLayout.CENTER);
- initHandlers();
- return pane;
- }
- private function createSimpleDialogBox() : JPanel{
- var numButtons : int = 4;
- var radioButtons : Array = new Array(numButtons);
- var group : ButtonGroup = new ButtonGroup();
- var defaultMessageCommand : String = "default";
- var yesNoCommand : String = "yesno";
- var yeahNahCommand : String = "yeahnah";
- var yncCommand : String = "ync";
- var jrb0 : JRadioButton = new JRadioButton(
- "Candidate 1: Sparky the Dog");
- jrb0.setName(defaultMessageCommand);
- jrb0.setHorizontalAlignment(AbstractButton.LEFT);
- radioButtons[0] = jrb0;
- var jrb1 : JRadioButton = new JRadioButton(
- "Candidate 2: Shady Sadie");
- jrb1.setName(yesNoCommand);
- jrb1.setHorizontalAlignment(AbstractButton.LEFT);
- radioButtons[1] = jrb1;
- var jrb2 : JRadioButton = new JRadioButton(
- "Candidate 3: R.I.P. McDaniels");
- jrb2.setName(yeahNahCommand);
- jrb2.setHorizontalAlignment(AbstractButton.LEFT);
- radioButtons[2] = jrb2;
- var jrb3 : JRadioButton = new JRadioButton(
- "Candidate 4: Alva Sun");
- jrb3.setName(yncCommand);
- jrb3.setHorizontalAlignment(AbstractButton.LEFT);
- radioButtons[3] = jrb3;
- for (var i:int = 0; i < numButtons; i++) {
- group.append(radioButtons[i]);
- JRadioButton(radioButtons[i]).addActionListener(__select);
- }
- radioButtons[0].setSelected(true);
- selectName = radioButtons[0].getName();
- voteButton = new JButton("Vote");
- voteButton.setPreferredWidth(100);
- var box : JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 5));
- box.setBorder(new EmptyBorder(null, new Insets(0,20,0,0)));
- for (var j:int = 0; j < numButtons; j++) {
- box.append(radioButtons[j]);
- }
- var p : JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 6));
- var lb : JLabel = new JLabel("The candidates:");
- lb.setHorizontalAlignment(JLabel.LEFT);
- p.append(lb);
- p.append(box);
- p.append(voteButton);
- return p;
- }
- private function initHandlers() : void{
- voteButton.addActionListener(__vote);
- }
- private function __vote(e : Event) : void{
- if(selectName == defaultMessageCommand){
- JOptionPane.showMessageDialog("Message",
- "This candidate is a dog. Invalid vote.",
- null,
- frame);
- }else if(selectName == yesNoCommand){
- JOptionPane.showMessageDialog("A Follow-up Question",
- "This candidate is a convicted felon. \nDo you still want to vote for her?",
- __finish1,
- frame,
- true,
- null,
- JOptionPane.YES|JOptionPane.NO);
- }else if(selectName == yeahNahCommand){
- var jop : JOptionPane = JOptionPane.showMessageDialog( "A Follow-up Question",
- "This candidate is deceased. \nDo you still want to vote for him?",
- __finish2,
- frame,
- true,
- null,
- JOptionPane.YES);
- var nobtn : JButton = new JButton("No, thanks");
- nobtn.addActionListener(function(): void{setLabel("Whew! Good choice.");jop.getFrame().tryToClose();});
- jop.addButton(nobtn);
- }else{
- var jop : JOptionPane = JOptionPane.showMessageDialog( "A Follow-up Question",
- "Alvasun is a mascot. \nDo you still want to cast your vote?",
- __finish3,
- frame,
- true,
- null,
- JOptionPane.YES|JOptionPane.NO|JOptionPane.CANCEL);
- }
- }
- private function __select( e : AWEvent ) : void{
- selectName = JRadioButton(e.target).getName();
- }
- private function __finish2(result:Number) :void{
- if(result == JOptionPane.YES){
- setLabel("I hope you don't expect much from your candidate.");
- }else{
- setLabel("It is your civic duty to cast your vote.");
- }
- }
- private function __finish1(result:Number) :void{
- if(result == JOptionPane.YES){
- setLabel("OK. Keep an eye on your wallet.");
- }else if(result == JOptionPane.NO){
- setLabel("Whew! Good choice.");
- }else{
- setLabel("It is your civic duty to cast your vote.");
- }
- }
- private function __finish3(result:Number) :void{
- if(result == JOptionPane.YES){
- setLabel("Excellent choice.");
- }else if(result == JOptionPane.NO){
- setLabel("Whatever you say. It's your vote.");
- }else if(result == JOptionPane.NO){
- setLabel("Well, I'm certainly not going to make you vote.");
- }else{
- setLabel("It is your civic duty to cast your vote.");
- }
- }
- private function setLabel(newText : String) :void {
- label.setText(newText);
- label.revalidate();
- }
- }
- }
これらをActionScript上でimportすれば良いです。だが、これではプログラムベースという難点が解決していないです。そこで使うのが同サイトで提供されているAsWing GuiBuilderというものもあります。興味がある方たちはぜひ使ってみようー
関連リンク
http://code.google.com/p/aswing/ 公式サイト
Posted on Friday, 24th April 2009 by admin
Tags: ActionScript, AsWing, Flash, Swing, フレームワーク
Posted in ActionScript, Flash Project | Comments (0) | 2,611 views
