Package org.dyno.visual.swing.widgets

Source Code of org.dyno.visual.swing.widgets.JRadioButtonAdapter

/************************************************************************************
* Copyright (c) 2008 William Chen.                                                 *
*                                                                                  *
* All rights reserved. This program and the accompanying materials are made        *
* available under the terms of the Eclipse Public License v1.0 which accompanies   *
* this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html *
*                                                                                  *
* Use is subject to the terms of Eclipse Public License v1.0.                      *
*                                                                                  *
* Contributors:                                                                    *
*     William Chen - initial API and implementation.                               *
************************************************************************************/

package org.dyno.visual.swing.widgets;

import javax.swing.ButtonGroup;
import javax.swing.DefaultButtonModel;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton.ToggleButtonModel;

import org.dyno.visual.swing.plugin.spi.IAdapter;
import org.dyno.visual.swing.plugin.spi.InvisibleAdapter;

@SuppressWarnings("unchecked")
public class JRadioButtonAdapter extends TextWidgetAdapter {

  @Override
  public Class getWidgetClass() {
    return JRadioButton.class;
  }

  @Override
  public IAdapter getParent() {
    JRadioButton jb=(JRadioButton)getWidget();
    ToggleButtonModel dbm=(ToggleButtonModel) jb.getModel();
    ButtonGroup bg=dbm.getGroup();
    if (bg != null) {
      for (InvisibleAdapter invisible : getRootAdapter().getInvisibles()) {
        if (invisible instanceof ButtonGroupAdapter) {
          if (bg == ((ButtonGroupAdapter) invisible).getButtonGroup())
            return invisible;
        }
      }
    }
    return super.getParent();
  }
  @Override
  public void deleteNotify() {
    JRadioButton jb = (JRadioButton) getWidget();
    DefaultButtonModel dbm = (DefaultButtonModel) jb.getModel();
    ButtonGroup bg = dbm.getGroup();
    if(bg!=null){
      bg.remove(jb);
    }
  }
}

TOP

Related Classes of org.dyno.visual.swing.widgets.JRadioButtonAdapter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.