View Javadoc

1   /***
2    * ValueIndexedTableColorModel.java
3    *
4    * This file is part of the creme library.
5    * The creme library intends to ease the development effort of large
6    * applications by providing easy to use support classes.
7    *
8    * Copyright (C) 2002 Denis Bregeon
9    *
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23   *
24   * contact information: dbregeon@sourceforge.net
25   */
26  package org.jcreme.swing.table.colormodel;
27  
28  import java.util.Comparator;
29  
30  import org.jcreme.swing.table.TableColorModelEvent;
31  
32  /***
33   * The purpose of this class is to have a specific background color for the
34   * lines that have a given reference column above a given Threshold value. (the
35   * value of a specified column is at a specified value).
36   * 
37   * @author $Author: dbregeon $
38   * @version $Revision: 1.2 $
39   */
40  public class GeneralValueIndexedTableColorModel extends
41          AbstractValueIndexedTableColorModel {
42      /***
43       * The treshold over which the color changes.
44       */
45      private Object thresholdValue = null;
46  
47      /***
48       * The comparator used with the thresholdValue.
49       */
50      private Comparator comparator = null;
51  
52      /***
53       * Sets the treshold value over which the task will be considered complete.
54       * 
55       * @param value
56       *            The value to use as a treshold.
57       * @param comp
58       *            the Comparator used to determine whether values are breaking
59       *            the threshold.
60       */
61      public void setThresholdValue(Object value, Comparator comp) {
62          if ((this.thresholdValue != value) || (this.comparator != comp)) {
63              this.thresholdValue = value;
64              this.comparator = comp;
65              fireTableColorModelChanged(new TableColorModelEvent(this));
66          }
67      }
68  
69      protected boolean testThreshold(Object value) {
70          return (this.comparator != null)
71                  && (this.comparator.compare(this.thresholdValue, value) <= 0);
72      }
73  }