001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.wizard.components.panels;
038:
039: import java.awt.Color;
040: import java.awt.GridBagConstraints;
041: import java.awt.Insets;
042: import java.awt.event.ActionEvent;
043: import java.awt.event.ActionListener;
044: import java.util.LinkedList;
045: import java.util.List;
046: import javax.swing.JComponent;
047: import javax.swing.border.EmptyBorder;
048: import org.netbeans.installer.product.components.Product;
049: import org.netbeans.installer.product.Registry;
050: import org.netbeans.installer.utils.StringUtils;
051: import org.netbeans.installer.utils.ErrorManager;
052: import org.netbeans.installer.utils.SystemUtils;
053: import org.netbeans.installer.utils.exceptions.InitializationException;
054: import org.netbeans.installer.utils.helper.swing.NbiCheckBox;
055: import org.netbeans.installer.utils.helper.swing.NbiScrollPane;
056: import org.netbeans.installer.utils.helper.swing.NbiTextPane;
057: import org.netbeans.installer.utils.helper.Text;
058: import org.netbeans.installer.utils.ResourceUtils;
059: import org.netbeans.installer.wizard.ui.SwingUi;
060: import org.netbeans.installer.wizard.ui.WizardUi;
061: import org.netbeans.installer.wizard.components.WizardPanel;
062: import org.netbeans.installer.wizard.components.WizardPanel.WizardPanelSwingUi;
063: import org.netbeans.installer.wizard.components.WizardPanel.WizardPanelUi;
064: import org.netbeans.installer.wizard.containers.SwingContainer;
065:
066: public class LicensesPanel extends WizardPanel {
067: /////////////////////////////////////////////////////////////////////////////////
068: // Instance
069: public LicensesPanel() {
070: setProperty(TITLE_PROPERTY, DEFAULT_TITLE);
071: setProperty(DESCRIPTION_PROPERTY, DEFAULT_DESCRIPTION);
072:
073: setProperty(ACCEPT_CHECKBOX_TEXT_PROPERTY,
074: DEFAULT_ACCEPT_CHECKBOX_TEXT);
075: setProperty(ERROR_CANNOT_GET_LOGIC_PROPERTY,
076: DEFAULT_ERROR_CANNOT_GET_LOGIC);
077: setProperty(APPEND_LICENSE_FORMAT_PROPERTY,
078: DEFAULT_APPEND_LICENSE_FORMAT);
079: setProperty(SINGLE_PRODUCT_LICENSE_FORMAT_PROPERTY,
080: DEFAULT_SINGLE_PRODUCT_LICENSE_FORMAT);
081: setProperty(OVERALL_LICENSE_FORMAT_PROPERTY,
082: DEFAULT_OVERALL_LICENSE_FORMAT);
083: }
084:
085: @Override
086: public boolean canExecuteForward() {
087: return Registry.getInstance().getProductsToInstall().size() > 0;
088: }
089:
090: @Override
091: public boolean canExecuteBackward() {
092: return Registry.getInstance().getProductsToInstall().size() > 0;
093: }
094:
095: @Override
096: public WizardUi getWizardUi() {
097: if (wizardUi == null) {
098: wizardUi = new LicensesPanelUi(this );
099: }
100:
101: return wizardUi;
102: }
103:
104: /////////////////////////////////////////////////////////////////////////////////
105: // Inner Classes
106: public static class LicensesPanelUi extends WizardPanelUi {
107: protected LicensesPanel component;
108:
109: public LicensesPanelUi(LicensesPanel component) {
110: super (component);
111:
112: this .component = component;
113: }
114:
115: @Override
116: public SwingUi getSwingUi(SwingContainer container) {
117: if (swingUi == null) {
118: swingUi = new LicensesPanelSwingUi(component, container);
119: }
120:
121: return super .getSwingUi(container);
122: }
123: }
124:
125: public static class LicensesPanelSwingUi extends WizardPanelSwingUi {
126: protected LicensesPanel component;
127:
128: private List<Product> acceptedProducts;
129:
130: private NbiTextPane licensePane;
131: private NbiScrollPane licenseScrollPane;
132:
133: private NbiCheckBox acceptCheckBox;
134:
135: public LicensesPanelSwingUi(final LicensesPanel component,
136: final SwingContainer container) {
137: super (component, container);
138:
139: this .component = component;
140: this .acceptedProducts = new LinkedList<Product>();
141:
142: initComponents();
143: }
144:
145: @Override
146: public JComponent getDefaultFocusOwner() {
147: return acceptCheckBox;
148: }
149:
150: // protected ////////////////////////////////////////////////////////////////
151: @Override
152: protected void initialize() {
153: acceptCheckBox.setText(component
154: .getProperty(ACCEPT_CHECKBOX_TEXT_PROPERTY));
155:
156: final List<Product> currentProducts = Registry
157: .getInstance().getProductsToInstall();
158:
159: final StringBuilder text = new StringBuilder();
160:
161: boolean everythingAccepted = true;
162:
163: if (System.getProperty(OVERALL_LICENSE_RESOURCE_PROPERTY) != null) {
164: if (acceptedProducts.size() == 0) {
165: everythingAccepted = false;
166: }
167: final String licenseValue = SystemUtils
168: .resolveString(System
169: .getProperty(OVERALL_LICENSE_RESOURCE_PROPERTY));
170: final String license = SystemUtils.resolveString("$R{"
171: + licenseValue + "}");
172: final String format = component
173: .getProperty(OVERALL_LICENSE_FORMAT_PROPERTY);
174: text.append(StringUtils.format(format, license));
175: } else {
176: final String format = (currentProducts.size() == 1) ? component
177: .getProperty(SINGLE_PRODUCT_LICENSE_FORMAT_PROPERTY)
178: : component
179: .getProperty(APPEND_LICENSE_FORMAT_PROPERTY);
180:
181: for (Product product : currentProducts) {
182: if (!acceptedProducts.contains(product)) {
183: everythingAccepted = false;
184: }
185: try {
186: Text license = product.getLogic().getLicense();
187: if (license != null) {
188: text.append(StringUtils.format(format,
189: product.getDisplayName(), license
190: .getText()));
191: }
192: } catch (InitializationException e) {
193: ErrorManager
194: .notifyError(
195: component
196: .getProperty(ERROR_CANNOT_GET_LOGIC_PROPERTY),
197: e);
198: }
199: }
200: }
201: licensePane.setText(text);
202: licensePane.setCaretPosition(0);
203:
204: if (!everythingAccepted) {
205: acceptCheckBox.setSelected(false);
206: }
207:
208: acceptCheckBoxToggled();
209: }
210:
211: // private //////////////////////////////////////////////////////////////////
212: private void initComponents() {
213: // licensePane //////////////////////////////////////////////////////////
214: licensePane = new NbiTextPane();
215: licensePane.setOpaque(true);
216: licensePane.setBackground(Color.WHITE);
217: licensePane.setBorder(new EmptyBorder(
218: new Insets(5, 5, 5, 5)));
219:
220: // licenseScrollPane ////////////////////////////////////////////////////
221: licenseScrollPane = new NbiScrollPane(licensePane);
222:
223: // acceptCheckBox ///////////////////////////////////////////////////////
224: acceptCheckBox = new NbiCheckBox();
225: acceptCheckBox.setSelected(false);
226: acceptCheckBox.addActionListener(new ActionListener() {
227: public void actionPerformed(ActionEvent event) {
228: acceptCheckBoxToggled();
229: }
230: });
231:
232: // this /////////////////////////////////////////////////////////////////
233: add(licenseScrollPane, new GridBagConstraints(0, 0, // x, y
234: 1, 1, // width, height
235: 1.0, 1.0, // weight-x, weight-y
236: GridBagConstraints.LINE_START, // anchor
237: GridBagConstraints.BOTH, // fill
238: new Insets(11, 11, 0, 11), // padding
239: 0, 0)); // padx, pady - ???
240: add(acceptCheckBox, new GridBagConstraints(0, 2, // x, y
241: 1, 1, // width, height
242: 1.0, 0.0, // weight-x, weight-y
243: GridBagConstraints.LINE_START, // anchor
244: GridBagConstraints.HORIZONTAL, // fill
245: new Insets(7, 11, 11, 11), // padding
246: 0, 0)); // padx, pady - ???
247: }
248:
249: private void acceptCheckBoxToggled() {
250: if (acceptCheckBox.isSelected()) {
251: for (Product product : Registry.getInstance()
252: .getProductsToInstall()) {
253: if (!acceptedProducts.contains(product)) {
254: acceptedProducts.add(product);
255: }
256: }
257:
258: container.getNextButton().setEnabled(true);
259: } else {
260: container.getNextButton().setEnabled(false);
261: }
262: }
263: }
264:
265: /////////////////////////////////////////////////////////////////////////////////
266: // Constants
267: public static final String ACCEPT_CHECKBOX_TEXT_PROPERTY = "accept.checkbox.text"; // NOI18N
268: public static final String ERROR_CANNOT_GET_LOGIC_PROPERTY = "error.cannot.get.logic";//NOI18N
269: public static final String OVERALL_LICENSE_RESOURCE_PROPERTY = "nbi.overall.license.resource";//NOI18N
270: public static final String APPEND_LICENSE_FORMAT_PROPERTY = "append.license.format";//NOI18N
271: public static final String OVERALL_LICENSE_FORMAT_PROPERTY = "overall.license.format";//NOI18N
272: public static final String SINGLE_PRODUCT_LICENSE_FORMAT_PROPERTY = "single.product.license.format";//NOI18N
273: public static final String DEFAULT_TITLE = ResourceUtils.getString(
274: LicensesPanel.class, "LP.title"); // NOI18N
275: public static final String DEFAULT_DESCRIPTION = ResourceUtils
276: .getString(LicensesPanel.class, "LP.description"); // NOI18N
277: public static final String DEFAULT_APPEND_LICENSE_FORMAT = ResourceUtils
278: .getString(LicensesPanel.class, "LP.append.license.format"); // NOI18N
279: public static final String DEFAULT_OVERALL_LICENSE_FORMAT = ResourceUtils
280: .getString(LicensesPanel.class, "LP.overall.license.format"); // NOI18N
281: public static final String DEFAULT_SINGLE_PRODUCT_LICENSE_FORMAT = ResourceUtils
282: .getString(LicensesPanel.class,
283: "LP.single.product.license.format"); // NOI18N
284: public static final String DEFAULT_ACCEPT_CHECKBOX_TEXT = ResourceUtils
285: .getString(LicensesPanel.class, "LP.accept.checkbox.text"); // NOI18N
286: public static final String DEFAULT_ERROR_CANNOT_GET_LOGIC = ResourceUtils
287: .getString(LicensesPanel.class, "LP.error.cannot.get.logic"); // NOI18N
288: }
|