Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

IChartPanelMouseListener exceptions
 Post subject: IChartPanelMouseListener exceptions Post rating: 0   New post Posted: Tue 12 Feb, 2013, 21:38 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
Standalone API 2.7.8 exceptions for IChartPanelMouseListener.
Is this fixed in the upcoming 2.7.9 API ?

When I do this:

// com.dukascopy.api.IClientGUI validClientGUI; // in reality, this has been properly initialized
IChart chart = validClientGUI.getChart();
chart.addMouseListener(false, new MyIChartPanelMouseListener()); // synchronous

The chart is functioning fine, but I get these exceptions whenever the mouse cursor goes into the chart drawing area:

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:91)
   at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
   at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at javax.swing.JComponent.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.trackMouseEnterExit(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
   at java.awt.EventQueue.access$400(Unknown Source)
   at java.awt.EventQueue$2.run(Unknown Source)
   at java.awt.EventQueue$2.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)


 
 Post subject: Re: IChartPanelMouseListener exceptions Post rating: 0   New post Posted: Wed 13 Feb, 2013, 16:31 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We could not replicate this with the following strategy:
https://www.dukascopy.com/wiki/#Chart_Operations/Add_mouse_listener
Please provide an example strategy and the lauch conditions.


 
 Post subject: Re: IChartPanelMouseListener exceptions Post rating: 0   New post Posted: Wed 13 Feb, 2013, 17:28 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
Standalone API 2.7.8
Yes, from your example, it seems to work within an IStrategy construct.

In my case, the standalone client creates the chart, and establishes the
IChartPanelMouseListener using the following steps:

In this code, the instance variables are named for clarity. Code fragments to explain
exactly how the IChartPanelMouseListener is established:
         ticksFeedDescriptor = new TicksFeedDescriptor(instrument); // Instrument.EURUSD
         ticksFeedDescriptor.setOfferSide(OfferSide.BID);
// ...
            ichart = getIClient().openChart(feedDescriptor);

            iclientGUI = getIClient().getClientGUI(ichart);
// ...then using SwingUtilities.invokeLater, code passes iclientGUI to the constructor for a JFrame
// ...as shown here
////            SwingUtilities.invokeLater(new Runnable() {
////               public void run() {
////                  chartFrame = new JForexChartFrame(iclientGUI);
////               }
////            });


// now, within the JForexChartFrame which extends JFrame constructor code
// ...within that constructor, the IChart instance is fetched **from the iclientGUI** like this:
// ichart and iclientGUI are member variables, not stack variables...
      ichart = iclientGUI.getChart();
// code functions perfectly, but adding this mouse listener causes exceptions
      ichart.addMouseListener(false, new MyIChartPanelMouseListener()); // synchronous
// code is fine, but when mouse enters the ichart area, exceptions are thrown to console


This is the only exception thrown, and only when mouse is being moved within the charting area.

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:91)
   at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at javax.swing.JComponent.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.trackMouseEnterExit(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
   at java.awt.EventQueue.access$400(Unknown Source)
   at java.awt.EventQueue$2.run(Unknown Source)
   at java.awt.EventQueue$2.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)


   // BUG?: adding this mouse listener causes null pointer exceptions
        // none of these events occurs
   final class MyIChartPanelMouseListener implements IChartPanelMouseListener {

      @Override
      public void mouseClicked(IChartPanelMouseEvent e) {
         // TODO Auto-generated method stub
         try {
            double price = e.getPrice();
            long time = e.getTime();
            System.out.println("mouseClicked price: "+price+" date: "+new java.util.Date(time));
         }
         catch(Exception ex) {
            ex.printStackTrace();
         }
      }

      @Override
      public void mouseDragged(IChartPanelMouseEvent e) {
         // TODO Auto-generated method stub
         System.out.println("mouseDragged");
         
      }

      @Override
      public void mouseEntered(IChartPanelMouseEvent e) {
         // TODO Auto-generated method stub
         System.out.println("mouseEntered");
      }

      @Override
      public void mouseExited(IChartPanelMouseEvent e) {
         // TODO Auto-generated method stub
         System.out.println("mouseExited");
      }

      @Override
      public void mouseMoved(IChartPanelMouseEvent e) {
         // TODO Auto-generated method stub
         System.out.println("mouseMoved");
      }

      @Override
      public void mousePressed(IChartPanelMouseEvent e) {
         // TODO Auto-generated method stub
         System.out.println("mousePressed");
      }

      @Override
      public void mouseReleased(IChartPanelMouseEvent e) {
         // TODO Auto-generated method stub
         System.out.println("mouseReleased");
      }
      
   }
   



 
 Post subject: Re: IChartPanelMouseListener exceptions Post rating: 0   New post Posted: Wed 13 Feb, 2013, 17:58 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide a full example program which replicates the case.


 
 Post subject: Re: IChartPanelMouseListener exceptions Post rating: 0   New post Posted: Wed 13 Feb, 2013, 18:28 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
