當前位置: 首頁>>代碼示例>>Java>>正文


Java DocumentFilter類代碼示例

本文整理匯總了Java中javax.swing.text.DocumentFilter的典型用法代碼示例。如果您正苦於以下問題:Java DocumentFilter類的具體用法?Java DocumentFilter怎麽用?Java DocumentFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DocumentFilter類屬於javax.swing.text包,在下文中一共展示了DocumentFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insertString

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
/** Inserts string into document */
    public @Override void insertString(int offset, String text, AttributeSet attrs)
    throws BadLocationException {
//        if (LOG_EDT.isLoggable(Level.FINE)) { // Only permit operations in EDT
//            // Disabled due to failing OpenEditorEnablesEditMenuFactoryTest
//            if (!SwingUtilities.isEventDispatchThread()) {
//                throw new IllegalStateException("BaseDocument.insertString not in EDT: offset=" + // NOI18N
//                        offset + ", text=" + org.netbeans.lib.editor.util.CharSequenceUtilities.debugText(text)); // NOI18N
//            }
//        }
        
        // Always acquire atomic lock (it simplifies processing and improves readability)
        atomicLockImpl();
        try {
            checkModifiable(offset);
            DocumentFilter filter = getDocumentFilter();
            if (filter != null) {
                filter.insertString(getFilterBypass(), offset, text, attrs);
            } else {
                handleInsertString(offset, text, attrs);
            }
        } finally {
            atomicUnlockImpl(true);
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:BaseDocument.java

示例2: replace

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
public void replace(int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
    // Always acquire atomic lock (it simplifies processing and improves readability)
    atomicLockImpl();
    try {
        checkModifiable(offset);
        DocumentFilter filter = getDocumentFilter();
        if (filter != null) {
            filter.replace(getFilterBypass(), offset, length, text, attrs);
        } else {
            handleRemove(offset, length);
            handleInsertString(offset, text, attrs);
        }
    } finally {
        atomicUnlockImpl(true);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:BaseDocument.java

示例3: remove

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void remove(DocumentFilter.FilterBypass fb, int offset, int length)
        throws BadLocationException {
    if (skipFiltersWhileTrue) {
        super.remove(fb, offset, length);
        return;
    }
    String oldText = fb.getDocument().getText(0, fb.getDocument().getLength());
    StringBuilder newTextBuilder = new StringBuilder(oldText);
    newTextBuilder.delete(offset, (offset + length));
    String newText = newTextBuilder.toString();
    if (newText.trim().isEmpty() || oldText.equals("-1")) {
        setFieldToDefaultValue();
    } else if (allowNegativeNumbers() && newText.trim().equals("-")) {
        setFieldToNegativeOne();
    } else if (isValidInteger(newText)) {
        super.remove(fb, offset, length);
    } else {
        Toolkit.getDefaultToolkit().beep();
    }
}
 
開發者ID:LGoodDatePicker,項目名稱:LGoodDatePicker,代碼行數:22,代碼來源:JIntegerTextField.java

示例4: PlugboardPanel

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
public PlugboardPanel() {
	
	// Create component
	pbField = new JTextField(95);
	pbField.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.gray), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
	
	// Adding border
	Border outerBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
	innerBorder = BorderFactory.createTitledBorder("Plugboard (e.g. AB CD) - Press \"SAVE\"");
	setBorder(BorderFactory.createCompoundBorder(outerBorder, innerBorder));
	
	// Add component
	add(pbField);
	
	// Filter input to upper case only
	( (AbstractDocument) pbField.getDocument() ).setDocumentFilter(new DocumentFilter(){
		public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
			for (int i = 0; i < text.length(); i++) 
				if( (text.charAt(i) < 'a' || text.charAt(i) > 'z') && (text.charAt(i) < 'A' || text.charAt(i) > 'Z') && text.charAt(0) != ' ')
					return;
			super.replace(fb, offset, length, text.toUpperCase(), attrs);
		}
	});
}
 
開發者ID:amirbawab,項目名稱:Enigma-machine-simulator,代碼行數:25,代碼來源:PlugboardPanel.java

示例5: replace

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
/**
 * Replace a string in the document, and then parse it if the parser has been
 * set.
 *
 * @param fb
 * @param offset
 * @param length
 * @param text
 * @param attrs
 * @throws BadLocationException
 */    
public void replace(DocumentFilter.FilterBypass fb, int offset, 
                    int length, String text, AttributeSet attrs)
    throws BadLocationException
{
    // text might be null and indicates no replacement text
    if (text == null) text = "";
    
    // remove problem meta characters returns
    text = replaceMetaCharacters(text);
    
    fb.replace(offset, length, text, attrs);
    
    // start on the text that was replaced
    parseDocument(offset, text.length());
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:27,代碼來源:StructuredSyntaxDocumentFilter.java

示例6: insertString

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
public void insertString(DocumentFilter.FilterBypass fb, int offset,
		String string, AttributeSet attr) throws BadLocationException {

	if (string == null) {
		return;
	} else {
		String newValue;
		Document doc = fb.getDocument();
		int length = doc.getLength();
		if (length == 0) {
			newValue = string;
		} else {
			String currentContent = doc.getText(0, length);
			StringBuilder currentBuffer = new StringBuilder(
					currentContent);
			currentBuffer.insert(offset, string);
			newValue = currentBuffer.toString();
		}
		currentValue = checkInput(newValue, offset);
		fb.insertString(offset, string, attr);
	}
}
 
開發者ID:thingweb,項目名稱:thingweb-gui,代碼行數:23,代碼來源:AbstractDocumentFilter.java

示例7: insertString

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset, String text,
	AttributeSet attr) throws BadLocationException {
	StringBuilder sb = new StringBuilder();
	for(int i = 0; i < text.length(); i++){
		char c = text.charAt(i);
		boolean isLegal = true;
		for(char illegal : illegalChars){
			if(c == illegal){
				isLegal = false;
				break;
			}
		}
		if(isLegal){
			sb.append(c);
		}
	}
	text = sb.toString();
	super.insertString(fb, offset, text, attr);
}
 
開發者ID:QuinnFreedman,項目名稱:THINK-VPL,代碼行數:21,代碼來源:SpecialEditorPane.java

示例8: replace

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text,
	AttributeSet attrs) throws BadLocationException {
	//String curentText = doc.getText(0, Math.min(4, doc.getLength()));
	/*if(doc.getLength() >= 4 && curentText.equals("true")){
		text = "true";
		offset = 0;
		length = doc.getLength();
	}else if(doc.getLength() >= 5){
		text = "false";
		offset = 0;
		length = doc.getLength();
	}*/
	if(doc.getText(0,Math.min(1, doc.getLength())).equals("t") || doc.getText(0,Math.min(1, doc.getLength())).equals("T") || (text.equals("t")) || (text.equals("T")) || (text.equals("true"))){
		text = "true";
		offset = 0;
		length = doc.getLength();
	}else{
		text = "false";
		offset = 0;
		length = doc.getLength();
	}
	super.replace(fb, offset, length, text, attrs);
}
 
開發者ID:QuinnFreedman,項目名稱:THINK-VPL,代碼行數:25,代碼來源:VBoolean.java

示例9: replace

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String str, AttributeSet attrs) throws BadLocationException {
    //XXX Attention : par défaut, dans Swing, insertString et remove appellent tous les deux replace, et non l'inverse
    if(str!=null && str.length()!=0) {//y aura-t-il une insertion ?
        if(length>0) {//il y aura aussi un remove
            undo.valider();
            flagRemove=true; remove(fb, offset, length);//remove sans valider le groupe d'edit
            flagInsert=true; insertString(fb, offset, str, attrs);//insert sans valider le groupe d'edit
            flagInsert=false; flagRemove=false;
        } else {//il s'agissait d'un insert déguisé
            insertString(fb, offset, str, attrs);
        }
    } else {//il s'agissait d'un remove déguisé
        remove(fb, offset, length);
    }
}
 
