package org.csstudio.utility.adlparser.fileParser.widgets;

import org.csstudio.utility.adlparser.fileParser.ADLWidget;
import org.csstudio.utility.adlparser.fileParser.FileLine;
import org.csstudio.utility.adlparser.fileParser.WrongADLFormatException;
import org.csstudio.utility.adlparser.fileParser.widgetParts.ADLMonitor;
import org.csstudio.utility.adlparser.fileParser.widgetParts.ADLObject;
import org.csstudio.utility.adlparser.internationalization.Messages;

public class Meter extends ADLAbstractWidget {
	private String color_mode = new String("static");
	private String label = new String("none");

	public Meter(ADLWidget adlWidget) {
		super(adlWidget);
		try {
			for (ADLWidget childWidget : adlWidget.getObjects()) {
	        	if (childWidget.getType().equals("object")){
	        		_adlObject = new ADLObject(childWidget);
	        		if (_adlObject != null){
	        			_hasObject = true;
	        		}
	        		
	        	}
	        	else if (childWidget.getType().equals("monitor")){
	        		_adlMonitor = new ADLMonitor(childWidget);
	        		if (_adlMonitor != null){
	        			_hasMonitor = true;
	        		}
	        	}
	        }
			for (FileLine fileLine : adlWidget.getBody()){
				String bodyPart = fileLine.getLine();
				String[] row = bodyPart.trim().split("=");
				if (row.length < 2){
					throw new WrongADLFormatException(Messages.Label_WrongADLFormatException_Parameter_Begin + bodyPart + Messages.Label_WrongADLFormatException_Parameter_End);
				}
				if (FileLine.argEquals(row[0], "clrmod")){
					setColor_mode(FileLine.getTrimmedValue(row[1]));
				}
				if (FileLine.argEquals(row[0], "label")){
					setLabel(FileLine.getTrimmedValue(row[1]));
				}
			}
		}
		catch (WrongADLFormatException ex) {
			
		}
		//TODO Add PV Limits to Meter
	}

	/**
	 * @param color_mode the color_mode to set
	 */
	private void setColor_mode(String color_mode) {
		this.color_mode = color_mode;
	}

	/**
	 * @return the color_mode
	 */
	public String getColor_mode() {
		return color_mode;
	}

	/**
	 * @param label the label to set
	 */
	private void setLabel(String label) {
		this.label = label;
	}

	/**
	 * @return the label
	 */
	public String getLabel() {
		return label;
	}
}

@@ -246,16 +246,88 @@
 eption;%0A
+import org.csstudio.utility.adlparser.fileParser.widgetParts.ADLLimits;%0A
 import o
@@ -391,16 +391,16 @@
 onitor;%0A
-
 import o
@@ -1211,32 +1211,236 @@
 %09%09%7D%0A%09        %09%7D%0A
+%09        %09else if (childWidget.getType().equals(%22limits%22))%7B%0A%09        %09%09_adlLimits = new ADLLimits(childWidget);%0A%09        %09%09if (_adlLimits != null)%7B%0A%09        %09%09%09_hasLimits = true;%0A%09        %09%09%7D%0A%09        %09%7D%0A
 %09        %7D%0A%09%09%09fo
@@ -2030,44 +2030,12 @@
 %09%09%09%0A
+
 %09%09%7D%0A
-%09%09//TODO Add PV Limits to Meter%0A
 %09%7D%0A%0A

Add limits to clear TODO list