protected Button createButton(Composite parent, String label)

package com.clustercontrol.monitor.run.composite;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.PlatformUI;
import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.dialog.CommonDialog;
import com.clustercontrol.util.Messages;

public class TableItemInfoComposite<T> extends Composite {

    /**
     * 判定情報一覧 コンポジット。
     */
    protected TableItemListComposite<T> m_infoList = null;

    protected ITableItemCompositeDefine<T> m_define = null;

    /**
     * 追加 ボタン。
     */
    protected Button m_buttonAdd = null;

    /**
     * 変更 ボタン。
     */
    protected Button m_buttonModify = null;

    /**
     * 削除 ボタン。
     */
    protected Button m_buttonDelete = null;

    protected Button m_buttonCopy = null;

    /**
     * 上へ ボタン。
     */
    protected Button m_buttonUp = null;

    /**
     * 下へ ボタン。
     */
    protected Button m_buttonDown = null;

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define) {
        this(parent, style, define, null);
    }

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define, List<T> items) {
        super(parent, style);
        this.m_define = define;
        if (items != null) {
            this.m_define.initTableItemInfoManager(items);
        } else {
            this.m_define.initTableItemInfoManager();
        }
        this.initialize();
    }

    protected void initialize() {
        // 変数として利用されるグリッドデータ
        GridData gridData = null;
        GridLayout layout = new GridLayout(1, true);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 15;
        this.setLayout(layout);
        this.m_infoList = new TableItemListComposite<T>(this, SWT.BORDER, this.m_define);
        WidgetTestUtil.setTestId(this, "pagelist", m_infoList);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 11;
        this.m_infoList.setLayoutData(gridData);
        Composite composite = new Composite(this, SWT.NONE);
        WidgetTestUtil.setTestId(this, "button", composite);
        layout = new GridLayout(1, true);
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MULTI) != 0) {
            layout.numColumns = 2;
        }
        composite.setLayout(layout);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 4;
        composite.setLayoutData(gridData);
        // 追加ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.ADD) != 0) {
            this.m_buttonAdd = this.createButton(composite, Messages.getString("add"));
            WidgetTestUtil.setTestId(this, "add", m_buttonAdd);
            this.m_buttonAdd.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    CommonDialog dialog = m_define.createDialog(shell);
                    if (dialog.open() == IDialogConstants.OK_ID) {
                        m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                        m_infoList.update();
                    }
                }
            });
        }
        // 変更ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MODIFY) != 0) {
            this.m_buttonModify = this.createButton(composite, Messages.getString("modify"));
            WidgetTestUtil.setTestId(this, "modify", m_buttonModify);
            this.m_buttonModify.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = getSelectedItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().modify(item, m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 削除ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DELETE) != 0) {
            this.m_buttonDelete = this.createButton(composite, Messages.getString("delete"));
            WidgetTestUtil.setTestId(this, "delete", m_buttonDelete);
            this.m_buttonDelete.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        String detail = m_define.getItemsIdentifier(item);
                        String[] args = { detail };
                        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.monitor.31", args))) {
                            m_define.getTableItemInfoManager().delete(getSelectedItem());
                            m_infoList.update();
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.COPY) != 0) {
            this.m_buttonCopy = this.createButton(composite, Messages.getString("copy"));
            WidgetTestUtil.setTestId(this, "copy", m_buttonCopy);
            this.m_buttonCopy.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.SPACE) != 0) {
            Label label = new Label(composite, SWT.NONE);
            WidgetTestUtil.setTestId(this, "space", label);
        }
        // 上へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.UP) != 0) {
            this.m_buttonUp = this.createButton(composite, Messages.getString("up"));
            WidgetTestUtil.setTestId(this, "up", m_buttonUp);
            this.m_buttonUp.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().upOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 下へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DOWN) != 0) {
            this.m_buttonDown = this.createButton(composite, Messages.getString("down"));
            WidgetTestUtil.setTestId(this, "down", m_buttonDown);
            this.m_buttonDown.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().downOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
    }

    public void setInputData(List<T> list) {
        if (list != null) {
            this.m_infoList.setInputData(list);
        }
        // 必須項目を明示
        this.update();
    }

    /* (非 Javadoc)
	 * @see org.eclipse.swt.widgets.Control#setEnabled(boolean)
	 */
    @Override
    public void setEnabled(boolean enabled) {
        this.m_infoList.setEnabled(enabled);
        if (this.m_buttonAdd != null) {
            this.m_buttonAdd.setEnabled(enabled);
        }
        if (this.m_buttonModify != null) {
            this.m_buttonModify.setEnabled(enabled);
        }
        if (this.m_buttonDelete != null) {
            this.m_buttonDelete.setEnabled(enabled);
        }
        if (this.m_buttonCopy != null) {
            this.m_buttonCopy.setEnabled(enabled);
        }
        if (this.m_buttonUp != null) {
            this.m_buttonUp.setEnabled(enabled);
        }
        if (this.m_buttonDown != null) {
            this.m_buttonDown.setEnabled(enabled);
        }
    }

{
        Button button = new Button(parent, SWT.NONE);
        WidgetTestUtil.setTestId(this, null, button);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        button.setLayoutData(gridData);
        button.setText(label);
        return button;
    }

    protected void selectItem(T item) {
        Table table = this.m_infoList.getTableViewer().getTable();
        WidgetTestUtil.setTestId(this, null, table);
        TableItem[] items = table.getItems();
        if (items == null || item == null) {
            return;
        }
        for (int i = 0; i < items.length; i++) {
            @SuppressWarnings("unchecked")
            T tmpItem = (T) items[i].getData();
            WidgetTestUtil.setTestId(this, "items" + i, items[i]);
            if (item.equals(tmpItem)) {
                table.select(i);
                return;
            }
        }
    }

    protected T getSelectedItem() {
        StructuredSelection selection = (StructuredSelection) this.m_infoList.getTableViewer().getSelection();
        @SuppressWarnings("unchecked")
        T tableItemInfo = (T) selection.getFirstElement();
        return tableItemInfo;
    }

    public List<T> getItems() {
        return this.m_infoList.getTableItemData();
    }
}


{
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    CommonDialog dialog = m_define.createDialog(shell);
                    if (dialog.open() == IDialogConstants.OK_ID) {
                        m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                        m_infoList.update();
                    }
                }

package com.clustercontrol.monitor.run.composite;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.PlatformUI;
import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.dialog.CommonDialog;
import com.clustercontrol.util.Messages;

public class TableItemInfoComposite<T> extends Composite {

