package jadx.gui.treemodel;

import jadx.api.JavaField;
import jadx.core.dex.info.AccessInfo;
import jadx.gui.utils.OverlayIcon;
import jadx.gui.utils.Utils;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class JField extends JNode {
	private static final long serialVersionUID = 1712572192106793359L;

	private static final ImageIcon ICON_FLD_DEF = Utils.openIcon("field_default_obj");
	private static final ImageIcon ICON_FLD_PRI = Utils.openIcon("field_private_obj");
	private static final ImageIcon ICON_FLD_PRO = Utils.openIcon("field_protected_obj");
	private static final ImageIcon ICON_FLD_PUB = Utils.openIcon("field_public_obj");

	private static final ImageIcon ICON_TRANSIENT = Utils.openIcon("transient_co");
	private static final ImageIcon ICON_VOLATILE = Utils.openIcon("volatile_co");

	private final JavaField field;
	private final JClass jParent;

	public JField(JavaField javaField, JClass jClass) {
		this.field = javaField;
		this.jParent = jClass;
	}

	@Override
	public JClass getJParent() {
		return jParent;
	}

	@Override
	public JClass getRootClass() {
		return jParent.getRootClass();
	}

	@Override
	public int getLine() {
		return field.getDecompiledLine();
	}

	@Override
	public Icon getIcon() {
		AccessInfo af = field.getAccessFlags();
		OverlayIcon icon = Utils.makeIcon(af, ICON_FLD_PUB, ICON_FLD_PRI, ICON_FLD_PRO, ICON_FLD_DEF);
		if (af.isTransient()) {
			icon.add(ICON_TRANSIENT);
		}
		if (af.isVolatile()) {
			icon.add(ICON_VOLATILE);
		}
		return icon;
	}

	@Override
	public String makeString() {
		return Utils.typeFormat(field.getName(), field.getType());
	}

	@Override
	public String makeLongString() {
		return Utils.typeFormat(field.getFullName(), field.getType());
	}
}
