import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.Font;
import java.io.File;
import com.denova.ui.WizardPanel;
import com.denova.util.LocaleTranslator;
import com.denova.util.PropertyList;
import com.denova.JExpress.Installer.InstallPropertyNames;
import com.denova.JExpress.Installer.CustomInstaller;
import com.denova.JExpress.Installer.Installer;


/** Make the installer silent. 
  * This functionality is also available as a setting in JExpress.
  *
  * This eliminates the need for the user to 
  * pass the -q switch and the install directory on the command line.
  *
  * The applicationDirectory *must* be set in the installer's properties *before*
  * trying to make the installer silent.
  *
  * © 2003-2011 DeNova
  * Last modified: 2012-01-15
  *
  * @author DeNova
  *
  * Important:
  *  1. This class must be included in the "Before install" field on the Custom panel in JExpress Developer.
  *
  *  2. This class is not dependent on any other custom classes.
  *
  *  3. You must adapt InstallDir constant to the correct install directory.
  *     A silent install can't ask the user for the install dir.
  *
  *  4. If the installer requires additional custom properties, then you must load those properties
  *     and "addProperties" to the getPropertyList().It would be best to set the applicationDirectory
  *     in the constructor, but load/add any additional properties in the setAcitve() method.
  */


public class MakeInstallerSilent extends WizardPanel {

    // a silent install can't ask the user for the install dir, so we define it 
    // change the following constant to fit the target system
    private final static String InstallDir = "/tmp/test";
    
    
    /**
      *   Make installer silent.
      */

    public MakeInstallerSilent(PropertyList properties) {
    
        // initialize WizardPanel superclass
        super(properties);
    
        File installDir = new File(InstallDir);
        installDir.mkdirs();
        
        properties.setProperty(InstallPropertyNames.ApplicationDirectory, InstallDir);
        
        if (CustomInstaller.makeInstallerSilent())
        {
            CustomInstaller.setVisible(false);
        }
    }


    /** 
     * Enter the panel. 
     *
     * Do not call this method; only the wizard should call it.
     */
     public synchronized void enter()
     {
         CustomInstaller.logToInstaller(
             "app dir: " + getPropertyList().getProperty(
                 InstallPropertyNames.ApplicationDirectory, ""));

        showNextPanel();
    }

    
    /**
      * Determines if the 'Next" button is accessible to the user.
      *
      * @return always false because this is a non-interactive panel.
      */

    public boolean isNextButtonEnabled() {
        return false;
    }

    
    /**
      * Determines if the 'Cancel" button is accessible to the user.
      *
      * @return always false because this is a non-interactive panel.
      */

    public boolean isCancelButtonEnabled() {
        return false;
    }

    
    /**
      * Determines if the 'Back" button is accessible to the user.
      *
      * @return always false because this is a non-interactive panel.
      */

    public boolean isPreviousButtonEnabled() {
        return false;
    }

    
    /**
      * Supplies the name of the panel.
      */

    public String getName() {
        return "MakeInstallerSilent";
    }
    
}  // MakeInstallerSilent