Java Code Examples for javax.swing.event.DocumentListener

The following are top voted examples for showing how to use javax.swing.event.DocumentListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: SuiteCustomizerBasicBranding.java   Source Code and License 6 votes vote down vote up
/**
 * Creates new form SuiteCustomizerLibraries
 */
public SuiteCustomizerBasicBranding(final SuiteProperties suiteProps, ProjectCustomizer.Category cat, 
        BasicCustomizer.SubCategoryProvider prov) {
    super(suiteProps, SuiteCustomizerBasicBranding.class, cat);
    initComponents();        
    this.prov = prov;
    refresh(); 
    checkValidity();
    DocumentListener textFieldChangeListener = new UIUtil.DocumentAdapter() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            checkValidity();
        }
    };
    nameValue.getDocument().addDocumentListener(textFieldChangeListener);
}
 
Example 2
Project: incubator-netbeans   File: BasicBrandingPanel.java   Source Code and License 6 votes vote down vote up
public BasicBrandingPanel(BrandingModel model) {
    super(NbBundle.getMessage(BasicBrandingPanel.class, "LBL_BasicTab"), model); //NOI18N
    initComponents();        
    refresh(); 
    checkValidity();
    DocumentListener textFieldChangeListener = new UIUtil.DocumentAdapter() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            checkValidity();
            setModified();
            titleValueModified = true;
        }
    };
    titleValue.getDocument().addDocumentListener(textFieldChangeListener);
    titleValueModified = false;
}
 
Example 3
Project: incubator-netbeans   File: ViewUpdates.java   Source Code and License 6 votes vote down vote up
public ViewUpdates(DocumentView docView) {
    this.docView = docView;
    incomingModificationListener = new IncomingModificationListener();
    Document doc = docView.getDocument();
    // View hierarchy uses a pair of its own document listeners and DocumentView ignores
    // document change notifications sent from BasicTextUI.RootView.
    // First listener - incomingModificationListener at DocumentListenerPriority.FIRST notifies the hierarchy
    // about incoming document modification.
    // Second listener is "this" at DocumentListenerPriority.VIEW updates the view hierarchy structure
    // according to the document modification.
    // These two listeners avoid situation when a document modification modifies line structure
    // and so the view hierarchy (which uses swing Positions for line view statrts) is inconsistent
    // since e.g. with insert there may be gaps between views and with removal there may be overlapping views
    // but the document listeners that are just being notified include a highlighting layer's document listener
    // BEFORE the BasicTextUI.RootView listener. At that point the highlighting layer would fire a highlighting
    // change and the view hierarchy would attempt to rebuild itself but that would fail.
    listenerPriorityAwareDoc = DocumentUtilities.addPriorityDocumentListener(doc, 
            WeakListeners.create(DocumentListener.class, incomingModificationListener, null),
            DocumentListenerPriority.FIRST);
    // Add the second listener in all cases.
    DocumentUtilities.addDocumentListener(doc,
            WeakListeners.create(DocumentListener.class, this, doc),
            DocumentListenerPriority.VIEW);
}
 
Example 4
Project: incubator-netbeans   File: OutputDocument.java   Source Code and License 6 votes vote down vote up
public void addDocumentListener(DocumentListener listener) {
    if (listener == null) {
        return;
    }

    if (docListeners == null) {
        docListeners = new DocumentListener[1];
        docListeners[0] = listener;
    } else {
        DocumentListener[] oldArr = docListeners;
        docListeners = new DocumentListener[oldArr.length + 1];
        System.arraycopy(oldArr, 0,
                         docListeners, 0,
                         oldArr.length);
        docListeners[oldArr.length] = listener;
    }
}
 
