Dukascopy
 
 
Wiki JStore Search Login

Standalone IChartPanel.addMouseListener API 2.7.9 exceptions
 Post subject: Standalone IChartPanel.addMouseListener API 2.7.9 exceptions Post rating: 0   New post Posted: Sun 24 Feb, 2013, 18:35 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
Standalone API 2.7.8 or 2.7.9

This is for standalone client developers only.

Before I go to the trouble of submitting a test case, can ANYONE state that they've been able to use

IChartPanel.addMouseListener(boolean asynchronous,IChartPanelMouseListener chartMouseListener)


successfully?

No matter what I have tried so far, all I get is this exception when the mouse pointer touches the chart area, as you can see when it attempts to handle the mouseEntered event:

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)



I define my listener as follows, by subclassing ChartPanelMouseAdapter and, of course, I add the listener:

// ichart is a valid IChart instance...
ichart.addMouseListener(false, new MyIChartPanelMouseListener()); // synchronous


final class MyIChartPanelMouseListener extends ChartPanelMouseAdapter {
         // all methods are implemented
}


 
 Post subject: Re: Stantalone IChartPanel.addMouseListener API 2.7.9 exceptions Post rating: 0   New post Posted: Tue 26 Feb, 2013, 19:35 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We could not reproduce this, please provide full example program which replicates the case.


Attachments:
MainOpenChartMouseListener.java [17.59 KiB]
Downloaded 439 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: Stantalone IChartPanel.addMouseListener API 2.7.9 exceptions Post rating: 0   New post Posted: Tue 26 Feb, 2013, 21:18 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
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


 

Jump to:  

cron
  © 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