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

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

DEFINITIONS

This source file includes following definitions.
  1. DlgNeighbor
  2. initComponents
  3. processButtonActionPerformed
  4. getParameterType
  5. getParameters
  6. addActionListener
  7. removeActionListener
  8. requireSrc

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 DlgNeighbor extends JPanel
        implements ParameterSetting
{
        private ActionListener actionListener_;
        private JTextField[] fields_;
        int paramType_;
        int[] params_;
        
        public DlgNeighbor( int paramType ) {
                paramType_ = paramType;
                
                initComponents();
                
                params_ = new int[9];
                switch(paramType) {
                case ParameterSetting.PARAM_TYPE_SHOW_EDGE:
                        params_[0] = 1;
                        params_[1] = 1;
                        params_[2] = 1;
                        params_[3] = 0;
                        params_[4] = 0;
                        params_[5] = 0;
                        params_[6] = -1;
                        params_[7] = -1;
                        params_[8] = -1;
                        break;
                case ParameterSetting.PARAM_TYPE_SMOOTHING:
                        params_[0] = 1;
                        params_[1] = 1;
                        params_[2] = 1;
                        params_[3] = 1;
                        params_[4] = 1;
                        params_[5] = 1;
                        params_[6] = 1;
                        params_[7] = 1;
                        params_[8] = 1;
                        break;
                case ParameterSetting.PARAM_TYPE_REMOVE_NOISE:
                        params_[0] = 1;
                        params_[1] = 1;
                        params_[2] = 1;
                        params_[3] = 1;
                        params_[4] = 4;
                        params_[5] = 1;
                        params_[6] = 1;
                        params_[7] = 1;
                        params_[8] = 1;
                        break;
                case ParameterSetting.PARAM_TYPE_EMPHASIS:
                        params_[0] = -1;
                        params_[1] = -1;
                        params_[2] = -1;
                        params_[3] = -1;
                        params_[4] = 8;
                        params_[5] = -1;
                        params_[6] = -1;
                        params_[7] = -1;
                        params_[8] = -1;
                        break;        
                }
                for (int i = 0; i < 9; i++) {
                        fields_[i].setText( String.valueOf(params_[i]) );
                }
        }
        
        /** This method is called from within the constructor to initialize the form.
         */
        private void initComponents() {
                setBorder(new TitledBorder(GrpSim.res_.getString("DlgNeighborCaption")));
                setMaximumSize(new Dimension(320, 240));
                setMinimumSize(new Dimension(320, 240));
                setPreferredSize(new Dimension(320, 240));
                setLayout(new BorderLayout());
                
                JPanel jPanel1 = new JPanel();
                
                jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.Y_AXIS));
                
                JPanel jPanel2 = new JPanel();
                jPanel2.setLayout(new GridBagLayout());
                GridBagConstraints gridBagConstraints = new GridBagConstraints();
                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                
                fields_ = new JTextField[9];
                
                for (int i = 0; i < 3; i++) {
                        gridBagConstraints.gridy = i;
                        for (int j = 0; j < 3; j++) {
                                gridBagConstraints.gridx = j;
                                JTextField f = new JTextField();
                                fields_[i*3+j] = f;
                                f.setHorizontalAlignment(JTextField.RIGHT);
                                f.setPreferredSize(new Dimension(40, 20));
                                f.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent evt) {
                                                processButtonActionPerformed(evt);
                                        }
                                });
                                jPanel2.add(f, gridBagConstraints);
                        }
                }
                jPanel1.add(jPanel2);
                
                JPanel jPanel3 = new JPanel();
                jPanel3.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 5));
                
                JButton processButton = new JButton();
                processButton.setText(GrpSim.res_.getString("DlgNeighborButton"));
                processButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processButtonActionPerformed(evt);
                        }
                });
                jPanel3.add(processButton);
                
                jPanel1.add(jPanel3);
                
                add(jPanel1, BorderLayout.NORTH);
        }

        private void processButtonActionPerformed(ActionEvent evt) {
                try {
                        for (int i = 0; i < 9; i++) {
                                params_[i] = Integer.parseInt( fields_[i].getText() );
                        }
                }
                catch(NullPointerException ex) {
                        // 文字列が空だった
                        return;
                }
                catch(NumberFormatException ex){
                        // 文字列から数値への変換に失敗した
                        return;
                }
                // パラメータの変更が起きたことを知らせる
                actionListener_.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "ParameterChanged"));
        }

        /** 変換の種類を取得します
         * @return 変換の種類を表す値
         */
        public int getParameterType() {
                return paramType_;
        }
        
        /** 変換のパラメータを取得します
         * @return パラメータを表す配列。内容については変換の種類に依存します。
         */
        public int[] getParameters() {
                return params_;
        }
        
        public void addActionListener(ActionListener listener) {
                actionListener_ = AWTEventMulticaster.add(actionListener_, listener);
        }
        public void removeActionListener(ActionListener listener) {
                actionListener_ = AWTEventMulticaster.remove(actionListener_, listener);
        }
        
        /** 変換元画像を必要とするかどうかを返す
         * @return 変換元画像を必要とするならtrueを返す
         */
        public boolean requireSrc() {
                return true;
        }
        
}

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