Example 5
Project: incubator-netbeans   File: NameAndLocationPanel.java   Source Code and License 6 votes vote down vote up
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final NewLibraryDescriptor.DataModel data) {
    super(setting);
    this.data = data;
    initComponents();
    initAccessibility();
    putClientProperty("NewFileWizard_Title",// NOI18N
            NbBundle.getMessage(NameAndLocationPanel.class,"LBL_LibraryWizardTitle")); // NOI18N
    
    DocumentListener dListener = new UIUtil.DocumentAdapter() {
        public void insertUpdate(DocumentEvent e) {
            NewLibraryDescriptor.DataModel _data = getTemporaryDataModel();                
            setEnabledForFilesInfo(checkValidity(_data));
            setFilesInfoIntoTextAreas(_data);
        }
    };
    libraryNameVale.getDocument().addDocumentListener(dListener);
    libraryDisplayNameValue.getDocument().addDocumentListener(dListener);        
}
 
Example 6
Project: incubator-netbeans   File: NameIconLocationPanel.java   Source Code and License 6 votes vote down vote up
/** Creates new NameIconLocationPanel */
public NameIconLocationPanel(final WizardDescriptor setting, final DataModel data) {
    super(setting);
    this.data = data;
    initComponents();
    initAccessibility();
    putClientProperty("NewFileWizard_Title", getMessage("LBL_WizardWizardTitle"));
    DocumentListener updateListener = new UIUtil.DocumentAdapter() {
        public void insertUpdate(DocumentEvent e) {
            updateData();
        }
    };
    classNamePrefix.getDocument().addDocumentListener(updateListener);
    displayName.getDocument().addDocumentListener(updateListener);
    icon.getDocument().addDocumentListener(updateListener);        
    Component editorComp = packageName.getEditor().getEditorComponent();
    if (editorComp instanceof JTextComponent) {
        ((JTextComponent) editorComp).getDocument().addDocumentListener(updateListener);
    }
    if (category.getEditor().getEditorComponent() instanceof JTextField) {
        JTextComponent txt = (JTextComponent) category.getEditor().getEditorComponent();
        txt.getDocument().addDocumentListener(updateListener);
    }
}
 
Example 7
Project: incubator-netbeans   File: NameAndLocationPanel.java   Source Code and License 6 votes vote down vote up
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final HTMLIterator.DataModel data) {
    super(setting);
    this.data = data;
    initComponents();
    initAccessibility();
    putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle"));
    
    DocumentListener dListener = new UIUtil.DocumentAdapter() {
        public void insertUpdate(DocumentEvent e) {
            if (checkValidity()) {
                updateData();
            }
        }
    };
    txtPrefix.getDocument().addDocumentListener(dListener);
    txtIcon.getDocument().addDocumentListener(dListener);
    
    if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) {
        JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent();
        txt.getDocument().addDocumentListener(dListener);
    }
}
 
Example 8
Project: incubator-netbeans   File: NameAndLocationPanel.java   Source Code and License 6 votes vote down vote up
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) {
    super(setting);
    this.data = data;
    initComponents();
    initAccessibility();
    putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle"));
    
    DocumentListener dListener = new UIUtil.DocumentAdapter() {
        public void insertUpdate(DocumentEvent e) {
            if (checkValidity()) {
                updateData();
            }
        }
    };
    txtPrefix.getDocument().addDocumentListener(dListener);
    txtIcon.getDocument().addDocumentListener(dListener);
    
    if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) {
        JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent();
        txt.getDocument().addDocumentListener(dListener);
    }
}
 
