公司系统用tikeswing做表现层,配置布局的时候有很多重复的代码,于是使用这个工具自动生成代码:
左边是变化的变量名,右下是套用的重复代码格式,按钮指代使用哪种格式填入变量名。
package transms.app._0all.util;
import java.awt.BorderLayout;
import java.text.BreakIterator;
import javax.swing.JTextArea;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.JSplitPane;
public class AutoCodeGenTool extends javax.swing.JFrame {
private static final long serialVersionUID = 627855237034164778L;
private javax.swing.JButton ivjJButton1 = null;
private javax.swing.JPanel ivjJFrameContentPane = null;
private javax.swing.JTextArea txtVar1 = null;
private JTextArea txtResult = null;
private JTextArea txtPara1 = null;
private JTabbedPane tpWest = null;
private JScrollPane spWest1 = null;
private JScrollPane spWest2 = null;
private JTextArea txtVar2 = null;
private JScrollPane spWest3 = null;
private JTextArea txtVar3 = null;
private JTabbedPane tpSouth = null;
private JScrollPane spSouth1 = null;
private JScrollPane spSouth2 = null;
private JScrollPane spSouth3 = null;
private JTextArea txtPara2 = null;
private JTextArea txtPara3 = null;
private JScrollPane spCenter = null;
private JToolBar jJToolBarBar = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JButton jButton3 = null;
private JSplitPane jSplitPane = null;
private JSplitPane jSplitPane1 = null;
private JPanel jPanel = null;
public AutoCodeGenTool() {
super();
initialize();
}
/**
* Return the JButton1 property value.
*
* @return javax.swing.JButton
*/
private javax.swing.JButton getJButton1() {
if (ivjJButton1 == null) {
ivjJButton1 = new javax.swing.JButton();
ivjJButton1.setName("JButton1");
ivjJButton1.setText("开始");
ivjJButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
doStaff1();
getTxtResult().setSelectionStart(0);
getTxtResult().setSelectionEnd(getTxtResult().getCaretPosition());
getTxtResult().requestFocusInWindow();
getTxtResult().copy();
}
});
}
return ivjJButton1;
}
protected void doStaff1() {
String s1 = getVar();
BreakIterator it = BreakIterator.getLineInstance();
it.setText(s1);
int start = it.first();
txtResult.setText("");
for (int end = it.next(); end != BreakIterator.DONE; start = end, end = it.next()) {
doStaff2(s1.substring(start, end));
}
}
private String getVar() {
switch (this.tpWest.getSelectedIndex()) {
case 0:
return txtVar1.getText();
case 1:
return txtVar2.getText();
case 2:
return txtVar3.getText();
default:
return "";
}
}
private void doStaff2(String para) {
String org = getPara();
/**
* @@原参数
* @#首字母大写其他不变参数 #@首字母小写其他不变参数 <>全大写参数 ><全小写参数 @< 首字母大写其他小写
*/
para = para.replaceAll("\r", "");
para = para.replaceAll("\n", "");
org = org.replaceAll("@@", para);
org = org
.replaceAll("@#", para.substring(0, 1).toUpperCase() + para.substring(1));
org = org.replaceAll("@<", para.substring(0, 1).toUpperCase()
+ para.substring(1).toLowerCase());
org = org
.replaceAll("#@", para.substring(0, 1).toLowerCase() + para.substring(1));
org = org.replaceAll("<>", para.toUpperCase());
org = org.replaceAll("><", para.toLowerCase());
txtResult.append(org + "\r\n");
}
private String getPara() {
switch (this.tpSouth.getSelectedIndex()) {
case 0:
return txtPara1.getText();
case 1:
return txtPara2.getText();
case 2:
return txtPara3.getText();
default:
return "";
}
}
private JTextArea getTxt() {
switch (this.tpSouth.getSelectedIndex()) {
case 0:
return txtPara1;
case 1:
return txtPara2;
case 2:
return txtPara3;
default:
return null;
}
}
/**
* Return the JFrameContentPane property value.
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJFrameContentPane() {
if (ivjJFrameContentPane == null) {
BorderLayout borderLayout = new BorderLayout();
borderLayout.setHgap(6);
borderLayout.setVgap(6);
ivjJFrameContentPane = new javax.swing.JPanel();
ivjJFrameContentPane.setLayout(borderLayout);
ivjJFrameContentPane.setName("JFrameContentPane");
ivjJFrameContentPane.add(getJButton1(), BorderLayout.NORTH);
ivjJFrameContentPane.add(getJSplitPane(), BorderLayout.CENTER);
}
return ivjJFrameContentPane;
}
/**
* Return the JTextArea1 property value.
*
* @return javax.swing.JTextArea
*/
private javax.swing.JTextArea getJTextArea1() {
if (txtVar1 == null) {
txtVar1 = new javax.swing.JTextArea();
txtVar1.setName("JTextArea1");
txtVar1.setRows(3);
txtVar1.setColumns(17);
}
return txtVar1;
}
/**
* Initialize the class.
*/
private void initialize() {
this.setName("JFrame1");
this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
this.setBounds(45, 25, 800, 600);
this.setTitle("AutoCodeGenTool");
this.setContentPane(getJFrameContentPane());
}
/**
* This method initializes txtResult
*
* @return javax.swing.JTextArea
*/
private JTextArea getTxtResult() {
if (txtResult == null) {
txtResult = new JTextArea();
}
return txtResult;
}
/**
* This method initializes jTextArea1
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea12() {
if (txtPara1 == null) {
txtPara1 = new JTextArea();
txtPara1.setRows(10);
}
return txtPara1;
}
/**
* This method initializes tbWest
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getTbWest() {
if (tpWest == null) {
tpWest = new JTabbedPane();
tpWest.addTab("VAR1", null, getSpWest1(), null);
tpWest.addTab("VAR2", null, getSpWest2(), null);
tpWest.addTab("VAR3", null, getSpWest3(), null);
}
return tpWest;
}
/**
* This method initializes spWest1
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getSpWest1() {
if (spWest1 == null) {
spWest1 = new JScrollPane();
spWest1.setViewportView(getJTextArea1());
}
return spWest1;
}
/**
* This method initializes spWest2
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getSpWest2() {
if (spWest2 == null) {
spWest2 = new JScrollPane();
spWest2.setViewportView(getTxtVar2());
}
return spWest2;
}
/**
* This method initializes txtVar2
*
* @return javax.swing.JTextArea
*/
private JTextArea getTxtVar2() {
if (txtVar2 == null) {
txtVar2 = new JTextArea();
}
return txtVar2;
}
/**
* This method initializes spWest3
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getSpWest3() {
if (spWest3 == null) {
spWest3 = new JScrollPane();
spWest3.setViewportView(getTxtVar3());
}
return spWest3;
}
/**
* This method initializes txtVar3
*
* @return javax.swing.JTextArea
*/
private JTextArea getTxtVar3() {
if (txtVar3 == null) {
txtVar3 = new JTextArea();
}
return txtVar3;
}
/**
* This method initializes tpSouth
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getTpSouth() {
if (tpSouth == null) {
tpSouth = new JTabbedPane();
tpSouth.addTab("Para1", null, getSpSouth1(), null);
tpSouth.addTab("Para2", null, getSpSouth2(), null);
tpSouth.addTab("Para3", null, getSpSouth3(), null);
}
return tpSouth;
}
private void focusSouth() {
((JScrollPane) getTpSouth().getSelectedComponent()).getViewport().getView()
.requestFocusInWindow();
}
/**
* This method initializes spSouth1
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getSpSouth1() {
if (spSouth1 == null) {
spSouth1 = new JScrollPane();
spSouth1.setViewportView(getJTextArea12());
}
return spSouth1;
}
/**
* This method initializes spSouth2
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getSpSouth2() {
if (spSouth2 == null) {
spSouth2 = new JScrollPane();
spSouth2.setViewportView(getTxtPara2());
}
return spSouth2;
}
/**
* This method initializes spSouth3
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getSpSouth3() {
if (spSouth3 == null) {
spSouth3 = new JScrollPane();
spSouth3.setViewportView(getTxtPara3());
}
return spSouth3;
}
/**
* This method initializes txtPara2
*
* @return javax.swing.JTextArea
*/
private JTextArea getTxtPara2() {
if (txtPara2 == null) {
txtPara2 = new JTextArea();
}
return txtPara2;
}
/**
* This method initializes txtPara3
*
* @return javax.swing.JTextArea
*/
private JTextArea getTxtPara3() {
if (txtPara3 == null) {
txtPara3 = new JTextArea();
}
return txtPara3;
}
/**
* This method initializes spCenter
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getSpCenter() {
if (spCenter == null) {
TitledBorder vitalBorder = new TitledBorder("结果:");
spCenter = new JScrollPane();
spCenter.setViewportView(getTxtResult());
spCenter.setBorder(vitalBorder);
}
return spCenter;
}
/**
* This method initializes jJToolBarBar
*
* @return javax.swing.JToolBar
*/
private JToolBar getJJToolBarBar() {
if (jJToolBarBar == null) {
jJToolBarBar = new JToolBar();
jJToolBarBar.add(getJButton());
jJToolBarBar.add(getJButton12());
jJToolBarBar.add(getJButton2());
jJToolBarBar.add(getJButton3());
}
return jJToolBarBar;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText(" 原 ");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
getTxt().replaceSelection("@@");
focusSouth();
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton12() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("大小");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
getTxt().replaceSelection("@<");
focusSouth();
}
});
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setText(" 大 ");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
getTxt().replaceSelection("<>");
focusSouth();
}
});
}
return jButton2;
}
/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setText(" 小 ");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
getTxt().replaceSelection("><");
focusSouth();
}
});
}
return jButton3;
}
/**
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
*/
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setResizeWeight(0.2D);
jSplitPane.setRightComponent(getJSplitPane1());
jSplitPane.setLeftComponent(getTbWest());
}
return jSplitPane;
}
/**
* This method initializes jSplitPane1
*
* @return javax.swing.JSplitPane
*/
private JSplitPane getJSplitPane1() {
if (jSplitPane1 == null) {
jSplitPane1 = new JSplitPane();
jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
jSplitPane1.setResizeWeight(0.8D);
jSplitPane1.setBottomComponent(getJPanel());
jSplitPane1.setTopComponent(getSpCenter());
}
return jSplitPane1;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(new BorderLayout());
jPanel.add(getJJToolBarBar(), BorderLayout.NORTH);
jPanel.add(getTpSouth(), BorderLayout.CENTER);
}
return jPanel;
}
}