| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hivegui.component; |
| 16 | |
| 17 | import javax.swing.JLabel; |
| 18 | |
| 19 | import org.apache.commons.logging.Log; |
| 20 | import org.apache.commons.logging.LogFactory; |
| 21 | import org.jdesktop.application.ApplicationContext; |
| 22 | import org.jdesktop.application.ResourceMap; |
| 23 | |
| 24 | import net.sourceforge.hivegui.application.ApplicationContextHolder; |
| 25 | |
| 26 | public abstract class AbstractRendererDelegate implements RendererDelegate |
| 27 | { |
| 28 | static private final Log _logger = LogFactory.getLog(AbstractRendererDelegate.class); |
| 29 | |
| 30 | public void setRendererName(String name) |
| 31 | { |
| 32 | if (_map != null) |
| 33 | { |
| 34 | _logger.warn("setRendererName(): _map has already been set!"); |
| 35 | } |
| 36 | _prefix = name; |
| 37 | } |
| 38 | |
| 39 | public void setContextHolder(ApplicationContextHolder holder) |
| 40 | { |
| 41 | if (_map == null) |
| 42 | { |
| 43 | _context = holder.getContext(); |
| 44 | _map = _context.getResourceMap(getClass()); |
| 45 | init(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | protected String getKey(Object value) |
| 50 | { |
| 51 | String prefix = (_prefix != null ? _prefix : getClass().getSimpleName()); |
| 52 | String suffix = (value != null ? value.toString() : "null"); |
| 53 | String key = prefix + "." + suffix; |
| 54 | return key; |
| 55 | } |
| 56 | |
| 57 | abstract protected void init(); |
| 58 | abstract public void setValue(JLabel renderer, Object value); |
| 59 | |
| 60 | private String _prefix; |
| 61 | protected ApplicationContext _context; |
| 62 | protected ResourceMap _map; |
| 63 | } |