001 /*
002 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.swing.plaf;
026
027 import javax.swing.Action;
028 import javax.swing.BoundedRangeModel;
029 import java.awt.Point;
030 import java.awt.Rectangle;
031 import java.awt.Insets;
032 import javax.swing.text.*;
033
034 /**
035 * Text editor user interface
036 *
037 * @author Timothy Prinzing
038 * @version 1.40 05/05/07
039 */
040 public abstract class TextUI extends ComponentUI {
041 /**
042 * Converts the given location in the model to a place in
043 * the view coordinate system.
044 *
045 * @param pos the local location in the model to translate >= 0
046 * @return the coordinates as a rectangle
047 * @exception BadLocationException if the given position does not
048 * represent a valid location in the associated document
049 */
050 public abstract Rectangle modelToView(JTextComponent t, int pos)
051 throws BadLocationException;
052
053 /**
054 * Converts the given location in the model to a place in
055 * the view coordinate system.
056 *
057 * @param pos the local location in the model to translate >= 0
058 * @return the coordinates as a rectangle
059 * @exception BadLocationException if the given position does not
060 * represent a valid location in the associated document
061 */
062 public abstract Rectangle modelToView(JTextComponent t, int pos,
063 Position.Bias bias) throws BadLocationException;
064
065 /**
066 * Converts the given place in the view coordinate system
067 * to the nearest representative location in the model.
068 *
069 * @param pt the location in the view to translate. This
070 * should be in the same coordinate system as the mouse
071 * events.
072 * @return the offset from the start of the document >= 0
073 */
074 public abstract int viewToModel(JTextComponent t, Point pt);
075
076 /**
077 * Provides a mapping from the view coordinate space to the logical
078 * coordinate space of the model.
079 *
080 * @param pt the location in the view to translate.
081 * This should be in the same coordinate system
082 * as the mouse events.
083 * @param biasReturn
084 * filled in by this method to indicate whether
085 * the point given is closer to the previous or the next
086 * character in the model
087 *
088 * @return the location within the model that best represents the
089 * given point in the view >= 0
090 */
091 public abstract int viewToModel(JTextComponent t, Point pt,
092 Position.Bias[] biasReturn);
093
094 /**
095 * Provides a way to determine the next visually represented model
096 * location that one might place a caret. Some views may not be visible,
097 * they might not be in the same order found in the model, or they just
098 * might not allow access to some of the locations in the model.
099 *
100 * @param t the text component for which this UI is installed
101 * @param pos the position to convert >= 0
102 * @param b the bias for the position
103 * @param direction the direction from the current position that can
104 * be thought of as the arrow keys typically found on a keyboard.
105 * This may be SwingConstants.WEST, SwingConstants.EAST,
106 * SwingConstants.NORTH, or SwingConstants.SOUTH
107 * @param biasRet an array to contain the bias for the returned position
108 * @return the location within the model that best represents the next
109 * location visual position
110 * @exception BadLocationException
111 * @exception IllegalArgumentException for an invalid direction
112 */
113 public abstract int getNextVisualPositionFrom(JTextComponent t,
114 int pos, Position.Bias b, int direction,
115 Position.Bias[] biasRet) throws BadLocationException;
116
117 /**
118 * Causes the portion of the view responsible for the
119 * given part of the model to be repainted.
120 *
121 * @param p0 the beginning of the range >= 0
122 * @param p1 the end of the range >= p0
123 */
124 public abstract void damageRange(JTextComponent t, int p0, int p1);
125
126 /**
127 * Causes the portion of the view responsible for the
128 * given part of the model to be repainted.
129 *
130 * @param p0 the beginning of the range >= 0
131 * @param p1 the end of the range >= p0
132 */
133 public abstract void damageRange(JTextComponent t, int p0, int p1,
134 Position.Bias firstBias, Position.Bias secondBias);
135
136 /**
137 * Fetches the binding of services that set a policy
138 * for the type of document being edited. This contains
139 * things like the commands available, stream readers and
140 * writers, etc.
141 *
142 * @return the editor kit binding
143 */
144 public abstract EditorKit getEditorKit(JTextComponent t);
145
146 /**
147 * Fetches a View with the allocation of the associated
148 * text component (i.e. the root of the hierarchy) that
149 * can be traversed to determine how the model is being
150 * represented spatially.
151 *
152 * @return the view
153 */
154 public abstract View getRootView(JTextComponent t);
155
156 /**
157 * Returns the string to be used as the tooltip at the passed in location.
158 *
159 * @see javax.swing.text.JTextComponent#getToolTipText
160 * @since 1.4
161 */
162 public String getToolTipText(JTextComponent t, Point pt) {
163 return null;
164 }
165 }
|