Hi,
I have 2 components one at WEST side and the other at CENTER. They are both scrollable and have the same height. What I would like to do is to scroll vertically both when just one is currently scrolled.
What I've done works well when I scroll keeping the "finger" (currently mouse on the simulator) on one component, but stops working when I spin it. I don't understand why during tensile or spin animation setScrollX/Y are not called. Can you help me?
Thank you in advance
Claudio
Here is my code:
public abstract class AbstractComponent extends Component {
private boolean scrollableX;
private boolean scrollableY;
private List<AbstractComponent> scrollYListeners = new ArrayList<AbstractComponent>(1);
private boolean scrollingY = false;
@SuppressWarnings( "OverridableMethodCallInConstructor" )
public AbstractComponent ( boolean scrollableX, boolean scrollableY ) {
this.scrollableX = scrollableX;
this.scrollableY = scrollableY;
setAlwaysTensile(true);
setEnabled(true);
setFocusable(false);
setScrollVisible(true);
setSmoothScrolling(true);
setTensileDragEnabled(true);
}
public void addScrollYListener ( AbstractComponent listener ) {
scrollYListeners.add(listener);
}
@Override
public boolean isScrollableX () {
return scrollableX;
}
@Override
public boolean isScrollableY () {
return scrollableY;
}
@Override
public void paint ( Graphics g ) {
...
}
@Override
protected void setScrollY ( int scrollY ) {
if ( !scrollingY ) {
scrollingY = true;
super.setScrollY(scrollY);
for ( AbstractComponent c : scrollYListeners ) {
c.updateScrollY(scrollY);
}
scrollingY = false;
}
}
void updateScrollY ( int scrollY ) {
setScrollY(scrollY);
}
}
public class InstrumentNamesComponent extends AbstractComponent {
public InstrumentNamesComponent () {
super(false, true);
init();
}
private void init () {
setName("InstrumentNamesComponent");
setCompactInstrumentNames(false);
Dimension d = new Dimension(200, 10000);
setPreferredSize(d);
setScrollSize(d);
}
}
public class SplitsComponent extends AbstractComponent {
public SplitsComponent () {
super(true, true);
init();
}
private void init () {
setName("SplitsComponent");
setCompactInstrumentNames(false);
Dimension d = new Dimension(10000, 10000);
setPreferredSize(d);
setScrollSize(d);
}
}
public class StateMachine extends StateMachineBase {
private InstrumentNamesComponent instrumentNamesComponent;
private SplitsComponent splitsComponent;
...
protected void beforeMain ( Form form ) {
findCenterContainer(form).addComponent(BorderLayout.WEST, instrumentNamesComponent);
findCenterContainer(form).addComponent(BorderLayout.CENTER, splitsComponent);
...
instrumentNamesComponent.addScrollYListener(splitsComponent);
splitsComponent.addScrollYListener(instrumentNamesComponent);
}
protected void initVars ( Resources resources ) {
instrumentNamesComponent = new InstrumentNamesComponent();
splitsComponent = new SplitsComponent();
}
}