/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in 
 * compliance with the License.  You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is Protege-2000.
 *
 * The Initial Developer of the Original Code is Stanford University. Portions
 * created by Stanford University are Copyright (C) 2007.  All Rights Reserved.
 *
 * Protege was developed by Stanford Medical Informatics
 * (http://www.smi.stanford.edu) at the Stanford University School of Medicine
 * with support from the National Library of Medicine, the National Science
 * Foundation, and the Defense Advanced Research Projects Agency.  Current
 * information about Protege can be obtained at http://protege.stanford.edu.
 *
 */

package edu.stanford.smi.protege.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import edu.stanford.smi.protege.model.Cls;
import edu.stanford.smi.protege.model.Frame;
import edu.stanford.smi.protege.model.KnowledgeBase;
import edu.stanford.smi.protege.model.Localizable;

public class FrameWithBrowserText implements Serializable, Localizable {
	private static final long serialVersionUID = -8597023478383674378L;

	private Frame frame;
	private String browserText;
	private Collection<Cls> types;


	public FrameWithBrowserText(Frame frame) {
		this(frame, null, null);
	}

	public FrameWithBrowserText(Frame frame, String browserText,
			Collection<Cls> types) {
		this.frame = frame;
		this.browserText = browserText == null ? frame.getName() : browserText;
		this.types = types == null ? new ArrayList<Cls>() : types;
	}

	public Frame getFrame() {
		return frame;
	}
	public void setFrame(Frame frame) {
		this.frame = frame;
	}
	public String getBrowserText() {
		return browserText;
	}
	public void setBrowserText(String browserText) {
		this.browserText = browserText;
	}
	public Collection<Cls> getTypes() {
		return types;
	}
	public void setTypes(Collection<Cls> types) {
		this.types = types;
	}

	public void localize(KnowledgeBase kb) {
		LocalizeUtils.localize(frame, kb);
		LocalizeUtils.localize(types, kb);
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof FrameWithBrowserText)) { return false;}
		FrameWithBrowserText fbt = (FrameWithBrowserText)obj;		
		return fbt.getFrame() == null ? false : fbt.getFrame().equals(frame);
	}

	@Override
	public int hashCode() {
		return
			frame == null ? 42 :
				frame.getName().length() * 43 + 7 * browserText.length() + 5 * types.size() + 3;
	}

}
