いろいろ備忘録日記

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

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

評価される文字列を入力するエリアを表すクラス。

package gsf.tools.regexp.regexptester.bean;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.Serializable;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class TargetInputFieldsBean extends JPanel {
  private JTextField field;
  private JButton    execBtn;
  private JButton    clearBtn;
  
  public TargetInputFieldsBean(){
    super();
    
    this.buildContents();
  }
  
  public JTextField getFieldComponent(){
    return this.field;
  }
  
  public JButton getExecButtonComponent(){
    return this.execBtn;
  }

  public JButton getClearButtonComponent(){
    return this.clearBtn;
  }
  
  private void buildContents(){
    super.setLayout(new GridBagLayout());
    
    super.add(this.getLabel(), this.getLabelConstraints());
    super.add(this.getField(), this.getFieldConstraints());
    
  }
  
  private JComponent getLabel() {
    JLabel l = new JLabel("対象文字列:");
    
    l.setHorizontalAlignment(JLabel.RIGHT);
    l.setFont(this.getMyFont());
    
    return l;
  }

  private GridBagConstraints getLabelConstraints(){
    GridBagConstraints c = new GridBagConstraints();
    
    c.gridx  = GridBagConstraints.RELATIVE;
    c.gridy  = 0;
    c.insets = this.getMyInsets();
    c.fill   = GridBagConstraints.BOTH;
    
    return c;
  }
  
  private JComponent getField(){
    JTextField t = new JTextField();
    t.setFont(this.getMyFont());
    
    this.field = t;
    
    return t;
  }
  
  private GridBagConstraints getFieldConstraints(){
    GridBagConstraints c = new GridBagConstraints();
    
    c.gridx   = GridBagConstraints.RELATIVE;
    c.gridy     = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets  = this.getMyInsets();
    c.weightx = 1.0;
    c.fill    = GridBagConstraints.BOTH;
    
    return c;
  }
  
  private Insets getMyInsets(){
    return new Insets(3, 3, 3, 3);
  }
  
  private Font getMyFont(){
    return new Font("MS ゴシック", Font.PLAIN, 13);
  }
}

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