Thanks very much for the example. The issue is completely clear to me, let me explain.
I can see immediately why your sample works, and my does not.
Although you have created the chart outside of an (anonymous) IStrategy instance, you use the running hosted IStrategy to actually install the mouse listener in IStrategy.onStart. Of course it doesn't have to be anonymous but that is the critical difference from my code. Then you started the IStrategy instance, and in its IStrategy.onStart, that is where you installed the mouse listener. Obviously, that works, and I was unaware that it had to happen within a Hosted, running IStrategy instance.
In my case, I did NOT add the mouse listener from within a running IStrategy object, since I had no idea this would be relevant. And that is the reason why my code did not work. It was not clear at all that the mouse listener had to be added WITHIN the callback execution context of an IStrategy module. Now that I know that, I can easily arrange my code to emulate what you have done, and it should work.
As you have explained before, the standalone API is designed to facilitate the running of IStrategy modules, and critical functionality requires that code be executed within the IStrategy modules, as you have done it.
But an attempt to add such a mouse listener OUTSIDE of an IStrategy context, fails.
I would suggest that you make it much clearer that the execution context of API functions, such as this one, REQUIRE that they execute within an IStrategy module, hosted by the API standalone client.
Thanks very much for your example, and I'd suggest you might put such information in the Wiki, if you do provide more information for standalone API users. (I realize you are reluctant to put examples of standalone in the Wiki, but I would suggest you consider doing so, as it is often not clear exactly how these are intended to be used.)
Thanks again for providing this code for me. I'm sure I can manage from this point forward.
Your code, which works, of course, because it is done within IStrategy.onStart hosted in the API standalone client.
// a strategy that checks which charts are available from it
client.startStrategy(new IStrategy() {
private IContext context;
@Override
public void onStart(IContext context) throws JFException {
this.context = context;
System.out.println("Add mouse listener");
context.getChart(Instrument.EURUSD).addMouseListener(false, new IChartPanelMouseListener(){
@Override
public void mouseClicked(IChartPanelMouseEvent arg0) {
System.out.println("mouseClicked");
}
@Override
public void mouseDragged(IChartPanelMouseEvent arg0) {
System.out.println("mouseDragged");
}
@Override
public void mouseEntered(IChartPanelMouseEvent arg0) {
System.out.println("mouseEntered");
}
@Override
public void mouseExited(IChartPanelMouseEvent arg0) {
System.out.println("mouseExited");
}
@Override
public void mouseMoved(IChartPanelMouseEvent arg0) {
System.out.println("mouseMoved");
}
@Override
public void mousePressed(IChartPanelMouseEvent arg0) {
System.out.println("mousePressed");
}
@Override
public void mouseReleased(IChartPanelMouseEvent arg0) {
System.out.println("mouseReleased");
}});
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
IChart chart = context.getChart(instrument);
if (chart != null) {
//System.out.println(chart.getFeedDescriptor() + " " + tick);
}
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onAccount(IAccount account) throws JFException { }
public void onStop() throws JFException { }
});
So, clearly, you then add/install the MouseListener instance WITHIN the IStrategy.onStart method and it works as expected.
If that is how it must be done, then that's how I can easily do it myself.
I'll just define an IStrategy module whose main purpose is to install a MouseListener.
THANKS FOR THE ASSISTANCE!
HyperScalper