001 /* 002 * Copyright 2002-2005 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * 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, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.binding.form.support; 017 018 import java.awt.Image; 019 020 import javax.swing.AbstractButton; 021 import javax.swing.Icon; 022 import javax.swing.ImageIcon; 023 import javax.swing.JLabel; 024 025 import org.springframework.binding.form.FieldFace; 026 import org.springframework.binding.value.support.AbstractPropertyChangePublisher; 027 import org.springframework.richclient.core.LabelInfo; 028 import org.springframework.util.Assert; 029 030 /** 031 * A default implementation of FieldFace 032 * 033 * @author Oliver Hutchison 034 */ 035 public class DefaultFieldFace extends AbstractPropertyChangePublisher implements FieldFace { 036 037 private final String displayName; 038 039 private final String caption; 040 041 private final String description; 042 043 private final LabelInfo labelInfo; 044 045 private final Icon icon; 046 047 /** 048 * Constructs a new DefaultFieldFace with the provided values. 049 */ 050 public DefaultFieldFace(String displayName, String caption, String description, String encodedLabel, Icon icon) { 051 this(displayName, caption, description, LabelInfo.valueOf(encodedLabel), icon); 052 } 053 054 public DefaultFieldFace(String displayName, String caption, String description, LabelInfo labelInfo, Icon icon) { 055 this.displayName = displayName; 056 this.caption = caption; 057 this.description = description; 058 this.labelInfo = labelInfo; 059 this.icon = icon; 060 } 061 062 public String getDisplayName() { 063 return displayName; 064 } 065 066 public String getCaption() { 067 return caption; 068 } 069 070 public String getDescription() { 071 return description; 072 } 073 074 public LabelInfo getLabelInfo() { 075 return labelInfo; 076 } 077 078 public Image getImage() { 079 if (getIcon() instanceof ImageIcon) { 080 return ((ImageIcon)getIcon()).getImage(); 081 } 082 else { 083 return null; 084 } 085 } 086 087 public Icon getIcon() { 088 return icon; 089 } 090 091 public void configure(JLabel label) { 092 Assert.notNull(label, "The JLabel to configure is required"); 093 labelInfo.configureLabel(label); 094 label.setIcon(icon); 095 } 096 097 public void configure(AbstractButton button) { 098 Assert.notNull(button, "The AbstractButton to configure is required"); 099 labelInfo.configureButton(button); 100 button.setIcon(icon); 101 } 102 }