001: //package statement
002: package com.salmonllc.examples.example19;
003:
004: //Salmon import statements
005: import java.text.DecimalFormat;
006: import java.util.Enumeration;
007:
008: import com.salmonllc.html.HtmlButton;
009: import com.salmonllc.html.HtmlComponent;
010: import com.salmonllc.html.HtmlLookUpComponent;
011: import com.salmonllc.html.HtmlScriptGenerator;
012: import com.salmonllc.html.events.PageEvent;
013: import com.salmonllc.html.events.PageListener;
014: import com.salmonllc.jsp.JspController;
015: import com.salmonllc.properties.Props;
016:
017: //The Salmon Open Framework for Internet Applications (SOFIA)
018: //Copyright (C) 1999 - 2002, Salmon LLC
019: //
020: //This program is free software; you can redistribute it and/or
021: //modify it under the terms of the GNU General Public License version 2
022: //as published by the Free Software Foundation;
023: //
024: //This program is distributed in the hope that it will be useful,
025: //but WITHOUT ANY WARRANTY; without even the implied warranty of
026: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
027: //GNU General Public License for more details.
028: //
029: //You should have received a copy of the GNU General Public License
030: //along with this program; if not, write to the Free Software
031: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
032: //
033: //For more information please visit http://www.salmonllc.com
034:
035: /**
036: * CalculatorController: The controller for the Drop Down Calculator
037: * This demonstrates how you can create your own type of popup using SOFIA component
038: * The calculator isn't a SOFIA component itself, but is constructed out of SOFIA components and javascript
039: */
040: public class CalculatorLookupController extends JspController implements
041: PageListener {
042: public com.salmonllc.html.HtmlButton _buttonCancel;
043: public com.salmonllc.html.HtmlButton _buttonEnter;
044: public com.salmonllc.html.HtmlTextEdit _text1;
045:
046: /**
047: * Initialize the page. Set up listeners and perform other initialization activities.
048: */
049: public void initialize() {
050: addPageListener(this );
051:
052: //For IE, mousedown and double click is more responsive then onclick so copy all the javascript from one to the other
053: if (getBrowserType() == BROWSER_MICROSOFT) {
054: Enumeration en = getComponents();
055: while (en.hasMoreElements()) {
056: HtmlComponent comp = (HtmlComponent) en.nextElement();
057: if (comp instanceof HtmlButton) {
058: HtmlButton b = (HtmlButton) comp;
059: b.setOnMouseDown(b.getOnClick());
060: b.setOnDoubleClick(b.getOnClick());
061: b.setOnClick(null);
062: }
063: }
064: }
065:
066: }
067:
068: /**
069: * Process the page requested event
070: * @param event the page event to be processed
071: */
072: public void pageRequested(PageEvent event) {
073: if (!isReferredByCurrentPage()) {
074: //set the appropriate script for the cancel button
075: HtmlScriptGenerator gen = new HtmlScriptGenerator(this );
076: _buttonCancel.setOnClick(gen.generateCancelLookupScript());
077:
078: //set value and the max length in the text box in the calculator
079: _text1.setMaxLength(HtmlLookUpComponent
080: .getParentLookupMaxLength(this ));
081: _text1.setValue(HtmlLookUpComponent
082: .getParentLookupValue(this ));
083:
084: //set focus to the window
085: writeScript("document.forms[0]."
086: + _buttonEnter.getFullName() + ".focus();");
087:
088: //set the background color so this matchs the calendar lookup
089: Props p = getPageProperties();
090: setBackgroundColor(p
091: .getProperty(Props.CAL_WEEK_BACKGROUND_COLOR));
092:
093: }
094: }
095:
096: public void pageRequestEnd(PageEvent event) {
097: }
098:
099: /**
100: * Fired when the user hits the Enter button
101: */
102: public void pageSubmitEnd(PageEvent event) {
103: //Take the value from the calculator, format it and copy the value back to the field
104: HtmlLookUpComponent comp = getPopupLookupComponent();
105: String lookupFormat = comp.getEditField().getDisplayFormat();
106: HtmlScriptGenerator gen = new HtmlScriptGenerator(this );
107: String numVal = _text1.getValue();
108: if (numVal == null)
109: numVal = "";
110: if (lookupFormat != null) {
111: try {
112: double dv = Double.parseDouble(numVal);
113: DecimalFormat df = new DecimalFormat(lookupFormat);
114: numVal = df.format(dv);
115: } catch (Exception ex) {
116: }
117: }
118: writeScript(gen.generateReturnValueToLookupScript(numVal, ""));
119: }
120:
121: /**
122: * Process the page submit event
123: * @param event the page event to be processed
124: */
125: public void pageSubmitted(PageEvent event) {
126: }
127:
128: }
|