当前位置: 首页>>代码示例>>Java>>正文


Java Document.getText方法代码示例

本文整理汇总了Java中javax.swing.text.Document.getText方法的典型用法代码示例。如果您正苦于以下问题:Java Document.getText方法的具体用法?Java Document.getText怎么用?Java Document.getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.Document的用法示例。


在下文中一共展示了Document.getText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showEncode

import javax.swing.text.Document; //导入方法依赖的package包/类
protected String showEncode(Document doc) {
  String charsetName = "";
  try {
    String convertedPlainText = doc.getText(0, doc.getLength());
    try (InputStream is = convertStringToStream(convertedPlainText)) {
      CharsetMatch charsetMatch = new CharsetDetector().setText(is).detect();
      charsetName = charsetMatch.getName();
      charsetName = charsetName != null ? charsetName : "NULL";
      if (isPoorMatch(charsetMatch.getConfidence())) {
        charsetName = verifyPossibleUtf8(charsetName, is);
      }
      charsetName += showByteOfMark(is);
    }
  } catch (BadLocationException | IOException ex) {
    Exceptions.printStackTrace(ex);
  }
  return charsetName;
}
 
开发者ID:maumss,项目名称:file-type-plugin,代码行数:19,代码来源:FileType.java

示例2: returnPressed

