use of javax.swing.event.UndoableEditEvent in project pcgen by PCGen.
the class ExtendedHTMLDocument method replaceAttributes.
/**
* Replaces attributes on a tag. Used by Swing.
*
* @param e the element to edit
* @param a the attributes to change
* @param tag the tag to edit
*/
public void replaceAttributes(Element e, AttributeSet a, Tag tag) {
writeLock();
if ((e != null) && (a != null)) {
try {
int start = e.getStartOffset();
DefaultDocumentEvent changes = new DefaultDocumentEvent(start, e.getEndOffset() - start, EventType.CHANGE);
AttributeSet sCopy = a.copyAttributes();
changes.addEdit(new AttributeUndoableEdit(e, sCopy, false));
MutableAttributeSet attr = (MutableAttributeSet) e.getAttributes();
Enumeration<?> aNames = attr.getAttributeNames();
while (aNames.hasMoreElements()) {
Object aName = aNames.nextElement();
Object value = attr.getAttribute(aName);
if ((value != null) && !value.toString().equalsIgnoreCase(tag.toString())) {
attr.removeAttribute(aName);
}
}
attr.addAttributes(a);
changes.end();
fireChangedUpdate(changes);
fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
} finally {
writeUnlock();
}
}
}
use of javax.swing.event.UndoableEditEvent in project vcell by virtualcell.
the class EventPanel method getDelayTextField.
// private InputVerifier delayInputVerifier = new InputVerifier() {
// @Override
// public boolean verify(JComponent input) {
// boolean bValid = true;
// Exception delayException = null;
// boolean bTextNotEmpty = getDelayTextField().getText() != null && getDelayTextField().getText().trim().length() > 0;
// try{
// if (bTextNotEmpty) {
// //Use createDelay to check validity
// createDelay(getBioEvent(),getDelayTextField().getText(),getSimulationContext(),getRdbtnTrigTime().isSelected());
// }
// }catch(Exception e){
// bValid = false;
// delayException = e;
// // e.printStackTrace();
// }
// if (bValid) {
// getDelayTextField().setBorder(UIManager.getBorder("TextField.border"));
// getDelayTextField().setToolTipText(null);
// enableTriggerRadioButtons(bTextNotEmpty);
// } else {
// getDelayTextField().setBorder(GuiConstants.ProblematicTextFieldBorder);
// getDelayTextField().setToolTipText("Error parse 'delay': "+delayException.getMessage());
// enableTriggerRadioButtons(false);
// // SwingUtilities.invokeLater(new Runnable() {
// // public void run() {
// // getDelayTextField().requestFocus();
// // }
// // });
// }
// return bValid;
// }
// };
// ActionListener editTimerActionListener = new ActionListener() {
// private String lastEdit = null;
// @Override
// public void actionPerformed(ActionEvent e) {
// if(!delayTextField.isPopupVisible()){
//
// }
// }
// };
// Timer editTimer;
private TextFieldAutoCompletion getDelayTextField() {
if (delayTextField == null) {
try {
delayTextField = new TextFieldAutoCompletion();
delayTextField.setName("DelayTextField");
KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
// System.out.println(evt);
if (evt.getPropertyName().equals("focusOwner") && evt.getNewValue() == delayTextField) {
// System.out.println("-----I got Focus "+delayTextField.hashCode()+" "+(getBioEvent()==null?null:getBioEvent().hashCode()));
} else if (evt.getPropertyName().equals("focusOwner") && evt.getOldValue() == delayTextField && evt.getNewValue() != delayTextField) {
// System.out.println("-----I lost Focus "+bErrorDialog+" "+delayTextField.hashCode()+" autolist visible="+delayTextField.isPopupVisible()+" "+(getBioEvent()==null?null:getBioEvent().hashCode()));
if (!delayTextField.isPopupVisible()) {
try {
setNewDelay(getBioEvent(), getDelayTextField().getText(), getSimulationContext(), getRdbtnTrigTime().isSelected());
} catch (Exception e) {
e.printStackTrace();
}
// System.out.println("set new delay="+(getBioEvent()==null?null:getBioEvent().getDelay()));
}
}
// System.out.println(EventPanel.this.hashCode()+" "+evt);
}
});
delayTextField.getDocument().addUndoableEditListener(new UndoableEditListener() {
@Override
public void undoableEditHappened(UndoableEditEvent e) {
if (delayTextField.getText() != null && delayTextField.getText().length() > 0) {
enableTriggerRadioButtons(true);
} else {
enableTriggerRadioButtons(false);
}
// delayInputVerifier.verify(delayTextField);
}
});
// delayTextField.addMouseListener(new MouseAdapter() {
// @Override
// public void mouseExited(MouseEvent e) {
// super.mouseExited(e);
// if(!delayTextField.isPopupVisible()){
// delayInputVerifier.verify(delayTextField);
// }else{
// System.out.println("-----MouseExit");
// }
// }
// });
delayTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateDelay();
}
});
//
// delayTextField.setInputVerifier(delayInputVerifier);
} catch (java.lang.Throwable e) {
e.printStackTrace(System.out);
}
}
return delayTextField;
}
Aggregations