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

📄 rtarootview.java~1~

📁 具有不同语法高亮的编辑器实例
💻 JAVA~1~
📖 第 1 页 / 共 2 页
字号:
/*
 * 07/29/2004
 *
 * RTARootView.java - Root view for an RTextArea.
 * 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.rtextarea;

import java.awt.*;
import javax.swing.event.*;
import javax.swing.text.*;


/**
 * The root view for an <code>RTextArea</code>.  This class is pretty much a
 * ripoff of an inner class in <code>BasicTextUI</code>.
 *
 * @author Robert Futrell
 * @version 0.1
 */
class RTARootView extends View {

	private View view;
	private RTextAreaUI ui;
	private RTextArea editor;


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


	/**
	 * Constructor.
	 */
	RTARootView(RTextAreaUI ui) {
		super(null);
		this.ui = ui;
		this.editor = ui.getRTextArea();
	}


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


	/**
	 * Gives notification from the document that attributes were changed
	 * in a location that this view is responsible for.
	 *
	 * @param e the change information from the associated document
	 * @param a the current allocation of the view
	 */
	public void changedUpdate(DocumentEvent e, Shape a) {
		if (view != null)
			view.changedUpdate(e, a, getViewFactory());
	}


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


	/**
	 * Determines the desired alignment for this view along an axis.
	 *
	 * @param axis may be either X_AXIS or Y_AXIS
	 * @return the desired alignment, where 0.0 indicates the origin
	 *     and 1.0 the full span away from the origin
	 */
	public float getAlignment(int axis) {
		if (view != null)
			return view.getAlignment(axis);
		return 0;
	}


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


	/**
	 * Fetches the attributes to use when rendering.  At the root
	 * level there are no attributes.  If an attribute is resolved
	 * up the view hierarchy this is the end of the line.
	 */
	public AttributeSet getAttributes() {
		return null;
	}


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


	/**
	 * Fetches the allocation for the given child view. 
	 * This enables finding out where various views
	 * are located, without assuming the views store
	 * their location.  This returns the given allocation
	 * since this view simply acts as a gateway between
	 * the view hierarchy and the associated component.
	 *
	 * @param index the index of the child
	 * @param a  the allocation to this view.
	 * @return the allocation to the child
	 */
	public Shape getChildAllocation(int index, Shape a) {
		return a;
	}


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


	/**
	 * Fetches the container hosting the view.  This is useful for
	 * things like scheduling a repaint, finding out the host 
	 * components font, etc.  The default implementation
	 * of this is to forward the query to the parent view.
	 *
	 * @return the container
	 */
	public Container getContainer() {
		return editor;
	}
        

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


	/**
	 * Returns the document model underlying the view.
	 *
	 * @return the model
	 */
	public Document getDocument() {
		return editor.getDocument();
	}
        

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


	/**
	 * Gets the element that this view is mapped to.
	 *
	 * @return The element.
	 */
	public Element getElement() {
		if (view != null)
			return view.getElement();
		return editor.getDocument().getDefaultRootElement();
	}


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


	/**
	 * Returns the ending offset into the model for this view.
	 *
	 * @return the ending offset
	 */
	public int getEndOffset() {
		if (view != null)
			return view.getEndOffset();
		return getElement().getEndOffset();
	}


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


	/**
	 * Determines the maximum span for this view along an axis.
	 *
	 * @param axis may be either X_AXIS or Y_AXIS
	 * @return the span the view would like to be rendered into.
	 *         Typically the view is told to render into the span
	 *         that is returned, although there is no guarantee.
	 *         The parent may choose to resize or break the view.
	 */
	public float getMaximumSpan(int axis) {
		return Integer.MAX_VALUE;
	}


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


	/**
	 * Determines the minimum span for this view along an axis.
	 *
	 * @param axis may be either X_AXIS or Y_AXIS
	 * @return the span the view would like to be rendered into.
	 *         Typically the view is told to render into the span
	 *         that is returned, although there is no guarantee.
	 *         The parent may choose to resize or break the view.
	 */
	public float getMinimumSpan(int axis) {
		if (view != null)
			return view.getMinimumSpan(axis);
		return 10;
	}


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


        /**
         * Provides a way to determine the next visually represented model 
         * location that one might place a caret.  Some views may not be visible,
         * they might not be in the same order found in the model, or they just
         * might not allow access to some of the locations in the model.
         *
         * @param pos the position to convert >= 0
         * @param a the allocated region to render into
         * @param direction the direction from the current position that can
         *  be thought of as the arrow keys typically found on a keyboard.
         *  This may be SwingConstants.WEST, SwingConstants.EAST, 
         *  SwingConstants.NORTH, or SwingConstants.SOUTH.  
         * @return the location within the model that best represents the next
         *  location visual position.
         * @exception BadLocationException
         * @exception IllegalArgumentException for an invalid direction
         */
        public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, 
                                             int direction,
                                             Position.Bias[] biasRet) 
            throws BadLocationException {
            if( view != null ) {
                int nextPos = view.getNextVisualPositionFrom(pos, b, a,
						     direction, biasRet);
		if(nextPos != -1) {
		    pos = nextPos;
		}
		else {
		    biasRet[0] = b;
		}
            } 
            return pos;
        }


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


        /**
         * Determines the preferred span for this view along an axis.
         *
         * @param axis may be either X_AXIS or Y_AXIS
         * @return the span the view would like to be rendered into.
         *         Typically the view is told to render into the span
         *         that is returned, although there is no guarantee.
         *         The parent may choose to resize or break the view.
         */
        public float getPreferredSpan(int axis) {
            if (view != null) {
                return view.getPreferredSpan(axis);
            }
            return 10;
        }


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


        /**
         * Returns the starting offset into the model for this view.
         *
         * @return the starting offset
         */
        public int getStartOffset() {
            if (view != null) {
                return view.getStartOffset();
            }
            return getElement().getStartOffset();
        }


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


        /** 
         * Gets the n-th view in this container.
         *
         * @param n the number of the view to get
         * @return the view
         */
        public View getView(int n) {
            return view;
        }

⌨️ 快捷键说明

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