All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.objects.acroforms.creation.TextDocumentListener Maven / Gradle / Ivy

/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * TextDocumentListener.java
 * ---------------
 */
package org.jpedal.objects.acroforms.creation;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.JTextComponent;

import org.jpedal.objects.raw.FormObject;

/**
 * listener to ensure that if component directly accesed it synchronized with
 * our FormObject
 */
public class TextDocumentListener implements DocumentListener {

    final JTextComponent textcomp;
    final FormObject form;

    TextDocumentListener(final JTextComponent textcomp, final FormObject form) {
        this.textcomp = textcomp;
        this.form = form;
    }

    @Override
    public void changedUpdate(final DocumentEvent e) {
        updateFormValue();
    }

    @Override
    public void removeUpdate(final DocumentEvent e) {
        updateFormValue();
    }

    @Override
    public void insertUpdate(final DocumentEvent e) {
        updateFormValue();
    }

    /**
     * write value back to our Object from GUI widget
     */
    private void updateFormValue() {
        form.updateValue(textcomp.getText(), false, false);  //last false is critical to stop it looping
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy