-/*******************************************************************************\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.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.Cursor;\r
-import java.awt.Graphics2D;\r
-import java.awt.Shape;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import javax.swing.JToggleButton;\r
-\r
-import org.simantics.scenegraph.utils.DummyComponent;\r
-\r
-public class JBooleanToggleValueNode extends ComponentNode<JToggleButton> implements ActionListener {\r
- /**\r
- * \r
- */\r
- private static final long serialVersionUID = 3255791584573492072L;\r
-\r
- protected static final BasicStroke STROKE = new BasicStroke(1.0f);\r
- protected static final Rectangle2D BOUNDS = new Rectangle2D.Double(-10, -10, 20, 20);\r
-\r
- protected Boolean value = null;\r
- protected transient Set<ActionListener> actionListeners = new HashSet<ActionListener>();\r
-\r
- @SyncField("value")\r
- public void setValue(Boolean value) {\r
- this.value = value;\r
- if(component instanceof JToggleButton) {\r
- ((JToggleButton)component).setSelected(value == null ? false : value);\r
- }\r
- }\r
- \r
- @SyncField("transform")\r
- public void setTransform(AffineTransform transform) {\r
- assert(transform != null);\r
- this.transform = transform;\r
- this.transform.translate(-10, -10);\r
- }\r
-\r
- @Override\r
- public void render(Graphics2D g2d) {\r
- if (component != null) {\r
- int width = (int)BOUNDS.getWidth();\r
- int height = (int)BOUNDS.getHeight();\r
- \r
- AffineTransform ot = g2d.getTransform();\r
- double sx = 1;\r
- double sy = 1;\r
- if(transform != null) {\r
- g2d.transform(transform);\r
- sx = g2d.getTransform().getScaleX();\r
- sy = g2d.getTransform().getScaleY();\r
- g2d.scale(1/sx, 1/sy);\r
- }\r
- component.setSize((int)(width*sx), (int)(height*sy));\r
- component.paint(g2d);\r
- \r
- g2d.setTransform(ot);\r
- }\r
- }\r
- \r
- /**\r
- * Helper method to be used inside MonitorClass\r
- * @return\r
- */\r
- public static Shape getOutline() {\r
- return BOUNDS;\r
- }\r
- \r
- @Override\r
- public Rectangle2D getBoundsInLocal() {\r
- return BOUNDS;\r
- }\r
-\r
- /**\r
- * ClientSide method for handling event and transforming it\r
- * NOTE: This is just a wrapper method\r
- */\r
- @Override\r
- public void actionPerformed(ActionEvent e) {\r
- Boolean s = component.isSelected();\r
- performAction(new ActionEvent(new DummyComponent(), ActionEvent.ACTION_PERFORMED, ""+s));\r
- }\r
- \r
- /**\r
- * ServerSide method for calling the actionlisteners\r
- * @param e\r
- */\r
- @ServerSide\r
- protected void performAction(ActionEvent e) {\r
- for(ActionListener listener : actionListeners)\r
- listener.actionPerformed(e);\r
- }\r
- \r
- public void addActionListener(ActionListener l) {\r
- actionListeners.add(l);\r
- }\r
- \r
- public void removeActionListener(ActionListener l) {\r
- actionListeners.remove(l);\r
- }\r
- \r
- @Override\r
- public void init() {\r
- Boolean s = value == null ? false : value;\r
- component = new JToggleButton(null, null, s);\r
- component.setCursor(new Cursor(Cursor.HAND_CURSOR));\r
- component.addActionListener(this);\r
- component.setBackground(Color.RED);\r
- super.init();\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.BasicStroke;
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.swing.JToggleButton;
+
+import org.simantics.scenegraph.utils.DummyComponent;
+
+public class JBooleanToggleValueNode extends ComponentNode<JToggleButton> implements ActionListener {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3255791584573492072L;
+
+ protected static final BasicStroke STROKE = new BasicStroke(1.0f);
+ protected static final Rectangle2D BOUNDS = new Rectangle2D.Double(-10, -10, 20, 20);
+
+ protected Boolean value = null;
+ protected transient Set<ActionListener> actionListeners = new HashSet<ActionListener>();
+
+ @SyncField("value")
+ public void setValue(Boolean value) {
+ this.value = value;
+ if(component instanceof JToggleButton) {
+ ((JToggleButton)component).setSelected(value == null ? false : value);
+ }
+ }
+
+ @SyncField("transform")
+ public void setTransform(AffineTransform transform) {
+ assert(transform != null);
+ this.transform = transform;
+ this.transform.translate(-10, -10);
+ }
+
+ @Override
+ public void render(Graphics2D g2d) {
+ if (component != null) {
+ int width = (int)BOUNDS.getWidth();
+ int height = (int)BOUNDS.getHeight();
+
+ AffineTransform ot = g2d.getTransform();
+ double sx = 1;
+ double sy = 1;
+ if(transform != null) {
+ g2d.transform(transform);
+ sx = g2d.getTransform().getScaleX();
+ sy = g2d.getTransform().getScaleY();
+ g2d.scale(1/sx, 1/sy);
+ }
+ component.setSize((int)(width*sx), (int)(height*sy));
+ component.paint(g2d);
+
+ g2d.setTransform(ot);
+ }
+ }
+
+ /**
+ * Helper method to be used inside MonitorClass
+ * @return
+ */
+ public static Shape getOutline() {
+ return BOUNDS;
+ }
+
+ @Override
+ public Rectangle2D getBoundsInLocal() {
+ return BOUNDS;
+ }
+
+ /**
+ * ClientSide method for handling event and transforming it
+ * NOTE: This is just a wrapper method
+ */
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Boolean s = component.isSelected();
+ performAction(new ActionEvent(new DummyComponent(), ActionEvent.ACTION_PERFORMED, ""+s));
+ }
+
+ /**
+ * ServerSide method for calling the actionlisteners
+ * @param e
+ */
+ @ServerSide
+ protected void performAction(ActionEvent e) {
+ for(ActionListener listener : actionListeners)
+ listener.actionPerformed(e);
+ }
+
+ public void addActionListener(ActionListener l) {
+ actionListeners.add(l);
+ }
+
+ public void removeActionListener(ActionListener l) {
+ actionListeners.remove(l);
+ }
+
+ @Override
+ public void init() {
+ Boolean s = value == null ? false : value;
+ component = new JToggleButton(null, null, s);
+ component.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ component.addActionListener(this);
+ component.setBackground(Color.RED);
+ super.init();
+ }
+}