package samples.javaclient.analyzer;
import oracle.bali.ewt.wizard.Wizard;
import oracle.dss.datautil.gui.panel.DefaultStandardPanel;
import java.awt.GridBagLayout;
import javax.swing.ButtonGroup;
import javax.swing.JToggleButton;
import javax.swing.ImageIcon;
import javax.swing.JSeparator;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import oracle.dss.datautil.gui.DefaultBuilderContext;
import java.awt.Image;
import oracle.bali.ewt.graphics.ImageUtils;

public class NewOrOpenPanel extends DefaultStandardPanel  {
  JToggleButton btnCrosstab = new JToggleButton(new ImageIcon(ImageUtils.getImageResource (getClass(), "images/crosstab_db.gif")), true);
  JToggleButton btnGraph = new JToggleButton(new ImageIcon(ImageUtils.getImageResource (getClass(), "images/graph_db.gif")), false);
  ButtonGroup btnGroup = new ButtonGroup();
  NewPresentationWizard m_newPrezWiz = null;
  Image m_image;

  public NewOrOpenPanel() {
    super();
  }
  public String getId() {
    return "NEW_OR_OPEN";
  }

  // Returns the title for this panel
  public String getTitle() {
      return "Create/Open Worksheet";
  }

  // Returns the image that is displayed on the left-hand side of the wizard
  public Image getImage() {
      return m_image;
  }

  // Initialize the UI that enables the user to select the presentation type
  public boolean initUIContent () {
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    this.setLayout(gridBagLayout1);

    // User can pick a Crosstab or Graph using the toggle buttons
    btnGroup.add(btnCrosstab);
    btnGroup.add(btnGraph);
    
    ImageIcon iconCrosstab = new ImageIcon(ImageUtils.getImageResource (getClass(), "images/crosstab_db.gif")); 
    btnCrosstab.setIcon(iconCrosstab);
    btnCrosstab.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          btnViewType_actionPerformed(e);
        }
      });

    ImageIcon iconGraph = new ImageIcon(ImageUtils.getImageResource (getClass(), "images/graph_db.gif")); 
    btnGraph.setIcon(iconGraph);
    btnGraph.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          btnViewType_actionPerformed(e);
        }
      });

    int left = 40;
    this.add(new JLabel("What type of presentation would you like to create?"), 
             new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, left, 0, 0), 0, 0));
    this.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, left, 5, 0), 0, 0));

    this.add(btnCrosstab, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(8, left, 2, 0), 0, 0));

    this.add(new JLabel("Crosstab"), 
             new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(8, 4, 5, 0), 0, 0));

    this.add(btnGraph, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, left, 2, 0), 0, 0));
    this.add(new JLabel("Graph"), 
             new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 4, 5, 0), 0, 0));    

    return true;

  }

  void btnViewType_actionPerformed(ActionEvent e) {
    // Set the view type based on the selected toggle button
    if (e.getSource().equals(btnGraph)) {
      m_newPrezWiz.setViewType(NewPresentationWizard.GRAPH);
    }
    else {
      m_newPrezWiz.setViewType(NewPresentationWizard.CROSSTAB);
    }
  }
  
}