GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
mark.george
/
jrex
Browse code
Rewrote JRex frame. Added transpose option.
master
1 parent
e99a352
commit
b6df4c04b32027cafd8d5cfdda1ff28d6cba8995
Mark
authored
on 8 Sep 2016
Patch
Showing
5 changed files
src/JRexFrame.form
src/JRexFrame.java
src/JSedFrame.java
src/JSedUtils.java
src/RegexTool.java
Ignore Space
Show notes
View
src/JRexFrame.form
0 → 100644
<?xml version="1.0" encoding="UTF-8" ?> <Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <NonVisualComponents> <Component class="javax.swing.ButtonGroup" name="expGrp"> </Component> </NonVisualComponents> <Properties> <Property name="defaultCloseOperation" type="int" value="3"/> </Properties> <SyntheticProperties> <SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="generateCenter" type="boolean" value="false"/> </SyntheticProperties> <AuxValues> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/> <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> </AuxValues> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Container class="javax.swing.JSplitPane" name="splitPane"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="null"/> </Property> <Property name="dividerLocation" type="int" value="366"/> <Property name="dividerSize" type="int" value="15"/> <Property name="orientation" type="int" value="0"/> <Property name="name" type="java.lang.String" value="splitPane" noResource="true"/> <Property name="oneTouchExpandable" type="boolean" value="true"/> </Properties> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/> <SubComponents> <Container class="javax.swing.JPanel" name="pnlInput"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> <TitledBorder title="Input"/> </Border> </Property> <Property name="name" type="java.lang.String" value="pnlInput" noResource="true"/> </Properties> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription"> <JSplitPaneConstraints position="top"/> </Constraint> </Constraints> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Component id="scrollTable" pref="566" max="32767" attributes="0"/> <Component id="scrollInput" alignment="0" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="spnColumns" min="-2" pref="46" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnCSV" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTSV" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="lblExpression" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtRegex" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnMatch" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" alignment="1" attributes="0"> <EmptySpace min="0" pref="0" max="32767" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="1" attributes="0"> <Component id="btnLoad" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnClear" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" alignment="1" attributes="0"> <Component id="jButton1" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnTranspose" min="-2" max="-2" attributes="0"/> </Group> </Group> </Group> </Group> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnLoad" alignment="3" max="32767" attributes="0"/> <Component id="btnClear" alignment="3" max="32767" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> <Component id="scrollInput" pref="100" max="32767" attributes="0"/> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="txtRegex" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lblExpression" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTSV" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCSV" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="spnColumns" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnMatch" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Component id="scrollTable" pref="101" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnTranspose" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JButton" name="btnClear"> <Properties> <Property name="text" type="java.lang.String" value="Clear"/> <Property name="name" type="java.lang.String" value="btnClear" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClearActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnLoad"> <Properties> <Property name="text" type="java.lang.String" value="Load"/> <Property name="name" type="java.lang.String" value="btnLoad" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLoadActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollInput"> <Properties> <Property name="name" type="java.lang.String" value="scrollInput" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTextArea" name="txtInput"> <Properties> <Property name="columns" type="int" value="20"/> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="rows" type="int" value="5"/> <Property name="name" type="java.lang.String" value="txtInput" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JLabel" name="lblExpression"> <Properties> <Property name="horizontalAlignment" type="int" value="4"/> <Property name="text" type="java.lang.String" value="Expression:"/> <Property name="name" type="java.lang.String" value="lblExpression" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtRegex"> <Properties> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="name" type="java.lang.String" value="txtRegex" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JSpinner" name="spnColumns"> <Properties> <Property name="name" type="java.lang.String" value="spnColumns" noResource="true"/> </Properties> <Events> <EventHandler event="mouseWheelMoved" listener="java.awt.event.MouseWheelListener" parameters="java.awt.event.MouseWheelEvent" handler="spnColumnsMouseWheelMoved"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnTSV"> <Properties> <Property name="text" type="java.lang.String" value="TSV"/> <Property name="name" type="java.lang.String" value="btnTSV" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTSVActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnCSV"> <Properties> <Property name="text" type="java.lang.String" value="CSV"/> <Property name="name" type="java.lang.String" value="btnCSV" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCSVActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnMatch"> <Properties> <Property name="text" type="java.lang.String" value="Apply"/> <Property name="name" type="java.lang.String" value="btnMatch" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMatchActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollTable"> <Properties> <Property name="name" type="java.lang.String" value="scrollTable" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTable" name="jTable"> <Properties> <Property name="name" type="java.lang.String" value="jTable" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JButton" name="btnTranspose"> <Properties> <Property name="text" type="java.lang.String" value="Transpose"/> <Property name="name" type="java.lang.String" value="btnTranspose" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTransposeActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="jButton1"> <Properties> <Property name="text" type="java.lang.String" value="Literalise Expression"/> <Property name="name" type="java.lang.String" value="jButton1" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/> </Events> </Component> </SubComponents> </Container> <Container class="javax.swing.JPanel" name="pnlOutput"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> <TitledBorder title="Output"/> </Border> </Property> <Property name="name" type="java.lang.String" value="pnlOutput" noResource="true"/> </Properties> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription"> <JSplitPaneConstraints position="right"/> </Constraint> </Constraints> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Component id="scrollOutput" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="jLabel1" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoQuestion" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoDollar" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoSlash" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="cbBlanks" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtReplace" pref="177" max="32767" attributes="0"/> </Group> <Group type="102" alignment="0" attributes="0"> <Component id="lblFormat" min="-2" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/> <Component id="txtFormat" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnFormat" min="-2" max="-2" attributes="0"/> </Group> </Group> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="3" attributes="0"> <Component id="rdoQuestion" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="rdoDollar" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="rdoSlash" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="cbBlanks" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txtReplace" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="lblFormat" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txtFormat" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnFormat" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Component id="scrollOutput" pref="102" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JLabel" name="lblFormat"> <Properties> <Property name="horizontalAlignment" type="int" value="4"/> <Property name="text" type="java.lang.String" value="Format:"/> <Property name="name" type="java.lang.String" value="lblFormat" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtFormat"> <Properties> <Property name="name" type="java.lang.String" value="txtFormat" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JButton" name="btnFormat"> <Properties> <Property name="text" type="java.lang.String" value="Apply"/> <Property name="name" type="java.lang.String" value="btnFormat" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnFormatActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollOutput"> <Properties> <Property name="name" type="java.lang.String" value="scrollOutput" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTextArea" name="txtOutput"> <Properties> <Property name="columns" type="int" value="20"/> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="rows" type="int" value="5"/> <Property name="name" type="java.lang.String" value="txtOutput" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JRadioButton" name="rdoQuestion"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="selected" type="boolean" value="true"/> <Property name="text" type="java.lang.String" value="?"/> <Property name="name" type="java.lang.String" value="rdoQuestion" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoQuestionActionPerformed"/> </Events> </Component> <Component class="javax.swing.JRadioButton" name="rdoDollar"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="text" type="java.lang.String" value="$"/> <Property name="name" type="java.lang.String" value="rdoDollar" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoDollarActionPerformed"/> </Events> </Component> <Component class="javax.swing.JRadioButton" name="rdoSlash"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="text" type="java.lang.String" value="\u005c" containsInvalidXMLChars="true"/> <Property name="name" type="java.lang.String" value="rdoSlash" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoSlashActionPerformed"/> </Events> </Component> <Component class="javax.swing.JLabel" name="jLabel1"> <Properties> <Property name="text" type="java.lang.String" value="Argument Marker:"/> <Property name="name" type="java.lang.String" value="jLabel1" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JCheckBox" name="cbBlanks"> <Properties> <Property name="text" type="java.lang.String" value="Replace blanks?"/> <Property name="name" type="java.lang.String" value="cbBlanks" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtReplace"> <Properties> <Property name="text" type="java.lang.String" value="null"/> <Property name="name" type="java.lang.String" value="txtReplace" noResource="true"/> </Properties> </Component> </SubComponents> </Container> </SubComponents> </Container> </SubComponents> </Form>
Ignore Space
Show notes
View
src/JRexFrame.java
0 → 100644
import java.awt.Color; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.SpinnerNumberModel; import javax.swing.UIManager; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; /** * * @author Mark George <mark.george@otago.ac.nz> */ public class JRexFrame extends javax.swing.JFrame { private String exprChar = "?"; /** * Creates new form JRexFrame */ public JRexFrame() { initComponents(); splitPane.setResizeWeight(0.66); spnColumns.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1)); } /** * This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { expGrp = new javax.swing.ButtonGroup(); splitPane = new javax.swing.JSplitPane(); pnlInput = new javax.swing.JPanel(); btnClear = new javax.swing.JButton(); btnLoad = new javax.swing.JButton(); scrollInput = new javax.swing.JScrollPane(); txtInput = new javax.swing.JTextArea(); lblExpression = new javax.swing.JLabel(); txtRegex = new javax.swing.JTextField(); spnColumns = new javax.swing.JSpinner(); btnTSV = new javax.swing.JButton(); btnCSV = new javax.swing.JButton(); btnMatch = new javax.swing.JButton(); scrollTable = new javax.swing.JScrollPane(); jTable = new javax.swing.JTable(); btnTranspose = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); pnlOutput = new javax.swing.JPanel(); lblFormat = new javax.swing.JLabel(); txtFormat = new javax.swing.JTextField(); btnFormat = new javax.swing.JButton(); scrollOutput = new javax.swing.JScrollPane(); txtOutput = new javax.swing.JTextArea(); rdoQuestion = new javax.swing.JRadioButton(); rdoDollar = new javax.swing.JRadioButton(); rdoSlash = new javax.swing.JRadioButton(); jLabel1 = new javax.swing.JLabel(); cbBlanks = new javax.swing.JCheckBox(); txtReplace = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); splitPane.setBorder(null); splitPane.setDividerLocation(366); splitPane.setDividerSize(15); splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); splitPane.setName("splitPane"); // NOI18N splitPane.setOneTouchExpandable(true); pnlInput.setBorder(javax.swing.BorderFactory.createTitledBorder("Input")); pnlInput.setName("pnlInput"); // NOI18N btnClear.setText("Clear"); btnClear.setName("btnClear"); // NOI18N btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } }); btnLoad.setText("Load"); btnLoad.setName("btnLoad"); // NOI18N btnLoad.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLoadActionPerformed(evt); } }); scrollInput.setName("scrollInput"); // NOI18N txtInput.setColumns(20); txtInput.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtInput.setRows(5); txtInput.setName("txtInput"); // NOI18N scrollInput.setViewportView(txtInput); lblExpression.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblExpression.setText("Expression:"); lblExpression.setName("lblExpression"); // NOI18N txtRegex.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtRegex.setName("txtRegex"); // NOI18N spnColumns.setName("spnColumns"); // NOI18N spnColumns.addMouseWheelListener(new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { spnColumnsMouseWheelMoved(evt); } }); btnTSV.setText("TSV"); btnTSV.setName("btnTSV"); // NOI18N btnTSV.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTSVActionPerformed(evt); } }); btnCSV.setText("CSV"); btnCSV.setName("btnCSV"); // NOI18N btnCSV.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCSVActionPerformed(evt); } }); btnMatch.setText("Apply"); btnMatch.setName("btnMatch"); // NOI18N btnMatch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMatchActionPerformed(evt); } }); scrollTable.setName("scrollTable"); // NOI18N jTable.setName("jTable"); // NOI18N scrollTable.setViewportView(jTable); btnTranspose.setText("Transpose"); btnTranspose.setName("btnTranspose"); // NOI18N btnTranspose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTransposeActionPerformed(evt); } }); jButton1.setText("Literalise Expression"); jButton1.setName("jButton1"); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout pnlInputLayout = new javax.swing.GroupLayout(pnlInput); pnlInput.setLayout(pnlInputLayout); pnlInputLayout.setHorizontalGroup( pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlInputLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollTable, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE) .addComponent(scrollInput) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCSV) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTSV) .addGap(18, 18, 18) .addComponent(lblExpression) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtRegex) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnMatch)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInputLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInputLayout.createSequentialGroup() .addComponent(btnLoad) .addGap(18, 18, 18) .addComponent(btnClear)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInputLayout.createSequentialGroup() .addComponent(jButton1) .addGap(18, 18, 18) .addComponent(btnTranspose))))) .addContainerGap()) ); pnlInputLayout.setVerticalGroup( pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlInputLayout.createSequentialGroup() .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnLoad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnClear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollInput, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtRegex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblExpression) .addComponent(btnTSV) .addComponent(btnCSV) .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnMatch)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(scrollTable, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnTranspose) .addComponent(jButton1)) .addContainerGap()) ); splitPane.setTopComponent(pnlInput); pnlOutput.setBorder(javax.swing.BorderFactory.createTitledBorder("Output")); pnlOutput.setName("pnlOutput"); // NOI18N lblFormat.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblFormat.setText("Format:"); lblFormat.setName("lblFormat"); // NOI18N txtFormat.setName("txtFormat"); // NOI18N btnFormat.setText("Apply"); btnFormat.setName("btnFormat"); // NOI18N btnFormat.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFormatActionPerformed(evt); } }); scrollOutput.setName("scrollOutput"); // NOI18N txtOutput.setColumns(20); txtOutput.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtOutput.setRows(5); txtOutput.setName("txtOutput"); // NOI18N scrollOutput.setViewportView(txtOutput); expGrp.add(rdoQuestion); rdoQuestion.setSelected(true); rdoQuestion.setText("?"); rdoQuestion.setName("rdoQuestion"); // NOI18N rdoQuestion.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoQuestionActionPerformed(evt); } }); expGrp.add(rdoDollar); rdoDollar.setText("$"); rdoDollar.setName("rdoDollar"); // NOI18N rdoDollar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoDollarActionPerformed(evt); } }); expGrp.add(rdoSlash); rdoSlash.setText("\\"); rdoSlash.setName("rdoSlash"); // NOI18N rdoSlash.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoSlashActionPerformed(evt); } }); jLabel1.setText("Argument Marker:"); jLabel1.setName("jLabel1"); // NOI18N cbBlanks.setText("Replace blanks?"); cbBlanks.setName("cbBlanks"); // NOI18N txtReplace.setText("null"); txtReplace.setName("txtReplace"); // NOI18N javax.swing.GroupLayout pnlOutputLayout = new javax.swing.GroupLayout(pnlOutput); pnlOutput.setLayout(pnlOutputLayout); pnlOutputLayout.setHorizontalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollOutput) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoQuestion) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoDollar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoSlash) .addGap(18, 18, 18) .addComponent(cbBlanks) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtReplace, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnFormat))) .addContainerGap()) ); pnlOutputLayout.setVerticalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(rdoQuestion) .addComponent(rdoDollar) .addComponent(rdoSlash) .addComponent(jLabel1) .addComponent(cbBlanks) .addComponent(txtReplace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblFormat) .addComponent(txtFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnFormat)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(scrollOutput, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE) .addContainerGap()) ); splitPane.setRightComponent(pnlOutput); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(splitPane) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(splitPane) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void match() { String regex = txtRegex.getText(); String text = txtInput.getText(); String[] input = text.split("\n"); Pattern pattern = Pattern.compile(regex); DefaultTableModel model = new DefaultTableModel(); jTable.setModel(model); int numMatches = 0; for (String line : input) { Matcher matcher = pattern.matcher(line); if (matcher.find()) { numMatches++; int groupCount = matcher.groupCount(); model.setColumnCount(groupCount); Object[] headers = new Object[groupCount]; for (int k = 0; k < groupCount; k++) { headers[k] = k + 1; } model.setColumnIdentifiers(headers); txtOutput.append(matcher.group(0) + "\n"); String[] groups = new String[matcher.groupCount()]; for (int j = 1; j <= matcher.groupCount(); j++) { String s = matcher.group(j); groups[j - 1] = s; } model.addRow(groups); } } txtOutput.setText(""); txtOutput.append("Matched " + numMatches + " line(s) out of " + input.length + " line(s) of input."); } private void format() { txtOutput.setText(""); TableModel model = jTable.getModel(); String formatter = this.txtFormat.getText().replaceAll("\\" + exprChar + "(\\d*)", "%$1\\$s"); for (int row = 0; row < model.getRowCount(); row++) { Object[] values = new Object[model.getColumnCount()]; for (int col = 0; col < model.getColumnCount(); col++) { String val = (String) model.getValueAt(row, col); if (cbBlanks.isSelected() && val.isEmpty()) { val = txtReplace.getText(); } values[col] = val; } String formatted = String.format(formatter, values); txtOutput.append(formatted + "\n"); } } private void transpose() { TableModel model = jTable.getModel(); DefaultTableModel transposed = new DefaultTableModel(model.getColumnCount(), model.getRowCount()); for (int row = 0; row < model.getRowCount(); row++) { for (int col = 0; col < model.getColumnCount(); col++) { Object val = model.getValueAt(row, col); transposed.setValueAt(val, col, row); } } Object[] headers = new Object[transposed.getColumnCount()]; for (int i = 0; i < headers.length; i++) { headers[i] = i + 1; } transposed.setColumnIdentifiers(headers); jTable.setModel(transposed); } private void csv() { Integer cols = (Integer) spnColumns.getValue(); System.out.println(cols); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols - 1; i++) { sb.append("(.*?),"); } sb.append("(.*)"); txtRegex.setText(sb.toString()); } private void tsv() { Integer cols = (Integer) spnColumns.getValue(); System.out.println(cols); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols - 1; i++) { sb.append("(.*?)\\t"); } sb.append("(.*)"); txtRegex.setText(sb.toString()); } private void load() { JFileChooser jfc = new JFileChooser(); if (jfc.showOpenDialog(JRexFrame.this) == JFileChooser.APPROVE_OPTION) { try { String data = JSedUtils.readFile(jfc.getSelectedFile()); txtInput.setText(data); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error", ex.getMessage(), JOptionPane.ERROR_MESSAGE); } } } private void btnFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormatActionPerformed format(); }//GEN-LAST:event_btnFormatActionPerformed private void btnTransposeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTransposeActionPerformed transpose(); }//GEN-LAST:event_btnTransposeActionPerformed private void btnMatchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMatchActionPerformed match(); }//GEN-LAST:event_btnMatchActionPerformed private void btnCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCSVActionPerformed csv(); }//GEN-LAST:event_btnCSVActionPerformed private void btnTSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTSVActionPerformed tsv(); }//GEN-LAST:event_btnTSVActionPerformed private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed load(); }//GEN-LAST:event_btnLoadActionPerformed private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed txtInput.setText(""); }//GEN-LAST:event_btnClearActionPerformed private void rdoQuestionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoQuestionActionPerformed exprChar = "?"; }//GEN-LAST:event_rdoQuestionActionPerformed private void rdoDollarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoDollarActionPerformed exprChar = "$"; }//GEN-LAST:event_rdoDollarActionPerformed private void rdoSlashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoSlashActionPerformed exprChar = "\\"; }//GEN-LAST:event_rdoSlashActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed txtOutput.setText(this.txtRegex.getText().replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"")); }//GEN-LAST:event_jButton1ActionPerformed private void spnColumnsMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_spnColumnsMouseWheelMoved Integer value = (Integer) spnColumns.getValue(); value -= evt.getUnitsToScroll(); spnColumns.setValue(value > 0 ? value : 0); }//GEN-LAST:event_spnColumnsMouseWheelMoved /** * @param args the command line arguments */ public static void main(String args[]) throws Exception { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); UIManager.put("control", new Color(50, 50, 50)); UIManager.put("nimbusBase", new Color(60, 60, 60)); UIManager.put("nimbusBlueGrey", new Color(60, 60, 60)); UIManager.put("nimbusFocus", new Color(90, 90, 90)); UIManager.put("nimbusLightBackground", new Color(70, 70, 70)); UIManager.put("text", new Color(230, 230, 230)); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new JRexFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCSV; private javax.swing.JButton btnClear; private javax.swing.JButton btnFormat; private javax.swing.JButton btnLoad; private javax.swing.JButton btnMatch; private javax.swing.JButton btnTSV; private javax.swing.JButton btnTranspose; private javax.swing.JCheckBox cbBlanks; private javax.swing.ButtonGroup expGrp; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JTable jTable; private javax.swing.JLabel lblExpression; private javax.swing.JLabel lblFormat; private javax.swing.JPanel pnlInput; private javax.swing.JPanel pnlOutput; private javax.swing.JRadioButton rdoDollar; private javax.swing.JRadioButton rdoQuestion; private javax.swing.JRadioButton rdoSlash; private javax.swing.JScrollPane scrollInput; private javax.swing.JScrollPane scrollOutput; private javax.swing.JScrollPane scrollTable; private javax.swing.JSplitPane splitPane; private javax.swing.JSpinner spnColumns; private javax.swing.JTextField txtFormat; private javax.swing.JTextArea txtInput; private javax.swing.JTextArea txtOutput; private javax.swing.JTextField txtRegex; private javax.swing.JTextField txtReplace; // End of variables declaration//GEN-END:variables }
Ignore Space
Show notes
View
src/JSedFrame.java
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.io.File; import java.util.Vector; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class JSedFrame extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JSplitPane jSplitPane = null; private JSplitPane jSplitPane1 = null; private JScrollPane jScrollPane = null; private JTextArea taInput = null; private JScrollPane jScrollPane1 = null; private JTextArea taResult = null; private final DefaultTableModel expressionTableModel = new DefaultTableModel(new String[]{"Search","Replace"}, 0); private JButton jButton = null; private JPanel jPanel1 = null; private JScrollPane jScrollPane2 = null; private JTable jTable = null; private JPanel jPanel2 = null; private JButton btnAddRow = null; private JButton btnLoad = null; private JButton jButton1 = null; /** * This is the default constructor */ public JSedFrame() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(600, 400); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); // synchronise the scrolling of the two text areas jScrollPane.getVerticalScrollBar().setModel(jScrollPane1.getVerticalScrollBar().getModel()); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getJSplitPane(), BorderLayout.CENTER); } return jContentPane; } /** * This method initializes jSplitPane * * @return javax.swing.JSplitPane */ private JSplitPane getJSplitPane() { if (jSplitPane == null) { jSplitPane = new JSplitPane(); jSplitPane.setResizeWeight(0.75D); jSplitPane.setRightComponent(getJPanel1()); jSplitPane.setLeftComponent(getJSplitPane1()); } return jSplitPane; } /** * This method initializes jSplitPane1 * * @return javax.swing.JSplitPane */ private JSplitPane getJSplitPane1() { if (jSplitPane1 == null) { jSplitPane1 = new JSplitPane(); jSplitPane1.setPreferredSize(new Dimension(400, 0)); jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT); jSplitPane1.setResizeWeight(0.5D); jSplitPane1.setBottomComponent(getJScrollPane1()); jSplitPane1.setTopComponent(getJScrollPane()); } return jSplitPane1; } /** * This method initializes jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setViewportView(getTaInput()); } return jScrollPane; } /** * This method initializes taInput * * @return javax.swing.JTextPane */ private JTextArea getTaInput() { if (taInput == null) { taInput = new JTextArea(); } return taInput; } /** * This method initializes jScrollPane1 * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane1() { if (jScrollPane1 == null) { jScrollPane1 = new JScrollPane(); jScrollPane1.setViewportView(getTaResult()); } return jScrollPane1; } /** * This method initializes taResult * * @return javax.swing.JTextPane */ private JTextArea getTaResult() { if (taResult == null) { taResult = new JTextArea(); } return taResult; } /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setText("Process"); jButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { process(); } }); } return jButton; } @SuppressWarnings("unchecked") protected void process() { String data = taInput.getText(); Vector<Vector<String>> v = expressionTableModel.getDataVector(); for (Vector<String> row : v) { if(!row.elementAt(0).isEmpty()) { String search = row.elementAt(0); String replace = row.elementAt(1); data = JSedUtils.performReplace(data, search, replace); } } taResult.setText(data); } /** * This method initializes jPanel1 * * @return javax.swing.JPanel */ private JPanel getJPanel1() { if (jPanel1 == null) { GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); gridBagConstraints3.gridx = 0; gridBagConstraints3.ipadx = 79; gridBagConstraints3.gridy = 1; GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); gridBagConstraints2.fill = GridBagConstraints.BOTH; gridBagConstraints2.gridy = 0; gridBagConstraints2.ipadx = -138; gridBagConstraints2.ipady = -113; gridBagConstraints2.weightx = 1.0; gridBagConstraints2.weighty = 1.0; gridBagConstraints2.gridx = 0; jPanel1 = new JPanel(); jPanel1.setLayout(new BorderLayout()); jPanel1.add(getJScrollPane2(), BorderLayout.CENTER); jPanel1.add(getJPanel2(), BorderLayout.SOUTH); } return jPanel1; } /** * This method initializes jScrollPane2 * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane2() { if (jScrollPane2 == null) { jScrollPane2 = new JScrollPane(); jScrollPane2.setViewportView(getJTable()); } return jScrollPane2; } /** * This method initializes jTable * * @return javax.swing.JTable */ private JTable getJTable() { if (jTable == null) { jTable = new JTable(); jTable.setModel(expressionTableModel); expressionTableModel.setColumnCount(2); expressionTableModel.setColumnIdentifiers(new String[]{"Search", "Replace"}); } return jTable; } /** * This method initializes jPanel2 * * @return javax.swing.JPanel */ private JPanel getJPanel2() { if (jPanel2 == null) { GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); gridBagConstraints5.gridx = 0; gridBagConstraints5.gridwidth = 2; gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints5.gridy = 2; GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); gridBagConstraints4.gridy = 1; gridBagConstraints4.weightx = 1.0; gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints4.gridx = 1; GridBagConstraints gridBagConstraints31 = new GridBagConstraints(); gridBagConstraints31.gridy = 1; gridBagConstraints31.weightx = 1.0; gridBagConstraints31.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints31.gridx = 0; GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); gridBagConstraints21.gridy = 0; gridBagConstraints21.gridwidth = 2; gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints21.weightx = 1.0; gridBagConstraints21.gridx = 0; GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.gridx = 2; gridBagConstraints1.gridy = 0; GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; jPanel2 = new JPanel(); jPanel2.setLayout(new GridBagLayout()); jPanel2.add(getBtnAddRow(), gridBagConstraints21); jPanel2.add(getBtnLoad(), gridBagConstraints31); jPanel2.add(getJButton1(), gridBagConstraints4); jPanel2.add(getJButton(), gridBagConstraints5); } return jPanel2; } /** * This method initializes btnAddRow * * @return javax.swing.JButton */ private JButton getBtnAddRow() { if (btnAddRow == null) { btnAddRow = new JButton(); btnAddRow.setText("Add Row"); btnAddRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { addNewExpression(); } }); } return btnAddRow; } protected void addNewExpression() { expressionTableModel.addRow(new String[]{"",""}); } /** * This method initializes btnLoad * * @return javax.swing.JButton */ private JButton getBtnLoad() { if (btnLoad == null) { btnLoad = new JButton(); btnLoad.setText("Load"); btnLoad.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { load(); } }); } return btnLoad; } protected void load() { JFileChooser jfc = new JFileChooser(); if(jfc.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) { try { String data = JSedUtils.readFile(jfc.getSelectedFile()); String[] rows = data.split("\n"); for (int i = 0; i < rows.length; i++) { String csvRow = rows[i]; expressionTableModel.addRow(JSedUtils.parseCSV(csvRow)); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE); } } } /** * This method initializes jButton1 * * @return javax.swing.JButton */ private JButton getJButton1() { if (jButton1 == null) { jButton1 = new JButton(); jButton1.setText("Save"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { save(); } }); } return jButton1; } @SuppressWarnings("unchecked") protected void save() { StringBuilder data = new StringBuilder(); Vector<Vector<String>> v = expressionTableModel.getDataVector(); for (Vector<String> row : v) { data.append("\""); data.append(row.elementAt(0)); data.append("\",\""); data.append(row.elementAt(1)); data.append("\""); data.append("\n"); } JFileChooser jfc = new JFileChooser(); int result = jfc.showSaveDialog(this); if(result==JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); if(f.exists()) { int confirm = JOptionPane.showConfirmDialog(this, "Overwrite existing file?"); if(confirm==JOptionPane.YES_OPTION) { try { JSedUtils.writeFile(f, data.toString()); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE); } } } } } public static void main(String[] args) throws Exception { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); UIManager.put("control", new Color(50, 50, 50)); UIManager.put("nimbusBase", new Color(60, 60, 60)); UIManager.put("nimbusBlueGrey", new Color(60, 60, 60)); UIManager.put("nimbusFocus", new Color(90, 90, 90)); UIManager.put("nimbusLightBackground", new Color(70, 70, 70)); UIManager.put("text", new Color(230, 230, 230)); SwingUtilities.invokeLater(new Runnable() { public void run() { final JSedFrame sedFrame = new JSedFrame(); sedFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); sedFrame.setVisible(true); } }); } }
import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.io.File; import java.util.Vector; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class JSedFrame extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JSplitPane jSplitPane = null; private JSplitPane jSplitPane1 = null; private JScrollPane jScrollPane = null; private JTextArea taInput = null; private JScrollPane jScrollPane1 = null; private JTextArea taResult = null; private final DefaultTableModel expressionTableModel = new DefaultTableModel(new String[]{"Search","Replace"}, 0); private JButton jButton = null; private JPanel jPanel1 = null; private JScrollPane jScrollPane2 = null; private JTable jTable = null; private JPanel jPanel2 = null; private JButton btnAddRow = null; private JButton btnLoad = null; private JButton jButton1 = null; /** * This is the default constructor */ public JSedFrame() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(600, 400); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); // synchronise the scrolling of the two text areas jScrollPane.getVerticalScrollBar().setModel(jScrollPane1.getVerticalScrollBar().getModel()); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getJSplitPane(), BorderLayout.CENTER); } return jContentPane; } /** * This method initializes jSplitPane * * @return javax.swing.JSplitPane */ private JSplitPane getJSplitPane() { if (jSplitPane == null) { jSplitPane = new JSplitPane(); jSplitPane.setResizeWeight(0.75D); jSplitPane.setRightComponent(getJPanel1()); jSplitPane.setLeftComponent(getJSplitPane1()); } return jSplitPane; } /** * This method initializes jSplitPane1 * * @return javax.swing.JSplitPane */ private JSplitPane getJSplitPane1() { if (jSplitPane1 == null) { jSplitPane1 = new JSplitPane(); jSplitPane1.setPreferredSize(new Dimension(400, 0)); jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT); jSplitPane1.setResizeWeight(0.5D); jSplitPane1.setBottomComponent(getJScrollPane1()); jSplitPane1.setTopComponent(getJScrollPane()); } return jSplitPane1; } /** * This method initializes jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setViewportView(getTaInput()); } return jScrollPane; } /** * This method initializes taInput * * @return javax.swing.JTextPane */ private JTextArea getTaInput() { if (taInput == null) { taInput = new JTextArea(); } return taInput; } /** * This method initializes jScrollPane1 * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane1() { if (jScrollPane1 == null) { jScrollPane1 = new JScrollPane(); jScrollPane1.setViewportView(getTaResult()); } return jScrollPane1; } /** * This method initializes taResult * * @return javax.swing.JTextPane */ private JTextArea getTaResult() { if (taResult == null) { taResult = new JTextArea(); } return taResult; } /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setText("Process"); jButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { process(); } }); } return jButton; } @SuppressWarnings("unchecked") protected void process() { String data = taInput.getText(); Vector<Vector<String>> v = expressionTableModel.getDataVector(); for (Vector<String> row : v) { if(!row.elementAt(0).isEmpty()) { String search = row.elementAt(0); String replace = row.elementAt(1); data = JSedUtils.performReplace(data, search, replace); } } taResult.setText(data); } /** * This method initializes jPanel1 * * @return javax.swing.JPanel */ private JPanel getJPanel1() { if (jPanel1 == null) { GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); gridBagConstraints3.gridx = 0; gridBagConstraints3.ipadx = 79; gridBagConstraints3.gridy = 1; GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); gridBagConstraints2.fill = GridBagConstraints.BOTH; gridBagConstraints2.gridy = 0; gridBagConstraints2.ipadx = -138; gridBagConstraints2.ipady = -113; gridBagConstraints2.weightx = 1.0; gridBagConstraints2.weighty = 1.0; gridBagConstraints2.gridx = 0; jPanel1 = new JPanel(); jPanel1.setLayout(new BorderLayout()); jPanel1.add(getJScrollPane2(), BorderLayout.CENTER); jPanel1.add(getJPanel2(), BorderLayout.SOUTH); } return jPanel1; } /** * This method initializes jScrollPane2 * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane2() { if (jScrollPane2 == null) { jScrollPane2 = new JScrollPane(); jScrollPane2.setViewportView(getJTable()); } return jScrollPane2; } /** * This method initializes jTable * * @return javax.swing.JTable */ private JTable getJTable() { if (jTable == null) { jTable = new JTable(); jTable.setModel(expressionTableModel); expressionTableModel.setColumnCount(2); expressionTableModel.setColumnIdentifiers(new String[]{"Search", "Replace"}); } return jTable; } /** * This method initializes jPanel2 * * @return javax.swing.JPanel */ private JPanel getJPanel2() { if (jPanel2 == null) { GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); gridBagConstraints5.gridx = 0; gridBagConstraints5.gridwidth = 2; gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints5.gridy = 2; GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); gridBagConstraints4.gridy = 1; gridBagConstraints4.weightx = 1.0; gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints4.gridx = 1; GridBagConstraints gridBagConstraints31 = new GridBagConstraints(); gridBagConstraints31.gridy = 1; gridBagConstraints31.weightx = 1.0; gridBagConstraints31.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints31.gridx = 0; GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); gridBagConstraints21.gridy = 0; gridBagConstraints21.gridwidth = 2; gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints21.weightx = 1.0; gridBagConstraints21.gridx = 0; GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.gridx = 2; gridBagConstraints1.gridy = 0; GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; jPanel2 = new JPanel(); jPanel2.setLayout(new GridBagLayout()); jPanel2.add(getBtnAddRow(), gridBagConstraints21); jPanel2.add(getBtnLoad(), gridBagConstraints31); jPanel2.add(getJButton1(), gridBagConstraints4); jPanel2.add(getJButton(), gridBagConstraints5); } return jPanel2; } /** * This method initializes btnAddRow * * @return javax.swing.JButton */ private JButton getBtnAddRow() { if (btnAddRow == null) { btnAddRow = new JButton(); btnAddRow.setText("Add Row"); btnAddRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { addNewExpression(); } }); } return btnAddRow; } protected void addNewExpression() { expressionTableModel.addRow(new String[]{"",""}); } /** * This method initializes btnLoad * * @return javax.swing.JButton */ private JButton getBtnLoad() { if (btnLoad == null) { btnLoad = new JButton(); btnLoad.setText("Load"); btnLoad.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { load(); } }); } return btnLoad; } protected void load() { JFileChooser jfc = new JFileChooser(); if(jfc.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) { try { String data = JSedUtils.readFile(jfc.getSelectedFile()); String[] rows = data.split("\n"); for (int i = 0; i < rows.length; i++) { String csvRow = rows[i]; expressionTableModel.addRow(JSedUtils.parseCSV(csvRow)); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE); } } } /** * This method initializes jButton1 * * @return javax.swing.JButton */ private JButton getJButton1() { if (jButton1 == null) { jButton1 = new JButton(); jButton1.setText("Save"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { save(); } }); } return jButton1; } @SuppressWarnings("unchecked") protected void save() { StringBuilder data = new StringBuilder(); Vector<Vector<String>> v = expressionTableModel.getDataVector(); for (Vector<String> row : v) { data.append("\""); data.append(row.elementAt(0)); data.append("\",\""); data.append(row.elementAt(1)); data.append("\""); data.append("\n"); } JFileChooser jfc = new JFileChooser(); int result = jfc.showSaveDialog(this); if(result==JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); if(f.exists()) { int confirm = JOptionPane.showConfirmDialog(this, "Overwrite existing file?"); if(confirm==JOptionPane.YES_OPTION) { try { JSedUtils.writeFile(f, data.toString()); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE); } } } } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final JSedFrame sedFrame = new JSedFrame(); sedFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); sedFrame.setVisible(true); } }); } }
Ignore Space
Show notes
View
src/JSedUtils.java
import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author mark * */ public class JSedUtils { // a simplistic regex for parsing a single line of well formed CSV with two columns private static final String CSV_REGEXP = "\"(.*)\",\"(.*)\""; private static final Pattern CSV_PATTERN = Pattern.compile(CSV_REGEXP); public static String[] parseCSV(String csv) { Matcher m = CSV_PATTERN.matcher(csv); String[] result = new String[2]; if(m.find()) { result[0] = m.group(1); result[1] = m.group(2); return result; } else { // panic! throw new RuntimeException("Could not parse the following CSV: " +csv); } } public static String readFile(String fileName) throws Exception { return readFile(new File(fileName)); } public static String readFile(File file) throws Exception { BufferedReader reader = new BufferedReader(new FileReader(file)); String line = null; StringBuilder fileContents = new StringBuilder(); while( (line = reader.readLine()) != null ) { fileContents.append(line); fileContents.append(System.getProperty("line.separator")); } reader.close(); return fileContents.toString(); } public static void writeFile(File file, String data) throws Exception { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(data); writer.close(); } public static String performReplace(String input, String search, String replace) { Pattern pattern = Pattern.compile(search, Pattern.MULTILINE+Pattern.DOTALL+Pattern.COMMENTS); Matcher matcher = pattern.matcher(input); return matcher.replaceAll(replace); } public static void main(String[] args) throws Exception { if(args.length != 2 && args.length != 3) { System.out.println("Usage: java JSed input-file search replace"); System.out.println("or java JSed input-file expression-file"); return; } String inputFile = args[0]; if(args.length == 3) { String search = args[1]; String replace = args[2]; System.out.println(performReplace(readFile(inputFile), search, replace)); } else if (args.length == 2) { String expressionFile = args[1]; String expressionsStr = readFile(expressionFile); String[] expressions = expressionsStr.split(System.getProperty("line.separator")); String data = readFile(inputFile); for (int i = 0; i < expressions.length; i++) { String anExpression = expressions[i]; String[] anExpressionSplit = anExpression.split(" "); String search = anExpressionSplit[0]; String replace = anExpressionSplit[1]; data = performReplace(data, search, replace); } System.out.println(data); } } }
import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author mark * */ public class JSedUtils { // a simplistic regex for parsing a single line of well formed CSV with two columns private static final String CSV_REGEXP = "\"(.*)\",\"(.*)\""; private static final Pattern CSV_PATTERN = Pattern.compile(CSV_REGEXP); public static String[] parseCSV(String csv) { Matcher m = CSV_PATTERN.matcher(csv); String[] result = new String[2]; if(m.find()) { result[0] = m.group(1); result[1] = m.group(2); return result; } else { // panic! throw new RuntimeException("Could not parse the following CSV: " +csv); } } public static String readFile(String fileName) throws Exception { return readFile(new File(fileName)); } public static String readFile(File file) throws Exception { BufferedReader reader = new BufferedReader(new FileReader(file)); String line = null; StringBuilder fileContents = new StringBuilder(); while( (line = reader.readLine()) != null ) { fileContents.append(line); fileContents.append(System.getProperty("line.separator")); } reader.close(); return fileContents.toString(); } public static void writeFile(File file, String data) throws Exception { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(data); writer.close(); } public static String performReplace(String input, String search, String replace) { Pattern pattern = Pattern.compile(search, Pattern.MULTILINE+Pattern.DOTALL+Pattern.COMMENTS); Matcher matcher = pattern.matcher(input); return matcher.replaceAll(replace); } public static void main(String[] args) throws Exception { if(args.length != 2 && args.length != 3) { System.out.println("Usage: java JSed input-file search replace"); System.out.println("or java JSed input-file expression-file"); return; } String inputFile = args[0]; if(args.length == 3) { String search = args[1]; String replace = args[2]; System.out.println(performReplace(readFile(inputFile), search, replace)); } else if (args.length == 2) { String expressionFile = args[1]; String expressionsStr = readFile(expressionFile); String[] expressions = expressionsStr.split(System.getProperty("line.separator")); String data = readFile(inputFile); for (int i = 0; i < expressions.length; i++) { String anExpression = expressions[i]; String[] anExpressionSplit = anExpression.split(" "); String search = anExpressionSplit[0]; String replace = anExpressionSplit[1]; data = performReplace(data, search, replace); } System.out.println(data); } } }
Show notes
View
src/RegexTool.java
100644 → 0
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.*; import javax.swing.table.DefaultTableModel; /* * Created on Mar 1, 2005 */ /** * @author mark */ @SuppressWarnings("serial") public class RegexTool extends JFrame { private javax.swing.JPanel jContentPane = null; private JPanel pnlButtons = null; private JPanel pnlMain = null; private JTextField tfRE = null; private JLabel jLabel = null; private JButton btnMatch = null; private JButton btnExit = null; private JLabel jLabel4; private JTextField txtFormat; private JLabel jLabel3; private JTextArea taFormatted; private JScrollPane jScrollPane2; private JPanel jPanel2; private JLabel jLabel5; private JTable jTable; private JScrollPane jScrollPane3; private JPanel jPanel1; private JSplitPane splitBottom; private JLabel jLabel2; private JTextArea taMatched; private JScrollPane jScrollPane1; private JPanel pnlMatches; private JTextArea taText; private JScrollPane jScrollPane; private JLabel jLabel1; private JPanel pnlTextToProcess; private JSplitPane splitTop; private JSplitPane splitMain; private JButton btnFormat = null; private String[] groups; private List groupList; private Font mono = new Font("Monospaced", Font.PLAIN, 12); private JCheckBox cbLiteralize; private String re; private JButton jButton = null; private JButton jButton1 = null; private JButton jButton2 = null; private JPanel jPanel = null; private JPanel jPanel3 = null; private JCheckBox cbMultiline = null; private JLabel lblMultiline = null; private JCheckBox cbNulls = new JCheckBox();; private JLabel lblNulls = new JLabel("Use Nulls?"); private JLabel lblDirtyHackySpacer = null; /** * This method initializes pnlButtons * * @return javax.swing.JPanel */ @SuppressWarnings({"all"}) private JPanel getPnlButtons() { if (this.pnlButtons == null) { try { lblDirtyHackySpacer = new JLabel(); lblDirtyHackySpacer.setText(" "); lblMultiline = new JLabel(); lblMultiline.setText("Multiline?"); this.pnlButtons = new JPanel(); pnlButtons.add(lblMultiline, null); pnlButtons.add(getCbMultiline(), null); pnlButtons.add(new JLabel(" "), null); pnlButtons.add(lblNulls, null); pnlButtons.add(cbNulls, null); pnlButtons.add(lblDirtyHackySpacer, null); this.pnlButtons.add(getBtnMatch(), null); this.pnlButtons.add(getJButton(), null); final JButton btnLoad = new JButton("Load from file"); btnLoad.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser(); if (jfc.showOpenDialog(RegexTool.this) == JFileChooser.APPROVE_OPTION) { try { String data = JSedUtils.readFile(jfc.getSelectedFile()); taText.setText(data); } catch (Exception ex) { JOptionPane.showMessageDialog(RegexTool.this, "Error", ex.getMessage(), JOptionPane.ERROR_MESSAGE); } } } }); this.pnlButtons.add(btnLoad, null); this.pnlButtons.add(getBtnExit(), null); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return this.pnlButtons; } /** * This method initializes jPanel1 * * @return javax.swing.JPanel */ @SuppressWarnings({"all"}) private JPanel getPnlMain() { if (pnlMain == null) { try { GridBagConstraints gridBagConstraints32 = new GridBagConstraints(); GridBagConstraints gridBagConstraints71 = new GridBagConstraints(); GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); GridBagConstraints gridBagConstraints31 = new GridBagConstraints(); GridBagConstraints gridBagConstraints51 = new GridBagConstraints(); this.jLabel = new JLabel(); GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); this.pnlMain = new JPanel(); this.pnlMain.setLayout(new GridBagLayout()); gridBagConstraints1.gridx = 1; gridBagConstraints1.gridy = 0; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 5); gridBagConstraints2.gridx = 0; gridBagConstraints2.gridy = 0; gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints2.insets = new java.awt.Insets(0, 5, 0, 5); this.jLabel.setText("Regular Expression:"); gridBagConstraints3.gridx = 0; gridBagConstraints3.gridy = 1; gridBagConstraints3.insets = new java.awt.Insets(5, 0, 0, 0); gridBagConstraints3.anchor = java.awt.GridBagConstraints.CENTER; gridBagConstraints3.gridwidth = 2; gridBagConstraints5.gridx = 0; gridBagConstraints5.gridy = 3; gridBagConstraints5.insets = new java.awt.Insets(5, 0, 0, 0); gridBagConstraints5.anchor = java.awt.GridBagConstraints.CENTER; gridBagConstraints5.gridwidth = 2; gridBagConstraints7.gridx = 0; gridBagConstraints7.gridy = 2; gridBagConstraints7.weightx = 1.0; gridBagConstraints7.weighty = 1.0; gridBagConstraints7.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints7.insets = new java.awt.Insets(0, 5, 0, 5); gridBagConstraints7.gridwidth = 2; gridBagConstraints8.gridx = 0; gridBagConstraints8.gridy = 4; gridBagConstraints8.weightx = 1.0; gridBagConstraints8.weighty = 1.0; gridBagConstraints8.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints8.insets = new java.awt.Insets(0, 5, 0, 5); gridBagConstraints8.gridwidth = 2; gridBagConstraints11.gridx = 0; gridBagConstraints11.gridy = 7; gridBagConstraints11.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints11.insets = new java.awt.Insets(5, 5, 0, 5); gridBagConstraints21.gridx = 1; gridBagConstraints21.gridy = 7; gridBagConstraints21.weightx = 1.0; gridBagConstraints21.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints21.insets = new java.awt.Insets(5, 0, 0, 5); gridBagConstraints31.gridx = 0; gridBagConstraints31.gridy = 8; gridBagConstraints31.insets = new java.awt.Insets(5, 0, 0, 0); gridBagConstraints31.anchor = java.awt.GridBagConstraints.CENTER; gridBagConstraints31.gridwidth = 2; gridBagConstraints51.gridx = 0; gridBagConstraints51.gridy = 9; gridBagConstraints51.weightx = 1.0; gridBagConstraints51.weighty = 1.0; gridBagConstraints51.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints51.insets = new java.awt.Insets(0, 5, 0, 5); gridBagConstraints51.gridwidth = 2; gridBagConstraints71.gridx = 0; gridBagConstraints71.gridy = 6; gridBagConstraints71.weightx = 1.0; gridBagConstraints71.weighty = 1.0; gridBagConstraints71.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints71.insets = new java.awt.Insets(0, 5, 0, 5); gridBagConstraints71.gridwidth = 2; gridBagConstraints32.gridx = 0; gridBagConstraints32.gridy = 5; gridBagConstraints32.anchor = java.awt.GridBagConstraints.CENTER; gridBagConstraints32.insets = new java.awt.Insets(5, 0, 0, 0); gridBagConstraints32.gridwidth = 2; this.pnlMain.add(getTfRE(), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); this.pnlMain.add(getCbLiteralize(), new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0) ); this.pnlMain.add(new JLabel("Literalize"), new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0) ); this.pnlMain.add(this.jLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets( 5, 5, 5, 5), 0, 0)); this.pnlMain.add(getSplitMain(), new GridBagConstraints(0, 5, 4, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return this.pnlMain; } /** * This method initializes jTextField * * @return javax.swing.JTextField */ @SuppressWarnings({"all"}) private JTextField getTfRE() { if (this.tfRE == null) { try { this.tfRE = new JTextField(); this.tfRE.setFont(this.mono); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return this.tfRE; } /** * This method initializes jButton * * @return javax.swing.JButton */ @SuppressWarnings({"all"}) private JButton getBtnMatch() { if (this.btnMatch == null) { try { this.btnMatch = new JButton(); this.btnMatch.setText("Match"); this.btnMatch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { btnMatchClicked(); } }); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return this.btnMatch; } /** * */ @SuppressWarnings(value= {"all"}) protected void btnMatchClicked() { try { taMatched.setText(""); if(cbMultiline.isSelected()) { doMultilineMatch(); } else { doLineByLineMatch(); } } catch (Exception e) { e.printStackTrace(); taMatched.setText(e.getMessage()); } } private void doLineByLineMatch() { groupList = new ArrayList(); String regex = tfRE.getText(); String text = taText.getText(); String[] input = text.split("\n"); Pattern pattern = Pattern.compile(regex); DefaultTableModel model = new DefaultTableModel(); jTable.setModel(model); int numMatches = 0; for (int i = 0; i < input.length; i++) { String line = input[i]; Matcher matcher = pattern.matcher(line); if (matcher.find()) { numMatches++; int groupCount = matcher.groupCount(); model.setColumnCount(groupCount); Object[] headers = new Object[groupCount]; for (int k = 0; k < groupCount; k++) { headers[k] = new Integer(k + 1); } model.setColumnIdentifiers(headers); taMatched.append(matcher.group(0) + "\n"); groups = new String[matcher.groupCount()]; for (int j = 1; j <= matcher.groupCount(); j++) { String s = matcher.group(j); groups[j - 1] = s; } model.addRow(groups); groupList.add(groups); } } taMatched.append("Matched " + numMatches + " line(s) out of " + input.length + " line(s) of input."); } private void doMultilineMatch() { groupList = new ArrayList(); String regex = tfRE.getText(); String text = taText.getText(); Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE+Pattern.DOTALL); DefaultTableModel model = new DefaultTableModel(); jTable.setModel(model); int numMatches = 0; int i = 0; Matcher matcher = pattern.matcher(text); while (matcher.find(i)) { i=matcher.end(); numMatches++; int groupCount = matcher.groupCount(); model.setColumnCount(groupCount); Object[] headers = new Object[groupCount]; for (int k = 0; k < groupCount; k++) { headers[k] = new Integer(k + 1); } model.setColumnIdentifiers(headers); taMatched.append(matcher.group(0) + "\n"); groups = new String[matcher.groupCount()]; for (int j = 1; j <= matcher.groupCount(); j++) { String s = matcher.group(j); groups[j - 1] = s; } model.addRow(groups); groupList.add(groups); } taMatched.append("Found " + numMatches + " matches."); } /** * This method initializes jButton1 * * @return javax.swing.JButton */ @SuppressWarnings({"all"}) private JButton getBtnExit() { if (btnExit == null) { try { btnExit = new JButton(); btnExit.setText("Exit"); btnExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.exit(0); } }); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return btnExit; } protected void cbLiteralClicked(ItemEvent e) { if(e.getStateChange() == ItemEvent.SELECTED) { this.re = this.tfRE.getText(); String literalizedRE = this.re.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\""); this.tfRE.setText(literalizedRE); } else { this.tfRE.setText(this.re); } } /** * This method initializes jButton * * @return javax.swing.JButton */ @SuppressWarnings({"all"}) private JButton getJButton() { if (btnFormat == null) { try { btnFormat = new JButton(); btnFormat.setText("Format"); btnFormat.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { btnFormatClick(); } }); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return btnFormat; } protected void btnFormatClick() { if (this.groupList == null || this.txtFormat.getText().length() == 0) return; this.taFormatted.setText(""); String formatter = this.txtFormat.getText() .replaceAll("\\\\(\\d*)", "%$1\\$s"); Iterator it = this.groupList.iterator(); while (it.hasNext()) { Object[] groups = (Object[]) it.next(); // replace empty strings with "null" (handy for DB inserts) if (cbNulls.isSelected()) { for (int i = 0; i < groups.length; i++) { Object object = groups[i]; if (object.toString().isEmpty()) { groups[i] = "null"; } } } this.taFormatted.append(String.format(formatter, groups) + "\n"); } } /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton2() { if (jButton == null) { jButton = new JButton(); jButton.setText("x"); jButton.setFont(new Font("SansSerif", Font.PLAIN, 8)); jButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { taText.setText(""); } }); } return jButton; } /** * This method initializes jButton1 * * @return javax.swing.JButton */ private JButton getJButton1() { if (jButton1 == null) { jButton1 = new JButton(); jButton1.setFont(new Font("SansSerif", Font.PLAIN, 8)); jButton1.setText("x"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { taMatched.setText(""); } }); } return jButton1; } /** * This method initializes jButton2 * * @return javax.swing.JButton */ private JButton getJButton22() { if (jButton2 == null) { jButton2 = new JButton(); jButton2.setFont(new Font("SansSerif", Font.PLAIN, 8)); jButton2.setText("x"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { taFormatted.setText(""); } }); } return jButton2; } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); gridBagConstraints4.gridx = 0; gridBagConstraints4.gridy = 0; gridBagConstraints4.weightx = 1; GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = GridBagConstraints.WEST; jPanel = new JPanel(); jPanel.setLayout(new GridBagLayout()); jPanel.add(getJButton2(), gridBagConstraints); jPanel.add(getJLabel1(), gridBagConstraints4); } return jPanel; } /** * This method initializes jPanel3 * * @return javax.swing.JPanel */ private JPanel getJPanel3() { if (jPanel3 == null) { GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); gridBagConstraints9.gridx = 0; gridBagConstraints9.gridy = 0; gridBagConstraints9.weightx = 1; GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); gridBagConstraints6.gridx = 0; gridBagConstraints6.gridy = 0; gridBagConstraints6.anchor = GridBagConstraints.WEST; jPanel3 = new JPanel(); jPanel3.setLayout(new GridBagLayout()); jPanel3.add(getJButton1(), gridBagConstraints6); jPanel3.add(getJLabel2(), gridBagConstraints9); } return jPanel3; } /** * This method initializes cbMultiline * * @return javax.swing.JCheckBox */ private JCheckBox getCbMultiline() { if (cbMultiline == null) { cbMultiline = new JCheckBox(); } return cbMultiline; } public static void main(String[] args) { if(System.getProperty("os.name").equalsIgnoreCase("linux")) { System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); } else { System.setProperty("swing.defaultlaf", UIManager.getSystemLookAndFeelClassName()); } SwingUtilities.invokeLater(new Runnable() { public void run() { new RegexTool().setVisible(true); } }); } /** * This is the default constructor */ public RegexTool() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); this.setSize(600, 500); this.setContentPane(getJContentPane()); this.setTitle("RegEx Tool"); this.validate(); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ @SuppressWarnings({"all"}) private javax.swing.JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new javax.swing.JPanel(); jContentPane.setLayout(new java.awt.BorderLayout()); jContentPane.add(getPnlButtons(), java.awt.BorderLayout.SOUTH); jContentPane.add(getPnlMain(), java.awt.BorderLayout.CENTER); } return jContentPane; } @SuppressWarnings({"all"}) private JSplitPane getSplitMain() { if (splitMain == null) { splitMain = new JSplitPane(); splitMain.setOrientation(JSplitPane.VERTICAL_SPLIT); splitMain.setResizeWeight(0.5); splitMain.setOneTouchExpandable(true); splitMain.setContinuousLayout(true); splitMain.add(getSplitTop(), JSplitPane.TOP); splitMain.add(getSplitBottom(), JSplitPane.BOTTOM); } return splitMain; } @SuppressWarnings({"all"}) private JSplitPane getSplitTop() { if (splitTop == null) { splitTop = new JSplitPane(); splitTop.setOrientation(JSplitPane.VERTICAL_SPLIT); splitTop.setResizeWeight(0.5); splitTop.setOneTouchExpandable(true); splitTop.setContinuousLayout(true); splitTop.add(getPnlTextToProcess(), JSplitPane.TOP); splitTop.add(getPnlMatches(), JSplitPane.BOTTOM); } return splitTop; } @SuppressWarnings({"all"}) private JPanel getPnlTextToProcess() { if (pnlTextToProcess == null) { pnlTextToProcess = new JPanel(); pnlTextToProcess.setLayout(new BorderLayout()); pnlTextToProcess.add(getJPanel(), BorderLayout.NORTH); pnlTextToProcess.add(getJScrollPane(), BorderLayout.CENTER); } return pnlTextToProcess; } @SuppressWarnings({"all"}) private JLabel getJLabel1() { if (jLabel1 == null) { jLabel1 = new JLabel(); jLabel1.setText("Text to Process"); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); } return jLabel1; } /** * This method initializes jScrollPane * * @return javax.swing.JScrollPane */ @SuppressWarnings({"all"}) private JScrollPane getJScrollPane() { if (jScrollPane == null) { try { jScrollPane = new JScrollPane(); jScrollPane.setViewportView(getTaText()); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return jScrollPane; } /** * This method initializes jTextArea * * @return javax.swing.JTextArea */ @SuppressWarnings({"all"}) private JTextArea getTaText() { if (taText == null) { try { taText = new JTextArea(); taText.setFont(mono); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return taText; } @SuppressWarnings({"all"}) private JPanel getPnlMatches() { if (pnlMatches == null) { pnlMatches = new JPanel(); pnlMatches.setLayout(new BorderLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = -1; gbc.gridy = -1; gbc.anchor=GridBagConstraints.WEST; pnlMatches.add(getJScrollPane1(), BorderLayout.CENTER); pnlMatches.add(getJPanel3(), BorderLayout.NORTH); } return pnlMatches; } /** * This method initializes jScrollPane1 * * @return javax.swing.JScrollPane */ @SuppressWarnings({"all"}) private JScrollPane getJScrollPane1() { if (jScrollPane1 == null) { try { jScrollPane1 = new JScrollPane(); jScrollPane1.setAutoscrolls(true); jScrollPane1.setViewportView(getTaMatched()); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return jScrollPane1; } /** * This method initializes jTextArea1 * * @return javax.swing.JTextArea */ @SuppressWarnings({"all"}) private JTextArea getTaMatched() { if (taMatched == null) { try { taMatched = new JTextArea(); taMatched.setFont(mono); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return taMatched; } @SuppressWarnings({"all"}) private JLabel getJLabel2() { if (jLabel2 == null) { jLabel2 = new JLabel(); jLabel2.setText("Matches"); jLabel2.setHorizontalAlignment(SwingConstants.CENTER); } return jLabel2; } @SuppressWarnings({"all"}) private JSplitPane getSplitBottom() { if (splitBottom == null) { splitBottom = new JSplitPane(); splitBottom.setOrientation(JSplitPane.VERTICAL_SPLIT); splitBottom.setResizeWeight(0.5); splitBottom.setOneTouchExpandable(true); splitBottom.setContinuousLayout(true); splitBottom.add(getJPanel1(), JSplitPane.TOP); splitBottom.add(getJPanel2(), JSplitPane.BOTTOM); } return splitBottom; } @SuppressWarnings({"all"}) private JPanel getJPanel1() { if (jPanel1 == null) { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jPanel1.add(getJScrollPane3(), BorderLayout.CENTER); jPanel1.add(getJLabel5(), BorderLayout.NORTH); } return jPanel1; } /** * This method initializes jScrollPane3 * * @return javax.swing.JScrollPane */ @SuppressWarnings({"all"}) private JScrollPane getJScrollPane3() { if (jScrollPane3 == null) { try { jScrollPane3 = new JScrollPane(); jScrollPane3.setViewportView(getJTable()); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return jScrollPane3; } /** * This method initializes jTable * * @return javax.swing.JTable */ @SuppressWarnings({"all"}) private JTable getJTable() { if (jTable == null) { try { jTable = new JTable(); jTable .setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return jTable; } @SuppressWarnings({"all"}) private JLabel getJLabel5() { if (jLabel5 == null) { jLabel5 = new JLabel(); jLabel5.setText("Groups"); jLabel5.setHorizontalAlignment(SwingConstants.CENTER); } return jLabel5; } @SuppressWarnings({"all"}) private JPanel getJPanel2() { if (jPanel2 == null) { GridBagConstraints gridBagConstraints13 = new GridBagConstraints(); gridBagConstraints13.gridx = 0; gridBagConstraints13.anchor = GridBagConstraints.WEST; gridBagConstraints13.gridy = 3; GridBagConstraints gridBagConstraints10 = new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0); jPanel2 = new JPanel(); GridBagLayout jPanel2Layout = new GridBagLayout(); jPanel2.setLayout(jPanel2Layout); jPanel2.add(getJScrollPane2(), new GridBagConstraints(0, 14, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); jPanel2.add(getJLabel3(), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); jPanel2.add(getTxtFormat(), new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); jPanel2.add(getJLabel4(), gridBagConstraints10); jPanel2.add(getJButton22(), gridBagConstraints13); } return jPanel2; } /** * This method initializes jScrollPane2 * * @return javax.swing.JScrollPane */ @SuppressWarnings({"all"}) private JScrollPane getJScrollPane2() { if (jScrollPane2 == null) { try { jScrollPane2 = new JScrollPane(); jScrollPane2.setAutoscrolls(true); jScrollPane2.setViewportView(getTaFormatted()); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return jScrollPane2; } /** * This method initializes jTextArea * * @return javax.swing.JTextArea */ @SuppressWarnings({"all"}) private JTextArea getTaFormatted() { if (taFormatted == null) { try { taFormatted = new JTextArea(); taFormatted.setFont(mono); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return taFormatted; } @SuppressWarnings({"all"}) private JLabel getJLabel3() { if (jLabel3 == null) { jLabel3 = new JLabel(); jLabel3.setText("Formatting String:"); } return jLabel3; } /** * This method initializes jTextField * * @return javax.swing.JTextField */ @SuppressWarnings({"all"}) private JTextField getTxtFormat() { if (txtFormat == null) { try { txtFormat = new JTextField(); txtFormat.setFont(mono); } catch (java.lang.Throwable e) { e.printStackTrace(); } } return txtFormat; } @SuppressWarnings({"all"}) private JLabel getJLabel4() { if (jLabel4 == null) { jLabel4 = new JLabel(); jLabel4.setText("Formatted Text"); } return jLabel4; } public JCheckBox getCbLiteralize() { if (this.cbLiteralize == null) { this.cbLiteralize = new JCheckBox(); this.cbLiteralize.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { cbLiteralClicked(e); } }); } return this.cbLiteralize; } }
Show line notes below