< prev index next >

src/java.desktop/share/classes/java/awt/font/LineBreakMeasurer.java

Print this page


   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


 470      *    text used to construct this {@code LineBreakMeasurer} (or in
 471      *    the text most recently passed to {@code insertChar}
 472      *    or {@code deleteChar}
 473      * @see #getPosition
 474      */
 475     public void setPosition(int newPosition) {
 476         if (newPosition < start || newPosition > limit) {
 477             throw new IllegalArgumentException("position is out of range");
 478         }
 479         pos = newPosition;
 480     }
 481 
 482     /**
 483      * Updates this {@code LineBreakMeasurer} after a single
 484      * character is inserted into the text, and sets the current
 485      * position to the beginning of the paragraph.
 486      *
 487      * @param newParagraph the text after the insertion
 488      * @param insertPos the position in the text at which the character
 489      *    is inserted


 490      * @throws IndexOutOfBoundsException if {@code insertPos} is less
 491      *         than the start of {@code newParagraph} or greater than
 492      *         or equal to the end of {@code newParagraph}
 493      * @throws NullPointerException if {@code newParagraph} is
 494      *         {@code null}
 495      * @see #deleteChar
 496      */
 497     public void insertChar(AttributedCharacterIterator newParagraph,
 498                            int insertPos) {
 499 
 500         measurer.insertChar(newParagraph, insertPos);
 501 
 502         limit = newParagraph.getEndIndex();
 503         pos = start = newParagraph.getBeginIndex();
 504 
 505         charIter.reset(measurer.getChars(), newParagraph.getBeginIndex());
 506         breakIter.setText(charIter);
 507     }
 508 
 509     /**
 510      * Updates this {@code LineBreakMeasurer} after a single
 511      * character is deleted from the text, and sets the current
 512      * position to the beginning of the paragraph.
 513      * @param newParagraph the text after the deletion
 514      * @param deletePos the position in the text at which the character
 515      *    is deleted


 516      * @throws IndexOutOfBoundsException if {@code deletePos} is
 517      *         less than the start of {@code newParagraph} or greater
 518      *         than the end of {@code newParagraph}
 519      * @throws NullPointerException if {@code newParagraph} is
 520      *         {@code null}
 521      * @see #insertChar
 522      */
 523     public void deleteChar(AttributedCharacterIterator newParagraph,
 524                            int deletePos) {
 525 
 526         measurer.deleteChar(newParagraph, deletePos);
 527 
 528         limit = newParagraph.getEndIndex();
 529         pos = start = newParagraph.getBeginIndex();
 530 
 531         charIter.reset(measurer.getChars(), start);
 532         breakIter.setText(charIter);
 533     }
 534 }
   1 /*
   2  * Copyright (c) 1998, 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


 470      *    text used to construct this {@code LineBreakMeasurer} (or in
 471      *    the text most recently passed to {@code insertChar}
 472      *    or {@code deleteChar}
 473      * @see #getPosition
 474      */
 475     public void setPosition(int newPosition) {
 476         if (newPosition < start || newPosition > limit) {
 477             throw new IllegalArgumentException("position is out of range");
 478         }
 479         pos = newPosition;
 480     }
 481 
 482     /**
 483      * Updates this {@code LineBreakMeasurer} after a single
 484      * character is inserted into the text, and sets the current
 485      * position to the beginning of the paragraph.
 486      *
 487      * @param newParagraph the text after the insertion
 488      * @param insertPos the position in the text at which the character
 489      *    is inserted
 490      * @throws IllegalArgumentException if multiple characters are inserted
 491      *         in the text represented by {@code newParagraph}
 492      * @throws IndexOutOfBoundsException if {@code insertPos} is less
 493      *         than the start of {@code newParagraph} or greater than
 494      *         or equal to the end of {@code newParagraph}
 495      * @throws NullPointerException if {@code newParagraph} is
 496      *         {@code null}
 497      * @see #deleteChar
 498      */
 499     public void insertChar(AttributedCharacterIterator newParagraph,
 500                            int insertPos) {
 501 
 502         measurer.insertChar(newParagraph, insertPos);
 503 
 504         limit = newParagraph.getEndIndex();
 505         pos = start = newParagraph.getBeginIndex();
 506 
 507         charIter.reset(measurer.getChars(), newParagraph.getBeginIndex());
 508         breakIter.setText(charIter);
 509     }
 510 
 511     /**
 512      * Updates this {@code LineBreakMeasurer} after a single
 513      * character is deleted from the text, and sets the current
 514      * position to the beginning of the paragraph.
 515      * @param newParagraph the text after the deletion
 516      * @param deletePos the position in the text at which the character
 517      *    is deleted
 518      * @throws IllegalArgumentException if multiple characters are deleted from
 519      *         the text represented by {@code newParagraph}
 520      * @throws IndexOutOfBoundsException if {@code deletePos} is
 521      *         less than the start of {@code newParagraph} or greater
 522      *         than the end of {@code newParagraph}
 523      * @throws NullPointerException if {@code newParagraph} is
 524      *         {@code null}
 525      * @see #insertChar
 526      */
 527     public void deleteChar(AttributedCharacterIterator newParagraph,
 528                            int deletePos) {
 529 
 530         measurer.deleteChar(newParagraph, deletePos);
 531 
 532         limit = newParagraph.getEndIndex();
 533         pos = start = newParagraph.getBeginIndex();
 534 
 535         charIter.reset(measurer.getChars(), start);
 536         breakIter.setText(charIter);
 537     }
 538 }
< prev index next >