bibliothek.gui.dock.common.action.CRadioButton Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docking-frames-common Show documentation
Show all versions of docking-frames-common Show documentation
DockingFrames is an open source Java Swing docking framework, licenced under LGPL 2.1.
This is the same distribution as the original distribution (http://www.docking-frames.org/), only reinstalled in maven
/*
* Bibliothek - DockingFrames
* Library built on Java/Swing, allows the user to "drag and drop"
* panels containing any Swing-Component the developer likes to add.
*
* Copyright (C) 2007 Benjamin Sigg
*
* This library 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.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Benjamin Sigg
* [email protected]
* CH - Switzerland
*/
package bibliothek.gui.dock.common.action;
import java.util.Set;
import javax.swing.Icon;
import javax.swing.JRadioButton;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.action.SelectableDockAction;
import bibliothek.gui.dock.common.action.core.CommonSimpleRadioAction;
import bibliothek.gui.dock.common.intern.action.CSelectableAction;
import bibliothek.gui.dock.event.SelectableDockActionListener;
import bibliothek.util.FrameworkOnly;
/**
* An action which behaves like a {@link JRadioButton}.
* Several {@link CRadioButton}s can be added to a {@link CRadioGroup}, only
* one {@link CRadioButton} of such a group will be selected.
* @author Benjamin Sigg
*/
public abstract class CRadioButton extends CSelectableAction {
/** group to which this button belongs */
private CRadioGroup group;
/**
* Creates a new radiobutton
*/
public CRadioButton() {
super( null );
init( new CommonSimpleRadioAction( this ));
}
/**
* Creates a new radiobutton using action
as internal representation
* @param action the internal representation, can be null
in which case
* subclasses should call {@link #init(CommonSimpleRadioAction)}
*/
protected CRadioButton( CommonSimpleRadioAction action ){
super( null );
if( action != null ){
init( action );
}
}
/**
* Creates a new radiobutton
* @param text the text of this button
* @param icon the icon of this button
*/
public CRadioButton( String text, Icon icon ){
this();
setText( text );
setIcon( icon );
}
@Override
protected void init( CommonSimpleRadioAction action ) {
super.init( action );
action.addSelectableListener( new SelectableDockActionListener(){
public void selectedChanged( SelectableDockAction action, Set dockables ) {
if( isSelected() && group != null )
group.selected( CRadioButton.this );
}
});
}
/**
* Sets the group to which this button belongs.
* @param group the group
*/
@FrameworkOnly
void setGroup( CRadioGroup group ) {
this.group = group;
}
}