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
Created table model backed by Guava table.
master
1 parent
5d6712a
commit
d10605a83e4d784ffe1730d9aefb6d559585cb11
Mark George
authored
on 25 Aug 2017
Patch
Showing
3 changed files
src/JRexFrame.form
src/JRexFrame.java
src/PivotTableModel.java
Ignore Space
Show notes
View
src/JRexFrame.form
<?xml version="1.0" encoding="UTF-8" ?> <Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <NonVisualComponents> <Component class="javax.swing.ButtonGroup" name="expGrp"> </Component> </NonVisualComponents> <Properties> <Property name="defaultCloseOperation" type="int" value="3"/> </Properties> <SyntheticProperties> <SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="generateCenter" type="boolean" value="false"/> </SyntheticProperties> <AuxValues> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/> <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> </AuxValues> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Container class="javax.swing.JSplitPane" name="splitPane"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="null"/> </Property> <Property name="dividerLocation" type="int" value="366"/> <Property name="dividerSize" type="int" value="15"/> <Property name="orientation" type="int" value="0"/> <Property name="name" type="java.lang.String" value="splitPane" noResource="true"/> <Property name="oneTouchExpandable" type="boolean" value="true"/> </Properties> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/> <SubComponents> <Container class="javax.swing.JPanel" name="pnlInput"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> <TitledBorder title="Input"/> </Border> </Property> <Property name="name" type="java.lang.String" value="pnlInput" noResource="true"/> </Properties> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription"> <JSplitPaneConstraints position="top"/> </Constraint> </Constraints> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="1" attributes="0"> <Component id="scrollTable" alignment="0" pref="566" max="32767" attributes="0"/> <Component id="scrollInput" alignment="0" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="spnColumns" min="-2" pref="46" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnCSV" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTSV" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="lblExpression" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtRegex" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnMatch" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" attributes="0"> <EmptySpace min="0" pref="0" max="32767" attributes="0"/> <Group type="103" groupAlignment="1" 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="btnClear" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" alignment="1" attributes="0"> <Component id="btnLiteralise" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnPivot" min="-2" pref="73" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/> <Component id="btnTranspose" min="-2" pref="103" max="-2" attributes="0"/> </Group> </Group> </Group> </Group> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnLoad" alignment="3" max="32767" attributes="0"/> <Component id="btnClear" alignment="3" max="32767" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> <Component id="scrollInput" pref="100" max="32767" attributes="0"/> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="txtRegex" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lblExpression" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTSV" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCSV" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="spnColumns" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnMatch" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Component id="scrollTable" pref="101" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnTranspose" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnLiteralise" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnPivot" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JButton" name="btnClear"> <Properties> <Property name="text" type="java.lang.String" value="Clear"/> <Property name="name" type="java.lang.String" value="btnClear" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClearActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnLoad"> <Properties> <Property name="text" type="java.lang.String" value="Load"/> <Property name="name" type="java.lang.String" value="btnLoad" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLoadActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollInput"> <Properties> <Property name="name" type="java.lang.String" value="scrollInput" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTextArea" name="txtInput"> <Properties> <Property name="columns" type="int" value="20"/> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="rows" type="int" value="5"/> <Property name="name" type="java.lang.String" value="txtInput" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JLabel" name="lblExpression"> <Properties> <Property name="horizontalAlignment" type="int" value="4"/> <Property name="text" type="java.lang.String" value="Expression:"/> <Property name="name" type="java.lang.String" value="lblExpression" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtRegex"> <Properties> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="name" type="java.lang.String" value="txtRegex" noResource="true"/> </Properties> <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="btnTSV"> <Properties> <Property name="text" type="java.lang.String" value="TSV"/> <Property name="name" type="java.lang.String" value="btnTSV" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTSVActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnCSV"> <Properties> <Property name="text" type="java.lang.String" value="CSV"/> <Property name="name" type="java.lang.String" value="btnCSV" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCSVActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnMatch"> <Properties> <Property name="text" type="java.lang.String" value="Apply"/> <Property name="name" type="java.lang.String" value="btnMatch" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMatchActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollTable"> <Properties> <Property name="name" type="java.lang.String" value="scrollTable" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTable" name="jTable"> <Properties> <Property name="name" type="java.lang.String" value="jTable" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JButton" name="btnTranspose"> <Properties> <Property name="text" type="java.lang.String" value="Transpose"/> <Property name="name" type="java.lang.String" value="btnTranspose" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTransposeActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnLiteralise"> <Properties> <Property name="text" type="java.lang.String" value="Literalise Expression"/> <Property name="name" type="java.lang.String" value="btnLiteralise" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLiteraliseActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnPivot"> <Properties> <Property name="text" type="java.lang.String" value="Pivot"/> <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> </SubComponents> </Container> <Container class="javax.swing.JPanel" name="pnlOutput"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> <TitledBorder title="Output"/> </Border> </Property> <Property name="name" type="java.lang.String" value="pnlOutput" noResource="true"/> </Properties> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription"> <JSplitPaneConstraints position="right"/> </Constraint> </Constraints> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Component id="scrollOutput" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="lblArgumentMarker" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoQuestion" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoDollar" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoSlash" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="cbBlanks" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtReplace" pref="177" max="32767" attributes="0"/> </Group> <Group type="102" alignment="0" attributes="0"> <Component id="lblFormat" min="-2" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/> <Component id="txtFormat" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnFormat" min="-2" max="-2" attributes="0"/> </Group> </Group> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="3" attributes="0"> <Component id="rdoQuestion" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="rdoDollar" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="rdoSlash" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="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"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="lblFormat" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txtFormat" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnFormat" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Component id="scrollOutput" pref="102" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JLabel" name="lblFormat"> <Properties> <Property name="horizontalAlignment" type="int" value="4"/> <Property name="text" type="java.lang.String" value="Format:"/> <Property name="name" type="java.lang.String" value="lblFormat" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtFormat"> <Properties> <Property name="name" type="java.lang.String" value="txtFormat" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JButton" name="btnFormat"> <Properties> <Property name="text" type="java.lang.String" value="Apply"/> <Property name="name" type="java.lang.String" value="btnFormat" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnFormatActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollOutput"> <Properties> <Property name="name" type="java.lang.String" value="scrollOutput" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTextArea" name="txtOutput"> <Properties> <Property name="columns" type="int" value="20"/> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="rows" type="int" value="5"/> <Property name="name" type="java.lang.String" value="txtOutput" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JRadioButton" name="rdoQuestion"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="selected" type="boolean" value="true"/> <Property name="text" type="java.lang.String" value="?"/> <Property name="name" type="java.lang.String" value="rdoQuestion" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoQuestionActionPerformed"/> </Events> </Component> <Component class="javax.swing.JRadioButton" name="rdoDollar"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="text" type="java.lang.String" value="$"/> <Property name="name" type="java.lang.String" value="rdoDollar" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoDollarActionPerformed"/> </Events> </Component> <Component class="javax.swing.JRadioButton" name="rdoSlash"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="text" type="java.lang.String" value="\u005c" containsInvalidXMLChars="true"/> <Property name="name" type="java.lang.String" value="rdoSlash" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoSlashActionPerformed"/> </Events> </Component> <Component class="javax.swing.JLabel" name="lblArgumentMarker"> <Properties> <Property name="text" type="java.lang.String" value="Argument Marker:"/> <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> </SubComponents> </Container> </SubComponents> </Container> </SubComponents> </Form>
<?xml version="1.0" encoding="UTF-8" ?> <Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <NonVisualComponents> <Component class="javax.swing.ButtonGroup" name="expGrp"> </Component> <Component class="javax.swing.ButtonGroup" name="btnGrpTheme"> </Component> </NonVisualComponents> <Properties> <Property name="defaultCloseOperation" type="int" value="3"/> </Properties> <SyntheticProperties> <SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="generateCenter" type="boolean" value="false"/> </SyntheticProperties> <AuxValues> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/> <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> </AuxValues> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Component id="splitPane" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Container class="javax.swing.JSplitPane" name="splitPane"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="null"/> </Property> <Property name="dividerLocation" type="int" value="366"/> <Property name="dividerSize" type="int" value="15"/> <Property name="orientation" type="int" value="0"/> <Property name="name" type="java.lang.String" value="splitPane" noResource="true"/> <Property name="oneTouchExpandable" type="boolean" value="true"/> </Properties> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/> <SubComponents> <Container class="javax.swing.JPanel" name="pnlInput"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> <TitledBorder title="Input"/> </Border> </Property> <Property name="name" type="java.lang.String" value="pnlInput" noResource="true"/> </Properties> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription"> <JSplitPaneConstraints position="top"/> </Constraint> </Constraints> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Component id="scrollTable" pref="566" max="32767" attributes="0"/> <Component id="scrollInput" alignment="0" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="spnColumns" min="-2" pref="46" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnCSV" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnTSV" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="lblExpression" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtRegex" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnMatch" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" alignment="1" attributes="0"> <EmptySpace min="0" pref="0" max="32767" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="1" attributes="0"> <Component id="jButton1" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnTranspose" min="-2" max="-2" attributes="0"/> </Group> <Group type="102" alignment="1" attributes="0"> <Component id="btnLoad" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="btnClear" min="-2" max="-2" attributes="0"/> </Group> </Group> </Group> </Group> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnLoad" alignment="3" max="32767" attributes="0"/> <Component id="btnClear" alignment="3" max="32767" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> <Component id="scrollInput" pref="100" max="32767" attributes="0"/> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="txtRegex" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lblExpression" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTSV" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnCSV" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="spnColumns" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnMatch" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Component id="scrollTable" pref="101" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="btnTranspose" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JButton" name="btnClear"> <Properties> <Property name="text" type="java.lang.String" value="Clear"/> <Property name="name" type="java.lang.String" value="btnClear" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClearActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnLoad"> <Properties> <Property name="text" type="java.lang.String" value="Load"/> <Property name="name" type="java.lang.String" value="btnLoad" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLoadActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollInput"> <Properties> <Property name="name" type="java.lang.String" value="scrollInput" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTextArea" name="txtInput"> <Properties> <Property name="columns" type="int" value="20"/> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="rows" type="int" value="5"/> <Property name="name" type="java.lang.String" value="txtInput" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JLabel" name="lblExpression"> <Properties> <Property name="horizontalAlignment" type="int" value="4"/> <Property name="text" type="java.lang.String" value="Expression:"/> <Property name="name" type="java.lang.String" value="lblExpression" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtRegex"> <Properties> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="name" type="java.lang.String" value="txtRegex" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JSpinner" name="spnColumns"> <Properties> <Property name="name" type="java.lang.String" value="spnColumns" noResource="true"/> </Properties> <Events> <EventHandler event="mouseWheelMoved" listener="java.awt.event.MouseWheelListener" parameters="java.awt.event.MouseWheelEvent" handler="spnColumnsMouseWheelMoved"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnTSV"> <Properties> <Property name="text" type="java.lang.String" value="TSV"/> <Property name="name" type="java.lang.String" value="btnTSV" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTSVActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnCSV"> <Properties> <Property name="text" type="java.lang.String" value="CSV"/> <Property name="name" type="java.lang.String" value="btnCSV" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCSVActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="btnMatch"> <Properties> <Property name="text" type="java.lang.String" value="Apply"/> <Property name="name" type="java.lang.String" value="btnMatch" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMatchActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollTable"> <Properties> <Property name="name" type="java.lang.String" value="scrollTable" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTable" name="jTable"> <Properties> <Property name="name" type="java.lang.String" value="jTable" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JButton" name="btnTranspose"> <Properties> <Property name="text" type="java.lang.String" value="Transpose"/> <Property name="name" type="java.lang.String" value="btnTranspose" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTransposeActionPerformed"/> </Events> </Component> <Component class="javax.swing.JButton" name="jButton1"> <Properties> <Property name="text" type="java.lang.String" value="Literalise Expression"/> <Property name="name" type="java.lang.String" value="jButton1" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/> </Events> </Component> </SubComponents> </Container> <Container class="javax.swing.JPanel" name="pnlOutput"> <Properties> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo"> <TitledBorder title="Output"/> </Border> </Property> <Property name="name" type="java.lang.String" value="pnlOutput" noResource="true"/> </Properties> <Constraints> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription"> <JSplitPaneConstraints position="right"/> </Constraint> </Constraints> <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Component id="scrollOutput" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Component id="jLabel1" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoQuestion" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoDollar" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="rdoSlash" min="-2" max="-2" attributes="0"/> <EmptySpace type="separate" max="-2" attributes="0"/> <Component id="cbBlanks" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="txtReplace" pref="177" max="32767" attributes="0"/> </Group> <Group type="102" alignment="0" attributes="0"> <Component id="lblFormat" min="-2" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/> <Component id="txtFormat" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="btnFormat" min="-2" max="-2" attributes="0"/> </Group> </Group> <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="3" attributes="0"> <Component id="rdoQuestion" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="rdoDollar" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="rdoSlash" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="cbBlanks" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txtReplace" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> <Component id="lblFormat" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="txtFormat" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnFormat" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <Component id="scrollOutput" pref="102" max="32767" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> </Layout> <SubComponents> <Component class="javax.swing.JLabel" name="lblFormat"> <Properties> <Property name="horizontalAlignment" type="int" value="4"/> <Property name="text" type="java.lang.String" value="Format:"/> <Property name="name" type="java.lang.String" value="lblFormat" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtFormat"> <Properties> <Property name="name" type="java.lang.String" value="txtFormat" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JButton" name="btnFormat"> <Properties> <Property name="text" type="java.lang.String" value="Apply"/> <Property name="name" type="java.lang.String" value="btnFormat" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnFormatActionPerformed"/> </Events> </Component> <Container class="javax.swing.JScrollPane" name="scrollOutput"> <Properties> <Property name="name" type="java.lang.String" value="scrollOutput" noResource="true"/> </Properties> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <SubComponents> <Component class="javax.swing.JTextArea" name="txtOutput"> <Properties> <Property name="columns" type="int" value="20"/> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Font name="Monospaced" size="12" style="0"/> </Property> <Property name="rows" type="int" value="5"/> <Property name="name" type="java.lang.String" value="txtOutput" noResource="true"/> </Properties> </Component> </SubComponents> </Container> <Component class="javax.swing.JRadioButton" name="rdoQuestion"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="selected" type="boolean" value="true"/> <Property name="text" type="java.lang.String" value="?"/> <Property name="name" type="java.lang.String" value="rdoQuestion" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoQuestionActionPerformed"/> </Events> </Component> <Component class="javax.swing.JRadioButton" name="rdoDollar"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="text" type="java.lang.String" value="$"/> <Property name="name" type="java.lang.String" value="rdoDollar" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoDollarActionPerformed"/> </Events> </Component> <Component class="javax.swing.JRadioButton" name="rdoSlash"> <Properties> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <ComponentRef name="expGrp"/> </Property> <Property name="text" type="java.lang.String" value="\u005c" containsInvalidXMLChars="true"/> <Property name="name" type="java.lang.String" value="rdoSlash" noResource="true"/> </Properties> <Events> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rdoSlashActionPerformed"/> </Events> </Component> <Component class="javax.swing.JLabel" name="jLabel1"> <Properties> <Property name="text" type="java.lang.String" value="Argument Marker:"/> <Property name="name" type="java.lang.String" value="jLabel1" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JCheckBox" name="cbBlanks"> <Properties> <Property name="text" type="java.lang.String" value="Replace blanks?"/> <Property name="name" type="java.lang.String" value="cbBlanks" noResource="true"/> </Properties> </Component> <Component class="javax.swing.JTextField" name="txtReplace"> <Properties> <Property name="text" type="java.lang.String" value="null"/> <Property name="name" type="java.lang.String" value="txtReplace" noResource="true"/> </Properties> </Component> </SubComponents> </Container> </SubComponents> </Container> </SubComponents> </Form>
Ignore Space
Show notes
View
src/JRexFrame.java
import com.google.common.collect.Table; import com.google.common.collect.Tables; import java.awt.Color; 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 String exprChar = "?"; private 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(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { expGrp = new javax.swing.ButtonGroup(); splitPane = new javax.swing.JSplitPane(); pnlInput = new javax.swing.JPanel(); btnClear = new javax.swing.JButton(); btnLoad = new javax.swing.JButton(); scrollInput = new javax.swing.JScrollPane(); txtInput = new javax.swing.JTextArea(); lblExpression = new javax.swing.JLabel(); txtRegex = new javax.swing.JTextField(); spnColumns = new javax.swing.JSpinner(); btnTSV = new javax.swing.JButton(); btnCSV = new javax.swing.JButton(); btnMatch = new javax.swing.JButton(); scrollTable = new javax.swing.JScrollPane(); jTable = new javax.swing.JTable(); btnTranspose = new javax.swing.JButton(); btnLiteralise = new javax.swing.JButton(); btnPivot = new javax.swing.JButton(); pnlOutput = new javax.swing.JPanel(); lblFormat = new javax.swing.JLabel(); txtFormat = new javax.swing.JTextField(); btnFormat = new javax.swing.JButton(); scrollOutput = new javax.swing.JScrollPane(); txtOutput = new javax.swing.JTextArea(); rdoQuestion = new javax.swing.JRadioButton(); rdoDollar = new javax.swing.JRadioButton(); rdoSlash = new javax.swing.JRadioButton(); lblArgumentMarker = new javax.swing.JLabel(); cbBlanks = new javax.swing.JCheckBox(); txtReplace = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); splitPane.setBorder(null); splitPane.setDividerLocation(366); splitPane.setDividerSize(15); splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); splitPane.setName("splitPane"); // NOI18N splitPane.setOneTouchExpandable(true); pnlInput.setBorder(javax.swing.BorderFactory.createTitledBorder("Input")); pnlInput.setName("pnlInput"); // NOI18N btnClear.setText("Clear"); btnClear.setName("btnClear"); // NOI18N btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } }); btnLoad.setText("Load"); btnLoad.setName("btnLoad"); // NOI18N btnLoad.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLoadActionPerformed(evt); } }); scrollInput.setName("scrollInput"); // NOI18N txtInput.setColumns(20); txtInput.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtInput.setRows(5); txtInput.setName("txtInput"); // NOI18N scrollInput.setViewportView(txtInput); lblExpression.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblExpression.setText("Expression:"); lblExpression.setName("lblExpression"); // NOI18N txtRegex.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtRegex.setName("txtRegex"); // NOI18N 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); } }); btnTSV.setText("TSV"); btnTSV.setName("btnTSV"); // NOI18N btnTSV.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTSVActionPerformed(evt); } }); btnCSV.setText("CSV"); btnCSV.setName("btnCSV"); // NOI18N btnCSV.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCSVActionPerformed(evt); } }); btnMatch.setText("Apply"); btnMatch.setName("btnMatch"); // NOI18N btnMatch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMatchActionPerformed(evt); } }); scrollTable.setName("scrollTable"); // NOI18N jTable.setName("jTable"); // NOI18N scrollTable.setViewportView(jTable); btnTranspose.setText("Transpose"); btnTranspose.setName("btnTranspose"); // NOI18N btnTranspose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTransposeActionPerformed(evt); } }); btnLiteralise.setText("Literalise Expression"); btnLiteralise.setName("btnLiteralise"); // NOI18N btnLiteralise.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLiteraliseActionPerformed(evt); } }); btnPivot.setText("Pivot"); btnPivot.setName("btnPivot"); // NOI18N btnPivot.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPivotActionPerformed(evt); } }); javax.swing.GroupLayout pnlInputLayout = new javax.swing.GroupLayout(pnlInput); pnlInput.setLayout(pnlInputLayout); pnlInputLayout.setHorizontalGroup( pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlInputLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(scrollTable, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE) .addComponent(scrollInput, javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlInputLayout.createSequentialGroup() .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCSV) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTSV) .addGap(18, 18, 18) .addComponent(lblExpression) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtRegex) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnMatch)) .addGroup(pnlInputLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(btnLoad) .addGap(18, 18, 18) .addComponent(btnClear)) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(btnLiteralise) .addGap(18, 18, 18) .addComponent(btnPivot, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnTranspose, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addContainerGap()) ); pnlInputLayout.setVerticalGroup( pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlInputLayout.createSequentialGroup() .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnLoad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnClear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollInput, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtRegex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblExpression) .addComponent(btnTSV) .addComponent(btnCSV) .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnMatch)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(scrollTable, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnTranspose) .addComponent(btnLiteralise) .addComponent(btnPivot)) .addContainerGap()) ); splitPane.setTopComponent(pnlInput); pnlOutput.setBorder(javax.swing.BorderFactory.createTitledBorder("Output")); pnlOutput.setName("pnlOutput"); // NOI18N lblFormat.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblFormat.setText("Format:"); lblFormat.setName("lblFormat"); // NOI18N txtFormat.setName("txtFormat"); // NOI18N btnFormat.setText("Apply"); btnFormat.setName("btnFormat"); // NOI18N btnFormat.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFormatActionPerformed(evt); } }); scrollOutput.setName("scrollOutput"); // NOI18N txtOutput.setColumns(20); txtOutput.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtOutput.setRows(5); txtOutput.setName("txtOutput"); // NOI18N scrollOutput.setViewportView(txtOutput); expGrp.add(rdoQuestion); rdoQuestion.setSelected(true); rdoQuestion.setText("?"); rdoQuestion.setName("rdoQuestion"); // NOI18N rdoQuestion.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoQuestionActionPerformed(evt); } }); expGrp.add(rdoDollar); rdoDollar.setText("$"); rdoDollar.setName("rdoDollar"); // NOI18N rdoDollar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoDollarActionPerformed(evt); } }); expGrp.add(rdoSlash); rdoSlash.setText("\\"); rdoSlash.setName("rdoSlash"); // NOI18N rdoSlash.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoSlashActionPerformed(evt); } }); lblArgumentMarker.setText("Argument Marker:"); lblArgumentMarker.setName("lblArgumentMarker"); // NOI18N cbBlanks.setText("Replace blanks?"); cbBlanks.setName("cbBlanks"); // NOI18N txtReplace.setText("null"); txtReplace.setName("txtReplace"); // NOI18N javax.swing.GroupLayout pnlOutputLayout = new javax.swing.GroupLayout(pnlOutput); pnlOutput.setLayout(pnlOutputLayout); pnlOutputLayout.setHorizontalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollOutput) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblArgumentMarker) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoQuestion) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoDollar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoSlash) .addGap(18, 18, 18) .addComponent(cbBlanks) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtReplace, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnFormat))) .addContainerGap()) ); pnlOutputLayout.setVerticalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(rdoQuestion) .addComponent(rdoDollar) .addComponent(rdoSlash) .addComponent(lblArgumentMarker) .addComponent(cbBlanks) .addComponent(txtReplace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblFormat) .addComponent(txtFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnFormat)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(scrollOutput, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE) .addContainerGap()) ); splitPane.setRightComponent(pnlOutput); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(splitPane) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(splitPane) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void match() { 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() { txtOutput.setText(""); TableModel model = jTable.getModel(); String formatter = this.txtFormat.getText().replaceAll("\\" + exprChar + "(\\d*)", "%$1\\$s"); for (int row = 0; row < model.getRowCount(); row++) { Object[] values = new Object[model.getColumnCount()]; for (int col = 0; col < model.getColumnCount(); col++) { String val = (String) model.getValueAt(row, col); if (cbBlanks.isSelected() && val.isEmpty()) { val = txtReplace.getText(); } values[col] = val; } String formatted = String.format(formatter, values); txtOutput.append(formatted + "\n"); } } private void transpose() { PivotTableModel model = (PivotTableModel) jTable.getModel(); model.transpose(); } private void pivot() { new PivotDialog(this).setVisible(true); } 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 = JSedUtils.readFile(jfc.getSelectedFile()); txtInput.setText(data); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error", ex.getMessage(), JOptionPane.ERROR_MESSAGE); } } } private void btnFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormatActionPerformed format(); }//GEN-LAST:event_btnFormatActionPerformed private void btnTransposeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTransposeActionPerformed transpose(); }//GEN-LAST:event_btnTransposeActionPerformed private void btnMatchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMatchActionPerformed match(); }//GEN-LAST:event_btnMatchActionPerformed private void btnCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCSVActionPerformed csv(); }//GEN-LAST:event_btnCSVActionPerformed private void btnTSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTSVActionPerformed tsv(); }//GEN-LAST:event_btnTSVActionPerformed private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed load(); }//GEN-LAST:event_btnLoadActionPerformed private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed txtInput.setText(""); }//GEN-LAST:event_btnClearActionPerformed private void rdoQuestionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoQuestionActionPerformed exprChar = "?"; }//GEN-LAST:event_rdoQuestionActionPerformed private void rdoDollarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoDollarActionPerformed exprChar = "$"; }//GEN-LAST:event_rdoDollarActionPerformed private void rdoSlashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoSlashActionPerformed exprChar = "\\"; }//GEN-LAST:event_rdoSlashActionPerformed private void btnLiteraliseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLiteraliseActionPerformed txtOutput.setText(this.txtRegex.getText().replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"")); }//GEN-LAST:event_btnLiteraliseActionPerformed 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 pivot(); }//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 /** * @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 btnCSV; private javax.swing.JButton btnClear; private javax.swing.JButton btnFormat; private javax.swing.JButton btnLiteralise; private javax.swing.JButton btnLoad; private javax.swing.JButton btnMatch; private javax.swing.JButton btnPivot; private javax.swing.JButton btnTSV; private javax.swing.JButton btnTranspose; private javax.swing.JCheckBox cbBlanks; private javax.swing.ButtonGroup expGrp; 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 javax.swing.JRadioButton rdoDollar; private javax.swing.JRadioButton rdoQuestion; private javax.swing.JRadioButton rdoSlash; private javax.swing.JScrollPane scrollInput; private javax.swing.JScrollPane scrollOutput; private javax.swing.JScrollPane scrollTable; private javax.swing.JSplitPane splitPane; private javax.swing.JSpinner spnColumns; private javax.swing.JTextField txtFormat; private javax.swing.JTextArea txtInput; private javax.swing.JTextArea txtOutput; private javax.swing.JTextField txtRegex; private javax.swing.JTextField txtReplace; // End of variables declaration//GEN-END:variables }
import java.awt.Color; 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.DefaultTableModel; 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 String exprChar = "?"; /** * 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); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { expGrp = new javax.swing.ButtonGroup(); btnGrpTheme = new javax.swing.ButtonGroup(); splitPane = new javax.swing.JSplitPane(); pnlInput = new javax.swing.JPanel(); btnClear = new javax.swing.JButton(); btnLoad = new javax.swing.JButton(); scrollInput = new javax.swing.JScrollPane(); txtInput = new javax.swing.JTextArea(); lblExpression = new javax.swing.JLabel(); txtRegex = new javax.swing.JTextField(); spnColumns = new javax.swing.JSpinner(); btnTSV = new javax.swing.JButton(); btnCSV = new javax.swing.JButton(); btnMatch = new javax.swing.JButton(); scrollTable = new javax.swing.JScrollPane(); jTable = new javax.swing.JTable(); btnTranspose = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); pnlOutput = new javax.swing.JPanel(); lblFormat = new javax.swing.JLabel(); txtFormat = new javax.swing.JTextField(); btnFormat = new javax.swing.JButton(); scrollOutput = new javax.swing.JScrollPane(); txtOutput = new javax.swing.JTextArea(); rdoQuestion = new javax.swing.JRadioButton(); rdoDollar = new javax.swing.JRadioButton(); rdoSlash = new javax.swing.JRadioButton(); jLabel1 = new javax.swing.JLabel(); cbBlanks = new javax.swing.JCheckBox(); txtReplace = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); splitPane.setBorder(null); splitPane.setDividerLocation(366); splitPane.setDividerSize(15); splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); splitPane.setName("splitPane"); // NOI18N splitPane.setOneTouchExpandable(true); pnlInput.setBorder(javax.swing.BorderFactory.createTitledBorder("Input")); pnlInput.setName("pnlInput"); // NOI18N btnClear.setText("Clear"); btnClear.setName("btnClear"); // NOI18N btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } }); btnLoad.setText("Load"); btnLoad.setName("btnLoad"); // NOI18N btnLoad.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLoadActionPerformed(evt); } }); scrollInput.setName("scrollInput"); // NOI18N txtInput.setColumns(20); txtInput.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtInput.setRows(5); txtInput.setName("txtInput"); // NOI18N scrollInput.setViewportView(txtInput); lblExpression.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblExpression.setText("Expression:"); lblExpression.setName("lblExpression"); // NOI18N txtRegex.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtRegex.setName("txtRegex"); // NOI18N spnColumns.setName("spnColumns"); // NOI18N spnColumns.addMouseWheelListener(new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { spnColumnsMouseWheelMoved(evt); } }); btnTSV.setText("TSV"); btnTSV.setName("btnTSV"); // NOI18N btnTSV.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTSVActionPerformed(evt); } }); btnCSV.setText("CSV"); btnCSV.setName("btnCSV"); // NOI18N btnCSV.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCSVActionPerformed(evt); } }); btnMatch.setText("Apply"); btnMatch.setName("btnMatch"); // NOI18N btnMatch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMatchActionPerformed(evt); } }); scrollTable.setName("scrollTable"); // NOI18N jTable.setName("jTable"); // NOI18N scrollTable.setViewportView(jTable); btnTranspose.setText("Transpose"); btnTranspose.setName("btnTranspose"); // NOI18N btnTranspose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTransposeActionPerformed(evt); } }); jButton1.setText("Literalise Expression"); jButton1.setName("jButton1"); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout pnlInputLayout = new javax.swing.GroupLayout(pnlInput); pnlInput.setLayout(pnlInputLayout); pnlInputLayout.setHorizontalGroup( pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlInputLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollTable, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE) .addComponent(scrollInput) .addGroup(pnlInputLayout.createSequentialGroup() .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCSV) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnTSV) .addGap(18, 18, 18) .addComponent(lblExpression) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtRegex) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnMatch)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInputLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInputLayout.createSequentialGroup() .addComponent(jButton1) .addGap(18, 18, 18) .addComponent(btnTranspose)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInputLayout.createSequentialGroup() .addComponent(btnLoad) .addGap(18, 18, 18) .addComponent(btnClear))))) .addContainerGap()) ); pnlInputLayout.setVerticalGroup( pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlInputLayout.createSequentialGroup() .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnLoad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnClear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollInput, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtRegex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblExpression) .addComponent(btnTSV) .addComponent(btnCSV) .addComponent(spnColumns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnMatch)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(scrollTable, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnTranspose) .addComponent(jButton1)) .addContainerGap()) ); splitPane.setTopComponent(pnlInput); pnlOutput.setBorder(javax.swing.BorderFactory.createTitledBorder("Output")); pnlOutput.setName("pnlOutput"); // NOI18N lblFormat.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblFormat.setText("Format:"); lblFormat.setName("lblFormat"); // NOI18N txtFormat.setName("txtFormat"); // NOI18N btnFormat.setText("Apply"); btnFormat.setName("btnFormat"); // NOI18N btnFormat.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFormatActionPerformed(evt); } }); scrollOutput.setName("scrollOutput"); // NOI18N txtOutput.setColumns(20); txtOutput.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N txtOutput.setRows(5); txtOutput.setName("txtOutput"); // NOI18N scrollOutput.setViewportView(txtOutput); expGrp.add(rdoQuestion); rdoQuestion.setSelected(true); rdoQuestion.setText("?"); rdoQuestion.setName("rdoQuestion"); // NOI18N rdoQuestion.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoQuestionActionPerformed(evt); } }); expGrp.add(rdoDollar); rdoDollar.setText("$"); rdoDollar.setName("rdoDollar"); // NOI18N rdoDollar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoDollarActionPerformed(evt); } }); expGrp.add(rdoSlash); rdoSlash.setText("\\"); rdoSlash.setName("rdoSlash"); // NOI18N rdoSlash.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rdoSlashActionPerformed(evt); } }); jLabel1.setText("Argument Marker:"); jLabel1.setName("jLabel1"); // NOI18N cbBlanks.setText("Replace blanks?"); cbBlanks.setName("cbBlanks"); // NOI18N txtReplace.setText("null"); txtReplace.setName("txtReplace"); // NOI18N javax.swing.GroupLayout pnlOutputLayout = new javax.swing.GroupLayout(pnlOutput); pnlOutput.setLayout(pnlOutputLayout); pnlOutputLayout.setHorizontalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollOutput) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoQuestion) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoDollar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rdoSlash) .addGap(18, 18, 18) .addComponent(cbBlanks) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtReplace, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)) .addGroup(pnlOutputLayout.createSequentialGroup() .addComponent(lblFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtFormat) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnFormat))) .addContainerGap()) ); pnlOutputLayout.setVerticalGroup( pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlOutputLayout.createSequentialGroup() .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(rdoQuestion) .addComponent(rdoDollar) .addComponent(rdoSlash) .addComponent(jLabel1) .addComponent(cbBlanks) .addComponent(txtReplace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblFormat) .addComponent(txtFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnFormat)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(scrollOutput, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE) .addContainerGap()) ); splitPane.setRightComponent(pnlOutput); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(splitPane) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(splitPane) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void match() { 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 "); } DefaultTableModel model = new DefaultTableModel(); 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++; int groupCount = matcher.groupCount(); model.setColumnCount(groupCount); Object[] headers = new Object[groupCount]; for (int k = 0; k < groupCount; k++) { headers[k] = k + 1; } model.setColumnIdentifiers(headers); txtOutput.append(matcher.group(0) + "\n"); String[] groups = new String[matcher.groupCount()]; for (int j = 1; j <= matcher.groupCount(); j++) { String s = matcher.group(j); groups[j - 1] = s; } model.addRow(groups); } } txtOutput.append("Matched " + 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("Error in expression\n\n"); txtOutput.append(ex.getMessage()); } } private void format() { txtOutput.setText(""); TableModel model = jTable.getModel(); String formatter = this.txtFormat.getText().replaceAll("\\" + exprChar + "(\\d*)", "%$1\\$s"); for (int row = 0; row < model.getRowCount(); row++) { Object[] values = new Object[model.getColumnCount()]; for (int col = 0; col < model.getColumnCount(); col++) { String val = (String) model.getValueAt(row, col); if (cbBlanks.isSelected() && val.isEmpty()) { val = txtReplace.getText(); } values[col] = val; } String formatted = String.format(formatter, values); txtOutput.append(formatted + "\n"); } } private void transpose() { TableModel model = jTable.getModel(); DefaultTableModel transposed = new DefaultTableModel(model.getColumnCount(), model.getRowCount()); for (int row = 0; row < model.getRowCount(); row++) { for (int col = 0; col < model.getColumnCount(); col++) { Object val = model.getValueAt(row, col); transposed.setValueAt(val, col, row); } } Object[] headers = new Object[transposed.getColumnCount()]; for (int i = 0; i < headers.length; i++) { headers[i] = i + 1; } transposed.setColumnIdentifiers(headers); jTable.setModel(transposed); } private void csv() { Integer cols = (Integer) spnColumns.getValue(); 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 = JSedUtils.readFile(jfc.getSelectedFile()); txtInput.setText(data); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error", ex.getMessage(), JOptionPane.ERROR_MESSAGE); } } } private void btnFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormatActionPerformed format(); }//GEN-LAST:event_btnFormatActionPerformed private void btnTransposeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTransposeActionPerformed transpose(); }//GEN-LAST:event_btnTransposeActionPerformed private void btnMatchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMatchActionPerformed match(); }//GEN-LAST:event_btnMatchActionPerformed private void btnCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCSVActionPerformed csv(); }//GEN-LAST:event_btnCSVActionPerformed private void btnTSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTSVActionPerformed tsv(); }//GEN-LAST:event_btnTSVActionPerformed private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed load(); }//GEN-LAST:event_btnLoadActionPerformed private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed txtInput.setText(""); }//GEN-LAST:event_btnClearActionPerformed private void rdoQuestionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoQuestionActionPerformed exprChar = "?"; }//GEN-LAST:event_rdoQuestionActionPerformed private void rdoDollarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoDollarActionPerformed exprChar = "$"; }//GEN-LAST:event_rdoDollarActionPerformed private void rdoSlashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdoSlashActionPerformed exprChar = "\\"; }//GEN-LAST:event_rdoSlashActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed txtOutput.setText(this.txtRegex.getText().replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"")); }//GEN-LAST:event_jButton1ActionPerformed private void spnColumnsMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_spnColumnsMouseWheelMoved Integer value = (Integer) spnColumns.getValue(); value -= evt.getUnitsToScroll(); spnColumns.setValue(value > 0 ? value : 0); }//GEN-LAST:event_spnColumnsMouseWheelMoved /** * @param args the command line arguments */ public static void main(String args[]) throws Exception { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 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 btnCSV; private javax.swing.JButton btnClear; private javax.swing.JButton btnFormat; private javax.swing.ButtonGroup btnGrpTheme; private javax.swing.JButton btnLoad; private javax.swing.JButton btnMatch; private javax.swing.JButton btnTSV; private javax.swing.JButton btnTranspose; private javax.swing.JCheckBox cbBlanks; private javax.swing.ButtonGroup expGrp; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JTable jTable; private javax.swing.JLabel lblExpression; private javax.swing.JLabel lblFormat; private javax.swing.JPanel pnlInput; private javax.swing.JPanel pnlOutput; private javax.swing.JRadioButton rdoDollar; private javax.swing.JRadioButton rdoQuestion; private javax.swing.JRadioButton rdoSlash; private javax.swing.JScrollPane scrollInput; private javax.swing.JScrollPane scrollOutput; private javax.swing.JScrollPane scrollTable; private javax.swing.JSplitPane splitPane; private javax.swing.JSpinner spnColumns; private javax.swing.JTextField txtFormat; private javax.swing.JTextArea txtInput; private javax.swing.JTextArea txtOutput; private javax.swing.JTextField txtRegex; private javax.swing.JTextField txtReplace; // End of variables declaration//GEN-END:variables }
Ignore Space
Show notes
View
src/PivotTableModel.java
0 → 100644
import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import com.google.common.collect.Tables; import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; /** * * @author Mark George <mark.george@otago.ac.nz> */ public class PivotTableModel extends AbstractTableModel { private Table<Integer, Integer, Object> table = HashBasedTable.create(); private TableModelListener listener; @Override public int getRowCount() { return table.rowKeySet().size(); } @Override public int getColumnCount() { return table.columnKeySet().size(); } @Override public String getColumnName(int columnIndex) { return String.valueOf(columnIndex+1); } @Override public Class<?> getColumnClass(int columnIndex) { return Object.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return table.get(rowIndex, columnIndex); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { table.put(rowIndex, columnIndex, aValue); fireTableCellUpdated(rowIndex, columnIndex); } public void addRow(String[] values) { int rowCount = getRowCount(); for (int i = 0; i < values.length; i++) { table.put(rowCount, i, values[i]); } fireTableRowsInserted(rowCount, rowCount); } public void transpose() { table = Tables.transpose(table); fireTableStructureChanged(); } @Override public String toString() { return table.toString(); } }
Show line notes below