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

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

DEFINITIONS

This source file includes following definitions.
  1. GrpSim
  2. isApplet
  3. adjustFrameSize
  4. initComponents
  5. codecMenuItemSoundActionPerformed
  6. codecMenuItemMovieActionPerformed
  7. codecMenuItemStillActionPerformed
  8. analyzeMenuItemAnalyzeReflectancePerformed
  9. analyzeMenuItemAnalyzeCameraPerformed
  10. analyzeMenuItemFourierActionPerformed
  11. measureMenuItemTrimActionPerformed
  12. measureMenuItemScaleActionPerformed
  13. measureMenuItemSharpnessActionPerformed
  14. measureMenuItemAreaActionPerformed
  15. descriptMenuItem1ActionPerformed
  16. descriptMenuItem2ActionPerformed
  17. processingNeighborItem4ActionPerformed
  18. processingNeighborItem3ActionPerformed
  19. processingNeighborItem2ActionPerformed
  20. processingNeighborItem1ActionPerformed
  21. processingHistogramItemBinaryActionPerformed
  22. processingHistogramItemNormalizeActionPerformed
  23. processingHistogramItemViewActionPerformed
  24. menuLevelChangeActionPerformed
  25. menuDensityLineActionPerformed
  26. menuLabelingActionPerformed
  27. menuHighCutActionPerformed
  28. menuHighPassActionPerformed
  29. menuContrastActionPerformed
  30. fileExitMenuItemActionPerformed
  31. fileSaveMenuItemActionPerformed
  32. fileLoadMenuItemActionPerformed
  33. exitForm
  34. main
  35. changeMode
  36. parameterChanged
  37. convertImage
  38. imageClicked
  39. imageReloaded
  40. undoBuffer
  41. actionPerformed
  42. initLookAndFeelMenu
  43. setLookAndFeel

package jp.ac.nime.computer.grpsimulator;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import jp.ac.nime.computer.grpsimulator.ImgPr.*;


/** GrpSimクラスは画像処理シミュレータのメインクラスです
 * @author igarashi
 * @version 1.0.0
 */
