/*
 *  SpecialDialog.java
 * 
 *  RELOAD Editor - An IMS Metadata, Content Packaging and Learning Design tool 
 *  with ADAPTATION AT ACTIVITY LEVEL
 *
 *  Copyright (c) 2006 Miguel Fernandez Lores
 *
 *  Technical Contact:
 *  Miguel Fern�ndez Lores
 *  e-mail: tucias@hotmail.com
 *
 */

package uk.ac.reload.editor.scormadaptive.rules.tools;

/**
 * Gestiona los JOptionPane de aceptacion, entrada de datos,
 * confirmacion y error
 *
 * @author  lagar
 * @version 0.2 
 */
public class SpecialDialog {
    
    /**
     * Este metodo presenta un mensaje de informacion al usuario con un boton para
     * aceptarlo.
     */
    public static int showMessageDialog(java.awt.Component oComponent,Object oMessage,String sTitle,int iOption,int iType) {
        String[] oOptions = new String[1];
        oOptions[0]="Accept"; // Opci�n ACEPTAR
        javax.swing.JOptionPane oPane = new javax.swing.JOptionPane(oMessage,iType,iOption,null,oOptions);
        javax.swing.JDialog oDialog = oPane.createDialog(oComponent, sTitle);
        oDialog.setVisible(true);
        Object oSelectedValue = oPane.getValue();
        if (oSelectedValue == null) return javax.swing.JOptionPane.CLOSED_OPTION;
        if (oSelectedValue.equals(oOptions[0])) return javax.swing.JOptionPane.OK_OPTION;
        return javax.swing.JOptionPane.CLOSED_OPTION;
        
    }
    
    /**
     * Este metodo se utiliza para preguntar al usuario sobre una accion
     * El usuario debe responder si o no;
     */
    public static int showConfirmDialog(java.awt.Component oComponent,Object oMessage,String sTitle,int iOption) {
        return showConfirmDialog(oComponent, oMessage, sTitle, iOption,javax.swing.JOptionPane.QUESTION_MESSAGE);
    }
    
    /**
     * Este metodo se utiliza para preguntar al usuario sobre una accion
     * El usuario debe responder si o no;
     */
    public static int showConfirmDialog(java.awt.Component oComponent,Object oMessage,String sTitle,int iOption,int iType) {
        String[] oOptions = new String[2];
        oOptions[0]="YES"; // Opcion SI
        oOptions[1]="NO"; // Opcion NO
        javax.swing.JOptionPane oPane = new javax.swing.JOptionPane(oMessage,iType,iOption,null,oOptions);
        javax.swing.JDialog oDialog = oPane.createDialog(oComponent, sTitle);
        oDialog.setVisible(true);
        Object oSelectedValue = oPane.getValue();
        if (oSelectedValue == null) return javax.swing.JOptionPane.CLOSED_OPTION;
        if (oSelectedValue.equals(oOptions[0])) return javax.swing.JOptionPane.YES_OPTION;
        if (oSelectedValue.equals(oOptions[1])) return javax.swing.JOptionPane.NO_OPTION;
        return javax.swing.JOptionPane.CLOSED_OPTION;
    }
    
    /**
     * Dialogo para que el usuario introduzca algun parametro
     */
    public static String showInputDialog(java.awt.Component oComponent,Object oMessage,String sTitle,int iType) {
        String[] oOptions = new String[2];
        oOptions[0]="ACCEPT";
        oOptions[1]="CANCEL";
        javax.swing.JOptionPane oPane = new javax.swing.JOptionPane(oMessage,javax.swing.JOptionPane.QUESTION_MESSAGE,javax.swing.JOptionPane.OK_CANCEL_OPTION,null,oOptions);
        oPane.setWantsInput(true);
        javax.swing.JDialog oDialog = oPane.createDialog(oComponent, sTitle);
        oDialog.setVisible(true);
        Object oSelectedValue = oPane.getValue();
        if (oSelectedValue == null) return null;
        if (oSelectedValue.equals(oOptions[0])) return (String) oPane.getInputValue();
        else return null;
    }
    
    /**
     * Dialogo para que el usuario seleccione entre alguno de los parametros
     * que le ofrece el dialogo
     */
    public static Object showInputDialog(java.awt.Component oComponent,Object oMessage,String sTitle,int iType,javax.swing.Icon oIcon,Object[] oValues,Object oInitial) {
        String[] oOptions = new String[2];
        oOptions[0]="ACCEPT";
        oOptions[1]="CANCEL";
        javax.swing.JOptionPane oPane = new javax.swing.JOptionPane(oMessage,javax.swing.JOptionPane.QUESTION_MESSAGE,javax.swing.JOptionPane.OK_CANCEL_OPTION,null,oOptions);
        oPane.setWantsInput(true);
        oPane.setSelectionValues(oValues);
        oPane.setInitialSelectionValue(oInitial);
        javax.swing.JDialog oDialog = oPane.createDialog(oComponent, sTitle);
        oDialog.setVisible(true);
        Object oSelectedValue = oPane.getValue();
        if (oSelectedValue == null) return null;
        if (oSelectedValue.equals(oOptions[0])) return oPane.getInputValue();
        else return null;
    }
    
}

