01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings;
14:
15: import org.wings.plaf.MenuBarCG;
16: import javax.swing.*;
17:
18: /**
19: * A chooseable item in a {@link SMenuBar} arranged inside a main {@link SMenu} topic.
20: *
21: * @author <a href="mailto:andre@lison.de">Andre Lison</a>
22: * @author <a href="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
23: */
24: public class SMenuItem extends SButton {
25: protected SComponent menuParent;
26: private KeyStroke accelerator;
27:
28: public SMenuItem() {
29: init();
30: }
31:
32: public SMenuItem(Action action) {
33: super (action);
34: init();
35: }
36:
37: public SMenuItem(String text) {
38: super (text);
39: init();
40: }
41:
42: public SMenuItem(SIcon icon) {
43: super (icon);
44: init();
45: }
46:
47: public SMenuItem(String text, SIcon icon) {
48: super (text, icon);
49: init();
50: }
51:
52: private void init() {
53: setShowAsFormComponent(false);
54: putClientProperty("drm:realParentComponent", "drm:null");
55: }
56:
57: final void setParentMenu(SComponent menuParent) {
58: this .menuParent = menuParent;
59: setParentFrame(menuParent != null ? menuParent.getParentFrame()
60: : null);
61: }
62:
63: public SComponent getParentMenu() {
64: return this .menuParent;
65: }
66:
67: public void setCG(MenuBarCG cg) {
68: super .setCG(cg);
69: }
70:
71: public void setAccelerator(KeyStroke keyStroke) {
72: accelerator = keyStroke;
73: if (accelerator != null) {
74: getInputMap(WHEN_IN_FOCUSED_FRAME).put(accelerator,
75: "item_accelerator");
76: getActionMap().put("item_accelerator", getAction());
77: }
78: }
79:
80: public KeyStroke getAccelerator() {
81: return accelerator;
82: }
83:
84: public boolean isRecursivelyVisible() {
85: return visible
86: && (menuParent != null ? menuParent
87: .isRecursivelyVisible() : super
88: .isRecursivelyVisible());
89: }
90:
91: public boolean getResidesInForm() {
92: return true;
93: }
94: }
|