1 /*
2 * ObjectLab, http://www.objectlab.co.uk/open is supporting JTreeMap.
3 *
4 * Based in London, we are world leaders in the design and development
5 * of bespoke applications for the securities financing markets.
6 *
7 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
8 * ___ _ _ _ _ _
9 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
10 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
11 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
12 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
13 * |__/
14 *
15 * www.ObjectLab.co.uk
16 *
17 * $Id: TM3TreeMapProvider.java 75 2006-10-24 23:00:51Z benoitx $
18 *
19 * Copyright 2006 the original author or authors.
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
22 * use this file except in compliance with the License. You may obtain a copy of
23 * the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
30 * License for the specific language governing permissions and limitations under
31 * the License.
32 */
33 package net.sf.jtreemap.ktreemap.example;
34
35 import java.util.Date;
36
37 import net.sf.jtreemap.ktreemap.ITreeMapProvider;
38 import net.sf.jtreemap.ktreemap.TreeMapNode;
39
40 /**
41 * TreeMapProvider for a TM3 file
42 *
43 */
44 public class TM3TreeMapProvider implements ITreeMapProvider {
45 private static String valueField = "";
46
47 public double getDoubleValue(Object value) {
48 if (value instanceof TM3Bean) {
49 TM3Bean bean = (TM3Bean)value;
50 Object obj = bean.getValue(getValueField());
51 if (obj instanceof Number) {
52 Number number = (Number)obj;
53 return number.doubleValue();
54 } else if (obj instanceof Date) {
55 Date date = (Date)obj;
56 return date.getTime();
57 }
58 }
59 return 0;
60 }
61
62 public String getLabel(TreeMapNode node) {
63 Object value = node.getValue();
64 if (value instanceof TM3Bean) {
65 TM3Bean bean = (TM3Bean)value;
66 return bean.getLabel();
67 }
68 return null;
69 }
70
71 public String getValueLabel(Object value) {
72 return "" + getDoubleValue(value);
73 }
74
75 /**
76 * @return the valueField
77 */
78 public static String getValueField() {
79 return valueField;
80 }
81
82 /**
83 * @param valueField the valueField to set
84 */
85 public static void setValueField(String valueField) {
86 TM3TreeMapProvider.valueField = valueField;
87 }
88 }
89 /*
90 * ObjectLab is supporing JTreeMap
91 *
92 * Based in London, we are world leaders in the design and development
93 * of bespoke applications for the securities financing markets.
94 *
95 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
96 * ___ _ _ _ _ _
97 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
98 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
99 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
100 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
101 * |__/
102 *
103 * www.ObjectLab.co.uk
104 */