package de.bwvaachen.beamoflightgame.editor;
/*
Copyright (C) 2013 - 2014 by Andreas Pauls, Georg Braun, Christian Frühholz, Marius Spix, Christopher Müller and Bastian Winzen Part of the Beam Of Lights Puzzle Project
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
/**
* This class extends JButton for properties that are needed by our GUI.
*
* @author gbraun,cm
*
*/
@SuppressWarnings("serial")
public class TileButton extends JButton {
private int col;
private int row;
private BufferedImage image;
private TileState state;
private int lightPower;
/**
* Eigener Konstruktor
* @param row Die Zeile des Buttons
* @param col Die Spalte des Buttons
*/
public TileButton(int col, int row ) {
this.col = col ;
this.row = row ;
this.image = null ;
this.state = TileState.EMPTY;
this.lightPower = 0 ;
}
public int getCol() {
return col;
}
public int getRow() {
return row;
}
public BufferedImage getImage(){
return image;
}
public TileState getState(){
return state ;
}
public int getLightPower(){
return lightPower ;
}
public void reset(){
this.image = null ;
this.state = TileState.EMPTY;
this.lightPower = 0 ;
repaint();
}
public void setLightPower(int lightPower) throws IIOException, IOException{
this.lightPower = lightPower ;
this.state = TileState.NUMBER ;
this.setImage("resources/themes/moon/"+this.lightPower+".png");
}
public void setImage(BufferedImage image){
this.image = image;
repaint();
}
public void setImage(String path) throws IOException, IIOException {
this.image = ImageIO.read(new File(path));
repaint();
}
public void setImage(String path, double angle) throws IOException{
this.image = BeamsOfLightEditor.rotate(ImageIO.read(new File(path)),angle) ;
if(angle == 90.0 || angle == 270.0){
this.state = TileState.H_LIGHT ;
}else{
this.state = TileState.V_LIGHT ;
}
repaint();
}
@Override
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
super.paintComponent(g2);
if(image != null){
g2.drawImage(image,0,0,null);
}
}
}