-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.scenegraph.swing;\r
-\r
-import java.awt.Color;\r
-import java.awt.Font;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import javax.swing.Box;\r
-import javax.swing.BoxLayout;\r
-import javax.swing.JRadioButton;\r
-\r
-public class RadioButtonListNode extends ComponentNode<Box> implements ActionListener {\r
- /**\r
- * \r
- */\r
- private static final long serialVersionUID = 7073028693751719102L;\r
-\r
- protected boolean editable = true;\r
- protected Object value = "";\r
- protected String tooltip = "";\r
- protected double borderWidth = 0;\r
-\r
- protected transient ActionListener actionListener = null;\r
-\r
- protected Font font = null;\r
- protected Color color = null;\r
- protected Map<String, JRadioButton> items = new HashMap<String, JRadioButton>();\r
- \r
- @Override\r
- public String toString() {\r
- return super.toString() + "[editable=" + editable + ", value=" + value + "]";\r
- }\r
- \r
- @Override\r
- public void init() {\r
- component = new Box(BoxLayout.Y_AXIS);\r
- component.setEnabled(editable);\r
- component.setLocation(0, 0);\r
- \r
- super.init();\r
- }\r
-\r
- @SyncField("items")\r
- public void setItems(List<String> items) {\r
- this.items.clear();\r
- component.removeAll();\r
- for(String item : items) {\r
- JRadioButton btn = new JRadioButton();\r
- btn.setText(item);\r
- btn.addActionListener(this);\r
- component.add(btn);\r
- this.items.put(item, btn);\r
- }\r
- if(items.size() > 0)\r
- ((JRadioButton)component.getComponent(0)).setSelected(true); // First item selected\r
-\r
- component.doLayout();\r
- }\r
-\r
- @SyncField("editable")\r
- public void setEditable(boolean value) {\r
- this.editable = value;\r
-\r
- if(component != null) {\r
- component.setEnabled(value);\r
- }\r
- }\r
-\r
- @PropertySetter("Stroke Width")\r
- @SyncField("borderWidth")\r
- public void setBorderWidth(Float borderWidth) {\r
- this.borderWidth = borderWidth;\r
-// if(component != null) {\r
-// ((TextField)component).setBorder(borderWidth);\r
-// }\r
- }\r
-\r
- @SyncField("value")\r
- public void setValue(Object value) {\r
- this.value = value;\r
- // RemoteViewer does not have component initialized\r
- if (component != null && value != null) {\r
- JRadioButton b = items.get(value);\r
- if(b != null) {\r
- for(JRadioButton i : items.values()) {\r
- if(i == b) {\r
- i.setSelected(true);\r
- } else {\r
- i.setSelected(false);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- @SyncField("tooltip")\r
- public void setToolTipText(String tooltip) {\r
- this.tooltip = tooltip;\r
- if (component != null) {\r
- component.setToolTipText(tooltip);\r
- }\r
- }\r
-\r
- @PropertySetter("Font")\r
- @SyncField("font")\r
- public void setFont(Font font) {\r
- this.font = font;\r
- if (component != null) {\r
- setComponentFont(font);\r
- }\r
- }\r
-\r
- @PropertySetter("Color")\r
- @SyncField("color")\r
- public void setColor(Color color) {\r
- this.color = color;\r
- if (component != null) {\r
- component.setForeground(color);\r
- }\r
- }\r
-\r
- public Object getValue() {\r
- return value;\r
- }\r
-\r
- public Font getFont() {\r
- return font;\r
- }\r
- \r
- public void setActionListener(ActionListener actionListener) {\r
- this.actionListener = actionListener;\r
- }\r
-\r
- /**\r
- * Wrapper method to send event to server side\r
- * \r
- * @param e\r
- */\r
- @ServerSide\r
- public void performAction(ActionEvent e) {\r
- if (actionListener != null) {\r
- //System.out.println("MonitorNode.performAction(" + e + ")");\r
- actionListener.actionPerformed(e);\r
- }\r
- }\r
- @Override\r
- public void actionPerformed(ActionEvent e) {\r
- JRadioButton b = items.get(e.getActionCommand());\r
- if(b != null) {\r
- for(JRadioButton i : items.values()) {\r
- if(i == b) {\r
- i.setSelected(true);\r
- } else {\r
- i.setSelected(false);\r
- }\r
- }\r
- }\r
- performAction(e);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.scenegraph.swing;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JRadioButton;
+
+public class RadioButtonListNode extends ComponentNode<Box> implements ActionListener {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7073028693751719102L;
+
+ protected boolean editable = true;
+ protected Object value = "";
+ protected String tooltip = "";
+ protected double borderWidth = 0;
+
+ protected transient ActionListener actionListener = null;
+
+ protected Font font = null;
+ protected Color color = null;
+ protected Map<String, JRadioButton> items = new HashMap<String, JRadioButton>();
+
+ @Override
+ public String toString() {
+ return super.toString() + "[editable=" + editable + ", value=" + value + "]";
+ }
+
+ @Override
+ public void init() {
+ component = new Box(BoxLayout.Y_AXIS);
+ component.setEnabled(editable);
+ component.setLocation(0, 0);
+
+ super.init();
+ }
+
+ @SyncField("items")
+ public void setItems(List<String> items) {
+ this.items.clear();
+ component.removeAll();
+ for(String item : items) {
+ JRadioButton btn = new JRadioButton();
+ btn.setText(item);
+ btn.addActionListener(this);
+ component.add(btn);
+ this.items.put(item, btn);
+ }
+ if(items.size() > 0)
+ ((JRadioButton)component.getComponent(0)).setSelected(true); // First item selected
+
+ component.doLayout();
+ }
+
+ @SyncField("editable")
+ public void setEditable(boolean value) {
+ this.editable = value;
+
+ if(component != null) {
+ component.setEnabled(value);
+ }
+ }
+
+ @PropertySetter("Stroke Width")
+ @SyncField("borderWidth")
+ public void setBorderWidth(Float borderWidth) {
+ this.borderWidth = borderWidth;
+// if(component != null) {
+// ((TextField)component).setBorder(borderWidth);
+// }
+ }
+
+ @SyncField("value")
+ public void setValue(Object value) {
+ this.value = value;
+ // RemoteViewer does not have component initialized
+ if (component != null && value != null) {
+ JRadioButton b = items.get(value);
+ if(b != null) {
+ for(JRadioButton i : items.values()) {
+ if(i == b) {
+ i.setSelected(true);
+ } else {
+ i.setSelected(false);
+ }
+ }
+ }
+ }
+ }
+
+ @SyncField("tooltip")
+ public void setToolTipText(String tooltip) {
+ this.tooltip = tooltip;
+ if (component != null) {
+ component.setToolTipText(tooltip);
+ }
+ }
+
+ @PropertySetter("Font")
+ @SyncField("font")
+ public void setFont(Font font) {
+ this.font = font;
+ if (component != null) {
+ setComponentFont(font);
+ }
+ }
+
+ @PropertySetter("Color")
+ @SyncField("color")
+ public void setColor(Color color) {
+ this.color = color;
+ if (component != null) {
+ component.setForeground(color);
+ }
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public Font getFont() {
+ return font;
+ }
+
+ public void setActionListener(ActionListener actionListener) {
+ this.actionListener = actionListener;
+ }
+
+ /**
+ * Wrapper method to send event to server side
+ *
+ * @param e
+ */
+ @ServerSide
+ public void performAction(ActionEvent e) {
+ if (actionListener != null) {
+ //System.out.println("MonitorNode.performAction(" + e + ")");
+ actionListener.actionPerformed(e);
+ }
+ }
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JRadioButton b = items.get(e.getActionCommand());
+ if(b != null) {
+ for(JRadioButton i : items.values()) {
+ if(i == b) {
+ i.setSelected(true);
+ } else {
+ i.setSelected(false);
+ }
+ }
+ }
+ performAction(e);
+ }
+
+}