-/*******************************************************************************\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
+/*******************************************************************************
+ * 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;
-\r
-import java.awt.Color;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.awt.event.MouseEvent;\r
-import java.awt.event.MouseListener;\r
-\r
-import javax.swing.BorderFactory;\r
-import javax.swing.JSlider;\r
-\r
-import org.simantics.scenegraph.ExportableWidget.InputWidget;\r
-import org.simantics.scenegraph.ExportableWidget.OutputWidget;\r
-\r
-@OutputWidget({"value", "min", "max"})\r
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.JSlider;
+
+import org.simantics.scenegraph.ExportableWidget.InputWidget;
+import org.simantics.scenegraph.ExportableWidget.OutputWidget;
+
+@OutputWidget({"value", "min", "max"})
@InputWidget("value")
public class SliderNode extends ComponentNode<JSlider> {
- private static final long serialVersionUID = 3161843367263793336L;\r
+ private static final long serialVersionUID = 3161843367263793336L;
protected transient ActionListener actionListener = null;
-\r
- // Necessary for widget ui:\r
- protected Integer value = 0;\r
- protected Integer min = 0;\r
- protected Integer max = 0;\r
- \r
+
+ // Necessary for widget ui:
+ protected Integer value = 0;
+ protected Integer min = 0;
+ protected Integer max = 0;
+
+ @ClientSide
+ public void setValue(Integer value) {
+ this.value = value;
+ if(component != null) {
+ if(!component.getValueIsAdjusting()) { // FIXME: propably does not work
+// System.out.println("valueIsAdjusting == false");
+ component.setValue(value);
+ } else {
+ // TODO: cache value?
+// System.out.println("valueIsAdjusting == true");
+ }
+ }
+ }
+
+ @Override
+ public void init() {
+ component = new JSlider();
+ component.setPaintTicks(true);
+ component.addMouseListener(new MouseListener() {
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ if(component.getValueIsAdjusting())
+ valueChanged(component.getValue());
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }});
+ super.init();
+ }
+
+ @ServerSide
+ protected void valueChanged(Integer value) {
+ if(actionListener != null) { // FIXME: there might not be a component on the server side
+ ActionEvent e = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, ""+value);
+ actionListener.actionPerformed(e);
+ }
+ }
+
+ public void setActionListener(ActionListener actionListener) {
+ this.actionListener = actionListener;
+ }
+
+ @PropertySetter("Value Extent")
+ @ClientSide
+ public void setExtent(Integer extent) {
+ if(component != null)
+ component.setExtent(extent);
+ }
+
+ @PropertySetter("Min Value")
+ @ClientSide
+ public void setMinimum(Integer min) {
+ this.min = min;
+ if(component != null)
+ component.setMinimum(min);
+ }
+
+ @PropertySetter("Max Value")
+ @ClientSide
+ public void setMaximum(Integer max) {
+ this.max = max;
+ if(component != null)
+ component.setMaximum(max);
+ }
+
+ @ClientSide
+ public void setOrientation(Integer orientation) {
+ if(component != null) {
+ component.setOrientation(orientation);
+ }
+ }
+
+ @ClientSide
+ public void setTitle(String string) {
+ if(component != null)
+ component.setBorder(BorderFactory.createTitledBorder(string));
+ }
+
+ @PropertySetter("Major Tick Spacing")
+ @ClientSide
+ public void setMajorTickSpacing(Integer i) {
+ if(component != null) {
+ component.setLabelTable(component.createStandardLabels(i, component.getMinimum()));
+ component.setMajorTickSpacing(i);
+ }
+ }
+
+ @PropertySetter("Minor Tick Spacing")
+ @ClientSide
+ public void setMinorTickSpacing(Integer i) {
+ if(component != null) {
+ component.setMinorTickSpacing(i);
+ }
+ }
+
+ @PropertySetter("Paint Ticks")
+ @ClientSide
+ public void setPaintTicks(Boolean b) {
+ if(component != null) {
+ component.setPaintTicks(b);
+ component.updateUI();
+ }
+ }
+
+ @PropertySetter("Paint Labels")
+ @ClientSide
+ public void setPaintLabels(Boolean b) {
+ if(component != null)
+ component.setPaintLabels(b);
+ }
+
+ @PropertySetter("Paint Track")
+ @ClientSide
+ public void setPaintTrack(Boolean b) {
+ if(component != null)
+ component.setPaintTrack(b);
+ }
+
+ @PropertySetter("Snap To Ticks")
+ @ClientSide
+ public void setSnapToTicks(Boolean b) {
+ if(component != null)
+ component.setSnapToTicks(b);
+ }
+
+ @PropertySetter("Inverted")
+ @ClientSide
+ public void setInverted(Boolean b) {
+ if(component != null)
+ component.setInverted(b);
+ }
+
+ @PropertySetter("Background Color")
@ClientSide
- public void setValue(Integer value) {\r
- this.value = value;\r
- if(component != null) {\r
- if(!component.getValueIsAdjusting()) { // FIXME: propably does not work\r
-// System.out.println("valueIsAdjusting == false");\r
- component.setValue(value);\r
- } else {\r
- // TODO: cache value?\r
-// System.out.println("valueIsAdjusting == true"); \r
- }\r
- }\r
- }\r
-
- @Override\r
- public void init() {\r
- component = new JSlider();\r
- component.setPaintTicks(true);\r
- component.addMouseListener(new MouseListener() {\r
-\r
- @Override\r
- public void mouseClicked(MouseEvent e) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public void mousePressed(MouseEvent e) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public void mouseReleased(MouseEvent e) {\r
- if(component.getValueIsAdjusting())\r
- valueChanged(component.getValue());\r
- }\r
-\r
- @Override\r
- public void mouseEntered(MouseEvent e) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public void mouseExited(MouseEvent e) {\r
- // TODO Auto-generated method stub\r
- \r
- }});\r
- super.init();\r
- }\r
- \r
- @ServerSide\r
- protected void valueChanged(Integer value) {\r
- if(actionListener != null) { // FIXME: there might not be a component on the server side\r
- ActionEvent e = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, ""+value);\r
- actionListener.actionPerformed(e);\r
- }\r
- }\r
- \r
- public void setActionListener(ActionListener actionListener) {\r
- this.actionListener = actionListener;\r
- }\r
-\r
- @PropertySetter("Value Extent")\r
- @ClientSide\r
- public void setExtent(Integer extent) {\r
- if(component != null)\r
- component.setExtent(extent);\r
- }\r
- \r
- @PropertySetter("Min Value")\r
- @ClientSide\r
- public void setMinimum(Integer min) {\r
- this.min = min;\r
- if(component != null)\r
- component.setMinimum(min);\r
- }\r
- \r
- @PropertySetter("Max Value")\r
- @ClientSide\r
- public void setMaximum(Integer max) {\r
- this.max = max;\r
- if(component != null)\r
- component.setMaximum(max);\r
- }\r
- \r
- @ClientSide\r
- public void setOrientation(Integer orientation) {\r
- if(component != null) {\r
- component.setOrientation(orientation);\r
- }\r
- }\r
-\r
- @ClientSide\r
- public void setTitle(String string) {\r
- if(component != null)\r
- component.setBorder(BorderFactory.createTitledBorder(string));\r
- }\r
-\r
- @PropertySetter("Major Tick Spacing")\r
- @ClientSide\r
- public void setMajorTickSpacing(Integer i) {\r
- if(component != null) {\r
- component.setLabelTable(component.createStandardLabels(i, component.getMinimum()));\r
- component.setMajorTickSpacing(i);\r
- }\r
- }\r
-\r
- @PropertySetter("Minor Tick Spacing")\r
- @ClientSide\r
- public void setMinorTickSpacing(Integer i) {\r
- if(component != null) {\r
- component.setMinorTickSpacing(i);\r
- }\r
- }\r
-\r
- @PropertySetter("Paint Ticks")\r
- @ClientSide\r
- public void setPaintTicks(Boolean b) {\r
- if(component != null) {\r
- component.setPaintTicks(b);\r
- component.updateUI();\r
- }\r
- }\r
- \r
- @PropertySetter("Paint Labels")\r
- @ClientSide\r
- public void setPaintLabels(Boolean b) {\r
- if(component != null)\r
- component.setPaintLabels(b);\r
- }\r
- \r
- @PropertySetter("Paint Track")\r
- @ClientSide\r
- public void setPaintTrack(Boolean b) {\r
- if(component != null)\r
- component.setPaintTrack(b);\r
- }\r
- \r
- @PropertySetter("Snap To Ticks")\r
- @ClientSide\r
- public void setSnapToTicks(Boolean b) {\r
- if(component != null)\r
- component.setSnapToTicks(b);\r
- }\r
- \r
- @PropertySetter("Inverted")\r
- @ClientSide\r
- public void setInverted(Boolean b) {\r
- if(component != null)\r
- component.setInverted(b);\r
- }\r
- \r
- @PropertySetter("Background Color")\r
- @ClientSide\r
- public void setBackgroundColor(Color color) {\r
- // Not supported (For some reason this hides the slider)\r
- }\r
- \r
- public String widgetGet(String name) {\r
- if("value".equals(name)) {\r
- return ""+value;\r
- } else if("min".equals(name)) {\r
- return ""+min;\r
- } else if("max".equals(name)) {\r
- return ""+max;\r
- }\r
- return null;\r
- }\r
- \r
- public void widgetSet(String name, String value) {\r
- if("value".equals(name)) {\r
- this.value = Integer.parseInt(value);\r
- valueChanged(this.value);\r
- }\r
- }\r
+ public void setBackgroundColor(Color color) {
+ // Not supported (For some reason this hides the slider)
+ }
+
+ public String widgetGet(String name) {
+ if("value".equals(name)) {
+ return ""+value;
+ } else if("min".equals(name)) {
+ return ""+min;
+ } else if("max".equals(name)) {
+ return ""+max;
+ }
+ return null;
+ }
+
+ public void widgetSet(String name, String value) {
+ if("value".equals(name)) {
+ this.value = Integer.parseInt(value);
+ valueChanged(this.value);
+ }
+ }
}