import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolTip;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import administration.RefreshUI;
public class GButton extends JButton implements RefreshUI{
private JToolTip tooltip=new JToolTip();
private Color backgroundcolor;
private Window window;
private Point tooltiplocation=new Point();
public GButton(int x,int y,int w,int h,String pfad,Color color){
this(x, y, w, h, IMoYUtil.getBuffImg(pfad), color);
}
public GButton(int x,int y,int w,int h){
this(x,y,w,h,"",new Color(155,155,155));
}
public GButton(int x,int y,int w,int h,String pfad){
this(x, y, w, h, pfad, new Color(155,155,155));
}
public GButton(int x,int y,int w,int h,BufferedImage img,Color color){
this.setBounds(x,y,w,h);
if(img!=null)
this.setIcon(new ImageIcon(img));
this.setFocusable(false);
this.setBorderPainted(false);
this.setRolloverEnabled(false);
this.backgroundcolor=color;
ToolTipManager tips=ToolTipManager.sharedInstance();
tips.setInitialDelay(100);
tips.setDismissDelay(60000);
tips.setReshowDelay(0);
}
@Override
public JToolTip createToolTip() {
tooltip.setBorder(BorderFactory.createBevelBorder(1));
tooltip.setFont(new Font("Comic Sans MS",Font.BOLD,12));
tooltip.setBackground(backgroundcolor);
return tooltip;
}
public void refresh(int time) {
}
public JToolTip customizeTooltip(){
return tooltip;
}
@Override
public Point getToolTipLocation(MouseEvent event) {
if(window==null)
window = SwingUtilities.getWindowAncestor(this);
final Point coordsInWindow = SwingUtilities.convertPoint(this,0,0, window);
int quad=0;
int ww=window.getWidth();
int wh=window.getHeight();
if(coordsInWindow.x>ww/2&&coordsInWindow.x<=ww&&coordsInWindow.y>0&&coordsInWindow.y<=wh/2)
quad=1;
else
if(coordsInWindow.x>ww/2&&coordsInWindow.x<=ww&&coordsInWindow.y>wh/2&&coordsInWindow.y<=wh)
quad=2;
else
if(coordsInWindow.x>0&&coordsInWindow.x<=ww/2&&coordsInWindow.y>wh/2&&coordsInWindow.y<=wh)
quad=3;
switch (quad) {
case 0:tooltiplocation.x=this.getWidth()/2;tooltiplocation.y=this.getHeight()/2;break;
case 1:tooltiplocation.x=this.getWidth()/2-tooltip.getWidth();tooltiplocation.y=this.getHeight()/2;break;
case 2:tooltiplocation.x=this.getWidth()/2-tooltip.getWidth();tooltiplocation.y=this.getHeight()/2-tooltip.getHeight();break;
case 3:tooltiplocation.x=this.getWidth()/2;tooltiplocation.y=this.getHeight()/2-tooltip.getHeight();break;
default:break;
}
return tooltiplocation;
}
}