/* * [StringLiteral.java] * * Summary: Describes one String literal token for display. Used by both BatTokenizer and JavaTokenizer. * * Copyright: (c) 2004-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: * 2.0 2009-04-19 tidy comments, more accurate colour names */ package com.mindprod.jtokens; import java.awt.Color; import java.awt.Font; import static com.mindprod.jtokens.TokenColourScheme.COMMON_FOREGROUND_FOR_STRING; import static com.mindprod.jtokens.TokenFonts.EMPHASIS_FONT_SIZE_IN_POINTS; import static com.mindprod.jtokens.TokenFonts.MONO_FONTS; /** * Describes one String literal token for display. Used by both BatTokenizer and JavaTokenizer. * * @author Roedy Green, Canadian Mind Products * @version 2.0 2009-04-19 tidy comments, more accurate colour names * @since 2004-04-24 */ public final class StringLiteral extends Literal { /** * version number for the class */ static final long serialVersionUID = 1L; /** * Font to render this token */ @SuppressWarnings( { "ConstantNamingConvention" } ) private static final Font font = bestFont( MONO_FONTS, Font.PLAIN, EMPHASIS_FONT_SIZE_IN_POINTS ); /** * Constructor * * @param c single char that is erroneous syntax */ public StringLiteral( char c ) { super( c ); } /** * Constructor * * @param stringLit literal text without the enclosing " */ public StringLiteral( String stringLit ) { super( stringLit ); } /** * font to render this token. * * @return Font, in the correct size. */ public Font getFont() { return font; } /** * foreground colour to render this token. * * @return Color object. */ public Color getForeground() { return COMMON_FOREGROUND_FOR_STRING; } /** * @overide * @inheritDoc */ public String getHTML() { return "" + getRawHTML() + ""; } /** * @overide * @inheritDoc */ public String getText() { return '\"' + super.getText() + '\"'; } /** * Can this token be collapsed with following space or with a following identical token? * * @return true if can be collapsed simply by combining text */ public boolean isCollapsible() { // would confuse auto tick surrounding return false; } /** * Is this token useless? In other words would rendering it have no visible effect? NL and Space are not considered * useless, unless they have 0 counts. Usually a token is useless because it has and empty or null text string. * Always false because of surrounding " " * * @return true if this token can be thrown away as useless */ public boolean isUseless() { return false; } }