/*
 * @(#)RedBlackTreeJPanel.java

 *
 * Last Modified: 9/15/01
 */

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import java.beans.*;

/** * This class provides the panel for a <code>RedBlackTree</code>. It keeps the graphics for drawing
	* the tree and the image for redrawing. It also keeps a timer for the animation and all changes
	* to the tree proceed through the panel.
	*
	*
 	* @author  Corey Sanders
	* @version 1.1 9/15/01
 	*/
public class RedBlackTreeJPanel extends BSTTreeJPanel {

	/**
	 * Sole Constructor. It simply calls the super constructor and then calls
	 * <code>setTree</code> with the ANIMATING_BST_TREE_TYPE.
	 */
    public RedBlackTreeJPanel() {
		super();
		setTree(new RedBlackTreeHead(BSTTree.ANIMATING_BST_TREE_TYPE));
    }

	/**
	 * Draws the current drawing node using the specific stoke and paint for the red links.
	 */
	public void drawDrawingNode() {
		super.drawDrawingNode();

		NodeAndLinkDrawingJPanel drawingPanel = colorOptionsPanel.getDrawingPanel();

		drawingPanel.setBackground(PaintSettings.getColor(backgroundColor));

		if (((String)functionJComboBox.getSelectedItem()).equals(DRAWING)) {
			drawingPanel.getNode().setSettings(NodeSettings.getScheme(drawingNodeSettings));
			((DrawableKey)drawingPanel.getNode().getValue()).setSettings(KeySettings.getScheme(drawingKeySettings));
		}

		drawingPanel.getNode().getSettings().setRightLinkStroke((BasicStroke)((RedBlackTreeHead)getTree()).getRedLinkStroke());
		drawingPanel.getNode().getSettings().setRightLinkPaint(((RedBlackTreeHead)getTree()).getRedLinkPaint().getPaint());

		drawingPanel.setDrawTree(true);
		drawingPanel.repaint();
	}

	/**
	 * Constructs a popupmenu, using the actionlistener passed. The popupMenu
	 * contains all of the options available through the current tree. For this
	 * class, no items are added, making it necessary to overide the method.
	 *
	 * @param actionListener the listener add to the actions of all the items made in the menu.
	 *
	 * @return JPopupMenu which is the menu constructed within the panel.
	 */
	public JPopupMenu makeJPopupMenu(ActionListener actionlistener) {
		JPopupMenu popupMenu = new JPopupMenu();

      /*  JMenuItem deleteItem = new JMenuItem("Delete Node");
        deleteItem.setBackground(Color.black);
		deleteItem.setForeground(Color.white);
		deleteItem.addActionListener(actionlistener);
        deleteItem.setActionCommand(OptionEvent.DELETE_CLICK);*/
        JMenuItem selectItem = new JMenuItem("Select");
		selectItem.addActionListener(actionlistener);
        selectItem.setActionCommand(OptionEvent.SELECT_CLICK);

        //popupMenu.add(deleteItem);
        popupMenu.add(selectItem);

        return popupMenu;
	}


 	/**
 	 * Constructs an error type if the tree is attempted to balance.
 	 */
 	 protected void makeBalanceErrorMessage() {
		 String errorMsg = new String("Red-Black trees are\nalready balanced.");

 		 messageAction(TreeMessageEvent.ERROR_MESSAGE, errorMsg.toString());

 	 }

 	/**
 	 * Constructs an error type if a node is attempted to delete.
 	 */
 	 protected void makeDeleteErrorMessage() {
		 String errorMsg = new String("Red-Black tree do deletion\nnot yet supported.");

 		 messageAction(TreeMessageEvent.ERROR_MESSAGE, errorMsg.toString());

 	 }

	/**
	 * RotateUp command. No action.
	 *
	 * @param node Tree to rotateUp.
	 */
	public void rotateUpCommand(Tree node) {

	}

	/**
	 * RotateToTop command. No action.
	 *
	 * @param node Tree to rotateToTop.
	 */
	public void rotateToTopCommand(Tree node) {

	}

	/**
	 * RotateUpDouble command. No action.
	 *
	 * @param node Tree to rotateUpDouble.
	 */
	public void rotateUpDoubleCommand(Tree node) {

	}

	/**
	 * Splay command. No action.
	 *
	 * @param node Tree to splay.
	 */
	public void splayCommand(Tree node) {

	}

	/**
	 * Balance command. No action.
	 *
	 * @param node Tree to balance.
	 */
	public void balanceCommand(Tree node) {
		makeBalanceErrorMessage();
	}

	/**
	 * Delete command. No action.
	 *
	 * @param node Tree to delete.
	 */
	public void deleteCommand(String text) {
		makeDeleteErrorMessage();
	}

	/**
	 * Change Display Command. No action....yet!
	 */
	public void displayChangeCommand() {

	}
}

