本文整理汇总了Java中javax.swing.text.StyledDocument.remove方法的典型用法代码示例。如果您正苦于以下问题:Java StyledDocument.remove方法的具体用法?Java StyledDocument.remove怎么用?Java StyledDocument.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyledDocument
的用法示例。
在下文中一共展示了StyledDocument.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testXMLDTDFormed
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public void testXMLDTDFormed() throws Exception{
final String err = "<!!!>";
System.out.println("running testDTDWellFormed");
String fileName = "DTDformed.xml";
Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
StyledDocument doc = openFile(projectName, fileName);
checkXML(node);
int error = doc.getText(0, doc.getLength()).indexOf(err);
doc.remove(error, err.length());
checkXML(node);
validateXML(node);
error = doc.getText(0,doc.getLength()).indexOf("<collection>")-1;
doc.insertString(error, "<!DOCTYPE collection SYSTEM 'DTDformed.dtd'>", null);
validateXML(node);
error = doc.getText(0,doc.getLength()).indexOf("jmeno");
doc.remove(error, 15);
validateXML(node);
error = doc.getText(0,doc.getLength()).indexOf("alcohol");
doc.insertString(error, "calories = \"nut\" ", null);
validateXML(node);
ending();
}
示例2: testXMLXSDFormed
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public void testXMLXSDFormed() throws Exception{
final String err1 = "shiporders";
final String err2 = "title";
final String err3 = "orderid=";
System.out.println("running testXMLXSDFormed");
String fileName = "shiporders.xml";
Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
StyledDocument doc = openFile(projectName, fileName);
checkXML(node);
validateXML(node);
int error = doc.getText(0, doc.getLength()).indexOf(err1)+err1.length()+1;
doc.insertString(error, "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='shiporder.xsd'", null);
error = doc.getText(0, doc.getLength()).indexOf(err2);
doc.insertString(error,"s", null);
checkXML(node);
doc.remove(error, 1);
error = doc.getText(0, doc.getLength()).indexOf(err3)+err3.length()+1;
doc.insertString(error, "1", null);
checkXML(node);
validateXML(node);
doc.remove(error+2,1);
validateXML(node);
ending();
}
示例3: deleteText
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Deletes the text in the section.
* @exception BadLocationException
*/
final void deleteText() throws BadLocationException {
if (valid) {
final StyledDocument doc = guards.getDocument();
final BadLocationException[] blex = new BadLocationException[1];
Runnable r = new Runnable() {
public void run() {
try {
int start = getStartPosition().getOffset();
if (start > 0 && "\n".equals(doc.getText(start - 1, 1))) { // NOI18N
start--;
}
doc.remove(start, getEndPosition().getOffset() - start + 1);
} catch (BadLocationException ex) {
blex[0] = ex;
}
}
};
GuardedSectionsImpl.doRunAtomic(doc, r);
if (blex[0] != null) {
throw blex[0];
}
}
}
示例4: setLength
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/**
* Truncate the log to the given length; if the log is shorter than the
* number given, then nothing happens.
*/
void setLength(int newLength) {
if (log == null)
return;
clearError();
StyledDocument doc = log.getStyledDocument();
int n = doc.getLength();
if (n <= newLength)
return;
try {
doc.remove(newLength, n - newLength);
} catch (BadLocationException e) {
// Harmless
}
if (lastSize > doc.getLength()) {
lastSize = doc.getLength();
}
}
示例5: showDescription
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void showDescription() {
StyledDocument doc = descValue.getStyledDocument();
final Boolean matchCase = matchCaseValue.isSelected();
try {
doc.remove(0, doc.getLength());
ModuleDependency[] deps = getSelectedDependencies();
if (deps.length != 1) {
return;
}
String longDesc = deps[0].getModuleEntry().getLongDescription();
if (longDesc != null) {
doc.insertString(0, longDesc, null);
}
String filterText = filterValue.getText().trim();
if (filterText.length() != 0 && !FILTER_DESCRIPTION.equals(filterText)) {
doc.insertString(doc.getLength(), "\n\n", null); // NOI18N
Style bold = doc.addStyle(null, null);
bold.addAttribute(StyleConstants.Bold, Boolean.TRUE);
doc.insertString(doc.getLength(), getMessage("TEXT_matching_filter_contents"), bold);
doc.insertString(doc.getLength(), "\n", null); // NOI18N
if (filterText.length() > 0) {
String filterTextLC = matchCase?filterText:filterText.toLowerCase(Locale.US);
Style match = doc.addStyle(null, null);
match.addAttribute(StyleConstants.Background, UIManager.get("selection.highlight")!=null?
UIManager.get("selection.highlight"):new Color(246, 248, 139));
boolean isEven = false;
Style even = doc.addStyle(null, null);
even.addAttribute(StyleConstants.Background, UIManager.get("Panel.background"));
if (filterer == null) {
return; // #101776
}
for (String hit : filterer.getMatchesFor(filterText, deps[0])) {
int loc = doc.getLength();
doc.insertString(loc, hit, (isEven ? even : null));
int start = (matchCase?hit:hit.toLowerCase(Locale.US)).indexOf(filterTextLC);
while (start != -1) {
doc.setCharacterAttributes(loc + start, filterTextLC.length(), match, true);
start = hit.toLowerCase(Locale.US).indexOf(filterTextLC, start + 1);
}
doc.insertString(doc.getLength(), "\n", (isEven ? even : null)); // NOI18N
isEven ^= true;
}
} else {
Style italics = doc.addStyle(null, null);
italics.addAttribute(StyleConstants.Italic, Boolean.TRUE);
doc.insertString(doc.getLength(), getMessage("TEXT_no_filter_specified"), italics);
}
}
descValue.setCaretPosition(0);
} catch (BadLocationException e) {
Util.err.notify(ErrorManager.INFORMATIONAL, e);
}
}
示例6: removelast
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public static void removelast(JTextPane interpreter, int i) {
StyledDocument doc = interpreter.getStyledDocument();
Style style = interpreter.addStyle("Style", null);
try {
doc.remove(doc.getLength()-i, i);
}
catch (BadLocationException ex){}
}
示例7: clearSD
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void clearSD (JTextPane pane, StyledDocument sd) {
try {
Style noindentStyle = createNoindentStyle(pane);
sd.remove(0, sd.getLength());
sd.setParagraphAttributes(0, sd.getLength(), noindentStyle, false);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
示例8: testXMLWellFormed
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public void testXMLWellFormed() throws Exception{
System.out.println("running testXMLWellFormed");
String fileName = "well.xml";
Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
StyledDocument doc = openFile(projectName, fileName);
checkXML(node);
int error = doc.getText(0, doc.getLength()).indexOf("notes")+4;
doc.remove(error, 1);
checkXML(node);
validateXML(node);
error = doc.getText(0, doc.getLength()).indexOf("a=");
doc.remove(error, 5);
validateXML(node);
ending();
}
示例9: insertColonyButtons
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void insertColonyButtons(StyledDocument doc, List<Colony> colonies) throws Exception {
for (Colony colony : colonies) {
StyleConstants.setComponent(doc.getStyle("button"), createColonyButton(colony, false));
doc.insertString(doc.getLength(), " ", doc.getStyle("button"));
doc.insertString(doc.getLength(), ", ", doc.getStyle("regular"));
}
doc.remove(doc.getLength() - 2, 2);
}
示例10: doTestSetTextWithGuardMarks
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void doTestSetTextWithGuardMarks() throws BadLocationException {
StyledDocument doc = editor.doc;
doc.insertString(0, "abcdef", null);
Position p = doc.createPosition(1);
assertTrue(!GuardUtils.isGuarded(doc, 1));
NbDocument.markGuarded(doc, 1, 3);
// As of #174294 the GuardedDocument.isPosGuarded returns false
// at the begining of an intra-line guarded section since an insert is allowed there.
assertFalse(GuardUtils.isGuarded(doc, 1));
assertTrue(GuardUtils.isGuarded(doc, 2));
doc.insertString(1, "x", null);
assertEquals(2, p.getOffset());
assertTrue(GuardUtils.isGuarded(doc, 3));
assertTrue(!GuardUtils.isGuarded(doc, 1));
doc.insertString(4, "x", null);
assertEquals(2, p.getOffset());
assertTrue(GuardUtils.isGuarded(doc, 4));
assertTrue(GuardUtils.isGuarded(doc, 3));
assertTrue(GuardUtils.isGuarded(doc, 5));
assertFalse(GuardUtils.isGuarded(doc, 2));
assertTrue(!GuardUtils.isGuarded(doc, 1));
GuardUtils.dumpGuardedAttr(doc);
doc.remove(1, 1);
assertEquals(1, p.getOffset());
}
示例11: defaultAction
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/**
* Gets invoked when user presses VK_ENTER key or when he double-clicks on
* item. This method gets invoked from AWT thread.
*
* @param jTextComponent text component for which the completion was
* invoked.
*/
@Override
public void defaultAction(JTextComponent jTextComponent) {
try {
StyledDocument doc = (StyledDocument) jTextComponent.getDocument();
Caret caret = jTextComponent.getCaret();
int endOffset = doc.getParagraphElement(dotOffset).getEndOffset();
int indexOfWhite = CompletionUtils.getIndexOfAttributesEnd(doc.getText(dotOffset, endOffset - dotOffset).toCharArray());
if (caretOffset != dotOffset) {
doc.remove(dotOffset, indexOfWhite);
}
if (text.startsWith("th:") || text.startsWith("layout:") || text.startsWith("data")) {
String attribute = text + "=\"\"";
if (caretOffset == dotOffset) {
attribute += " ";
}
doc.insertString(dotOffset, attribute, null);
caret.setDot(caret.getDot() - 1);
} else {
doc.insertString(dotOffset, text, null);
if (text.startsWith("#") || text.startsWith("$")) {
caret.setDot(caret.getDot() - 1);
}
}
Completion.get().hideAll();
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
示例12: clearError
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Removes any messages writtin in "red" style. */
public void clearError() {
if (log==null) return;
// Since this class always removes "red" messages prior to writing anything,
// that means if there are any red messages, they will always be at the end of the JTextPane.
StyledDocument doc=log.getStyledDocument();
int n=doc.getLength();
if (n>lastSize) {
try {doc.remove(lastSize, n-lastSize);} catch (BadLocationException e) {}
}
if (batch.size()>0) {
for(String msg: batch) { reallyLog(msg, styleRegular); }
batch.clear();
}
}
示例13: setLength
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Truncate the log to the given length; if the log is shorter than the number given, then nothing happens. */
void setLength(int newLength) {
if (log==null) return;
clearError();
StyledDocument doc=log.getStyledDocument();
int n=doc.getLength();
if (n<=newLength) return;
try {
doc.remove(newLength, n-newLength);
} catch (BadLocationException e) {
// Harmless
}
if (lastSize>doc.getLength()) { lastSize=doc.getLength(); }
}
示例14: actionPerformed
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
if (ignoreComboAction)
return; // not invoked by user, ignore
GuardedBlock gBlock = codeData.getGuardedBlock(category, blockIndex);
GuardBlockInfo gInfo = getGuardInfos(category)[blockIndex];
int[] blockBounds = getGuardBlockBounds(category, blockIndex);
int startOffset = blockBounds[0];
int endOffset = blockBounds[1];
int gHead = gBlock.getHeaderLength();
int gFoot = gBlock.getFooterLength();
JTextComponent editor = getEditor(category);
StyledDocument doc = (StyledDocument) editor.getDocument();
changed = true;
JComboBox combo = (JComboBox) e.getSource();
try {
docListener.setActive(false);
if (combo.getSelectedIndex() == 1) { // changing from default to custom
NbDocument.unmarkGuarded(doc, startOffset, endOffset - startOffset);
// keep last '\n' so we don't destroy next editable block's position
doc.remove(startOffset, endOffset - startOffset - 1);
// insert the custom code into the document
String customCode = gBlock.getCustomCode();
int customLength = customCode.length();
if (gInfo.customizedCode != null) { // already was edited before
customCode = customCode.substring(0, gHead)
+ gInfo.customizedCode
+ customCode.substring(customLength - gFoot);
customLength = customCode.length();
}
if (customCode.endsWith("\n")) // NOI18N
customCode = customCode.substring(0, customLength-1);
doc.insertString(startOffset, customCode, null);
gInfo.customized = true;
// make guarded "header" and "footer", select the text in between
NbDocument.markGuarded(doc, startOffset, gHead);
NbDocument.markGuarded(doc, startOffset + customLength - gFoot, gFoot);
editor.setSelectionStart(startOffset + gHead);
editor.setSelectionEnd(startOffset + customLength - gFoot);
editor.requestFocus();
combo.setToolTipText(gBlock.getCustomEntry().getToolTipText());
}
else { // changing from custom to default
// remember the customized code
gInfo.customizedCode = doc.getText(startOffset + gHead,
endOffset - gFoot - gHead - startOffset);
NbDocument.unmarkGuarded(doc, endOffset - gFoot, gFoot);
NbDocument.unmarkGuarded(doc, startOffset, gHead);
// keep last '\n' so we don't destroy next editable block's position
doc.remove(startOffset, endOffset - startOffset - 1);
String defaultCode = gBlock.getDefaultCode();
if (defaultCode.endsWith("\n")) // NOI18N
defaultCode = defaultCode.substring(0, defaultCode.length()-1);
doc.insertString(startOffset, defaultCode, null);
gInfo.customized = false;
// make the whole text guarded, cancel selection
NbDocument.markGuarded(doc, startOffset, defaultCode.length()+1); // including '\n'
if (editor.getSelectionStart() >= startOffset && editor.getSelectionEnd() <= endOffset)
editor.setCaretPosition(startOffset);
combo.setToolTipText(NbBundle.getMessage(CustomCodeData.class, "CTL_GuardCombo_Default_Hint")); // NOI18N
}
// we must create a new Position - current was moved away by inserting new string on it
gInfo.position = NbDocument.createPosition(doc, startOffset, Position.Bias.Forward);
docListener.setActive(true);
}
catch (BadLocationException ex) { // should not happen
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
}
}
示例15: setText
import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Replaces the text contained in this range.
* This replacement is done atomically, and so is preferable to manual inserts & removes.
* <p>If you are running this from user-oriented code, you may want to wrap it in {@link NbDocument#runAtomicAsUser}.
* @param text new text to insert over existing text
* @exception IOException if any problem occurred during document loading (if that was necessary)
* @exception BadLocationException if the positions are out of the bounds of the document
*/
public void setText(final String text) throws IOException, BadLocationException {
final CloneableEditorSupport editor = begin.getCloneableEditorSupport();
final StyledDocument doc = editor.openDocument();
final BadLocationException[] hold = new BadLocationException[] { null };
Runnable run = new Runnable() {
public void run() {
try {
int p1 = begin.getOffset();
int p2 = end.getOffset();
int len = text.length();
if (len == 0) { // 1) set empty string
if (p2 > p1) {
doc.remove(p1, p2 - p1);
}
} else { // 2) set non empty string
int docLen = doc.getLength();
if ((p2 - p1) >= 2) {
doc.insertString(p1 + 1, text, null);
// [MaM] compute length of inserted string
len = doc.getLength() - docLen;
doc.remove(p1 + 1 + len, p2 - p1 - 1);
doc.remove(p1, 1);
} else {
// zero or exactly one character:
// adjust the positions if they are
// biased to not absorb the text inserted at the start/end
// it would be ridiculous not to have text set by setText
// be part of the bounds.
doc.insertString(p1, text, null);
// [MaM] compute length of inserted string
len = doc.getLength() - docLen;
if (p2 > p1) {
doc.remove(p1 + len, p2 - p1);
}
if (begin.getOffset() != p1) {
begin = editor.createPositionRef(p1, begin.getPositionBias());
}
if ((end.getOffset() - p1) != len) {
end = editor.createPositionRef(p1 + len, end.getPositionBias());
}
}
}
} catch (BadLocationException e) {
hold[0] = e;
}
}
};
NbDocument.runAtomic(doc, run);
if (hold[0] != null) {
throw hold[0];
}
}