Example 9
Project: incubator-netbeans   File: Repository.java   Source Code and License 6 votes vote down vote up
private void initPanel() {
    repositoryPanel = new RepositoryPanel();

    urlComboEditor = (JTextComponent) repositoryPanel.urlComboBox
                                      .getEditor().getEditorComponent();
    urlDoc = urlComboEditor.getDocument();
    usernameDoc = repositoryPanel.userTextField.getDocument();
    passwordDoc = repositoryPanel.userPasswordField.getDocument();
    tunnelCmdDoc = repositoryPanel.tunnelCommandTextField.getDocument();

    DocumentListener documentListener = new DocumentChangeHandler();
    urlDoc.addDocumentListener(documentListener);
    passwordDoc.addDocumentListener(documentListener);
    usernameDoc.addDocumentListener(documentListener);
    tunnelCmdDoc.addDocumentListener(documentListener);

    repositoryPanel.savePasswordCheckBox.addItemListener(this);
    repositoryPanel.urlComboBox.addItemListener(this);

    repositoryPanel.proxySettingsButton.addActionListener(this);

    repositoryPanel.userPasswordField.addFocusListener(this);

    tweakComboBoxEditor();
}
 
Example 10
Project: educational-plugin   File: StudyTwitterUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Listener updates label indicating remaining symbols number like in twitter.
 */
private static DocumentListener createTextFieldLengthDocumentListener(@NotNull TwitterDialogWrapper builder, @NotNull final StudyTwitterUtils.TwitterDialogPanel panel) {
  return new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      int length = e.getDocument().getLength();
      if (length > 140 || length == 0) {
        builder.setOKActionEnabled(false);
        panel.getRemainSymbolsLabel().setText("<html><font color='red'>" + String.valueOf(140 - length) + "</font></html>");
      } else {
        builder.setOKActionEnabled(true);
        panel.getRemainSymbolsLabel().setText(String.valueOf(140 - length));
      }

    }
  };
}
 
Example 11
Project: intellij-ce-playground   File: AppEngineCloudConfigurable.java   Source Code and License 6 votes vote down vote up
public AppEngineCloudConfigurable(@NotNull AppEngineServerConfiguration configuration,
                                  @Nullable Project project, boolean alwaysRememberPassword) {
  myConfiguration = configuration;
  myProject = project;
  ActionListener actionListener = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent event) {
      updateControls();
    }
  };
  myPasswordLoginButton.addActionListener(actionListener);
  myOAuthLoginButton.addActionListener(actionListener);
  DocumentListener documentListener = new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      updateControls();
    }
  };
  myEmailField.getDocument().addDocumentListener(documentListener);
  myPasswordField.getDocument().addDocumentListener(documentListener);
  myAlwaysRememberPassword = alwaysRememberPassword;
  updateControls();
}
 
Example 12
Project: intellij-ce-playground   File: GithubRepositoryEditor.java   Source Code and License 6 votes vote down vote up
public GithubRepositoryEditor(final Project project, final GithubRepository repository, Consumer<GithubRepository> changeListener) {
  super(project, repository, changeListener);
  myUrlLabel.setVisible(false);
  myUsernameLabel.setVisible(false);
  myUserNameText.setVisible(false);
  myPasswordLabel.setVisible(false);
  myPasswordText.setVisible(false);
  myUseHttpAuthenticationCheckBox.setVisible(false);

  myRepoAuthor.setText(repository.getRepoAuthor());
  myRepoName.setText(repository.getRepoName());
  myToken.setText(repository.getToken());
  myToken.setText(repository.getToken());
  myShowNotAssignedIssues.setSelected(!repository.isAssignedIssuesOnly());

  DocumentListener buttonUpdater = new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      updateTokenButton();
    }
  };

  myURLText.getDocument().addDocumentListener(buttonUpdater);
  myRepoAuthor.getDocument().addDocumentListener(buttonUpdater);
  myRepoName.getDocument().addDocumentListener(buttonUpdater);
}
 
Example 13
Project: intellij-ce-playground   File: HgTagDialog.java   Source Code and License 6 votes vote down vote up
public HgTagDialog(@NotNull Project project, @NotNull Collection<HgRepository> repositories, @Nullable HgRepository selectedRepo) {
  super(project, false);
  hgRepositorySelectorComponent.setTitle("Select repository to tag");
  DocumentListener documentListener = new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      validateFields();
    }
  };

  tagTxt.getDocument().addDocumentListener(documentListener);

  setTitle("Tag");
  init();

  setRoots(repositories, selectedRepo);
}
 
