package j3deditor.bin.editor;

import java.awt.Font;

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


/**
 * Shows information about active tool/button.
 *
 * @author Risto Seene
 */
public class InfoPanel extends JPanel{


	/** label for info */
	private JLabel info;

	/** label for info */
	private JLabel subInfo;


	/**
	 * Creates an instance of <code>InfoPanel</code>
	 * with the given width and height.
	 *
	 * @param width
	 *	width of this panel
	 * @param height
	 *	height of this panel
	 */
	public InfoPanel(int width, int height){
		setOpaque(false);
		setLayout(null);
		info = new JLabel("", 0);
		info.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14));
		info.setBounds(1, 1, width - 2, 15);
		add(info);

		subInfo = new JLabel("", 0);
		subInfo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
		subInfo.setBounds(1, 16, width - 2, 15);
		add(subInfo);
	}


	/**
	 * Updates the information shown on the labels of this panel.
	 * If input text contains <code>|</code> the text is devided
	 * to two parts - for both labels
	 *
	 * @param info
	 *	input text
	 */
	public void setInfo(String info){
		String subInfo = null;
		if(info.contains("|")){
			subInfo = info.substring(info.lastIndexOf("|") + 1);
			info = info.substring(0, info.indexOf("|"));
		}

		setInfo(info, subInfo);
	}


	/**
	 * Updates the information shown on the labels of this panel.
	 *
	 * @param info
	 *	input text for first label
	 * @param subInfo
	 *	input text for second label
	 */
	public void setInfo(String info, String subInfo){
		if(info == null){
			info = new String();
		}
		if(subInfo == null){
			subInfo = new String();
		}

		this.info.setText(info);
		this.subInfo.setText("<html><body><center>" + subInfo + "</center></body></html>");
	}

}
