KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > bridges > menu > ScriptedPopupMenu


1 package rero.bridges.menu;
2
3 import java.awt.*;
4 import java.awt.event.*;
5
6 import javax.swing.*;
7 import javax.swing.event.*;
8
9 import sleep.runtime.*;
10 import sleep.engine.*;
11
12 import java.util.*;
13
14 import rero.script.ScriptCore;
15
16 public class ScriptedPopupMenu extends JPopupMenu implements PopupMenuListener, MenuBridgeParent
17 {
18    //
19
// Static code for keeping track of current menu data set (truth is again that only one popup menu will be showing at once)
20
//
21
protected static HashMap MenuData = null;
22
23    public static void SetMenuData(HashMap h)
24    {
25       if (h != null)
26          MenuData = h;
27    }
28
29    public static HashMap getMenuData()
30    {
31       return MenuData;
32    }
33
34    public static void FinishMenuData()
35    {
36       MenuData = null;
37    }
38
39
40    protected LinkedList code;
41
42    public ScriptedPopupMenu(ScriptInstance _owner, Block _code)
43    {
44        code = new LinkedList();
45        installCode(_owner, _code);
46
47        addPopupMenuListener(this);
48    }
49
50    public ScriptedPopupMenu(LinkedList _code)
51    {
52        code = _code;
53        addPopupMenuListener(this);
54    }
55
56    public void installCode(ScriptInstance _owner, Block _code)
57    {
58        code.add(new CodeSnippet(_owner, _code));
59    }
60
61    public boolean isValidCode()
62    {
63        Iterator i = code.iterator();
64        while (i.hasNext())
65        {
66           CodeSnippet temp = (CodeSnippet)i.next();
67           if (!temp.getOwner().isLoaded())
68           {
69              i.remove();
70           }
71        }
72
73        return code.size() > 0;
74    }
75
76    public void popupMenuWillBecomeVisible(PopupMenuEvent e)
77    {
78        MenuBridge.SetParent(this);
79
80        Iterator i = code.iterator();
81        while (i.hasNext())
82        {
83           CodeSnippet temp = (CodeSnippet)i.next();
84           if (temp.getOwner().isLoaded())
85           {
86              ScriptCore.runCode(temp.getOwner(), temp.getBlock(), MenuData);
87           }
88           else
89           {
90              i.remove();
91           }
92        }
93
94        MenuBridge.FinishParent();
95    }
96
97    public void popupMenuWillBecomeInvisible(PopupMenuEvent e)
98    {
99        removeAll();
100    }
101
102    public void popupMenuCanceled(PopupMenuEvent e)
103    {
104        removeAll();
105    }
106 }
107
Popular Tags