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.

context.openChart from BottomTab
 Post subject: context.openChart from BottomTab Post rating: 0   New post Posted: Tue 17 Sep, 2013, 11:40 

User rating: 1
Joined: Tue 18 Jun, 2013, 09:03
Posts: 14
Location: GermanyGermany
Hallo,
currently i am trying to open a chart from a PopUpMenu located on a panel in a BottomTab.
The context is passed during init of the panel. If i place the openChart line in the constructor of the panel, the chart opens as wanted. If i place the code inside the actionperformed of the menuaction, chart wont show.

Any clue why that is and how to fix it? Thanks!

Fabwa


Action showChart = new AbstractAction("Show on Chart") {

@Override
public void actionPerformed(ActionEvent e) {
context.openChart(new TimePeriodAggregationFeedDescriptor(Instrument.CADJPY,
Period.DAILY,
OfferSide.ASK,
Filter.WEEKENDS));
}
};


 
 Post subject: Re: context.openChart from BottomTab Post rating: 0   New post Posted: Tue 17 Sep, 2013, 11:45 
User avatar

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


 
 Post subject: Re: context.openChart from BottomTab Post rating: 0   New post Posted: Tue 17 Sep, 2013, 12:09 

User rating: 1
Joined: Tue 18 Jun, 2013, 09:03
Posts: 14
Location: GermanyGermany
import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.JTable;

public class Strategy implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    private GUIPanel GuiPanel;
   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
        JPanel myTab = userInterface.getBottomTab("Context Test");

        myTab.setLayout(new BorderLayout());
        GuiPanel = new GUIPanel(context);
        myTab.add(GuiPanel, BorderLayout.CENTER);
    }

    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 {
    }
}
 class GUIPanel extends JPanel {

        private JPanel JPanel_Test;
        private JPopupMenu popupMenu = new JPopupMenu();
        public IContext tabcontext;
               
        public GUIPanel(IContext context) {

           
            this.setLayout(new BorderLayout());
           
            tabcontext = context;
            tabcontext.openChart(new TimePeriodAggregationFeedDescriptor(Instrument.CADJPY,
                            Period.DAILY,
                            OfferSide.ASK,
                            Filter.WEEKENDS));

            JButton testbutton = new JButton("test");
           
            testbutton.addActionListener(new ActionListener(){

                @Override
                public void actionPerformed(ActionEvent e) {
                    tabcontext.openChart(new TimePeriodAggregationFeedDescriptor(Instrument.AUDJPY,
                            Period.DAILY,
                            OfferSide.ASK,
                            Filter.WEEKENDS));                }
            });

           
            add(testbutton);



        }



    }


 
The Best Answer  Post subject: Re: context.openChart from BottomTab Post rating: 0   New post Posted: Tue 17 Sep, 2013, 12:56 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The internal implementation of IContext.openChart uses SwingUtilities.invokeAndWait, hence you can't call the method from the event dispatch thread. Therefore you need to call the method from another thread:
            JButton testbutton = new JButton("test");

            testbutton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    tabcontext.setSubscribedInstruments(new HashSet<Instrument>(Arrays.asList(Instrument.AUDJPY)), true);
                    new Thread(new Runnable(){
                        @Override
                        public void run() {
                            tabcontext.openChart(new TimePeriodAggregationFeedDescriptor(Instrument.AUDJPY, Period.DAILY, OfferSide.ASK, Filter.WEEKENDS));
                        }})
                    .start();
                }
            });


 

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