alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.util.actions;


/** An action that can be toggled on or off.
* The actual "performing" of the action is the toggle itself, so
* this action should be used by listening to the {@link #PROP_BOOLEAN_STATE} property.
* 

The default value of the state is true (on). * * * @author Ian Formanek, Petr Hamernik */ public abstract class BooleanStateAction extends SystemAction implements Presenter.Menu, Presenter.Popup, Presenter.Toolbar { /** serialVersionUID */ static final long serialVersionUID = 6394800019181426199L; /** Name of property hold the state of the action. */ public static final String PROP_BOOLEAN_STATE = "booleanState"; // NOI18N /* Returns a JMenuItem that presents the Action, that implements this * interface, in a MenuBar. * @return the JMenuItem representation for the Action */ public javax.swing.JMenuItem getMenuPresenter() { return org.netbeans.modules.openide.util.AWTBridge.getDefault ().createMenuPresenter (this); } /* Returns a JMenuItem that presents the Action, that implements this * interface, in a Popup Menu. * The default implmentation returns the same JMenuItem as the getMenuPresenter. * @return the JMenuItem representation for the Action */ public javax.swing.JMenuItem getPopupPresenter() { return org.netbeans.modules.openide.util.AWTBridge.getDefault ().createPopupPresenter (this); } /* Returns a Component that presents the Action, that implements this * interface, in a ToolBar. * @return the Component representation for the Action */ public java.awt.Component getToolbarPresenter() { return org.netbeans.modules.openide.util.AWTBridge.getDefault ().createToolbarPresenter (this); } /** Get the current state. * @return true if on */ public boolean getBooleanState() { return getProperty (PROP_BOOLEAN_STATE).equals (Boolean.TRUE); } /** Set the current state. * Fires a change event, which should be used to affect other components when * its state is toggled. * @param value true to turn on, false to turn off */ public void setBooleanState(boolean value) { Boolean newValue = value ? Boolean.TRUE : Boolean.FALSE; Boolean oldValue = (Boolean)putProperty (PROP_BOOLEAN_STATE, newValue); firePropertyChange(PROP_BOOLEAN_STATE, oldValue, newValue); } /* Initializes its own properties (and let superclass initialize * too). */ protected void initialize () { putProperty(PROP_BOOLEAN_STATE, Boolean.TRUE); super.initialize(); } /* Implementation of method of javax.swing.Action interface. * Changes the boolean state. * * @param ev ignored */ public void actionPerformed (java.awt.event.ActionEvent ev) { setBooleanState (!getBooleanState ()); } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.