/*
 * Copyright (C) 1999-2006 <a href="mailto:adrian.paschke@gmx.de">Adrian Paschke</a>
 * 
 * The RBSLM Environment is part of the Rule Based Service Level Agreement (RBSLA)
 * framework, available at 
 * <a href=" http://ibis.in.tum.de/staff/paschke/rbsla/index.htm">RBSLA</a>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package rbsla.environment.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Hashtable;

import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListModel;

import rbsla.environment.ECAConstraints;

public class ActiveRulesViewer implements Viewer 
{
	JPanel rulePanel = new JPanel(new BorderLayout());
	JList ruleList = new JList();
	JScrollPane rulePane = new JScrollPane(ruleList);
	
	public JComponent getContentPane(Hashtable viewProperties)
    {
		rulePane.setPreferredSize(new Dimension(400,200));
		ruleList.setEnabled(false);
		rulePanel.add(rulePane, BorderLayout.CENTER);
		return rulePanel;
    }

    public void dataChanged(String result, String debugText) throws Throwable
    {
    	ruleList.removeAll();
    	String[] rules = result.split("\n");
    	String[] listData = new String[rules.length];
    	for(int i=0; i<rules.length;i++)
    	{
    		String ruleTmp = rules[i];
    		ruleTmp ="<html><font "+ ECAConstraints._ACITVE_RULE + ">"+ruleTmp+"</font></html>";
    		listData[i] = ruleTmp;
    	}
    	ruleList.setListData(listData);
    	
    	 	
    	ListModel model = ruleList.getModel();
    	String test = (String)model.getElementAt(1);
    	test = test.replaceAll(ECAConstraints._ACITVE_RULE, ECAConstraints._FIRED_RULE);
    	listData[1] = test;    	
    }
	
	
	public Hashtable getViewerPropertieNames()
    {
        return null;
    }

}
