001: /*
002: *
003: * Copyright (c) 2007, Sun Microsystems, Inc.
004: *
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * * Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * * Neither the name of Sun Microsystems nor the names of its contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032: package com.sun.perseus.demo;
033:
034: import com.sun.svg.component.SVGTextBinding;
035: import org.w3c.dom.Document;
036:
037: /**
038: * The <code>ContactDetailsForm</code> class simplifies binding a contact's
039: * information (name, phone number, etc...) to the various
040: * SVG elements in the current skin.
041: */
042: public class ContactDetailsForm {
043: /**
044: * Identifier conventions used for contact details information.
045: */
046: public static final String CONTACT_DETAILS_PREFIX = "contactDetails.";
047: public static final String CONTACT_DETAILS_NAME = "selectedItem."
048: + "text";
049: public static final String CONTACT_DETAILS_EMAIL = CONTACT_DETAILS_PREFIX
050: + "email";
051: public static final String CONTACT_DETAILS_CELL = CONTACT_DETAILS_PREFIX
052: + "cell";
053: public static final String CONTACT_DETAILS_WORK = CONTACT_DETAILS_PREFIX
054: + "work";
055: public static final String CONTACT_DETAILS_HOME = CONTACT_DETAILS_PREFIX
056: + "home";
057: public static final String CONTACT_DETAILS_ADDRESS1 = CONTACT_DETAILS_PREFIX
058: + "address1";
059: public static final String CONTACT_DETAILS_ADDRESS2 = CONTACT_DETAILS_PREFIX
060: + "address2";
061:
062: protected SVGTextBinding name;
063: protected SVGTextBinding email;
064: protected SVGTextBinding cellPhone;
065: protected SVGTextBinding workPhone;
066: protected SVGTextBinding homePhone;
067: protected SVGTextBinding address1;
068: protected SVGTextBinding address2;
069:
070: /**
071: * Default constructor.
072: */
073: public ContactDetailsForm() {
074: name = new SVGTextBinding(CONTACT_DETAILS_NAME);
075: email = new SVGTextBinding(CONTACT_DETAILS_EMAIL);
076: cellPhone = new SVGTextBinding(CONTACT_DETAILS_CELL);
077: workPhone = new SVGTextBinding(CONTACT_DETAILS_WORK);
078: homePhone = new SVGTextBinding(CONTACT_DETAILS_HOME);
079: address1 = new SVGTextBinding(CONTACT_DETAILS_ADDRESS1);
080: address2 = new SVGTextBinding(CONTACT_DETAILS_ADDRESS2);
081: }
082:
083: /**
084: * Establishes new bindings between to the new skin.
085: *
086: * @param doc - the new skin to hook into.
087: */
088: public void hookSkin(final Document doc) {
089: name.hookSkin(doc);
090: email.hookSkin(doc);
091: cellPhone.hookSkin(doc);
092: workPhone.hookSkin(doc);
093: homePhone.hookSkin(doc);
094: address1.hookSkin(doc);
095: address2.hookSkin(doc);
096: }
097:
098: /**
099: * Applies the input contact details to the XML UI markup.
100: *
101: * @param contactDetailsData - the new data to display.
102: */
103: void setContactDetails(ContactDetails contactDetailsData) {
104: name.set(contactDetailsData.getName());
105: email.set(contactDetailsData.getEmail());
106: cellPhone.set(contactDetailsData.getCellPhone());
107: workPhone.set(contactDetailsData.getWorkPhone());
108: homePhone.set(contactDetailsData.getHomePhone());
109: address1.set(contactDetailsData.getAddress1());
110: address2.set(contactDetailsData.getAddress2());
111: }
112: }
|