001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2004 Klaus Bartz
008 * 
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package com.izforge.izpack.panels;
023
024import net.n3.nanoxml.XMLElement;
025
026import com.izforge.izpack.installer.InstallData;
027import com.izforge.izpack.installer.InstallerFrame;
028
029/**
030 * The taget directory selection panel.
031 * 
032 * @author Julien Ponge
033 */
034public class TargetPanel extends PathInputPanel
035{
036
037    /**
038     * 
039     */
040    private static final long serialVersionUID = 3256443616359429170L;
041
042    /**
043     * The constructor.
044     * 
045     * @param parent The parent window.
046     * @param idata The installation data.
047     */
048    public TargetPanel(InstallerFrame parent, InstallData idata)
049    {
050        super(parent, idata);
051        // load the default directory info (if present)
052        loadDefaultInstallDir(parent, idata);
053        if (getDefaultInstallDir() != null)
054        {
055            // override the system default that uses app name (which is set in
056            // the Installer class)
057            idata.setInstallPath(getDefaultInstallDir());
058        }
059    }
060
061    /** Called when the panel becomes active. */
062    public void panelActivate()
063    {
064        // Resolve the default for chosenPath
065        super.panelActivate();
066        // Set the default or old value to the path selection panel.
067        pathSelectionPanel.setPath(idata.getInstallPath());
068    }
069
070    /**
071     * This method simple delegates to <code>PathInputPanel.loadDefaultInstallDir</code> with the
072     * current parent as installer frame.
073     */
074    public void loadDefaultDir()
075    {
076        super.loadDefaultInstallDir(parent, idata);
077    }
078
079    /**
080     * Indicates wether the panel has been validated or not.
081     * 
082     * @return Wether the panel has been validated or not.
083     */
084    public boolean isValidated()
085    {
086        // Standard behavior of PathInputPanel.
087        if (!super.isValidated()) return (false);
088        idata.setInstallPath(pathSelectionPanel.getPath());
089        return (true);
090    }
091
092    /**
093     * Returns the default install directory. This is equal to
094     * <code>PathInputPanel.getDefaultInstallDir</code>
095     * 
096     * @return the default install directory
097     */
098    public String getDefaultDir()
099    {
100        return getDefaultInstallDir();
101    }
102
103    /**
104     * Sets the default install directory to the given String. This is equal to
105     * <code>PathInputPanel.setDefaultInstallDir</code>
106     * 
107     * @param defaultDir path to be used for the install directory
108     */
109    public void setDefaultDir(String defaultDir)
110    {
111        setDefaultInstallDir(defaultDir);
112    }
113
114    /**
115     * Asks to make the XML panel data.
116     * 
117     * @param panelRoot The tree to put the data in.
118     */
119    public void makeXMLData(XMLElement panelRoot)
120    {
121        new TargetPanelAutomationHelper().makeXMLData(idata, panelRoot);
122    }
123
124    /*
125     * (non-Javadoc)
126     * 
127     * @see com.izforge.izpack.installer.IzPanel#getSummaryBody()
128     */
129    public String getSummaryBody()
130    {
131        return (idata.getInstallPath());
132    }
133}