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