001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2002 Jan Blok
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: * This panel written by Hal Vaughan
022: * http://thresholddigital.com
023: * hal@thresholddigital.com
024: *
025: * And updated by Fabrice Mirabile
026: * miraodb@hotmail.com
027: */
028:
029: package com.izforge.izpack.panels;
030:
031: import java.util.Enumeration;
032: import java.util.List;
033: import java.util.Properties;
034:
035: import javax.swing.BoxLayout;
036: import javax.swing.JEditorPane;
037: import javax.swing.JLabel;
038: import javax.swing.JScrollPane;
039:
040: import com.izforge.izpack.installer.InstallData;
041: import com.izforge.izpack.installer.InstallerFrame;
042: import com.izforge.izpack.installer.IzPanel;
043: import com.izforge.izpack.Pack;
044:
045: /**
046: *
047: * DataCheckPanel: Provide a lot of debugging information. Print a simple header of our
048: * instance number and a line to separate output from other instances, then print all
049: * the InstallData variables and list all the packs and selected packs. I hope this will
050: * be expanded by others to provide needed debugging information by those developing panels
051: * for IzPack.
052: * @author Hal Vaughan
053: * @author Fabrice Mirabile
054: */
055: public class DataCheckPanel extends IzPanel {
056:
057: private static final long serialVersionUID = 3257848774955905587L;
058:
059: static int instanceCount = 0;
060:
061: protected int instanceNumber = 0;
062:
063: private InstallData iData;
064:
065: JEditorPane staticText;
066:
067: /**
068: * The constructor.
069: *
070: * @param parent The parent.
071: * @param id The installation data.
072: */
073: public DataCheckPanel(InstallerFrame parent, InstallData id) {
074: super (parent, id);
075:
076: iData = id;
077: instanceNumber = instanceCount++;
078:
079: String sInfo = "Debugging data. All InstallData variables and all packs (selected packs are marked).";
080: BoxLayout bLayout = new BoxLayout(this , BoxLayout.Y_AXIS);
081: setLayout(bLayout);
082: // setLayout(new GridLayout(3,1));
083: JLabel lInfo = new JLabel(sInfo);
084: add(lInfo);
085: staticText = new JEditorPane();
086: staticText.setEditable(false);
087: JScrollPane scrollText = new JScrollPane(staticText);
088: add(new JLabel(" "));
089: add(scrollText);
090:
091: }
092:
093: /**
094: * When the panel is made active, call the printDebugInfo method.
095: *
096: * @see com.izforge.izpack.installer.IzPanel#panelActivate()
097: */
098: public void panelActivate() {
099: printDebugInfo();
100: }
101:
102: /**
103: * Get and return the list of pack names.
104: *
105: * @param packList
106: * @return String
107: */
108: private String getPackNames(List<Pack> packList) {
109: int i;
110: String pStatus;
111: String sOutput = "";
112: Pack iPack;
113: for (i = 0; i < packList.size(); i++) {
114: iPack = packList.get(i);
115: if (iData.selectedPacks.indexOf(iPack) != -1)
116: pStatus = "Selected";
117: else
118: pStatus = "Unselected";
119: sOutput = sOutput + "\t" + i + ": " + iPack.name + " ("
120: + pStatus + ")\n";
121: }
122: return sOutput;
123: }
124:
125: /**
126: * Print list of variables names and value, as well as the list
127: * of packages and their status (selected or not).
128: *
129: */
130: private void printDebugInfo() {
131: int i = 0;
132: String sInfo = "InstallData Variables:\n";
133: System.out
134: .println("------------------------Data Check Panel Instance "
135: + instanceNumber + "------------------------");
136: System.out.println("InstallData Variables:");
137: Properties varList = iData.getVariables();
138: String[] alphaName = new String[varList.size()];
139: Enumeration<String> varNames = (Enumeration<String>) varList
140: .propertyNames();
141: while (varNames.hasMoreElements())
142: alphaName[i++] = varNames.nextElement();
143: java.util.Arrays.sort(alphaName);
144: for (i = 0; i < alphaName.length; i++)
145: sInfo = sInfo + "\tName: " + alphaName[i] + ", Value: "
146: + varList.getProperty(alphaName[i]) + "\n";
147: sInfo = sInfo + "\nAvailable Packs: \n"
148: + getPackNames(iData.allPacks) + "\n";
149: System.out.println(sInfo);
150: staticText.setText(sInfo);
151: }
152:
153: /**
154: * By nature, always true.
155: *
156: * @return True
157: */
158: public boolean isValidated() {
159: return true;
160: }
161: }
|