aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/javax/swing/text
diff options
context:
space:
mode:
authordmarkov <none@none>2013-09-12 18:44:14 +0400
committerdmarkov <none@none>2013-09-12 18:44:14 +0400
commit26d37f7ff4cede48bdf7cd701b321cd598ca357b (patch)
tree9f1c7e67209768934ae95833bb126c0cb7698c66 /src/share/classes/javax/swing/text
parent58bd100d5bfdad0541d9ac167d39a479d7ea86d9 (diff)
8024395: Improve fix for line break calculations
Reviewed-by: alexp, alexsch
Diffstat (limited to 'src/share/classes/javax/swing/text')
-rw-r--r--src/share/classes/javax/swing/text/FlowView.java18
-rw-r--r--src/share/classes/javax/swing/text/View.java78
2 files changed, 65 insertions, 31 deletions
diff --git a/src/share/classes/javax/swing/text/FlowView.java b/src/share/classes/javax/swing/text/FlowView.java
index e04b2fe91..8cd647ce9 100644
--- a/src/share/classes/javax/swing/text/FlowView.java
+++ b/src/share/classes/javax/swing/text/FlowView.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -796,6 +796,22 @@ public abstract class FlowView extends BoxView {
v.setParent(parent);
}
+ /** {@inheritDoc} */
+ @Override
+ protected void forwardUpdate(DocumentEvent.ElementChange ec,
+ DocumentEvent e, Shape a, ViewFactory f) {
+ calculateUpdateIndexes(e);
+ // Send update event to all views followed by the changed place.
+ lastUpdateIndex = Math.max((getViewCount() - 1), 0);
+ for (int i = firstUpdateIndex; i <= lastUpdateIndex; i++) {
+ View v = getView(i);
+ if (v != null) {
+ Shape childAlloc = getChildAllocation(i, a);
+ forwardUpdateToView(v, e, childAlloc, f);
+ }
+ }
+ }
+
// The following methods don't do anything useful, they
// simply keep the class from being abstract.
diff --git a/src/share/classes/javax/swing/text/View.java b/src/share/classes/javax/swing/text/View.java
index c2e1e023d..be3a0e433 100644
--- a/src/share/classes/javax/swing/text/View.java
+++ b/src/share/classes/javax/swing/text/View.java
@@ -1137,32 +1137,9 @@ public abstract class View implements SwingConstants {
*/
protected void forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e, Shape a, ViewFactory f) {
- Element elem = getElement();
- int pos = e.getOffset();
- int index0 = getViewIndex(pos, Position.Bias.Forward);
- if (index0 == -1 && e.getType() == DocumentEvent.EventType.REMOVE &&
- pos >= getEndOffset()) {
- // Event beyond our offsets. We may have represented this, that is
- // the remove may have removed one of our child Elements that
- // represented this, so, we should foward to last element.
- index0 = getViewCount() - 1;
- }
- int index1 = index0;
- View v = (index0 >= 0) ? getView(index0) : null;
- if (v != null) {
- if ((v.getStartOffset() == pos) && (pos > 0)) {
- // If v is at a boundary, forward the event to the previous
- // view too.
- index0 = Math.max(index0 - 1, 0);
- }
- }
- if (e.getType() != DocumentEvent.EventType.REMOVE) {
- index1 = getViewIndex(pos + e.getLength(), Position.Bias.Forward);
- if (index1 < 0) {
- index1 = getViewCount() - 1;
- }
- }
- int hole0 = index1 + 1;
+ calculateUpdateIndexes(e);
+
+ int hole0 = lastUpdateIndex + 1;
int hole1 = hole0;
Element[] addedElems = (ec != null) ? ec.getChildrenAdded() : null;
if ((addedElems != null) && (addedElems.length > 0)) {
@@ -1173,11 +1150,9 @@ public abstract class View implements SwingConstants {
// forward to any view not in the forwarding hole
// formed by added elements (i.e. they will be updated
// by initialization.
- index0 = Math.max(index0, 0);
- index1 = Math.max((getViewCount() - 1), 0);
- for (int i = index0; i <= index1; i++) {
+ for (int i = firstUpdateIndex; i <= lastUpdateIndex; i++) {
if (! ((i >= hole0) && (i <= hole1))) {
- v = getView(i);
+ View v = getView(i);
if (v != null) {
Shape childAlloc = getChildAllocation(i, a);
forwardUpdateToView(v, e, childAlloc, f);
@@ -1187,6 +1162,39 @@ public abstract class View implements SwingConstants {
}
/**
+ * Calculates the first and the last indexes of the child views
+ * that need to be notified of the change to the model.
+ * @param e the change information from the associated document
+ */
+ void calculateUpdateIndexes(DocumentEvent e) {
+ int pos = e.getOffset();
+ firstUpdateIndex = getViewIndex(pos, Position.Bias.Forward);
+ if (firstUpdateIndex == -1 && e.getType() == DocumentEvent.EventType.REMOVE &&
+ pos >= getEndOffset()) {
+ // Event beyond our offsets. We may have represented this, that is
+ // the remove may have removed one of our child Elements that
+ // represented this, so, we should forward to last element.
+ firstUpdateIndex = getViewCount() - 1;
+ }
+ lastUpdateIndex = firstUpdateIndex;
+ View v = (firstUpdateIndex >= 0) ? getView(firstUpdateIndex) : null;
+ if (v != null) {
+ if ((v.getStartOffset() == pos) && (pos > 0)) {
+ // If v is at a boundary, forward the event to the previous
+ // view too.
+ firstUpdateIndex = Math.max(firstUpdateIndex - 1, 0);
+ }
+ }
+ if (e.getType() != DocumentEvent.EventType.REMOVE) {
+ lastUpdateIndex = getViewIndex(pos + e.getLength(), Position.Bias.Forward);
+ if (lastUpdateIndex < 0) {
+ lastUpdateIndex = getViewCount() - 1;
+ }
+ }
+ firstUpdateIndex = Math.max(firstUpdateIndex, 0);
+ }
+
+ /**
* Forwards the <code>DocumentEvent</code> to the give child view. This
* simply messages the view with a call to <code>insertUpdate</code>,
* <code>removeUpdate</code>, or <code>changedUpdate</code> depending
@@ -1345,4 +1353,14 @@ public abstract class View implements SwingConstants {
private View parent;
private Element elem;
+ /**
+ * The index of the first child view to be notified.
+ */
+ int firstUpdateIndex;
+
+ /**
+ * The index of the last child view to be notified.
+ */
+ int lastUpdateIndex;
+
};