Example 14
Project: swingx   File: AutoCompleteDocument.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void changedUpdate(DocumentEvent e) {
    e = new DelegatingDocumentEvent(AutoCompleteDocument.this, e);

    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==DocumentListener.class) {
            // Lazily create the event:
            // if (e == null)
            // e = new ListSelectionEvent(this, firstIndex, lastIndex);
            ((DocumentListener)listeners[i+1]).changedUpdate(e);
        }
    }
}
 
Example 15
Project: swingx   File: AutoCompleteDocument.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void insertUpdate(DocumentEvent e) {
    e = new DelegatingDocumentEvent(AutoCompleteDocument.this, e);

    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==DocumentListener.class) {
            // Lazily create the event:
            // if (e == null)
            // e = new ListSelectionEvent(this, firstIndex, lastIndex);
            ((DocumentListener)listeners[i+1]).insertUpdate(e);
        }
    }
}
 
Example 16
Project: swingx   File: AutoCompleteDocument.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void removeUpdate(DocumentEvent e) {
    e = new DelegatingDocumentEvent(AutoCompleteDocument.this, e);

    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==DocumentListener.class) {
            // Lazily create the event:
            // if (e == null)
            // e = new ListSelectionEvent(this, firstIndex, lastIndex);
            ((DocumentListener)listeners[i+1]).removeUpdate(e);
        }
    }
}
 
Example 17
Project: aibench-project   File: AutoCompleteDocument.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void changedUpdate(DocumentEvent e) {
    e = new DelegatingDocumentEvent(AutoCompleteDocument.this, e);
    
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==DocumentListener.class) {
            // Lazily create the event:
            // if (e == null)
            // e = new ListSelectionEvent(this, firstIndex, lastIndex);
            ((DocumentListener)listeners[i+1]).changedUpdate(e);
        }          
    }
}
 
Example 18
Project: aibench-project   File: AutoCompleteDocument.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void insertUpdate(DocumentEvent e) {
    e = new DelegatingDocumentEvent(AutoCompleteDocument.this, e);
    
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==DocumentListener.class) {
            // Lazily create the event:
            // if (e == null)
            // e = new ListSelectionEvent(this, firstIndex, lastIndex);
            ((DocumentListener)listeners[i+1]).insertUpdate(e);
        }          
    }
}
 
Example 19
Project: aibench-project   File: AutoCompleteDocument.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void removeUpdate(DocumentEvent e) {
    e = new DelegatingDocumentEvent(AutoCompleteDocument.this, e);
    
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==DocumentListener.class) {
            // Lazily create the event:
            // if (e == null)
            // e = new ListSelectionEvent(this, firstIndex, lastIndex);
            ((DocumentListener)listeners[i+1]).removeUpdate(e);
        }          
    }
}
 
Example 20
Project: LoboBrowser   File: TextViewerWindow.java   Source Code and License 6 votes vote down vote up
public TextViewerWindow() {
  super("LoboBrowser Console");
  final UserAgentContext uaContext = null; // TODO
  this.setIconImage(DefaultWindowFactory.getInstance().getDefaultImageIcon(uaContext).getImage());
  final JMenuBar menuBar = this.createMenuBar();
  this.setJMenuBar(menuBar);
  final Container contentPane = this.getContentPane();
  final JTextArea textArea = createTextArea();
  this.textArea = textArea;
  contentPane.setLayout(WrapperLayout.getInstance());
  contentPane.add(new JScrollPane(textArea));
  this.addWindowListener(new java.awt.event.WindowAdapter() {
    @Override
    public void windowClosed(final WindowEvent e) {
      final DocumentListener cl = cachedListener;
      if (cl != null) {
        final Document prevDocument = textArea.getDocument();
        if (prevDocument != null) {
          prevDocument.removeDocumentListener(cl);
        }
      }
    }
  });
}
 
