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

📄 modalwindow.java

📁 Wicket一个开发Java Web应用程序框架。它使得开发web应用程序变得容易而轻松。 Wicket利用一个POJO data beans组件使得它可以与任何持久层技术相结合。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * not resizable.	 * 	 * @param widthUnit	 *            CSS unit for initial window width.	 */	public void setWidthUnit(String widthUnit)	{		this.widthUnit = widthUnit;	}	/**	 * Returns the CSS unit for initial window width.	 * 	 * @return CSS unit for initial window width.	 */	public String getWidthUnit()	{		return widthUnit;	}	/**	 * Sets the CSS unit used for initial window height. This is only applicable when the window is	 * not resizable.	 * 	 * @param heightUnit	 *            CSS unit for initial window height.	 */	public void setHeightUnit(String heightUnit)	{		this.heightUnit = heightUnit;	}	/**	 * Retrns the CSS unit for initial window height.	 * 	 * @return CSS unit for initial window height.	 */	public String getHeightUnit()	{		return heightUnit;	}	/**	 * Sets the name of the cookie that is used to remember window position (and size if the window	 * is resizable).	 * 	 * @param cookieName	 *            Name of the cookie	 */	public void setCookieName(String cookieName)	{		if (cookieName != null && cookieName.indexOf(",") != -1 && cookieName.indexOf("|") != -1)		{			throw new IllegalArgumentException("Cookie name may not contain ',' or '|' characters.");		}		this.cookieName = cookieName;	}	/**	 * Returns the name of cookie that is used to remember window position (and size if the window	 * is resizable).	 * 	 * @return Name of the cookie	 */	public String getCookieName()	{		return cookieName;	}	/**	 * Sets the title of window. If the window is a page, title can be <code>null</code>. In that	 * case it will display the title document inside the window.	 * 	 * @param title	 *            Title of the window	 */	public void setTitle(String title)	{		this.title = new Model(title);	}	/**	 * Sets the title of window. If the window is a page, title can be <code>null</code>. In that	 * case it will display the title document inside the window.	 * 	 * @param title	 *            Title of the window	 */	public void setTitle(IModel title)	{		this.title = title;	}	/**	 * Returns the title of the window.	 * 	 * @return Title of the window	 */	public IModel getTitle()	{		return title;	}	/**	 * Mask is the element behind the window, that prevents user from interacting the rest of page.	 * Mask can be either	 * <ul>	 * <li><code>{@link #TRANSPARENT}</code> - the mask is invisible	 * <li><code>{@link #SEMI_TRANSPARENT}</code> - the mask is black with small opacity (10%)	 * </ul>	 * 	 * @author Matej Knopp	 */	public static final class MaskType extends EnumeratedType	{		private static final long serialVersionUID = 1L;		/**		 * Transparent mask (not visible).		 */		public static final MaskType TRANSPARENT = new MaskType("TRANSPARENT");		/**		 * Visible mask (black with low opacity).		 */		public static final MaskType SEMI_TRANSPARENT = new MaskType("SEMI_TRANSPARENT");		/**		 * Constructor.		 * 		 * @param name		 */		public MaskType(String name)		{			super(name);		}	};	/**	 * Sets the mask type of the window.	 * 	 * @param mask	 *            The mask type	 */	public void setMaskType(MaskType mask)	{		maskType = mask;	}	/**	 * Returns the mask type of the window	 * 	 * @return The mask type	 */	public MaskType getMaskType()	{		return maskType;	}	/**	 * Creates the page.	 * 	 * @return Page instance or null if page couldn't be created.	 */	private Page createPage()	{		if (pageCreator == null)		{			return null;		}		else		{			RequestParameters parameters = RequestCycle.get().getRequest().getRequestParameters();			String oldPageMapName = parameters.getPageMapName();			// if there is a pagemap name specified and multiwindow support is			// on			if (getPageMapName() != null)			{				// try to find out whether the pagemap already exists				Session session = Session.get();				if (session.pageMapForName(getPageMapName(), false) == null)				{					deletePageMap = true;				}				parameters.setPageMapName(getPageMapName());			}			try			{				Page page = pageCreator.createPage();				return page;			}			finally			{				parameters.setPageMapName(oldPageMapName);			}		}	}	/**	 * @see org.apache.wicket.Component#onBeforeRender()	 */	protected void onBeforeRender()	{		// if user is refreshing whole page, the window will not be shown		if (((WebRequest)getRequest()).isAjax() == false)		{			shown = false;		}		getContent().setOutputMarkupId(true);		getContent().setVisible(shown);		super.onBeforeRender();	}	/**	 * @see org.apache.wicket.markup.html.panel.Panel#onComponentTag(org.apache.wicket.markup.ComponentTag)	 */	protected void onComponentTag(ComponentTag tag)	{		super.onComponentTag(tag);		tag.put("style", "display:none");	}	/**	 * Returns a content component. In case user haven't specified any content component, it returns	 * an empty WebMarkupContainer.	 * 	 * @return Content component	 */	private Component getContent()	{		return get(getContentId());	}	/**	 * Returns true if user has added own component to the window.	 * 	 * @return True if user has added own component to the window, false otherwise.	 */	private boolean isCustomComponent()	{		return getContent() != empty;	}	/**	 * @see org.apache.wicket.MarkupContainer#remove(org.apache.wicket.Component)	 */	public void remove(Component component)	{		super.remove(component);		if (component.getId().equals(getContentId()))		{			add(empty = new WebMarkupContainer(getContentId()));		}	}	/**	 * Sets the content of the modal window.	 * 	 * @param component	 */	public void setContent(Component component)	{		if (component.getId().equals(getContentId()) == false)		{			throw new WicketRuntimeException("Modal window content id is wrong.");		}		replace(component);		shown = false;	}	/**	 * @author Matej Knopp	 */	private class WindowClosedBehavior extends AbstractDefaultAjaxBehavior	{		private static final long serialVersionUID = 1L;		protected void respond(AjaxRequestTarget target)		{			shown = false;			// should we cleanup the pagemap?			if (deletePageMap == true)			{				// get the pagemap				Session session = Session.get();				IPageMap pageMap = session.pageMapForName(getPageMapName(), false);				// if there is any remove it				if (pageMap != null)				{					session.removePageMap(pageMap);					deletePageMap = false;				}			}			if (windowClosedCallback != null)			{				windowClosedCallback.onClose(target);			}		}		protected CharSequence getCallbackScript()		{			return super.getCallbackScript();		}	};	/**	 * @author Matej Knopp	 */	private class CloseButtonBehavior extends AbstractDefaultAjaxBehavior	{		private static final long serialVersionUID = 1L;		protected void respond(AjaxRequestTarget target)		{			if (closeButtonCallback == null ||				closeButtonCallback.onCloseButtonClicked(target) == true)			{				close(target);			}		}		/**		 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getAjaxCallDecorator()		 */		protected IAjaxCallDecorator getAjaxCallDecorator()		{			return new CancelEventIfNoAjaxDecorator(super.getAjaxCallDecorator());		}		/**		 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getCallbackScript()		 */		protected CharSequence getCallbackScript()		{			return super.getCallbackScript();		}	}	/**	 * Returns the markup id of the component.	 * 	 * @return component id	 */	private String getContentMarkupId()	{		return getContent().getMarkupId();	}	/**	 * Replaces all occurrences of " in string with \".	 * 	 * @param string	 *            String to be escaped.	 * 	 * @return escaped string	 */	private String escapeQuotes(String string)	{		if (string.indexOf('"') != -1)		{			string = Strings.replaceAll(string, "\"", "\\\"").toString();		}		return string;	}	/**	 * Returns the javascript used to open the window.	 * 	 * @return javascript that opens the window	 */	private String getWindowOpenJavascript()	{		AppendingStringBuffer buffer = new AppendingStringBuffer();		if (isCustomComponent() == true)		{			buffer.append("var element = document.getElementById(\"" + getContentMarkupId() +				"\");\n");		}		buffer.append("var settings = new Object();\n");		buffer.append("settings.minWidth=" + getMinimalWidth() + ";\n");		buffer.append("settings.minHeight=" + getMinimalHeight() + ";\n");		buffer.append("settings.className=\"" + getCssClassName() + "\";\n");		buffer.append("settings.width=\"" + getInitialWidth() + "\";\n");		if (isUseInitialHeight() == true || isCustomComponent() == false)			buffer.append("settings.height=\"" + getInitialHeight() + "\";\n");		else			buffer.append("settings.height=null;\n");		buffer.append("settings.resizable=" + Boolean.toString(isResizable()) + ";\n");		if (isResizable() == false)		{			buffer.append("settings.widthUnit=\"" + getWidthUnit() + "\";\n");			buffer.append("settings.heightUnit=\"" + getHeightUnit() + "\";\n");		}		if (isCustomComponent() == false)		{			Page page = createPage();			if (page == null)			{				throw new WicketRuntimeException("Error creating page for modal dialog.");			}			RequestCycle.get().setUrlForNewWindowEncoding();			buffer.append("settings.src=\"" + RequestCycle.get().urlFor(page) + "\";\n");			if (getPageMapName() != null)			{				buffer.append("settings.iframeName=\"" + getPageMapName() + "\";\n");			}		}		else		{			buffer.append("settings.element = element;\n");		}		if (getCookieName() != null)		{			buffer.append("settings.cookieId=\"" + getCookieName() + "\";\n");		}		Object title = getTitle() != null ? getTitle().getObject() : null;		if (title != null)		{			buffer.append("settings.title=\"" + escapeQuotes(title.toString()) + "\";\n");		}		if (getMaskType() == MaskType.TRANSPARENT)		{			buffer.append("settings.mask=\"transparent\";\n");		}		else if (getMaskType() == MaskType.SEMI_TRANSPARENT)		{			buffer.append("settings.mask=\"semi-transparent\";\n");		}		// set true if we set a windowclosedcallback		boolean haveCloseCallback = false;		// in case user is interested in window close callback or we have a		// pagemap to clean		// attach notification request		if ((isCustomComponent() == false && deletePageMap) || windowClosedCallback != null)		{			WindowClosedBehavior behavior = (WindowClosedBehavior)getBehaviors(				WindowClosedBehavior.class).get(0);			buffer.append("settings.onClose = function() { " + behavior.getCallbackScript() +				" };\n");			haveCloseCallback = true;		}		// in case we didn't set windowclosecallback, we need at least callback		// on close button,		// to close window property (thus cleaning the shown flag)		if (closeButtonCallback != null || haveCloseCallback == false)		{			CloseButtonBehavior behavior = (CloseButtonBehavior)getBehaviors(				CloseButtonBehavior.class).get(0);			buffer.append("settings.onCloseButton = function() { " + behavior.getCallbackScript() +				"};\n");		}		postProcessSettings(buffer);		buffer.append("Wicket.Window.create(settings).show();\n");		return buffer.toString();	}	/**	 * Method that allows tweaking the settings	 * 	 * @param settings	 * @return settings javascript	 */	protected AppendingStringBuffer postProcessSettings(AppendingStringBuffer settings)	{		return settings;	}	private boolean deletePageMap = false;	private boolean shown = false;	// empty container - used when no component is added	private WebMarkupContainer empty;	private int minimalWidth = 200;	private int minimalHeight = 200;	private String cssClassName = CSS_CLASS_BLUE;	private int initialWidth = 600;	private int initialHeight = 400;	private boolean useInitialHeight = true;	private boolean resizable = true;	private String widthUnit = "px";	private String heightUnit = "px";	private String cookieName;	private IModel title = null;	private MaskType maskType = MaskType.SEMI_TRANSPARENT;	private String pageMapName = "modal-dialog-pagemap";	private PageCreator pageCreator = null;	private CloseButtonCallback closeButtonCallback = null;	private WindowClosedCallback windowClosedCallback = null;}

⌨️ 快捷键说明

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