1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.scenegraph.swing;
14 import java.awt.Color;
\r
15 import java.awt.event.ActionEvent;
\r
16 import java.awt.event.ActionListener;
\r
17 import java.awt.event.MouseEvent;
\r
18 import java.awt.event.MouseListener;
\r
20 import javax.swing.BorderFactory;
\r
21 import javax.swing.JSlider;
\r
23 import org.simantics.scenegraph.ExportableWidget.InputWidget;
\r
24 import org.simantics.scenegraph.ExportableWidget.OutputWidget;
\r
26 @OutputWidget({"value", "min", "max"})
\r
28 public class SliderNode extends ComponentNode<JSlider> {
29 private static final long serialVersionUID = 3161843367263793336L;
\r
30 protected transient ActionListener actionListener = null;
32 // Necessary for widget ui:
\r
33 protected Integer value = 0;
\r
34 protected Integer min = 0;
\r
35 protected Integer max = 0;
\r
38 public void setValue(Integer value) {
\r
40 if(component != null) {
\r
41 if(!component.getValueIsAdjusting()) { // FIXME: propably does not work
\r
42 // System.out.println("valueIsAdjusting == false");
\r
43 component.setValue(value);
\r
45 // TODO: cache value?
\r
46 // System.out.println("valueIsAdjusting == true");
\r
52 public void init() {
\r
53 component = new JSlider();
\r
54 component.setPaintTicks(true);
\r
55 component.addMouseListener(new MouseListener() {
\r
58 public void mouseClicked(MouseEvent e) {
\r
59 // TODO Auto-generated method stub
\r
64 public void mousePressed(MouseEvent e) {
\r
65 // TODO Auto-generated method stub
\r
70 public void mouseReleased(MouseEvent e) {
\r
71 if(component.getValueIsAdjusting())
\r
72 valueChanged(component.getValue());
\r
76 public void mouseEntered(MouseEvent e) {
\r
77 // TODO Auto-generated method stub
\r
82 public void mouseExited(MouseEvent e) {
\r
83 // TODO Auto-generated method stub
\r
90 protected void valueChanged(Integer value) {
\r
91 if(actionListener != null) { // FIXME: there might not be a component on the server side
\r
92 ActionEvent e = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, ""+value);
\r
93 actionListener.actionPerformed(e);
\r
97 public void setActionListener(ActionListener actionListener) {
\r
98 this.actionListener = actionListener;
\r
101 @PropertySetter("Value Extent")
\r
103 public void setExtent(Integer extent) {
\r
104 if(component != null)
\r
105 component.setExtent(extent);
\r
108 @PropertySetter("Min Value")
\r
110 public void setMinimum(Integer min) {
\r
112 if(component != null)
\r
113 component.setMinimum(min);
\r
116 @PropertySetter("Max Value")
\r
118 public void setMaximum(Integer max) {
\r
120 if(component != null)
\r
121 component.setMaximum(max);
\r
125 public void setOrientation(Integer orientation) {
\r
126 if(component != null) {
\r
127 component.setOrientation(orientation);
\r
132 public void setTitle(String string) {
\r
133 if(component != null)
\r
134 component.setBorder(BorderFactory.createTitledBorder(string));
\r
137 @PropertySetter("Major Tick Spacing")
\r
139 public void setMajorTickSpacing(Integer i) {
\r
140 if(component != null) {
\r
141 component.setLabelTable(component.createStandardLabels(i, component.getMinimum()));
\r
142 component.setMajorTickSpacing(i);
\r
146 @PropertySetter("Minor Tick Spacing")
\r
148 public void setMinorTickSpacing(Integer i) {
\r
149 if(component != null) {
\r
150 component.setMinorTickSpacing(i);
\r
154 @PropertySetter("Paint Ticks")
\r
156 public void setPaintTicks(Boolean b) {
\r
157 if(component != null) {
\r
158 component.setPaintTicks(b);
\r
159 component.updateUI();
\r
163 @PropertySetter("Paint Labels")
\r
165 public void setPaintLabels(Boolean b) {
\r
166 if(component != null)
\r
167 component.setPaintLabels(b);
\r
170 @PropertySetter("Paint Track")
\r
172 public void setPaintTrack(Boolean b) {
\r
173 if(component != null)
\r
174 component.setPaintTrack(b);
\r
177 @PropertySetter("Snap To Ticks")
\r
179 public void setSnapToTicks(Boolean b) {
\r
180 if(component != null)
\r
181 component.setSnapToTicks(b);
\r
184 @PropertySetter("Inverted")
\r
186 public void setInverted(Boolean b) {
\r
187 if(component != null)
\r
188 component.setInverted(b);
\r
191 @PropertySetter("Background Color")
\r
193 public void setBackgroundColor(Color color) {
\r
194 // Not supported (For some reason this hides the slider)
\r
197 public String widgetGet(String name) {
\r
198 if("value".equals(name)) {
\r
200 } else if("min".equals(name)) {
\r
202 } else if("max".equals(name)) {
\r
208 public void widgetSet(String name, String value) {
\r
209 if("value".equals(name)) {
\r
210 this.value = Integer.parseInt(value);
\r
211 valueChanged(this.value);
\r