/**
 * Copyright (c) Artenum SARL 2004-2005
 * @author Julien Forest / Sebastien Jourdain
 *
 * All rights reserved. This software can
 * not be used or copy or diffused without
 * an explicit license of Artenum SARL, Paris-France
 */
package com.artenum.cassandra.plugin.defaults;

import com.artenum.cassandra.pipeline.PipeLineManager;

import vtk.vtk3DSImporter;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;

public class ImportFrom3DS implements ActionListener {
    private PipeLineManager pipelineManager;
    private Frame owner;
    private vtk3DSImporter importer;

    public ImportFrom3DS(PipeLineManager pipelineManager, Frame owner) {
        this.pipelineManager = pipelineManager;
        this.owner = owner;
        importer = new vtk3DSImporter();
    }

    public void actionPerformed(ActionEvent e) {
        JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new FileFilter() {
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().endsWith(".3ds");
                }

                public String getDescription() {
                    return "3DS files";
                }
            });
        if (chooser.showOpenDialog(owner) == JFileChooser.APPROVE_OPTION) {
            String file = chooser.getSelectedFile().getAbsolutePath();
            try {
                importer.SetFileName(file);
                importer.SetRenderWindow(pipelineManager.getCassandraView().GetRenderWindow());
                importer.Update();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(owner, "Unable to load: " + file);
            }
        }
    }
}
