Typo: inspect_jpegs, not inspect-jpegs in form
[privoxy.git] / src / java / org / privoxy / activityconsole / BevelArrowIcon.java
1 /*********************************************************************
2  *
3  * File        :  $Source$
4  *
5  * Purpose     :  Painting details for rendering the beveled arrow icon.
6  *
7  * Copyright   :  Written by and Copyright (C) 2003 the SourceForge
8  *                Privoxy team. http://www.privoxy.org/
9  *
10  *                Based on the Internet Junkbuster originally written
11  *                by and Copyright (C) 1997 Anonymous Coders and
12  *                Junkbusters Corporation.  http://www.junkbusters.com
13  *
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.
19  *
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.
25  *
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.
31  *
32  * Revisions   :
33  *    $Log$
34  *********************************************************************/
35
36 package org.privoxy.activityconsole;
37
38 import java.awt.*;
39 import javax.swing.*;
40
41 /** 
42  * Painting details for rendering the beveled arrow icon.
43  * @author Last Modified By: $Author$
44  * @version $Rev$-$Date$$State$
45  */
46 public class BevelArrowIcon implements Icon
47 {
48
49   private static final String
50   COPYRIGHT = org.privoxy.activityconsole.Copyright.COPYRIGHT;
51
52   public static final int UP    = 0;         // direction
53   public static final int DOWN  = 1;
54
55   private static final int DEFAULT_SIZE = 11;
56
57   private Color edge1;
58   private Color edge2;
59   private Color fill;
60   private int size;
61   private int direction;
62
63   public BevelArrowIcon(int direction, boolean isRaisedView, boolean isPressedView)
64   {
65     if (isRaisedView)
66     {
67       if (isPressedView)
68       {
69         init( UIManager.getColor("controlLtHighlight"),
70               UIManager.getColor("controlDkShadow"),
71               UIManager.getColor("controlShadow"),
72               DEFAULT_SIZE, direction);
73       }
74       else
75       {
76         init( UIManager.getColor("controlHighlight"),
77               UIManager.getColor("controlShadow"),
78               UIManager.getColor("control"),
79               DEFAULT_SIZE, direction);
80       }
81     }
82     else
83     {
84       if (isPressedView)
85       {
86         init( UIManager.getColor("controlDkShadow"),
87               UIManager.getColor("controlLtHighlight"),
88               UIManager.getColor("controlShadow"),
89               DEFAULT_SIZE, direction);
90       }
91       else
92       {
93         init( UIManager.getColor("controlShadow"),
94               UIManager.getColor("controlHighlight"),
95               UIManager.getColor("control"),
96               DEFAULT_SIZE, direction);
97       }
98     }
99   }
100
101   public BevelArrowIcon(Color edge1, Color edge2, Color fill,
102                         int size, int direction)
103   {
104     init(edge1, edge2, fill, size, direction);
105   }
106
107
108   public void paintIcon(Component c, Graphics g, int x, int y)
109   {
110     switch (direction)
111     {
112     case DOWN: drawDownArrow(g, x, y); break;
113     case   UP: drawUpArrow(g, x, y);   break;
114     }
115   }
116
117   public int getIconWidth()
118   {
119     return size;
120   }
121
122   public int getIconHeight()
123   {
124     return size;
125   }
126
127
128   private void init(Color edge1, Color edge2, Color fill,
129                     int size, int direction)
130   {
131     this.edge1 = edge1;
132     this.edge2 = edge2;
133     this.fill = fill;
134     this.size = size;
135     this.direction = direction;
136   }
137
138   private void drawDownArrow(Graphics g, int xo, int yo)
139   {
140     g.setColor(edge1);
141     g.drawLine(xo, yo,   xo+size-1, yo);
142     g.drawLine(xo, yo+1, xo+size-3, yo+1);
143     g.setColor(edge2);
144     g.drawLine(xo+size-2, yo+1, xo+size-1, yo+1);
145     int x = xo+1;
146     int y = yo+2;
147     int dx = size-6;      
148     while (y+1 < yo+size)
149     {
150       g.setColor(edge1);
151       g.drawLine(x, y,   x+1, y);
152       g.drawLine(x, y+1, x+1, y+1);
153       if (0 < dx)
154       {
155         g.setColor(fill);
156         g.drawLine(x+2, y,   x+1+dx, y);
157         g.drawLine(x+2, y+1, x+1+dx, y+1);
158       }
159       g.setColor(edge2);
160       g.drawLine(x+dx+2, y,   x+dx+3, y);
161       g.drawLine(x+dx+2, y+1, x+dx+3, y+1);
162       x += 1;
163       y += 2;
164       dx -= 2;     
165     }
166     g.setColor(edge1);
167     g.drawLine(xo+(size/2), yo+size-1, xo+(size/2), yo+size-1); 
168   }
169
170   private void drawUpArrow(Graphics g, int xo, int yo)
171   {
172     g.setColor(edge1);
173     int x = xo+(size/2);
174     g.drawLine(x, yo, x, yo); 
175     x--;
176     int y = yo+1;
177     int dx = 0;
178     while (y+3 < yo+size)
179     {
180       g.setColor(edge1);
181       g.drawLine(x, y,   x+1, y);
182       g.drawLine(x, y+1, x+1, y+1);
183       if (0 < dx)
184       {
185         g.setColor(fill);
186         g.drawLine(x+2, y,   x+1+dx, y);
187         g.drawLine(x+2, y+1, x+1+dx, y+1);
188       }
189       g.setColor(edge2);
190       g.drawLine(x+dx+2, y,   x+dx+3, y);
191       g.drawLine(x+dx+2, y+1, x+dx+3, y+1);
192       x -= 1;
193       y += 2;
194       dx += 2;     
195     }
196     g.setColor(edge1);
197     g.drawLine(xo, yo+size-3,   xo+1, yo+size-3);
198     g.setColor(edge2);
199     g.drawLine(xo+2, yo+size-2, xo+size-1, yo+size-2);
200     g.drawLine(xo, yo+size-1, xo+size, yo+size-1);
201   }
202 }