001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Evgeniya G. Maenkova
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import java.awt.FontMetrics;
023: import java.awt.Graphics;
024:
025: import org.apache.harmony.awt.text.TextUtils;
026:
027: public class Utilities {
028: public static final int drawTabbedText(final Segment s,
029: final int x, final int y, final Graphics g,
030: final TabExpander t, final int pos) {
031: return TextUtils.drawTabbedText(s, x, y, g, t, pos);
032: }
033:
034: /**
035: * Uses BreakIterator.
036: */
037: public static final int getBreakLocation(final Segment s,
038: final FontMetrics fm, final int start, final int end,
039: final TabExpander t, final int pos) {
040: return TextUtils.getBreakLocation(s, fm, start, end, t, pos);
041: }
042:
043: public static final int getNextWord(final JTextComponent c,
044: final int pos) throws BadLocationException {
045: return TextUtils.getNextWord(c.getDocument(), pos);
046: }
047:
048: /**
049: * If the components document is instanceof AbstractDocument uses by its
050: * method(getParagraphElement). Otherwise, uses Document.getDefaultRoot for
051: * search.
052: */
053: public static final Element getParagraphElement(
054: final JTextComponent c, final int p) {
055: return TextUtils.getParagraphElement(c.getDocument(), p);
056: }
057:
058: /**
059: * Finds row above, calculates modelToView for all position from this view
060: * and selects the best (the closest).
061: */
062: public static final int getPositionAbove(final JTextComponent c,
063: final int p, final int x) throws BadLocationException {
064: return TextUtils
065: .getPositionAbove(TextUtils.getTextKit(c), p, x);
066: }
067:
068: /**
069: * Finds row below, calculates modelToView for all position from this view
070: * and selects the best (the closest).
071: */
072: public static final int getPositionBelow(final JTextComponent c,
073: final int p, final int x) throws BadLocationException {
074: return TextUtils
075: .getPositionBelow(TextUtils.getTextKit(c), p, x);
076: }
077:
078: public static final int getPreviousWord(final JTextComponent c,
079: final int pos) throws BadLocationException {
080: return TextUtils.getPreviousWord(c.getDocument(), pos);
081: }
082:
083: public static final int getRowEnd(final JTextComponent c,
084: final int pos) throws BadLocationException {
085: return TextUtils.getRowEnd(TextUtils.getTextKit(c), pos);
086: }
087:
088: public static final int getRowStart(final JTextComponent c,
089: final int pos) throws BadLocationException {
090: return TextUtils.getRowStart(TextUtils.getTextKit(c), pos);
091: }
092:
093: public static final int getTabbedTextOffset(final Segment s,
094: final FontMetrics fm, final int start, final int end,
095: final TabExpander t, final int pos) {
096: return TextUtils.getTabbedTextOffset(s, fm, start, end, t, pos,
097: true);
098: }
099:
100: /**
101: * If round equals false, it needs that symbol is placed completely. If
102: * round equals true, it needs that more than half of the symbol is placed.
103: */
104: public static final int getTabbedTextOffset(final Segment s,
105: final FontMetrics fm, final int start, final int end,
106: final TabExpander t, final int pos, final boolean round) {
107: return TextUtils.getTabbedTextOffset(s, fm, start, end, t, pos,
108: round);
109: }
110:
111: public static final int getTabbedTextWidth(final Segment s,
112: final FontMetrics fm, final int x, final TabExpander t,
113: final int pos) {
114: return TextUtils.getTabbedTextWidth(s, fm, x, t, pos);
115: }
116:
117: /**
118: * If pos < 0 or pos > length of the document BadLocationException will be
119: * thrown
120: */
121: public static final int getWordEnd(final JTextComponent c,
122: final int pos) throws BadLocationException {
123: return TextUtils.getWordEnd(TextUtils.getTextKit(c), pos);
124: }
125:
126: /**
127: * If pos < 0 or pos > length of the document BadLocationException will be
128: * thrown.
129: */
130: public static final int getWordStart(final JTextComponent c,
131: final int pos) throws BadLocationException {
132: return TextUtils.getWordStart(TextUtils.getTextKit(c), pos);
133: }
134: }
|