]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/RadioButtonNode.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph.swing / src / org / simantics / scenegraph / swing / RadioButtonNode.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.scenegraph.swing;
13
14 import java.awt.Color;\r
15 import java.awt.Font;\r
16 import java.awt.Graphics2D;
17 import java.awt.event.ActionEvent;
18 import java.awt.event.ActionListener;\r
19 import java.awt.geom.Rectangle2D;\r
20 import java.util.HashSet;
21 import java.util.Set;
22 \r
23 import javax.swing.JRadioButton;\r
24
25 public class RadioButtonNode extends ComponentNode<JRadioButton> implements ActionListener {
26
27     private static final long serialVersionUID = 3161843367263793336L;
28
29     protected String text;
30     protected Font font = null;\r
31     protected Color color = null;\r
32
33     protected transient Set<ActionListener> actionListeners = new HashSet<ActionListener>();\r
34     
35     @Override\r
36     public void render(Graphics2D g2d) {\r
37         if(component != null && component.getText() != null && component.getText().equals(text) == false)\r
38                 component.setText(text);\r
39         super.render(g2d);\r
40     }\r
41
42     @SyncField("bounds")\r
43     public void setBounds(Rectangle2D bounds) {\r
44         this.bounds = bounds;\r
45     }\r
46
47     @SyncField("text")
48     public void setText(String text) {
49         this.text = text;
50     }\r
51     
52     @SyncField("font")\r
53     public void setFont(Font font) {\r
54         this.font = font;\r
55         if (component != null) {\r
56             setComponentFont(font);\r
57         }\r
58     }\r
59 \r
60     @SyncField("color")\r
61     public void setColor(Color color) {\r
62         this.color = color;\r
63         if (component != null) {\r
64             component.setForeground(color);\r
65         }\r
66     }\r
67     \r
68     public Font getFont() {\r
69         return font;\r
70     }\r
71
72     @ServerSide
73         @Override
74         public void actionPerformed(ActionEvent e) {
75                 for(ActionListener listener : actionListeners)
76                         listener.actionPerformed(e);
77         }
78         
79     public void addActionListener(ActionListener l) {
80         actionListeners.add(l);
81     }
82     
83     public void removeActionListener(ActionListener l) {
84         actionListeners.remove(l);
85     }\r
86
87     @Override\r
88     public void init() {\r
89         component = new JRadioButton();\r
90                 component.addActionListener(this);\r
91         super.init();\r
92     }
93 }