/*
 * PresentationTypePanel.java
 *
 * Copyright (c) 2003, Oracle Corporation. All rights reserved. Oracle grants
 * you ("Licensee") a non-exclusive, royalty-free, worldwide license to use,
 * modify and redistribute this software in source and binary code form, provided
 * that (i) this copyright notice and license appear on all copies of the
 * software; (ii) Licensee does not utilize the software in a manner disparaging
 * to Oracle; and (iii) Licensee does not utilize the software in a manner that
 * violates the terms of any Licensee agreement with Oracle.
 */

package samples.javaclient.analyzer;
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;

 /**
  * The first panel of the New Presentation wizard.  It prompts the user
  * to select the type of presentation to create.
  * 
  */
public class PresentationTypePanel extends DefaultStandardPanel  {
  /**
   * Button for choosing to create a crosstab.
   */
  JToggleButton btnCrosstab = new JToggleButton(new ImageIcon(ImageUtils.getImageResource (getClass(), "images/crosstab_db.gif")), true);
  /**
   * Button for choosing to create a graph.
   */
  JToggleButton btnGraph = new JToggleButton(new ImageIcon(ImageUtils.getImageResource (getClass(), "images/graph_db.gif")), false);
  /**
   * Group for btnGraph and btnCrosstab, so only one can be selected at a time.
   */
  ButtonGroup btnGroup = new ButtonGroup();
  /**
   * Wizard that this panel is added to.
   */
  NewPresentationWizard m_newPrezWiz = null;
  /**
   * Image to display in this panel.
   */
  Image m_image;

  /** 
   * Constructor.
   * 
   * @param npw The wizard to add this panel to.
   */
  public PresentationTypePanel(NewPresentationWizard npw) {
    super();
    m_newPrezWiz = npw;
    m_image = ImageUtils.getImageResource (getClass(), "images/graph.gif");
  }

  /** 
   * Gets the unique ID for this panel.
   * @return "PRESENTATION_TYPE".
   */
  public String getId () {
    return "PRESENTATION_TYPE";
  }

  /** 
   * Gets the title for this panel.
   * @return "Choose a Presentation Type".
   */
  public String getTitle() {
      return "Choose a Presentation Type";
  }

  /** 
   * Gets the image that is displayed on the left-hand side of the wizard.
   * @return The image to display.
   */
  public Image getImage() {
      return m_image;
  }

  /** 
   * Initializes the user interface for this panel.
   * @return <code>true</code>.
   */
  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("How would you like to display your data?"), 
             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;

  }

  /**
   * Responds to button clicks.
   * This method sets the view type on the NewPresentationWizard.
   * 
   * @param e Information about what the user clicked.
   * @see NewPresentationWizard#setViewType
   */
  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);
    }
  }

}