開發者ID:Sharcoux,項目名稱:MathEOS,代碼行數:17,代碼來源:JMathTextPane.java

示例10: insertString

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)
        throws BadLocationException {
    if (useFilters) {
        // determine if we can insert
        if (console.getSelectionStart() >= console.editStart) {
            // can insert
            fb.insertString(offset, string, attr);
        } else {
            // insert at the end of the document
            fb.insertString(console.getText().length(), string, attr);
            // move cursor to the end
            console.getCaret().setDot(console.getText().length());
            // console.setSelectionEnd(console.getText().length());
            // console.setSelectionStart(console.getText().length());
        }
    } else {
        fb.insertString(offset, string, attr);
    }
}
 
開發者ID:opensim-org,項目名稱:opensim-gui,代碼行數:21,代碼來源:JConsole.java

示例11: replace

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
        throws BadLocationException {
    if (useFilters) {
        // determine if we can replace
        if (console.getSelectionStart() >= console.editStart) {
            // can replace
            fb.replace(offset, length, text, attrs);
        } else {
            // insert at end
            fb.insertString(console.getText().length(), text, attrs);
            // move cursor to the end
            console.getCaret().setDot(console.getText().length());
            // console.setSelectionEnd(console.getText().length());
            // console.setSelectionStart(console.getText().length());
        }
    } else {
        fb.replace(offset, length, text, attrs);
    }
}
 