    /**
     * 判定情報一覧 コンポジット。
     */
    protected TableItemListComposite<T> m_infoList = null;

    protected ITableItemCompositeDefine<T> m_define = null;

    /**
     * 追加 ボタン。
     */
    protected Button m_buttonAdd = null;

    /**
     * 変更 ボタン。
     */
    protected Button m_buttonModify = null;

    /**
     * 削除 ボタン。
     */
    protected Button m_buttonDelete = null;

    protected Button m_buttonCopy = null;

    /**
     * 上へ ボタン。
     */
    protected Button m_buttonUp = null;

    /**
     * 下へ ボタン。
     */
    protected Button m_buttonDown = null;

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define) {
        this(parent, style, define, null);
    }

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define, List<T> items) {
        super(parent, style);
        this.m_define = define;
        if (items != null) {
            this.m_define.initTableItemInfoManager(items);
        } else {
            this.m_define.initTableItemInfoManager();
        }
        this.initialize();
    }

    protected void initialize() {
        // 変数として利用されるグリッドデータ
        GridData gridData = null;
        GridLayout layout = new GridLayout(1, true);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 15;
        this.setLayout(layout);
        this.m_infoList = new TableItemListComposite<T>(this, SWT.BORDER, this.m_define);
        WidgetTestUtil.setTestId(this, "pagelist", m_infoList);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 11;
        this.m_infoList.setLayoutData(gridData);
        Composite composite = new Composite(this, SWT.NONE);
        WidgetTestUtil.setTestId(this, "button", composite);
        layout = new GridLayout(1, true);
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MULTI) != 0) {
            layout.numColumns = 2;
        }
        composite.setLayout(layout);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 4;
        composite.setLayoutData(gridData);
        // 追加ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.ADD) != 0) {
            this.m_buttonAdd = this.createButton(composite, Messages.getString("add"));
            WidgetTestUtil.setTestId(this, "add", m_buttonAdd);
            this.m_buttonAdd.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e)

            });
        }
        // 変更ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MODIFY) != 0) {
            this.m_buttonModify = this.createButton(composite, Messages.getString("modify"));
            WidgetTestUtil.setTestId(this, "modify", m_buttonModify);
            this.m_buttonModify.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = getSelectedItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().modify(item, m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 削除ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DELETE) != 0) {
            this.m_buttonDelete = this.createButton(composite, Messages.getString("delete"));
            WidgetTestUtil.setTestId(this, "delete", m_buttonDelete);
            this.m_buttonDelete.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        String detail = m_define.getItemsIdentifier(item);
                        String[] args = { detail };
                        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.monitor.31", args))) {
                            m_define.getTableItemInfoManager().delete(getSelectedItem());
                            m_infoList.update();
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.COPY) != 0) {
            this.m_buttonCopy = this.createButton(composite, Messages.getString("copy"));
            WidgetTestUtil.setTestId(this, "copy", m_buttonCopy);
            this.m_buttonCopy.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.SPACE) != 0) {
            Label label = new Label(composite, SWT.NONE);
            WidgetTestUtil.setTestId(this, "space", label);
        }
        // 上へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.UP) != 0) {
            this.m_buttonUp = this.createButton(composite, Messages.getString("up"));
            WidgetTestUtil.setTestId(this, "up", m_buttonUp);
            this.m_buttonUp.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().upOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 下へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DOWN) != 0) {
            this.m_buttonDown = this.createButton(composite, Messages.getString("down"));
            WidgetTestUtil.setTestId(this, "down", m_buttonDown);
            this.m_buttonDown.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().downOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
    }

    public void setInputData(List<T> list) {
        if (list != null) {
            this.m_infoList.setInputData(list);
        }
        // 必須項目を明示
        this.update();
    }

    /* (非 Javadoc)
	 * @see org.eclipse.swt.widgets.Control#setEnabled(boolean)
	 */
    @Override
    public void setEnabled(boolean enabled) {
        this.m_infoList.setEnabled(enabled);
        if (this.m_buttonAdd != null) {
            this.m_buttonAdd.setEnabled(enabled);
        }
        if (this.m_buttonModify != null) {
            this.m_buttonModify.setEnabled(enabled);
        }
        if (this.m_buttonDelete != null) {
            this.m_buttonDelete.setEnabled(enabled);
        }
        if (this.m_buttonCopy != null) {
            this.m_buttonCopy.setEnabled(enabled);
        }
        if (this.m_buttonUp != null) {
            this.m_buttonUp.setEnabled(enabled);
        }
        if (this.m_buttonDown != null) {
            this.m_buttonDown.setEnabled(enabled);
        }
    }

    protected Button createButton(Composite parent, String label) {
        Button button = new Button(parent, SWT.NONE);
        WidgetTestUtil.setTestId(this, null, button);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        button.setLayoutData(gridData);
        button.setText(label);
        return button;
    }

    protected void selectItem(T item) {
        Table table = this.m_infoList.getTableViewer().getTable();
        WidgetTestUtil.setTestId(this, null, table);
        TableItem[] items = table.getItems();
        if (items == null || item == null) {
            return;
        }
        for (int i = 0; i < items.length; i++) {
            @SuppressWarnings("unchecked")
            T tmpItem = (T) items[i].getData();
            WidgetTestUtil.setTestId(this, "items" + i, items[i]);
            if (item.equals(tmpItem)) {
                table.select(i);
                return;
            }
        }
    }

    protected T getSelectedItem() {
        StructuredSelection selection = (StructuredSelection) this.m_infoList.getTableViewer().getSelection();
        @SuppressWarnings("unchecked")
        T tableItemInfo = (T) selection.getFirstElement();
        return tableItemInfo;
    }

    public List<T> getItems() {
        return this.m_infoList.getTableItemData();
    }
}


package com.clustercontrol.monitor.run.composite;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.PlatformUI;
import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.dialog.CommonDialog;
import com.clustercontrol.util.Messages;

public class TableItemInfoComposite<T> extends Composite {

    /**
     * 判定情報一覧 コンポジット。
     */
    protected TableItemListComposite<T> m_infoList = null;

    protected ITableItemCompositeDefine<T> m_define = null;

    /**
     * 追加 ボタン。
     */
    protected Button m_buttonAdd = null;

    /**
     * 変更 ボタン。
     */
    protected Button m_buttonModify = null;

    /**
     * 削除 ボタン。
     */
    protected Button m_buttonDelete = null;

    protected Button m_buttonCopy = null;

    /**
     * 上へ ボタン。
     */
    protected Button m_buttonUp = null;

