/* * [TargetOption.java] * * Summary: enumeration for the various sorts of transformations possible on text. * * Copyright: (c) 2002-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 4.5 2009-02-26 add both Java string quoting and plain for Java search/regexes. */ package com.mindprod.quoter; import com.mindprod.common18.FontFactory; import java.awt.Font; /** * enumeration for the various sorts of transformations possible on text. *

* They describe the format of the target. * * @author Roedy Green, Canadian Mind Products * @version 4.5 2009-02-26 add both Java string quoting and plain for Java search/regexes. * @since 2002-06-19 */ public enum TargetOption { // don't reorder these! /** * flow, strip newlines. */ STRIP_NEWLINES( new PlainReservedChars(), new StripNewlines(), "flow by stripping newline chars." ), /** * convert text to html. */ TO_HTML( new HTMLReservedChars(), new HTMLTouchUp(), "to HTML, including &entities" ) { /** * Get Applet version of the instructions * * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked HTML " + "from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked HTML."; } }, /** * convert text to html. */ TO_XML( new XMLReservedChars(), new HTMLTouchUp(), "to XML, including &entity references" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked HTML " + "from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked HTML."; } }, /** * convert java literal in quotes to string */ FROM_JAVA_LITERAL( null, new FromJavaStringLiteral(), "from Java String literal to text" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked Java " + "code from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked Java."; } }, /** * convert text to java literal in quotes. */ TO_JAVA_LITERAL( null, new ToJavaStringLiteral(), "from text to Java String literal" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked Java " + "code from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked Java."; } }, /** * convent text to java literal in quotes. */ TO_CSV( null, new ToCSV(), "to CSV field" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] CSV field from " + "lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] CSV " + "field."; } }, /** * convert text to Java char array initialisation code. */ TO_JAVA_CHARARRY( null, new ToJavaCharArrayLiteral(), "to Java char[] literal" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked Java " + "code from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked Java."; } }, /** * strip tags from text. */ STRIP_HTML_TAGS( new PlainReservedChars(), new StripHTMLTags(), "Remove HTML " ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] HTML text to upper; click Convert; then copy[ctrl-c] stripped text " + "from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] HTML text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "stripped text."; } }, /** * strip tags from text. */ STRIP_XML_TAGS( new PlainReservedChars(), new StripXMLTags(), "Remove XML " ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] HTML text to upper; click Convert; then copy[ctrl-c] stripped text " + "from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] HTML text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "stripped text."; } }, /** * strip entities from text. */ STRIP_HTML_ENTITIES( new PlainReservedChars(), new StripHTMLEntities(), "Convert HTML &entities, to plain" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] HTML text to upper; click Convert; then copy[ctrl-c] stripped text " + "from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] HTML text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "stripped text."; } }, /** * strip entities from text. */ STRIP_XML_ENTITIES( new PlainReservedChars(), new StripXMLEntities(), "Convert XML &entity references, to plain" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] HTML text to upper; click Convert; then copy[ctrl-c] stripped text " + "from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] HTML text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "stripped text."; } }, /** * encode a URL. */ ENCODE_URL( new EncodeURL(), null, "Encode a URL using %xx" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw URL to upper; click Convert; then copy[ctrl-c] encoded URL from" + " lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw URL to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "encoded URL."; } }, /** * decode a URL. */ DECODE_URL( new DecodeURL(), null, "Decode a URL containing %xx" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] encoded URL to upper; click Convert; then copy[ctrl-c] plain " + "decoded URL from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] encoded URL to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "plain decoded URL."; } }, /** * leave text alone. */ PLAIN( new PlainReservedChars(), null, "Remove control chars (except tab)" ), /** * leave text alone. */ HEX( new PlainReservedChars(), new ToHex(), "Display codepoints as hex" ), /** * collapse multiple spaces one. */ COLLAPSE_SPACES( new PlainReservedChars(), new CollapseEmbeddedSpaces(), "Collapse multiple spaces" ), /** * collapse multiple blank lines to one. */ COLLAPSE_LINES( new PlainReservedChars(), new CollapseBlankLines(), "Collapse multiple blank lines" ), /** * align text in columns. * * @noinspection WeakerAccess */ ALIGN( new PlainReservedChars(), new Align(), "Align text in columns" ), /** * align java source in columns. * * @noinspection WeakerAccess */ ALIGN_JAVA( new PlainReservedChars(), new AlignJava(), "Align Java source in columns" ), /** * convert text to upper case. */ UPPER( new PlainReservedChars(), new ToUpperCase(), "TO UPPER CASE" ), /** * convert text to lower case. */ LOWER( new PlainReservedChars(), new ToLowerCase(), "to lower case" ), /** * covert text to book title case, first letter of each word caps. */ TITLE( new PlainReservedChars(), new ToBookCase(), "To Book Title Case" ), /** * convert text to a Java regex search string. */ JAVA_REGEX( new JavaRegex(), null, "To Regex (Java)" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked search " + "string from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Type or paste[ctrl-v] raw text to the clipboard; click Convert Clipboard; then " + "paste[ctrl-v] cooked search string."; } }, /** * convert text to a Java regex search string. */ JAVA_REGEX_STRING( new JavaRegexString(), null, "To Regex (Java String)" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked search " + "string from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Type or paste[ctrl-v] raw text to the clipboard; click Convert Clipboard; then " + "paste[ctrl-v] cooked search string."; } }, /** * convert text to a Java regex search CSV. */ JAVA_REGEX_CSV( new JavaRegexCSV(), null, "To Regex (Java CSV)" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] CSV field from " + "lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Type or paste[ctrl-v] raw text to the clipboard; click Convert Clipboard; then " + "paste[ctrl-v] CSV field."; } }, /** * convert text to a Funduc regex search string. */ FUNDUC_REGEX_SEARCH( new FunducRegexSearch(), null, "To Search Regex (Funduc)" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked search " + "string from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked search string."; } }, /** * convert text to a Funduc regex replace string. */ FUNDUC_REGEX_REPLACE( new FunducRegexReplace(), null, "To Replace Regex (Funduc)" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked replace " + "string from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked replace string."; } }, /** * convert text to a Funduc regex search string. */ VSLICK_REGEX_SEARCH( new VSlickRegexSearch(), null, "To Search Regex (Vslick)" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked search " + "string from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked search string."; } }, /** * convert text to a Funduc regex replace string. */ VSLICK_REGEX_REPLACE( new VSlickRegexReplace(), null, "To Replace Regex (VSlick)" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] cooked replace " + "string from lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] " + "cooked replace string."; } }, // end of enum constants /** * convert text to a Funduc regex replace string. */ SPAN( null, new Span(), "To determine the span, raw regex to bypass string" ) { /** * Get Applet version of the instructions * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] regex from " + "lower."; } /** * Get application version of the instructions * @return instruction when using this transform in an * application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] regex."; } } // end of enum constants ; private static final Font monoFont = FontFactory.build( "Monospaced", Font.PLAIN, 13 ); private static final Font regularFont = FontFactory.build( "Dialog", Font.PLAIN, 13 ); private final String desc; /** * Object that can do this sort of transform. */ private final TextProcessor processor; /** * Object that can do this sort of translation to deal with reserved chars. */ private final Translator translator; private TargetOption( Translator translator, TextProcessor processor, String desc ) { this.translator = translator; this.processor = processor; this.desc = desc; } /** * Get Applet version of the instructions. * * @return instruction when using this transform in an Applet */ public String getAppletInstructions() { return "Type or paste[ctrl-v] raw text to upper; click Convert; then copy[ctrl-c] tidied text from lower."; } /** * Get application version of the instructions. * * @return instruction when using this transform in an application. */ public String getApplicationInstructions() { return "Copy[ctrl-c] raw text to the clipboard; click Convert Clipboard; then paste[ctrl-v] tidied text."; } /** * get font to display this transformation. * * @return font to use */ public final Font getFont() { switch ( this ) { default: return regularFont; case ALIGN: case ALIGN_JAVA: return monoFont; } } /** * Get processor. * * @return processor for this transform.. */ public final TextProcessor getProcessor() { return processor; } /** * Get translator. * * @return translator for this transform.. */ public final Translator getTranslator() { return translator; } /** * get human readable description of this transformation. * * @return description. */ public final String toString() { return desc; } }