⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syntaxscheme.java

📁 具有不同语法高亮的编辑器实例
💻 JAVA
字号:
/*
 * 08/06/2004
 *
 * SyntaxScheme.java - A set of traits for a particular token type to use while
 *                     painting.
 * Copyright (C) 2004 Robert Futrell
 * email@address.com
 * www.website.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.fife.ui.rsyntaxtextarea;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import javax.swing.JPanel;


/**
 * The color and style information for any given token type.  Each token type in
 * an <code>RSyntaxTextArea</code> has a corresponding syntax scheme; this
 * scheme tells us the following things:
 *
 * <ul>
 *   <li>What foreground color to use for tokens of this type.</li>
 *   <li>What background color to use.</li>
 *   <li>The font to use.</li>
 * </ul>
 *
 * @author Robert Futrell
 * @version 0.5
 */
public class SyntaxScheme {

	public static final Color DEFAULT_FOREGROUND		= Color.BLACK;
	public static final Color DEFAULT_BACKGROUND		= null;
	public static final Font DEFAULT_FONT			= new Font("Monospaced", Font.PLAIN, 13);

	public Color foreground;
	public Color background;
	public boolean underline;
	public Font font;

	public FontMetrics fontMetrics;


/*****************************************************************************/


	/**
	 * Creates a new syntax scheme defaulting to black foreground, no
	 * background, and no styling.
	 */
	public SyntaxScheme() {
		this(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
	}


/*****************************************************************************/


	/**
	 * Creates a new syntax scheme with the specified colors and no styling.
	 *
	 * @param fg The foreground color to use.
	 * @param bg The background color to use.
	 */
	public SyntaxScheme(Color fg, Color bg) {
		this(fg, bg, DEFAULT_FONT);
	}


/*****************************************************************************/


	/**
	 * Creates a new syntax scheme.
	 *
	 * @param fg The foreground color to use.
	 * @param bg The background color to use.
	 * @param font The font for this syntax scheme.
	 */
	public SyntaxScheme(Color fg, Color bg, Font font) {
		this(fg, bg, font, false);
	}


/*****************************************************************************/


	/**
	 * Creates a new syntax scheme.
	 *
	 * @param fg The foreground color to use.
	 * @param bg The background color to use.
	 * @param font The font for this syntax scheme.
	 * @param underline Whether or not to underline tokens with this style.
	 */
	public SyntaxScheme(Color fg, Color bg, Font font, boolean underline) {
		foreground = fg;
		background = bg;
		this.font = font;
		this.underline = underline;
		this.fontMetrics = new JPanel().
						getFontMetrics(font); // Default, no rendering hints!
	}


/*****************************************************************************/


	/**
	 * Returns whether or not two (possibly <code>null</code>) objects are
	 * equal.
	 */
	private boolean areEqual(Object o1, Object o2) {
		return (o1==null && o2==null) || (o1!=null && o1.equals(o2));
	}


/*****************************************************************************/


	/**
	 * Returns whether or not two syntax schemes are equal.
	 *
	 * @param o2 The object with which to compare this syntax scheme.
	 * @return Whether or not these two syntax schemes represent the same
	 *         scheme.
	 */
	public boolean equals(Object o2) {
		if (o2!=null && o2 instanceof SyntaxScheme) {
			SyntaxScheme ss2 = (SyntaxScheme)o2;
			if (this.underline==ss2.underline &&
				areEqual(foreground, ss2.foreground) &&
				areEqual(background, ss2.background) &&
				font.equals(ss2.font) &&
				areEqual(fontMetrics, ss2.fontMetrics))
					return true;
		}
		return false;
	}


/*****************************************************************************/


	/**
	 * Returns a string representation of this syntax scheme.
	 */
	public String toString() {
		return "[SyntaxScheme: foreground: " + foreground +
			  ", background: " + background + ", underline: " +
			  underline + ", font: " + font + "]";
	}


/*****************************************************************************/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -