diff --git a/src/name/mlopatkin/andlogview/search/RequestCompilationException.java b/search/src/main/java/name/mlopatkin/andlogview/search/RequestCompilationException.java similarity index 90% rename from src/name/mlopatkin/andlogview/search/RequestCompilationException.java rename to search/src/main/java/name/mlopatkin/andlogview/search/RequestCompilationException.java index bf3502a3..f4d92072 100644 --- a/src/name/mlopatkin/andlogview/search/RequestCompilationException.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/RequestCompilationException.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,10 @@ import java.util.regex.PatternSyntaxException; +/** + * This exception is thrown when a string representation of a search pattern cannot be converted into something that the + * search machinery can use. + */ public class RequestCompilationException extends Exception { private String request; private final @Nullable PatternSyntaxException cause; diff --git a/src/name/mlopatkin/andlogview/search/HighlightStrategy.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/HighlightStrategy.java similarity index 80% rename from src/name/mlopatkin/andlogview/search/HighlightStrategy.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/HighlightStrategy.java index b7287177..6d95a9d1 100644 --- a/src/name/mlopatkin/andlogview/search/HighlightStrategy.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/HighlightStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package name.mlopatkin.andlogview.search; +package name.mlopatkin.andlogview.search.text; +/** + * A predicate that can highlight occurrences of the pattern in the text. + */ public interface HighlightStrategy extends SearchStrategy { void highlightOccurences(String text, TextHighlighter highlighter); } diff --git a/src/name/mlopatkin/andlogview/search/IgnoreCaseSearcher.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/IgnoreCaseSearcher.java similarity index 91% rename from src/name/mlopatkin/andlogview/search/IgnoreCaseSearcher.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/IgnoreCaseSearcher.java index f9b9cc7d..34754e41 100644 --- a/src/name/mlopatkin/andlogview/search/IgnoreCaseSearcher.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/IgnoreCaseSearcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package name.mlopatkin.andlogview.search; +package name.mlopatkin.andlogview.search.text; import name.mlopatkin.andlogview.utils.MyStringUtils; class IgnoreCaseSearcher implements HighlightStrategy, SearchStrategy { - private String textToSearch; + private final String textToSearch; public IgnoreCaseSearcher(String text) { this.textToSearch = text; diff --git a/src/name/mlopatkin/andlogview/search/RegExpSearcher.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/RegExpSearcher.java similarity index 91% rename from src/name/mlopatkin/andlogview/search/RegExpSearcher.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/RegExpSearcher.java index 3c8ebdd4..b3633aa6 100644 --- a/src/name/mlopatkin/andlogview/search/RegExpSearcher.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/RegExpSearcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package name.mlopatkin.andlogview.search; +package name.mlopatkin.andlogview.search.text; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; class RegExpSearcher implements HighlightStrategy, SearchStrategy { - private Pattern pattern; + private final Pattern pattern; public RegExpSearcher(String regex) throws PatternSyntaxException { pattern = Pattern.compile(regex); diff --git a/src/name/mlopatkin/andlogview/search/SearchRequestParser.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearchRequestParser.java similarity index 96% rename from src/name/mlopatkin/andlogview/search/SearchRequestParser.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/SearchRequestParser.java index b9518b70..30f7af74 100644 --- a/src/name/mlopatkin/andlogview/search/SearchRequestParser.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearchRequestParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,11 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * */ -package name.mlopatkin.andlogview.search; +package name.mlopatkin.andlogview.search.text; + +import name.mlopatkin.andlogview.search.RequestCompilationException; import com.google.common.base.CharMatcher; import com.google.common.base.Preconditions; diff --git a/src/name/mlopatkin/andlogview/search/SearchStrategy.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearchStrategy.java similarity index 80% rename from src/name/mlopatkin/andlogview/search/SearchStrategy.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/SearchStrategy.java index 37677a2c..ccc9e22f 100644 --- a/src/name/mlopatkin/andlogview/search/SearchStrategy.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearchStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package name.mlopatkin.andlogview.search; +package name.mlopatkin.andlogview.search.text; import java.util.function.Predicate; +/** + * A predicate that can check if the String contains some pattern. + */ public interface SearchStrategy extends Predicate {} diff --git a/src/name/mlopatkin/andlogview/search/SearchStrategyFactory.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearchStrategyFactory.java similarity index 93% rename from src/name/mlopatkin/andlogview/search/SearchStrategyFactory.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/SearchStrategyFactory.java index 8f35cd0e..45332fa5 100644 --- a/src/name/mlopatkin/andlogview/search/SearchStrategyFactory.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearchStrategyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package name.mlopatkin.andlogview.search; +package name.mlopatkin.andlogview.search.text; + +import name.mlopatkin.andlogview.search.RequestCompilationException; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; diff --git a/src/name/mlopatkin/andlogview/search/SearcherBuilder.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearcherBuilder.java similarity index 95% rename from src/name/mlopatkin/andlogview/search/SearcherBuilder.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/SearcherBuilder.java index 678b3225..884d3317 100644 --- a/src/name/mlopatkin/andlogview/search/SearcherBuilder.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/SearcherBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,11 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * */ -package name.mlopatkin.andlogview.search; +package name.mlopatkin.andlogview.search.text; + +import name.mlopatkin.andlogview.search.RequestCompilationException; import java.util.function.Predicate; import java.util.regex.Pattern; diff --git a/search/src/main/java/name/mlopatkin/andlogview/search/text/TextHighlighter.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/TextHighlighter.java new file mode 100644 index 00000000..2bcf9d97 --- /dev/null +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/TextHighlighter.java @@ -0,0 +1,31 @@ +/* + * Copyright 2011 Mikhail Lopatkin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package name.mlopatkin.andlogview.search.text; + +/** + * An implementation of this interface can mark portions of text as highlighted. + */ +public interface TextHighlighter { + /** + * Request highlighting of a text portion starting at char at {@code from} index (inclusive) and ending at char at + * {@code end} index (exclusive). The {@code end} index can be outside the text bounds if the highlighting spans to + * the end of text. + * + * @param from the index of the start of the highlighted portion of text + * @param to the first index after the end of the highlighted portion of text + */ + void highlightText(int from, int to); +} diff --git a/src/name/mlopatkin/andlogview/search/TextHighlighter.java b/search/src/main/java/name/mlopatkin/andlogview/search/text/package-info.java similarity index 73% rename from src/name/mlopatkin/andlogview/search/TextHighlighter.java rename to search/src/main/java/name/mlopatkin/andlogview/search/text/package-info.java index 14af5ab6..df00a848 100644 --- a/src/name/mlopatkin/andlogview/search/TextHighlighter.java +++ b/search/src/main/java/name/mlopatkin/andlogview/search/text/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 Mikhail Lopatkin + * Copyright 2022 the Andlogview authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package name.mlopatkin.andlogview.search; /** - * + * The infrastructure for the text search. Creating patterns from regular expressions, highlighting matches, etc. */ -public interface TextHighlighter { - void highlightText(int from, int to); - - void clearHighlight(); -} +package name.mlopatkin.andlogview.search.text; diff --git a/src/name/mlopatkin/andlogview/TooltipGenerator.java b/src/name/mlopatkin/andlogview/TooltipGenerator.java index 82f23a67..ef861188 100644 --- a/src/name/mlopatkin/andlogview/TooltipGenerator.java +++ b/src/name/mlopatkin/andlogview/TooltipGenerator.java @@ -16,7 +16,7 @@ package name.mlopatkin.andlogview; import name.mlopatkin.andlogview.config.Configuration; -import name.mlopatkin.andlogview.search.TextHighlighter; +import name.mlopatkin.andlogview.search.text.TextHighlighter; import com.google.common.collect.Range; import com.google.common.html.HtmlEscapers; @@ -40,11 +40,6 @@ public void highlightText(int from, int to) { highlightRanges.add(Range.closedOpen(from, to)); } - @Override - public void clearHighlight() { - highlightRanges.clear(); - } - private static final String highlightBackgroundColor = "yellow"; private static final String highlightTextColor = "red"; private static final String SPAN_BEGIN = String.format( diff --git a/src/name/mlopatkin/andlogview/search/RowSearchStrategy.java b/src/name/mlopatkin/andlogview/search/RowSearchStrategy.java index c6e11997..be767acb 100644 --- a/src/name/mlopatkin/andlogview/search/RowSearchStrategy.java +++ b/src/name/mlopatkin/andlogview/search/RowSearchStrategy.java @@ -16,6 +16,7 @@ package name.mlopatkin.andlogview.search; import name.mlopatkin.andlogview.logmodel.LogRecord; +import name.mlopatkin.andlogview.search.text.TextHighlighter; import java.util.function.Predicate; diff --git a/src/name/mlopatkin/andlogview/search/RowSearchStrategyFactory.java b/src/name/mlopatkin/andlogview/search/RowSearchStrategyFactory.java index 89228a4a..9788d104 100644 --- a/src/name/mlopatkin/andlogview/search/RowSearchStrategyFactory.java +++ b/src/name/mlopatkin/andlogview/search/RowSearchStrategyFactory.java @@ -1,5 +1,7 @@ package name.mlopatkin.andlogview.search; +import name.mlopatkin.andlogview.search.text.HighlightStrategy; +import name.mlopatkin.andlogview.search.text.SearchStrategyFactory; import name.mlopatkin.andlogview.ui.logtable.Column; import com.google.common.base.CharMatcher; diff --git a/src/name/mlopatkin/andlogview/search/Searchers.java b/src/name/mlopatkin/andlogview/search/Searchers.java index 219e0d5e..ee305333 100644 --- a/src/name/mlopatkin/andlogview/search/Searchers.java +++ b/src/name/mlopatkin/andlogview/search/Searchers.java @@ -17,6 +17,7 @@ package name.mlopatkin.andlogview.search; import name.mlopatkin.andlogview.logmodel.LogRecord; +import name.mlopatkin.andlogview.search.text.TextHighlighter; import com.google.common.collect.ImmutableList; diff --git a/src/name/mlopatkin/andlogview/search/ValueSearcher.java b/src/name/mlopatkin/andlogview/search/ValueSearcher.java index 71fcc8a0..f223551f 100644 --- a/src/name/mlopatkin/andlogview/search/ValueSearcher.java +++ b/src/name/mlopatkin/andlogview/search/ValueSearcher.java @@ -17,6 +17,8 @@ package name.mlopatkin.andlogview.search; import name.mlopatkin.andlogview.logmodel.LogRecord; +import name.mlopatkin.andlogview.search.text.HighlightStrategy; +import name.mlopatkin.andlogview.search.text.TextHighlighter; import name.mlopatkin.andlogview.ui.logtable.Column; class ValueSearcher implements RowSearchStrategy { diff --git a/src/name/mlopatkin/andlogview/ui/filterdialog/FilterFromDialog.java b/src/name/mlopatkin/andlogview/ui/filterdialog/FilterFromDialog.java index 5e83d987..ea49525a 100644 --- a/src/name/mlopatkin/andlogview/ui/filterdialog/FilterFromDialog.java +++ b/src/name/mlopatkin/andlogview/ui/filterdialog/FilterFromDialog.java @@ -21,8 +21,8 @@ import name.mlopatkin.andlogview.logmodel.LogRecord; import name.mlopatkin.andlogview.logmodel.LogRecordPredicates; import name.mlopatkin.andlogview.search.RequestCompilationException; -import name.mlopatkin.andlogview.search.SearchRequestParser; -import name.mlopatkin.andlogview.search.SearcherBuilder; +import name.mlopatkin.andlogview.search.text.SearchRequestParser; +import name.mlopatkin.andlogview.search.text.SearcherBuilder; import name.mlopatkin.andlogview.utils.MorePredicates; import com.google.common.base.Joiner; diff --git a/src/name/mlopatkin/andlogview/ui/logtable/HighlightCellRenderer.java b/src/name/mlopatkin/andlogview/ui/logtable/HighlightCellRenderer.java index bc958961..eb0ef912 100644 --- a/src/name/mlopatkin/andlogview/ui/logtable/HighlightCellRenderer.java +++ b/src/name/mlopatkin/andlogview/ui/logtable/HighlightCellRenderer.java @@ -16,7 +16,7 @@ package name.mlopatkin.andlogview.ui.logtable; import name.mlopatkin.andlogview.TooltipGenerator; -import name.mlopatkin.andlogview.search.TextHighlighter; +import name.mlopatkin.andlogview.search.text.TextHighlighter; import name.mlopatkin.andlogview.thirdparty.styledlabel.StyledLabel; import name.mlopatkin.andlogview.widgets.UiHelper; @@ -122,8 +122,7 @@ public void highlightText(int from, int to) { document.setCharacterAttributes(from, to - from, highlighted, true); } - @Override - public void clearHighlight() { + private void clearHighlight() { document.setCharacterAttributes(0, document.getLength(), BASE_STYLE, true); } } diff --git a/src/name/mlopatkin/andlogview/ui/search/logtable/SearchResultsHighlightCellRenderer.java b/src/name/mlopatkin/andlogview/ui/search/logtable/SearchResultsHighlightCellRenderer.java index 0d9ac171..ab53ba66 100644 --- a/src/name/mlopatkin/andlogview/ui/search/logtable/SearchResultsHighlightCellRenderer.java +++ b/src/name/mlopatkin/andlogview/ui/search/logtable/SearchResultsHighlightCellRenderer.java @@ -18,7 +18,7 @@ import name.mlopatkin.andlogview.TooltipGenerator; import name.mlopatkin.andlogview.logmodel.LogRecord; import name.mlopatkin.andlogview.search.RowSearchStrategy; -import name.mlopatkin.andlogview.search.TextHighlighter; +import name.mlopatkin.andlogview.search.text.TextHighlighter; import name.mlopatkin.andlogview.ui.logtable.Column; import name.mlopatkin.andlogview.ui.logtable.LogRecordTableModel; import name.mlopatkin.andlogview.widgets.DecoratingCellRenderer; diff --git a/test/name/mlopatkin/andlogview/search/RowSearchersTest.java b/test/name/mlopatkin/andlogview/search/RowSearchersTest.java index 39ebdecc..c01bf709 100644 --- a/test/name/mlopatkin/andlogview/search/RowSearchersTest.java +++ b/test/name/mlopatkin/andlogview/search/RowSearchersTest.java @@ -7,6 +7,8 @@ import name.mlopatkin.andlogview.logmodel.LogRecord; import name.mlopatkin.andlogview.logmodel.LogRecordUtils; +import name.mlopatkin.andlogview.search.text.SearchStrategyFactory; +import name.mlopatkin.andlogview.search.text.TextHighlighter; import name.mlopatkin.andlogview.ui.logtable.Column; import org.junit.Test; diff --git a/test/name/mlopatkin/andlogview/search/SearchRequestParserTest.java b/test/name/mlopatkin/andlogview/search/SearchRequestParserTest.java index 7a373ef7..74c23ba6 100644 --- a/test/name/mlopatkin/andlogview/search/SearchRequestParserTest.java +++ b/test/name/mlopatkin/andlogview/search/SearchRequestParserTest.java @@ -21,6 +21,8 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.lenient; +import name.mlopatkin.andlogview.search.text.SearchRequestParser; + import org.junit.Assert; import org.junit.Before; import org.junit.Rule; diff --git a/test/name/mlopatkin/andlogview/search/SearcherBuilderTest.java b/test/name/mlopatkin/andlogview/search/SearcherBuilderTest.java index 2051de17..f9877881 100644 --- a/test/name/mlopatkin/andlogview/search/SearcherBuilderTest.java +++ b/test/name/mlopatkin/andlogview/search/SearcherBuilderTest.java @@ -20,6 +20,8 @@ import static org.hamcrest.MatcherAssert.assertThat; +import name.mlopatkin.andlogview.search.text.SearcherBuilder; + import com.google.common.collect.ImmutableList; import org.hamcrest.BaseMatcher;