Lines 1-7
Link Here
|
1 |
/* |
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
3 |
* |
4 |
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. |
4 |
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
6 |
* The contents of this file are subject to the terms of either the GNU |
7 |
* General Public License Version 2 only ("GPL") or the Common |
7 |
* General Public License Version 2 only ("GPL") or the Common |
Lines 43-49
Link Here
|
43 |
import java.awt.Color; |
43 |
import java.awt.Color; |
44 |
|
44 |
|
45 |
import java.beans.BeanInfo; |
45 |
import java.beans.BeanInfo; |
|
|
46 |
import java.util.logging.Level; |
47 |
import java.util.logging.Logger; |
48 |
import javax.swing.text.BadLocationException; |
49 |
import javax.swing.text.JTextComponent; |
50 |
import org.netbeans.editor.BaseDocument; |
51 |
import org.netbeans.editor.TokenID; |
52 |
import org.netbeans.editor.TokenItem; |
46 |
import org.netbeans.modules.xml.api.model.*; |
53 |
import org.netbeans.modules.xml.api.model.*; |
|
|
54 |
import org.netbeans.modules.xml.text.api.XMLDefaultTokenContext; |
55 |
import org.netbeans.modules.xml.text.syntax.XMLSyntaxSupport; |
47 |
|
56 |
|
48 |
|
57 |
|
49 |
/** |
58 |
/** |
Lines 60-65
Link Here
|
60 |
* @author Petr Kuzel |
69 |
* @author Petr Kuzel |
61 |
*/ |
70 |
*/ |
62 |
class ValueResultItem extends XMLResultItem { |
71 |
class ValueResultItem extends XMLResultItem { |
|
|
72 |
private static final Logger _logger = Logger.getLogger(ValueResultItem.class.getName()); |
63 |
|
73 |
|
64 |
private final String replacementText; |
74 |
private final String replacementText; |
65 |
|
75 |
|
Lines 77-82
Link Here
|
77 |
} |
87 |
} |
78 |
|
88 |
|
79 |
@Override |
89 |
@Override |
|
|
90 |
boolean replaceText(final JTextComponent component, |
91 |
final String replaceToText, final int offset, final int len) { |
92 |
//+++ fix for issue #173691 |
93 |
// (http://netbeans.org/bugzilla/show_bug.cgi?id=173691) |
94 |
final BaseDocument doc = (BaseDocument)component.getDocument(); |
95 |
final XMLSyntaxSupport support = (XMLSyntaxSupport)org.netbeans.editor.Utilities. |
96 |
getSyntaxSupport(component); |
97 |
try { |
98 |
final TokenItem tokenItem = support.getTokenChain(offset, doc. |
99 |
getLength()); |
100 |
final TokenID tokenID = tokenItem.getTokenID(); |
101 |
int id = (tokenID != null ? tokenID.getNumericID() : -1); |
102 |
if (id != XMLDefaultTokenContext.VALUE_ID) { |
103 |
return super.replaceText(component, replaceToText, offset, len); |
104 |
} |
105 |
final String tokenImage = tokenItem.getImage(); |
106 |
doc.runAtomic(new Runnable() { |
107 |
@Override |
108 |
public void run() { |
109 |
try { |
110 |
int imageLength = tokenImage.length(); |
111 |
if (tokenImage.startsWith("\"")) { |
112 |
imageLength--; |
113 |
} |
114 |
if (tokenImage.endsWith("\"")) { |
115 |
imageLength--; |
116 |
} |
117 |
doc.remove(offset, imageLength); |
118 |
doc.insertString(offset, replaceToText, null); |
119 |
} catch (BadLocationException e) { |
120 |
_logger.log(Level.SEVERE, e.getMessage() == null ? e. |
121 |
getClass().getName() : e.getMessage(), e); |
122 |
} |
123 |
} |
124 |
}); |
125 |
} catch (BadLocationException e) { |
126 |
_logger.log(Level.SEVERE, e.getMessage() == null ? e.getClass(). |
127 |
getName() : e.getMessage(), e); |
128 |
} |
129 |
return true; |
130 |
} |
131 |
|
132 |
@Override |
80 |
Color getPaintColor() { return Color.blue; } |
133 |
Color getPaintColor() { return Color.blue; } |
81 |
|
134 |
|
82 |
} |
135 |
} |