Mercurial > hg > jslab
comparison src/samer/core_/util/heavy/MenuBuilder.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Tools.java | |
3 * | |
4 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
5 * All rights reserved. | |
6 * | |
7 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
8 * without even the implied warranty of MERCHANTABILITY or | |
9 * FITNESS FOR A PARTICULAR PURPOSE. | |
10 */ | |
11 | |
12 package samer.core.util.heavy; | |
13 import samer.core.util.*; | |
14 import samer.core.*; | |
15 import java.awt.*; | |
16 | |
17 public class MenuBuilder implements Agent.Registry | |
18 { | |
19 Menu menu; | |
20 AgentAdapter ad; | |
21 Font font=X.font(Shell.datum("menu.font"),null); | |
22 | |
23 public MenuBuilder(Menu m, AgentAdapter a) { menu=m; ad=a; } | |
24 | |
25 public Agent.Registry add(String l) { | |
26 MenuItem mi = new MenuItem(l); | |
27 mi.setFont(font); | |
28 mi.addActionListener(ad); | |
29 menu.add(mi); | |
30 return this; | |
31 } | |
32 public Agent.Registry add(String l, boolean state) { | |
33 CheckboxMenuItem mi = new CheckboxMenuItem(l, state); | |
34 mi.setFont(font); | |
35 mi.addItemListener(ad); | |
36 menu.add(mi); | |
37 return this; | |
38 } | |
39 public void setTarget(Agent a) { ad=new AgentAdapter(a); group(); } | |
40 public void group() { menu.add("-"); } | |
41 | |
42 public static Menu showCommands( Agent agent, Component c, Menu menu) | |
43 { | |
44 AgentAdapter adapter=new AgentAdapter(agent); | |
45 | |
46 if (menu==null) { | |
47 PopupMenu p=new PopupMenu(c.getName()); | |
48 | |
49 c.add(p); | |
50 c.removeMouseListener( MouseRetarget.listener); | |
51 c.addMouseListener( new PopupHandler(p)); | |
52 c.addMouseListener( MouseRetarget.listener); | |
53 menu=p; | |
54 } else { | |
55 menu.add("-"); | |
56 } | |
57 | |
58 agent.getCommands( new MenuBuilder(menu,adapter)); | |
59 return menu; | |
60 } | |
61 }; |