View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.component;
21  
22  import java.awt.Graphics;
23  import java.awt.Insets;
24  import java.awt.event.MouseEvent;
25  
26  import javax.swing.Action;
27  import javax.swing.JButton;
28  
29  import org.xnap.gui.util.IconHelper;
30  
31  /***
32   * This class provides a toolbar button with an appropriate sized icon.
33   */
34  public class XNapToolBarButton extends JButton
35  {
36  
37      //--- Constant(s) ---
38  
39      //--- Data field(s) ---
40  
41      private boolean showBorder = false;
42      private boolean showMenuHint;
43  
44      //--- Constructor(s) ---
45  
46      public XNapToolBarButton(Action action)
47      {
48  		super(action);
49  
50  		String filename = (String)action.getValue(IconHelper.XNAP_ICON);
51  		setIcon(IconHelper.getToolBarIcon(filename));
52  
53  		setText(null);
54  		setMargin(new Insets(1, 1, 1, 1));
55  
56  		putClientProperty("hideActionText", new Boolean(true));
57      }
58  
59      //--- Method(s) ---
60  
61      protected void paintBorder(Graphics g)
62      {
63  		if (showBorder) {
64  			super.paintBorder(g);
65  		}
66      }
67  
68  	protected void processMouseEvent(MouseEvent e)
69  	{
70  		super.processMouseEvent(e);
71  		
72  		if (e.getID() == MouseEvent.MOUSE_ENTERED) {
73  			showBorder = true;
74  			repaint();
75  		}
76  		else if (e.getID() == MouseEvent.MOUSE_EXITED) {
77  			showBorder = false;
78  			repaint();
79  		}
80  	}
81  	
82  }