本文整理汇总了Java中javax.swing.event.DocumentEvent类的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent类的具体用法?Java DocumentEvent怎么用?Java DocumentEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentEvent类属于javax.swing.event包,在下文中一共展示了DocumentEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
/**
* This method implements the <code>DocumentListener</code>.
* <br>
* It is not intended to be called by clients.
*/
public void insertUpdate(DocumentEvent evt) {
// Check whether there was an insert done right
// at the original ending offset of the fold
// so the fold end offset should be moved back.
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("insertUpdate: offset=" + evt.getOffset() // NOI18N
+ ", length=" + evt.getLength() + '\n'); // NOI18N
}
try {
if (FoldHierarchyExecution.isEventInUndoRedoHack(evt)) {
validateAffectedFolds(execution.getRootFold(), evt);
}
insertCheckEndOffset(execution.getRootFold(), evt);
} catch (BadLocationException e) {
ErrorManager.getDefault().notify(e);
}
}
示例2: updateTexts
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
/** Handles changes in the Project name and project directory
*/
private void updateTexts(DocumentEvent e) {
Document doc = e.getDocument();
if (doc.equals(projectNameTextField.getDocument()) || doc.equals(projectLocationTextField.getDocument())) {
// Change in the project name
String projectName = projectNameTextField.getText();
String projectFolder = projectLocationTextField.getText();
String projFolderPath = FileUtil.normalizeFile(new File(projectFolder)).getAbsolutePath();
if (projFolderPath.endsWith(File.separator)) {
createdFolderTextField.setText(projFolderPath + projectName);
} else {
createdFolderTextField.setText(projFolderPath + File.separator + projectName);
}
}
panel.fireChangeEvent(); // Notify that the panel changed
if (this.projectNameTextField.getDocument().equals(e.getDocument())) {
firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
}
if (this.projectLocationTextField.getDocument().equals(e.getDocument())) {
firePropertyChange(PROP_PROJECT_LOCATION, null, this.projectLocationTextField.getText());
}
}
示例3: BasicBrandingPanel
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
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;
}
示例4: updateDefaultDirectory
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
private void updateDefaultDirectory(DocumentEvent e) {
Document doc = e.getDocument();
if (doc.equals(username.getDocument())) {
String usernameText = username.getText();
if (!usernameText.isEmpty()) {
String workdirText = workingDir.getText();
if (workdirText.isEmpty() || (currentDefaultWorkDir != null && workdirText.equals(currentDefaultWorkDir))) {
String updatedDefaultworkDir = "/home/" + usernameText + "/NetBeansProjects/"; //NOI18N
workingDir.setText(updatedDefaultworkDir);
currentDefaultWorkDir = updatedDefaultworkDir;
}
} else {
if (currentDefaultWorkDir != null && workingDir.getText().equals(currentDefaultWorkDir)) {
workingDir.setText(""); //NOI18N
currentDefaultWorkDir = null;
}
}
}
}
示例5: createTextFieldLengthDocumentListener
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
/**
* 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));
}
}
};
}
示例6: removeUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
/** Remove from document notification. */
public void removeUpdate(DocumentEvent evt) {
checkLengthyAtomicEdit(evt);
// No longer trigger syntax update related repaint
// try {
// BaseDocumentEvent bevt = (BaseDocumentEvent)evt;
// EditorUI eui = getEditorUI();
// int y = getYFromPos(evt.getOffset());
// int lineHeight = eui.getLineHeight();
// int syntaxY = getYFromPos(bevt.getSyntaxUpdateOffset());
// // !!! patch for case when DocMarksOp.eolMark is at the end of document
// if (bevt.getSyntaxUpdateOffset() == evt.getDocument().getLength()) {
// syntaxY += lineHeight;
// }
// if (getComponent().isShowing()) {
// eui.repaint(y, Math.max(lineHeight, syntaxY - y));
// }
//
// } catch (BadLocationException ex) {
// Utilities.annotateLoggable(ex);
// }
}
示例7: changeTab
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
/**
* ȭ���� ������ �ٲ� Ouput�� ���̰� ��ȯ�Ѵ�.
*/
private void changeTab( DocumentEvent e ) {
if ( e.getDocument() == outputStd.getOutput().getDocument() ) {
if ( tabPane.getSelectedComponent() != outputStd )
tabPane.setSelectedComponent(outputStd);
} else if ( e.getDocument() == outputErr.getOutput().getDocument() ) {
if ( tabPane.getSelectedComponent() != outputErr )
tabPane.setSelectedComponent(outputErr);
}
}
示例8: removeUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
/** Gives notification from the document that attributes were removed
* in a location that this view is responsible for.
*
* @param e the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
*/
public @Override void removeUpdate(DocumentEvent evt, Shape a, ViewFactory f) {
try {
BaseDocumentEvent bevt = (BaseDocumentEvent)evt;
EditorUI editorUI = getEditorUI();
int y = getYFromPos(evt.getOffset());
int lineHeight = editorUI.getLineHeight();
if (bevt.getLFCount() > 0) { // one or more lines removed
int removeHeight = bevt.getLFCount() * lineHeight;
mainHeight -= removeHeight;
editorUI.repaint(y);
} else { // removing on one line
int syntaxY = getYFromPos(bevt.getSyntaxUpdateOffset());
// !!! patch for case when DocMarksOp.eolMark is at the end of document
if (bevt.getSyntaxUpdateOffset() == evt.getDocument().getLength()) {
syntaxY += lineHeight;
}
if (getComponent().isShowing()) {
editorUI.repaint(y, Math.max(lineHeight, syntaxY - y));
}
}
} catch (BadLocationException ex) {
Utilities.annotateLoggable(ex);
}
}
示例9: changedUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
public void changedUpdate( DocumentEvent e ) {
updateTexts( e );
if (this.projectNameTextField.getDocument() == e.getDocument()) {
firePropertyChange (PROP_PROJECT_NAME,null,this.projectNameTextField.getText());
}
if (this.projectLocationTextField.getDocument() == e.getDocument()) {
firePropertyChange (PROP_PROJECT_LOCATION,null,this.projectLocationTextField.getText());
}
}
示例10: insertUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
@Override
public void insertUpdate(DocumentEvent e) {
try {
Vector<String> vectorOfStrings = new Vector<String>();
for (int i = 0; i < getModel().getSize(); i++) {
vectorOfStrings.add(String.valueOf(getModel().getElementAt(i)));
}
Document document = e.getDocument();
String documentText = document.getText(0, document.getLength());
final String result = checkForMatch(documentText, vectorOfStrings, caseSensitive);
final String newString = (result == null) ? documentText : result;
final int startSelect = document.getLength();
final int endSelect = newString.length();
final JTextField editorComponent = (JTextField) getEditor().getEditorComponent();
if (startSelect == e.getOffset() + e.getLength()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setSelectedItem(newString);
editorComponent.getDocument().removeDocumentListener(docListener);
editorComponent.setText(newString);
editorComponent.getDocument().addDocumentListener(docListener);
Caret caret = editorComponent.getCaret();
caret.setDot(endSelect);
caret.moveDot(startSelect);
}
});
}
} catch (BadLocationException e1) {
}
}
示例11: insertUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
@Override
public void insertUpdate(DocumentEvent de) {
if(!listen) return;
try {
String added = pane.getStyledDocument().getText(de.getOffset(), de.getLength());
TextAddedAction action = new TextAddedAction(
new TextDelta(de.getOffset(), added),
pane.getStyledDocument());
actionList.add(action);
} catch (BadLocationException ex) {
Logger.getLogger(TextChangedActionAdder.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例12: removeUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
@Override
public void removeUpdate( DocumentEvent arg0 ) {
if (this.room != null) {
this.room.setNotes( this.roomNotes.getText() );
}
}
示例13: processInsert
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
private void processInsert(DocumentEvent e) throws BadLocationException {
final Document document = e.getDocument();
Element root = document.getDefaultRootElement();
int start = root.getElementIndex(e.getOffset());
int end = root.getElementIndex(e.getOffset() + e.getLength() - 1);
Element startElement = root.getElement(start);
Element endElement = root.getElement(end);
if (start == end) {
String newValue = getText(document, startElement);
replaceLine(document, start, newValue);
if (e.getOffset() + e.getLength() == startElement.getEndOffset()) {
Element startNext = root.getElement(start + 1);
insertLines(document, start + 1, Collections.singletonList(
getText(document, startNext)
));
}
} else {
removeLines(document, start, start);
List<String> lines = new ArrayList<>();
for (int line = start; line <= end; ++line) {
lines.add(getText(document, root.getElement(line)));
}
if (e.getOffset() + e.getLength() == endElement.getEndOffset() && end + 1 < root.getElementCount()) {
Element endNext = root.getElement(end + 1);
lines.add(getText(document, endNext));
}
insertLines(document, start, lines);
}
}
示例14: forwardUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
protected void forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e, Shape a, ViewFactory f) {
super.forwardUpdate(ec, e, a, f);
// A change in any of the table cells usually effects the whole table,
// so redraw it all!
if (a != null) {
Component c = getContainer();
if (c != null) {
Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
a.getBounds();
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
}
示例15: insertUpdate
import javax.swing.event.DocumentEvent; //导入依赖的package包/类
/** Gives notification that something was inserted into the document
* in a location that this view is responsible for.
*
* @param e the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
*/
public @Override void insertUpdate(DocumentEvent evt, Shape a, ViewFactory f) {
try {
BaseDocumentEvent bevt = (BaseDocumentEvent)evt;
EditorUI editorUI = getEditorUI();
int y = getYFromPos(evt.getOffset());
int lineHeight = editorUI.getLineHeight();
if (bevt.getLFCount() > 0) { // one or more lines inserted
int addHeight = bevt.getLFCount() * lineHeight;
mainHeight += addHeight;
editorUI.repaint(y);
} else { // inserting on one line
int syntaxY = getYFromPos(bevt.getSyntaxUpdateOffset());
// !!! patch for case when DocMarksOp.eolMark is at the end of document
if (bevt.getSyntaxUpdateOffset() == evt.getDocument().getLength()) {
syntaxY += lineHeight;
}
if (getComponent().isShowing()) {
editorUI.repaint(y, Math.max(lineHeight, syntaxY - y));
}
}
} catch (BadLocationException ex) {
Utilities.annotateLoggable(ex);
}
}