Example 21
Project: intelij-hippo-groovy   File: PluginConfiguration.java   Source Code and License 6 votes vote down vote up
public PluginConfiguration() {

        final DocumentListener listener = new DocumentAdapter() {
            @Override
            protected void textChanged(DocumentEvent documentEvent) {
                groovyDirectory.getText();
            }
        };
        groovyDirectory.getChildComponent().getDocument().addDocumentListener(listener);
        groovyDirectory.setTextFieldPreferredWidth(50);
        groovyDirectory.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                chooseFolder(groovyDirectory, false);
            }
        });


    }
 
Example 22
Project: breakout   File: AnnotatingJTables.java   Source Code and License 6 votes vote down vote up
public static DocumentListener createFilterFieldListener(
		final AnnotatingJTable table, final JTextComponent filterField,
		final RowFilterFactory<String, TableModel, Integer> filterFactory) {
	return new EasyDocumentListener() {
		@Override
		public void documentChanged(DocumentEvent e) {
			if (table.getAnnotatingRowSorter() == null) {
				return;
			}
			if (filterField.getText() != null && filterField.getText().length() > 0) {
				RowFilter<TableModel, Integer> filter = null;
				try {
					filter = filterFactory.createFilter(filterField.getText());
					filterField.setForeground(Color.BLACK);
				} catch (Exception ex) {
					filterField.setForeground(Color.RED);
				}
				table.getAnnotatingRowSorter().setRowFilter(filter);
			} else {
				filterField.setForeground(Color.BLACK);

				table.getAnnotatingRowSorter().setRowFilter(null);
			}
		}
	};
}
 
Example 23
Project: intellij-xquery   File: ConnectionParametersPanel.java   Source Code and License 6 votes vote down vote up
private void setUpChangeListeners(final DataSourceConfigurationAggregatingPanel
                                          aggregatingPanel,
                                  final ConfigurationChangeListener listener) {
    DocumentListener textFieldListener = new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            listener.changeApplied(aggregatingPanel
                    .getCurrentConfigurationState());
        }
    };
    host.getComponent().getDocument().addDocumentListener(textFieldListener);
    port.getComponent().getDocument().addDocumentListener(textFieldListener);
    username.getComponent().getDocument().addDocumentListener(textFieldListener);
    password.getComponent().getDocument().addDocumentListener(textFieldListener);
    databaseName.getComponent().getDocument().addDocumentListener(textFieldListener);
}
 
Example 24
Project: incubator-netbeans   File: BaseDocument.java   Source Code and License 5 votes vote down vote up
void firePreRemoveUpdate(DefaultDocumentEvent chng) {
    // Notify the remove update listeners - before the actual remove happens
    // so that it adheres to removeUpdate() logic; also the listeners can check
    // positions' offsets before the actual removal happens.
    for (DocumentListener listener: updateDocumentListenerList.getListeners()) {
        listener.removeUpdate(chng);
    }
}
 
Example 25
Project: incubator-netbeans   File: BaseDocument.java   Source Code and License 5 votes vote down vote up
@Override
   public void addDocumentListener(DocumentListener listener) {
       if (LOG_LISTENER.isLoggable(Level.FINE)) {
           LOG_LISTENER.fine("ADD DocumentListener of class " + listener.getClass() + " to existing " +
                   org.netbeans.lib.editor.util.swing.DocumentUtilities.getDocumentListenerCount(this) +
                   " listeners. Listener: " + listener + '\n'
           );
           if (LOG_LISTENER.isLoggable(Level.FINER)) {
               LOG_LISTENER.log(Level.FINER, "    StackTrace:\n", new Exception());
           }
       }
if (!org.netbeans.lib.editor.util.swing.DocumentUtilities.addPriorityDocumentListener(
               this, listener, DocumentListenerPriority.DEFAULT))
           super.addDocumentListener(listener);
   }
 
