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$
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.provider;
34  
35  import java.awt.Color;
36  import java.awt.Graphics;
37  
38  import javax.swing.JPanel;
39  
40  import net.sf.jtreemap.swing.Value;
41  
42  /**
43   * Color Provider by default.<BR>
44   * All values are associated to a unique color.
45   *
46   * @author Laurent DUTHEIL
47   *
48   */
49  public class UniqueColorProvider extends ColorProvider {
50      /**
51       *
52       */
53      private static final long serialVersionUID = -7571926934516139432L;
54  
55      private static final Color DEFAULT_COLOR = new Color(153, 153, 51);
56  
57      private final Color color;
58  
59      private JPanel legend;
60  
61      /**
62       * Constructor.
63       */
64      public UniqueColorProvider() {
65          this.color = DEFAULT_COLOR;
66      }
67  
68      /**
69       * Constructor.
70       *
71       * @param color
72       *            unique color
73       */
74      public UniqueColorProvider(final Color color) {
75          this.color = color;
76      }
77  
78      /*
79       * (non-Javadoc)
80       *
81       * @see net.sf.jtreemap.swing.ColorProvider#getColor(double)
82       */
83      @Override
84      public Color getColor(final Value value) {
85          return this.color;
86      }
87  
88      /*
89       * (non-Javadoc)
90       *
91       * @see net.sf.jtreemap.swing.ColorProvider#getLegendPanel()
92       */
93      @Override
94      public JPanel getLegendPanel() {
95          if (this.legend == null) {
96              this.legend = new Legend();
97          }
98          return this.legend;
99      }
100 
101     /**
102      * Panel with the legend.
103      *
104      * @author Laurent Dutheil
105      */
106     private static class Legend extends JPanel {
107         private static final int LEGEND_Y_POS = 20;
108 
109         private static final int LEGEND_X_POS = 20;
110 
111         private static final int LEGEND_HEIGHT = 40;
112 
113         private static final int LEGEND_WIDTH = 100;
114 
115         private static final long serialVersionUID = -8046211081305644785L;
116 
117         private static final String TEXT = "Unique Color Provider";
118 
119         /**
120          * Constructor.
121          */
122         public Legend() {
123             this.setPreferredSize(new java.awt.Dimension(LEGEND_WIDTH, LEGEND_HEIGHT));
124 
125         }
126 
127         @Override
128         public void paint(final Graphics g) {
129             g.setColor(Color.black);
130             g.drawString(Legend.TEXT, LEGEND_X_POS, LEGEND_Y_POS);
131         }
132     }
133 }
134 /*
135  *                 ObjectLab is supporing JTreeMap
136  *
137  * Based in London, we are world leaders in the design and development
138  * of bespoke applications for the securities financing markets.
139  *
140  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
141  *           ___  _     _           _   _          _
142  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
143  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
144  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
145  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
146  *                   |__/
147  *
148  *                     www.ObjectLab.co.uk
149  */