KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > panels > DataCheckPanel


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2002 Jan Blok
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * This panel written by Hal Vaughan
22  * http://thresholddigital.com
23  * hal@thresholddigital.com
24  *
25  * And updated by Fabrice Mirabile
26  * miraodb@hotmail.com
27  */

28
29 package com.izforge.izpack.panels;
30
31 import java.util.Enumeration JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Properties JavaDoc;
34
35 import javax.swing.BoxLayout JavaDoc;
36 import javax.swing.JEditorPane JavaDoc;
37 import javax.swing.JLabel JavaDoc;
38 import javax.swing.JScrollPane JavaDoc;
39
40 import com.izforge.izpack.installer.InstallData;
41 import com.izforge.izpack.installer.InstallerFrame;
42 import com.izforge.izpack.installer.IzPanel;
43 import com.izforge.izpack.Pack;
44
45 /**
46  *
47  * DataCheckPanel: Provide a lot of debugging information. Print a simple header of our
48  * instance number and a line to separate output from other instances, then print all
49  * the InstallData variables and list all the packs and selected packs. I hope this will
50  * be expanded by others to provide needed debugging information by those developing panels
51  * for IzPack.
52  * @author Hal Vaughan
53  * @author Fabrice Mirabile
54  */

55 public class DataCheckPanel extends IzPanel
56 {
57     
58     private static final long serialVersionUID = 3257848774955905587L;
59     
60     static int instanceCount = 0;
61     
62     protected int instanceNumber = 0;
63     
64     private InstallData iData;
65     
66     JEditorPane JavaDoc staticText;
67             
68     /**
69      * The constructor.
70      *
71      * @param parent The parent.
72      * @param id The installation data.
73      */

74     public DataCheckPanel(InstallerFrame parent, InstallData id)
75     {
76         super(parent, id);
77         
78         iData = id;
79         instanceNumber = instanceCount++;
80         
81         String JavaDoc sInfo = "Debugging data. All InstallData variables and all packs (selected packs are marked).";
82         BoxLayout JavaDoc bLayout = new BoxLayout JavaDoc(this, BoxLayout.Y_AXIS);
83         setLayout (bLayout);
84 // setLayout(new GridLayout(3,1));
85
JLabel JavaDoc lInfo = new JLabel JavaDoc(sInfo);
86         add(lInfo);
87         staticText = new JEditorPane JavaDoc();
88         staticText.setEditable(false);
89         JScrollPane JavaDoc scrollText = new JScrollPane JavaDoc(staticText);
90         add(new JLabel JavaDoc(" "));
91         add(scrollText);
92         
93     }
94     
95     /**
96      * When the panel is made active, call the printDebugInfo method.
97      *
98      * @see com.izforge.izpack.installer.IzPanel#panelActivate()
99      * @param none
100      * @return void
101      */

102     public void panelActivate()
103     {
104         printDebugInfo();
105         return;
106     }
107     
108     /**
109      * Get and return the list of pack names.
110      *
111      * @param packList
112      * @return String
113      */

114     private String JavaDoc getPackNames(List JavaDoc packList)
115     {
116         int i;
117         String JavaDoc pStatus;
118         String JavaDoc sOutput = "";
119         Pack iPack;
120         for (i = 0; i < packList.size(); i++)
121         {
122             iPack = (Pack) packList.get(i);
123             if (iData.selectedPacks.indexOf(iPack) != -1)
124                 pStatus = "Selected";
125             else
126                 pStatus = "Unselected";
127             sOutput = sOutput + "\t" + i + ": " + iPack.name + " (" + pStatus + ")\n";
128         }
129         return sOutput;
130     }
131
132     /**
133      * Print list of variables names and value, as well as the list
134      * of packages and their status (selected or not).
135      *
136      * @param none
137      * @return void
138      */

139     private void printDebugInfo()
140     {
141         int i = 0;
142         String JavaDoc sInfo = "InstallData Variables:\n";
143         System.out.println("------------------------Data Check Panel Instance " +
144                 instanceNumber + "------------------------");
145         System.out.println("InstallData Variables:");
146         Properties JavaDoc varList = iData.getVariables();
147         String JavaDoc[] alphaName = new String JavaDoc[varList.size()];
148         Enumeration JavaDoc varNames = varList.propertyNames();
149         while (varNames.hasMoreElements())
150             alphaName[i++] = (String JavaDoc) varNames.nextElement();
151         java.util.Arrays.sort(alphaName);
152         for (i = 0; i < alphaName.length; i++)
153             sInfo = sInfo + "\tName: " + alphaName[i] + ", Value: " + varList.getProperty(alphaName[i]) + "\n";
154         sInfo = sInfo + "\nAvailable Packs: \n" + getPackNames(iData.allPacks) + "\n";
155         System.out.println(sInfo);
156         staticText.setText(sInfo);
157     }
158
159     /**
160      * By nature, always true.
161      *
162      * @return True
163      */

164     public boolean isValidated()
165     {
166         return true;
167     }
168 }
169
Popular Tags