Example 26
Project: incubator-netbeans   File: BaseDocument.java   Source Code and License 5 votes vote down vote up
@Override
   public void removeDocumentListener(DocumentListener listener) {
       if (LOG_LISTENER.isLoggable(Level.FINE)) {
           LOG_LISTENER.fine("REMOVE DocumentListener of class " + listener.getClass() + " from existing " +
                   org.netbeans.lib.editor.util.swing.DocumentUtilities.getDocumentListenerCount(this) +
                   " listeners. Listener: " + listener + '\n'
           );
           if (LOG_LISTENER.isLoggable(Level.FINER)) {
               LOG_LISTENER.log(Level.FINER, "    StackTrace:\n", new Exception());
           }
       }
if (!org.netbeans.lib.editor.util.swing.DocumentUtilities.removePriorityDocumentListener(
               this, listener, DocumentListenerPriority.DEFAULT))
           super.removeDocumentListener(listener);
   }
 
Example 27
Project: incubator-netbeans   File: XMLSyntaxSupport.java   Source Code and License 5 votes vote down vote up
/** Creates new XMLSyntaxSupport */
public XMLSyntaxSupport(BaseDocument doc) {
    super(doc);
    
    // listener has same lifetime as this class
    documentMonitor = new DocumentMonitor();
    DocumentListener l = WeakListeners.document(documentMonitor, doc);
    doc.addDocumentListener(l);
    
}
 
Example 28
Project: incubator-netbeans   File: OutputDocument.java   Source Code and License 5 votes vote down vote up
public void removeDocumentListener(DocumentListener listener) {
    if (listener == null) {
        return;
    }

    if (docListeners == null) {
        return;
    }

    int index = -1;
    for (int i = 0; i < docListeners.length; i++) {
        if (docListeners[i] == listener) {
            index = i;
            break;
        }
    }
    if (index != -1) {
        if (docListeners.length == 1) {
            docListeners = null;
        } else {
            DocumentListener[] oldArr = docListeners;
            docListeners = new DocumentListener[oldArr.length - 1];
            if (index != 0) {
                System.arraycopy(oldArr, 0,
                                 docListeners, 0,
                                 index);
            }
            if (index != oldArr.length - 1) {
                System.arraycopy(oldArr, index + 1,
                                 docListeners, index,
                                 oldArr.length - (index + 1));
            }
        }
    }
}
 
Example 29
Project: incubator-netbeans   File: XmlMultiViewEditorSupport.java   Source Code and License 5 votes vote down vote up
public void run() {
    Document document = getDocument();
    DocumentListener listener = document == null ? null :
        (DocumentListener) document.getProperty(PROPERTY_MODIFICATION_LISTENER);
    if (listener != null) {
        document.removeDocumentListener(listener);
    }
    try {
        reloadModel();
    } finally {
        if (listener != null) {
            document.addDocumentListener(listener);
        }
    }
}
 
Example 30
Project: incubator-netbeans   File: PropertiesTableCellEditor.java   Source Code and License 5 votes vote down vote up
/** Constructs a PropertiesTableCellEditor that uses a text field.
 * @param tf  a JTextField object ...
 * @param  commentComponent
 * @param valueComponent
 * @param valueLabel
 * @param listener 
 */
public PropertiesTableCellEditor(JTextField tf, final JTextComponent commentComponent,
    final JTextComponent valueComponent, final JLabel valueLabel, DocumentListener listener) {
    super(tf);
    // Number of clicks needed to edit an editable cell.
    this.clickCountToStart = 1;
    this.listener = listener;
    this.valueComponent = valueComponent;
    this.commentComponent = commentComponent;
    valueComponent.setDocument(tf.getDocument());
    this.delegate = new PropertiesEditorDelegate(commentComponent, valueComponent, valueLabel);
    ((JTextField)editorComponent).addActionListener(delegate);
    
    settings = TableViewSettings.getDefault();
}
 
