Search in sources :

Example 6 with TextFieldAutoCompletion

use of cbit.gui.TextFieldAutoCompletion 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

TextFieldAutoCompletion (cbit.gui.TextFieldAutoCompletion)6 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 Insets (java.awt.Insets)3 JButton (javax.swing.JButton)2 JLabel (javax.swing.JLabel)2 JScrollPane (javax.swing.JScrollPane)2 JTextField (javax.swing.JTextField)2 BioModelNode (cbit.vcell.desktop.BioModelNode)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)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 Calendar (java.util.Calendar)1