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
Implemented save feature. Save replace table on focus change.
master
1 parent
5c3abab
commit
453de23917666f080629862ffe93b981c03d663b
Mark George
authored
on 30 Oct 2017
Patch
Showing
3 changed files
src/jrex/JRexFrame.form
src/jrex/JRexFrame.java
src/jrex/ReplacePanel.java
Ignore Space
Show notes
View
src/jrex/JRexFrame.form
<?xml version="1.0" encoding="UTF-8" ?> <Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <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 min="-2" max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> <Component id="pnlReplace" pref="197" max="32767" 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"/> <Group type="103" groupAlignment="0" attributes="0"> <Component id="pnlReplace" max="32767" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> </Group> <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"> <Font PropertyName="font" name="Dialog" size="12" style="0"/> </TitledBorder> </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"> <Component id="spnColumns" min="-2" pref="46" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnCsvInput" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTsvInput" 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 type="unrelated" max="-2" attributes="0"/> <Component id="btnMatch" min="-2" max="-2" attributes="0"/> </Group> <Component id="scrollInput" max="32767" attributes="0"/> <Group type="102" attributes="0"> <Component id="btnLoad" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="cbReplace" min="-2" max="-2" attributes="0"/> <EmptySpace max="32767" attributes="0"/> <Component id="btnClear" min="-2" max="-2" attributes="0"/> </Group> <Component id="scrollTable" alignment="1" pref="711" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="btnPivot" linkSize="1" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="jButton1" linkSize="1" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTranspose" linkSize="1" min="-2" max="-2" attributes="0"/> <EmptySpace min="0" pref="0" max="32767" 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"/> <Component id="cbReplace" alignment="3" min="-2" max="-2" 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="btnTsvInput" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCsvInput" 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 min="-2" max="-2" attributes="0"/> <Component id="scrollTable" pref="113" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnPivot" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTranspose" alignment="3" min="-2" max="-2" attributes="0"/> </Group> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JButton" name="btnClear"> <Properties> <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Connection code="UIManager.getIcon("FileView.fileIcon")" type="code"/> </Property> <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="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Connection code="UIManager.getIcon("FileView.directoryIcon")
" type="code"/> </Property> <Property name="text" type="java.lang.String" value="Open"/> <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> <Events> <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtRegexKeyPressed"/> </Events> </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="btnTsvInput"> <Properties> <Property name="text" type="java.lang.String" value="TSV"/> <Property name="name" type="java.lang.String" value="btnTsvInput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTsvInputActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnCsvInput"> <Properties> <Property name="text" type="java.lang.String" value="CSV"/> <Property name="name" type="java.lang.String" value="btnCsvInput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCsvInputActionPerformed"/> </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.JCheckBox" name="cbReplace"> <Properties> <Property name="text" type="java.lang.String" value="Search/Replace "/> <Property name="name" type="java.lang.String" value="cbReplace" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbReplaceActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnPivot"> <Properties> <Property name="text" type="java.lang.String" value="Pivot Wide to Long"/> <Property name="name" type="java.lang.String" value="btnPivot" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnPivotActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="jButton1"> <Properties> <Property name="text" type="java.lang.String" value="Pivot Long to Wide"/> <Property name="name" type="java.lang.String" value="jButton1" noResource="true"/> </Properties> </Component> <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> </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"> <Font PropertyName="font" name="Dialog" size="12" style="0"/> </TitledBorder> </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"> <Component id="scrollOutput" max="32767" attributes="0"/> <Group type="102" attributes="0"> <Component id="lblArgumentMarker" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtMarker" linkSize="3" min="-2" pref="32" 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" linkSize="3" min="-2" pref="62" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnCsvOutput" linkSize="2" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTsvOutput" linkSize="2" max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/> <Component id="btnSwap" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnSave" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" attributes="0"> <Component id="lblFormat" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtFormat" max="32767" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnFormat" min="-2" 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="lblArgumentMarker" 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"/> <Component id="btnSwap" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txtMarker" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCsvOutput" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTsvOutput" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnSave" 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 max="-2" attributes="0"/> <Component id="scrollOutput" pref="152" max="32767" 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.JLabel" name="lblArgumentMarker"> <Properties> <Property name="text" type="java.lang.String" value="Column Prefix: "/> <Property name="name" type="java.lang.String" value="lblArgumentMarker" 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> <Component class="javax.swing.JButton" name="btnSwap"> <Properties> <Property name="text" type="java.lang.String" value="Output to Input"/> <Property name="name" type="java.lang.String" value="btnSwap" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSwapActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnCsvOutput"> <Properties> <Property name="text" type="java.lang.String" value="CSV"/> <Property name="name" type="java.lang.String" value="btnCsvOutput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCsvOutputActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnTsvOutput"> <Properties> <Property name="text" type="java.lang.String" value="TSV"/> <Property name="name" type="java.lang.String" value="btnTsvOutput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTsvOutputActionPerformed"/> </Events> </Component> <Component class="javax.swing.JTextField" name="txtMarker"> <Properties> <Property name="text" type="java.lang.String" value="?"/> <Property name="name" type="java.lang.String" value="txtMarker" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JButton" name="btnSave"> <Properties> <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Connection code="UIManager.getIcon("FileView.floppyDriveIcon")" type="code"/> </Property> <Property name="text" type="java.lang.String" value="Save"/> <Property name="name" type="java.lang.String" value="btnSave" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSaveActionPerformed"/> </Events> </Component> </SubComponents> </Container> </SubComponents> </Container> <Component class="jrex.ReplacePanel" name="pnlReplace"> <Properties> <Property name="name" type="java.lang.String" value="pnlReplace" noResource="true"/> </Properties> </Component> </SubComponents> </Form>
<?xml version="1.0" encoding="UTF-8" ?> <Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <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 min="-2" max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> <Component id="pnlReplace" pref="197" max="32767" 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"/> <Group type="103" groupAlignment="0" attributes="0"> <Component id="pnlReplace" max="32767" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> </Group> <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"> <Font PropertyName="font" name="Dialog" size="12" style="0"/> </TitledBorder> </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"> <Component id="spnColumns" min="-2" pref="46" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnCsvInput" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTsvInput" 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 type="unrelated" max="-2" attributes="0"/> <Component id="btnMatch" min="-2" max="-2" attributes="0"/> </Group> <Component id="scrollInput" max="32767" attributes="0"/> <Group type="102" attributes="0"> <Component id="btnLoad" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="cbReplace" min="-2" max="-2" attributes="0"/> <EmptySpace max="32767" attributes="0"/> <Component id="btnClear" min="-2" max="-2" attributes="0"/> </Group> <Component id="scrollTable" alignment="1" pref="711" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="btnPivot" linkSize="1" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="jButton1" linkSize="1" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTranspose" linkSize="1" min="-2" max="-2" attributes="0"/> <EmptySpace min="0" pref="0" max="32767" 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"/> <Component id="cbReplace" alignment="3" min="-2" max="-2" 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="btnTsvInput" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCsvInput" 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 min="-2" max="-2" attributes="0"/> <Component id="scrollTable" pref="113" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnPivot" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTranspose" alignment="3" min="-2" max="-2" attributes="0"/> </Group> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JButton" name="btnClear"> <Properties> <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Connection code="UIManager.getIcon("FileView.fileIcon")" type="code"/> </Property> <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="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Connection code="UIManager.getIcon("FileView.directoryIcon")
" type="code"/> </Property> <Property name="text" type="java.lang.String" value="Open"/> <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> <Events> <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtRegexKeyPressed"/> </Events> </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="btnTsvInput"> <Properties> <Property name="text" type="java.lang.String" value="TSV"/> <Property name="name" type="java.lang.String" value="btnTsvInput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTsvInputActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnCsvInput"> <Properties> <Property name="text" type="java.lang.String" value="CSV"/> <Property name="name" type="java.lang.String" value="btnCsvInput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCsvInputActionPerformed"/> </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.JCheckBox" name="cbReplace"> <Properties> <Property name="text" type="java.lang.String" value="Search/Replace "/> <Property name="name" type="java.lang.String" value="cbReplace" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbReplaceActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnPivot"> <Properties> <Property name="text" type="java.lang.String" value="Pivot Wide to Long"/> <Property name="name" type="java.lang.String" value="btnPivot" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnPivotActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="jButton1"> <Properties> <Property name="text" type="java.lang.String" value="Pivot Long to Wide"/> <Property name="name" type="java.lang.String" value="jButton1" noResource="true"/> </Properties> </Component> <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> </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"> <Font PropertyName="font" name="Dialog" size="12" style="0"/> </TitledBorder> </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"> <Component id="scrollOutput" max="32767" attributes="0"/> <Group type="102" attributes="0"> <Component id="lblArgumentMarker" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtMarker" linkSize="3" min="-2" pref="32" 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" linkSize="3" min="-2" pref="62" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnCsvOutput" linkSize="2" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTsvOutput" linkSize="2" max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/> <Component id="btnSwap" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="jButton2" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" attributes="0"> <Component id="lblFormat" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtFormat" max="32767" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnFormat" min="-2" 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="lblArgumentMarker" 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"/> <Component id="btnSwap" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txtMarker" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCsvOutput" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTsvOutput" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton2" 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 max="-2" attributes="0"/> <Component id="scrollOutput" pref="152" max="32767" 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.JLabel" name="lblArgumentMarker"> <Properties> <Property name="text" type="java.lang.String" value="Column Prefix: "/> <Property name="name" type="java.lang.String" value="lblArgumentMarker" 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> <Component class="javax.swing.JButton" name="btnSwap"> <Properties> <Property name="text" type="java.lang.String" value="Output to Input"/> <Property name="name" type="java.lang.String" value="btnSwap" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSwapActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnCsvOutput"> <Properties> <Property name="text" type="java.lang.String" value="CSV"/> <Property name="name" type="java.lang.String" value="btnCsvOutput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCsvOutputActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnTsvOutput"> <Properties> <Property name="text" type="java.lang.String" value="TSV"/> <Property name="name" type="java.lang.String" value="btnTsvOutput" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTsvOutputActionPerformed"/> </Events> </Component> <Component class="javax.swing.JTextField" name="txtMarker"> <Properties> <Property name="text" type="java.lang.String" value="?"/> <Property name="name" type="java.lang.String" value="txtMarker" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JButton" name="jButton2"> <Properties> <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Connection code="UIManager.getIcon("FileView.floppyDriveIcon")" type="code"/> </Property> <Property name="text" type="java.lang.String" value="Save"/> <Property name="name" type="java.lang.String" value="jButton2" noResource="true"/> </Properties> </Component> </SubComponents> </Container> </SubComponents> </Container> <Component class="jrex.ReplacePanel" name="pnlReplace"> <Properties> <Property name="name" type="java.lang.String" value="pnlReplace" noResource="true"/> </Properties> </Component> </SubComponents> </Form>
Ignore Space
Show notes
View
src/jrex/JRexFrame.java
package jrex; import com.google.common.collect.ListMultimap; import java.awt.Color; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import javax.swing.Action; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import javax.swing.KeyStroke; import javax.swing.SpinnerNumberModel; import javax.swing.UIManager; import javax.swing.table.TableModel; import javax.swing.text.DefaultEditorKit; /** * * @author Mark George <mark.george@otago.ac.nz> */ public class JRexFrame extends javax.swing.JFrame { private final Color defaultTextColor; /** * Creates new form JRexFrame */ public JRexFrame() { initComponents(); splitPane.setResizeWeight(0.66); spnColumns.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1)); JPopupMenu rightClickMenu = new JPopupMenu(); Action cut = new DefaultEditorKit.CutAction(); cut.putValue(Action.NAME, "Cut"); cut.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control X")); rightClickMenu.add(cut); Action copy = new DefaultEditorKit.CopyAction(); copy.putValue(Action.NAME, "Copy"); copy.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control C")); rightClickMenu.add(copy); Action paste = new DefaultEditorKit.PasteAction(); paste.putValue(Action.NAME, "Paste"); paste.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control V")); rightClickMenu.add(paste); Action tab = new DefaultEditorKit.InsertTabAction(); tab.putValue(Action.NAME, "Insert Tab"); rightClickMenu.add(tab); txtInput.setComponentPopupMenu(rightClickMenu); txtOutput.setComponentPopupMenu(rightClickMenu); txtRegex.setComponentPopupMenu(rightClickMenu); txtFormat.setComponentPopupMenu(rightClickMenu); txtReplace.setComponentPopupMenu(rightClickMenu); defaultTextColor = txtRegex.getBackground(); pnlReplace.setVisible(false); pnlReplace.setComponents(txtInput, txtOutput); } /** * 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() { 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(); btnTsvInput = new javax.swing.JButton(); btnCsvInput = new javax.swing.JButton(); btnMatch = new javax.swing.JButton(); scrollTable = new javax.swing.JScrollPane(); jTable = new javax.swing.JTable(); cbReplace = new javax.swing.JCheckBox(); btnPivot = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); btnTranspose = 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(); lblArgumentMarker = new javax.swing.JLabel(); cbBlanks = new javax.swing.JCheckBox(); txtReplace = new javax.swing.JTextField(); btnSwap = new javax.swing.JButton(); btnCsvOutput = new javax.swing.JButton(); btnTsvOutput = new javax.swing.JButton(); txtMarker = new javax.swing.JTextField(); btnSave = new javax.swing.JButton(); pnlReplace = new jrex.ReplacePanel(); 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(null, "Input", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12))); // NOI18N pnlInput.setName("pnlInput"); // NOI18N btnClear.setIcon(UIManager.getIcon("FileView.fileIcon")); 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.setIcon(UIManager.getIcon("FileView.directoryIcon") ); btnLoad.setText("Open"); 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 txtRegex.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { txtRegexKeyPressed(evt); } }); spnColumns.setName("spnColumns"); // NOI18N spnColumns.addMouseWheelListener(new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { spnColumnsMouseWheelMoved(evt); } }); btnTsvInput.setText("TSV"); btnTsvInput.setName("btnTsvInput"); // NOI18N btnTsvInput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTsvInputActionPerformed(evt); } }); btnCsvInput.setText("CSV"); btnCsvInput.setName("btnCsvInput"); // NOI18N btnCsvInput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCsvInputActionPerformed(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); cbReplace.setText("Search/Replace "); cbReplace.setName("cbReplace"); // NOI18N cbReplace.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbReplaceActionPerformed(evt); } }); btnPivot.setText("Pivot Wide to Long"); btnPivot.setName("btnPivot"); // NOI18N btnPivot.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPivotActionPerformed(evt); } }); jButton1.setText("Pivot Long to Wide"); jButton1.setName("jButton1"); // NOI18N btnTranspose.setText("Transpose"); btnTranspose.setName("btnTranspose"); // NOI18N btnTranspose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTransposeActionPerformed(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() .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCsvInput) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTsvInput) .addGap(18, 18, 18) .addComponent(lblExpression) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtRegex) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnMatch)) .addComponent(scrollInput) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(btnLoad) .addGap(18, 18, 18) .addComponent(cbReplace) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnClear)) .addComponent(scrollTable, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 711, Short.MAX_VALUE) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(btnPivot) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTranspose) .addGap(0, 0, Short.MAX_VALUE)) ); pnlInputLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnPivot, btnTranspose, jButton1}); 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) .addComponent(cbReplace)) .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(btnTsvInput) .addComponent(btnCsvInput) .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnMatch)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollTable, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnPivot) .addComponent(jButton1) .addComponent(btnTranspose))) ); splitPane.setTopComponent(pnlInput); pnlOutput.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Output", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12))); // NOI18N 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); lblArgumentMarker.setText("Column Prefix: "); lblArgumentMarker.setName("lblArgumentMarker"); // NOI18N cbBlanks.setText("Replace blanks? "); cbBlanks.setName("cbBlanks"); // NOI18N txtReplace.setText("null"); txtReplace.setName("txtReplace"); // NOI18N btnSwap.setText("Output to Input"); btnSwap.setName("btnSwap"); // NOI18N btnSwap.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSwapActionPerformed(evt); } }); btnCsvOutput.setText("CSV"); btnCsvOutput.setName("btnCsvOutput"); // NOI18N btnCsvOutput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCsvOutputActionPerformed(evt); } }); btnTsvOutput.setText("TSV"); btnTsvOutput.setName("btnTsvOutput"); // NOI18N btnTsvOutput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTsvOutputActionPerformed(evt); } }); txtMarker.setText("?"); txtMarker.setName("txtMarker"); // NOI18N btnSave.setIcon(UIManager.getIcon("FileView.floppyDriveIcon")); btnSave.setText("Save"); btnSave.setName("btnSave"); // NOI18N btnSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt); } }); javax.swing.GroupLayout pnlOutputLayout = new javax.swing.GroupLayout(pnlOutput); pnlOutput.setLayout(pnlOutputLayout); pnlOutputLayout.setHorizontalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollOutput) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblArgumentMarker) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtMarker, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(cbBlanks) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtReplace, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(btnCsvOutput) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTsvOutput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnSwap) .addGap(18, 18, 18) .addComponent(btnSave)) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtFormat) .addGap(18, 18, 18) .addComponent(btnFormat)) ); pnlOutputLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCsvOutput, btnTsvOutput}); pnlOutputLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtMarker, txtReplace}); pnlOutputLayout.setVerticalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblArgumentMarker) .addComponent(cbBlanks) .addComponent(txtReplace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnSwap) .addComponent(txtMarker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnCsvOutput) .addComponent(btnTsvOutput) .addComponent(btnSave)) .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.RELATED) .addComponent(scrollOutput, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)) ); splitPane.setRightComponent(pnlOutput); pnlReplace.setName("pnlReplace"); // NOI18N 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) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlReplace, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(pnlReplace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(splitPane)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void match() { txtOutput.setText(""); String regex = txtRegex.getText(); String text = txtInput.getText(); String[] input = null; try { Pattern pattern = Pattern.compile(regex); int flagsMask = pattern.flags(); StringBuilder flags = new StringBuilder(); boolean dotall = false; // work out which flags are being used if ((flagsMask & Pattern.DOTALL) == Pattern.DOTALL) { flags.append("DOTALL "); dotall = true; } if ((flagsMask & Pattern.MULTILINE) == Pattern.MULTILINE) { flags.append("MULTILINE "); } if ((flagsMask & Pattern.CASE_INSENSITIVE) == Pattern.CASE_INSENSITIVE) { flags.append("CASE_INSENSITIVE "); } PivotTableModel model = new PivotTableModel(); jTable.setModel(model); int numMatches = 0; // it DOTALL mode is on then grab the entire text rather then seperating by line if (dotall) { input = new String[1]; input[0] = text; } else { input = text.split("\n"); } for (String line : input) { Matcher matcher = pattern.matcher(line); while (matcher.find()) { // group() matches the entire line if there was a match. // This if-statment is to suppress extra empty groups from being // produced if the regex matches the entire line if (matcher.group().length() != line.length()) { continue; } numMatches++; 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); } } model.fireTableStructureChanged(); txtOutput.append("\nMatched " + numMatches + " line(s) out of " + input.length + " line(s) of input."); if (!flags.toString().isEmpty()) { txtOutput.append("\n\nFlags: " + flags.toString().trim()); } } catch (PatternSyntaxException ex) { txtOutput.setText(""); txtOutput.append(ex.getMessage()); txtRegex.setBackground(new Color(1f, 0.3f, 0.3f)); } } private void format() { String marker = txtMarker.getText(); txtOutput.setText(""); TableModel model = jTable.getModel(); String formatter = this.txtFormat.getText().replaceAll("\\" + marker + "(\\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() { PivotTableModel model = (PivotTableModel) jTable.getModel(); model.transpose(); } private void pivotWideToLong() { PivotTableModel model = (PivotTableModel) jTable.getModel(); ListMultimap<String, String> columns = new PivotDialog(this).mapColumns(model); model.pivotWideToLong(columns.get("preserved"), columns.get("values")); } private void csv() { Integer cols = (Integer) spnColumns.getValue(); 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(); 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 = readFile(jfc.getSelectedFile()); txtInput.setText(data); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error", ex.getMessage(), JOptionPane.ERROR_MESSAGE); } } } private void save() { 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 (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) { writer.write(txtOutput.getText()); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE); } } } else { try (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) { writer.write(txtOutput.getText()); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error", e.getMessage(), JOptionPane.ERROR_MESSAGE); } } } } public String readFile(File file) throws Exception { StringBuilder fileContents; try (BufferedReader reader = new BufferedReader(new FileReader(file))) { @SuppressWarnings("UnusedAssignment") String line = null; fileContents = new StringBuilder(); while ((line = reader.readLine()) != null) { fileContents.append(line); fileContents.append(System.getProperty("line.separator")); } } return fileContents.toString(); } 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 btnCsvInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCsvInputActionPerformed csv(); }//GEN-LAST:event_btnCsvInputActionPerformed private void btnTsvInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTsvInputActionPerformed tsv(); }//GEN-LAST:event_btnTsvInputActionPerformed 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 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 private void btnPivotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPivotActionPerformed pivotWideToLong(); }//GEN-LAST:event_btnPivotActionPerformed private void txtRegexKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRegexKeyPressed // restore default color txtRegex.setBackground(defaultTextColor); }//GEN-LAST:event_txtRegexKeyPressed private void cbReplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbReplaceActionPerformed pnlReplace.setVisible(cbReplace.isSelected()); }//GEN-LAST:event_cbReplaceActionPerformed private void btnSwapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSwapActionPerformed txtInput.setText(txtOutput.getText()); }//GEN-LAST:event_btnSwapActionPerformed private void btnCsvOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCsvOutputActionPerformed String marker = txtMarker.getText(); Integer cols = (Integer) jTable.getColumnCount(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols; i++) { sb.append(marker).append(i + 1).append(","); } String format = sb.toString(); txtFormat.setText(format.substring(0, format.length() - 1)); format(); }//GEN-LAST:event_btnCsvOutputActionPerformed private void btnTsvOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTsvOutputActionPerformed String marker = txtMarker.getText(); Integer cols = (Integer) jTable.getColumnCount(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols; i++) { sb.append(marker).append(i + 1).append("\t"); } String format = sb.toString(); txtFormat.setText(format.substring(0, format.length() - 1)); format(); }//GEN-LAST:event_btnTsvOutputActionPerformed private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed save(); }//GEN-LAST:event_btnSaveActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) throws Exception { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); if (args.length > 0 && "dark".equalsIgnoreCase(args[0])) { 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() { @Override public void run() { new JRexFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnClear; private javax.swing.JButton btnCsvInput; private javax.swing.JButton btnCsvOutput; private javax.swing.JButton btnFormat; private javax.swing.JButton btnLoad; private javax.swing.JButton btnMatch; private javax.swing.JButton btnPivot; private javax.swing.JButton btnSave; private javax.swing.JButton btnSwap; private javax.swing.JButton btnTranspose; private javax.swing.JButton btnTsvInput; private javax.swing.JButton btnTsvOutput; private javax.swing.JCheckBox cbBlanks; private javax.swing.JCheckBox cbReplace; private javax.swing.JButton jButton1; private javax.swing.JTable jTable; private javax.swing.JLabel lblArgumentMarker; private javax.swing.JLabel lblExpression; private javax.swing.JLabel lblFormat; private javax.swing.JPanel pnlInput; private javax.swing.JPanel pnlOutput; private jrex.ReplacePanel pnlReplace; 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.JTextField txtMarker; private javax.swing.JTextArea txtOutput; private javax.swing.JTextField txtRegex; private javax.swing.JTextField txtReplace; // End of variables declaration//GEN-END:variables }
package jrex; import com.google.common.collect.ListMultimap; import java.awt.Color; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import javax.swing.Action; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import javax.swing.KeyStroke; import javax.swing.SpinnerNumberModel; import javax.swing.UIManager; import javax.swing.table.TableModel; import javax.swing.text.DefaultEditorKit; /** * * @author Mark George <mark.george@otago.ac.nz> */ public class JRexFrame extends javax.swing.JFrame { private final Color defaultTextColor; /** * Creates new form JRexFrame */ public JRexFrame() { initComponents(); splitPane.setResizeWeight(0.66); spnColumns.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1)); JPopupMenu rightClickMenu = new JPopupMenu(); Action cut = new DefaultEditorKit.CutAction(); cut.putValue(Action.NAME, "Cut"); cut.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control X")); rightClickMenu.add(cut); Action copy = new DefaultEditorKit.CopyAction(); copy.putValue(Action.NAME, "Copy"); copy.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control C")); rightClickMenu.add(copy); Action paste = new DefaultEditorKit.PasteAction(); paste.putValue(Action.NAME, "Paste"); paste.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control V")); rightClickMenu.add(paste); Action tab = new DefaultEditorKit.InsertTabAction(); tab.putValue(Action.NAME, "Insert Tab"); rightClickMenu.add(tab); txtInput.setComponentPopupMenu(rightClickMenu); txtOutput.setComponentPopupMenu(rightClickMenu); txtRegex.setComponentPopupMenu(rightClickMenu); txtFormat.setComponentPopupMenu(rightClickMenu); txtReplace.setComponentPopupMenu(rightClickMenu); defaultTextColor = txtRegex.getBackground(); pnlReplace.setVisible(false); pnlReplace.setComponents(txtInput, txtOutput); } /** * 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() { 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(); btnTsvInput = new javax.swing.JButton(); btnCsvInput = new javax.swing.JButton(); btnMatch = new javax.swing.JButton(); scrollTable = new javax.swing.JScrollPane(); jTable = new javax.swing.JTable(); cbReplace = new javax.swing.JCheckBox(); btnPivot = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); btnTranspose = 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(); lblArgumentMarker = new javax.swing.JLabel(); cbBlanks = new javax.swing.JCheckBox(); txtReplace = new javax.swing.JTextField(); btnSwap = new javax.swing.JButton(); btnCsvOutput = new javax.swing.JButton(); btnTsvOutput = new javax.swing.JButton(); txtMarker = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); pnlReplace = new jrex.ReplacePanel(); 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(null, "Input", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12))); // NOI18N pnlInput.setName("pnlInput"); // NOI18N btnClear.setIcon(UIManager.getIcon("FileView.fileIcon")); 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.setIcon(UIManager.getIcon("FileView.directoryIcon") ); btnLoad.setText("Open"); 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 txtRegex.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { txtRegexKeyPressed(evt); } }); spnColumns.setName("spnColumns"); // NOI18N spnColumns.addMouseWheelListener(new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { spnColumnsMouseWheelMoved(evt); } }); btnTsvInput.setText("TSV"); btnTsvInput.setName("btnTsvInput"); // NOI18N btnTsvInput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTsvInputActionPerformed(evt); } }); btnCsvInput.setText("CSV"); btnCsvInput.setName("btnCsvInput"); // NOI18N btnCsvInput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCsvInputActionPerformed(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); cbReplace.setText("Search/Replace "); cbReplace.setName("cbReplace"); // NOI18N cbReplace.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbReplaceActionPerformed(evt); } }); btnPivot.setText("Pivot Wide to Long"); btnPivot.setName("btnPivot"); // NOI18N btnPivot.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPivotActionPerformed(evt); } }); jButton1.setText("Pivot Long to Wide"); jButton1.setName("jButton1"); // NOI18N btnTranspose.setText("Transpose"); btnTranspose.setName("btnTranspose"); // NOI18N btnTranspose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTransposeActionPerformed(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() .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCsvInput) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTsvInput) .addGap(18, 18, 18) .addComponent(lblExpression) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtRegex) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnMatch)) .addComponent(scrollInput) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(btnLoad) .addGap(18, 18, 18) .addComponent(cbReplace) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnClear)) .addComponent(scrollTable, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 711, Short.MAX_VALUE) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(btnPivot) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTranspose) .addGap(0, 0, Short.MAX_VALUE)) ); pnlInputLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnPivot, btnTranspose, jButton1}); 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) .addComponent(cbReplace)) .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(btnTsvInput) .addComponent(btnCsvInput) .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnMatch)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollTable, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnPivot) .addComponent(jButton1) .addComponent(btnTranspose))) ); splitPane.setTopComponent(pnlInput); pnlOutput.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Output", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12))); // NOI18N 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); lblArgumentMarker.setText("Column Prefix: "); lblArgumentMarker.setName("lblArgumentMarker"); // NOI18N cbBlanks.setText("Replace blanks? "); cbBlanks.setName("cbBlanks"); // NOI18N txtReplace.setText("null"); txtReplace.setName("txtReplace"); // NOI18N btnSwap.setText("Output to Input"); btnSwap.setName("btnSwap"); // NOI18N btnSwap.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSwapActionPerformed(evt); } }); btnCsvOutput.setText("CSV"); btnCsvOutput.setName("btnCsvOutput"); // NOI18N btnCsvOutput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCsvOutputActionPerformed(evt); } }); btnTsvOutput.setText("TSV"); btnTsvOutput.setName("btnTsvOutput"); // NOI18N btnTsvOutput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTsvOutputActionPerformed(evt); } }); txtMarker.setText("?"); txtMarker.setName("txtMarker"); // NOI18N jButton2.setIcon(UIManager.getIcon("FileView.floppyDriveIcon")); jButton2.setText("Save"); jButton2.setName("jButton2"); // NOI18N javax.swing.GroupLayout pnlOutputLayout = new javax.swing.GroupLayout(pnlOutput); pnlOutput.setLayout(pnlOutputLayout); pnlOutputLayout.setHorizontalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollOutput) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblArgumentMarker) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtMarker, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(cbBlanks) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtReplace, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(btnCsvOutput) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTsvOutput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnSwap) .addGap(18, 18, 18) .addComponent(jButton2)) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtFormat) .addGap(18, 18, 18) .addComponent(btnFormat)) ); pnlOutputLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCsvOutput, btnTsvOutput}); pnlOutputLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtMarker, txtReplace}); pnlOutputLayout.setVerticalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblArgumentMarker) .addComponent(cbBlanks) .addComponent(txtReplace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnSwap) .addComponent(txtMarker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnCsvOutput) .addComponent(btnTsvOutput) .addComponent(jButton2)) .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.RELATED) .addComponent(scrollOutput, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)) ); splitPane.setRightComponent(pnlOutput); pnlReplace.setName("pnlReplace"); // NOI18N 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) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlReplace, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(pnlReplace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(splitPane)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void match() { txtOutput.setText(""); String regex = txtRegex.getText(); String text = txtInput.getText(); String[] input = null; try { Pattern pattern = Pattern.compile(regex); int flagsMask = pattern.flags(); StringBuilder flags = new StringBuilder(); boolean dotall = false; // work out which flags are being used if ((flagsMask & Pattern.DOTALL) == Pattern.DOTALL) { flags.append("DOTALL "); dotall = true; } if ((flagsMask & Pattern.MULTILINE) == Pattern.MULTILINE) { flags.append("MULTILINE "); } if ((flagsMask & Pattern.CASE_INSENSITIVE) == Pattern.CASE_INSENSITIVE) { flags.append("CASE_INSENSITIVE "); } PivotTableModel model = new PivotTableModel(); jTable.setModel(model); int numMatches = 0; // it DOTALL mode is on then grab the entire text rather then seperating by line if (dotall) { input = new String[1]; input[0] = text; } else { input = text.split("\n"); } for (String line : input) { Matcher matcher = pattern.matcher(line); while (matcher.find()) { // group() matches the entire line if there was a match. // This if-statment is to suppress extra empty groups from being // produced if the regex matches the entire line if (matcher.group().length() != line.length()) { continue; } numMatches++; 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); } } model.fireTableStructureChanged(); txtOutput.append("\nMatched " + numMatches + " line(s) out of " + input.length + " line(s) of input."); if (!flags.toString().isEmpty()) { txtOutput.append("\n\nFlags: " + flags.toString().trim()); } } catch (PatternSyntaxException ex) { txtOutput.setText(""); txtOutput.append(ex.getMessage()); txtRegex.setBackground(new Color(1f, 0.3f, 0.3f)); } } private void format() { String marker = txtMarker.getText(); txtOutput.setText(""); TableModel model = jTable.getModel(); String formatter = this.txtFormat.getText().replaceAll("\\" + marker + "(\\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() { PivotTableModel model = (PivotTableModel) jTable.getModel(); model.transpose(); } private void pivotWideToLong() { PivotTableModel model = (PivotTableModel) jTable.getModel(); ListMultimap<String, String> columns = new PivotDialog(this).mapColumns(model); model.pivotWideToLong(columns.get("preserved"), columns.get("values")); } private void csv() { Integer cols = (Integer) spnColumns.getValue(); 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(); 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 = readFile(jfc.getSelectedFile()); txtInput.setText(data); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error", ex.getMessage(), JOptionPane.ERROR_MESSAGE); } } } public String readFile(File file) throws Exception { StringBuilder fileContents; try (BufferedReader reader = new BufferedReader(new FileReader(file))) { @SuppressWarnings("UnusedAssignment") String line = null; fileContents = new StringBuilder(); while ((line = reader.readLine()) != null) { fileContents.append(line); fileContents.append(System.getProperty("line.separator")); } } return fileContents.toString(); } 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 btnCsvInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCsvInputActionPerformed csv(); }//GEN-LAST:event_btnCsvInputActionPerformed private void btnTsvInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTsvInputActionPerformed tsv(); }//GEN-LAST:event_btnTsvInputActionPerformed 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 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 private void btnPivotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPivotActionPerformed pivotWideToLong(); }//GEN-LAST:event_btnPivotActionPerformed private void txtRegexKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRegexKeyPressed // restore default color txtRegex.setBackground(defaultTextColor); }//GEN-LAST:event_txtRegexKeyPressed private void cbReplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbReplaceActionPerformed pnlReplace.setVisible(cbReplace.isSelected()); }//GEN-LAST:event_cbReplaceActionPerformed private void btnSwapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSwapActionPerformed txtInput.setText(txtOutput.getText()); }//GEN-LAST:event_btnSwapActionPerformed private void btnCsvOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCsvOutputActionPerformed String marker = txtMarker.getText(); Integer cols = (Integer) jTable.getColumnCount(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols; i++) { sb.append(marker).append(i + 1).append(","); } String format = sb.toString(); txtFormat.setText(format.substring(0, format.length() - 1)); format(); }//GEN-LAST:event_btnCsvOutputActionPerformed private void btnTsvOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTsvOutputActionPerformed String marker = txtMarker.getText(); Integer cols = (Integer) jTable.getColumnCount(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < cols; i++) { sb.append(marker).append(i + 1).append("\t"); } String format = sb.toString(); txtFormat.setText(format.substring(0, format.length() - 1)); format(); }//GEN-LAST:event_btnTsvOutputActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) throws Exception { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); if (args.length > 0 && "dark".equalsIgnoreCase(args[0])) { 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() { @Override public void run() { new JRexFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnClear; private javax.swing.JButton btnCsvInput; private javax.swing.JButton btnCsvOutput; private javax.swing.JButton btnFormat; private javax.swing.JButton btnLoad; private javax.swing.JButton btnMatch; private javax.swing.JButton btnPivot; private javax.swing.JButton btnSwap; private javax.swing.JButton btnTranspose; private javax.swing.JButton btnTsvInput; private javax.swing.JButton btnTsvOutput; private javax.swing.JCheckBox cbBlanks; private javax.swing.JCheckBox cbReplace; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JTable jTable; private javax.swing.JLabel lblArgumentMarker; private javax.swing.JLabel lblExpression; private javax.swing.JLabel lblFormat; private javax.swing.JPanel pnlInput; private javax.swing.JPanel pnlOutput; private jrex.ReplacePanel pnlReplace; 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.JTextField txtMarker; 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/jrex/ReplacePanel.java
package jrex; import com.google.common.collect.Table; import java.util.Arrays; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JTextArea; /** * @author Mark George */ public class ReplacePanel extends javax.swing.JPanel { private final MutableTableModel model = new MutableTableModel(Arrays.asList("Search", "Replace")); private JTextArea txtInput; private JTextArea txtOutput; public ReplacePanel() { initComponents(); tblExpressions.setModel(model); model.addRow(new String[]{"", ""}); model.fireTableStructureChanged(); tblExpressions.setShowGrid(true); tblExpressions.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); } public void setComponents(JTextArea input, JTextArea output) { this.txtInput = input; this.txtOutput = output; } /** * 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() { scrlTable = new javax.swing.JScrollPane(); tblExpressions = new javax.swing.JTable(); btnAddRow = new javax.swing.JButton(); btnReplace = new javax.swing.JButton(); btnUp = new javax.swing.JButton(); btnDown = new javax.swing.JButton(); btnDelete = new javax.swing.JButton(); setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search/Replace", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12))); // NOI18N scrlTable.setAlignmentY(0.0F); scrlTable.setName("scrlTable"); // NOI18N tblExpressions.setFillsViewportHeight(true); tblExpressions.setName("tblExpressions"); // NOI18N tblExpressions.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); scrlTable.setViewportView(tblExpressions); btnAddRow.setText("Add Row"); btnAddRow.setName("btnAddRow"); // NOI18N btnAddRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddRowActionPerformed(evt); } }); btnReplace.setText("Replace"); btnReplace.setName("btnReplace"); // NOI18N btnReplace.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnReplaceActionPerformed(evt); } }); btnUp.setText("Move Up"); btnUp.setName("btnUp"); // NOI18N btnUp.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnUpActionPerformed(evt); } }); btnDown.setText("Move Down"); btnDown.setName("btnDown"); // NOI18N btnDown.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDownActionPerformed(evt); } }); btnDelete.setText("Delete Row"); btnDelete.setName("btnDelete"); // NOI18N btnDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDeleteActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnReplace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(scrlTable, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(btnAddRow, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) .addComponent(btnUp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnDown, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(scrlTable, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnAddRow) .addComponent(btnDelete)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnUp) .addComponent(btnDown)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnReplace)) ); }// </editor-fold>//GEN-END:initComponents private void btnAddRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddRowActionPerformed model.addRow(new String[]{"", ""}); }//GEN-LAST:event_btnAddRowActionPerformed private void btnReplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReplaceActionPerformed String data = txtInput.getText(); Table<Integer, Integer, String> table = model.getTable(); for (Map<Integer, String> row : table.rowMap().values()) { if (!row.get(0).isEmpty()) { String search = row.get(0); String replace = row.get(1); data = performReplace(data, search, replace); } } txtOutput.setText(data); }//GEN-LAST:event_btnReplaceActionPerformed private void btnUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpActionPerformed int row = tblExpressions.getSelectedRow(); if (row > 0) { model.moveUp(row); tblExpressions.setRowSelectionInterval(row - 1, row - 1); } }//GEN-LAST:event_btnUpActionPerformed private void btnDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownActionPerformed int row = tblExpressions.getSelectedRow(); if (row < model.getRowCount() - 1) { model.moveDown(row); tblExpressions.setRowSelectionInterval(row + 1, row + 1); } }//GEN-LAST:event_btnDownActionPerformed private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed int row = tblExpressions.getSelectedRow(); if (row >= 0) { model.deleteRow(row); if (model.getRowCount() > 0) { if (row < model.getRowCount() - 1) { tblExpressions.setRowSelectionInterval(row, row); } else { tblExpressions.setRowSelectionInterval(model.getRowCount() - 1, model.getRowCount() - 1); } } } }//GEN-LAST:event_btnDeleteActionPerformed public String performReplace(String input, String search, String replace) { try { Pattern pattern = Pattern.compile(search, Pattern.MULTILINE + Pattern.DOTALL + Pattern.COMMENTS); Matcher matcher = pattern.matcher(input); return matcher.replaceAll(replace); } catch (Exception ex) { return ex.getMessage(); } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAddRow; private javax.swing.JButton btnDelete; private javax.swing.JButton btnDown; private javax.swing.JButton btnReplace; private javax.swing.JButton btnUp; private javax.swing.JScrollPane scrlTable; private javax.swing.JTable tblExpressions; // End of variables declaration//GEN-END:variables }
package jrex; import com.google.common.collect.Table; import java.util.Arrays; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JTextArea; /** * @author Mark George */ public class ReplacePanel extends javax.swing.JPanel { private final MutableTableModel model = new MutableTableModel(Arrays.asList("Search", "Replace")); private JTextArea txtInput; private JTextArea txtOutput; public ReplacePanel() { initComponents(); tblExpressions.setModel(model); model.addRow(new String[]{"", ""}); model.fireTableStructureChanged(); tblExpressions.setShowGrid(true); } public void setComponents(JTextArea input, JTextArea output) { this.txtInput = input; this.txtOutput = output; } /** * 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() { scrlTable = new javax.swing.JScrollPane(); tblExpressions = new javax.swing.JTable(); btnAddRow = new javax.swing.JButton(); btnReplace = new javax.swing.JButton(); btnUp = new javax.swing.JButton(); btnDown = new javax.swing.JButton(); btnDelete = new javax.swing.JButton(); setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search/Replace", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12))); // NOI18N scrlTable.setAlignmentY(0.0F); scrlTable.setName("scrlTable"); // NOI18N tblExpressions.setFillsViewportHeight(true); tblExpressions.setName("tblExpressions"); // NOI18N tblExpressions.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); scrlTable.setViewportView(tblExpressions); btnAddRow.setText("Add Row"); btnAddRow.setName("btnAddRow"); // NOI18N btnAddRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddRowActionPerformed(evt); } }); btnReplace.setText("Replace"); btnReplace.setName("btnReplace"); // NOI18N btnReplace.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnReplaceActionPerformed(evt); } }); btnUp.setText("Move Up"); btnUp.setName("btnUp"); // NOI18N btnUp.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnUpActionPerformed(evt); } }); btnDown.setText("Move Down"); btnDown.setName("btnDown"); // NOI18N btnDown.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDownActionPerformed(evt); } }); btnDelete.setText("Delete Row"); btnDelete.setName("btnDelete"); // NOI18N btnDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDeleteActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnReplace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(scrlTable, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(btnAddRow, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) .addComponent(btnUp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnDown, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(scrlTable, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnAddRow) .addComponent(btnDelete)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnUp) .addComponent(btnDown)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnReplace)) ); }// </editor-fold>//GEN-END:initComponents private void btnAddRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddRowActionPerformed model.addRow(new String[]{"", ""}); }//GEN-LAST:event_btnAddRowActionPerformed private void btnReplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReplaceActionPerformed String data = txtInput.getText(); Table<Integer, Integer, String> table = model.getTable(); for (Map<Integer, String> row : table.rowMap().values()) { if (!row.get(0).isEmpty()) { String search = row.get(0); String replace = row.get(1); data = performReplace(data, search, replace); } } txtOutput.setText(data); }//GEN-LAST:event_btnReplaceActionPerformed private void btnUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpActionPerformed int row = tblExpressions.getSelectedRow(); if (row > 0) { model.moveUp(row); tblExpressions.setRowSelectionInterval(row - 1, row - 1); } }//GEN-LAST:event_btnUpActionPerformed private void btnDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownActionPerformed int row = tblExpressions.getSelectedRow(); if (row < model.getRowCount() - 1) { model.moveDown(row); tblExpressions.setRowSelectionInterval(row + 1, row + 1); } }//GEN-LAST:event_btnDownActionPerformed private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed int row = tblExpressions.getSelectedRow(); if (row >= 0) { model.deleteRow(row); if (model.getRowCount() > 0) { if (row < model.getRowCount() - 1) { tblExpressions.setRowSelectionInterval(row, row); } else { tblExpressions.setRowSelectionInterval(model.getRowCount() - 1, model.getRowCount() - 1); } } } }//GEN-LAST:event_btnDeleteActionPerformed public String performReplace(String input, String search, String replace) { try { Pattern pattern = Pattern.compile(search, Pattern.MULTILINE + Pattern.DOTALL + Pattern.COMMENTS); Matcher matcher = pattern.matcher(input); return matcher.replaceAll(replace); } catch (Exception ex) { return ex.getMessage(); } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAddRow; private javax.swing.JButton btnDelete; private javax.swing.JButton btnDown; private javax.swing.JButton btnReplace; private javax.swing.JButton btnUp; private javax.swing.JScrollPane scrlTable; private javax.swing.JTable tblExpressions; // End of variables declaration//GEN-END:variables }
Show line notes below