package gve.calc.formula;

public class StringPart extends Part {
	private String string;
	
	public StringPart() { string = ""; }
	
	public StringPart(String str) { string = str; }
	
	public Object clone() {
		return new StringPart(string);
	}
	
	public void setString(String str) {
		string = str;
		MVC.changed(this);
	}
	
	public String getString() { return string; }
	
	public Part evaluate(Evaluator ev) {
		return new StringPart(string);
	}
	
	public String toString() {
		return "StringPart[\""+string+"\"]";
	}

	public void write(java.io.Writer w) throws java.io.IOException {
		super.write(w);
		w.write(string);
		w.write('\n');
	}

	public static Part read(java.io.BufferedReader r) throws java.io.IOException,
			ClassNotFoundException,NoSuchMethodException,
			java.lang.reflect.InvocationTargetException,IllegalAccessException {
		String line = r.readLine();
		return new StringPart(line);
	}

	public boolean same(Object o) {
		o = Brackets.unbracket(o);
		return o instanceof StringPart && ((StringPart)o).string.equals(string);
	}
	
	public java.awt.Component createView(FormulaView f) {
		return new StringPartView(this);
	}

	public void saveLatex(java.io.BufferedWriter w) throws java.io.IOException {
		w.write("\\mbox{\\bf``");
		w.write(string);
		w.write("''}");
	}
}