001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Darrell Meyer <darrell@mygwt.net> - derived implementation
011: *******************************************************************************/package net.mygwt.ui.client.widget;
012:
013: import net.mygwt.ui.client.MyDOM;
014: import net.mygwt.ui.client.Style;
015: import net.mygwt.ui.client.util.Format;
016:
017: import com.google.gwt.user.client.DOM;
018: import com.google.gwt.user.client.Element;
019:
020: /**
021: * Instances of this class are used to inform or warn the user.
022: *
023: * <dl>
024: * <dt><b>Icons:</b></dt>
025: * <dd>ICON_ERROR, ICON_INFO, ICON_QUESTION, ICON_WARNING</dd>
026: *
027: * <dt><b>Styles:</b></dt>
028: * <dd>OK, OK_CANCEL, YES_NO, YES_NO_CANCEL</dd>
029: * </dl>
030: */
031: public class MessageBox extends Dialog {
032:
033: private String message;
034: private int icon;
035:
036: /**
037: * Creates a new message box instance with the given icon and button(s).
038: *
039: * @param icon the icon to display
040: * @param style the buttons to display
041: */
042: public MessageBox(int icon, int style) {
043: super (style);
044: this .icon = icon;
045: setCloseOnButtonClick(true);
046: }
047:
048: /**
049: * Returns the dialog's message.
050: *
051: * @return the message
052: */
053: public String getMessage() {
054: return message;
055: }
056:
057: /**
058: * Sets the dialog's message.
059: *
060: * @param message the message
061: */
062: public void setMessage(String message) {
063: this .message = message;
064: }
065:
066: protected void createContent(WidgetContainer container) {
067: StringBuffer sb = new StringBuffer();
068: sb.append("<table width=100% height=100%><tr>");
069: sb
070: .append("<td class='my-mbox-icon'><div class='my-mbox-icon {0}'></div></td>");
071: sb.append("<td width=100% class=my-mbox-text>{1}</td>");
072: sb.append("</tr></table>");
073:
074: String path = null;
075: switch (icon) {
076: case Style.ICON_ERROR:
077: path = "my-mbox-error";
078: break;
079: case Style.ICON_INFO:
080: path = "my-mbox-info";
081: break;
082: case Style.ICON_QUESTION:
083: path = "my-mbox-question";
084: break;
085: case Style.ICON_WARNING:
086: path = "my-mbox-warning";
087: break;
088: }
089:
090: String html = Format.substitute(sb.toString(), new String[] {
091: path, message });
092: Element elem = MyDOM.create(html);
093: DOM.appendChild(container.getElement(), elem);
094:
095: }
096:
097: protected void onRender() {
098: super .onRender();
099: addStyleName("my-message-box");
100: addStyleName("my-shell-plain");
101: }
102:
103: }
|