Example 31
Project: incubator-netbeans   File: AbstractDocumentModel.java   Source Code and License 5 votes vote down vote up
private DocumentListener getDelegate() {
    DocumentListener l = delegate.get();
    if (l == null) {
	source.removeDocumentListener(this);
    }
    
    return l;
}
 
Example 32
Project: incubator-netbeans   File: AbstractDocumentModel.java   Source Code and License 5 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    DocumentListener l = getDelegate();
    if (l != null) {
	l.removeUpdate(e);
    }
}
 
Example 33
Project: incubator-netbeans   File: AbstractDocumentModel.java   Source Code and License 5 votes vote down vote up
@Override
public void changedUpdate(DocumentEvent e) {
    DocumentListener l = getDelegate();
    if (l != null) {
	l.changedUpdate(e);
    }
}
 
Example 34
Project: incubator-netbeans   File: AbstractDocumentModel.java   Source Code and License 5 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent e) {
    DocumentListener l = getDelegate();
    if (l != null) {
	l.insertUpdate(e);
    }
}
 
Example 35
Project: incubator-netbeans   File: PriorityDocumentListenerList.java   Source Code and License 5 votes vote down vote up
/**
 * Implementation of DocumentListener's method fires all the added
 * listeners according to their priority.
 */
public void insertUpdate(DocumentEvent evt) {
    logEvent(evt, "insertUpdate");
    // Fire the prioritized listeners
    EventListener[][] listenersArray = getListenersArray();
    // Attempt to fire to all listeners catching possible exception(s) and report first fired then
    RuntimeException runtimeException = null;
    for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
        logPriority(priority);
        EventListener[] listeners = listenersArray[priority];
        for (int i = listeners.length - 1; i >= 0; i--) {
            DocumentListener l = (DocumentListener) listeners[i];
            logListener(l);
            try {
                l.insertUpdate(evt);
            } catch (RuntimeException ex) {
                if (runtimeException == null) { // Only record first thrown
                    runtimeException = ex;
                }
            }
        }
    }
    if (runtimeException != null) {
        throw runtimeException; // Re-throw remembered exception
    }
    logEventEnd("insertUpdate");
}
 
Example 36
Project: incubator-netbeans   File: PriorityDocumentListenerList.java   Source Code and License 5 votes vote down vote up
/**
 * Implementation of DocumentListener's method fires all the added
 * listeners according to their priority.
 */
public void removeUpdate(DocumentEvent evt) {
    logEvent(evt, "removeUpdate");
    // Fire the prioritized listeners
    EventListener[][] listenersArray = getListenersArray();
    // Attempt to fire to all listeners catching possible exception(s) and report first fired then
    RuntimeException runtimeException = null;
    for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
        logPriority(priority);
        EventListener[] listeners = listenersArray[priority];
        for (int i = listeners.length - 1; i >= 0; i--) {
            DocumentListener l = (DocumentListener) listeners[i];
            logListener(l);
            try {
                l.removeUpdate(evt);
            } catch (RuntimeException ex) {
                if (runtimeException == null) { // Only record first thrown
                    runtimeException = ex;
                }
            }
        }
    }
    if (runtimeException != null) {
        throw runtimeException; // Re-throw remembered exception
    }
    logEventEnd("removeUpdate");
}
 
Example 37
Project: incubator-netbeans   File: PriorityDocumentListenerList.java   Source Code and License 5 votes vote down vote up
/**
 * Implementation of DocumentListener's method fires all the added
 * listeners according to their priority.
 */
