読者です 読者をやめる 読者になる 読者になる

いろいろ備忘録日記

主に .NET 絡みのメモを公開しています。

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

java swing

正規表現を入力するエリアを表すクラス。
本当はボタンの部分も分けたほうがよさそうだったけど
面倒なのでそのまま配置。

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 RegInputFieldsBean extends JPanel {
  private JTextField field;
  private JButton    execBtn;
  private JButton    clearBtn;
  
  public RegInputFieldsBean(){
    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());
    super.add(this.getExecButton(), this.getExecButtonConstraints());
    super.add(this.getClearButton(), this.getClearButtonConstraints());
    
  }
  
  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.insets  = this.getMyInsets();
    c.weightx = 1.0;
    c.fill    = GridBagConstraints.BOTH;
    
    return c;
  }
  
  private JComponent getExecButton(){
    JButton b = new JButton("実行");
    
    b.setFont(this.getMyFont());
    
    this.execBtn = b;
    
    return b;
  }

  private GridBagConstraints getExecButtonConstraints(){
    GridBagConstraints c = new GridBagConstraints();
    
    c.gridx   = GridBagConstraints.RELATIVE;
    c.gridy   = 0;
    c.insets  = this.getMyInsets();
    c.anchor  = GridBagConstraints.CENTER;
    
    return c;
  }

  private JComponent getClearButton(){
    JButton b = new JButton("クリア");
    
    b.setFont(this.getMyFont());
    
    this.clearBtn = b;
    
    return b;
  }

  private GridBagConstraints getClearButtonConstraints(){
    GridBagConstraints c = new GridBagConstraints();
    
    c.gridx   = GridBagConstraints.RELATIVE;
    c.gridy   = 0;
    c.insets  = this.getMyInsets();
    c.anchor  = GridBagConstraints.CENTER;
    
    return c;
  }
      
  private Insets getMyInsets(){
    return new Insets(3, 3, 3, 3);
  }
  
  private Font getMyFont(){
    return new Font("MS ゴシック", Font.PLAIN, 13);
  }
}


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