01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.swing.tips;
18:
19: import com.l2fprod.common.swing.TipModel;
20:
21: import java.util.ArrayList;
22: import java.util.List;
23: import java.util.Properties;
24:
25: /**
26: * Loads tips from various sources.<br>
27: */
28: public class TipLoader {
29:
30: /**
31: * Initializes a TipModel from properties. Each tip is defined by two
32: * properties, its name and its description:
33: *
34: * <pre>
35: * tip.1.name=First Tip
36: * tip.1.description=This is the description
37: *
38: * tip.2.name=Second Tip
39: * tip.2.description=<html>This is an html description
40: * </pre>
41: *
42: * @param props
43: * @return a TipModel
44: * @throws IllegalArgumentException
45: * if a name is found without description
46: */
47: public static TipModel load(Properties props) {
48: List tips = new ArrayList();
49:
50: int count = 1;
51: while (true) {
52: String nameKey = "tip." + count + ".name";
53: String nameValue = props.getProperty(nameKey);
54:
55: String descriptionKey = "tip." + count + ".description";
56: String descriptionValue = props.getProperty(descriptionKey);
57:
58: if (nameValue != null && descriptionValue == null) {
59: throw new IllegalArgumentException(
60: "No description for name " + nameValue);
61: }
62:
63: if (descriptionValue == null) {
64: break;
65: }
66:
67: DefaultTip tip = new DefaultTip(nameValue, descriptionValue);
68: tips.add(tip);
69:
70: count++;
71: }
72:
73: return new DefaultTipModel(tips);
74: }
75:
76: }
|