I used the MainOpenChart.java (
https://www.dukascopy.com/wiki/#IClient_functionality) and added an IChartPanelMouseListener. (The additional code I show at the end of this post. The whole source code you'll find in the attachement.
maven dependencies:
<dependency>
<groupId>com.dukascopy.dds2</groupId>
<artifactId>DDS2-jClient-JForex</artifactId>
<!-- find the latest available version here: https://www.dukascopy.com/client/jforexlib/publicrepo/com/dukascopy/dds2/DDS2-jClient-JForex/ -->
<version>2.45.52</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- find the latest available version here: https://www.dukascopy.com/client/jforexlib/publicrepo/com/dukascopy/api/JForex-API/ -->
<dependency>
<groupId>com.dukascopy.api</groupId>
<artifactId>JForex-API</artifactId>
<version>2.12.41</version>
<classifier>sources</classifier>
</dependency>
I also tested this in my own implementations, where the same exception happened.
It seems only to happen with the live chart -> ClientFactory.getDefaultInstance()
It works perfectly if a backtest is running -> TesterFactory.getDefaultInstance()
The NPE:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.dukascopy.charts.wrapper.StrategyThreadDelegatableMouseListener.mouseEntered(StrategyThreadDelegatableMouseListener.java:69)
at com.dukascopy.charts.view.swing.AbstractChartPanelView$1.mouseEntered(AbstractChartPanelView.java:127)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:300)
at java.awt.Component.processMouseEvent(Component.java:6544)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6300)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.retargetMouseEnterExit(Container.java:4676)
at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4654)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4505)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Sourcecode:
// open charts
for (Instrument instrument : instrArr) {
IFeedDescriptor feedDescriptor = new TicksFeedDescriptor(instrument);
feedDescriptor.setOfferSide(OfferSide.BID);// need to set due to
// platform requirements
IChart chart = client.openChart(feedDescriptor);
chart.addMouseListener(false, new IChartPanelMouseListener() {
@Override
public void mouseReleased(IChartPanelMouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(IChartPanelMouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(IChartPanelMouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(IChartPanelMouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(IChartPanelMouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(IChartPanelMouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(IChartPanelMouseEvent e) {
// TODO Auto-generated method stub
}
});
final IClientGUI clientGUI = client.getClientGUI(chart);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ChartFrame frame = new ChartFrame(clientGUI, client.getSubscribedInstruments());
chartFrameMap.put(clientGUI.getChart(), frame);
// Handle manual close - we need to call IClient.closeChart
// for strategy to know that the chart is no more there
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
LOGGER.info("Chart manually closed, removing the chart from the strategy context");
client.closeChart(clientGUI.getChart());
chartFrameMap.remove(clientGUI.getChart());
if (chartFrameMap.isEmpty()) {
LOGGER.info("All charts closed, stopping the program");
System.exit(0);
}
}
});
}
});
}