8337287: Update image in javax.swing.text.Document.insert

Reviewed-by: serb, prr, abhiscxk
This commit is contained in:
Alexey Ivanov 2024-12-03 15:05:13 +00:00
parent 8647c00114
commit caf053b3ad
3 changed files with 171 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, 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
@ -471,24 +471,31 @@ public interface Document {
public void remove(int offs, int len) throws BadLocationException;
/**
* Inserts a string of content. This will cause a DocumentEvent
* of type DocumentEvent.EventType.INSERT to be sent to the
* registered DocumentListeners, unless an exception is thrown.
* The DocumentEvent will be delivered by calling the
* insertUpdate method on the DocumentListener.
* The offset and length of the generated DocumentEvent
* will indicate what change was actually made to the Document.
* <p style="text-align:center"><img src="doc-files/Document-insert.gif"
* Inserts a string of content. This will cause a {@code DocumentEvent}
* of type {@code DocumentEvent.EventType.INSERT} to be sent to the
* registered {@code DocumentListener}s, unless an exception is thrown.
* The {@code DocumentEvent} will be delivered by calling the
* {@code insertUpdate} method on the {@code DocumentListener}.
* The offset and length of the generated {@code DocumentEvent}
* will indicate what change was actually made to the {@code Document}.
* <p>
* For example, if the document contains the text
* <i>&lsquo;The brown fox&rsquo;</i>,
* calling {@code insert(4, "quick ", null)} will insert the word
* <i>&lsquo;quick&rsquo;</i> and the following space into the text,
* and all the marks at 4 and above will be moved by 6 (the number
* of inserted characters).
* <p style="text-align:center"><img src="doc-files/Document-insert.svg"
* alt="Diagram shows insertion of 'quick' in 'The quick brown fox'">
* <p>
* If the Document structure changed as result of the insertion,
* the details of what Elements were inserted and removed in
* If the {@code Document} structure changed as result of the insertion,
* the details of what {@code Element}s were inserted and removed in
* response to the change will also be contained in the generated
* DocumentEvent. It is up to the implementation of a Document
* {@code DocumentEvent}. It is up to the implementation of a {@code Document}
* to decide how the structure should change in response to an
* insertion.
* <p>
* If the Document supports undo/redo, an UndoableEditEvent will
* If the {@code Document} supports undo/redo, an {@code UndoableEditEvent} will
* also be generated.
*
* @param offset the offset into the document to insert the content &gt;= 0.
@ -496,7 +503,7 @@ public interface Document {
* will move.
* @param str the string to insert
* @param a the attributes to associate with the inserted
* content. This may be null if there are no attributes.
* content. This may be {@code null} if there are no attributes.
* @throws BadLocationException the given insert position is not a valid
* position within the document
* @see javax.swing.event.DocumentEvent

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024, 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
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<svg width="458" height="165"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<style><![CDATA[
rect, path {
fill: none;
stroke: black;
stroke-width: 1px;
}
marker path {
fill: black;
}
g#quick rect {
fill: #C0DCC0;
}
line {
stroke: red;
stroke-width: 1px;
}
text {
font-family: Arial, 'DejaVu Sans', sans-serif;
font-size: 13px;
text-anchor: middle;
dominant-baseline: middle;
}
text.left {
text-anchor: start;
dominant-baseline: auto;
}
text.bold {
font-weight: bold;
}
text.top {
dominant-baseline: hanging;
}
]]></style>
<defs>
<marker
id="arrow"
viewBox="0 0 10 10"
refX="10"
refY="5"
markerWidth="7"
markerHeight="7"
orient="auto">
<path
d="M 0 0 L 10 5 L 0 10"
/>
</marker>
</defs>
<text x="1" y="16" class="left bold">Before Insert</text>
<use
x="0"
y="-94"
xlink:href="#the"
/>
<use
x="-144"
y="-94"
xlink:href="#brownFox"
/>
<line x1="97.5" y1="22" x2="97.5" y2="55"/>
<text x="97" y="57" class="top">4</text>
<text x="1" y="110" class="left bold">After Insert</text>
<g id="the">
<rect x="3.5" y="119.5" width="20" height="20"/>
<text x="13" y="129">T</text>
<rect x="27.5" y="119.5" width="20" height="20"/>
<text x="37" y="129">h</text>
<rect x="51.5" y="119.5" width="20" height="20"/>
<text x="61" y="129">e</text>
<rect x="75.5" y="119.5" width="20" height="20"/>
<text x="85" y="129"> </text>
</g>
<g id="quick">
<rect x="99.5" y="119.5" width="20" height="20"/>
<text x="109" y="129">q</text>
<rect x="123.5" y="119.5" width="20" height="20"/>
<text x="133" y="129">u</text>
<rect x="147.5" y="119.5" width="20" height="20"/>
<text x="157" y="129">i</text>
<rect x="171.5" y="119.5" width="20" height="20"/>
<text x="181" y="129">c</text>
<rect x="195.5" y="119.5" width="20" height="20"/>
<text x="205" y="129">k</text>
<rect x="219.5" y="119.5" width="20" height="20"/>
<text x="229" y="129"> </text>
</g>
<g id="brownFox">
<rect x="243.5" y="119.5" width="20" height="20"/>
<text x="253" y="129">b</text>
<rect x="267.5" y="119.5" width="20" height="20"/>
<text x="277" y="129">r</text>
<rect x="291.5" y="119.5" width="20" height="20"/>
<text x="301" y="129">o</text>
<rect x="315.5" y="119.5" width="20" height="20"/>
<text x="325" y="129">w</text>
<rect x="339.5" y="119.5" width="20" height="20"/>
<text x="349" y="129">n</text>
<rect x="363.5" y="119.5" width="20" height="20"/>
<text x="373" y="129"> </text>
<rect x="387.5" y="119.5" width="20" height="20"/>
<text x="397" y="129">f</text>
<rect x="411.5" y="119.5" width="20" height="20"/>
<text x="421" y="129">o</text>
<rect x="435.5" y="119.5" width="20" height="20"/>
<text x="445" y="129">x</text>
</g>
<path d="M 97.5,71 L 241.5,114" marker-end="url(#arrow)"/>
<line x1="241.5" y1="116" x2="241.5" y2="149"/>
<text x="241" y="151" class="top">10</text>
</svg>