KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > framework > HImageButton


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package net.sf.jftp.gui.framework;
17
18 import net.sf.jftp.*;
19
20 import java.awt.*;
21 import java.awt.event.*;
22
23 import javax.swing.*;
24
25
26 public class HImageButton extends JButton implements MouseListener
27 {
28     public String JavaDoc label = "";
29     public ActionListener who = null;
30     private boolean entered = false;
31     private Color cacheBack = GUIDefaults.light;
32
33     //private Color back = cacheBack;
34
private Color swing = new Color(155, 155, 205);
35
36     //private Color swing2 = new Color(75,75,125);
37
//private Color front = GUIDefaults.front;
38
//private Font font = GUIDefaults.font;
39
//private Image img;
40
//private String image = null;
41
private String JavaDoc cmd = "default";
42     private boolean drawBorder = true;
43     private JButton button;
44
45     public HImageButton(String JavaDoc image, String JavaDoc cmd, String JavaDoc label,
46                         ActionListener who)
47     {
48         //this.image = image;
49
this.cmd = cmd;
50         this.label = label;
51         this.who = who;
52
53         try {
54         //cacheBack = getBackground();
55
//back = cacheBack;
56
//button = new JButton(new ImageIcon(HImage.getImage(this,image)));
57
setIcon(new ImageIcon(HImage.getImage(this, image)));
58         }
59         catch(Exception JavaDoc ex) {
60             System.out.println("Image file: "+image);
61             ex.printStackTrace();
62         }
63         //add(button, BorderLayout.CENTER);
64
addMouseListener(this);
65
66         //addMouseListener(this);
67
setVisible(true);
68         setMinimumSize(new Dimension(25, 25));
69         setPreferredSize(new Dimension(25, 25));
70         setMaximumSize(new Dimension(25, 25));
71     }
72
73     /*
74         public void paintComponent(Graphics g)
75         {
76             g.setColor(back);
77             g.fillRect(0,0,getSize().width,getSize().height);
78
79             if(drawBorder)
80             {
81                     g.setColor(front);
82                     g.drawRect(0,0,getSize().width-1,getSize().height-1);
83                     //g.setColor(swing2);
84                     g.drawRect(0,0,getSize().width-2,getSize().height-2);
85                     g.setColor(back);
86                     g.fillRect(0,0,1,1);
87                     g.fillRect(0,getSize().height,1,getSize().height-1);
88                     g.fillRect(getSize().width-1,0,getSize().width,1);
89                     g.fillRect(getSize().width-1,getSize().height,getSize().width,getSize().height-1);
90             }
91             g.drawImage(img,2,2,this);
92         }
93     */

94     public void update(Graphics g)
95     {
96         paintComponent(g);
97     }
98
99     public void mouseClicked(MouseEvent e)
100     {
101     }
102
103     public void mousePressed(MouseEvent e)
104     {
105     }
106
107     public void mouseReleased(MouseEvent e)
108     {
109         //back = cacheBack;
110
who.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
111                                             cmd));
112
113         //repaint();
114
}
115
116     public void mouseEntered(MouseEvent e)
117     {
118         entered = true;
119         setCursor(new Cursor(Cursor.HAND_CURSOR));
120
121         //back = swing;
122
//button.setBackground(swing);
123
//paintImmediately(0,0,getSize().width,getSize().height);
124
JFtp.statusP.status(label);
125     }
126
127     public void mouseExited(MouseEvent e)
128     {
129         entered = false;
130         setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
131
132         //back = cacheBack;
133
//button.setBackground(cacheBack);
134
//paintImmediately(0,0,getSize().width,getSize().height);
135
JFtp.statusP.status("");
136     }
137
138     public void setBorder(boolean what)
139     {
140         drawBorder = what;
141     }
142 }
143
Popular Tags