001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.gui.framework;
017:
018: import net.sf.jftp.*;
019:
020: import java.awt.*;
021: import java.awt.event.*;
022:
023: import javax.swing.*;
024:
025: public class HImageButton extends JButton implements MouseListener {
026: public String label = "";
027: public ActionListener who = null;
028: private boolean entered = false;
029: private Color cacheBack = GUIDefaults.light;
030:
031: //private Color back = cacheBack;
032: private Color swing = new Color(155, 155, 205);
033:
034: //private Color swing2 = new Color(75,75,125);
035: //private Color front = GUIDefaults.front;
036: //private Font font = GUIDefaults.font;
037: //private Image img;
038: //private String image = null;
039: private String cmd = "default";
040: private boolean drawBorder = true;
041: private JButton button;
042:
043: public HImageButton(String image, String cmd, String label,
044: ActionListener who) {
045: //this.image = image;
046: this .cmd = cmd;
047: this .label = label;
048: this .who = who;
049:
050: try {
051: //cacheBack = getBackground();
052: //back = cacheBack;
053: //button = new JButton(new ImageIcon(HImage.getImage(this,image)));
054: setIcon(new ImageIcon(HImage.getImage(this , image)));
055: } catch (Exception ex) {
056: System.out.println("Image file: " + image);
057: ex.printStackTrace();
058: }
059: //add(button, BorderLayout.CENTER);
060: addMouseListener(this );
061:
062: //addMouseListener(this);
063: setVisible(true);
064: setMinimumSize(new Dimension(25, 25));
065: setPreferredSize(new Dimension(25, 25));
066: setMaximumSize(new Dimension(25, 25));
067: }
068:
069: /*
070: public void paintComponent(Graphics g)
071: {
072: g.setColor(back);
073: g.fillRect(0,0,getSize().width,getSize().height);
074:
075: if(drawBorder)
076: {
077: g.setColor(front);
078: g.drawRect(0,0,getSize().width-1,getSize().height-1);
079: //g.setColor(swing2);
080: g.drawRect(0,0,getSize().width-2,getSize().height-2);
081: g.setColor(back);
082: g.fillRect(0,0,1,1);
083: g.fillRect(0,getSize().height,1,getSize().height-1);
084: g.fillRect(getSize().width-1,0,getSize().width,1);
085: g.fillRect(getSize().width-1,getSize().height,getSize().width,getSize().height-1);
086: }
087: g.drawImage(img,2,2,this);
088: }
089: */
090: public void update(Graphics g) {
091: paintComponent(g);
092: }
093:
094: public void mouseClicked(MouseEvent e) {
095: }
096:
097: public void mousePressed(MouseEvent e) {
098: }
099:
100: public void mouseReleased(MouseEvent e) {
101: //back = cacheBack;
102: who.actionPerformed(new ActionEvent(this ,
103: ActionEvent.ACTION_PERFORMED, cmd));
104:
105: //repaint();
106: }
107:
108: public void mouseEntered(MouseEvent e) {
109: entered = true;
110: setCursor(new Cursor(Cursor.HAND_CURSOR));
111:
112: //back = swing;
113: //button.setBackground(swing);
114: //paintImmediately(0,0,getSize().width,getSize().height);
115: JFtp.statusP.status(label);
116: }
117:
118: public void mouseExited(MouseEvent e) {
119: entered = false;
120: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
121:
122: //back = cacheBack;
123: //button.setBackground(cacheBack);
124: //paintImmediately(0,0,getSize().width,getSize().height);
125: JFtp.statusP.status("");
126: }
127:
128: public void setBorder(boolean what) {
129: drawBorder = what;
130: }
131: }
|