/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware.sparkimpl.plugin.phone;

import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.util.ResourceUtils;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

public class DialPanel extends JPanel {
    private JButton dialButton;
    private JTextField dialField;
    final JLabel iconLabel;
    final JPanel dialPanel = new JPanel();

    public DialPanel() {
        setLayout(new GridBagLayout());

        JPanel imagePanel = new JPanel();
        imagePanel.setLayout(new BorderLayout());


        imagePanel.setBackground(Color.white);

        iconLabel = new JLabel(SparkRes.getImageIcon(SparkRes.TELEPHONE_24x24));
        iconLabel.setHorizontalAlignment(JLabel.CENTER);
        iconLabel.setVerticalTextPosition(JLabel.BOTTOM);
        iconLabel.setHorizontalTextPosition(JLabel.CENTER);
        imagePanel.add(iconLabel, BorderLayout.CENTER);
        iconLabel.setFont(new Font("Verdana", Font.BOLD, 14));


        dialPanel.setLayout(new GridBagLayout());

        JLabel dialLabel = new JLabel("Number:");
        dialPanel.add(dialLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(5, 5, 5, 5), 0, 0));

        dialField = new JTextField();
        dialPanel.add(dialField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

        dialButton = new JButton("Dial");
        dialPanel.add(dialButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(5, 5, 5, 5), 0, 0));

        add(imagePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        add(dialPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

        iconLabel.setText("Waiting to place call");

        ResourceUtils.resButton(dialButton, "&Dial");
        ResourceUtils.resLabel(dialLabel, dialField, "&Number:");
    }

    public void changeToRinging() {
        remove(dialPanel);
        dialPanel.setVisible(false);
    }

    public void showDialog(String number) {
        iconLabel.setText("Calling " + number);
    }

    public void setText(String text) {
        iconLabel.setText(text);
    }

    public JButton getDialButton() {
        return dialButton;
    }

    public String getNumberToDial() {
        return dialField.getText();
    }

    public JTextField getDialField() {
        return dialField;
    }
}