    /**
     * 下へ ボタン。
     */
    protected Button m_buttonDown = null;

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define) {
        this(parent, style, define, null);
    }

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define, List<T> items) {
        super(parent, style);
        this.m_define = define;
        if (items != null) {
            this.m_define.initTableItemInfoManager(items);
        } else {
            this.m_define.initTableItemInfoManager();
        }
        this.initialize();
    }

    protected void initialize() {
        // 変数として利用されるグリッドデータ
        GridData gridData = null;
        GridLayout layout = new GridLayout(1, true);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 15;
        this.setLayout(layout);
        this.m_infoList = new TableItemListComposite<T>(this, SWT.BORDER, this.m_define);
        WidgetTestUtil.setTestId(this, "pagelist", m_infoList);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 11;
        this.m_infoList.setLayoutData(gridData);
        Composite composite = new Composite(this, SWT.NONE);
        WidgetTestUtil.setTestId(this, "button", composite);
        layout = new GridLayout(1, true);
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MULTI) != 0) {
            layout.numColumns = 2;
        }
        composite.setLayout(layout);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHo

        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 4;
        composite.setLayoutData(gridData);
        // 追加ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.ADD) != 0) {
            this.m_buttonAdd = this.createButton(composite, Messages.getString("add"));
            WidgetTestUtil.setTestId(this, "add", m_buttonAdd);
            this.m_buttonAdd.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    CommonDialog dialog = m_define.createDialog(shell);
                    if (dialog.open() == IDialogConstants.OK_ID) {
                        m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                        m_infoList.update();
                    }
                }
            });
        }
        // 変更ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MODIFY) != 0) {
            this.m_buttonModify = this.createButton(composite, Messages.getString("modify"));
            WidgetTestUtil.setTestId(this, "modify", m_buttonModify);
            this.m_buttonModify.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = getSelectedItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().modify(item, m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 削除ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DELETE) != 0) {
            this.m_buttonDelete = this.createButton(composite, Messages.getString("delete"));
            WidgetTestUtil.setTestId(this, "delete", m_buttonDelete);
            this.m_buttonDelete.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        String detail = m_define.getItemsIdentifier(item);
                        String[] args = { detail };
                        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.monitor.31", args))) {
                            m_define.getTableItemInfoManager().delete(getSelectedItem());
                            m_infoList.update();
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.COPY) != 0) {
            this.m_buttonCopy = this.createButton(composite, Messages.getString("copy"));
            WidgetTestUtil.setTestId(this, "copy", m_buttonCopy);
            this.m_buttonCopy.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.SPACE) != 0) {
            Label label = new Label(composite, SWT.NONE);
            WidgetTestUtil.setTestId(this, "space", label);
        }
        // 上へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.UP) != 0) {
            this.m_buttonUp = this.createButton(composite, Messages.getString("up"));
            WidgetTestUtil.setTestId(this, "up", m_buttonUp);
            this.m_buttonUp.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().upOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 下へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DOWN) != 0) {
            this.m_buttonDown = this.createButton(composite, Messages.getString("down"));
            WidgetTestUtil.setTestId(this, "down", m_buttonDown);
            this.m_buttonDown.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().downOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
    }

    public void setInputData(List<T> list) {
        if (list != null) {
            this.m_infoList.setInputData(list);
        }
        // 必須項目を明示
        this.update();
    }

    /* (非 Javadoc)
	 * @see org.eclipse.swt.widgets.Control#setEnabled(boolean)
	 */
    @Override
    public void setEnabled(boolean enabled) {
        this.m_infoList.setEnabled(enabled);
        if (this.m_buttonAdd != null) {
            this.m_buttonAdd.setEnabled(enabled);
        }
        if (this.m_buttonModify != null) {
            this.m_buttonModify.setEnabled(enabled);
        }
        if (this.m_buttonDelete != null) {
            this.m_buttonDelete.setEnabled(enabled);
        }
        if (this.m_buttonCopy != null) {
            this.m_buttonCopy.setEnabled(enabled);
        }
        if (this.m_buttonUp != null) {
            this.m_buttonUp.setEnabled(enabled);
        }
        if (this.m_buttonDown != null) {
            this.m_buttonDown.setEnabled(enabled);
        }
    }

    protected Button createButton(Composite parent, String label) {
        Button button = new Button(parent, SWT.NONE);
        WidgetTestUtil.setTestId(this, null, button);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        button.setLayoutData(gridData);
        button.setText(label);
        return button;
    }

    protected void selectItem(T item) {
        Table table = this.m_infoList.getTableViewer().getTable();
        WidgetTestUtil.setTestId(this, null, table);
        TableItem[] items = table.getItems();
        if (items == null || item == null) {
            return;
        }
        for (int i = 0; i < items.length; i++) {
            @SuppressWarnings("unchecked")
            T tmpItem = (T) items[i].getData();
            WidgetTestUtil.setTestId(this, "items" + i, items[i]);
            if (item.equals(tmpItem)) {
                table.select(i);
                return;
            }
        }
    }

    protected T getSelectedItem() {
        StructuredSelection selection = (StructuredSelection) this.m_infoList.getTableViewer().getSelection();
        @SuppressWarnings("unchecked")
        T tableItemInfo = (T) selection.getFirstElement();
        return tableItemInfo;
    }

    public List<T> getItems() {
        return this.m_infoList.getTableItemData();
    }
}


for (int i = 0; i < items.length; i++) {
            @SuppressWarnings("unchecked")
            T tmpItem = (T) items[i].getData();
            WidgetTestUtil.setTestId(this, "items" + i, items[i]);
            if (item.equals(tmpItem)) {
                table.select(i);
                return;
            }
        }

package com.clustercontrol.monitor.run.composite;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.PlatformUI;
import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.dialog.CommonDialog;
import com.clustercontrol.util.Messages;

public class TableItemInfoComposite<T> extends Composite {

    /**
     * 判定情報一覧 コンポジット。
     */
    protected TableItemListComposite<T> m_infoList = null;

    protected ITableItemCompositeDefine<T> m_define = null;

    /**
     * 追加 ボタン。
     */
    protected Button m_buttonAdd = null;

    /**
     * 変更 ボタン。
     */
    protected Button m_buttonModify = null;

    /**
     * 削除 ボタン。
     */
    protected Button m_buttonDelete = null;

    protected Button m_buttonCopy = null;

    /**
     * 上へ ボタン。
     */
    protected Button m_buttonUp = null;

    /**
     * 下へ ボタン。
     */
    protected Button m_buttonDown = null;

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define) {
        this(parent, style, define, null);
    }

    public TableItemInfoComposite(Composite parent, int style, ITableItemCompositeDefine<T> define, List<T> items) {
        super(parent, style);
        this.m_define = define;
        if (items != null) {
            this.m_define.initTableItemInfoManager(items);
        } else {
            this.m_define.initTableItemInfoManager();
        }
        this.initialize();
    }

    protected void initialize() {
        // 変数として利用されるグリッドデータ
        GridData gridData = null;
        GridLayout layout = new GridLayout(1, true);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 15;
        this.setLayout(layout);
        this.m_infoList = new TableItemListComposite<T>(this, SWT.BORDER, this.m_define);
        WidgetTestUtil.setTestId(this, "pagelist", m_infoList);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 11;
        this.m_infoList.setLayoutData(gridData);
        Composite composite = new Composite(this, SWT.NONE);
        WidgetTestUtil.setTestId(this, "button", composite);
        layout = new GridLayout(1, true);
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MULTI) != 0) {
            layout.numColumns = 2;
        }
        composite.setLayout(layout);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 4;
        composite.setLayoutData(gridData);
        // 追加ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.ADD) != 0) {
            this.m_buttonAdd = this.createButton(composite, Messages.getString("add"));
            WidgetTestUtil.setTestId(this, "add", m_buttonAdd);
            this.m_buttonAdd.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    CommonDialog dialog = m_define.createDialog(shell);
                    if (dialog.open() == IDialogConstants.OK_ID) {
                        m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                        m_infoList.update();
                    }
                }
            });
        }
        // 変更ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.MODIFY) != 0) {
            this.m_buttonModify = this.createButton(composite, Messages.getString("modify"));
            WidgetTestUtil.setTestId(this, "modify", m_buttonModify);
            this.m_buttonModify.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = getSelectedItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().modify(item, m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 削除ボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DELETE) != 0) {
            this.m_buttonDelete = this.createButton(composite, Messages.getString("delete"));
            WidgetTestUtil.setTestId(this, "delete", m_buttonDelete);
            this.m_buttonDelete.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        String detail = m_define.getItemsIdentifier(item);
                        String[] args = { detail };
                        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.monitor.31", args))) {
                            m_define.getTableItemInfoManager().delete(getSelectedItem());
                            m_infoList.update();
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.COPY) != 0) {
            this.m_buttonCopy = this.createButton(composite, Messages.getString("copy"));
            WidgetTestUtil.setTestId(this, "copy", m_buttonCopy);
            this.m_buttonCopy.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        CommonDialog dialog = m_define.createDialog(shell, item);
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            Table table = m_infoList.getTableViewer().getTable();
                            WidgetTestUtil.setTestId(this, "modify", table);
                            int selectIndex = table.getSelectionIndex();
                            m_define.getTableItemInfoManager().add(m_define.getCurrentCreatedItem());
                            m_infoList.update();
                            table.setSelection(selectIndex);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.SPACE) != 0) {
            Label label = new Label(composite, SWT.NONE);
            WidgetTestUtil.setTestId(this, "space", label);
        }
        // 上へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.UP) != 0) {
            this.m_buttonUp = this.createButton(composite, Messages.getString("up"));
            WidgetTestUtil.setTestId(this, "up", m_buttonUp);
            this.m_buttonUp.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().upOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
        // 下へボタン
        if ((this.m_define.getButtonOptions() & ITableItemCompositeDefine.DOWN) != 0) {
            this.m_buttonDown = this.createButton(composite, Messages.getString("down"));
            WidgetTestUtil.setTestId(this, "down", m_buttonDown);
            this.m_buttonDown.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    T item = m_infoList.getTableItem();
                    if (item != null) {
                        if (m_define.getTableItemInfoManager().downOrder(item)) {
                            m_infoList.update();
                            selectItem(item);
                        }
                    } else {
                        MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.monitor.30"));
                    }
                }
            });
        }
    }

    public void setInputData(List<T> list) {
        if (list != null) {
            this.m_infoList.setInputData(list);
        }
        // 必須項目を明示
        this.update();
    }

    /* (非 Javadoc)
	 * @see org.eclipse.swt.widgets.Control#setEnabled(boolean)
	 */
    @Override
    public void setEnabled(boolean enabled) {
        this.m_infoList.setEnabled(enabled);
        if (this.m_buttonAdd != null) {
            this.m_buttonAdd.setEnabled(enabled);
        }
        if (this.m_buttonModify != null) {
            this.m_buttonModify.setEnabled(enabled);
        }
        if (this.m_buttonDelete != null) {
            this.m_buttonDelete.setEnabled(enabled);
        }
        if (this.m_buttonCopy != null) {
            this.m_buttonCopy.setEnabled(enabled);
        }
        if (this.m_buttonUp != null) {
            this.m_buttonUp.setEnabled(enabled);
        }
        if (this.m_buttonDown != null) {
            this.m_buttonDown.setEnabled(enabled);
        }
    }

    protected Button createButton(Composite parent, String label) {
        Button button = new Button(parent, SWT.NONE);
        WidgetTestUtil.setTestId(this, null, button);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        button.setLayoutData(gridData);
        button.setText(label);
        return button;
    }

    protected void selectItem(T item) {
        Table table = this.m_infoList.getTableViewer().getTable();
        WidgetTestUtil.setTestId(this, null, table);
        TableItem[] items = table.getItems();
        if (items == null || item == null) {
            return;
        }

    }

    protected T getSelectedItem() {
        StructuredSelection selection = (StructuredSelection) this.m_infoList.getTableViewer().getSelection();
        @SuppressWarnings("unchecked")
        T tableItemInfo = (T) selection.getFirstElement();
        return tableItemInfo;
    }

    public List<T> getItems() {
        return this.m_infoList.getTableItemData();
    }
}


@Override
    public String commandAction()

package info.nightscout.androidaps.plugins.pump.medtronic.defs;

import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType;

/**
 * Created by andy on 4/5/19.
 */
public enum CommandValueDefinitionMDTType implements CommandValueDefinitionType {

    GetModel, TuneUp, GetProfile, GetTBR;

    @Override
    public String getName() {
        return this.name();
    }

    @Override
    public String getDescription() {
        return null;
    }


package info.nightscout.androidaps.plugins.pump.medtronic.defs;

import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType;

/**
 * Created by andy on 4/5/19.
 */
public enum CommandValueDefinitionMDTType implements CommandValueDefinitionType {

    GetModel, TuneUp, GetProfile, GetTBR;

    @Override
    public String getName() {
        return this.name();
    }

    @Override
    public String getDescription() {
        return null;
    }

