/* * [JavaConstant.java] * * Summary: Describes one variable name token for display. * * 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.java; import java.awt.Color; import java.awt.Font; import static com.mindprod.jtokens.TokenColourScheme.JAVA_FOREGROUND_FOR_CONSTANT; import static com.mindprod.jtokens.TokenFonts.MONO_FONTS; import static com.mindprod.jtokens.TokenFonts.NORMAL_FONT_SIZE_IN_POINTS; import static java.lang.System.*; /** * Describes one variable name token for display. * * @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 JavaConstant extends Definable { /** * version number for the class */ static final long serialVersionUID = 1L; /** * fonts in order of preference to use for rendering JavaConstant definitions. */ @SuppressWarnings( { "ConstantNamingConvention" } ) private static final Font fontDef = bestFont( MONO_FONTS, Font.BOLD, NORMAL_FONT_SIZE_IN_POINTS ); /** * fonts in order of preference to use for rendering JavaConstant references. */ @SuppressWarnings( { "ConstantNamingConvention" } ) private static final Font fontRef = bestFont( MONO_FONTS, Font.PLAIN, NORMAL_FONT_SIZE_IN_POINTS ); /** * Constructor * * @param constantName the name of a variable e.g. PI. * @param defining true if this where the variable is defined. false if it is a reference to the variable. */ public JavaConstant( String constantName, boolean defining ) { super( constantName, defining ); if ( !constantName.toUpperCase().equals( constantName ) ) { err.println( "\007Constants must be all upper case." ); } } /** * font to render this token. * * @return Font, in the correct size. */ public Font getFont() { return defining ? fontDef : fontRef; } /** * foreground color to render this token. * * @return Color object. */ public Color getForeground() { return JAVA_FOREGROUND_FOR_CONSTANT; } /** * get the text surrounded by CSS html * @return decorated HTML in a " : "" ) + getRawHTML() + ""; } }