in progress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 14 Oct 2014 20:03:38 +0000 (20:03 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Tue, 14 Oct 2014 20:03:38 +0000 (20:03 +0000)
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java
forester/java/src/org/forester/archaeopteryx/ControlPanel.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/archaeopteryx/Options.java
forester/java/src/org/forester/phylogeny/PhylogenyMethods.java

index 2796e00..ffac851 100644 (file)
@@ -115,6 +115,8 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
     private JCheckBoxMenuItem           _search_case_senstive_cbmi;
     private JCheckBoxMenuItem           _search_whole_words_only_cbmi;
     private JCheckBoxMenuItem           _inverse_search_result_cbmi;
+    private JCheckBoxMenuItem           _search_with_regex_cbmi;
+    
     private JCheckBoxMenuItem           _show_overview_cbmi;
     private JMenuItem                   _choose_minimal_confidence_mi;
     private JMenuItem                   _collapse_species_specific_subtrees;
@@ -260,6 +262,11 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
             getMainPanel().getControlPanel().search0();
             getMainPanel().getControlPanel().search1();
         }
+        else if ( o == _search_with_regex_cbmi ) {
+            updateOptions( getOptions() );
+            getMainPanel().getControlPanel().search0();
+            getMainPanel().getControlPanel().search1();
+        }
         else if ( o == _show_scale_cbmi ) {
             updateOptions( getOptions() );
         }
@@ -790,6 +797,16 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         _options_jmenu
                 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
+        
+        
+        
+        _options_jmenu
+        .add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
+
+        
+        
+        
+        
         _options_jmenu
                 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
         customizeJMenuItem( _choose_font_mi );
@@ -823,6 +840,12 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
                                       getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
+        
+        
+        customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
+        
+        
+        
         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
         customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
@@ -1341,6 +1364,9 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
                 && _show_confidence_stddev_cbmi.isSelected() );
         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
                 && _search_whole_words_only_cbmi.isSelected() );
+        options.setSearchWithRegex( ( _search_with_regex_cbmi != null )
+                                        && _search_with_regex_cbmi.isSelected() );
+        
         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
                 && _inverse_search_result_cbmi.isSelected() );
         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
index 8b2b585..f532cc9 100644 (file)
@@ -1834,6 +1834,9 @@ final class ControlPanel extends JPanel implements ActionListener {
                                                                tree,
                                                                getOptions().isSearchCaseSensitive(),
                                                                !getOptions().isMatchWholeTermsOnly(),
+                                                               getOptions().isSearchWithRegex(),
+                                                               
+                                                               
                                                                isShowDomainArchitectures() ) );
                 }
             }
@@ -1888,6 +1891,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                                                                tree,
                                                                getOptions().isSearchCaseSensitive(),
                                                                !getOptions().isMatchWholeTermsOnly(),
+                                                               getOptions().isSearchWithRegex(),
                                                                isShowDomainArchitectures() ) );
                 }
             }
index dedc7ac..7708753 100644 (file)
@@ -96,6 +96,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     static final String         SEARCH_SUBHEADER                        = "Search:";\r
     static final String         DISPLAY_SUBHEADER                       = "Display:";\r
     static final String         SEARCH_TERMS_ONLY_LABEL                 = "Match Complete Terms Only";\r
+    static final String         SEARCH_REGEX_LABEL                       = "Search with Regular Expressions";\r
     static final String         SEARCH_CASE_SENSITIVE_LABEL             = "Case Sensitive";\r
     static final String         INVERSE_SEARCH_RESULT_LABEL             = "Negate Result";\r
     static final String         COLOR_BY_TAXONOMIC_GROUP                = "Colorize by Taxonomic Group";\r
@@ -223,6 +224,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JCheckBoxMenuItem           _search_case_senstive_cbmi;\r
     JCheckBoxMenuItem           _search_whole_words_only_cbmi;\r
     JCheckBoxMenuItem           _inverse_search_result_cbmi;\r
+    JCheckBoxMenuItem           _search_with_regex_cbmi;\r
     // type menu:\r
     JMenu                       _type_menu;\r
     JCheckBoxMenuItem           _rectangular_type_cbmi;\r
@@ -461,6 +463,11 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             getMainPanel().getControlPanel().search0();\r
             getMainPanel().getControlPanel().search1();\r
         }\r
+        else if ( o == _search_with_regex_cbmi ) {\r
+            updateOptions( getOptions() );\r
+            getMainPanel().getControlPanel().search0();\r
+            getMainPanel().getControlPanel().search1();\r
+        }\r
         else if ( o == _show_scale_cbmi ) {\r
             updateOptions( getOptions() );\r
         }\r
@@ -1381,6 +1388,9 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                 && _allow_errors_in_distance_to_parent_cbmi.isSelected() );\r
         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )\r
                 && _search_whole_words_only_cbmi.isSelected() );\r
