1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.scenegraph.swing;
14 import java.awt.Color;
16 import java.awt.Graphics2D;
17 import java.awt.event.ActionEvent;
18 import java.awt.event.ActionListener;
19 import java.awt.geom.Rectangle2D;
20 import java.util.HashSet;
23 import javax.swing.JRadioButton;
25 public class RadioButtonNode extends ComponentNode<JRadioButton> implements ActionListener {
27 private static final long serialVersionUID = 3161843367263793336L;
29 protected String text;
30 protected Font font = null;
31 protected Color color = null;
33 protected transient Set<ActionListener> actionListeners = new HashSet<ActionListener>();
36 public void render(Graphics2D g2d) {
37 if(component != null && component.getText() != null && component.getText().equals(text) == false)
38 component.setText(text);
43 public void setBounds(Rectangle2D bounds) {
48 public void setText(String text) {
53 public void setFont(Font font) {
55 if (component != null) {
56 setComponentFont(font);
61 public void setColor(Color color) {
63 if (component != null) {
64 component.setForeground(color);
68 public Font getFont() {
74 public void actionPerformed(ActionEvent e) {
75 for(ActionListener listener : actionListeners)
76 listener.actionPerformed(e);
79 public void addActionListener(ActionListener l) {
80 actionListeners.add(l);
83 public void removeActionListener(ActionListener l) {
84 actionListeners.remove(l);
89 component = new JRadioButton();
90 component.addActionListener(this);