package org.pentaho.ui.xul.swing.tags;

import javax.swing.JButton;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.components.XulScale;
import org.pentaho.ui.xul.dom.Element;
import org.pentaho.ui.xul.swing.SwingElement;
import org.pentaho.ui.xul.util.Orient;

public class SwingScale extends SwingElement implements XulScale{
  

  private int min = 0;
  private int max = 100;
  private int value = 0;
  private int increment = 1;
  
  private String direction;
  
  public SwingScale(Element self, XulComponent parent, XulDomContainer domContainer, String tagName) {
    super("scale");
  }
  
  public String getDir() {
    return direction;
  }

  public int getMax() {
    return max;
  }

  public int getMin() {
    return min;
  }

  public int getPageincrement() {
    return increment;
  }

  public int getValue() {
    return value;
  }

  public void setDir(String direction) {
    this.direction = direction;
  }

  public void setMax(int max) {
    this.max = max;
  }

  public void setMin(int min) {
    this.min = min;
  }

  public void setPageincrement(int increment) {
    this.increment = increment;
  }

  public void setValue(int value) {
    int prevVal = this.value;
    this.value = value;
    this.changeSupport.firePropertyChange("value", prevVal, value);
  }

  public void layout() {
    int orient = (orientation == Orient.VERTICAL)? JSlider.VERTICAL: JSlider.HORIZONTAL;
    final JSlider slider = new JSlider(orient, this.min, this.max, Math.max(min, this.value));
    this.managedObject = slider;
    
    slider.setMajorTickSpacing(this.increment);
    
    slider.setSnapToTicks(true);
    slider.setPaintTicks(true);
    
    slider.addChangeListener(new ChangeListener(){

      
      public void stateChanged(ChangeEvent arg0) {
        setValue(slider.getValue());
      }
      
    });

  }
}

@@ -596,16 +596,42 @@
 nt = 1;%0A
+  private JSlider slider;%0A
   %0A  pri
@@ -1403,24 +1403,84 @@
 ue = value;%0A
+    if(slider != null)%7B%0A      slider.setValue(value);%0A    %7D%0A
     this.cha
@@ -1662,22 +1662,8 @@
     
-final JSlider 
 slid
@@ -2023,16 +2023,32 @@
 etValue(
+SwingScale.this.
 slider.g

Update to allow outside code to update current value