All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pekinsoft.desktop.error.MessagePanel Maven / Gradle / Ivy

/*
 * Copyright (C) 2024 PekinSOFT Systems
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 *
 * *****************************************************************************
 *  Project    :   ErrorPaneInProcess
 *  Class      :   MessagePanel.java
 *  Author     :   Sean Carrick
 *  Created    :   Apr 14, 2024
 *  Modified   :   Apr 14, 2024
 *
 *  Purpose: See class JavaDoc for explanation
 *
 *  Revision History:
 *
 *  WHEN          BY                   REASON
 *  ------------  -------------------  -----------------------------------------
 *  Apr 14, 2024  Sean Carrick         Initial creation.
 * *****************************************************************************
 */
package com.pekinsoft.desktop.error;

import com.pekinsoft.desktop.error.ErrorPane;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.plaf.basic.BasicHTML;

/**
 *
 * @author Sean Carrick
 */
class MessagePanel extends javax.swing.JPanel 
        implements PropertyChangeListener {

    /**
     * Creates new form MessagePanel
     */
    public MessagePanel() {
        initComponents();
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName() != null) switch (evt.getPropertyName()) {
            case ErrorPane.PROP_ERROR_MESSAGE -> {
                String errorText = (String) evt.getNewValue();
                
                if (BasicHTML.isHTMLString(errorText)) {
                    errorMessage.setContentType("text/html");
                } else {
                    errorMessage.setContentType("text/plain");
                }
                
                errorMessage.setText(errorText);
                errorMessage.setCaretPosition(0);
            }
            case ErrorPane.PROP_ERROR_ICON -> {
                Icon errorIcon = (Icon) evt.getNewValue();
                iconLabel.setIcon(errorIcon);
            }
        }
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        iconPanel = new JPanel();
        iconLabel = new JLabel();
        errorMessageScrollPane = new JScrollPane();
        errorMessage = new JEditorPane();

        setMaximumSize(new Dimension(700, 275));
        setMinimumSize(new Dimension(250, 150));
        setPreferredSize(new Dimension(700, 200));
        setLayout(new BorderLayout());

        iconPanel.setMaximumSize(new Dimension(108, 32767));
        iconPanel.setMinimumSize(new Dimension(108, 0));
        iconPanel.setName("iconPanel"); // NOI18N

        iconLabel.setMaximumSize(new Dimension(96, 96));
        iconLabel.setMinimumSize(new Dimension(96, 96));
        iconLabel.setName("iconLabel"); // NOI18N
        iconLabel.setPreferredSize(new Dimension(96, 96));

        GroupLayout iconPanelLayout = new GroupLayout(iconPanel);
        iconPanel.setLayout(iconPanelLayout);
        iconPanelLayout.setHorizontalGroup(iconPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(iconPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        iconPanelLayout.setVerticalGroup(iconPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(iconPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(98, Short.MAX_VALUE))
        );

        add(iconPanel, BorderLayout.LINE_START);

        errorMessageScrollPane.setMaximumSize(new Dimension(32767, 275));
        errorMessageScrollPane.setMinimumSize(new Dimension(16, 200));
        errorMessageScrollPane.setName("errorMessageScrollPane"); // NOI18N
        errorMessageScrollPane.setPreferredSize(new Dimension(64, 200));

        errorMessage.setEditable(false);
        errorMessage.setContentType("text/html"); // NOI18N
        errorMessage.setName("errorMessage"); // NOI18N
        errorMessage.setOpaque(false);
        errorMessageScrollPane.setViewportView(errorMessage);

        add(errorMessageScrollPane, BorderLayout.CENTER);
    }// //GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JEditorPane errorMessage;
    private JScrollPane errorMessageScrollPane;
    private JLabel iconLabel;
    private JPanel iconPanel;
    // End of variables declaration//GEN-END:variables
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy