View Javadoc

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: ColorProvider.java 69 2006-10-24 16:20:20Z 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.swing;
34  
35  import java.text.NumberFormat;
36  
37  
38  /**
39   * class who can display the values of elements of a JTreeMap with pourcent
40   * 
41   * @author Laurent Dutheil
42   */
43  
44  public class ValuePercent extends Value {
45      /**
46       * 
47       */
48      private static final long serialVersionUID = 1087258219010392928L;
49  
50      private double value;
51  
52      private NumberFormat nf;
53  
54      /**
55       * Constructor of ValuePercent
56       */
57      public ValuePercent() {
58          this.nf = NumberFormat.getInstance();
59          this.nf.setMaximumFractionDigits(2);
60          this.nf.setMinimumFractionDigits(2);
61          this.nf.setMinimumIntegerDigits(1);
62      }
63  
64      /**
65       * Constructor of ValuePercent
66       * 
67       * @param value
68       *            double value
69       */
70      public ValuePercent(final double value) {
71          this();
72          this.value = value;
73      }
74  
75      @Override
76      public void setValue(final double d) {
77          this.value = d;
78      }
79  
80      @Override
81      public void setLabel(final String stLibelle) {
82          // ignore
83      }
84  
85      @Override
86      public double getValue() {
87          return this.value;
88      }
89  
90      @Override
91      public String getLabel() {
92          if (this.value >= 0) {
93              return "+" + this.nf.format(this.value) + " %";
94          }
95          return this.nf.format(this.value) + " %";
96      }
97  }
98  /*
99   *                 ObjectLab is supporing JTreeMap
100  * 
101  * Based in London, we are world leaders in the design and development 
102  * of bespoke applications for the securities financing markets.
103  * 
104  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
105  *           ___  _     _           _   _          _
106  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
107  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
108  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
109  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
110  *                   |__/
111  *
112  *                     www.ObjectLab.co.uk
113  */