1 /*********************************************************************
5 * Purpose : Swing details of rendering a column header as a button.
7 * Copyright : Written by and Copyright (C) 2003 the SourceForge
8 * Privoxy team. http://www.privoxy.org/
10 * Based on the Internet Junkbuster originally written
11 * by and Copyright (C) 1997 Anonymous Coders and
12 * Junkbusters Corporation. http://www.junkbusters.com
14 * This program is free software; you can redistribute it
15 * and/or modify it under the terms of the GNU General
16 * Public License as published by the Free Software
17 * Foundation; either version 2 of the License, or (at
18 * your option) any later version.
20 * This program is distributed in the hope that it will
21 * be useful, but WITHOUT ANY WARRANTY; without even the
22 * implied warranty of MERCHANTABILITY or FITNESS FOR A
23 * PARTICULAR PURPOSE. See the GNU General Public
24 * License for more details.
26 * The GNU General Public License should be included with
27 * this file. If not, you can view it at
28 * http://www.gnu.org/copyleft/gpl.html
29 * or write to the Free Software Foundation, Inc., 59
30 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 *********************************************************************/
36 package org.privoxy.activityconsole;
41 import javax.swing.table.*;
44 * Swing details of rendering a column header as a button.
45 * @author Last Modified By: $Author$
46 * @version $Rev$-$Date$$State$
48 public class SortButtonRenderer extends JButton implements TableCellRenderer
51 private static final String
52 COPYRIGHT = org.privoxy.activityconsole.Copyright.COPYRIGHT;
54 public static final int NONE = 0;
55 public static final int DOWN = 1;
56 public static final int UP = 2;
60 JButton downButton,upButton;
62 public SortButtonRenderer()
65 state = new Hashtable();
67 setMargin(new Insets(0,0,0,0));
68 setHorizontalTextPosition(LEFT);
69 setIcon(new BlankIcon());
71 downButton = new JButton();
72 downButton.setMargin(new Insets(0,0,0,0));
73 downButton.setHorizontalTextPosition(LEFT);
74 downButton.setIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, false));
75 downButton.setPressedIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, true));
77 upButton = new JButton();
78 upButton.setMargin(new Insets(0,0,0,0));
79 upButton.setHorizontalTextPosition(LEFT);
80 upButton.setIcon(new BevelArrowIcon(BevelArrowIcon.UP, false, false));
81 upButton.setPressedIcon(new BevelArrowIcon(BevelArrowIcon.UP, false, true));
85 public Component getTableCellRendererComponent(JTable table, Object value,
86 boolean isSelected, boolean hasFocus, int row, int column)
88 JButton button = this;
89 Object obj = state.get(new Integer(column));
92 if (((Integer)obj).intValue() == DOWN)
101 button.setText((value ==null) ? "" : value.toString());
102 boolean isPressed = (column == pushedColumn);
103 button.getModel().setPressed(isPressed);
104 button.getModel().setArmed(isPressed);
108 public void setPressedColumn(int col)
113 public void setSelectedColumn(int col)
116 Integer value = null;
117 Object obj = state.get(new Integer(col));
120 value = new Integer(DOWN);
124 if (((Integer)obj).intValue() == DOWN)
126 value = new Integer(UP);
130 value = new Integer(DOWN);
134 state.put(new Integer(col), value);
137 public int getState(int col)
140 Object obj = state.get(new Integer(col));
147 if (((Integer)obj).intValue() == DOWN)