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.

stop strategy on close of tab
 Post subject: stop strategy on close of tab Post rating: 0   New post Posted: Thu 12 May, 2011, 11:31 

User rating: -
How to stop the strategy when the panel created by the strategy

JPanel p = this.userInterface.getBottomTab("My Strategy");

gets closed?


 
 Post subject: Re: stop strategy on close of tab Post rating: 0   New post Posted: Tue 24 May, 2011, 07:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider the following example, which handles the close tab event.
package jforex.guitests;

import java.util.concurrent.Callable;
import javax.swing.*;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

import com.dukascopy.api.*;

public class CloseTabHandlingMinimal implements IStrategy {
   private JPanel myTab;
   private IContext context;
   private IConsole console;

   public void onStart(IContext context) throws JFException {
      this.context = context;
      this.console = context.getConsole();
      IUserInterface userInterface = context.getUserInterface();

      myTab = userInterface.getBottomTab("My tab");
      
      myTab.getParent().addContainerListener(new ContainerListener() {

         @Override
         public void componentRemoved(ContainerEvent arg0) {
            CloseTabHandlingMinimal.this.context.executeTask(new Callable<Object>() {
               public Object call() throws Exception {
                  console.getOut().println("stopping strategy");
                  CloseTabHandlingMinimal.this.context.stop();
                  return null;
               };
            });
            console.getOut().println("tab removed");
         }

         @Override
         public void componentAdded(ContainerEvent arg0) {
         }
      });

      SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
            JPanel myPanel = new JPanel();
            JLabel label = new JLabel();
            label.setText("Close the tab to stop the strategy");
            myPanel.add(label);
            myTab.add(myPanel);            
         }
      });
   }
   public void onAccount(IAccount account) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onStop() throws JFException {}
   public void onTick(Instrument instrument, ITick tick) throws JFException {}
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
}


 

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