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;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.awt.event.MouseEvent;
18 import java.awt.event.MouseListener;
20 import javax.swing.BorderFactory;
21 import javax.swing.JSlider;
23 import org.simantics.scenegraph.ExportableWidget.InputWidget;
24 import org.simantics.scenegraph.ExportableWidget.OutputWidget;
26 @OutputWidget({"value", "min", "max"})
28 public class SliderNode extends ComponentNode<JSlider> {
29 private static final long serialVersionUID = 3161843367263793336L;
30 protected transient ActionListener actionListener = null;
32 // Necessary for widget ui:
33 protected Integer value = 0;
34 protected Integer min = 0;
35 protected Integer max = 0;
38 public void setValue(Integer value) {
40 if(component != null) {
41 if(!component.getValueIsAdjusting()) { // FIXME: propably does not work
42 // System.out.println("valueIsAdjusting == false");
43 component.setValue(value);
46 // System.out.println("valueIsAdjusting == true");
53 component = new JSlider();
54 component.setPaintTicks(true);
55 component.addMouseListener(new MouseListener() {
58 public void mouseClicked(MouseEvent e) {
59 // TODO Auto-generated method stub
64 public void mousePressed(MouseEvent e) {
65 // TODO Auto-generated method stub
70 public void mouseReleased(MouseEvent e) {
71 if(component.getValueIsAdjusting())
72 valueChanged(component.getValue());
76 public void mouseEntered(MouseEvent e) {
77 // TODO Auto-generated method stub
82 public void mouseExited(MouseEvent e) {
83 // TODO Auto-generated method stub
90 protected void valueChanged(Integer value) {
91 if(actionListener != null) { // FIXME: there might not be a component on the server side
92 ActionEvent e = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, ""+value);
93 actionListener.actionPerformed(e);
97 public void setActionListener(ActionListener actionListener) {
98 this.actionListener = actionListener;
101 @PropertySetter("Value Extent")
103 public void setExtent(Integer extent) {
104 if(component != null)
105 component.setExtent(extent);
108 @PropertySetter("Min Value")
110 public void setMinimum(Integer min) {
112 if(component != null)
113 component.setMinimum(min);
116 @PropertySetter("Max Value")
118 public void setMaximum(Integer max) {
120 if(component != null)
121 component.setMaximum(max);
125 public void setOrientation(Integer orientation) {
126 if(component != null) {
127 component.setOrientation(orientation);
132 public void setTitle(String string) {
133 if(component != null)
134 component.setBorder(BorderFactory.createTitledBorder(string));
137 @PropertySetter("Major Tick Spacing")
139 public void setMajorTickSpacing(Integer i) {
140 if(component != null) {
141 component.setLabelTable(component.createStandardLabels(i, component.getMinimum()));
142 component.setMajorTickSpacing(i);
146 @PropertySetter("Minor Tick Spacing")
148 public void setMinorTickSpacing(Integer i) {
149 if(component != null) {
150 component.setMinorTickSpacing(i);
154 @PropertySetter("Paint Ticks")
156 public void setPaintTicks(Boolean b) {
157 if(component != null) {
158 component.setPaintTicks(b);
159 component.updateUI();
163 @PropertySetter("Paint Labels")
165 public void setPaintLabels(Boolean b) {
166 if(component != null)
167 component.setPaintLabels(b);
170 @PropertySetter("Paint Track")
172 public void setPaintTrack(Boolean b) {
173 if(component != null)
174 component.setPaintTrack(b);
177 @PropertySetter("Snap To Ticks")
179 public void setSnapToTicks(Boolean b) {
180 if(component != null)
181 component.setSnapToTicks(b);
184 @PropertySetter("Inverted")
186 public void setInverted(Boolean b) {
187 if(component != null)
188 component.setInverted(b);
191 @PropertySetter("Background Color")
193 public void setBackgroundColor(Color color) {
194 // Not supported (For some reason this hides the slider)
197 public String widgetGet(String name) {
198 if("value".equals(name)) {
200 } else if("min".equals(name)) {
202 } else if("max".equals(name)) {
208 public void widgetSet(String name, String value) {
209 if("value".equals(name)) {
210 this.value = Integer.parseInt(value);
211 valueChanged(this.value);