import java.io.File;
import java.io.FileOutputStream;
import com.denova.ui.UiPopups;
import com.denova.ui.WizardPanel;
import com.denova.util.PropertyList;
import com.denova.JExpress.Installer.CustomUninstaller;
import com.denova.JExpress.Installer.InstallPropertyNamex


/*
    Template if you'd like to get the user to input data during
    the installation. It's recommended, but not required, that you
    prompt for additional user input before the files are installed.
    This allows the user to answer all questions befoe the installation
    actually begins.

    Copyright (C) 1998-2010 DeNova
    
*/
public class UserInput extends WizardPanel 
                          implements InstallPropertyNames {

    private String progressLabel = getLocalizedString("Configuring");
    
    
    private class Action implements ActionListener
    {
        public void actionPerformed(ActionEvent event)
        {
            Object object = event.getSource();
            if (object == browseButton) {
                logDirMessage("browse button clicked");
                Browse browse = new Browse();
                browse.start();
            }
        }
    }


    private class Browse extends Thread
    {
        public synchronized void run()
        {
            File newDir = 
              VerifyDirectory.browse(DirectoryPanel.this, defaultDirectory, getPropertyList());
            if (newDir != null)
            {
                UiLayoutUtilities.update(dirname, newDir.getPath());
                defaultDirectory = newDir;
            }
        }
    }
    
    
    private class UserInputSwinger extends Swinger
    {
        File dir = null;
        String titleText = null;
        
        public void swingBefore()
        {
            // here's where you'll set up the panel with any
            // information that the installer already knows that
            // you want to show the user or set the focus if there's
            // a JTextField you want the cursor to start in.
            
            // if the dialog box is ready, then just leave this blank
            
            // if you need to do a lot of background work, then you 
            // probably want to disable the Next and Previous buttons
            // here so the user doesn't get confused -- be sure to let
            // them know what you're doing if the screen will be disabled
            // for long -- and remember users measure long in miliseconds
        }
        
        public void workInBackground()
        {
            // You don't want to prompt for user input
            // during a silent install so you need to decide
            // how you'll handle that situation
            if (!getPropertyList().getBooleanProperty(SilentInstall, false))
            {
                // Here's where you add anything that needs to
                // be done before the user can interact with the panel
                // do *not* do anything with the screen in this method
                // (that should be handled in swingBefore() or swingAfter()
            }
        }
        
        public void swingAfter()
        {
            // You have 1 last chance to make changes to the screen
            // before the user can interact with it. If you disabled the
            // Next and Previous buttons, then re-enable them now.
        }
        
        
        private void setFocus(final JTextField field)
        {
            // here's an example of how to set the focus
            // in a JTextField. It should only be called from
            // swingBefore() or swingAfter().
            JTextField textField = (JTextField) field;
            String text = textField. getText();
            int position = 0;
            if (text != null)
            {
                position = text.length();
            }
            textField. requestFocusInWindow();
            textField. setCaretPosition(position);
        }    
    }
    
    
    public UserInput(PropertyList properties)
    {
        super (properties);

        addPanel();
    }
    
    /** 
     * Enter the panel. 
     *
     * Do not call this method; only the wizard should call it.
     */
     public void enter()
     {
        UserInputSwinger swinger = new UserInputSwinger();
        swinger.execute();
     }

    private void addPanel()
    {
        // layout the panel -- see Samples/RegisterPanel.java for an example
    }
    
}  // UserInput