Search in sources :

Example 6 with UndoableEditEvent

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();
        }
    }
}
Also used : UndoableEditEvent(javax.swing.event.UndoableEditEvent)

Example 7 with UndoableEditEvent

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;
}
Also used : UndoableEditListener(javax.swing.event.UndoableEditListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TextFieldAutoCompletion(cbit.gui.TextFieldAutoCompletion) PropertyChangeListener(java.beans.PropertyChangeListener) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) UndoableEditEvent(javax.swing.event.UndoableEditEvent) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

UndoableEditEvent (javax.swing.event.UndoableEditEvent)7 UndoableEditListener (javax.swing.event.UndoableEditListener)5 TextFieldAutoCompletion (cbit.gui.TextFieldAutoCompletion)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 Var (clojure.lang.Var)1 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyVetoException (java.beans.PropertyVetoException)1 JMenuBar (javax.swing.JMenuBar)1 BadLocationException (javax.swing.text.BadLocationException)1 UndoableEdit (javax.swing.undo.UndoableEdit)1