public void changedUpdate(DocumentEvent evt) {
    logEvent(evt, "changedUpdate");
    // Fire the prioritized listeners
    EventListener[][] listenersArray = getListenersArray();
    // Attempt to fire to all listeners catching possible exception(s) and report first fired then
    RuntimeException runtimeException = null;
    for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
        logPriority(priority);
        EventListener[] listeners = listenersArray[priority];
        for (int i = listeners.length - 1; i >= 0; i--) {
            DocumentListener l = (DocumentListener) listeners[i];
            logListener(l);
            try {
                l.changedUpdate(evt);
            } catch (RuntimeException ex) {
                if (runtimeException == null) { // Only record first thrown
                    runtimeException = ex;
                }
            }
        }
    }
    if (runtimeException != null) {
        throw runtimeException; // Re-throw remembered exception
    }
    logEventEnd("changedUpdate");
}
 
Example 38
Project: incubator-netbeans   File: QuickSearchPanel.java   Source Code and License 5 votes vote down vote up
QuickSearchPanel(WizardDescriptor settings, DataModel data) {
    super(settings);
    this.data = data;
    initComponents();

    putClientProperty("NewFileWizard_Title", getMessage("LBL_QuickSearchPanel_Title"));

    DocumentListener dListener = new UIUtil.DocumentAdapter() {

        public void insertUpdate(DocumentEvent e) {
            checkValidity();
        }
    };

    if (data.getPackageName() != null) {
        packageCombo.setSelectedItem(data.getPackageName());
    }

    classNameTextField.getDocument().addDocumentListener(dListener);
    categoryNameTextField.getDocument().addDocumentListener(dListener);
    commandPrefixTextField.getDocument().addDocumentListener(dListener);
    positionTextField.getDocument().addDocumentListener(dListener);
    Component editorComp = packageCombo.getEditor().getEditorComponent();
    if (editorComp instanceof JTextComponent) {
        ((JTextComponent) editorComp).getDocument().addDocumentListener(dListener);
    }
}
 
Example 39
Project: incubator-netbeans   File: NameAndLocationPanel.java   Source Code and License 5 votes vote down vote up
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final NewLoaderIterator.DataModel data) {
    super(setting);
    this.data = data;
    initComponents();
    initAccessibility();
    putClientProperty("NewFileWizard_Title", getMessage("LBL_LoaderWizardTitle"));
    
    DocumentListener dListener = new UIUtil.DocumentAdapter() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            if (checkValidity()) {
                updateData();
            }
        }
    };
    txtPrefix.getDocument().addDocumentListener(dListener);
    txtIcon.getDocument().addDocumentListener(dListener);
    
    if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) {
        JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent();
        txt.getDocument().addDocumentListener(dListener);
    }
    
    if (data.canUseMultiview()) {
        useMultiView.setEnabled(true);
        useMultiView.setSelected(true);
    } else {
        useMultiView.setEnabled(false);
        useMultiView.setSelected(false);
    }
}
 
Example 40
Project: incubator-netbeans   File: CodeGeneratorPanel.java   Source Code and License 5 votes vote down vote up
/** Creates new form CodeGeneratorPanel */
CodeGeneratorPanel(WizardDescriptor settings, NewCodeGeneratorIterator.DataModel data) {
    super(settings);
    this.data = data;
    initComponents();
    
    putClientProperty("NewFileWizard_Title", getMessage("LBL_CodeGeneratorPanel_Title"));
    
    DocumentListener dListener = new UIUtil.DocumentAdapter() {
        public void insertUpdate(DocumentEvent e) {
            checkValidity();
        }
    };
    
    if (data.getPackageName() != null) {
        packageNameCombo.setSelectedItem(data.getPackageName());
    }
    
    fileNametextField.getDocument().addDocumentListener(dListener);
    cpFileNameField.getDocument().addDocumentListener(dListener);
    mimeTypeTextField.getDocument().addDocumentListener(dListener);
    Component editorComp = packageNameCombo.getEditor().getEditorComponent();
    if (editorComp instanceof JTextComponent) {
        ((JTextComponent) editorComp).getDocument().addDocumentListener(dListener);
    }
    
}