1 /*
2 * Copyright (c) 1997, 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
503 * @return the tab stop, measured in points >= 0
504 */
505 public float nextTabStop(float x, int tabOffset) {
506 if (tabSize == 0) {
507 return x;
508 }
509 int ntabs = (((int) x) - tabBase) / tabSize;
510 return tabBase + ((ntabs + 1) * tabSize);
511 }
512
513 // --- local methods ------------------------------------------------
514
515 /**
516 * Repaint the region of change covered by the given document
517 * event. Damages the line that begins the range to cover
518 * the case when the insert/remove is only on one line.
519 * If lines are added or removed, damages the whole
520 * view. The longest line is checked to see if it has
521 * changed.
522 *
523 * @since 1.4
524 */
525 protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
526 Component host = getContainer();
527 updateMetrics();
528 Element elem = getElement();
529 DocumentEvent.ElementChange ec = changes.getChange(elem);
530
531 Element[] added = (ec != null) ? ec.getChildrenAdded() : null;
532 Element[] removed = (ec != null) ? ec.getChildrenRemoved() : null;
533 if (((added != null) && (added.length > 0)) ||
534 ((removed != null) && (removed.length > 0))) {
535 // lines were added or removed...
536 if (added != null) {
537 int currWide = getLineWidth(longLine);
538 for (int i = 0; i < added.length; i++) {
539 int w = getLineWidth(added[i]);
540 if (w > currWide) {
541 currWide = w;
542 longLine = added[i];
591 */
592 protected void damageLineRange(int line0, int line1, Shape a, Component host) {
593 if (a != null) {
594 Rectangle area0 = lineToRect(a, line0);
595 Rectangle area1 = lineToRect(a, line1);
596 if ((area0 != null) && (area1 != null)) {
597 Rectangle damage = area0.union(area1);
598 host.repaint(damage.x, damage.y, damage.width, damage.height);
599 } else {
600 host.repaint();
601 }
602 }
603 }
604
605 /**
606 * Determine the rectangle that represents the given line.
607 *
608 * @param a the region allocated for the view to render into
609 * @param line the line number to find the region of. This must
610 * be a valid line number in the model.
611 * @since 1.4
612 */
613 protected Rectangle lineToRect(Shape a, int line) {
614 Rectangle r = null;
615 updateMetrics();
616 if (metrics != null) {
617 Rectangle alloc = a.getBounds();
618 if (line == 0) {
619 alloc.x += firstLineOffset;
620 alloc.width -= firstLineOffset;
621 }
622 r = new Rectangle(alloc.x, alloc.y + (line * metrics.getHeight()),
623 alloc.width, metrics.getHeight());
624 }
625 return r;
626 }
627
628 /**
629 * Iterate over the lines represented by the child elements
630 * of the element this view represents, looking for the line
|
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
503 * @return the tab stop, measured in points >= 0
504 */
505 public float nextTabStop(float x, int tabOffset) {
506 if (tabSize == 0) {
507 return x;
508 }
509 int ntabs = (((int) x) - tabBase) / tabSize;
510 return tabBase + ((ntabs + 1) * tabSize);
511 }
512
513 // --- local methods ------------------------------------------------
514
515 /**
516 * Repaint the region of change covered by the given document
517 * event. Damages the line that begins the range to cover
518 * the case when the insert/remove is only on one line.
519 * If lines are added or removed, damages the whole
520 * view. The longest line is checked to see if it has
521 * changed.
522 *
523 * @param changes the change information from the associated document
524 * @param a the current allocation of the view
525 * @param f the factory to use to rebuild if the view has children
526 * @since 1.4
527 */
528 protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
529 Component host = getContainer();
530 updateMetrics();
531 Element elem = getElement();
532 DocumentEvent.ElementChange ec = changes.getChange(elem);
533
534 Element[] added = (ec != null) ? ec.getChildrenAdded() : null;
535 Element[] removed = (ec != null) ? ec.getChildrenRemoved() : null;
536 if (((added != null) && (added.length > 0)) ||
537 ((removed != null) && (removed.length > 0))) {
538 // lines were added or removed...
539 if (added != null) {
540 int currWide = getLineWidth(longLine);
541 for (int i = 0; i < added.length; i++) {
542 int w = getLineWidth(added[i]);
543 if (w > currWide) {
544 currWide = w;
545 longLine = added[i];
594 */
595 protected void damageLineRange(int line0, int line1, Shape a, Component host) {
596 if (a != null) {
597 Rectangle area0 = lineToRect(a, line0);
598 Rectangle area1 = lineToRect(a, line1);
599 if ((area0 != null) && (area1 != null)) {
600 Rectangle damage = area0.union(area1);
601 host.repaint(damage.x, damage.y, damage.width, damage.height);
602 } else {
603 host.repaint();
604 }
605 }
606 }
607
608 /**
609 * Determine the rectangle that represents the given line.
610 *
611 * @param a the region allocated for the view to render into
612 * @param line the line number to find the region of. This must
613 * be a valid line number in the model.
614 * @return the rectangle that represents the given line
615 * @since 1.4
616 */
617 protected Rectangle lineToRect(Shape a, int line) {
618 Rectangle r = null;
619 updateMetrics();
620 if (metrics != null) {
621 Rectangle alloc = a.getBounds();
622 if (line == 0) {
623 alloc.x += firstLineOffset;
624 alloc.width -= firstLineOffset;
625 }
626 r = new Rectangle(alloc.x, alloc.y + (line * metrics.getHeight()),
627 alloc.width, metrics.getHeight());
628 }
629 return r;
630 }
631
632 /**
633 * Iterate over the lines represented by the child elements
634 * of the element this view represents, looking for the line
|