Dukascopy
 
 
Wiki JStore Search Login

Unwanted: chart grabs focus upon programmatic change of instrument
 Post subject: Unwanted: chart grabs focus upon programmatic change of instrument Post rating: 0   New post Posted: Wed 08 Nov, 2017, 21:18 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
For better view on state of and instrument I have 3 charts for same instrument open simultaneously with different intervals - 1min, 10min, 4hours.

To help in management of multiple instruments I have a button in plugin to switch instrument in all-charts-at-once and i have an annoying problem here - upon selection of instrument in chart - that chart grabs focus, this causes flickering and losing of focus from currently active control what is really not wanted. I've implemented a timer action to return focus to previous control, that workaround _somehow_ works in terms of keeping the focused control, but it can't fix flickering.

Can platform implementation be changed to NOT grab focus upon programmatic change of chart configuration (it seems any change, not only 'instrument', causes grabbing of focus)?

Below is simple plugin to reproduce the problem:

1. (optionally) Reset the workspace to "Default JForex" - you should get 4 different charts of the same size
2. Create new custom plugin and copy/paste into it the code provided below
3. Start plugin, click into textbox with "Test" text to put focus into it
4. click multiple times button "EUR/USD" and then multiple times "USD/JPY"

Expected behavior: focus stays in original textbox.
Actual behavior: focus is grabbed sequentially by each next chart.

BTW: in my environment plugin's tab does not appear immediately after start - i have to minimize "Navigator" window to make plugin's tab visible. It would be nice to have that fixed.

package jforex;

import com.dukascopy.api.IChart;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.plugins.IPluginContext;
import com.dukascopy.api.plugins.Plugin;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class UiTestPlugin extends Plugin {

    private String myTestTabTitle = "My Test Tab";
   
    private JPanel myTestTab;

    IPluginContext context;
   
    @Override
    public void onStart(IPluginContext context) throws JFException {
        this.context = context;
        myTestTab = context.getUserInterface().getLeftTab(myTestTabTitle);
        myTestTab.setLayout(new FlowLayout());

        JTextField text = new JTextField("Test", 5);
        myTestTab.add(text);
        text.grabFocus();

        JButton btnEurUsd = new JButton("EUR/USD");
        btnEurUsd.setFocusable(false);
        btnEurUsd.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectInstrument(Instrument.EURUSD);
            }
        });
        myTestTab.add(btnEurUsd);
       
        JButton btnUsdJpy = new JButton("USD/JPY");
        btnUsdJpy.setFocusable(false);
        btnUsdJpy.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectInstrument(Instrument.USDJPY);
            }
        });
        myTestTab.add(btnUsdJpy);
    }

    @Override
    public void onStop() throws JFException {
        context.getUserInterface().removeLeftTab(myTestTabTitle);
    }

    private void selectInstrument(Instrument instr) {
        for( IChart chart : context.getCharts() ) {
            if( chart.getInstrument() != instr ) {
                IFeedDescriptor fd = chart.getFeedDescriptor();
                fd.setInstrument(instr);
                chart.setFeedDescriptor(fd);
                break;
            }
        }
    }
}


 

Jump to:  

  © 1998-2024 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