1 /*********************************************************************
5 * Purpose : A graphical element (specifically, a JPanel) that
6 * displays a little box of color and a number. When
7 * tweaked with a new number, the color changes for a
8 * set period of time, then resets to the previous
11 * Copyright : Written by and Copyright (C) 2003 the SourceForge
12 * Privoxy team. http://www.privoxy.org/
14 * Based on the Internet Junkbuster originally written
15 * by and Copyright (C) 1997 Anonymous Coders and
16 * Junkbusters Corporation. http://www.junkbusters.com
18 * This program is free software; you can redistribute it
19 * and/or modify it under the terms of the GNU General
20 * Public License as published by the Free Software
21 * Foundation; either version 2 of the License, or (at
22 * your option) any later version.
24 * This program is distributed in the hope that it will
25 * be useful, but WITHOUT ANY WARRANTY; without even the
26 * implied warranty of MERCHANTABILITY or FITNESS FOR A
27 * PARTICULAR PURPOSE. See the GNU General Public
28 * License for more details.
30 * The GNU General Public License should be included with
31 * this file. If not, you can view it at
32 * http://www.gnu.org/copyleft/gpl.html
33 * or write to the Free Software Foundation, Inc., 59
34 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 *********************************************************************/
40 package org.privoxy.activityconsole;
44 import javax.swing.table.*;
47 * A graphical element that displays a little box of color and a number.
48 * @author Last Modified By: $Author$
49 * @version $Rev$-$Date$$State$
51 public class StatWidget extends JPanel implements Comparable
53 private static final String
54 COPYRIGHT = org.privoxy.activityconsole.Copyright.COPYRIGHT;
56 private JPanel _statusIcon;
57 private JLabel _valueLabel;
60 private int _row, _col;
61 private JTable _table = null;
62 private StatWidgetThread _thread;
63 Color activityColor = Color.yellow;
64 Color inactivityColor = getBackground().darker();
66 public StatWidget(int initialValue, int statusDurationMillis)
68 _value = initialValue;
69 _statusIcon = new JPanel();
70 _statusIcon.setBackground(inactivityColor);
71 _valueLabel = new JLabel(new Integer(initialValue).toString());
72 this.setLayout(new GridBagLayout());
73 ActivityConsoleGuiUtil.constrain(this, _statusIcon,
74 1, 1, // X, Y Coordinates
75 1, 1, // Grid width, height
76 GridBagConstraints.NONE, // Fill value
77 GridBagConstraints.WEST, // Anchor value
78 0.0,0.0, // Weight X, Y
79 0, 1, 0, 1 ); // Top, left, bottom, right insets
80 ActivityConsoleGuiUtil.constrain(this, _valueLabel,
81 2, 1, // X, Y Coordinates
82 1, 1, // Grid width, height
83 GridBagConstraints.HORIZONTAL, // Fill value
84 GridBagConstraints.WEST, // Anchor value
85 1.0,0.0, // Weight X, Y
86 0, 1, 0, 1 ); // Top, left, bottom, right insets
87 _thread = new StatWidgetThread(this, statusDurationMillis);
91 public void updateValue(int newValue)
93 if (_value != newValue)
96 _valueLabel.setText(new Integer(newValue).toString());
97 _statusIcon.setBackground(activityColor);
99 ((AbstractTableModel)_table.getModel()).fireTableCellUpdated(_row,_table.convertColumnIndexToModel(_col));
104 public void setRowColTable(int row, int col, JTable table)
121 public int getValue()
126 public void timerPop()
128 _statusIcon.setBackground(inactivityColor);
130 ((AbstractTableModel)_table.getModel()).fireTableCellUpdated(_row,_table.convertColumnIndexToModel(_col));
133 public int compareTo(Object compare)
135 int compareValue = ((StatWidget)compare).getValue();
136 if (_value < compareValue)
138 else if (_value == compareValue)