トップ  >  リファレンス  >  サンプルソースコード  >  ストラテジーAPI  >  ExtendUI_TickCountingComponent.java
ExtendUI_TickCountingComponent.java

注意事項:
サンプルソースコードには実際にオーダーを発注するものがあります。
サンプルソースコードのストラテジーを起動する場合は、注意して下さい。



// Copyright (c) 2009 Dukascopy (Suisse) SA. All Rights Reserved.
package jforex.guitests;

import javax.swing.*;

import com.dukascopy.api.*;
import java.awt.Color;
import java.awt.Container;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
  JForexクライアントのカスタマイズしたGUIコンポーネントを作成します。
 コンポーネントにはtickカウンターと、リセットボタンがあります。
 ユーザーはエレメントをボトムタブか新しいウインドウのどちらに表示するかを選択出来ます。
 */
public class TickCountingComponent implements IStrategy {
    private IUserInterface userInterface;
    private JTextField labelTickCount;

    // パラメータ設定
    @Configurable("タブに表示する")
    public boolean useTab = false;

    private int tickCount;
    private int resets;
    private final String tabName = "TickCounter";
    private Container container;

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

        // 新しいタブか新しいウインドウのいずれかを作成する
        container = useTab ? buildBottomTab() : buildWindow();

    }

    private void addComponentsToPane(Container pane) {

        pane.setLayout(null);
        
        labelTickCount = new JTextField();
        final JButton btn = new JButton("Reset");

        pane.add(labelTickCount);
        pane.add(btn);

        // "Reset"ボタンをクリックするとtickカウンターをリセットし、ラベルの色を変更します。
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tickCount = 0;
                labelTickCount.setForeground((resets % 2 == 0 ? Color.RED : Color.BLUE));
                btn.setText("Reset (" + ++resets + ")");
            }
        });

        
        // ラベルとボタンのサイズと配置をカスタマイズ
        Insets insets = pane.getInsets();
        btn.setBounds(25 + insets.left, 5 + insets.top, 100, 25);
        labelTickCount.setBounds(150 + insets.left, 15 + insets.top, 150, 25);

    }

    private JFrame buildWindow() {
        // ウインドウの作成と設定
        JFrame frame = new JFrame(tabName + " window with absolute layout");

        addComponentsToPane(frame);

        // ウインドウの表示とサイズ設定
        Insets insets = frame.getInsets();
        frame.setSize(400 + insets.left + insets.right, 150 + insets.top + insets.bottom);
        frame.setVisible(true);
        return frame;
    }

    private JPanel buildBottomTab() {
        JPanel tab = userInterface.getBottomTab(tabName);
        
        addComponentsToPane(tab);
        return tab;
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (labelTickCount != null)
            labelTickCount.setText("ticks since reset: " + tickCount++);
    }

    public void onStop() throws JFException {
        // タブの削除/ウインドウを閉じる
        if (useTab){
            userInterface.removeBottomTab(tabName);
        } else {
            ((JFrame)container).dispose();
        }        
    }

    public void onAccount(IAccount account) throws JFException {    }
    public void onMessage(IMessage message) throws JFException {    }
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {    }
}






スポンサーリンク

スポンサーリンク
検索
リファレンスツリー


Copyright ©2016 JForexAPIで自動売買させ隊! All Rights Reserved.


Top

inserted by FC2 system