alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.refactoring.ui;

import java.awt.Component;
import java.util.Vector;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.SwingConstants;
import org.netbeans.modules.refactoring.api.Problem;

/**
 *
 * @author  Jan Becicka
 */
public class ErrorPanel extends javax.swing.JPanel {
    
    private DefaultListModel errors = new DefaultListModel();
    private static ImageIcon fatalImage = null, nonFatalImage = null;
    
    /** Creates new form ErrorPanel */
    public ErrorPanel() {
        initComponents();
        errorList.setCellRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
	    if (value instanceof JLabel) {
                setIcon(((JLabel)value).getIcon());
                setText(((JLabel)value).getText());
            }
            return this;
        }});
    }
    
    public ErrorPanel(Problem problem) {
        this();
        setProblems(problem);
    }
    
    public void setProblems(Problem problem) {
        errors.clear();
        while (problem != null) {
            errors.addElement(new JLabel(
              problem.getMessage(),
              problem.isFatal()?getFatalErrorIcon():getNonfatalErrorIcon(),
              SwingConstants.LEFT
            ));
        problem = problem.getNext();
        }
    }
    
    private static ImageIcon getFatalErrorIcon() {
        if (fatalImage == null) {
            fatalImage = new ImageIcon(ErrorPanel.class.getResource("/org/netbeans/modules/refactoring/resources/fatalerror.gif")); //NOI18N
        }
        return fatalImage;
    }
    
    private static ImageIcon getNonfatalErrorIcon() {
        if (nonFatalImage == null) {
            nonFatalImage = new ImageIcon(ErrorPanel.class.getResource("/org/netbeans/modules/refactoring/resources/nonfatalerror.gif")); //NOI18N
        }
        return nonFatalImage;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        headLine = new javax.swing.JLabel();
        listPanel = new javax.swing.JPanel();
        errorLabel = new javax.swing.JLabel();
        listScrollPane = new javax.swing.JScrollPane();
        errorList = new javax.swing.JList(errors);
        explanationPanel = new javax.swing.JPanel();
        fatalError = new javax.swing.JLabel();
        nonFatalError = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        org.openide.awt.Mnemonics.setLocalizedText(headLine, org.openide.util.NbBundle.getMessage(ErrorPanel.class, "LBL_ErrorPanelDescription"));
        headLine.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 10, 1)));
        add(headLine, java.awt.BorderLayout.NORTH);

        listPanel.setLayout(new java.awt.BorderLayout());

        org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(ErrorPanel.class, "LBL_ErrorsList"));
        errorLabel.setLabelFor(errorList);
        listPanel.add(errorLabel, java.awt.BorderLayout.NORTH);

        errorList.setName("");
        listScrollPane.setViewportView(errorList);

        listPanel.add(listScrollPane, java.awt.BorderLayout.CENTER);

        add(listPanel, java.awt.BorderLayout.CENTER);

        explanationPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        org.openide.awt.Mnemonics.setLocalizedText(fatalError, org.openide.util.NbBundle.getMessage(ErrorPanel.class, "LBL_FatalError"));
        fatalError.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/refactoring/resources/fatalerror.gif")));
        fatalError.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 20)));
        explanationPanel.add(fatalError);

        org.openide.awt.Mnemonics.setLocalizedText(nonFatalError, org.openide.util.NbBundle.getMessage(ErrorPanel.class, "LBL_NonFatalError"));
        nonFatalError.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/refactoring/resources/nonfatalerror.gif")));
        explanationPanel.add(nonFatalError);

        add(explanationPanel, java.awt.BorderLayout.SOUTH);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel errorLabel;
    private javax.swing.JList errorList;
    private javax.swing.JPanel explanationPanel;
    private javax.swing.JLabel fatalError;
    private javax.swing.JLabel headLine;
    private javax.swing.JPanel listPanel;
    private javax.swing.JScrollPane listScrollPane;
    private javax.swing.JLabel nonFatalError;
    // End of variables declaration//GEN-END:variables
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.