Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package org.apache.cayenne.swing;
 
 import java.awt.Color;
 
 
 import  org.apache.cayenne.validation.ValidationException;

A generic text adapter that is bound to a bean property.
 
 public class TextBinding extends BindingBase {
 
     protected JTextComponent textComponent;
 
     protected Color defaultBGColor;
     protected Color errorColor;
     protected String defaultToolTip;
 
     public TextBinding(JTextField textFieldString expression) {
         super(expression);
         this. = textField;
         initComponentDefaults();
 
         textField.addActionListener(new ActionListener() {
 
             public void actionPerformed(ActionEvent e) {
                 if (!) {
                     updateModel();
                 }
             }
         });
 
         .setInputVerifier(new InputVerifier() {
 
             public boolean verify(JComponent c) {
                 updateModel();
                 // release focus after coloring the field...
                 return true;
             }
         });
 
     }
 
     public TextBinding(JTextArea textAreaString property) {
         super(property);
         this. = textArea;
         initComponentDefaults();
 
 
             public void insertUpdate(DocumentEvent e) {
                 verifyTextChange(e);
             }
 
             public void changedUpdate(DocumentEvent e) {
                 verifyTextChange(e);
             }
 
             public void removeUpdate(DocumentEvent e) {
                 verifyTextChange(e);
             }
 
             void verifyTextChange(DocumentEvent e) {
                 if (!) {
                     updateModel();
                 }
             }
         });
     }
    protected void initComponentDefaults() {
        this. = .;
        this. = .getBackground();
        this. = .getToolTipText();
    }
    public void updateView() {
        Object value = getValue();
        String text = (value != null) ? value.toString() : null;
         = true;
        try {
            clear();
            .setText(text);
        }
        finally {
             = false;
        }
    }

    
Returns internal text component.
    public Component getView() {
        return ;
    }
    protected void updateModel() {
        try {
            setValue(.getText());
            clear();
        }
        catch (ValidationException vex) {
            .setBackground();
            .setToolTipText(vex.getUnlabeledMessage());
        }
    }
    protected void clear() {
    }
New to GrepCode? Check out our FAQ X