/*
NCSA Portfolio
Copyright 1997-1998 The Board of Trustees of the University of Illinois
All Rights Reserved 

NCSA Portfolio software, binary, Java-bytecode, and source (hereafter,
Software) is copyrighted by The Board of Trustees of the University of
Illinois (hereafter, UI), and ownership remains with the UI.

The UI grants you (hereafter, Licensee) a license to use the Software for
academic, research and internal business purposes only, without a fee.
Licensee may distribute the binary, Java byte-code, and source code (if
released) to third parties provided that the copyright notice and this
statement appears on all copies and that no charge is associated with such
copies.

Licensee may make derivative works.  However, if Licensee distributes any
derivative work based on or derived from the Software, then Licensee will
(1) notify NCSA regarding its distribution of the derivative work, and (2)
clearly notify users that such derivative work is a modified version and
not the original Software (NCSA Portfolio) distributed by the UI.

Any Licensee wishing to make commercial use of the Software should contact
the UI, c/o NCSA, to negotiate an appropriate license for such commercial
use.  Commercial use includes (1) integration of all or part of the
Software into a product for sale or license by or on behalf of Licensee to
third parties, or (2) distribution of the Software to third parties that
need it to utilize a commercial product sold or licensed by or on behalf of
Licensee. 

UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY,
INCLUDING, WITHOUT LIMITATION, NO WARRANTY AGAINST INFRIGEMENT OF ANY
INTELLECTUAL PROPERY RIGHTS.  THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES
SUFFERED BY THE USERS OF THIS SOFTWARE.

By using or copying this Software, Licensee agrees to abide by the
copyright law and all other applicable laws of the U.S. including, but not
limited to, export control laws, and the terms of this license.  UI shall
have the right to terminate this license immediately by written notice upon
Licensee's breach of, or non-compliance with, any of its terms.  Licensee
may be held legally responsible for any copyright infringement that is
caused or encouraged by Licensee's failure to abide by the terms of this
license.

U.S. GOVERNMENT RESTRICTED RIGHTS 

The Software and/or user documentation are provided with RESTRICTED AND
LIMITED RIGHTS.  Use, duplication or disclosure by or to the United States
government shall be subject to restrictions as set forth in subparagraph
(c)(1)(ii) of Defense Federal Acquisition Regulations Supplement (DFARS)
Section 252.227-7013 for Department of Defense contracts and as set forth
in Federal Acquisition Regulations (FAR) Section 52.227-19 for civilian
agency contracts or any successor regulations.  Contractor/Manufacturer is
The Board of Trustees of the University of Illinois, Urbana, Illinois 61801.

NCSA is a registered trademark owned by The Board of Trustees of the
University of Illinois.
*/
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import ncsa.j3d.loaders.play.PlayWriter;

/** 
 * This is the button panel that floats off of the recordable display program.
 */

public class ButtonPanel extends Panel {
        Checkbox pickButton;
        Checkbox viewButton;
        Display disp;

        /** 
         * This is the constructor, The Display argument is the main program
         * @param d The Display Program
         */
        public ButtonPanel(Display d) {
                super();
                disp = d;

                setLayout(new BorderLayout());
                Panel panel = new Panel();
                panel.setLayout(new GridLayout(7, 1));

                panel.add(new Label("NCSA Display", Label.CENTER));

                CheckboxGroup group = new CheckboxGroup();

                setupTools(group,panel);

                Button snapshot = new Button("Take Snapshot of current view");

                snapshot.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                disp.getRecordableCanvas3D().takeSnapshot();
                        }
                });

                panel.add(snapshot);
                

                Panel framedumper = new Panel();

                framedumper.add(new Label("Continuous Snaphot", Label.CENTER));
                CheckboxGroup group2 = new CheckboxGroup();

                Checkbox offButton = new Checkbox("Off", group2, true);
                offButton.addItemListener(new ItemListener() {
                    public void itemStateChanged(ItemEvent e) {
                        System.out.println("record canvas off");
                        disp.getRecordableCanvas3D().stopRecording();
                    }
                });

                Checkbox onButton = new Checkbox("On", group2, false);

                onButton.addItemListener(new ItemListener() {
                    public void itemStateChanged(ItemEvent e) {
                        System.out.println("record canvas on"); 
                        disp.getRecordableCanvas3D().startRecording();
                    }
                });

                framedumper.add(offButton);
                framedumper.add(onButton);
                panel.add(framedumper);


/* Turn off for NCSA Portfolio 1.3 beta 1...should be fixed in next beta....
                Panel actionrecorder = new Panel();
                actionrecorder.add(new Label("Action Recorder", Label.CENTER));
                CheckboxGroup group3 = new CheckboxGroup();

                Checkbox offButton1 = new Checkbox("Off", group3, true);
                offButton1.addItemListener(new ItemListener() {
                    public void itemStateChanged(ItemEvent e) {
                        PlayWriter.close();
                    }
                });

                Checkbox onButton1 = new Checkbox("On", group3, false);

                onButton1.addItemListener(new ItemListener() {
                    public void itemStateChanged(ItemEvent e) {
                        PlayWriter.open("recorded");
                    }
                });

                actionrecorder.add(offButton1);
                actionrecorder.add(onButton1);
                panel.add(actionrecorder);      
*/

                add("North", panel);
        }

  protected void setupTools(CheckboxGroup group, Panel panel){

        String[] tools = disp.getToolNames();
        boolean first = true;

        for(int i = 0; i<tools.length; i++){
          Checkbox b = new Checkbox(tools[i],group,first);
          b.addItemListener(new MyListener(disp));
          panel.add(b);
          first = false;
        }

  }
}

class MyListener implements ItemListener{

        static int count = 0;
        int val = count++;
        Display disp;

        MyListener(Display disp){
                this.disp = disp;
        }

        public void itemStateChanged(ItemEvent e){
                disp.setActiveTool(val);
        }
}


