⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabcontenttag.java

📁 struts+spring+hibernate自创框架
💻 JAVA
字号:
package com.pegasus.framework.component.taglib.html.tabs;

import javax.servlet.jsp.JspException;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.Globals;

import com.pegasus.framework.component.taglib.util.BaseBodySupportTag;
import com.pegasus.framework.component.taglib.util.JspResponseWriter;
import com.pegasus.framework.component.taglib.xml.Xhtml;

/**
 * CHIIC SYSTEMS, INC.
 * Author: RoyZ
 * Date: 2007-7-23
 * Time: 14:04:57
 */
public class TabContentTag extends BaseBodySupportTag {

	private String tabTitle;
	private TabsContainerTag tabContainer;
	private JspResponseWriter out = new JspResponseWriter();
	private String bundle = Globals.MESSAGES_KEY;
	private String key = null;
	private String imgSrc = null;
	private String imgPosition = null;

	public TabContentTag(TabContentTag tag) throws Exception {
		BeanUtils.copyProperties(this, tag);
		this.out = new JspResponseWriter();
	}

	public TabContentTag() {
	}

	public void setId(final String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setTabTitle(final String tabTitle) {
		this.tabTitle = tabTitle;
	}

	public String getTabTitle() {
		return tabTitle;
	}

	public String getBundle() {
		return bundle;
	}

	public void setBundle(String bundle) {
		this.bundle = bundle;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getImgSrc() {
		return imgSrc;
	}

	public void setImgSrc(String imgSrc) {
		this.imgSrc = imgSrc;
	}

	public String getImgPosition() {
		return imgPosition;
	}

	public void setImgPosition(String imgPosition) {
		this.imgPosition = imgPosition;
	}

	/*public int doStartTag() throws JspException {


		return (EVAL_PAGE);
	}*/


	public int doEndTag() throws JspException {
//		System.out.println("start child " +  this.getId() + "doEndTag");
//		addToContainer();
		addToContainerString();
		renderComponent();
//		System.out.println("out: " +out.getBuffer());
		out = new JspResponseWriter();
//		System.out.println("end child" +  this.getId() + "doEndTag");
		return EVAL_BODY_INCLUDE;
	}

//	public void doTag() throws JspException, IOException {
//
//		renderComponent();
//	}

	public TabsContainerTag getTabsContainer() {
		if (null == tabContainer) {
			tabContainer = (TabsContainerTag)
					findAncestorWithClass(this, TabsContainerTag.class);
		}
		return tabContainer;
	}

	private void addToContainer() {
//		System.out.println("addToContainer: " + getTabsContainer() + "this : " + this.getTabTitle());

		try {
			getTabsContainer().addChild(this);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
//		System.out.println("addToContainer size: " + getTabsContainer().getChildCount());
	}

	private void addToContainerString() {
//		System.out.println("addToContainer: " + getTabsContainer() + "this : " + this.getTabTitle());


		getTabsContainer().setChildIndex(getTabsContainer().getChildIndex() + 1);
		if (this.getId().equals(getTabsContainer().getSelectedTabPaneId())) {
			getTabsContainer().setSelectedIndex(getTabsContainer().getChildIndex() + 1);
		}
		StringBuffer sb = getTabsContainer().getChildTab();

		JspResponseWriter outTmp = new JspResponseWriter();
//			TabContentTag tabPane = (TabContentTag) iter.next();
		outTmp.startElement(Xhtml.Html.DIV);
		outTmp.attribute(Xhtml.Attr.ID, this.getId() + TabsContainerTag.TAB_ID_SUFFIX);
		outTmp.attribute(Xhtml.Attr.NAME, TabsContainerTag.TAB_LABLE_NAME);
//			outTmp.attribute(Xhtml.Attr.ID, tabPane.getId());
//			if (null != getJsTabListener() && getJsTabListener().length() > 0) {
//				outTmp.attribute(Xhtml.Attr.ONCLICK,
//							  "org.ditchnet.jsp.TabUtils.tabClicked(event);" +
//				getJsTabListener().trim() + "(new org.ditchnet.jsp.TabEvent(this));");
//			} else {
//				outTmp.attribute(Xhtml.Attr.ONCLICK,
//							  "org.ditchnet.jsp.TabUtils.tabClicked(event);");
//			}
		if (null != getTabsContainer().getJsTabListener() && getTabsContainer().getJsTabListener().length() > 0) {
			outTmp.attribute(Xhtml.Attr.ONCLICK,
					"tabShow('" + this.getId() + "','" + getTabsContainer().TABS_NAME + "','" + this
							.getId() + TabsContainerTag.TAB_ID_SUFFIX + "','" + TabsContainerTag.TAB_LABLE_NAME + "');" +
							getTabsContainer().getJsTabListener().trim() + "();");
		}
		else {
			outTmp.attribute(Xhtml.Attr.ONCLICK,
					"tabShow('" + this.getId() + "','" + getTabsContainer().TABS_NAME + "','" + this
							.getId() + TabsContainerTag.TAB_ID_SUFFIX + "','" + TabsContainerTag.TAB_LABLE_NAME + "');");
		}
		if (isSelectedTab()) {
			outTmp.attribute(Xhtml.Attr.CLASS, TabsContainerTag.TAB_CLASS_NAME + " " +
					TabsContainerTag.FOCUSED_CLASS_NAME);
		}
		else {
			outTmp.attribute(Xhtml.Attr.CLASS, TabsContainerTag.TAB_CLASS_NAME + " " +
					TabsContainerTag.UNFOCUSED_CLASS_NAME);
		}
		outTmp.startElement(Xhtml.Html.SPAN);
		outTmp.attribute(Xhtml.Attr.CLASS, TabsContainerTag.TAB_BG_LEFT_CLASS_NAME);
		outTmp.text(" ");
		outTmp.endElement(Xhtml.Html.SPAN);
//			outTmp.startElement(Xhtml.XHtml.A);
//			outTmp.attribute(Xhtml.Attr.HREF,getTabUrl(tabPane) +
//										  TabLinkTag.QUESTION_MARK +
//										  TabLinkTag.PARAM_NAME_TAB_PANE_ID +
//										  TabLinkTag.EQUALS +
//										  tabPane.getId());
//			outTmp.attribute(Xhtml.Attr.ONCLICK,"return false;");
//
//			if (null != tabPane.getTabTitle() &&
//				0 < tabPane.getTabTitle().length()) {
//				outTmp.text(tabPane.getTabTitle());
//			}
//			outTmp.text(" ");
//			outTmp.endElement(Xhtml.XHtml.A);
		if (null != this.getImgSrc()) {
			outTmp.startElement(Xhtml.Html.IMG);
			outTmp.attribute(Xhtml.Attr.SRC, this.getImgSrc());
			outTmp.text(" ");
			outTmp.endElement(Xhtml.Html.IMG);
		}
		if ("up".equals(this.getImgPosition())) {
			outTmp.lineBreak();
		}
		if (null != this.getKey() &&
				0 < this.getKey().length()) {
			outTmp.text(getMessage(this.getKey(), true, getBundle()));
		}
		else if (null != this.getTabTitle() &&
				0 < this.getTabTitle().length()) {
			outTmp.text(this.getTabTitle());
		}
		outTmp.endElement(Xhtml.Html.DIV);
		sb.append(outTmp.getBuffer());

//		System.out.println("addToContainer size: " + getTabsContainer().getChildCount());
	}

	private void renderComponent() throws JspException {

		out.lineBreak();
		out.startElement(Xhtml.Html.DIV);
		out.attribute(Xhtml.Attr.ID, id);
		out.attribute(Xhtml.Attr.NAME, TabsContainerTag.TABS_NAME);
		out.attribute(Xhtml.Attr.CLASS, TabsContainerTag.TAB_PANE_CLASS_NAME);

		if (isSelectedTab()) {
			out.attribute(Xhtml.Attr.STYLE, "display:block;");
		}
		else {
			out.attribute(Xhtml.Attr.STYLE, "display:none;");
		}
		out.text(" ");

//		bodyContent.invoke(out.getWriter());
//		System.out.println("tab Content body: " + bodyContent.getString());
		if (null != bodyContent)
			out.text(bodyContent.getString());

		out.lineBreak();
		out.endElement(Xhtml.Html.DIV);

		this.getTabsContainer().setAfterEnd(this.getTabsContainer().getAfterEnd().append(out.getBuffer()));

//		try {
//			pageContext.getOut().println(out.getBuffer());
//		}
//		catch (IOException e) {
//			throw new JspException(e);
//		}

	}

	public void release() {
		tabTitle = null;
		tabContainer = null;
		out = new JspResponseWriter();
		super.release();
	}

	private boolean isSelectedTab() {
//		System.out.println("child index=" + getTabsContainer().getChildren().indexOf(this));
//		return getTabsContainer().getChildren().indexOf(this) ==
//				getTabsContainer().getSelectedIndex();
		if (getTabsContainer().getSelectedTabPaneId() != null) {
			if (getTabsContainer().getSelectedTabPaneId().equalsIgnoreCase(this.getId())) {
				return true;
			}
			else
				return false;
		}
		else
			return getTabsContainer().getChildIndex() == getTabsContainer().getSelectedIndex();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -