001: //The Salmon Open Framework for Internet Applications (SOFIA)
002: //Copyright (C) 1999 - 2002, Salmon LLC
003: //
004: //This program is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU General Public License version 2
006: //as published by the Free Software Foundation;
007: //
008: //This program is distributed in the hope that it will be useful,
009: //but WITHOUT ANY WARRANTY; without even the implied warranty of
010: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: //GNU General Public License for more details.
012: //
013: //You should have received a copy of the GNU General Public License
014: //along with this program; if not, write to the Free Software
015: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: //
017: //For more information please visit http://www.salmonllc.com
018:
019: package com.salmonllc.examples.example16;
020:
021: import com.salmonllc.jsp.*;
022: import com.salmonllc.examples.SiteMapConstants;
023: import com.salmonllc.html.events.*;
024: import com.salmonllc.personalization.SkinManager;
025: import com.salmonllc.personalization.Skin;
026:
027: /**
028: * An example of how to use the SOFIA personalization package to change the look and feel of your application
029: */
030: public class PersonalizationController extends JspController implements
031: SubmitListener, PageListener {
032:
033: //Visual Components
034: public com.salmonllc.html.HtmlDropDownList _swingSkin;
035: public com.salmonllc.html.HtmlDropDownList _webSkin;
036: public com.salmonllc.html.HtmlSubmitButton _apply;
037: public com.salmonllc.html.HtmlSubmitButton _customizeSwing;
038: public com.salmonllc.html.HtmlSubmitButton _customizeWeb;
039: public com.salmonllc.jsp.JspForm _pageForm;
040:
041: public com.salmonllc.html.HtmlText _capSwingSkin;
042: public com.salmonllc.html.HtmlText _capWebSkin;
043:
044: public void initialize() {
045: loadDropDowns();
046:
047: _pageForm.addSubmitListener(this );
048: _apply.addSubmitListener(this );
049: _customizeWeb.addSubmitListener(this );
050: _customizeSwing.addSubmitListener(this );
051: addPageListener(this );
052: }
053:
054: public boolean submitPerformed(SubmitEvent e) throws Exception {
055: if (e.getSource() == _apply)
056: apply();
057: else if (e.getSource() == _pageForm) {
058: _customizeWeb.setEnabled(!_webSkin.getValue()
059: .equals("none"));
060: _customizeSwing.setEnabled(_swingSkin.getValue().indexOf(
061: "Metal-") > -1
062: || _swingSkin.getValue().indexOf("User") > -1);
063: _apply.setEnabled(true);
064: } else if (e.getSource() == _customizeWeb)
065: gotoSiteMapPage(SiteMapConstants.PERSONALIZATION_WEB,
066: "?skin=browser" + _webSkin.getValue());
067: else if (e.getSource() == _customizeSwing)
068: gotoSiteMapPage(SiteMapConstants.PERSONALIZATION_SWING,
069: "?skin=swing" + _swingSkin.getValue());
070:
071: return true;
072: }
073:
074: /**
075: * This event will get fired each time a page is requested by the browser before any HTML is generated.
076: */
077: public void pageRequested(PageEvent p) throws Exception {
078: if (!isReferredByCurrentPage()) {
079: String webSkin = getParameter("webSkin");
080: String swingSkin = getParameter("swingSkin");
081: if (webSkin != null || swingSkin != null) {
082: loadDropDowns();
083: if (webSkin != null)
084: _webSkin.setValue(webSkin.substring(7));
085: if (swingSkin != null)
086: _swingSkin.setValue(swingSkin.substring(5));
087: apply();
088: }
089: }
090: }
091:
092: /**
093: * This event will get fired each time a page is requested by the browser after any HTML is generated.
094: */
095: public void pageRequestEnd(PageEvent p) throws Exception {
096: }
097:
098: /**
099: * This method occurs each time a page is submitted before values are copied from the HTML form to the framework component representing input fields.
100: */
101: public void pageSubmitEnd(PageEvent p) {
102: }
103:
104: /**
105: * This method occurs each time a page is submitted after all the values submitted from the HTML form are copied to framework components representing them.
106: */
107: public void pageSubmitted(PageEvent p) {
108: }
109:
110: private void apply() {
111: String webSkin = _webSkin.getValue();
112: String swingSkin = _swingSkin.getValue();
113: SkinManager man = SkinManager
114: .getSkinManager(getApplicationName());
115: Skin skin = new Skin();
116: if (webSkin != null)
117: man.load("browser" + webSkin, skin);
118: if (swingSkin != null)
119: man.load("swing" + swingSkin, skin);
120: clearAllPagesFromSessionButCurrent();
121: setDefaultSkin(skin, true);
122: }
123:
124: private void loadDropDowns() {
125: //get the default skin manager to populat the drop down lists
126: SkinManager man = SkinManager
127: .getSkinManager(getApplicationName());
128: String skin[] = man.getSkinNames();
129: //we use a naming convention to seperate the swing skins from the web ones. Swing ones start with swing.
130: _webSkin.resetOptions();
131: _swingSkin.resetOptions();
132: _webSkin.addOption("none", "Default");
133: _swingSkin.addOption("none", "Default");
134: for (int i = 0; i < skin.length; i++) {
135: if (skin[i].startsWith("swing")) {
136: String val = skin[i].substring(5);
137: _swingSkin.addOption(val, val);
138: } else if (skin[i].startsWith("browser")) {
139: String val = skin[i].substring(7);
140: _webSkin.addOption(val, val);
141: }
142: }
143: }
144: }
|