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.utils;
038:
039: import java.awt.BorderLayout;
040: import java.awt.Font;
041: import java.awt.GridBagConstraints;
042: import java.awt.GridBagLayout;
043: import java.awt.Insets;
044: import java.io.File;
045: import java.io.IOException;
046: import javax.swing.JScrollPane;
047: import javax.swing.border.EmptyBorder;
048: import org.netbeans.installer.utils.helper.ErrorLevel;
049: import org.netbeans.installer.utils.ErrorManager;
050: import org.netbeans.installer.utils.FileUtils;
051: import org.netbeans.installer.utils.LogManager;
052: import org.netbeans.installer.utils.ResourceUtils;
053: import org.netbeans.installer.utils.helper.swing.NbiDialog;
054: import org.netbeans.installer.utils.helper.swing.NbiLabel;
055: import org.netbeans.installer.utils.helper.swing.NbiPanel;
056: import org.netbeans.installer.utils.helper.swing.NbiScrollPane;
057: import org.netbeans.installer.utils.helper.swing.NbiTextPane;
058:
059: public class InstallationLogDialog extends NbiDialog {
060: private NbiTextPane logPane;
061: private NbiPanel logPanel;
062: private NbiScrollPane logScrollPane;
063:
064: private NbiLabel errorLabel;
065:
066: private File logFile;
067: private static final String MSG_LOADING_LOGFILE_KEY = "ILD.loading.logfile";//NOI18N
068: private static final String ERROR_READING_LOGFILE_KEY = "ILD.error.reading.log";//NOI18N
069: private static final String ERROR_LOG_CONTENTS = "ILD.error.log.contents";//NOI18N
070:
071: public InstallationLogDialog() {
072: super ();
073:
074: initComponents();
075: initialize();
076: }
077:
078: private void initialize() {
079: logFile = LogManager.getLogFile();
080:
081: setTitle(logFile.getAbsolutePath());
082: }
083:
084: private void initComponents() {
085: setLayout(new GridBagLayout());
086:
087: logPane = new NbiTextPane();
088: logPane.setFont(new Font("Monospaced", logPane.getFont()
089: .getStyle(), logPane.getFont().getSize()));
090:
091: logPanel = new NbiPanel();
092: logPanel.setLayout(new BorderLayout());
093: logPanel.add(logPane, BorderLayout.CENTER);
094:
095: logScrollPane = new NbiScrollPane(logPanel);
096: logScrollPane.setViewportBorder(new EmptyBorder(new Insets(5,
097: 5, 5, 5)));
098: logScrollPane
099: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
100:
101: errorLabel = new NbiLabel();
102:
103: add(logScrollPane, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
104: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
105: new Insets(11, 11, 11, 11), 0, 0));
106: add(errorLabel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
107: GridBagConstraints.CENTER, GridBagConstraints.NONE,
108: new Insets(11, 11, 11, 11), 0, 0));
109: }
110:
111: public void loadLogFile() {
112: try {
113: logScrollPane.setVisible(false);
114: errorLabel.setVisible(true);
115:
116: errorLabel.setText(ResourceUtils.getString(
117: InstallationLogDialog.class,
118: MSG_LOADING_LOGFILE_KEY));
119: logPane.setText(FileUtils.readFile(logFile));
120: logPane.setCaretPosition(0);
121:
122: logScrollPane.setVisible(true);
123: errorLabel.setVisible(false);
124: } catch (IOException e) {
125: ErrorManager.notify(ErrorLevel.WARNING, ResourceUtils
126: .getString(InstallationLogDialog.class,
127: ERROR_READING_LOGFILE_KEY, logFile), e);
128:
129: errorLabel.setText(ResourceUtils.getString(
130: InstallationLogDialog.class, ERROR_LOG_CONTENTS));
131:
132: logScrollPane.setVisible(false);
133: errorLabel.setVisible(true);
134: }
135: }
136: }
|