< prev index next >

src/java.desktop/share/classes/javax/swing/JLabel.java

Print this page


   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


1132 
1133         /**
1134          * Given a point in local coordinates, return the zero-based index
1135          * of the character under that Point.  If the point is invalid,
1136          * this method returns -1.
1137          *
1138          * @param p the Point in local coordinates
1139          * @return the zero-based index of the character under Point p; if
1140          * Point is invalid returns -1.
1141          * @since 1.3
1142          */
1143         public int getIndexAtPoint(Point p) {
1144             View view = (View) JLabel.this.getClientProperty("html");
1145             if (view != null) {
1146                 Rectangle r = getTextRectangle();
1147                 if (r == null) {
1148                     return -1;
1149                 }
1150                 Rectangle2D.Float shape =
1151                     new Rectangle2D.Float(r.x, r.y, r.width, r.height);
1152                 Position.Bias bias[] = new Position.Bias[1];
1153                 return view.viewToModel(p.x, p.y, shape, bias);
1154             } else {
1155                 return -1;
1156             }
1157         }
1158 
1159         /**
1160          * Returns the bounding box of the character at the given
1161          * index in the string.  The bounds are returned in local
1162          * coordinates. If the index is invalid, <code>null</code> is returned.
1163          *
1164          * @param i the index into the String
1165          * @return the screen coordinates of the character's bounding box.
1166          * If the index is invalid, <code>null</code> is returned.
1167          * @since 1.3
1168          */
1169         public Rectangle getCharacterBounds(int i) {
1170             View view = (View) JLabel.this.getClientProperty("html");
1171             if (view != null) {
1172                 Rectangle r = getTextRectangle();


   1 /*
   2  * Copyright (c) 1997, 2018, 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


1132 
1133         /**
1134          * Given a point in local coordinates, return the zero-based index
1135          * of the character under that Point.  If the point is invalid,
1136          * this method returns -1.
1137          *
1138          * @param p the Point in local coordinates
1139          * @return the zero-based index of the character under Point p; if
1140          * Point is invalid returns -1.
1141          * @since 1.3
1142          */
1143         public int getIndexAtPoint(Point p) {
1144             View view = (View) JLabel.this.getClientProperty("html");
1145             if (view != null) {
1146                 Rectangle r = getTextRectangle();
1147                 if (r == null) {
1148                     return -1;
1149                 }
1150                 Rectangle2D.Float shape =
1151                     new Rectangle2D.Float(r.x, r.y, r.width, r.height);
1152                 Position.Bias[] bias = new Position.Bias[1];
1153                 return view.viewToModel(p.x, p.y, shape, bias);
1154             } else {
1155                 return -1;
1156             }
1157         }
1158 
1159         /**
1160          * Returns the bounding box of the character at the given
1161          * index in the string.  The bounds are returned in local
1162          * coordinates. If the index is invalid, <code>null</code> is returned.
1163          *
1164          * @param i the index into the String
1165          * @return the screen coordinates of the character's bounding box.
1166          * If the index is invalid, <code>null</code> is returned.
1167          * @since 1.3
1168          */
1169         public Rectangle getCharacterBounds(int i) {
1170             View view = (View) JLabel.this.getClientProperty("html");
1171             if (view != null) {
1172                 Rectangle r = getTextRectangle();


< prev index next >