Package net.sf.myjaut.ui

Source Code of net.sf.myjaut.ui.JMessagePanel

/*
* Created on 12-mrt-2006.
*
* This software is published under the "GNU General Public
* license", see http://www.gnu.org/copyleft/gpl.html for
* additional information.
*
*/
package net.sf.myjaut.ui;

import java.awt.BorderLayout;
import java.awt.Image;
import java.io.IOException;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import net.sf.myjaut.URLProvider;
import net.sf.myjaut.i18n.I18nListener;
import net.sf.myjaut.i18n.I18nManager;

public class JMessagePanel extends JPanel implements I18nListener {
  public JMessagePanel(I18nManager i18n, String imagePath) {
        this.imagePath = imagePath;
        setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
        panel.setLayout(new BorderLayout());
        panel.add(imageLabel, BorderLayout.WEST);
        imageLabel.setVerticalAlignment(JLabel.VERTICAL);
        imageLabel.setBorder(new EmptyBorder(5, 0, 0, 0));
        message.setLineWrap(true);
        message.setWrapStyleWord(true);
        JScrollPane sp = new JScrollPane(message, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        sp.setBorder(new EmptyBorder(5, 5, 0, 0));
        panel.add(sp, BorderLayout.CENTER);
        add(panel);
        this.i18n = i18n;
        i18n.addI18nListener(this);
        message.setBackground(new JLabel().getBackground());
        message.setForeground(new JLabel().getForeground());
        message.setEditable(false);
    }

    public void setMessage(String key) {
        this.key = key;
        // TODO fix label vs. message size
        try {
            Image image = new URLProvider(imagePath).getImage();
            imageLabel.setIcon(i18n.getValue(key) != null
                    ? new ImageIcon(image)
                    : null);
        }
        catch (IOException exc) {
            // This shouldn't happen: image should be included in JAR-file distribution.
            throw new IllegalStateException(exc);
        }
        message.setText(i18n.getValue(key));
    }
   
    public void signalI18nChange(I18nManager i18n) {
        setMessage(key);
    }

    private JTextArea message = new JTextArea();
    private JLabel imageLabel = new JLabel();
    private I18nManager i18n;
    private String key;
    private String imagePath;
}
TOP

Related Classes of net.sf.myjaut.ui.JMessagePanel

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.