All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fife.ui.rsyntaxtextarea.DefaultTokenFactory Maven / Gradle / Ivy

Go to download

RSyntaxTextArea is the syntax highlighting text editor for Swing applications. Features include syntax highlighting for 40+ languages, code folding, code completion, regex find and replace, macros, code templates, undo/redo, line numbering and bracket matching.

There is a newer version: 3.5.1
Show newest version
/*
 * 10/28/2004
 *
 * DefaultTokenFactory.java - Default token factory.
 * Copyright (C) 2004 Robert Futrell
 * robert_futrell at users.sourceforge.net
 * http://fifesoft.com/rsyntaxtextarea
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; 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 javax.swing.text.Segment;


/**
 * This class generates tokens for a {@link TokenMaker}.  This class is here
 * because it reuses tokens when they aren't needed anymore to prevent
 * This class doesn't actually create new tokens every time
 * createToken is called.  Instead, it internally keeps a stack of
 * available already-created tokens.  When more tokens are needed to properly
 * display a line, more tokens are added to the available stack.  This saves
 * from needless repetitive memory allocation. However, it makes it IMPERATIVE
 * that users call resetTokenList when creating a new token list so
 * that the token maker can keep an accurate list of available tokens.

* * NOTE: This class should only be used by {@link TokenMaker}; nobody else * needs it! * * @author Robert Futrell * @version 0.1 */ class DefaultTokenFactory implements TokenFactory { private int size; private int increment; private Token[] tokenList; private int currentFreeToken; protected static final int DEFAULT_START_SIZE = 30; protected static final int DEFAULT_INCREMENT = 10; /** * Cosnstructor. */ public DefaultTokenFactory() { this(DEFAULT_START_SIZE, DEFAULT_INCREMENT); } /** * Constructor. * * @param size The initial number of tokens in this factory. * @param increment How many tokens to increment by when the stack gets * empty. */ public DefaultTokenFactory(int size, int increment) { this.size = size; this.increment = increment; this.currentFreeToken = 0; // Give us some tokens to initially work with. tokenList = new Token[size]; for (int i=0; iTokenMaker every time a token list is generated for * a new line so the tokens can be reused. */ public void resetAllTokens() { currentFreeToken = 0; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy