root/graph/JavaPopWeb/src/jp/ac/nime/computer/grpsimulator/DlgHistogram.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. DlgHistogram
  2. initComponents
  3. setHistogram
  4. setParameterType
  5. setEnableBinaryMode
  6. getParameterType
  7. getParameters
  8. requireSrc
  9. actionPerformed
  10. addActionListener
  11. removeActionListener

package jp.ac.nime.computer.grpsimulator;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;

/** 画像変換 ヒストグラム表示 パラメタ設定ダイアログ
 *
 * @version 1.0.0
 * @author  igarashi
 */
public class DlgHistogram extends JPanel
        implements ParameterSetting, ActionListener
{
        private int paramType_;
        private HistogramViewPanel histView_;
        private ActionListener actionListener_;
        private JPanel addPanel_;
        private JLabel limitLabel_;
        private JButton autoBtn_;
        private boolean bBinaryModeEnable_;

        /** Creates new form DlgHistogram */
        public DlgHistogram() {
                initComponents();
        }

        /** This method is called from within the constructor to initialize the form.
         */
        private void initComponents() {
                setBorder(new TitledBorder(GrpSim.res_.getString("DlgHistogramCaption")));
                setLayout(new BorderLayout());

                JPanel mainPanel = new JPanel();
                mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
                add(mainPanel, BorderLayout.NORTH);

                histView_ = new HistogramViewPanel(320,240);    // ヒストグラム表示の大きさ
                histView_.addActionListener(this);
                mainPanel.add(histView_);

                JPanel staticsPanel = new JPanel();
                staticsPanel.setLayout(new BorderLayout());
                mainPanel.add(staticsPanel);

                JLabel label;
                label = new JLabel();
                label.setHorizontalAlignment(SwingConstants.LEFT);
                label.setText("0");
                staticsPanel.add(label, BorderLayout.WEST);
                label = new JLabel();
                label.setHorizontalAlignment(SwingConstants.CENTER);
                label.setText("50");
                staticsPanel.add(label, BorderLayout.CENTER);
                label = new JLabel();
                label.setHorizontalAlignment(SwingConstants.RIGHT);
                label.setText("100");
                staticsPanel.add(label, BorderLayout.EAST);

                addPanel_ = new JPanel();
                addPanel_.setLayout(new FlowLayout(FlowLayout.RIGHT,10,2));
                mainPanel.add(addPanel_);
        }


        public boolean setHistogram( int[] histogram ) {
                return histView_.setHistogram( histogram );
        }

        public void setParameterType( int paramType ) {
                paramType_ = paramType;
        }

        public void setEnableBinaryMode(boolean bEnable) {
                addPanel_.removeAll();
                if (bEnable) {
                        JLabel jLabel = new JLabel();
                        jLabel.setText(GrpSim.res_.getString("DlgHistogramLimitLabel"));
                        addPanel_.add(jLabel);
                        limitLabel_ = new JLabel();
                        limitLabel_.setText("---");
                        addPanel_.add(limitLabel_);
                        autoBtn_ = new JButton();
                        autoBtn_.setText(GrpSim.res_.getString("DlgHistogramAutoButton"));
                        autoBtn_.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent evt) {
                                        histView_.autoBinarySelect();
                                }
                        });
                        addPanel_.add(autoBtn_);
                }
                bBinaryModeEnable_ = bEnable;
        }

        /** 変換の種類を取得します
         * @return 変換の種類を表す値
         */
        public int getParameterType() {
                return paramType_;
        }

        /** 変換のパラメータを取得します
         * @return パラメータを表す配列。内容については変換の種類に依存します。
         */
        public int[] getParameters() {
                return histView_.getParameters();
        }

        /** 変換元画像を必要とするかどうかを返す
         * @return 変換元画像を必要とするならtrueを返す
         */
        public boolean requireSrc() {
                return true;
        }

        /**
         *  イベント探知
         */
        public void actionPerformed(ActionEvent e) {
                if (bBinaryModeEnable_) {
                        int limit = histView_.getMinimum();
                        if (limit == -1) {
                                limitLabel_.setText("---");
                        } else {
                                String buf = "000" + String.valueOf(limit);
                                limitLabel_.setText(buf.substring(buf.length()-3));
                        }
                }
                actionListener_.actionPerformed(
                        new ActionEvent(this,ActionEvent.ACTION_PERFORMED,"ParameterChanged")
                );
        }

        public void addActionListener(ActionListener listener) {
                actionListener_ = AWTEventMulticaster.add(actionListener_, listener);
        }
        public void removeActionListener(ActionListener listener) {
                actionListener_ = AWTEventMulticaster.remove(actionListener_, listener);
        }
}

/* [<][>][^][v][top][bottom][index][help] */