Java Code Examples for javax.swing.text.AbstractDocument#setDocumentFilter()

The following examples show how to use javax.swing.text.AbstractDocument#setDocumentFilter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsoleModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void init() {
    AbstractDocument ad = LineDocumentUtils.asRequired(document, AbstractDocument.class);
    this.valid = true;
    ad.setDocumentFilter(new DocFilter());
    try {
        // initialize the bypass:
        ad.replace(0, 0, "", null);
    } catch (BadLocationException ex) {
    }
    org.netbeans.lib.editor.util.swing.DocumentUtilities.addPriorityDocumentListener(document,
            l = new DocL(), DocumentListenerPriority.CARET_UPDATE);
}
 
Example 2
Source File: BasicSearchForm.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setLengthFilter(JComboBox<?> cb) {
    Component editorComponent = cb.getEditor().getEditorComponent();
    if (editorComponent instanceof JTextComponent) {
        JTextComponent tc = (JTextComponent) editorComponent;
        Document document = tc.getDocument();
        if (document instanceof AbstractDocument) {
            AbstractDocument ad = (AbstractDocument) document;
            ad.setDocumentFilter(lengthFilter);
        }
    }
}
 
Example 3
Source File: JIntegerTextField.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
public JIntegerTextField(int preferredWidthFromColumnCount) {
    super(preferredWidthFromColumnCount);
    setText("" + getDefaultValue());
    selectAll();
    AbstractDocument document = (AbstractDocument) this.getDocument();
    document.setDocumentFilter(new IntegerFilter(this));
    getDocument().addDocumentListener(new NumberListener());
}
 
Example 4
Source File: SimpleTestStepLocation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 */
void setUp(final JUnitUtils utils) {
    final Project project = utils.getProject();
    
    if (project == this.project) {
        return;
    }
    
    this.project = project;
    this.sourcesToTestsMap = utils.getSourcesToTestsMap(true);
    
    int sourceGroupsCnt = sourcesToTestsMap.size();
    Set<Map.Entry<SourceGroup,Object[]>> mapEntries = sourcesToTestsMap.entrySet();
    List<SourceGroup> testGroups = new ArrayList<SourceGroup>(sourceGroupsCnt + 4);
    
    testableSourceGroups = new SourceGroup[sourceGroupsCnt];
    testableSourceGroupsRoots = new FileObject[sourceGroupsCnt];
    multipleSourceRoots = (sourceGroupsCnt > 1);
    
    Iterator<Map.Entry<SourceGroup,Object[]>> iterator = mapEntries.iterator();
    for (int i = 0; i < sourceGroupsCnt; i++) {
        Map.Entry<SourceGroup,Object[]> entry = iterator.next();
        SourceGroup srcGroup = entry.getKey();
        
        testableSourceGroups[i] = srcGroup;
        testableSourceGroupsRoots[i] = srcGroup.getRootFolder();
        
        Object[] testGroupsSubset = entry.getValue();
        for (int j = 0; j < testGroupsSubset.length; j++) {
            SourceGroup testGroup = (SourceGroup) testGroupsSubset[j];
            if (!testGroups.contains(testGroup)) {
                testGroups.add(testGroup);
            }
        }
    }
    allTestSourceGroups = testGroups.toArray(
                                        new SourceGroup[testGroups.size()]);
    
    tfProjectName.setText(
            ProjectUtils.getInformation(project).getDisplayName());
    try {
        programmaticChange = true;
        
        ignoreClsNameChanges = true;
        tfClassToTest.setText("");                                  //NOI18N
        ignoreClsNameChanges = false;
        
        classNameLength = 0;
        classNameChanged();
        srcGroupNameDisplayed = false;
        setNavigationFilterEnabled(false);
    } finally {
        ignoreClsNameChanges = false;
        programmaticChange = false;
    }
    if (checkClassNameValidity()) {
        checkSelectedClassExists();
    } else {
        classExists = false;
    }
    setErrorMsg(errMsg);
    setValidity();
    
    //PENDING - if possible, we should pre-set the test source group
    //          corresponding to the currently selected node
    updateLocationComboBox();
    updateTargetFolderData();           //sets also 'testRootFolder'
    updateCreatedFileName();
    
    srcFile = null;
    
    if (!multipleSourceRoots) {
        setInteractionRestrictionsEnabled(false);
    } else {
        AbstractDocument doc = (AbstractDocument)
                               tfClassToTest.getDocument();
        if (clsNameDocumentFilter == null) {
            clsNameDocumentFilter = new ClsNameDocumentFilter();
        }
        if (doc.getDocumentFilter() != clsNameDocumentFilter) {
            doc.setDocumentFilter(clsNameDocumentFilter);
        }
        setInteractionRestrictionsEnabled(true);
    }
}