KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 package com.izforge.izpack.panels;
23
24 import java.awt.LayoutManager2 JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import javax.swing.JLabel JavaDoc;
28
29 import com.izforge.izpack.Info;
30 import com.izforge.izpack.gui.IzPanelLayout;
31 import com.izforge.izpack.gui.LabelFactory;
32 import com.izforge.izpack.gui.LayoutConstants;
33 import com.izforge.izpack.installer.InstallData;
34 import com.izforge.izpack.installer.InstallerFrame;
35 import com.izforge.izpack.installer.IzPanel;
36
37 /**
38  * The Hello panel class.
39  *
40  * @author Julien Ponge
41  */

42 public class HelloPanel extends IzPanel
43 {
44
45     /**
46      *
47      */

48     private static final long serialVersionUID = 3257848774955905587L;
49
50     /**
51      * The constructor.
52      *
53      * @param parent The parent.
54      * @param idata The installation data.
55      */

56     public HelloPanel(InstallerFrame parent, InstallData idata)
57     {
58         this(parent, idata, new IzPanelLayout());
59     }
60
61     /**
62      * Creates a new HelloPanel object with the given layout manager. Valid layout manager are the
63      * IzPanelLayout and the GridBagLayout. New panels should be use the IzPanelLaout. If lm is
64      * null, no layout manager will be created or initialized.
65      *
66      * @param parent The parent IzPack installer frame.
67      * @param idata The installer internal data.
68      * @param layout layout manager to be used with this IzPanel
69      */

70
71     public HelloPanel(InstallerFrame parent, InstallData idata, LayoutManager2 JavaDoc layout)
72     {
73         // Layout handling. This panel was changed from a mixed layout handling
74
// with GridBagLayout and BoxLayout to IzPanelLayout. It can be used as an
75
// example how to use the IzPanelLayout. For this there are some comments
76
// which are excrescent for a "normal" panel.
77
// Set a IzPanelLayout as layout for this panel.
78
// This have to be the first line during layout if IzPanelLayout will be used.
79
super(parent, idata, layout);
80         // We create and put the labels
81
String JavaDoc str;
82         str = parent.langpack.getString("HelloPanel.welcome1") + idata.info.getAppName() + " "
83                 + idata.info.getAppVersion() + parent.langpack.getString("HelloPanel.welcome2");
84         JLabel JavaDoc welcomeLabel = LabelFactory.create(str, parent.icons.getImageIcon("host"), LEADING);
85         // IzPanelLayout is a constraint orientated layout manager. But if no constraint is
86
// given, a default will be used. It starts in the first line.
87
// NEXT_LINE have to insert also in the first line!!
88
add(welcomeLabel, NEXT_LINE);
89         // Yes, there exist also a strut for the IzPanelLayout.
90
// But the strut will be only used for one cell. A vertical strut will be use
91
// NEXT_ROW, a horizontal NEXT_COLUMN. For more information see the java doc.
92
// add(IzPanelLayout.createVerticalStrut(20));
93
// But for a strut you have to define a fixed height. Alternative it is possible
94
// to create a paragraph gap which is configurable.
95
add(IzPanelLayout.createParagraphGap());
96
97         ArrayList JavaDoc authors = idata.info.getAuthors();
98         int size = authors.size();
99         if (size > 0)
100         {
101             str = parent.langpack.getString("HelloPanel.authors");
102             JLabel JavaDoc appAuthorsLabel = LabelFactory.create(str, parent.icons
103                     .getImageIcon("information"), LEADING);
104             // If nothing will be sad to the IzPanelLayout the position of an add will be
105
// determined in the default constraint. For labels it is CURRENT_ROW, NEXT_COLUMN.
106
// But at this point we would place the label in the next row. It is possible
107
// to create an IzPanelConstraint with this options, but it is also possible to
108
// use simple the NEXT_LINE object as constraint. Attention!! Do not use
109
// LayoutConstants.NEXT_ROW else LayoutConstants.NEXT_LINE because NEXT_ROW is an
110
// int and with it an other add method will be used without any warning (there the
111
// parameter will be used as position of the component in the panel, not the
112
// layout manager.
113
add(appAuthorsLabel, LayoutConstants.NEXT_LINE);
114
115             JLabel JavaDoc label;
116             for (int i = 0; i < size; i++)
117             {
118                 Info.Author a = (Info.Author) authors.get(i);
119                 String JavaDoc email = (a.getEmail() != null && a.getEmail().length() > 0) ? (" <"
120                         + a.getEmail() + ">") : "";
121                 label = LabelFactory.create(" - " + a.getName() + email, parent.icons
122                         .getImageIcon("empty"), LEADING);
123                 add(label, NEXT_LINE);
124             }
125             add(IzPanelLayout.createParagraphGap());
126         }
127
128         if (idata.info.getAppURL() != null)
129         {
130             str = parent.langpack.getString("HelloPanel.url") + idata.info.getAppURL();
131             JLabel JavaDoc appURLLabel = LabelFactory.create(str, parent.icons.getImageIcon("bookmark"),
132                     LEADING);
133             add(appURLLabel, LayoutConstants.NEXT_LINE);
134         }
135         // At end of layouting we should call the completeLayout method also they do nothing.
136
getLayoutHelper().completeLayout();
137     }
138
139     /**
140      * Indicates wether the panel has been validated or not.
141      *
142      * @return Always true.
143      */

144     public boolean isValidated()
145     {
146         return true;
147     }
148 }
149
Popular Tags