いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

正規表現チェックツール SOURCE-0002

ウィンドウ本体。
コンポーネントを初期化、リスナー登録を行っています。

// vim: set ts=2 sw=2 et ft=java:
//
// RegexpTester.java
// 
//
package gsf.tools.regexp.regexptester;

import gsf.tools.regexp.regexptester.bean.InputAreaBean;
import gsf.tools.regexp.regexptester.bean.RegInputFieldsBean;
import gsf.tools.regexp.regexptester.bean.ResultAreaBean;
import gsf.tools.regexp.regexptester.bean.TargetInputFieldsBean;
import gsf.tools.regexp.regexptester.listener.ClearAction;
import gsf.tools.regexp.regexptester.listener.ExecuteAction;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class RegexpTester extends JFrame {
  
  private InputAreaBean         inputArea;
  private RegInputFieldsBean    regInputFields;
  private TargetInputFieldsBean targetInputFields;
  
  public RegexpTester(){
    super("正規表現簡易テスター");
    
    this.buildContents();
  }
  
  private void buildContents(){
    JPanel contentPane = new JPanel();
    
    contentPane.setLayout(new GridBagLayout());
    
    contentPane.add(this.getInputAreaBean(), this.getInputAreaBeanConstraints());
    
    this.setMyListeners();
    
    super.setContentPane(contentPane);
    
    super.setResizable(false);
    
    super.getRootPane().setDefaultButton(this.regInputFields.getExecButtonComponent());
    
  }
  
  private JComponent getInputAreaBean(){
    InputAreaBean inputArea = new InputAreaBean();
    
    this.inputArea         = inputArea;
    this.regInputFields    = (RegInputFieldsBean)    inputArea.getRegInputFields();
    this.targetInputFields = (TargetInputFieldsBean) inputArea.getTargetInputFields();
    
    return inputArea;
  }
  
  private GridBagConstraints getInputAreaBeanConstraints(){
    GridBagConstraints c = new GridBagConstraints();
    
    c.gridx = GridBagConstraints.RELATIVE;
    c.gridy = 0;
    c.fill  = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.insets  = this.getMyInsets();
    
    return c;
  }
  
  private void setMyListeners(){
    JButton execBtn  = this.regInputFields.getExecButtonComponent();
    JButton clearBtn = this.regInputFields.getClearButtonComponent();
    
    execBtn.addActionListener(new ExecuteAction(this.inputArea, new ResultAreaBean()));
    clearBtn.addActionListener(new ClearAction(this.regInputFields, this.targetInputFields));
  }

  private Insets getMyInsets(){
    return new Insets(3, 3, 3, 3);
  }
}

================================
過去の記事については、以下のページからご参照下さい。