開發者ID:opensim-org,項目名稱:opensim-gui,代碼行數:21,代碼來源:JConsole.java

示例12: remove

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException {
    if (useFilters) {
        if (offset > console.editStart) {
            // can remove
            fb.remove(offset, length);
        } else {
            // only remove the portion that's editable
            fb.remove(console.editStart, length - (console.editStart - offset));
            // move selection to the start of the editable section
            console.getCaret().setDot(console.editStart);
            // console.setSelectionStart(console.editStart);
            // console.setSelectionEnd(console.editStart);
        }
    } else {
        fb.remove(offset, length);
    }
}
 
開發者ID:opensim-org,項目名稱:opensim-gui,代碼行數:19,代碼來源:JConsole.java

示例13: replace

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String string, AttributeSet attrs) throws BadLocationException {
    Document document = fb.getDocument();
    if (length > 0) {
        fb.remove(offset, length);
    }
    for (int i = 0; i < string.length(); i++) {
        char charNow = string.charAt(i);
        if (Character.isDigit(charNow)) {
            fb.replace(offset, 0, String.valueOf(charNow), attrs);
        } else if (charNow == '.' || charNow == ',') {
            if (!document.getText(0, document.getLength()).contains(".")) {
                fb.replace(offset, 0, ".", attrs);

            }
        }
        offset++;
    }
}
 
開發者ID:jmayer13,項目名稱:academia_biometria,代碼行數:20,代碼來源:DecimalNumberDocumentFilter.java

示例14: insertString

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
	String content = fb.getDocument().getText(0, fb.getDocument().getLength());
	StringBuffer sb = new StringBuffer();
	if (offset < fb.getDocument().getLength()) {
		if (offset>0) sb.append(content.substring(0, offset));
		sb.append(string);
		sb.append(content.substring(offset, content.length()));
	}
	else {
		sb.append(content);
		sb.append(string);
	}
	
	super.insertString(fb, offset, string, attr);
	
	boolean success;
	if (!(success=validator.validateString(window, sb.toString())))
		super.remove(fb, offset, string.length());
	
	if (output!=null)
		notifyOutput(success);
}
 
開發者ID:relvaner,項目名稱:tools4j-validator,代碼行數:24,代碼來源:ValidationDocumentFilter.java

示例15: buildFilter

import javax.swing.text.DocumentFilter; //導入依賴的package包/類
public static DocumentFilter buildFilter(DocumentFilterType type, boolean notNull) {
	
	DocumentFilter filter = new DocumentFilter();
	
	switch(type) {
		
		case INT:
			filter = new IntFilter(notNull);
		break;
			
		case DATABASE_COLUMN_NAME_LENGTH:
			filter = new DatabaseColumnNameLengthFilter();
		break;
	}
	
	return filter;
}
 
開發者ID:ligenzatomas,項目名稱:firebird-vizualization-tool,代碼行數:18,代碼來源:DocumentFilterFactory.java


注:本文中的javax.swing.text.DocumentFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。