+        options.setSearchWithRegex( ( _search_with_regex_cbmi != null )\r
+                                    && _search_with_regex_cbmi.isSelected() );\r
+        \r
         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )\r
                 && _inverse_search_result_cbmi.isSelected() );\r
         if ( _graphics_export_visible_only_cbmi != null ) {\r
index 43fdc2e..c6bd428 100644 (file)
@@ -246,6 +246,14 @@ public final class MainFrameApplet extends MainFrame {
         _options_jmenu
                 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
+       
+        
+        
+        _options_jmenu
+        .add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
+
+        
+        
         _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
         customizeJMenuItem( _choose_font_mi );
         customizeJMenuItem( _switch_colors_mi );
@@ -278,6 +286,15 @@ public final class MainFrameApplet extends MainFrame {
         customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
         customizeCheckBoxMenuItem( _label_direction_cbmi,
                                    getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
+        
+        
+        
+        customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
+        
+        
+        
+        
+        
         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
         customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
index e0d7990..6d0ba08 100644 (file)
@@ -935,6 +935,13 @@ public final class MainFrameApplication extends MainFrame {
         _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );\r
         _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );\r
         _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );\r
+       \r
+        \r
+        _options_jmenu\r
+        .add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );\r
+\r
+        \r
+        \r
         _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );\r
         _options_jmenu.addSeparator();\r
         _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),\r
@@ -1029,6 +1036,12 @@ public final class MainFrameApplication extends MainFrame {
         customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );\r
         customizeCheckBoxMenuItem( _allow_errors_in_distance_to_parent_cbmi, getOptions()\r
                 .isReplaceUnderscoresInNhParsing() );\r
+        \r
+        \r
+        customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );\r
+        \r
+        \r
+        \r
         customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );\r
         customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );\r
         customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );\r
index 36d0224..b6992f0 100644 (file)
@@ -61,6 +61,7 @@ final public class Options {
     private boolean                           _internal_number_are_confidence_for_nh_parsing;
     private boolean                           _inverse_search_result;
     private boolean                           _match_whole_terms_only;
+    private boolean                           _search_with_regex;
     private double                            _min_confidence_value;
     private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
     private boolean                           _nh_parsing_replace_underscores;
@@ -255,6 +256,10 @@ final public class Options {
     final boolean isMatchWholeTermsOnly() {
         return _match_whole_terms_only;
     }
+    
+    final boolean isSearchWithRegex() {
+        return _search_with_regex;
+    }
 
     final boolean isPrintBlackAndWhite() {
         return _print_black_and_white;
@@ -361,6 +366,10 @@ final public class Options {
     final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
         _match_whole_terms_only = search_whole_words_only;
     }
+    
+    final void setSearchWithRegex( final boolean search_with_regex ) {
+        _search_with_regex = search_with_regex;
+    }
 
     final void setMinConfidenceValue( final double min_confidence_value ) {
         _min_confidence_value = min_confidence_value;
@@ -471,6 +480,7 @@ final public class Options {
         _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
         _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
         _match_whole_terms_only = false;
+        _search_with_regex = false;
         _search_case_sensitive = false;
         _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
         _show_overview = true;
index cc2a6b2..025b098 100644 (file)
@@ -40,6 +40,7 @@ import java.util.Map;
 import java.util.Set;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
+import java.util.regex.PatternSyntaxException;\r
 \r
 import org.forester.io.parsers.FastaParser;\r
 import org.forester.io.parsers.PhylogenyParser;\r
@@ -939,7 +940,9 @@ public class PhylogenyMethods {
                                                   final Phylogeny phy,\r
                                                   final boolean case_sensitive,\r
                                                   final boolean partial,\r
-                                                  final boolean search_domains ) {\r
+                                                  final boolean regex,\r
+                                                  final boolean search_domains\r
+                                                   ) {\r
         final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();\r
         if ( phy.isEmpty() || ( query == null ) ) {\r
             return nodes;\r
@@ -950,7 +953,7 @@ public class PhylogenyMethods {
         for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {\r
             final PhylogenyNode node = iter.next();\r
             boolean match = false;\r
-            if ( match( node.getName(), query, case_sensitive, partial ) ) {\r
+            if ( match( node.getName(), query, case_sensitive, partial, regex ) ) {\r
                 match = true;\r
             }\r
             else if ( node.getNodeData().isHasTaxonomy()\r
@@ -1616,16 +1619,45 @@ public class PhylogenyMethods {
                                   final String query,\r
                                   final boolean case_sensitive,\r
                                   final boolean partial ) {\r
+        return match( s, query, case_sensitive, partial, false );\r
+    }\r
+\r
+    private static boolean match( final String s,\r
+                                  final String query,\r
+                                  final boolean case_sensitive,\r
+                                  final boolean partial,\r
+                                  final boolean regex ) {\r
+       \r
         if ( ForesterUtil.isEmpty( s ) || ForesterUtil.isEmpty( query ) ) {\r
             return false;\r
         }\r
         String my_s = s.trim();\r
         String my_query = query.trim();\r
-        if ( !case_sensitive ) {\r
+        if ( !case_sensitive && !regex ) {\r
             my_s = my_s.toLowerCase();\r
             my_query = my_query.toLowerCase();\r
         }\r
-        if ( partial ) {\r
+        if ( regex ) {\r
+            Pattern p = null;\r
+            try {\r
+                if ( case_sensitive ) {\r
+                    p = Pattern.compile( my_query );\r
+                }\r
+                else {\r
+                    p = Pattern.compile( my_query, Pattern.CASE_INSENSITIVE );\r
+                }\r
+            }\r
+            catch ( final PatternSyntaxException e ) {\r
+                throw e;\r
+            }\r
+            if ( p != null ) {\r
+                return p.matcher( my_s ).find();\r
+            }\r
+            else {\r
+                throw new RuntimeException( "failed to create new pattern" );\r
+            }\r
+        }\r
+        else if ( partial ) {\r
             return my_s.indexOf( my_query ) >= 0;\r
         }\r
         else {\r