I thought that would be enough information.

If I just provide a class which you could embed in your own standalone test instance, to demonstrate the issue, is that OK?
So I would not have to supply an example with Login support included.

HELP: Is anyone out there using an IChartPanelMouseListener successfully in a standalone API client's charting?

You have shown that it doesn't replicate in an IStrategy. My problem is in a standalone API context.

HyperScalper.


 
 Post subject: Re: IChartPanelMouseListener exceptions Post rating: 0   New post Posted: Wed 13 Feb, 2013, 19:52 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
This can be used in a standalone API test runner. I've tried to keep it very simple.
I'm not able to supply my entire app since it is very complex and surely you can
easily use this in your own standalone API tester code to verify.

If others have been able to use the mouse listeners in a standalone API context,
then, of course, I must be making an error.

Thanks !

package com.fs;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.dukascopy.api.IChart;
import com.dukascopy.api.IClientGUI;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.chart.mouse.IChartPanelMouseEvent;
import com.dukascopy.api.chart.mouse.IChartPanelMouseListener;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.util.TicksFeedDescriptor;
import com.dukascopy.api.system.IClient;

// Standalone API 2.7.8 Bug in IChartPanelMouseListener
// Must test in standalone API mode
public class IChartPanelMouseListenerBug extends JFrame {
   
   IChart ichart;
   IClient iclient;
   IClientGUI iclientGUI;
   
   /*
    * Within a running API standalone client process
    * Supply an IChart which is created on Instrument.EURUSD
    * using a feed descriptor
    *       static IFeedDescriptor ticksFeedDescriptor = new TicksFeedDescriptor(Instrument.EURUSD);
    *      ticksFeedDescriptor.setOfferSide(OfferSide.BID);
    *      static IChart ichart = iclient.openChart(ticksFeedDescriptor);
    *      static IChartPanelMouseListenerBug bug = new IChartPanelMouseListenerBug(iclient, ichart);
    * (static variables only for purposes of the testing)
    * Then drag the mouse cursor over the JFrame and exceptions should appear in Java console
    */
   public IChartPanelMouseListenerBug(IClient iclientArg, IChart ichartArg) {
      ichart = ichartArg;
      iclient = iclientArg;
      ichart.addMouseListener(false, new MyIChartPanelMouseListener());
      setTitle("IChartPanelMouseListenerBug in standalone API 2.7.8 Client");
      iclientGUI = iclient.getClientGUI(ichart);
      this.getContentPane().add(iclientGUI.getChartPanel()); // a JPanel
      this.validate();
      this.pack();
      this.setVisible(true);
   }
   
   class MyIChartPanelMouseListener implements IChartPanelMouseListener {

      @Override
      public void mouseClicked(IChartPanelMouseEvent arg0) {
         // TODO Auto-generated method stub
         
      }

      @Override
      public void mouseDragged(IChartPanelMouseEvent arg0) {
         // TODO Auto-generated method stub
         
      }

      @Override
      public void mouseEntered(IChartPanelMouseEvent arg0) {
         // TODO Auto-generated method stub
         
      }

      @Override
      public void mouseExited(IChartPanelMouseEvent arg0) {
         // TODO Auto-generated method stub
         
      }

      @Override
      public void mouseMoved(IChartPanelMouseEvent arg0) {
         // TODO Auto-generated method stub
         
      }

      @Override
      public void mousePressed(IChartPanelMouseEvent arg0) {
         // TODO Auto-generated method stub
         
      }

      @Override
      public void mouseReleased(IChartPanelMouseEvent arg0) {
         // TODO Auto-generated method stub
         
      }
      
   }
   
}


Attachments:
IChartPanelMouseListenerBug.java [1.92 KiB]
Downloaded 274 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: IChartPanelMouseListener exceptions Post rating: 0   New post Posted: Wed 13 Feb, 2013, 19:58 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
hyperscalper wrote:
If I just provide a class which you could embed in your own standalone test instance, to demonstrate the issue, is that OK?
It's best when you always provide full example program which replicates the case. Fistly because we don't have to wrap it in our code by adapting to your variable names and helper classes. Secondly, and more importantly, because if we don't manage to replicate the case, then we don't need to go back and forth guessing what is the crucial difference between your code and ours.
Consider the following Bug report - the user posted both an example strategy and an example program which replicate the issue, such that it can get registered without any further inquiries:
viewtopic.php?f=16&t=48796


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com