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.event.ActionEvent;
17 import java.awt.event.ActionListener;
18 import java.util.HashMap;
19 import java.util.List;
22 import javax.swing.Box;
23 import javax.swing.BoxLayout;
24 import javax.swing.JRadioButton;
26 public class RadioButtonListNode extends ComponentNode<Box> implements ActionListener {
30 private static final long serialVersionUID = 7073028693751719102L;
32 protected boolean editable = true;
33 protected Object value = "";
34 protected String tooltip = "";
35 protected double borderWidth = 0;
37 protected transient ActionListener actionListener = null;
39 protected Font font = null;
40 protected Color color = null;
41 protected Map<String, JRadioButton> items = new HashMap<String, JRadioButton>();
44 public String toString() {
45 return super.toString() + "[editable=" + editable + ", value=" + value + "]";
50 component = new Box(BoxLayout.Y_AXIS);
51 component.setEnabled(editable);
52 component.setLocation(0, 0);
58 public void setItems(List<String> items) {
60 component.removeAll();
61 for(String item : items) {
62 JRadioButton btn = new JRadioButton();
64 btn.addActionListener(this);
66 this.items.put(item, btn);
69 ((JRadioButton)component.getComponent(0)).setSelected(true); // First item selected
74 @SyncField("editable")
75 public void setEditable(boolean value) {
76 this.editable = value;
78 if(component != null) {
79 component.setEnabled(value);
83 @PropertySetter("Stroke Width")
84 @SyncField("borderWidth")
85 public void setBorderWidth(Float borderWidth) {
86 this.borderWidth = borderWidth;
87 // if(component != null) {
88 // ((TextField)component).setBorder(borderWidth);
93 public void setValue(Object value) {
95 // RemoteViewer does not have component initialized
96 if (component != null && value != null) {
97 JRadioButton b = items.get(value);
99 for(JRadioButton i : items.values()) {
103 i.setSelected(false);
110 @SyncField("tooltip")
111 public void setToolTipText(String tooltip) {
112 this.tooltip = tooltip;
113 if (component != null) {
114 component.setToolTipText(tooltip);
118 @PropertySetter("Font")
120 public void setFont(Font font) {
122 if (component != null) {
123 setComponentFont(font);
127 @PropertySetter("Color")
129 public void setColor(Color color) {
131 if (component != null) {
132 component.setForeground(color);
136 public Object getValue() {
140 public Font getFont() {
144 public void setActionListener(ActionListener actionListener) {
145 this.actionListener = actionListener;
149 * Wrapper method to send event to server side
154 public void performAction(ActionEvent e) {
155 if (actionListener != null) {
156 //System.out.println("MonitorNode.performAction(" + e + ")");
157 actionListener.actionPerformed(e);
161 public void actionPerformed(ActionEvent e) {
162 JRadioButton b = items.get(e.getActionCommand());
164 for(JRadioButton i : items.values()) {
168 i.setSelected(false);