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 java.util.HashMap; |
18 | import java.util.HashSet; |
19 | import java.util.Map; |
20 | import java.util.Set; |
21 | |
22 | import javax.swing.JLabel; |
23 | |
24 | public class TextMapRendererDelegate extends AbstractRendererDelegate |
25 | { |
26 | @Override protected void init() |
27 | { |
28 | for (Object value: _keys) |
29 | { |
30 | String key = getKey(value); |
31 | addText(value, _map.getString(key)); |
32 | } |
33 | _keys = null; |
34 | } |
35 | |
36 | public void addText(Object value) |
37 | { |
38 | if (_map != null) |
39 | { |
40 | addText(value, _map.getString(getKey(value))); |
41 | } |
42 | else |
43 | { |
44 | _keys.add(value); |
45 | } |
46 | } |
47 | |
48 | public void addText(Object value, String text) |
49 | { |
50 | _texts.put(value, text); |
51 | } |
52 | |
53 | @Override public void setValue(JLabel renderer, Object value) |
54 | { |
55 | renderer.setText(_texts.get(value)); |
56 | } |
57 | |
58 | private Set<Object> _keys = new HashSet<Object>(); |
59 | private final Map<Object, String> _texts = new HashMap<Object, String>(); |
60 | } |