import javax.swing.text.Document; //导入方法依赖的package包/类
synchronized void returnPressed() {
    Document doc = getDocument();
    int len = doc.getLength();
    Segment segment = new Segment();
    try {
        doc.getText(outputMark, len - outputMark, segment);
    } catch(javax.swing.text.BadLocationException ignored) {
        ignored.printStackTrace();
    }
    if(segment.count > 0) {
        history.add(segment.toString());
    }
    historyIndex = history.size();
    inPipe.write(segment.array, segment.offset, segment.count);
    append("\n");
    outputMark = doc.getLength();
    inPipe.write("\n");
    inPipe.flush();
    console1.flush();
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:21,代码来源:ConsoleTextArea.java

示例3: actionPerformed

import javax.swing.text.Document; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent arg0) {
    JTextArea currentEditor = observer.getActiveEditor().getEditor();
    Document doc = currentEditor.getDocument();
    int len = Math.abs(currentEditor.getCaret().getDot()
            - currentEditor.getCaret().getMark());
    int offset = Math.min(currentEditor.getCaret().getDot(), currentEditor
            .getCaret().getMark());

    try {
        String text = doc.getText(offset, len);
        text = toggleCase(text);
        doc.remove(offset, len);
        doc.insertString(offset, text, null);
        currentEditor.getCaret().setDot(offset);
        currentEditor.getCaret().moveDot(offset + len);
        currentEditor.requestFocus();
    } catch (BadLocationException e1) {

    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:25,代码来源:InvertCaseAction.java

示例4: close

import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    indentImpl.reformatLock();
    try {
        Document doc = indentImpl.document();
        String text = buffer.toString();
        if (text.length() > 0 && offset <= doc.getLength()) {
            try {
                doc.insertString(offset, text, null);
                Position startPos = doc.createPosition(offset);
                Position endPos = doc.createPosition(offset + text.length());
                indentImpl.reformat(startPos.getOffset(), endPos.getOffset(), startPos.getOffset());
                int len = endPos.getOffset() - startPos.getOffset();
                String reformattedText = doc.getText(startPos.getOffset(), len);
                doc.remove(startPos.getOffset(), len);
                writer.write(reformattedText);
            } catch (BadLocationException e) {
                Exceptions.printStackTrace(e);
            }
        }
    } finally {
        indentImpl.reformatUnlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FormatterWriterImpl.java

示例5: DocumentWordTokenizer

import javax.swing.text.Document; //导入方法依赖的package包/类
/**
 * Creates a new DocumentWordTokenizer to work on a document
 * @param document The document to spell check
 */
public DocumentWordTokenizer(Document document) {
  this.document = document;
  //Create a text segment over the entire document
  text = new Segment();
  sentenceIterator = BreakIterator.getSentenceInstance();
  try {
    document.getText(0, document.getLength(), text);
    sentenceIterator.setText(text);
    // robert: use text.getBeginIndex(), not 0, for segment's first offset
    currentWordPos = getNextWordStart(text, text.getBeginIndex());
    //If the current word pos is -1 then the string was all white space
    if (currentWordPos != -1) {
      currentWordEnd = getNextWordEnd(text, currentWordPos);
      nextWordPos = getNextWordStart(text, currentWordEnd);
    } else {
      moreTokens = false;
    }
  } catch (BadLocationException ex) {
    moreTokens = false;
  }
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:26,代码来源:DocumentWordTokenizer.java

示例6: editAttribute

import javax.swing.text.Document; //导入方法依赖的package包/类
private void editAttribute(DocumentEvent documentEvent) {
    Document source = documentEvent.getDocument();
    int length = source.getLength();
    try {
        String value = source.getText(0, length);
        if (value == null) {
            value = "";
        }
        String selectedRmlAttributeKey = editor.getSelectedRmlAttributeKey();
        RmlTag selectedRmlTag = editor.getSelectedRmlTag();
        value = editor.formatValue(selectedRmlTag, selectedRmlAttributeKey, value);
        onEditorAttribute(selectedRmlTag, selectedRmlAttributeKey, value);
    } catch (BadLocationException e1) {
        e1.printStackTrace();
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:17,代码来源:TextAreaCellEditorComponentInstantEditDocumentAdapter.java

示例7: update

import javax.swing.text.Document; //导入方法依赖的package包/类
private void update(DocumentEvent event) {
	String newValue = "";
	try {
		Document doc = event.getDocument();
		newValue = doc.getText(0, doc.getLength());
	} catch (BadLocationException e) {
		Luyten.showExceptionDialog("Exception!", e);
	}

	if (newValue.length() > 0) {
		int index = targetList.getNextMatch(newValue, 0, Position.Bias.Forward);
		if (index < 0) {
			index = 0;
		}
		targetList.ensureIndexIsVisible(index);

		String matchedName = targetList.getModel().getElementAt(index).toString();
		if (newValue.equalsIgnoreCase(matchedName)) {
			if (index != targetList.getSelectedIndex()) {
				SwingUtilities.invokeLater(new ListSelector(index));
			}
		}
	}
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:25,代码来源:JFontChooser.java

示例8: getDocument

import javax.swing.text.Document; //导入方法依赖的package包/类
private Document getDocument(FileObject fo){
    Document result = null;
    try {
        DataObject dObject = DataObject.find(fo);
        EditorCookie ec = (EditorCookie)dObject.getCookie(EditorCookie.class);
        Document doc = ec.openDocument();
        if(doc instanceof BaseDocument)
            return doc;
        result = new org.netbeans.editor.BaseDocument(true, fo.getMIMEType());
        String str = doc.getText(0, doc.getLength());
        result.insertString(0,str,null);
        
    } catch (Exception dObjEx) {
        return null;
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CatalogModelTest.java

示例9: findLastBracketImpl

import javax.swing.text.Document; //导入方法依赖的package包/类
private static int findLastBracketImpl(Tree tree, CompilationUnitTree cu, SourcePositions positions, Document doc) {
    int start = (int)positions.getStartPosition(cu, tree);
    int end   = (int)positions.getEndPosition(cu, tree);
    
    if (start == (-1) || end == (-1)) {
        return -1;
    }
    
    if (start > doc.getLength() || end > doc.getLength()) {
        if (DEBUG) {
            System.err.println("Log: position outside document: ");
            System.err.println("decl = " + tree);
            System.err.println("startOffset = " + start);
            System.err.println("endOffset = " + end);
            Thread.dumpStack();
        }
        
        return (-1);
    }
    
    try {
        String text = doc.getText(end - 1, 1);
        
        if (text.charAt(0) == '}')
            return end - 1;
    } catch (BadLocationException e) {
        LOG.log(Level.INFO, null, e);
    }
    
    return (-1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:Utilities.java

示例10: getOutput

import javax.swing.text.Document; //导入方法依赖的package包/类
/**Return code after the fix has been applied.
 *
 * @param fileName file for which the code should be returned
 * @return the code after the fix has been applied
 */
public String getOutput(String fileName) throws Exception {
    FileObject toCheck = sourceRoot.getFileObject(fileName);

    assertNotNull(toCheck);

    DataObject toCheckDO = DataObject.find(toCheck);
    EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
    Document toCheckDocument = ec.openDocument();

    return toCheckDocument.getText(0, toCheckDocument.getLength());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:HintTest.java

示例11: charBackspaced

import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
public boolean charBackspaced(Document doc, int dotPos, JTextComponent target, char ch) throws BadLocationException {
    if (ch == '%' && dotPos > 0 && dotPos <= doc.getLength() - 2) {
        String s = doc.getText(dotPos - 1, 3);
        if ("<%>".equals(s)) { // NOI18N
            doc.remove(dotPos, 2);
            return true;
        }
    }

    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:YamlKeystrokeHandler.java

示例12: getContent

import javax.swing.text.Document; //导入方法依赖的package包/类
public String getContent(){
    Document doc = (Document) getCatalogModel().getModelSource().getLookup().lookup(Document.class);;
    try {
        return doc.getText(0, doc.getLength());
    } catch (BadLocationException ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:XAMCatalogWriteModelTest.java

示例13: isAutoActivateOkay

import javax.swing.text.Document; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public boolean isAutoActivateOkay(JTextComponent tc) {
	Document doc = tc.getDocument();
	char ch = 0;
	try {
		doc.getText(tc.getCaretPosition(), 1, s);
		ch = s.first();
	} catch (BadLocationException ble) { // Never happens
		ble.printStackTrace();
	}
	return (autoActivateAfterLetters && Character.isLetter(ch)) ||
			(autoActivateChars!=null && autoActivateChars.indexOf(ch)>-1);
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:17,代码来源:CompletionProviderBase.java

示例14: getContents

import javax.swing.text.Document; //导入方法依赖的package包/类
private String getContents(Document d, int startFrom) {
    try {
        int l = d.getLength() + 1;
        if (startFrom > l) {
            startFrom = l;
        }
        if (hasMoreParts()) {
            StringBuilder sb = new StringBuilder();
            for (Rng r : partOffsets) {
                if (startFrom >= r.end) {
                    continue;
                } else if (startFrom > r.start) {
                    sb.append(d.getText(startFrom, Math.min(l, r.end) - startFrom));
                } else {
                    startFrom = Math.min(l, r.start);
                    sb.append(d.getText(r.start, Math.min(l, r.end) - startFrom));
                }
            }
            return sb.toString();
        } else if (startFrom >= getEnd()) {
            return ""; // NOI18N
        } else if (startFrom > contentStart) {
            int e = Math.min(l, contentStart + getPartLen());
            return d.getText(startFrom, e - startFrom);
        } else {
            startFrom = Math.min(l, contentStart);
            return d.getText(startFrom, Math.min(l - startFrom, getPartLen()));
        }
    } catch (BadLocationException ex) {
        ex.printStackTrace();
    }
    return "";
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:ConsoleSection.java

示例15: testModifyTheFileAndThenPreventItToBeSavedOnClose

import javax.swing.text.Document; //导入方法依赖的package包/类
public void testModifyTheFileAndThenPreventItToBeSavedOnClose() throws Exception {
    Document doc = support.openDocument();
    
    doc.insertString(0, "Ahoj", null);
    assertTrue("Modified", support.isModified());
    
    support.open();
    waitEQ();

    JEditorPane[] arr = getPanes();
    assertNotNull("There is one opened pane", arr);
    
    java.awt.Component c = arr[0];
    while (!(c instanceof CloneableEditor)) {
        c = c.getParent();
    }
    CloneableEditor ce = (CloneableEditor)c;

    toThrow = new IOException("NetworkConnectionLost");

    // say save at the end
    DD.toReturn = 0;
    boolean result = ce.close();
    assertFalse("Refused to save due to the exception", result);
    waitEQ();
    
    assertNotNull("There was a question", DD.options);
    
    String txt = doc.getText(0, doc.getLength());
    assertEquals("The right text is there", txt, "Ahoj");
    assertEquals("Nothing has been saved", "", content);
    
    arr = getPanes();
    assertNotNull("Panes are still open", arr);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:NetworkConnectionLostTest.java


注:本文中的javax.swing.text.Document.getText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。