/* * [Operator.java] * * Summary: Describes one Operator token for JDisplay. * * 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_OPERATOR; import static com.mindprod.jtokens.TokenColourScheme.JAVA_FOREGROUND_FOR_DIV_OPERATOR; import static com.mindprod.jtokens.TokenFonts.EMPHASIS_FONT_SIZE_IN_POINTS; import static com.mindprod.jtokens.TokenFonts.MONO_FONTS; /** * Describes one Operator token for JDisplay. * * @author Roedy Green, Canadian Mind Products * @version 2.0 2009-04-19 tidy comments, more accurate colour names * @since 2004 */ public class Operator extends Token { /** * Describes one Operator token for JDisplay. *

* version number for this class */ static final long serialVersionUID = 2L; /** * Font to render this token */ @SuppressWarnings( { "ConstantNamingConvention" } ) private static final Font font = bestFont( MONO_FONTS, Font.BOLD, EMPHASIS_FONT_SIZE_IN_POINTS ); /** * constructor * * @param operator single char operator e.g. + - */ public Operator( char operator ) { super( operator ); } /** * Constructor * * @param operator e.g. "+", "--", "." ,"=",":",";" etc, but not ; */ public Operator( String operator ) { super( operator ); } /** * is this a division/remainder operator? * * @return true if this is / or % */ private boolean isDivOperator() { final String op = this.text.trim(); return op.equals( "/" ) || op.equals( "%" ); } /** * @inheritDoc */ public Font getFont() { // font is already very big and bold, so we can't very well get attention // by making it bigger and bolder for div operator. return font; } /** * @inheritDoc */ public Color getForeground() { return isDivOperator() ? JAVA_FOREGROUND_FOR_DIV_OPERATOR : COMMON_FOREGROUND_FOR_OPERATOR; } /** * @inheritDoc */ public String getHTML() { final String cssClass = isDivOperator() ? "divoperator" : "op"; return "" + getRawHTML() + ""; } }