Package simtools.ui

Source Code of simtools.ui.HeaderPanel

package simtools.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;



/**
* A Panel dedicated to display shape description or warnings/errors messages
* @author zxpletran007
*/
public class HeaderPanel extends JPanel implements MessageDisplayer {
   
    protected static MenuResourceBundle resources = ResourceFinder.getMenu(HeaderPanel.class);

   
    protected JLabel message;
    protected JLabel warningIcon;
    protected JLabel errorIcon;
    protected JLabel title;

   
    /**
     * @param largeHeight - If true  height is 80px, otherwise height is 35px.
     */
    public HeaderPanel(boolean largeHeight) {
        setLayout(new BorderLayout());
        JLabel headerIcon = new JLabel(largeHeight? resources.getIcon("largeHeaderIcon") : resources.getIcon("headerIcon"));
       
        warningIcon = new JLabel(resources.getIcon("headerWarning"));
        warningIcon.setOpaque(true);
        warningIcon.setBackground(Color.WHITE);
       
        errorIcon = new JLabel(resources.getIcon("headerError"));
        errorIcon.setOpaque(true);
        errorIcon.setBackground(Color.WHITE);     


        title = new JLabel();
        title.setFont(new Font("Dialog", Font.PLAIN,20));
        title.setOpaque(true);
        title.setBackground(Color.WHITE);

        message = new JLabel();
        message.setFont(new Font("Dialog", Font.PLAIN, 15));
        message.setOpaque(true);
        message.setBackground(Color.WHITE);

        JPanel p = new JPanel(new GridLayout(2,1));
        p.add(title);
        p.add(message);
       
        warningIcon.setVisible(false);
        add(warningIcon, BorderLayout.WEST);
        add(p, BorderLayout.CENTER);
        add(headerIcon, BorderLayout.EAST);
    }
   

    public HeaderPanel() {
        this(false);
    }

    public void setTitle(String titleText) {
        title.setText(titleText);
    }
   
    public void displayInfo(String infoMessage) {
        message.setText(infoMessage);
        warningIcon.setVisible(false);
        errorIcon.setVisible(false);
    }
   
    public void displayWarning(String warningMessage) {
        message.setText(warningMessage);
        warningIcon.setVisible(true);
        errorIcon.setVisible(false);
    }

    public void clearAllMessages() {
        message.setText("");
        errorIcon.setVisible(false);
        warningIcon.setVisible(false);
    }

    public void displayError(String errorText) {
        message.setText(errorText);
        errorIcon.setVisible(true);
        warningIcon.setVisible(false);
    }
}
TOP

Related Classes of simtools.ui.HeaderPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.