View Javadoc

1   /*
2    * Copyright (c) 2005 The University of Reading
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    * 1. Redistributions of source code must retain the above copyright
9    *    notice, this list of conditions and the following disclaimer.
10   * 2. Redistributions in binary form must reproduce the above copyright
11   *    notice, this list of conditions and the following disclaimer in the
12   *    documentation and/or other materials provided with the distribution.
13   * 3. Neither the name of the University of Reading, nor the names of the
14   *    authors or contributors may be used to endorse or promote products
15   *    derived from this software without specific prior written permission.
16   * 
17   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20   * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   */
28  
29  package uk.ac.rdg.resc.jstyx.interloper;
30  
31  import javax.swing.JTable;
32  import javax.swing.table.DefaultTableCellRenderer;
33  import java.awt.Component;
34  import java.awt.Color;
35  
36  /***
37   * Renderer for cells in a StyxMon table. Highlights error messages in red and 
38   * messages that have not been replied to in blue.
39   *
40   * @author Jon Blower
41   * $Revision: 31 $
42   * $Date: 2005-02-24 07:42:07 +0000 (Thu, 24 Feb 2005) $
43   * $Log$
44   * Revision 1.1  2005/02/24 07:42:07  jonblower
45   * Initial import
46   *
47   */
48  class StyxMonTableCellRenderer extends DefaultTableCellRenderer
49  {
50      
51      /***
52       * Calls the method in the superclass, then queries the data model to find
53       * out whether the row contains a message pair, or whether it contains an
54       * error
55       *
56       * @param table  the <code>JTable</code>
57       * @param value  the value to assign to the cell at
58       *			<code>[row, column]</code>
59       * @param isSelected true if cell is selected
60       * @param hasFocus true if cell has focus
61       * @param row  the row of the cell to render
62       * @param column the column of the cell to render
63       * @return the default table cell renderer
64       */
65      public Component getTableCellRendererComponent(JTable table, Object value,
66          boolean isSelected, boolean hasFocus, int row, int column)
67      {
68          Component c = super.getTableCellRendererComponent(table, value,
69              isSelected, hasFocus, row, column);
70          StyxMonTableModel model = (StyxMonTableModel)table.getModel();
71          if (!model.containsMessagePair(row))
72          {
73              // The Rmessage hasn't arrived yet, so colour the row blue
74              c.setBackground(new Color(128, 128, 255));
75          }
76          else if (model.containsError(row))
77          {
78              // The row contains an Rerror message, so colour the row red
79              c.setBackground(new Color(255, 128, 128));
80          }
81          else
82          {
83              c.setBackground(table.getBackground());
84          }
85          return c;
86      }
87      
88  }