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

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

DEFINITIONS

This source file includes following definitions.
  1. DlgMeasureArea
  2. initComponents
  3. jButton4_ActionPerformed
  4. jButton3_ActionPerformed
  5. jButton2_ActionPerformed
  6. jButton1_ActionPerformed
  7. resetState
  8. addActionListener
  9. removeActionListener
  10. getParameterType
  11. getParameters
  12. getStepCount
  13. requireSrc
  14. setStepDone
  15. setStepResult
  16. AreaLabel
  17. getListCellRendererComponent

package jp.ac.nime.computer.grpsimulator;

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

/** 画像計測 面積用 ダイアログ
 * @version 1.0.0
 * @author  igarashi
 * @author  kikuchi
 */
public class DlgMeasureArea extends JPanel
        implements OperationDialog, SteppingParameter
{
        
        private ActionListener actionListener_;
        
        private int nStepCount_;        // 状態を示す
  
        /** Creates new form DlgMeasureArea */
        public DlgMeasureArea() {
                initComponents();
              
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
    private void initComponents() {//GEN-BEGIN:initComponents
        JScrollPane jScrollPane1;
        GridBagConstraints gridBagConstraints;

        jButton1_ = new JButton();
        jButton2_ = new JButton();
        jButton3_ = new JButton();
        jButton4_ = new JButton();
        jScrollPane1 = new JScrollPane();
        jList_ = new JList();
                /* JList_ に CellRendererを設定する */
                AreaLabel renderer = new AreaLabel();
                jList_.setCellRenderer(renderer);

        setLayout(new GridBagLayout());

        setBorder(new javax.swing.border.TitledBorder(GrpSim.res_.getString("DlgMeasureAreaCaption")));
        setPreferredSize(new Dimension(320, 240));
        jButton1_.setText(GrpSim.res_.getString("DlgMeasureAreaButtonBinary"));
        jButton1_.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jButton1_ActionPerformed(evt);
            }
        });

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new Insets(10, 10, 10, 10);
        add(jButton1_, gridBagConstraints);

        jButton2_.setText(GrpSim.res_.getString("DlgMeasureAreaButtonLabeling"));
        jButton2_.setEnabled(false);
        jButton2_.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jButton2_ActionPerformed(evt);
            }
        });

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new Insets(10, 10, 10, 10);
        add(jButton2_, gridBagConstraints);

        jButton3_.setText(GrpSim.res_.getString("DlgMeasureAreaButtonStep"));
        jButton3_.setEnabled(false);
        jButton3_.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jButton3_ActionPerformed(evt);
            }
        });

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new Insets(10, 0, 10, 10);
        add(jButton3_, gridBagConstraints);

        jButton4_.setText(GrpSim.res_.getString("DlgMeasureAreaButtonFinal"));
        jButton4_.setEnabled(false);
        jButton4_.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jButton4_ActionPerformed(evt);
            }
        });

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new Insets(10, 0, 10, 10);
        add(jButton4_, gridBagConstraints);

        jScrollPane1.setPreferredSize(new Dimension(180, 3));
        jList_.setEnabled(false);
        jScrollPane1.setViewportView(jList_);

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        add(jScrollPane1, gridBagConstraints);

    }//GEN-END:initComponents

        private void jButton4_ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_jButton4_ActionPerformed
                // 最後まで実行
                nStepCount_ = -1;
                jButton2_.setEnabled(false);
                jButton3_.setEnabled(false);
                jButton4_.setEnabled(false);
                actionListener_.actionPerformed(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,"ParameterChanged"));
        }//GEN-LAST:event_jButton4_ActionPerformed

        private void jButton3_ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_jButton3_ActionPerformed
                // ステップ実行
                nStepCount_ ++;
                actionListener_.actionPerformed(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,"ParameterChanged"));
        }//GEN-LAST:event_jButton3_ActionPerformed

        private void jButton2_ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_jButton2_ActionPerformed
                // ラベリング
                nStepCount_ = 2;
                jButton2_.setEnabled(false);
                jButton3_.setEnabled(true);
                jButton4_.setEnabled(true);
                jList_.setEnabled(true);
                actionListener_.actionPerformed(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,"ParameterChanged"));
        }//GEN-LAST:event_jButton2_ActionPerformed

        private void jButton1_ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_jButton1_ActionPerformed
                // 2値化
              nStepCount_ = 1;
                jButton2_.setEnabled(true);
                jButton3_.setEnabled(false);
                jButton4_.setEnabled(false);
                jList_.setEnabled(true);
                String str[] = {"no data"};
            jList_.setListData(str);
                jList_.setEnabled(false);
                actionListener_.actionPerformed(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,"ParameterChanged"));
        }//GEN-LAST:event_jButton1_ActionPerformed

        /** ダイアログの状態をリセットする */
        public void resetState() {
                nStepCount_ = 0;
                jButton2_.setEnabled(false);
                jButton3_.setEnabled(false);
                jButton4_.setEnabled(false);
                jList_.setEnabled(false);
        }       
        
        
    // 変数宣言 - 編集不可//GEN-BEGIN:variables
    private JButton jButton1_;
    private JButton jButton2_;
    private JButton jButton3_;
    private JButton jButton4_;
    private JList jList_;
    // 変数宣言の終わり//GEN-END:variables

        public void addActionListener(ActionListener listener) {
                actionListener_ = AWTEventMulticaster.add(actionListener_, listener);
        }
        public void removeActionListener(ActionListener listener) {
                actionListener_ = AWTEventMulticaster.remove(actionListener_, listener);
        }
        
        /** 変換の種類を取得します
         * @return 変換の種類を表す値
         */
        public int getParameterType() {
                return ParameterSetting.PARAM_TYPE_MEASURE_AREA;
        }
        
        /** 変換のパラメータを取得します
         * @return パラメータを表す配列。内容については変換の種類に依存します。エラーはnullを返す。
         */
        public int[] getParameters() {
         int ret[] = new int [1];
               ret[0] = nStepCount_;
                return ret;
        }
        
        /** 現在のステップ数を返す
         * @return 現在のステップ数。-1はステップが完了している事を表す。
         */
        public int getStepCount() {
                return nStepCount_;
        }
        
        /** 変換元画像を必要とするかどうかを返す
         * @return 変換元画像を必要とするならtrueを返す
         */
        public boolean requireSrc() {
                return true;
        }
        
        /** ステップがすべて完了した
         */
        public void setStepDone() {
        }
        
        /** ステップごとの処理結果
         */
        public void setStepResult(Object obj) {
                // 描画
                int nArea[] = (int[])obj;
                String str[] = new String[nArea.length];
               for (int i = 0; i < nArea.length; i ++) {
                      str[i] = "@Area(" + i + ") = " + nArea[i];
             }
              jList_.setListData(str);
        }
        
       /** LISTの各行によって色を変える為のクラス ラベルをつくる為にJLabelを継承する
         */
        class AreaLabel extends JLabel implements ListCellRenderer {
                int nPaletteNum_;
                int nPalette_[];
                
                /** コンストラクタ
                 */
                public AreaLabel(){
                        // 色の設定
                        nPaletteNum_ = 64;
                        nPalette_ = new int [nPaletteNum_];
                        double y[] = {64, 128, 192, 255};
                        double u[] = { 0 - 128,  64 - 128, 192 - 128, 255 - 128};
                        double v[] = { 0 - 128,  64 - 128, 192 - 128, 255 - 128};
                        int c = 0;
                        for (int i = 0; i < 4; i ++) {
                                for (int j = 0; j < 4;  j++) {
                                        for (int k = 0; k < 4; k ++) {
                                                double r = y[i]                + 1.402 * v[k];
                                                double g = y[i] - 0.344 * u[j] - 0.714 * v[k];
                                                double b = y[i] + 1.772 * u[j];
                                                int ir, ig, ib, rgb;
                                                ir = (int)(r + 0.5);
                                                ig = (int)(g + 0.5);
                                                ib = (int)(b + 0.5);
                                                ir = Math.max(0, Math.min(ir, 255));
                                                ig = Math.max(0, Math.min(ig, 255));
                                                ib = Math.max(0, Math.min(ib, 255));
                                                nPalette_[c] = ((ir << 16) + (ig << 8) + ib);
                                                c ++;
                                        }
                                }
                        }
                        // 
                        setOpaque(true);
                }

                /** 一行を描画する
                 */
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){

                        /* 各項目で表示されるテキスト */
                        setText(value.toString());
                        
                        // バックグラウンドは白
                        setBackground(Color.white);
                        
                        /* 前景色を行によって変更する */
                        int pal = index % nPaletteNum_;
                        Color col = new Color(nPalette_[pal]);
                        setForeground(col);

                        /* この項目が選択状態だったら */
                        if (isSelected){
                                /* 真中に表示 */
                                setHorizontalAlignment(JLabel.CENTER);
                        }else{
                                setHorizontalAlignment(JLabel.LEFT);
                        }

                        return this;
                }
        }

}

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