001 /* 002 * LAPIS lightweight structured text processing system 003 * 004 * Copyright (C) 1998-2002 Carnegie Mellon University, 005 * Copyright (C) 2003 Massachusetts Institute of Technology. 006 * All rights reserved. 007 * 008 * This library is free software; you can redistribute it 009 * and/or modify it under the terms of the GNU General 010 * Public License as published by the Free Software 011 * Foundation, version 2. 012 * 013 * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/ 014 */ 015 016 package lapisx.swing; 017 018 import javax.swing.*; 019 020 public class AcceleratedMenu extends JMenu { 021 public AcceleratedMenu (String name) { 022 int ampersand = name.indexOf ('&'); 023 if (ampersand > -1 && ampersand < name.length()) { 024 char mnemonic = Character.toUpperCase (name.charAt (ampersand+1)); 025 setMnemonic (mnemonic); 026 name = name.substring (0, ampersand) + name.substring (ampersand + 1); 027 } 028 setText (name); 029 } 030 031 public JMenuItem add (Action action) { 032 JMenuItem item = super.add (action); 033 034 Object mn = action.getValue (AcceleratedAction.MNEMONIC); 035 if (mn != null) 036 item.setMnemonic (((Character)mn).charValue ()); 037 038 Object acc = action.getValue (AcceleratedAction.ACCELERATOR); 039 if (acc != null) 040 item.setAccelerator ((KeyStroke) acc); 041 042 return item; 043 } 044 } 045