SMenuItem.java :  » Swing-Library » wings3 » org » wings » Java Open Source

Java Open Source » Swing Library » wings3 
wings3 » org » wings » SMenuItem.java
/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */
package org.wings;

import org.wings.plaf.MenuBarCG;
import javax.swing.*;

/**
 * A chooseable item in a {@link SMenuBar} arranged inside a main {@link SMenu} topic.
 *
 * @author <a href="mailto:andre@lison.de">Andre Lison</a>
 * @author <a href="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
 */
public class SMenuItem extends SButton {
    protected SComponent menuParent;
    private KeyStroke accelerator;

    public SMenuItem() {
        init();
    }

    public SMenuItem(Action action) {
        super(action);
        init();
    }

    public SMenuItem(String text) {
        super(text);
        init();
    }

    public SMenuItem(SIcon icon) {
        super(icon);
        init();
    }

    public SMenuItem(String text, SIcon icon) {
        super(text, icon);
        init();
    }
    
    private void init() {
        setShowAsFormComponent(false);
        putClientProperty("drm:realParentComponent", "drm:null");
    }

    final void setParentMenu(SComponent menuParent) {
        this.menuParent = menuParent;
        setParentFrame(menuParent != null ? menuParent.getParentFrame() : null);
    }

    public SComponent getParentMenu() {
        return this.menuParent;
    }

    public void setCG(MenuBarCG cg) {
        super.setCG(cg);
    }

    public void setAccelerator(KeyStroke keyStroke) {
        accelerator = keyStroke;
        if (accelerator != null) {
            getInputMap(WHEN_IN_FOCUSED_FRAME).put(accelerator, "item_accelerator");
            getActionMap().put("item_accelerator", getAction());
        }
    }

    public KeyStroke getAccelerator() {
        return accelerator;
    }

    public boolean isRecursivelyVisible() {
        return visible && (menuParent != null ? menuParent.isRecursivelyVisible() : super.isRecursivelyVisible());
    }

    public boolean getResidesInForm() {
        return true;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.