/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2012 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.jaamsim.ui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;

import com.sandwell.JavaSimulation.CompatInput;
import com.sandwell.JavaSimulation.Input;

public class EditBoxColumnRenderer extends DefaultTableCellRenderer {

private final Border border;
private final Border focusBorder;
private final Color compatKeyword;

public EditBoxColumnRenderer() {
	border = BorderFactory.createEmptyBorder(0, 10, 0, 0);

	// single pixel outline for the focused cell, require an inset with one fewer
	// pixel due to the outline
	Border lineBorder = BorderFactory.createLineBorder(Color.BLUE);
	Border insetBorder = BorderFactory.createEmptyBorder(0, 9, 0, 0);
	focusBorder = BorderFactory.createCompoundBorder(lineBorder, insetBorder);

	compatKeyword = new Color(255, 0, 0);
}

@Override
public Component getTableCellRendererComponent(JTable table, Object value,
                                               boolean isSelected, boolean hasFocus,
                                               int row, int column) {

	Input<?> in = (Input<?>)value;

	String str;
	if (column == 0)
		str = in.getKeyword();
	else if (column == 1){
		str = in.getDefaultString();
	}
	else {
		str = in.getValueString();
	}

	// Pass along the keyword string, not the input itself
	Component cell = super.getTableCellRendererComponent(table, str, isSelected, hasFocus, row, column);

	if (row == table.getSelectedRow())
		cell.setBackground(FrameBox.TABLE_SELECT);
	else
		cell.setBackground(null);

	if (value instanceof CompatInput && column == 0)
		cell.setForeground(compatKeyword);
	else
		cell.setForeground(null);

	if (hasFocus)
		this.setBorder(focusBorder);
	else
		this.setBorder(border);
	return cell;
}
}

@@ -822,56 +822,8 @@
 r;%0A%0A
-import com.sandwell.JavaSimulation.CompatInput;%0A
 impo
@@ -860,16 +860,16 @@
 .Input;%0A
+
 %0Apublic 
@@ -998,43 +998,8 @@
 der;
-%0Aprivate final Color compatKeyword;
 %0A%0Apu
@@ -1405,48 +1405,8 @@
 er);
-%0A%0A%09compatKeyword = new Color(255, 0, 0);
 %0A%7D%0A%0A
@@ -2072,32 +2072,32 @@
 _SELECT);%0A%09else%0A
+
 %09%09cell.setBackgr
@@ -2113,130 +2113,8 @@
 );%0A%0A
-%09if (value instanceof CompatInput && column == 0)%0A%09%09cell.setForeground(compatKeyword);%0A%09else%0A%09%09cell.setForeground(null);%0A%0A
 %09if 

stop coloring Compat keywords in red