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:
022: package com.izforge.izpack.panels;
023:
024: import java.awt.LayoutManager2;
025: import java.util.ArrayList;
026:
027: import javax.swing.JLabel;
028:
029: import com.izforge.izpack.Info;
030: import com.izforge.izpack.gui.IzPanelLayout;
031: import com.izforge.izpack.gui.LabelFactory;
032: import com.izforge.izpack.gui.LayoutConstants;
033: import com.izforge.izpack.installer.InstallData;
034: import com.izforge.izpack.installer.InstallerFrame;
035: import com.izforge.izpack.installer.IzPanel;
036:
037: /**
038: * The Hello panel class.
039: *
040: * @author Julien Ponge
041: */
042: public class HelloPanel extends IzPanel {
043:
044: /**
045: *
046: */
047: private static final long serialVersionUID = 3257848774955905587L;
048:
049: /**
050: * The constructor.
051: *
052: * @param parent The parent.
053: * @param idata The installation data.
054: */
055: public HelloPanel(InstallerFrame parent, InstallData idata) {
056: this (parent, idata, new IzPanelLayout());
057: }
058:
059: /**
060: * Creates a new HelloPanel object with the given layout manager. Valid layout manager are the
061: * IzPanelLayout and the GridBagLayout. New panels should be use the IzPanelLaout. If lm is
062: * null, no layout manager will be created or initialized.
063: *
064: * @param parent The parent IzPack installer frame.
065: * @param idata The installer internal data.
066: * @param layout layout manager to be used with this IzPanel
067: */
068:
069: public HelloPanel(InstallerFrame parent, InstallData idata,
070: LayoutManager2 layout) {
071: // Layout handling. This panel was changed from a mixed layout handling
072: // with GridBagLayout and BoxLayout to IzPanelLayout. It can be used as an
073: // example how to use the IzPanelLayout. For this there are some comments
074: // which are excrescent for a "normal" panel.
075: // Set a IzPanelLayout as layout for this panel.
076: // This have to be the first line during layout if IzPanelLayout will be used.
077: super (parent, idata, layout);
078: // We create and put the labels
079: String str;
080: str = parent.langpack.getString("HelloPanel.welcome1")
081: + idata.info.getAppName() + " "
082: + idata.info.getAppVersion()
083: + parent.langpack.getString("HelloPanel.welcome2");
084: JLabel welcomeLabel = LabelFactory.create(str, parent.icons
085: .getImageIcon("host"), LEADING);
086: // IzPanelLayout is a constraint orientated layout manager. But if no constraint is
087: // given, a default will be used. It starts in the first line.
088: // NEXT_LINE have to insert also in the first line!!
089: add(welcomeLabel, NEXT_LINE);
090: // Yes, there exist also a strut for the IzPanelLayout.
091: // But the strut will be only used for one cell. A vertical strut will be use
092: // NEXT_ROW, a horizontal NEXT_COLUMN. For more information see the java doc.
093: // add(IzPanelLayout.createVerticalStrut(20));
094: // But for a strut you have to define a fixed height. Alternative it is possible
095: // to create a paragraph gap which is configurable.
096: add(IzPanelLayout.createParagraphGap());
097:
098: ArrayList<Info.Author> authors = idata.info.getAuthors();
099: int size = authors.size();
100: if (size > 0) {
101: str = parent.langpack.getString("HelloPanel.authors");
102: JLabel appAuthorsLabel = LabelFactory.create(str,
103: parent.icons.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 label;
116: for (int i = 0; i < size; i++) {
117: Info.Author a = authors.get(i);
118: String email = (a.getEmail() != null && a.getEmail()
119: .length() > 0) ? (" <" + a.getEmail() + ">")
120: : "";
121: label = LabelFactory.create(
122: " - " + a.getName() + email, parent.icons
123: .getImageIcon("empty"), LEADING);
124: add(label, NEXT_LINE);
125: }
126: add(IzPanelLayout.createParagraphGap());
127: }
128:
129: if (idata.info.getAppURL() != null) {
130: str = parent.langpack.getString("HelloPanel.url")
131: + idata.info.getAppURL();
132: JLabel appURLLabel = LabelFactory.create(str, parent.icons
133: .getImageIcon("bookmark"), LEADING);
134: add(appURLLabel, LayoutConstants.NEXT_LINE);
135: }
136: // At end of layouting we should call the completeLayout method also they do nothing.
137: getLayoutHelper().completeLayout();
138: }
139:
140: /**
141: * Indicates wether the panel has been validated or not.
142: *
143: * @return Always true.
144: */
145: public boolean isValidated() {
146: return true;
147: }
148: }
|