Hi Gordon,
You could do it on the server side with the IAdjustmentListener as follows:
ULCScrollPane scrollPane1 = new ULCScrollPane(jl1);
ULCScrollPane scrollPane2 = new ULCScrollPane(jl2);
final ULCScrollBar scrollBar1 = scrollPane1.getVerticalScrollBar();
final ULCScrollBar scrollBar2 = scrollPane2.getVerticalScrollBar();
scrollBar1.addAdjustmentListener(new IAdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent event) {
scrollBar2.setPosition(scrollBar1.getPosition());
}
});
scrollBar2.addAdjustmentListener(new IAdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent event) {
scrollBar1.setPosition(scrollBar2.getPosition());
}
});
However, you wouldn't want to incur a server roundtrip on every scroll.
To do the synching on the client, you will need an extension of ULCScrollBar
that provides you with API that acts like setModel().
Please see the snippet below.
Thanks and regards,
Janak
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Gordon Gridley
Sent: Monday, August 21, 2006 10:14 PM
To: [email protected]
Subject: [ULC-developer] Need to setModel on ULCScrollBar
I need to be able to synchronize two ULCScrollPanes with ULCScrollBars on
them. Here is a link to how it is done using a JScrollBar.
I don't see a setModel method on ULCScrollBar. Would that be difficult to
add, or is there a easier way for me to synchronize the movement of two
identical scrollpanes?
Thanks
Gords
-------------------------
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCBorderLayoutPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCScrollBar;
import com.ulcjava.base.application.ULCScrollPane;
import com.ulcjava.base.application.ULCSplitPane;
import com.ulcjava.base.application.ULCTextArea;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.client.UIScrollBar;
import com.ulcjava.base.development.DevelopmentRunner;
import javax.swing.BoundedRangeModel;
import javax.swing.JFrame;
public class ULCScrollBarExtSync extends AbstractApplication {
public String aszItems1 = "Item 1\n" + "Item 2\n" + "Item 3\n" + "Item
4\n" + "Item 5\n" + "Item 6\n" + "Item 7\n"
+ "Item 8\n" + "Item 9\n" + "Item 10\n" + "Item 11\n" + "Item
12\n" + "Item 13\n" + "Item 14\n"
+ "Item 15\n" + "Item 16\n" + "Item 17\n" + "Item 18\n" + "Item
19\n" + "Item 20\n" + "Item 21\n"
+ "Item 22\n" + "Item 23\n" + "Item 24\n" + "Item 25\n" + "Item
26\n" + "Item 27";
public String aszItems2 =
"Element 1\n" + "Element 2\n" + "Element 3\n" + "Element 4\n" + "Element
5\n" + "Element 6\n" + "Element 7\n"
+ "Element 8\n" + "Element 9\n" + "Element 10\n" + "Element
11\n" + "Element 12\n" + "Element 13\n"
+ "Element 14\n" + "Element 15\n" + "Element 16\n" + "Element
17\n" + "Element 18\n" + "Element 19\n"
+ "Element 20\n" + "Element 21\n" + "Element 22\n" + "Element
23\n" + "Element 24\n" + "Element 25\n"
+ "Element 26\n" + "Element 27\n" + "Element 28\n" + "Element
29";
public void start() {
ULCBorderLayoutPane content = new ULCBorderLayoutPane();
ULCTextArea jl1 = new ULCTextArea(aszItems1);
ULCTextArea jl2 = new ULCTextArea(aszItems2);
ULCScrollPane sc1 = new ULCScrollPane(jl1);
ULCScrollPane sc2 = new ULCScrollPane(jl2);
final ULCMyScrollBar sb1 = new ULCMyScrollBar();
final ULCMyScrollBar sb2 = new ULCMyScrollBar();
sc1.setVerticalScrollBar(sb1);
sc2.setVerticalScrollBar(sb2);
ULCSplitPane sp = new ULCSplitPane();
sp.setLeftComponent(sc1);
sp.setRightComponent(sc2);
sp.upload();
sp.setDividerLocation(0.5D);
content.add(sp, ULCBorderLayoutPane.CENTER);
final ULCButton button = new ULCButton("Synch");
button.addActionListener(new IActionListener() {
boolean isSynched = false;
public void actionPerformed(ActionEvent event) {
if (!isSynched) {
sb1.setSynchWithScrollBar(sb2);
isSynched = !isSynched;
button.setText("UnSynch");
} else {
sb1.setSynchWithScrollBar(null);
isSynched = !isSynched;
button.setText("Synch");
}
}
});
content.add(button, ULCBorderLayoutPane.SOUTH);
ULCFrame frame = new ULCFrame();
frame.setContentPane(content);
frame.setSize(300, 200);
frame.setLocation(50, 50);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String arg[]) {
DevelopmentRunner.setApplicationClass(ULCScrollBarExtSync.class);
DevelopmentRunner.run();
}
public static class ULCMyScrollBar extends ULCScrollBar {
private ULCScrollBar fSynchWithScrollBar;
protected String typeString() {
return UIMyScrollBar.class.getName();
}
protected void uploadStateUI() {
super.uploadStateUI();
createStateUI(new Object[] { fSynchWithScrollBar });
setStateUI("synchWithScrollBar", fSynchWithScrollBar);
}
public void setSynchWithScrollBar(ULCScrollBar sb) {
fSynchWithScrollBar =
(ULCScrollBar)setStateUI("synchWithScrollBar", sb);
}
}
public static class UIMyScrollBar extends UIScrollBar {
private BoundedRangeModel originalModel;
public void setSynchWithScrollBar(UIScrollBar sb) {
if (sb != null)
getBasicScrollBar().setModel(sb.getBasicScrollBar().getModel
());
else
getBasicScrollBar().setModel(originalModel);
}
protected void preInitializeState() {
super.preInitializeState();
originalModel = getBasicScrollBar().getModel();
}
}
}
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer