--- /dev/null
+/*******************************************************************************\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
+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
+@InputWidget("value")
+public class SliderNode extends ComponentNode<JSlider> {
+ private static final long serialVersionUID = 3161843367263793336L;\r
+ 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
+ @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
+}