public class GrpSim extends JPanel
        implements ActionListener
{
        /** 処理画像の幅 */
        private static final int IMG_WIDTH  = 320;
        /** 処理画像の高さ */
        private static final int IMG_HEIGHT = 240;

        /** 動作モード: なし */
        private static final int MODE_NONE      = 0;
        /** 動作モード: 階調変換 */
        private static final int MODE_VALUE     = 1;
        /** 動作モード: 濃度ヒストグラム変換 */
        private static final int MODE_HISTOGRAM = 2;
        /** 動作モード: 近傍処理 */
        private static final int MODE_NEIGHBOR  = 3;
        /** 動作モード: 画像計測 */
        private static final int MODE_MEASURE   = 4;
        /** 動作モード: 画像認識 */
        private static final int MODE_ANALYZE   = 5;
        /** 動作モード: データ表現 */
        private static final int MODE_DESCRIPT  = 6;
        /** 動作モード: 符号化・復号化 */
        private static final int MODE_CODEC     = 7;
        
        private JApplet applet_ = null;
        private JFrame frame_ = null;
        
        /** 画像処理シミュレータの国際化文字列リソースのハンドル */
        protected static ResourceBundle res_;
        
        private String srcPath_;
        private String dstPath_;
        private ImageViewPanel srcPanel_;
        private ImageViewPanel dstPanel_;
        private ColorDumpView dumpAreaL_;
        private ColorDumpView dumpAreaR_;
        private OperationPanel opPanel_;
        private DocumentPanel docPanel_;

        private GrpSimBuffer gsBuffer_;

        private int dlgMode_ = MODE_NONE;
        
        private String currentLookAndFeel_;
        
        private JMenu lafMenu_;
        
        private JMenuItem processingHistogramItemView_;
        private JMenuItem processingHistogramItemNormal_;
        private JMenuItem processingHistogramItemBinary_;
        
        private boolean isApplet() {
                return (applet_ != null);
        }
        
        private void adjustFrameSize() {
                if (isApplet()) {
                        applet_.invalidate();
                        applet_.validate();
                } else {
                        frame_.pack();
                }
        }
        
        /** Creates new form GrpSim */
        public GrpSim(JApplet applet) {
                //res_ = ResourceBundle.getBundle("jp.ac.nime.computer.grpsimulator.GrpSimRes");
                res_ = ResourceBundle.getBundle("GrpSimRes");
                
                if (applet == null) {
                        frame_ = new JFrame();
                        frame_.getContentPane().setLayout(new BorderLayout());
                        frame_.setTitle(res_.getString("MainFrameCaption"));
                        frame_.setResizable(false);
                        frame_.addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent evt) {
                                        exitForm(evt);
                                }
                        });
                } else {
                        applet_ = applet;
                }
                
                initComponents();
                initLookAndFeelMenu();
                
                // set default document
        docPanel_.setPageFile( res_.getString("DocumentHtmlDefault") );

                if (frame_!=null) {
                        frame_.getContentPane().add(this, BorderLayout.CENTER);
                        adjustFrameSize();
                        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                        Dimension siz = frame_.getSize();
                        frame_.setLocation((dim.width-siz.width)/2,(dim.height-siz.height)/2);
                        frame_.show();
                }
                
                // 画像buffer
                gsBuffer_ = new GrpSimBuffer(IMG_WIDTH, IMG_HEIGHT);
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         */
        private void initComponents() {
                setLayout(new BorderLayout());
                JPanel mainPanel = new JPanel();
                mainPanel.setLayout(new BorderLayout(1,2));
                add(mainPanel, BorderLayout.NORTH);
                
                JPanel srcParentPanel = new JPanel();
                srcParentPanel.setLayout(new BorderLayout());
                srcParentPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
                mainPanel.add(srcParentPanel, BorderLayout.WEST);
                JPanel dstParentPanel = new JPanel();
                dstParentPanel.setLayout(new BorderLayout());
                dstParentPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
                mainPanel.add(dstParentPanel, BorderLayout.EAST);
                
                ActionListener imageClickListener = new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                imageClicked( (Point) evt.getSource() );
                        }
                };
                srcPanel_ = new ImageViewPanel(IMG_WIDTH, IMG_HEIGHT);
                srcPanel_.addActionListener(imageClickListener);
                srcParentPanel.add(srcPanel_, BorderLayout.CENTER);
                dstPanel_ = new ImageViewPanel(IMG_WIDTH, IMG_HEIGHT);
                dstPanel_.addActionListener(imageClickListener);
                dstParentPanel.add(dstPanel_, BorderLayout.CENTER);
                
                JPanel dumpPanel = new JPanel();
                dumpPanel.setLayout(new BoxLayout(dumpPanel, BoxLayout.X_AXIS));
                dumpPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
                mainPanel.add(dumpPanel, BorderLayout.SOUTH);
                
                JPanel dumpParentPanelL = new JPanel();
                dumpParentPanelL.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 1));
                dumpPanel.add(dumpParentPanelL);
                JPanel dumpParentPanelR = new JPanel();
                dumpParentPanelR.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 1));
                dumpPanel.add(dumpParentPanelR);
                
                dumpAreaL_ = new ColorDumpView( 5, 5 );
                dumpParentPanelL.add( dumpAreaL_ );
                dumpAreaR_ = new ColorDumpView( 5, 5 );
                dumpParentPanelR.add( dumpAreaR_ );
                
                JPanel subPanel = new JPanel();
                subPanel.setLayout(new BorderLayout(1,2));
                add(subPanel, BorderLayout.CENTER);
                
                opPanel_ = new OperationPanel();
                opPanel_.addActionListener(this);
                subPanel.add(opPanel_, BorderLayout.WEST);
                
                docPanel_ = new DocumentPanel();
                subPanel.add(docPanel_, BorderLayout.CENTER);
                
                
                // build menubar & menus
                JMenuBar mainMenuBar = new JMenuBar();
                JSeparator jSeparator = new JSeparator();
                
                JMenu fileMenu = new JMenu();
                JMenuItem fileLoadMenuItem = new JMenuItem();
                JMenuItem fileSaveMenuItem = new JMenuItem();
                JMenuItem fileExitMenuItem = new JMenuItem();
                
                JMenu processingMenu = new JMenu();
                
                JMenu processingValueMenu = new JMenu();
                JMenuItem menuContrast = new JMenuItem();
                JMenuItem menuHighPass = new JMenuItem();
                JMenuItem menuHighCut = new JMenuItem();
                JMenuItem menuLabeling = new JMenuItem();
                JMenuItem menuDensityLine = new JMenuItem();
                JMenuItem menuLevelChange = new JMenuItem();
                
                JMenu processingHistogramMenu = new JMenu();
                processingHistogramItemView_ = new JMenuItem();
                processingHistogramItemNormal_ = new JMenuItem();
                processingHistogramItemBinary_ = new JMenuItem();
                
                JMenu processingNearMenu = new JMenu();
                JMenuItem processingNeighborItem1 = new JMenuItem();
                JMenuItem processingNeighborItem2 = new JMenuItem();
                JMenuItem processingNeighborItem3 = new JMenuItem();
                JMenuItem processingNeighborItem4 = new JMenuItem();
                
                JMenu measureMenu = new JMenu();
                JMenuItem measureMenuItem1 = new JMenuItem();
                JMenuItem measureMenuItem2 = new JMenuItem();
                JMenuItem measureMenuItem3 = new JMenuItem();
                JMenuItem measureMenuItem4 = new JMenuItem();
                
                JMenu analyzeMenu = new JMenu();
                JMenuItem analyzeMenuItem1 = new JMenuItem();
                JMenuItem analyzeMenuItem2 = new JMenuItem();
                JMenuItem analyzeMenuItem3 = new JMenuItem();
                
                JMenu descriptMenu = new JMenu();
                JMenuItem descriptMenuItem1 = new JMenuItem();
                JMenuItem descriptMenuItem2 = new JMenuItem();
                
                JMenu codecMenu = new JMenu();
                JMenuItem codecMenuItemStill = new JMenuItem();
                JMenuItem codecMenuItemMovie = new JMenuItem();
                JMenuItem codecMenuItemSound = new JMenuItem();
                
                lafMenu_ = new JMenu();

                mainMenuBar.setBorder(null);
                mainPanel.add(mainMenuBar,BorderLayout.NORTH);
                
                fileMenu.setText(res_.getString("MainMenuFileTop"));
                mainMenuBar.add(fileMenu);
                
                fileLoadMenuItem.setText(res_.getString("MainMenuFileLoad"));
                fileLoadMenuItem.setToolTipText(res_.getString("MainMenuFileLoadTooltip"));
                fileLoadMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                fileLoadMenuItemActionPerformed(evt);
                        }
                });
                fileMenu.add(fileLoadMenuItem);
                
                fileSaveMenuItem.setText(res_.getString("MainMenuFileSave"));
                fileSaveMenuItem.setToolTipText(res_.getString("MainMenuFileSaveTooltip"));
                fileSaveMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                fileSaveMenuItemActionPerformed(evt);
                        }
                });
                fileMenu.add(fileSaveMenuItem);
                
                if (!isApplet()) {
                        fileMenu.add(jSeparator);

                        fileExitMenuItem.setText(GrpSim.res_.getString("MainMenuFileExit"));
                        fileExitMenuItem.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent evt) {
                                        fileExitMenuItemActionPerformed(evt);
                                }
                        });
                        fileMenu.add(fileExitMenuItem);
                }
                
                processingMenu.setText(res_.getString("MainMenuProcessingTop"));
                mainMenuBar.add(processingMenu);
                
                processingValueMenu.setText(GrpSim.res_.getString("MainMenuProcessingValueTop"));
                processingMenu.add(processingValueMenu);
                
                menuContrast.setText(res_.getString("MainMenuProcessingContrast"));
                menuContrast.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                menuContrastActionPerformed(evt);
                        }
                });
                processingValueMenu.add(menuContrast);
                
                menuHighPass.setText(res_.getString("MainMenuProcessingHighPass"));
                menuHighPass.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                menuHighPassActionPerformed(evt);
                        }
                });
                processingValueMenu.add(menuHighPass);
                
                menuHighCut.setText(res_.getString("MainMenuProcessingHighCut"));
                menuHighCut.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                menuHighCutActionPerformed(evt);
                        }
                });
                processingValueMenu.add(menuHighCut);
                
                menuLabeling.setText(res_.getString("MainMenuProcessingLabeling"));
                menuLabeling.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                menuLabelingActionPerformed(evt);
                        }
                });
                processingValueMenu.add(menuLabeling);
                
                menuDensityLine.setText(res_.getString("MainMenuProcessingDensity"));
                menuDensityLine.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                menuDensityLineActionPerformed(evt);
                        }
                });
                processingValueMenu.add(menuDensityLine);
                
                menuLevelChange.setText(res_.getString("MainMenuProcessingLevel"));
                menuLevelChange.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                menuLevelChangeActionPerformed(evt);
                        }
                });
                processingValueMenu.add(menuLevelChange);
                
                processingHistogramMenu.setText(GrpSim.res_.getString("MainMenuProcessingHistogramTop"));
                processingMenu.add(processingHistogramMenu);
                
                processingHistogramItemView_.setText(GrpSim.res_.getString("MainMenuProcessingHistogramView"));
                processingHistogramItemView_.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processingHistogramItemViewActionPerformed(evt);
                        }
                });
                processingHistogramMenu.add(processingHistogramItemView_);
                
                processingHistogramItemNormal_.setText(GrpSim.res_.getString("MainMenuProcessingHistogramNormalize"));
                processingHistogramItemNormal_.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processingHistogramItemNormalizeActionPerformed(evt);
                        }
                });
                processingHistogramMenu.add(processingHistogramItemNormal_);
                
                processingHistogramItemBinary_.setText(GrpSim.res_.getString("MainMenuProcessingHistogramBinary"));
                processingHistogramItemBinary_.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processingHistogramItemBinaryActionPerformed(evt);
                        }
                });
                processingHistogramMenu.add(processingHistogramItemBinary_);
                
                processingNearMenu.setText(GrpSim.res_.getString("MainMenuProcessingNeighborTop"));
                processingMenu.add(processingNearMenu);
                
                processingNeighborItem1.setText(GrpSim.res_.getString("MainMenuProcessingNeighborEdge"));
                processingNeighborItem1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processingNeighborItem1ActionPerformed(evt);
                        }
                });
                processingNearMenu.add(processingNeighborItem1);
                
                processingNeighborItem2.setText(GrpSim.res_.getString("MainMenuProcessingNeighborSmoothing"));
                processingNeighborItem2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processingNeighborItem2ActionPerformed(evt);
                        }
                });
                processingNearMenu.add(processingNeighborItem2);
                
                processingNeighborItem3.setText(GrpSim.res_.getString("MainMenuProcessingNeighborRemoveNoise"));
                processingNeighborItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processingNeighborItem3ActionPerformed(evt);
                        }
                });
                processingNearMenu.add(processingNeighborItem3);
                
                processingNeighborItem4.setText(GrpSim.res_.getString("MainMenuProcessingNeighborEmpasis"));
                processingNeighborItem4.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                processingNeighborItem4ActionPerformed(evt);
                        }
                });
                processingNearMenu.add(processingNeighborItem4);
                
                measureMenu.setText(GrpSim.res_.getString("MainMenuMeasureTop"));
                mainMenuBar.add(measureMenu);
                
                measureMenuItem1.setText(GrpSim.res_.getString("MainMenuMeasureTrim"));
                measureMenuItem1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                measureMenuItemTrimActionPerformed(evt);
                        }
                });
                measureMenu.add(measureMenuItem1);
                measureMenuItem2.setText(GrpSim.res_.getString("MainMenuMeasureScaling"));
                measureMenuItem2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                measureMenuItemScaleActionPerformed(evt);
                        }
                });
                measureMenu.add(measureMenuItem2);
                measureMenuItem3.setText(GrpSim.res_.getString("MainMenuMeasureSharpness"));
                measureMenuItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                measureMenuItemSharpnessActionPerformed(evt);
                        }
                });
                measureMenu.add(measureMenuItem3);
                measureMenuItem4.setText(GrpSim.res_.getString("MainMenuMeasureArea"));
                measureMenuItem4.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                measureMenuItemAreaActionPerformed(evt);
                        }
                });
                measureMenu.add(measureMenuItem4);
                
                analyzeMenu.setText(GrpSim.res_.getString("MainMenuAnalyzeTop"));
                mainMenuBar.add(analyzeMenu);
                
                analyzeMenuItem1.setText(GrpSim.res_.getString("MainMenuAnalyzeFourier"));
                analyzeMenuItem1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                analyzeMenuItemFourierActionPerformed(evt);
                        }
                });
                analyzeMenu.add(analyzeMenuItem1);
                
                analyzeMenuItem2.setText(GrpSim.res_.getString("MainMenuAnalyzeCamera"));
                analyzeMenuItem2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                analyzeMenuItemAnalyzeCameraPerformed(evt);
                        }
                });
                analyzeMenu.add(analyzeMenuItem2);

                analyzeMenuItem3.setText(GrpSim.res_.getString("MainMenuAnalyzeRefrectance"));
                analyzeMenuItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                analyzeMenuItemAnalyzeReflectancePerformed(evt);
                        }
                });
                analyzeMenu.add(analyzeMenuItem3);
                
                descriptMenu.setText(GrpSim.res_.getString("MainMenuDescriptTop"));
                mainMenuBar.add(descriptMenu);
                
                descriptMenuItem1.setText(GrpSim.res_.getString("MainMenuDescriptPoint"));
                descriptMenuItem1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                descriptMenuItem1ActionPerformed(evt);
                        }
                });
                descriptMenu.add(descriptMenuItem1);
                
                descriptMenuItem2.setText(GrpSim.res_.getString("MainMenuDescriptColor"));
                descriptMenuItem2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                descriptMenuItem2ActionPerformed(evt);
                        }
                });
                descriptMenu.add(descriptMenuItem2);
                
                codecMenu.setText(GrpSim.res_.getString("MainMenuCodecTop"));
                mainMenuBar.add(codecMenu);
                
                codecMenuItemStill.setText(GrpSim.res_.getString("MainMenuCodecImage"));
                codecMenuItemStill.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                codecMenuItemStillActionPerformed(evt);
                        }
                });
                codecMenu.add(codecMenuItemStill);
                
                codecMenuItemMovie.setText(GrpSim.res_.getString("MainMenuCodecMovie"));
                codecMenuItemMovie.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                codecMenuItemMovieActionPerformed(evt);
                        }
                });
                codecMenu.add(codecMenuItemMovie);
                
                codecMenuItemSound.setText(GrpSim.res_.getString("MainMenuCodecSound"));
                codecMenuItemSound.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                                codecMenuItemSoundActionPerformed(evt);
                        }
                });
                codecMenu.add(codecMenuItemSound);
                
                lafMenu_.setText("Look&Feel");
                mainMenuBar.add(lafMenu_);
                
                adjustFrameSize();
        }
        
        ////////////////////////////////////////////////////////////////////////////

        private void codecMenuItemSoundActionPerformed(ActionEvent evt) {
                opPanel_.setDialog(null);
                docPanel_.setPageFile( res_.getString("DocumentHtmlEncodedSound") );
                changeMode(MODE_CODEC);
        }

        private void codecMenuItemMovieActionPerformed(ActionEvent evt) {
                opPanel_.setDialog(null);
                docPanel_.setPageFile( res_.getString("DocumentHtmlEncodedMovie") );
                changeMode(MODE_CODEC);
        }

        private void codecMenuItemStillActionPerformed(ActionEvent evt) {
                opPanel_.setDialog(null);
                docPanel_.setPageFile( res_.getString("DocumentHtmlEncodedStill") );
                changeMode(MODE_CODEC);
        }
        
        private void analyzeMenuItemAnalyzeReflectancePerformed(ActionEvent evt) {
                DlgAnalyzeReflectance dlg = new DlgAnalyzeReflectance();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlAnalyzeReflectance") );
                changeMode(MODE_ANALYZE);
                
                srcPanel_.setImage(gsBuffer_.getSrcImage(GrpSimBuffer.RGB));    // 画像バッファ指定
                imageReloaded();
        }
        
        private void analyzeMenuItemAnalyzeCameraPerformed(ActionEvent evt) {

                DlgAnalyzeProjection dlg = new DlgAnalyzeProjection();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlAnalyzeProjection") );
                changeMode(MODE_ANALYZE);

                srcPanel_.setImage(gsBuffer_.getSrcImage(GrpSimBuffer.RGB));    // 画像バッファ指定
                imageReloaded();
        }
        
        private void analyzeMenuItemFourierActionPerformed(ActionEvent evt) {
                DlgAnalyzeFourier dlg = new DlgAnalyzeFourier();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlAnalyzeFourier") );
                changeMode(MODE_ANALYZE);
        }

        private void measureMenuItemTrimActionPerformed(ActionEvent evt) {
                DlgMeasureTrim dlg = new DlgMeasureTrim();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlMeasureTrim") );
                changeMode(MODE_MEASURE);
        }
        
        private void measureMenuItemScaleActionPerformed(ActionEvent evt) {
                DlgMeasureScale dlg = new DlgMeasureScale();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlMeasureScale") );
                changeMode(MODE_MEASURE);
        }
        
        private void measureMenuItemSharpnessActionPerformed(ActionEvent evt) {
                DlgMeasureSharpness dlg = new DlgMeasureSharpness();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlMeasureSharp") );
                changeMode(MODE_MEASURE);
        }
        
        private void measureMenuItemAreaActionPerformed(ActionEvent evt) {
                DlgMeasureArea dlg = new DlgMeasureArea();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlMeasureArea") );
                changeMode(MODE_MEASURE);
        }
        
        private void descriptMenuItem1ActionPerformed(ActionEvent evt) {
                DlgDescriptPoint dlg = new DlgDescriptPoint();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlDescriptPoint") );
                srcPanel_.setImage(gsBuffer_.getSrcImage(GrpSimBuffer.RGB));    // 画像バッファ指定
                changeMode(MODE_DESCRIPT);
        }

        private void descriptMenuItem2ActionPerformed(ActionEvent evt) {
                DlgDescriptColor dlg = new DlgDescriptColor();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlDescriptColor") );
                changeMode(MODE_DESCRIPT);
        }

        private void processingNeighborItem4ActionPerformed(ActionEvent evt) {
                DlgNeighbor dlg = new DlgNeighbor( ParameterSetting.PARAM_TYPE_EMPHASIS );
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlEmphasis") );
                changeMode(MODE_NEIGHBOR);
        }

        private void processingNeighborItem3ActionPerformed(ActionEvent evt) {
                DlgNeighbor dlg = new DlgNeighbor( ParameterSetting.PARAM_TYPE_REMOVE_NOISE );
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlRemoveNoise") );
                changeMode(MODE_NEIGHBOR);
        }

        private void processingNeighborItem2ActionPerformed(ActionEvent evt) {
                DlgNeighbor dlg = new DlgNeighbor( ParameterSetting.PARAM_TYPE_SMOOTHING );
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlSmoothing") );
                changeMode(MODE_NEIGHBOR);
        }

        private void processingNeighborItem1ActionPerformed(ActionEvent evt) {
                DlgNeighbor dlg = new DlgNeighbor( ParameterSetting.PARAM_TYPE_SHOW_EDGE );
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlShowEdge") );
                changeMode(MODE_NEIGHBOR);
        }

        private void processingHistogramItemBinaryActionPerformed(ActionEvent evt) {
                JPanel dlg = opPanel_.getDialog();
                if ((dlg != null) && (dlg instanceof DlgHistogram)) {
                        // ドキュメント
                        docPanel_.setPageFile( res_.getString("DocumentHtmlHistogramBinary") );
                        DlgHistogram histDlg = (DlgHistogram) dlg;
                        histDlg.setEnableBinaryMode(true);
                        adjustFrameSize();
                        histDlg.setParameterType(ParameterSetting.PARAM_TYPE_HISTO_BINARY);
                        if ( convertImage( histDlg ) ) {
                                // 変換に成功したらヒストグラムを再生成&再設定
                                HistogramOp htop = new HistogramOp();
                                histDlg.setParameterType(ParameterSetting.PARAM_TYPE_HISTO_PRINT);
                                int[] histogram = htop.getHistgram(HistogramOp.YP, gsBuffer_.getDstImage(GrpSimBuffer.YUV), 100);
                                histDlg.setHistogram( histogram );
                        }
                }
        }

        private void processingHistogramItemNormalizeActionPerformed(ActionEvent evt) {
                JPanel dlg = opPanel_.getDialog();
                if ((dlg != null) && (dlg instanceof DlgHistogram)) {
                        // ドキュメント
                        docPanel_.setPageFile( res_.getString("DocumentHtmlHistogramNormal") );
                        DlgHistogram histDlg = (DlgHistogram) dlg;
                        histDlg.setEnableBinaryMode(false);
                        adjustFrameSize();
                        histDlg.setParameterType(ParameterSetting.PARAM_TYPE_HISTO_NORMAL);
                        if ( convertImage( histDlg ) ) {
                                // 変換に成功したらヒストグラムを再生成&再設定
                                HistogramOp htop = new HistogramOp();
                                histDlg.setParameterType(ParameterSetting.PARAM_TYPE_HISTO_PRINT);
                                int[] histogram = htop.getHistgram(HistogramOp.YP, gsBuffer_.getDstImage(GrpSimBuffer.YUV), 100);
                                histDlg.setHistogram( histogram );
                        }
                }
        }

        private void processingHistogramItemViewActionPerformed(ActionEvent evt) {
                DlgHistogram dlg = new DlgHistogram();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                // ドキュメント
                docPanel_.setPageFile( res_.getString("DocumentHtmlHistogram") );
                // ヒストグラムの取得
                HistogramOp htop = new HistogramOp();
                dlg.setParameterType(ParameterSetting.PARAM_TYPE_HISTO_PRINT);
                int[] histogram = htop.getHistgram(HistogramOp.YP, gsBuffer_.getSrcImage(GrpSimBuffer.YUV), 100);
                dlg.setHistogram( histogram );
                changeMode(MODE_HISTOGRAM);
        }

        private void menuLevelChangeActionPerformed(ActionEvent evt) {
                DlgLevelChange dlg = new DlgLevelChange();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlLevelChange") );
                changeMode(MODE_VALUE);
        }

        private void menuDensityLineActionPerformed(ActionEvent evt) {
                DlgDensityLine dlg = new DlgDensityLine();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlDensityLine") );
                changeMode(MODE_VALUE);
        }

        private void menuLabelingActionPerformed(ActionEvent evt) {
                DlgLabeling dlg = new DlgLabeling();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlLabeling") );
                changeMode(MODE_VALUE);
        }

        private void menuHighCutActionPerformed(ActionEvent evt) {
                DlgHighCut dlg = new DlgHighCut();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlHighCut") );
                changeMode(MODE_VALUE);
        }

        private void menuHighPassActionPerformed(ActionEvent evt) {
                DlgHighPass dlg = new DlgHighPass();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlHighPass") );
                changeMode(MODE_VALUE);
        }

        private void menuContrastActionPerformed(ActionEvent evt) {
                DlgContrast dlg = new DlgContrast();
                dlg.addActionListener(this);
                opPanel_.setDialog(dlg);
                docPanel_.setPageFile( res_.getString("DocumentHtmlContrast") );
                changeMode(MODE_VALUE);
        }

        private void fileExitMenuItemActionPerformed(ActionEvent evt) {
                System.exit(0);
        }

        private void fileSaveMenuItemActionPerformed(ActionEvent evt) {
                if (!gsBuffer_.chkValidDst()) return;   // 出力すべき画像が無い
                JFileChooser fc = new JFileChooser(dstPath_);
                fc.setAcceptAllFileFilterUsed(false);
                FileFilterNime jpgFilter = new FileFilterNime(".jpg", "JPEG-File");
                fc.setFileFilter( jpgFilter );
                FileFilterNime pngFilter = new FileFilterNime(".png", "PNG-File");
                fc.setFileFilter( pngFilter );
                if (JFileChooser.APPROVE_OPTION == fc.showSaveDialog(this)) {
                        dstPath_ = fc.getCurrentDirectory().getAbsolutePath();
                        File f = fc.getSelectedFile();
                        if (f != null) {
                                setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) );
                                try{
                                        // INT_RGB形式に変換してから保存する(JPEG保存に失敗するので)
                                        Image image = gsBuffer_.getDstImage(GrpSimBuffer.RGB);
                                        BufferedImage image2 = new BufferedImage(
                                                image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB );
                                        Graphics g = image2.createGraphics();
                                        g.drawImage(image,0,0,this);
                                        g.dispose();
                                        // 指定されたファイル形式で保存する
                                        FileFilterNime filter = (FileFilterNime) fc.getFileFilter();
                                        String saveType = filter.equals(pngFilter) ? "png":"jpg";
                                        if (!filter.accept(f)) { // 拡張子が無い時は付ける
                                                File f2 = new File(f.getAbsolutePath() + filter.getExtension());
                                                if (!f2.isDirectory()) f = f2;
                                        }
                                        ImageIO.write(image2,saveType,f);
                                }
                                catch(IOException e) {}
                                setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) );
                        }
                }
        }

        private void fileLoadMenuItemActionPerformed(ActionEvent evt) {
                // Load File
                JFileChooser fc = new JFileChooser(srcPath_);
                String exts[] = {".png", ".jpg" , ".jpeg"};
                FileFilterNime filter = new FileFilterNime(exts, res_.getString("MainMenuFileLoadTypeDescription"));
                fc.setFileFilter( filter );
                if (JFileChooser.APPROVE_OPTION == fc.showOpenDialog(this)) {
                        srcPath_ = fc.getCurrentDirectory().getAbsolutePath();
                        File f = fc.getSelectedFile();
                        if (f!=null) {
                                setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) );
                                try{
                                        BufferedImage img = ImageIO.read(f);
                                        if (img != null) {
                                                gsBuffer_.setSrcImage(GrpSimBuffer.RGB, img, this);
                                                gsBuffer_.setRecycle(false);
                                                srcPanel_.setImage(gsBuffer_.getSrcImage(GrpSimBuffer.RGB));
                                                imageReloaded();
                                        }
                                }
                                catch(Exception e) {}
                                setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) );
                        }
                }
        }
        
        /** Exit the Application */
        private void exitForm(WindowEvent evt) {
                System.exit(0);
        }

        /** Javaアプリケーションとして起動する
         * @param args コマンドラインパラメータ
         */
        public static void main(String args[]) {
                GrpSim wnd = new GrpSim(null);
        }
        
        /** 動作モードを変更する
         * @param newMode 新しい動作モード
         */
        private void changeMode( int newMode ) {
                if (dlgMode_ != newMode) {
                        processingHistogramItemNormal_.setEnabled( newMode == MODE_HISTOGRAM );
                        processingHistogramItemBinary_.setEnabled( newMode == MODE_HISTOGRAM );
                        if( newMode == MODE_NONE) {
                                opPanel_.setDialog(null);
                        } else if (newMode == MODE_CODEC) {
                                // パネル配置を説明用の配置にする
                                opPanel_.setDialog(null);
                        } else if (dlgMode_ == MODE_CODEC) {
                                // パネル配置を通常に戻す
                        }
                        dlgMode_ = newMode;
                }
                adjustFrameSize();
        }
        
        /** パラメタDlgでパラメタが変更されたときにこれを呼ぶ
         * @param param パラメタをあらわすクラス
         */
        public void parameterChanged(ParameterSetting param) {
                if ( convertImage( param ) ) {
                        srcPanel_.repaint();
                        dstPanel_.repaint();
                }
        }
        
        /** 画像を変換する
         * @param param 変換設定オブジェクト
         */
        private boolean convertImage( ParameterSetting param ) {
                if ( !param.requireSrc() || gsBuffer_.chkValidSrc() ) {
                        if ( ImageProcess.ProcessImage(gsBuffer_, param) ) {
                                // 変換に成功したら表示を更新
                                dstPanel_.setImage(gsBuffer_.getDstImage(GrpSimBuffer.RGB));
                                // Undoボタンを有効にする
                                if (!(param instanceof SteppingParameter) || (((SteppingParameter)param).getStepCount() == -1) ) {
                                        opPanel_.setUndoEnabled( true );
                                }
                                return true;
                        }
                }
                return false;
        }
        
        /** 画像がクリックされた場合の処理
         * @param ptClicked クリックされた画像内の位置
         */
        public void imageClicked(Point ptClicked) {
                int dump[];
                if (gsBuffer_.chkValidSrc()) {
                        dump = gsBuffer_.getSrcNearPointData(GrpSimBuffer.RGB, ptClicked.x, ptClicked.y );
                        dumpAreaL_.setDump(dump);
                }
                if (gsBuffer_.chkValidDst()) {
                        dump = gsBuffer_.getDstNearPointData(GrpSimBuffer.RGB, ptClicked.x, ptClicked.y );
                        dumpAreaR_.setDump(dump);
                }
        }
        
        /** 画像が再読み込みされた場合の処理
         */
        private void imageReloaded() {
                JPanel dlg = opPanel_.getDialog();
                if ( (dlg != null) && (dlg instanceof OperationDialog) ) {
                        ((OperationDialog)dlg).resetState();
                }
        }
        
        /** 画像バッファのUNDO処理
         */
        private void undoBuffer() {
                if (gsBuffer_.chkValidSrc()) {
                        gsBuffer_.undo();
                        dstPanel_.setImage(gsBuffer_.getDstImage(GrpSimBuffer.RGB));
                        opPanel_.setUndoEnabled( false );   // 2回以上のUndoはできない
                }
        }
        
        /** ActionListenerインターフェイスの実装
         * @param actionEvent 発生したアクションイベント
         */
        public void actionPerformed(ActionEvent actionEvent) {
                String cmd = actionEvent.getActionCommand();
                if (cmd.equals("ParameterChanged")) {
                        parameterChanged( (ParameterSetting) actionEvent.getSource() );
                }
                else
                if (cmd.equals("RecycleOn")) {
                        gsBuffer_.setRecycle( true );
                }
                else
                if (cmd.equals("RecycleOff")) {
                        gsBuffer_.setRecycle( false );
                }
                else
                if (cmd.equals("Undo")) {
                        undoBuffer();
                }
        }

        /**
         * LookAndFeelメニューに利用可能なLookAndFeelを追加する
         */
        private void initLookAndFeelMenu() {
                UIManager.LookAndFeelInfo[] laf;
                laf = UIManager.getInstalledLookAndFeels();
                if (laf == null) return;
                for (int i=0; i<laf.length; i++) {
                        final String lafClassName = laf[i].getClassName();
                        JMenuItem menuItem = new JMenuItem( laf[i].getName() );
                        menuItem.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent evt) {
                                        setLookAndFeel( lafClassName );
                                }
                        });
                        lafMenu_.add( menuItem );
                }
        }
        
        /**
         * LookAndFeelを変更する
         * @param laf LookAndFeelのクラス名
         */
        private void setLookAndFeel(String laf) {
                if (currentLookAndFeel_ == laf) return;
                currentLookAndFeel_ = laf;
                try {
                        UIManager.setLookAndFeel(laf);
                        SwingUtilities.updateComponentTreeUI( getParent() );
                        adjustFrameSize();
                } catch (Exception ex) {
                        System.out.println("Failed to load L&F: " + laf);
                        System.out.println(ex);
                }
        }
        
}

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