Package DisplayProject.binding

Source Code of DisplayProject.binding.TextComponentBinder

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject.binding;

import javax.swing.JComponent;
import javax.swing.text.JTextComponent;

import DisplayProject.binding.adapter.Bindings;
import DisplayProject.binding.value.ValueModel;
import DisplayProject.controls.MultiLineTextField;

/**
* A binder for binding strings and textdata property types to
* a jtext component i.e JTextField/JtextArea
*/
public class TextComponentBinder implements Binder
{
        /*
     * @see DisplayProject.binding.Binder#bind(javax.swing.JComponent, java.lang.Object, java.lang.String)
     */
    public void bind(JComponent control, ValueModel valueModel)
    {
        // Respect the document that already exists on the control, if any
        JTextComponent textControl = (JTextComponent)control;
        MultiLineTextField textArea = null;
        if (textControl instanceof MultiLineTextField) {
            textArea = (MultiLineTextField)textControl;
            // Text area is associated with valueModel so that the former can distinguish between
            // user entered text and model supplied text. Cursor is to be placed at the beginning of model
            // supplied text.
            textArea.setValueModel(valueModel);
            // Register the first PropertyChangeListener on valueModel BEFORE the DocumentAdapter has registered.
            textArea.registerPropertyChangeHandler();
        }
        if (textControl.getDocument() != null) {
          // TF:13/11/2009:LUM-48:Added the parameter to the TextDataToStringConverter to allow the use of identity comparisons when firing property change events
            Bindings.bind((JTextComponent) control,new TextDataToStringConverter(valueModel, textArea != null), textControl.getDocument(), false);
        }
        else {
          // TF:13/11/2009:LUM-48:Added the parameter to the TextDataToStringConverter to allow the use of identity comparisons when firing property change events
            Bindings.bind((JTextComponent) control,new TextDataToStringConverter(valueModel, textArea != null),false);
        }
        if (textArea != null) {
            // Register the second PropertyChangeListener on valueModel AFTER the DocumentAdapter has registered.
            textArea.registerCaratPositionHandler();
        }
    }
}
TOP

Related Classes of DisplayProject.binding.TextComponentBinder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.