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.util.HashSet;
22 import javax.swing.JButton;
24 public class ButtonNode extends ComponentNode<JButton> implements ActionListener {
26 private static final long serialVersionUID = 3161843367263793336L;
28 protected String text;
29 protected Font font = null;
30 protected Color color = null;
32 protected transient Set<ActionListener> actionListeners = new HashSet<ActionListener>();
35 public void render(Graphics2D g2d) {
36 if (component != null)
37 component.setText(text);
42 public void setText(String text) {
46 @PropertySetter("Font")
48 public void setFont(Font font) {
50 if (component != null) {
51 setComponentFont(font);
55 @PropertySetter("Color")
57 public void setColor(Color color) {
59 if (component != null) {
60 component.setForeground(color);
64 public Font getFont() {
70 public void actionPerformed(ActionEvent e) {
71 for(ActionListener listener : actionListeners)
72 listener.actionPerformed(e);
75 public void addActionListener(ActionListener l) {
76 actionListeners.add(l);
79 public void removeActionListener(ActionListener l) {
80 actionListeners.remove(l);
85 component = new JButton();
86 component.addActionListener(this);