Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/ui/EditableAtEndDocument.java @ 17524:89152779163c
Merge with jdk8-b132
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 15 Oct 2014 11:59:32 +0200 |
parents | c18cbe5936b8 |
children |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
2 * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. |
0 | 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.ui; | |
26 | |
27 import javax.swing.text.*; | |
28 | |
29 /** This class implements a special type of document in which edits | |
30 can only be performed at the end, from "mark" to the end of the | |
31 document. Thanks to Scott Violet for suggesting to subclass a | |
32 Document implementation for this purpose. (Can't do it with | |
33 DocumentEvents or UndoableEditEvents; however, in 1.4, there will | |
34 be a DocumentFilter which will allow this kind of functionality.) */ | |
35 | |
36 public class EditableAtEndDocument extends PlainDocument { | |
37 private int mark; | |
38 | |
39 public void insertString(int offset, String text, AttributeSet a) | |
40 throws BadLocationException { | |
41 int len = getLength(); | |
42 super.insertString(len, text, a); | |
43 } | |
44 | |
45 public void remove(int offs, int len) throws BadLocationException { | |
46 int start = offs; | |
47 int end = offs + len; | |
48 | |
49 int markStart = mark; | |
50 int markEnd = getLength(); | |
51 | |
52 if ((end < markStart) || (start > markEnd)) { | |
53 // no overlap | |
54 return; | |
55 } | |
56 | |
57 // Determine interval intersection | |
58 int cutStart = Math.max(start, markStart); | |
59 int cutEnd = Math.min(end, markEnd); | |
60 super.remove(cutStart, cutEnd - cutStart); | |
61 } | |
62 | |
63 public void setMark() { | |
64 mark = getLength(); | |
65 } | |
66 | |
67 public String getMarkedText() throws BadLocationException { | |
68 return getText(mark, getLength() - mark); | |
69 } | |
70 | |
71 /** Used to reset the contents of this document */ | |
72 public void clear() { | |
73 try { | |
74 super.remove(0, getLength()); | |
75 setMark(); | |
76 } | |
77 catch (BadLocationException e) { | |
78 } | |
79 } | |
80 } |