1 /*
2 * Copyright (c) 1997, 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
494 if (useFloatingPointAPI) {
495 float xOffs = Utilities.getTabbedTextWidth(s, metrics, (float) tabBase, this, p0);
496 SegmentCache.releaseSharedSegment(s);
497 return new Rectangle2D.Float(lineArea.x + xOffs, lineArea.y, 1, metrics.getHeight());
498 }
499
500 int xOffs = Utilities.getTabbedTextWidth(s, metrics, tabBase, this,p0);
501 SegmentCache.releaseSharedSegment(s);
502
503 // fill in the results and return
504 lineArea.x += xOffs;
505 lineArea.width = 1;
506 lineArea.height = metrics.getHeight();
507 return lineArea;
508 }
509
510 /**
511 * Provides a mapping from the view coordinate space to the logical
512 * coordinate space of the model.
513 *
514 * @param fx the X coordinate >= 0
515 * @param fy the Y coordinate >= 0
516 * @param a the allocated region to render into
517 * @return the location within the model that best represents the
518 * given point in the view >= 0
519 * @see View#viewToModel
520 */
521 public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
522 // PENDING(prinz) properly calculate bias
523 bias[0] = Position.Bias.Forward;
524
525 Rectangle alloc = a.getBounds();
526 Document doc = getDocument();
527
528 if (y < alloc.y) {
529 // above the area covered by this icon, so the position
530 // is assumed to be the start of the coverage for this view.
531 return getStartOffset();
532 } else if (y > alloc.y + alloc.height) {
533 // below the area covered by this icon, so the position
534 // is assumed to be the end of the coverage for this view.
535 return getEndOffset() - 1;
|
1 /*
2 * Copyright (c) 1997, 2017, 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
494 if (useFloatingPointAPI) {
495 float xOffs = Utilities.getTabbedTextWidth(s, metrics, (float) tabBase, this, p0);
496 SegmentCache.releaseSharedSegment(s);
497 return new Rectangle2D.Float(lineArea.x + xOffs, lineArea.y, 1, metrics.getHeight());
498 }
499
500 int xOffs = Utilities.getTabbedTextWidth(s, metrics, tabBase, this,p0);
501 SegmentCache.releaseSharedSegment(s);
502
503 // fill in the results and return
504 lineArea.x += xOffs;
505 lineArea.width = 1;
506 lineArea.height = metrics.getHeight();
507 return lineArea;
508 }
509
510 /**
511 * Provides a mapping from the view coordinate space to the logical
512 * coordinate space of the model.
513 *
514 * @param x the X coordinate >= 0
515 * @param y the Y coordinate >= 0
516 * @param a the allocated region to render into
517 * @return the location within the model that best represents the
518 * given point in the view >= 0
519 * @see View#viewToModel
520 */
521 public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
522 // PENDING(prinz) properly calculate bias
523 bias[0] = Position.Bias.Forward;
524
525 Rectangle alloc = a.getBounds();
526 Document doc = getDocument();
527
528 if (y < alloc.y) {
529 // above the area covered by this icon, so the position
530 // is assumed to be the start of the coverage for this view.
531 return getStartOffset();
532 } else if (y > alloc.y + alloc.height) {
533 // below the area covered by this icon, so the position
534 // is assumed to be the end of the coverage for this view.
535 return getEndOffset() - 1;
|