1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
211 /**
212 * Gives access to a buffer that can be used to fetch
213 * text from the associated document.
214 *
215 * @return the buffer
216 */
217 protected final Segment getLineBuffer() {
218 if (lineBuffer == null) {
219 lineBuffer = new Segment();
220 }
221 return lineBuffer;
222 }
223
224 /**
225 * This is called by the nested wrapped line
226 * views to determine the break location. This can
227 * be reimplemented to alter the breaking behavior.
228 * It will either break at word or character boundaries
229 * depending upon the break argument given at
230 * construction.
231 */
232 protected int calculateBreakPosition(int p0, int p1) {
233 int p;
234 Segment segment = SegmentCache.getSharedSegment();
235 loadText(segment, p0, p1);
236 int currentWidth = getWidth();
237 if (wordWrap) {
238 p = p0 + Utilities.getBreakLocation(segment, metrics,
239 tabBase, tabBase + currentWidth,
240 this, p0);
241 } else {
242 p = p0 + Utilities.getTabbedTextOffset(segment, metrics,
243 tabBase, tabBase + currentWidth,
244 this, p0, false);
245 }
246 SegmentCache.releaseSharedSegment(segment);
247 return p;
248 }
249
250 /**
|
1 /*
2 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
211 /**
212 * Gives access to a buffer that can be used to fetch
213 * text from the associated document.
214 *
215 * @return the buffer
216 */
217 protected final Segment getLineBuffer() {
218 if (lineBuffer == null) {
219 lineBuffer = new Segment();
220 }
221 return lineBuffer;
222 }
223
224 /**
225 * This is called by the nested wrapped line
226 * views to determine the break location. This can
227 * be reimplemented to alter the breaking behavior.
228 * It will either break at word or character boundaries
229 * depending upon the break argument given at
230 * construction.
231 * @param p0 the starting document location
232 * @param p1 the ending document location to use
233 * @return the break position
234 */
235 protected int calculateBreakPosition(int p0, int p1) {
236 int p;
237 Segment segment = SegmentCache.getSharedSegment();
238 loadText(segment, p0, p1);
239 int currentWidth = getWidth();
240 if (wordWrap) {
241 p = p0 + Utilities.getBreakLocation(segment, metrics,
242 tabBase, tabBase + currentWidth,
243 this, p0);
244 } else {
245 p = p0 + Utilities.getTabbedTextOffset(segment, metrics,
246 tabBase, tabBase + currentWidth,
247 this, p0, false);
248 }
249 SegmentCache.releaseSharedSegment(segment);
250 return p;
251 }
252
253 /**
|