Mercurial > hg > jslab
view 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 |
line wrap: on
line source
/* * Tools.java * * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.core.util.heavy; import samer.core.util.*; import samer.core.*; import java.awt.*; public class MenuBuilder implements Agent.Registry { Menu menu; AgentAdapter ad; Font font=X.font(Shell.datum("menu.font"),null); public MenuBuilder(Menu m, AgentAdapter a) { menu=m; ad=a; } public Agent.Registry add(String l) { MenuItem mi = new MenuItem(l); mi.setFont(font); mi.addActionListener(ad); menu.add(mi); return this; } public Agent.Registry add(String l, boolean state) { CheckboxMenuItem mi = new CheckboxMenuItem(l, state); mi.setFont(font); mi.addItemListener(ad); menu.add(mi); return this; } public void setTarget(Agent a) { ad=new AgentAdapter(a); group(); } public void group() { menu.add("-"); } public static Menu showCommands( Agent agent, Component c, Menu menu) { AgentAdapter adapter=new AgentAdapter(agent); if (menu==null) { PopupMenu p=new PopupMenu(c.getName()); c.add(p); c.removeMouseListener( MouseRetarget.listener); c.addMouseListener( new PopupHandler(p)); c.addMouseListener( MouseRetarget.listener); menu=p; } else { menu.add("-"); } agent.getCommands( new MenuBuilder(menu,adapter)); return menu; } };