<commit_before>package net.java.sip.communicator.plugin.branding;

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.*;

import net.java.sip.communicator.service.browserlauncher.BrowserLauncherService;
import net.java.sip.communicator.service.gui.*;

import org.osgi.framework.ServiceReference;

public class AboutWindow extends JDialog implements HyperlinkListener,
        ActionListener, ExportedWindow
{
    private WindowBackground mainPanel = new WindowBackground();

    private JLabel titleLabel = new JLabel(
        BrandingResources.getString("productName"));

    private JLabel versionLabel = new JLabel(" "
            + System.getProperty("sip-communicator.version"));

    private JTextArea logoArea = new JTextArea(
            "Open Source VoIP & Instant Messaging");

    private StyledHTMLEditorPane rightsArea = new StyledHTMLEditorPane();

    private StyledHTMLEditorPane licenseArea = new StyledHTMLEditorPane();

    private JButton okButton = new JButton(Resources.getString("ok"));

    private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    private JPanel textPanel = new JPanel();

    public AboutWindow(Frame owner)
    {
        super(owner);

        this.setTitle(  Resources.getString("aboutWindowTitle",
                        new String[]{BrandingResources
                                        .getString("productName")}));

        this.setModal(false);

        this.mainPanel.setLayout(new BorderLayout());

        this.textPanel.setPreferredSize(new Dimension(470, 280));
        this.textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
        this.textPanel.setBorder(BorderFactory
                .createEmptyBorder(15, 15, 15, 15));
        this.textPanel.setOpaque(false);

        this.titleLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 28));
        this.titleLabel.setForeground(Constants.DARK_BLUE);
        this.titleLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);

        this.versionLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 18));
        this.versionLabel.setForeground(Color.GRAY);
        this.versionLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);

        this.logoArea.setFont(Constants.FONT.deriveFont(Font.BOLD, 14));
        this.logoArea.setForeground(Constants.DARK_BLUE);
        this.logoArea.setOpaque(false);
        this.logoArea.setLineWrap(true);
        this.logoArea.setWrapStyleWord(true);
        this.logoArea.setEditable(false);
        this.logoArea.setPreferredSize(new Dimension(100, 20));
        this.logoArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
        this.logoArea.setBorder(BorderFactory.createEmptyBorder(30, 180, 0, 0));

        this.rightsArea.setContentType("text/html");

        this.rightsArea.appendToEnd(Resources.getString("copyright"));

        this.rightsArea.setPreferredSize(new Dimension(50, 20));
        this.rightsArea
                .setBorder(BorderFactory.createEmptyBorder(0, 180, 0, 0));
        this.rightsArea.setOpaque(false);
        this.rightsArea.setEditable(false);
        this.rightsArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
        this.rightsArea.addHyperlinkListener(this);

        this.licenseArea.setContentType("text/html");
        this.licenseArea.appendToEnd(Resources.getString("license"));

        this.licenseArea.setPreferredSize(new Dimension(50, 20));
        this.licenseArea.setBorder(BorderFactory.createEmptyBorder(10, 180, 0,
                0));
        this.licenseArea.setOpaque(false);
        this.licenseArea.setEditable(false);
        this.licenseArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
        this.licenseArea.addHyperlinkListener(this);

        this.textPanel.add(titleLabel);
        this.textPanel.add(versionLabel);
        this.textPanel.add(logoArea);
        this.textPanel.add(rightsArea);
        this.textPanel.add(licenseArea);

        this.getRootPane().setDefaultButton(okButton);

        this.okButton.setMnemonic(Resources.getString("ok").charAt(0));

        this.okButton.addActionListener(this);

        this.buttonPanel.add(okButton);
        this.buttonPanel.setOpaque(false);

        this.mainPanel.add(textPanel, BorderLayout.CENTER);
        this.mainPanel.add(buttonPanel, BorderLayout.SOUTH);

        this.getContentPane().add(mainPanel);
        this.setSize(mainPanel.getPreferredSize());

        this.setResizable(false);
        this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width / 2
                - getWidth() / 2,
                Toolkit.getDefaultToolkit().getScreenSize().height / 2
                        - getHeight() / 2);

    }

    protected void close(boolean isEscaped)
    {
        this.dispose();
    }

    /**
     * Constructs the window background in order to have a background image.
     */
    private class WindowBackground extends JPanel
    {
        private Image bgImage = null;

        public WindowBackground()
        {
            try
            {
                bgImage = ImageIO.read(WindowBackground.class
                        .getResource(
                            BrandingResources.getString("aboutWindowBg")));
            }
            catch (IOException e)
            {
                bgImage = null;
            }
            this.setPreferredSize(new Dimension(bgImage.getWidth(this),
                                                bgImage.getHeight(this)));
        }

        protected void paintComponent(Graphics g)
        {
            super.paintComponent(g);

            activateAntialiasing(g);

            Graphics2D g2 = (Graphics2D) g;

            g2.drawImage(bgImage, 0, 0, null);

            g2.setColor(new Color(255, 255, 255, 100));

            g2.fillRect(0, 0, getWidth(), getHeight());
        }
    }

    public void hyperlinkUpdate(HyperlinkEvent e)
    {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
        {
            String href = e.getDescription();
            ServiceReference serviceReference = BrandingActivator
                    .getBundleContext().getServiceReference(
                            BrowserLauncherService.class.getName());
<commit_msg>Fix obtaining background image for about window.<commit_after>package net.java.sip.communicator.plugin.branding;

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.*;

import net.java.sip.communicator.util.*;
import net.java.sip.communicator.service.browserlauncher.*;
import net.java.sip.communicator.service.gui.*;

import org.osgi.framework.ServiceReference;

public class AboutWindow extends JDialog implements HyperlinkListener,
        ActionListener, ExportedWindow
{
    private Logger logger = Logger.getLogger(AboutWindow.class.getName());
    
    private WindowBackground mainPanel = new WindowBackground();

    private JLabel titleLabel = new JLabel(
        BrandingResources.getString("productName"));

    private JLabel versionLabel = new JLabel(" "
            + System.getProperty("sip-communicator.version"));

    private JTextArea logoArea = new JTextArea(
            "Open Source VoIP & Instant Messaging");

    private StyledHTMLEditorPane rightsArea = new StyledHTMLEditorPane();

    private StyledHTMLEditorPane licenseArea = new StyledHTMLEditorPane();

    private JButton okButton = new JButton(Resources.getString("ok"));

    private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    private JPanel textPanel = new JPanel();

    public AboutWindow(Frame owner)
    {
        super(owner);

        this.setTitle(  Resources.getString("aboutWindowTitle",
                        new String[]{BrandingResources
                                        .getString("productName")}));

        this.setModal(false);

        this.mainPanel.setLayout(new BorderLayout());

        this.textPanel.setPreferredSize(new Dimension(470, 280));
        this.textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
        this.textPanel.setBorder(BorderFactory
                .createEmptyBorder(15, 15, 15, 15));
        this.textPanel.setOpaque(false);

        this.titleLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 28));
        this.titleLabel.setForeground(Constants.DARK_BLUE);
        this.titleLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);

        this.versionLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 18));
        this.versionLabel.setForeground(Color.GRAY);
        this.versionLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);

        this.logoArea.setFont(Constants.FONT.deriveFont(Font.BOLD, 14));
        this.logoArea.setForeground(Constants.DARK_BLUE);
        this.logoArea.setOpaque(false);
        this.logoArea.setLineWrap(true);
        this.logoArea.setWrapStyleWord(true);
        this.logoArea.setEditable(false);
        this.logoArea.setPreferredSize(new Dimension(100, 20));
        this.logoArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
        this.logoArea.setBorder(BorderFactory.createEmptyBorder(30, 180, 0, 0));

        this.rightsArea.setContentType("text/html");

        this.rightsArea.appendToEnd(Resources.getString("copyright"));

        this.rightsArea.setPreferredSize(new Dimension(50, 20));
        this.rightsArea
                .setBorder(BorderFactory.createEmptyBorder(0, 180, 0, 0));
        this.rightsArea.setOpaque(false);
        this.rightsArea.setEditable(false);
        this.rightsArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
        this.rightsArea.addHyperlinkListener(this);

        this.licenseArea.setContentType("text/html");
        this.licenseArea.appendToEnd(Resources.getString("license"));

        this.licenseArea.setPreferredSize(new Dimension(50, 20));
        this.licenseArea.setBorder(BorderFactory.createEmptyBorder(10, 180, 0,
                0));
        this.licenseArea.setOpaque(false);
        this.licenseArea.setEditable(false);
        this.licenseArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
        this.licenseArea.addHyperlinkListener(this);

        this.textPanel.add(titleLabel);
        this.textPanel.add(versionLabel);
        this.textPanel.add(logoArea);
        this.textPanel.add(rightsArea);
        this.textPanel.add(licenseArea);

        this.getRootPane().setDefaultButton(okButton);

        this.okButton.setMnemonic(Resources.getString("ok").charAt(0));

        this.okButton.addActionListener(this);

        this.buttonPanel.add(okButton);
        this.buttonPanel.setOpaque(false);

        this.mainPanel.add(textPanel, BorderLayout.CENTER);
        this.mainPanel.add(buttonPanel, BorderLayout.SOUTH);

        this.getContentPane().add(mainPanel);
        this.setSize(mainPanel.getPreferredSize());

        this.setResizable(false);
        this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width / 2
                - getWidth() / 2,
                Toolkit.getDefaultToolkit().getScreenSize().height / 2
                        - getHeight() / 2);

    }

    protected void close(boolean isEscaped)
    {
        this.dispose();
    }

    /**
     * Constructs the window background in order to have a background image.
     */
    private class WindowBackground extends JPanel
    {
        private Image bgImage = null;

        public WindowBackground()
        {
            try
            {
                bgImage = ImageIO.read(WindowBackground.class.getClassLoader()
                        .getResource(
                            BrandingResources.getString("aboutWindowBg")));
            }
            catch (IOException e)
            {
                logger.error("Error cannot obtain background image", e);
                bgImage = null;
            }
            this.setPreferredSize(new Dimension(bgImage.getWidth(this),
                                                bgImage.getHeight(this)));
        }

        protected void paintComponent(Graphics g)
        {
            super.paintComponent(g);

            activateAntialiasing(g);

            Graphics2D g2 = (Graphics2D) g;

            g2.drawImage(bgImage, 0, 0, null);

            g2.setColor(new Color(255, 255, 255, 100));

            g2.fillRect(0, 0, getWidth(), getHeight());
        }
    }

    public void hyperlinkUpdate(HyperlinkEvent e)
    {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
        {
            String href = e.getDescription();
            ServiceReference serviceReference = BrandingActivator
                    .getBundleContext().getServiceReference(
                            BrowserLauncherService.class.getName());

{'fraction_non_alphanumeric': 0.10616411464468002, 'fraction_numerical': 0.012563800549666274, 'mean_word_length': 2.5957086391869, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2141950', 'n_tokens_mistral': 3720, 'n_tokens_neox': 3452, 'n_words': 537}