package jmslexamples; import java.awt.FlowLayout; import javax.swing.JFrame; import com.didkovsky.portview.PVLabel; import com.didkovsky.portview.PVScrollbar; import com.didkovsky.portview.PVScrollbarListener; import com.didkovsky.portview.swing.ViewFactorySwing; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.view.PVLabelAdapter; /** * The com.didkovsky.portview scrollbar can be either awt or Swing compatible * depending on the ViewFactory * * @author Nick Didkovsky, (c) 2005 Nick Didkovsky * */ public class TestPortViewScrollbar extends JFrame implements PVScrollbarListener { PVScrollbar myScrollbar; PVLabel valueLabel; public void start() { JMSL.setViewFactory(new ViewFactorySwing()); // default value 50, min value 0, max value 100 myScrollbar = new PVScrollbar(50, 0, 100); myScrollbar.addPVScrollbarListener(this); // set the size of the scrollbar myScrollbar.setSize(200, 25); // set the increment that the value will jump when user clicks inside scrollbar myScrollbar.setPageIncrement(10); // set the increment that the value will jump when user clicks on arrows of // scrollbar myScrollbar.setLineIncrement(1); valueLabel = new PVLabelAdapter("PVScrollbar value"); setLayout(new FlowLayout()); add(myScrollbar.getComponent()); add(valueLabel.getComponent()); } void handleMyScrollbar() { valueLabel.setText(myScrollbar.getValue() + ""); } /** * This is the callback where a scrollbar notifies listeners that its value * changed. */ public void notifyScrollbarValueChanged(PVScrollbar sb) { if (sb == myScrollbar) { handleMyScrollbar(); } } public static void main(String[] args) { TestPortViewScrollbar test = new TestPortViewScrollbar(); test.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); test.start(); test.setSize(400, 100); test.setVisible(true); } }