Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jext/scripting/dawn/functions/CreateActionFunction.java


1   /*
2    * CreateActionFunction.java - creates a new action in Jext window
3    * Copyright (C) 2000 Romain Guy
4    * romain.guy@jext.org
5    * http://www.jext.org
6    *
7    * This program is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation; either While 2
10   * of the License, or any later While.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20   */
21  
22  package org.jext.scripting.dawn.functions;
23  
24  import java.awt.event.ActionEvent;
25  
26  import javax.swing.JMenu;
27  
28  import org.jext.dawn.*;
29  import org.jext.*;
30  import org.jext.gui.*;
31  import org.jext.scripting.dawn.Run;
32  
33  /**
34   * Creates a new action in Jext.<br>
35   * Usage:<br>
36   * <code>code actionLabel actionName createAction</code><br>
37   * code is the Dawn code which will be executed on click, actionLabel
38   * is the name which will appear in Jext menu bar, and actionName is
39   * Jext internal action name.
40   * @author Romain Guy
41   */
42  
43  public class CreateActionFunction extends Function
44  {
45    public CreateActionFunction()
46    {
47      super("createAction");
48    }
49  
50    public void invoke(DawnParser parser) throws DawnRuntimeException
51    {
52      parser.checkArgsNumber(this, 3);
53      String actionName = parser.popString();
54      String actionLabel = parser.popString();
55      String actionCode = parser.popString();
56  
57      DawnAction action = new DawnAction(actionName, actionCode);
58      //Jext.setProperty(actionName + ".label", actionLabel);
59      Jext.addAction(action);
60  
61      JextFrame parent = (JextFrame) parser.getProperty("JEXT.JEXT_FRAME");
62      JextMenu dawnMenu = (JextMenu) parent.getJextToolBar().getClientProperty("DAWN.DAWN_MENU");
63      if (dawnMenu == null)
64      {
65        parent.getJextToolBar().putClientProperty("DAWN.DAWN_MENU", dawnMenu = new JextMenu("Dawn"));
66        parent.getJextMenuBar().addMenu(dawnMenu, "Tools");
67      }
68  
69      dawnMenu.add(GUIUtilities.loadMenuItem(actionLabel, actionName, null, true, true));
70    }
71  
72    class DawnAction extends MenuAction
73    {
74      private String code;
75  
76      DawnAction(String name, String code)
77      {
78        super(name);
79        this.code = code;
80      }
81  
82      public void actionPerformed(ActionEvent evt)
83      {
84        Run.execute(code, getJextParent(evt));
85      }
86    }
87  }
88  
89  // End of CreateActionFunction.java