    @Override
    public String commandAction()


package info.nightscout.androidaps.plugins.pump.medtronic.defs;

import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType;

/**
 * Created by andy on 4/5/19.
 */
public enum CommandValueDefinitionMDTType implements CommandValueDefinitionType {

    GetModel, TuneUp, GetProfile, GetTBR;

    @Override
    public String getName() {
        return this.name();
    }

    @Override
    public String getDescription() {
        return n

    }

    @Override
    public String commandAction() {
        return null;
    }
}


package com.atguigu.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
// EurekaServer服务器端启动类,接受其它微服务注册进来
@EnableEurekaServer
public class EurekaServer7001_App {

{
        SpringApplication.run(EurekaServer7001_App.class, args);
    }
}


{
        SpringApplication.run(EurekaServer7001_App.class, args);
    }

package com.atguigu.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
// EurekaServer服务器端启动类,接受其它微服务注册进来
@EnableEurekaServer
public class EurekaServer7001_App {

    public static void main(String[] args)


package com.atguigu.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
// EurekaServer服务器端启动类,接受其它微服务注册进来
@EnableEurekaServer
public class EurekaServer7001_App {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServer


@Override
                public void run()

package com.thibaudperso.sonycamera.timelapse.ui.adjustments;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.ViewGroup.LayoutParams;
import com.thibaudperso.sonycamera.timelapse.ui.adjustments.SimpleLiveviewSlicer.Payload;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import static android.content.ContentValues.TAG;
import static com.thibaudperso.sonycamera.timelapse.Constants.LOG_TAG;

/**
 * A SurfaceView based class to draw liveview frames serially.
 */
public class SimpleStreamSurfaceView extends SurfaceView implements SurfaceHolder.Callback {

    private boolean mWhileFetching;

    private final BlockingQueue<byte[]> mJpegQueue = new ArrayBlockingQueue<>(2);

    private Thread mDrawerThread;

    private Handler mSlicerHandler;

    private int mPreviousWidth = 0;

    private int mPreviousHeight = 0;

    private final Paint mFramePaint;

    private SimpleLiveviewSlicer mSlicer;

    public SimpleStreamSurfaceView(Context context) {
        super(context);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mWhileFetching = false;
    }

    /**
     * Start retrieving and drawing liveview frame data by new threads.
     *
     * @return true if the starting is completed successfully, false otherwise.
     * @throws IllegalStateException when Remote API object is not set.
     */
    public boolean start(final String liveviewUrl) {
        if (mWhileFetching) {
            Log.w(TAG, "start() already starting.");
            return false;
        }
        mWhileFetching = true;
        // A thread for retrieving liveview data from server.
        Thread slicerThread = new Thread(new Runnable() {

            @Override
            public void run() {
                mSlicer = null;
                try {
                    // Create Slicer to open the stream and parse it.
                    mSlicer = new SimpleLiveviewSlicer();
                    mSlicer.open(liveviewUrl);
                    Looper.prepare();
                    mSlicerHandler = new Handler();
                    while (mWhileFetching) {
                        final Payload payload = mSlicer.nextPayload();
                        if (payload == null) {
                            // never occurs
                            Log.e(LOG_TAG, "Liveview Payload is null.");
                            continue;
                        }
                        if (mJpegQueue.size() == 2) {
                            mJpegQueue.remove();
                        }
                        mJpegQueue.add(payload.jpegData);
                    }
                } catch (IOException e) {
                    Log.w(LOG_TAG, "IOException while fetching: " + e.getMessage());
                } finally {
                    // Finalize
                    try {
                        if (mSlicer != null) {
                            mSlicer.close();
                        }
                    } catch (IOException e) {
                        Log.w(LOG_TAG, "IOException while closing slicer: " + e.getMessage());
                    }
                    if (mDrawerThread != null) {
                        mDrawerThread.interrupt();
                    }
                    mJpegQueue.clear();
                    mWhileFetching = false;
                }
            }
        });
        slicerThread.start();
        // A thread for drawing liveview frame fetched by above thread.
        mDrawerThread = new Thread() {

            @Override
            public void run() {
                Bitmap frameBitmap = null;
                BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
                factoryOptions.inSampleSize = 1;
                initInBitmap(factoryOptions);
                while (mWhileFetching) {
                    try {
                        byte[] jpegData = mJpegQueue.take();
                        frameBitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, factoryOptions);
                    } catch (IllegalArgumentException e) {
                        clearInBitmap(factoryOptions);
                        continue;
                    } catch (InterruptedException e) {
                        Log.i(TAG, "Drawer thread is Interrupted.");
                        e.printStackTrace();
                        break;
                    }
                    setInBitmap(factoryOptions, frameBitmap);
                    drawFrame(frameBitmap);
                }
                if (frameBitmap != null) {
                    frameBitmap.recycle();
                }
                mWhileFetching = false;
            }
        };
        mDrawerThread.start();
        return true;
    }

