「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」アプリケーションのソースコードです。

  1. package{
  2. import flash.display.Sprite;
  3. import org.aswing.*;
  4. public class HelloWorld extends Sprite{
  5.     public function HelloWorld(){
  6.         AsWingManager.initAsStandard(this);
  7.         JOptionPane.showMessageDialog(Title”, “Hello World!”);
  8.  
  9.     }
  10. }
  11. }

以下はAsWingのサイトに公開されているVoteダイアログサンプル実行結果とソースです。

jop

ソースコード:

  1. package example
  2. {
  3.     import flash.display.Sprite;
  4.     import flash.events.Event;
  5.     import flash.events.MouseEvent;
  6.    
  7.     import org.aswing.ASColor;
  8.     import org.aswing.AbstractButton;
  9.     import org.aswing.BorderLayout;
  10.     import org.aswing.BoxLayout;
  11.     import org.aswing.ButtonGroup;
  12.     import org.aswing.FlowLayout;
  13.     import org.aswing.GridLayout;
  14.     import org.aswing.Insets;
  15.     import org.aswing.JButton;
  16.     import org.aswing.JFrame;
  17.     import org.aswing.JLabel;
  18.     import org.aswing.JOptionPane;
  19.     import org.aswing.JPanel;
  20.     import org.aswing.JRadioButton;
  21.     import org.aswing.SoftBoxLayout;
  22.     import org.aswing.border.EmptyBorder;
  23.     import org.aswing.border.LineBorder;
  24.     import org.aswing.event.AWEvent;
  25.     import org.aswing.geom.IntDimension;
  26.    
  27.     public class VoteDialog extends Sprite
  28.     {
  29.        
  30.         private static var defaultMessageCommand : String = "default";
  31.         private static var yesNoCommand : String = "yesno";
  32.         private static var yeahNahCommand : String = "yeahnah";
  33.         private static var yncCommand : String = "ync";
  34.         private var frame : JFrame;
  35.         private var label : JLabel;
  36.         private var voteButton : JButton;
  37.         private var selectName : String;
  38.        
  39.         public function VoteDialog(){
  40.             super();
  41.             createUI();
  42.         }
  43.        
  44.         private function createUI() : void{
  45.             frame = new JFrame( this, "VoteDialog" );
  46.             frame.setContentPane( createCenterPane() );
  47.             frame.pack();
  48. //            frame.setSize(new IntDimension( 200, 120 ) );
  49.             frame.show();
  50.         }
  51.        
  52.         private function createCenterPane() : JPanel{
  53.             var pane : JPanel = new JPanel(new BorderLayout());
  54.             var title : JLabel = new JLabel("Click the \"Vote\" button"
  55.                            + " once you have selected a candidate.");
  56.             label = new JLabel("Vote now!");
  57.             label.setBorder(new EmptyBorder(null, new Insets(10, 10, 10, 10)));
  58.            
  59.             var choicePanel : JPanel = createSimpleDialogBox();
  60.             choicePanel.setBorder(new EmptyBorder(null, new Insets(20, 20, 5, 20)));
  61.             pane.append(title, BorderLayout.NORTH);           
  62.             pane.append(label, BorderLayout.SOUTH);
  63.             pane.append(choicePanel, BorderLayout.CENTER);                              
  64.             initHandlers();
  65.             return pane;
  66.         }
  67.        
  68.         private function createSimpleDialogBox() : JPanel{
  69.             var numButtons : int = 4;
  70.             var radioButtons : Array = new Array(numButtons);           
  71.             var group : ButtonGroup = new ButtonGroup();   
  72.    
  73.             var defaultMessageCommand : String = "default";
  74.             var yesNoCommand : String = "yesno";
  75.             var yeahNahCommand : String = "yeahnah";
  76.             var yncCommand : String = "ync";
  77.    
  78.             var jrb0 : JRadioButton = new JRadioButton(
  79.               "Candidate 1: Sparky the Dog");
  80.             jrb0.setName(defaultMessageCommand);
  81.             jrb0.setHorizontalAlignment(AbstractButton.LEFT);
  82.             radioButtons[0] = jrb0;
  83.    
  84.             var jrb1 : JRadioButton = new JRadioButton(
  85.               "Candidate 2: Shady Sadie");
  86.             jrb1.setName(yesNoCommand);
  87.              jrb1.setHorizontalAlignment(AbstractButton.LEFT);
  88.             radioButtons[1] = jrb1;
  89.    
  90.             var jrb2 : JRadioButton = new JRadioButton(
  91.               "Candidate 3: R.I.P. McDaniels");
  92.             jrb2.setName(yeahNahCommand);
  93.              jrb2.setHorizontalAlignment(AbstractButton.LEFT);
  94.             radioButtons[2] = jrb2;
  95.    
  96.                var jrb3 : JRadioButton = new JRadioButton(
  97.               "Candidate 4: Alva Sun");
  98.             jrb3.setName(yncCommand);
  99.              jrb3.setHorizontalAlignment(AbstractButton.LEFT);
  100.             radioButtons[3] = jrb3;
  101.    
  102.             for (var i:int = 0; i < numButtons; i++) {
  103.                 group.append(radioButtons[i]);
  104.                 JRadioButton(radioButtons[i]).addActionListener(__select);
  105.             }
  106.            
  107.             radioButtons[0].setSelected(true);
  108.             selectName = radioButtons[0].getName();
  109.                voteButton = new JButton("Vote");
  110.                voteButton.setPreferredWidth(100);
  111.             var box : JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 5));
  112.             box.setBorder(new EmptyBorder(null, new Insets(0,20,0,0)));
  113.             for (var j:int = 0; j < numButtons; j++) {
  114.                 box.append(radioButtons[j]);
  115.             }           
  116.             var p : JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 6));
  117.             var lb : JLabel = new JLabel("The candidates:");
  118.             lb.setHorizontalAlignment(JLabel.LEFT);
  119.             p.append(lb);   
  120.             p.append(box);
  121.             p.append(voteButton);
  122.             return p;
  123.         }
  124.        
  125.         private function initHandlers() : void{
  126.             voteButton.addActionListener(__vote);
  127.         }
  128.        
  129.         private function __vote(e : Event) : void{
  130.             if(selectName == defaultMessageCommand){
  131.                 JOptionPane.showMessageDialog("Message",
  132.                        "This candidate is a dog. Invalid vote.",
  133.                        null,
  134.                        frame);
  135.             }else if(selectName == yesNoCommand){
  136.                 JOptionPane.showMessageDialog("A Follow-up Question",
  137.                        "This candidate is a convicted felon. \nDo you still want to vote for her?",
  138.                        __finish1,
  139.                        frame,
  140.                        true,
  141.                        null,
  142.                        JOptionPane.YES|JOptionPane.NO);
  143.             }else if(selectName == yeahNahCommand){
  144.                 var jop : JOptionPane = JOptionPane.showMessageDialog( "A Follow-up Question",
  145.                     "This candidate is deceased. \nDo you still want to vote for him?",
  146.                     __finish2,
  147.                     frame,
  148.                     true,
  149.                     null,
  150.                     JOptionPane.YES);
  151.                 var nobtn : JButton = new JButton("No, thanks");
  152.                 nobtn.addActionListener(function(): void{setLabel("Whew! Good choice.");jop.getFrame().tryToClose();});
  153.                 jop.addButton(nobtn);
  154.             }else{
  155.                 var jop : JOptionPane = JOptionPane.showMessageDialog( "A Follow-up Question",
  156.                     "Alvasun is a mascot. \nDo you still want to cast your vote?",
  157.                     __finish3,
  158.                     frame,
  159.                     true,
  160.                     null,
  161.                     JOptionPane.YES|JOptionPane.NO|JOptionPane.CANCEL);
  162.             }
  163.         }
  164.        
  165.         private function __select( e : AWEvent ) : void{           
  166.             selectName = JRadioButton(e.target).getName();
  167.         }
  168.        
  169.         private function __finish2(result:Number)  :void{
  170.             if(result == JOptionPane.YES){
  171.                 setLabel("I hope you don't expect much from your candidate.");
  172.             }else{
  173.                 setLabel("It is your civic duty to cast your vote.");
  174.             }
  175.         }
  176.                
  177.         private function __finish1(result:Number)  :void{
  178.             if(result == JOptionPane.YES){
  179.                 setLabel("OK. Keep an eye on your wallet.");
  180.             }else if(result == JOptionPane.NO){
  181.                 setLabel("Whew! Good choice.");
  182.             }else{
  183.                 setLabel("It is your civic duty to cast your vote.");
  184.             }
  185.         }
  186.        
  187.         private function __finish3(result:Number)  :void{
  188.             if(result == JOptionPane.YES){
  189.                 setLabel("Excellent choice.");
  190.             }else if(result == JOptionPane.NO){
  191.                 setLabel("Whatever you say. It's your vote.");
  192.             }else if(result == JOptionPane.NO){
  193.                 setLabel("Well, I'm certainly not going to make you vote.");
  194.             }else{
  195.                 setLabel("It is your civic duty to cast your vote.");
  196.             }
  197.         }
  198.        
  199.         private function setLabel(newText : String) :void {
  200.             label.setText(newText);
  201.             label.revalidate();
  202.         }
  203.     }
  204. }

これらをActionScript上でimportすれば良いです。だが、これではプログラムベースという難点が解決していないです。そこで使うのが同サイトで提供されているAsWing GuiBuilderというものもあります。興味がある方たちはぜひ使ってみようー

関連リンク

http://code.google.com/p/aswing/ 公式サイト

メインコンテンツEND ■
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Posted on Friday, 24th April 2009 by admin

Tags: , , , ,
Posted in ActionScript, Flash Project | Comments (0) | 2,611 views

Leave a Reply