001 /* 002 * Copyright 2002-2004 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.springframework.richclient.form.binding.swing; 017 018 import javax.swing.JComponent; 019 import javax.swing.JLabel; 020 021 import org.springframework.binding.form.FormModel; 022 import org.springframework.richclient.form.binding.support.CustomBinding; 023 024 /** 025 * @author Mauro Ransolin 026 */ 027 public class LabelBinding extends CustomBinding { 028 029 private final JLabel label; 030 031 public LabelBinding(JLabel label, FormModel formModel, String formPropertyPath) { 032 super(formModel, formPropertyPath, String.class); 033 this.label = label; 034 } 035 036 protected JComponent doBindControl() { 037 label.setText((String)getValueModel().getValue()); 038 return label; 039 } 040 041 protected void readOnlyChanged() { 042 label.setEnabled(isEnabled() && !isReadOnly()); 043 } 044 045 protected void enabledChanged() { 046 label.setEnabled(isEnabled() && !isReadOnly()); 047 } 048 049 protected void valueModelChanged(Object newValue) { 050 label.setText((String)newValue); 051 } 052 }