org.jpedal.objects.acroforms.creation.RadioListener 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@
*
* ---------------
* RadioListener.java
* ---------------
*/
package org.jpedal.objects.acroforms.creation;
import javax.swing.AbstractButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jpedal.objects.raw.FormObject;
/**
* listener to ensure that if component directly accessed it synchronized with
* our FormObject
*/
public class RadioListener implements ChangeListener {
final AbstractButton comp;
final FormObject form;
//boolean avoidLooping = false;
RadioListener(final AbstractButton comp, final FormObject form) {
this.comp = comp;
this.form = form;
}
@Override
public void stateChanged(final ChangeEvent e) {
//idea for another day
// if(avoidLooping){ //swallow the extra call we created by reseting
// avoidLooping=false;
// }else if(form.isReadOnly()){ //not allowed so restore
// comp.setSelected(!comp.isSelected());
// avoidLooping=true;
// }else{
form.updateValue(comp.getText(), comp.isSelected(), false); //false is critical to stop it looping
//}
}
}