package warzone;

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;

//position set by WCanvas
public class WBoardNode extends JComponent {
	public static final int NOTHING = 0;
	public static final int VALID = 1;
	public static final int INVALID = 2;
	
	private WViewer viewer;
	private int row;
	private int col;
	private boolean mouseOverMe;
	private int highLightType;
	
	public WBoardNode(WViewer viewer1, int row1, int col1) {
		viewer = viewer1;
		row = row1;
		col = col1;
		mouseOverMe = false;
		highLightType = NOTHING;
		
		this.addMouseListener(new MouseAdapter() {
			public void mouseEntered(MouseEvent e) {
				doMouseEntered();
				
				if(viewer.getMode()==WViewer.UNIT_MODE) {
					WGameBoard gb = viewer.getGameBoard();
					if(gb.UnitAtSpace(row,col)==null&&gb.TerrainAtSpace(row,col)==null) viewer.SpaceClicked(row, col,0);
				}
			}
			
			public void mouseExited(MouseEvent e) {
				mouseOverMe = false;
				repaint();
			}
			
			public void mousePressed(MouseEvent e) {
				int b;
				
				if(e.getButton()==MouseEvent.BUTTON1) b = 1;
				else
					b = 2;
				viewer.SpaceClicked(row, col,b);
			}
			
			
		
		});
		
	}
	
	public void doMouseEntered() {
		mouseOverMe = true;
		WGameBoard gameBoard = viewer.getGameBoard();
		viewer.setInspector(gameBoard.UnitAtSpace(row,col));
		repaint();
	}
	
	public int getHighLight() {return highLightType; }
	
	public void changeHighlight(int newType) {
		highLightType = newType;
		repaint();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		int size = this.getHeight();
		g.setColor(Color.black);
		if(mouseOverMe) g.drawRect(0,0,size-1,size-1);
		if(highLightType!=NOTHING) {
			if(highLightType==VALID) g.setColor(Color.green);
			if(highLightType==INVALID) g.setColor(Color.gray);
			g.drawRect(1,1,size-3,size-3);
			g.drawRect(2,2,size-5,size-5);
		}
	}
}

@@ -1061,22 +1061,16 @@
 int b;%0D%0A
-%09%09%09%09%0D%0A
 %09%09%09%09if(e
@@ -1081,17 +1081,17 @@
 Button()
-=
+!
 =MouseEv
@@ -1105,39 +1105,233 @@
 TON1
-) b = 1;%0D%0A%09%09%09%09else%0D%0A%09%09%09%09%09b = 2;
+ %7C%7C e.isControlDown()) %7B%0D%0A                                    b = 2;                                    %0D%0A                                %7D else %7B%0D%0A                                    b = 1;%0D%0A                                %7D
 %0D%0A%09%09

make ctrl-clicking work on macs