    /**
     * Request to stop retrieving and drawing liveview data.
     */
    public void stop() {
        mWhileFetching = false;
        if (mSlicer != null && mSlicerHandler != null) {
            mSlicerHandler.post(new Runnable() {

{
                    try {
                        mSlicer.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            mSlicerHandler = null;
        }
    }

    /**
     * Check to see whether start() is already called.
     *
     * @return true if start() is already called, false otherwise.
     */
    public boolean isStarted() {
        return mWhileFetching;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void initInBitmap(BitmapFactory.Options options) {
        options.inBitmap = null;
        options.inMutable = true;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void clearInBitmap(BitmapFactory.Options options) {
        if (options.inBitmap != null) {
            options.inBitmap.recycle();
            options.inBitmap = null;
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setInBitmap(BitmapFactory.Options options, Bitmap bitmap) {
        options.inBitmap = bitmap;
    }

    // Draw frame bitmap onto a canvas.
    private void drawFrame(Bitmap frame) {
        if (frame.getWidth() != mPreviousWidth || frame.getHeight() != mPreviousHeight) {
            onDetectedFrameSizeChanged(frame.getWidth(), frame.getHeight());
            return;
        }
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        int w = frame.getWidth();
        int h = frame.getHeight();
        Rect src = new Rect(0, 0, w, h);
        float by = Math.min((float) getWidth() / w, (float) getHeight() / h);
        int offsetX = (getWidth() - (int) (w * by)) / 2;
        int offsetY = (getHeight() - (int) (h * by)) / 2;
        Rect dst = new Rect(offsetX, offsetY, getWidth() - offsetX, getHeight() - offsetY);
        canvas.drawBitmap(frame, src, dst, mFramePaint);
        getHolder().unlockCanvasAndPost(canvas);
    }

    // Called when the width or height of liveview frame image is changed.
    private void onDetectedFrameSizeChanged(final int width, final int height) {
        mPreviousWidth = width;
        mPreviousHeight = height;
        drawBlackFrame();
        drawBlackFrame();
        // delete triple buffers
        drawBlackFrame();
        ((Activity) getContext()).runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // Get the SurfaceView layout parameters
                LayoutParams lp = getLayoutParams();
                lp.width = getWidth();
                lp.height = (int) (((float) height / (float) width) * (float) getWidth());
                setLayoutParams(lp);
            }
        });
    }

    // Draw black screen.
    private void drawBlackFrame() {
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
        getHolder().unlockCanvasAndPost(canvas);
    }
}


{
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
        getHolder().unlockCanvasAndPost(canvas);
    }

package com.thibaudperso.sonycamera.timelapse.ui.adjustments;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.ViewGroup.LayoutParams;
import com.thibaudperso.sonycamera.timelapse.ui.adjustments.SimpleLiveviewSlicer.Payload;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import static android.content.ContentValues.TAG;
import static com.thibaudperso.sonycamera.timelapse.Constants.LOG_TAG;

/**
 * A SurfaceView based class to draw liveview frames serially.
 */
public class SimpleStreamSurfaceView extends SurfaceView implements SurfaceHolder.Callback {

    private boolean mWhileFetching;

    private final BlockingQueue<byte[]> mJpegQueue = new ArrayBlockingQueue<>(2);

    private Thread mDrawerThread;

    private Handler mSlicerHandler;

    private int mPreviousWidth = 0;

    private int mPreviousHeight = 0;

    private final Paint mFramePaint;

    private SimpleLiveviewSlicer mSlicer;

    public SimpleStreamSurfaceView(Context context) {
        super(context);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mWhileFetching = false;
    }

    /**
     * Start retrieving and drawing liveview frame data by new threads.
     *
     * @return true if the starting is completed successfully, false otherwise.
     * @throws IllegalStateException when Remote API object is not set.
     */
    public boolean start(final String liveviewUrl) {
        if (mWhileFetching) {
            Log.w(TAG, "start() already starting.");
            return false;
        }
        mWhileFetching = true;
        // A thread for retrieving liveview data from server.
        Thread slicerThread = new Thread(new Runnable() {

            @Override
            public void run() {
                mSlicer = null;
                try {
                    // Create Slicer to open the stream and parse it.
                    mSlicer = new SimpleLiveviewSlicer();
                    mSlicer.open(liveviewUrl);
                    Looper.prepare();
                    mSlicerHandler = new Handler();
                    while (mWhileFetching) {
                        final Payload payload = mSlicer.nextPayload();
                        if (payload == null) {
                            // never occurs
                            Log.e(LOG_TAG, "Liveview Payload is null.");
                            continue;
                        }
                        if (mJpegQueue.size() == 2) {
                            mJpegQueue.remove();
                        }
                        mJpegQueue.add(payload.jpegData);
                    }
                } catch (IOException e) {
                    Log.w(LOG_TAG, "IOException while fetching: " + e.getMessage());
                } finally {
                    // Finalize
                    try {
                        if (mSlicer != null) {
                            mSlicer.close();
                        }
                    } catch (IOException e) {
                        Log.w(LOG_TAG, "IOException while closing slicer: " + e.getMessage());
                    }
                    if (mDrawerThread != null) {
                        mDrawerThread.interrupt();
                    }
                    mJpegQueue.clear();
                    mWhileFetching = false;
                }
            }
        });
        slicerThread.start();
        // A thread for drawing liveview frame fetched by above thread.
        mDrawerThread = new Thread() {

            @Override
            public void run() {
                Bitmap frameBitmap = null;
                BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
                factoryOptions.inSampleSize = 1;
                initInBitmap(factoryOptions);
                while (mWhileFetching) {
                    try {
                        byte[] jpegData = mJpegQueue.take();
                        frameBitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, factoryOptions);
                    } catch (IllegalArgumentException e) {
                        clearInBitmap(factoryOptions);
                        continue;
                    } catch (InterruptedException e) {
                        Log.i(TAG, "Drawer thread is Interrupted.");
                        e.printStackTrace();
                        break;
                    }
                    setInBitmap(factoryOptions, frameBitmap);
                    drawFrame(frameBitmap);
                }
                if (frameBitmap != null) {
                    frameBitmap.recycle();
                }
                mWhileFetching = false;
            }
        };
        mDrawerThread.start();
        return true;
    }

    /**
     * Request to stop retrieving and drawing liveview data.
     */
    public void stop() {
        mWhileFetching = false;
        if (mSlicer != null && mSlicerHandler != null) {
            mSlicerHandler.post(new Runnable() {

                @Override
                public void run() {
                    try {
                        mSlicer.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            mSlicerHandler = null;
        }
    }

    /**
     * Check to see whether start() is already called.
     *
     * @return true if start() is already called, false otherwise.
     */
    public boolean isStarted() {
        return mWhileFetching;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void initInBitmap(BitmapFactory.Options options) {
        options.inBitmap = null;
        options.inMutable = true;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void clearInBitmap(BitmapFactory.Options options) {
        if (options.inBitmap != null) {
            options.inBitmap.recycle();
            options.inBitmap = null;
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setInBitmap(BitmapFactory.Options options, Bitmap bitmap) {
        options.inBitmap = bitmap;
    }

    // Draw frame bitmap onto a canvas.
    private void drawFrame(Bitmap frame) {
        if (frame.getWidth() != mPreviousWidth || frame.getHeight() != mPreviousHeight) {
            onDetectedFrameSizeChanged(frame.getWidth(), frame.getHeight());
            return;
        }
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        int w = frame.getWidth();
        int h = frame.getHeight();
        Rect src = new Rect(0, 0, w, h);
        float by = Math.min((float) getWidth() / w, (float) getHeight() / h);
        int offsetX = (getWidth() - (int) (w * by)) / 2;
        int offsetY = (getHeight() - (int) (h * by)) / 2;
        Rect dst = new Rect(offsetX, offsetY, getWidth() - offsetX, getHeight() - offsetY);
        canvas.drawBitmap(frame, src, dst, mFramePaint);
        getHolder().unlockCanvasAndPost(canvas);
    }

    // Called when the width or height of liveview frame image is changed.
    private void onDetectedFrameSizeChanged(final int width, final int height) {
        mPreviousWidth = width;
        mPreviousHeight = height;
        drawBlackFrame();
        drawBlackFrame();
        // delete triple buffers
        drawBlackFrame();
        ((Activity) getContext()).runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // Get the SurfaceView layout parameters
                LayoutParams lp = getLayoutParams();
                lp.width = getWidth();
                lp.height = (int) (((float) height / (float) width) * (float) getWidth());
                setLayoutParams(lp);
            }
        });
    }

    // Draw black screen.
    private void drawBlackFrame()


actoryOptions = new BitmapFactory.Options();

package com.thibaudperso.sonycamera.timelapse.ui.adjustments;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.ViewGroup.LayoutParams;
import com.thibaudperso.sonycamera.timelapse.ui.adjustments.SimpleLiveviewSlicer.Payload;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import static android.content.ContentValues.TAG;
import static com.thibaudperso.sonycamera.timelapse.Constants.LOG_TAG;

/**
 * A SurfaceView based class to draw liveview frames serially.
 */
public class SimpleStreamSurfaceView extends SurfaceView implements SurfaceHolder.Callback {

    private boolean mWhileFetching;

    private final BlockingQueue<byte[]> mJpegQueue = new ArrayBlockingQueue<>(2);

    private Thread mDrawerThread;

    private Handler mSlicerHandler;

    private int mPreviousWidth = 0;

    private int mPreviousHeight = 0;

    private final Paint mFramePaint;

    private SimpleLiveviewSlicer mSlicer;

    public SimpleStreamSurfaceView(Context context) {
        super(context);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mWhileFetching = false;
    }

    /**
     * Start retrieving and drawing liveview frame data by new threads.
     *
     * @return true if the starting is completed successfully, false otherwise.
     * @throws IllegalStateException when Remote API object is not set.
     */
    public boolean start(final String liveviewUrl) {
        if (mWhileFetching) {
            Log.w(TAG, "start() already starting.");
            return false;
        }
        mWhileFetching = true;
        // A thread for retrieving liveview data from server.
        Thread slicerThread = new Thread(new Runnable() {

            @Override
            public void run() {
                mSlicer = null;
                try {
                    // Create Slicer to open the stream and parse it.
                    mSlicer = new SimpleLiveviewSlicer();
                    mSlicer.open(liveviewUrl);
                    Looper.prepare();
                    mSlicerHandler = new Handler();
                    while (mWhileFetching) {
                        final Payload payload = mSlicer.nextPayload();
                        if (payload == null) {
                            // never occurs
                            Log.e(LOG_TAG, "Liveview Payload is null.");
                            continue;
                        }
                        if (mJpegQueue.size() == 2) {
                            mJpegQueue.remove();
                        }
                        mJpegQueue.add(payload.jpegData);
                    }
                } catch (IOException e) {
                    Log.w(LOG_TAG, "IOException while fetching: " + e.getMessage());
                } finally {
                    // Finalize
                    try {
                        if (mSlicer != null) {
                            mSlicer.close();
                        }
                    } catch (IOException e) {
                        Log.w(LOG_TAG, "IOException while closing slicer: " + e.getMessage());
                    }
                    if (mDrawerThread != null) {
                        mDrawerThread.interrupt();
                    }
                    mJpegQueue.clear();
                    mWhileFetching = false;
                }
            }
        });
        slicerThread.start();
        // A thread for drawing liveview frame fetched by above thread.
        mDrawerThread = new Thread() {

            @Override
            public void run() {
                Bitmap frameBitmap = null;
                BitmapFactory.Options f

                factoryOptions.inSampleSize = 1;
                initInBitmap(factoryOptions);
                while (mWhileFetching) {
                    try {
                        byte[] jpegData = mJpegQueue.take();
                        frameBitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, factoryOptions);
                    } catch (IllegalArgumentException e) {
                        clearInBitmap(factoryOptions);
                        continue;
                    } catch (InterruptedException e) {
                        Log.i(TAG, "Drawer thread is Interrupted.");
                        e.printStackTrace();
                        break;
                    }
                    setInBitmap(factoryOptions, frameBitmap);
                    drawFrame(frameBitmap);
                }
                if (frameBitmap != null) {
                    frameBitmap.recycle();
                }
                mWhileFetching = false;
            }
        };
        mDrawerThread.start();
        return true;
    }

    /**
     * Request to stop retrieving and drawing liveview data.
     */
    public void stop() {
        mWhileFetching = false;
        if (mSlicer != null && mSlicerHandler != null) {
            mSlicerHandler.post(new Runnable() {

                @Override
                public void run() {
                    try {
                        mSlicer.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            mSlicerHandler = null;
        }
    }

    /**
     * Check to see whether start() is already called.
     *
     * @return true if start() is already called, false otherwise.
     */
    public boolean isStarted() {
        return mWhileFetching;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void initInBitmap(BitmapFactory.Options options) {
        options.inBitmap = null;
        options.inMutable = true;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void clearInBitmap(BitmapFactory.Options options) {
        if (options.inBitmap != null) {
            options.inBitmap.recycle();
            options.inBitmap = null;
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setInBitmap(BitmapFactory.Options options, Bitmap bitmap) {
        options.inBitmap = bitmap;
    }

    // Draw frame bitmap onto a canvas.
    private void drawFrame(Bitmap frame) {
        if (frame.getWidth() != mPreviousWidth || frame.getHeight() != mPreviousHeight) {
            onDetectedFrameSizeChanged(frame.getWidth(), frame.getHeight());
            return;
        }
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        int w = frame.getWidth();
        int h = frame.getHeight();
        Rect src = new Rect(0, 0, w, h);
        float by = Math.min((float) getWidth() / w, (float) getHeight() / h);
        int offsetX = (getWidth() - (int) (w * by)) / 2;
        int offsetY = (getHeight() - (int) (h * by)) / 2;
        Rect dst = new Rect(offsetX, offsetY, getWidth() - offsetX, getHeight() - offsetY);
        canvas.drawBitmap(frame, src, dst, mFramePaint);
        getHolder().unlockCanvasAndPost(canvas);
    }

    // Called when the width or height of liveview frame image is changed.
    private void onDetectedFrameSizeChanged(final int width, final int height) {
        mPreviousWidth = width;
        mPreviousHeight = height;
        drawBlackFrame();
        drawBlackFrame();
        // delete triple buffers
        drawBlackFrame();
        ((Activity) getContext()).runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // Get the SurfaceView layout parameters
                LayoutParams lp = getLayoutParams();
                lp.width = getWidth();
                lp.height = (int) (((float) height / (float) width) * (float) getWidth());
                setLayoutParams(lp);
            }
        });
    }

    // Draw black screen.
    private void drawBlackFrame() {
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
        getHolder().unlockCanvasAndPost(canvas);
    }
}


public void stop() {
        mWhileFetching = false;
        if (mSlicer != null && mSlicerHandler != null) {
            mSlicerHandler.post(new Runnable() {

                @Override
                public void run() {
                    try {
                        mSlicer.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            mSlicerHandler = null;
        }
    }

package com.thibaudperso.sonycamera.timelapse.ui.adjustments;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.ViewGroup.LayoutParams;
import com.thibaudperso.sonycamera.timelapse.ui.adjustments.SimpleLiveviewSlicer.Payload;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import static android.content.ContentValues.TAG;
import static com.thibaudperso.sonycamera.timelapse.Constants.LOG_TAG;

/**
 * A SurfaceView based class to draw liveview frames serially.
 */
public class SimpleStreamSurfaceView extends SurfaceView implements SurfaceHolder.Callback {

    private boolean mWhileFetching;

    private final BlockingQueue<byte[]> mJpegQueue = new ArrayBlockingQueue<>(2);

    private Thread mDrawerThread;

    private Handler mSlicerHandler;

    private int mPreviousWidth = 0;

    private int mPreviousHeight = 0;

    private final Paint mFramePaint;

    private SimpleLiveviewSlicer mSlicer;

    public SimpleStreamSurfaceView(Context context) {
        super(context);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    public SimpleStreamSurfaceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        getHolder().addCallback(this);
        mFramePaint = new Paint();
        mFramePaint.setDither(true);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mWhileFetching = false;
    }

    /**
     * Start retrieving and drawing liveview frame data by new threads.
     *
     * @return true if the starting is completed successfully, false otherwise.
     * @throws IllegalStateException when Remote API object is not set.
     */
    public boolean start(final String liveviewUrl) {
        if (mWhileFetching) {
            Log.w(TAG, "start() already starting.");
            return false;
        }
        mWhileFetching = true;
        // A thread for retrieving liveview data from server.
        Thread slicerThread = new Thread(new Runnable() {

            @Override
            public void run() {
                mSlicer = null;
                try {
                    // Create Slicer to open the stream and parse it.
                    mSlicer = new SimpleLiveviewSlicer();
                    mSlicer.open(liveviewUrl);
                    Looper.prepare();
                    mSlicerHandler = new Handler();
                    while (mWhileFetching) {
                        final Payload payload = mSlicer.nextPayload();
                        if (payload == null) {
                            // never occurs
                            Log.e(LOG_TAG, "Liveview Payload is null.");
                            continue;
                        }
                        if (mJpegQueue.size() == 2) {
                            mJpegQueue.remove();
                        }
                        mJpegQueue.add(payload.jpegData);
                    }
                } catch (IOException e) {
                    Log.w(LOG_TAG, "IOException while fetching: " + e.getMessage());
                } finally {
                    // Finalize
                    try {
                        if (mSlicer != null) {
                            mSlicer.close();
                        }
                    } catch (IOException e) {
                        Log.w(LOG_TAG, "IOException while closing slicer: " + e.getMessage());
                    }
                    if (mDrawerThread != null) {
                        mDrawerThread.interrupt();
                    }
                    mJpegQueue.clear();
                    mWhileFetching = false;
                }
            }
        });
        slicerThread.start();
        // A thread for drawing liveview frame fetched by above thread.
        mDrawerThread = new Thread() {

            @Override
            public void run() {
                Bitmap frameBitmap = null;
                BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
                factoryOptions.inSampleSize = 1;
                initInBitmap(factoryOptions);
                while (mWhileFetching) {
                    try {
                        byte[] jpegData = mJpegQueue.take();
                        frameBitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, factoryOptions);
                    } catch (IllegalArgumentException e) {
                        clearInBitmap(factoryOptions);
                        continue;
                    } catch (InterruptedException e) {
                        Log.i(TAG, "Drawer thread is Interrupted.");
                        e.printStackTrace();
                        break;
                    }
                    setInBitmap(factoryOptions, frameBitmap);
                    drawFrame(frameBitmap);
                }
                if (frameBitmap != null) {
                    frameBitmap.recycle();
                }
                mWhileFetching = false;
            }
        };
        mDrawerThread.start();
        return true;
    }

    /**
     * Request to stop retrieving and drawing liveview data.
     */

    /**
     * Check to see whether start() is already called.
     *
     * @return true if start() is already called, false otherwise.
     */
    public boolean isStarted() {
        return mWhileFetching;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void initInBitmap(BitmapFactory.Options options) {
        options.inBitmap = null;
        options.inMutable = true;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void clearInBitmap(BitmapFactory.Options options) {
        if (options.inBitmap != null) {
            options.inBitmap.recycle();
            options.inBitmap = null;
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setInBitmap(BitmapFactory.Options options, Bitmap bitmap) {
        options.inBitmap = bitmap;
    }

    // Draw frame bitmap onto a canvas.
    private void drawFrame(Bitmap frame) {
        if (frame.getWidth() != mPreviousWidth || frame.getHeight() != mPreviousHeight) {
            onDetectedFrameSizeChanged(frame.getWidth(), frame.getHeight());
            return;
        }
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        int w = frame.getWidth();
        int h = frame.getHeight();
        Rect src = new Rect(0, 0, w, h);
        float by = Math.min((float) getWidth() / w, (float) getHeight() / h);
        int offsetX = (getWidth() - (int) (w * by)) / 2;
        int offsetY = (getHeight() - (int) (h * by)) / 2;
        Rect dst = new Rect(offsetX, offsetY, getWidth() - offsetX, getHeight() - offsetY);
        canvas.drawBitmap(frame, src, dst, mFramePaint);
        getHolder().unlockCanvasAndPost(canvas);
    }

    // Called when the width or height of liveview frame image is changed.
    private void onDetectedFrameSizeChanged(final int width, final int height) {
        mPreviousWidth = width;
        mPreviousHeight = height;
        drawBlackFrame();
        drawBlackFrame();
        // delete triple buffers
        drawBlackFrame();
        ((Activity) getContext()).runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // Get the SurfaceView layout parameters
                LayoutParams lp = getLayoutParams();
                lp.width = getWidth();
                lp.height = (int) (((float) height / (float) width) * (float) getWidth());
                setLayoutParams(lp);
            }
        });
    }

    // Draw black screen.
    private void drawBlackFrame() {
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
        getHolder().unlockCanvasAndPost(canvas);
    }
}