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 {}
}