當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。