/*
 * 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; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOUSE. See the GNU
 * General Public License for more details.
 *
 * You should have recieved a copy of the GNU General Public License
 * along with this program; if not write to the Free Software
 * Foundation, inc., 59 Temple Place, Suite 330, Boston MA 02111-1307
 * USA
 */
package j3d;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.tree.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import gui.*;
/**
 * Insert the type's description here.
 *
 * @author: Yuriy Mikhaylovskiy
 */

public class _BgImage implements _Object, Serializable{
  public int x,y;
  public BufferedImage img;
  private String Id;
  public boolean selected = false;

  private void writeObject(ObjectOutputStream out)  throws IOException{
    out.writeFloat(x);
    out.writeFloat(y);
    out.writeObject(img);
  }
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
    x = in.readInt();
    y = in.readInt();
    img = (BufferedImage)in.readObject();
    selected = false;
  }

  public void mesh(int type, float size){}
  public boolean delete(){return selected;}

  public _BgImage(BufferedImage i, int xx, int yy){
    img=i;
    x=xx;
    y=yy;
  }
  public _BgImage(BufferedImage i){
    img=i;
    x=0;
    y=0;
  }
  public Object[] get_Array(Canvas3D j3d){
    Object[] arr = {new shpBgImage(img,x,y)};
    return arr;
  }
  public String get_Id(){
    return Id;
  }
  public void set_Id(String id){
    Id=id;
  }
  public boolean isSelected(){return selected;}
  public void Select(String st){ selected=st!=null; }
  public String toString(){ return "Background Image ID="+Id;}
  public MutableTreeNode get_TreeNode(){
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(this);
    //node.add(new DefaultMutableTreeNode("Color"));
    return node;
  }
  public void transform3D(Matrix3D t){
    if(!selected)return;
    int xx=(int)(x*t.xx+y*t.xy+t.xo);
    int yy=(int)(x*t.yx+y*t.yy+t.yo);
    x=xx; y=yy;
  }
  public JPanel getEditPanel(Canvas3D j3d, PreProcessor pp){ return new JPanel(); }
  public _Node[] get_Nodes(){return null;}
  public _Object[] get_Elements(){return null;}
}