Source Code Cross Referenced for HtmlSubmitButton.java in  » J2EE » Sofia » com » salmonllc » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        // Copyright (C) 1999 - 2002, Salmon LLC
004:        //
005:        // This program is free software; you can redistribute it and/or
006:        // modify it under the terms of the GNU General Public License version 2
007:        // as published by the Free Software Foundation;
008:        // 
009:        // This program is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        // GNU General Public License for more details.
013:        // 
014:        // You should have received a copy of the GNU General Public License
015:        // along with this program; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:        // 
018:        // For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:        package com.salmonllc.html;
021:
022:        /////////////////////////
023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlSubmitButton.java $
024:        //$Author: Dan $
025:        //$Revision: 24 $
026:        //$Modtime: 1/22/04 3:44p $
027:        /////////////////////////
028:
029:        import java.util.Hashtable;
030:        import java.util.Vector;
031:
032:        import com.salmonllc.html.events.SubmitEvent;
033:        import com.salmonllc.html.events.SubmitListener;
034:        import com.salmonllc.localizer.LanguagePreferences;
035:        import com.salmonllc.localizer.LanguageResourceFinder;
036:        import com.salmonllc.properties.Props;
037:
038:        /**
039:         * This class generates an html submit button.
040:         */
041:        public class HtmlSubmitButton extends HtmlComponent {
042:            String _dispName = "";
043:            String _onClick = "";
044:
045:            Vector _listeners;
046:            private String _fontTagStart = null;
047:            private String _fontTagEnd = null;
048:            private int _rowNo = -1;
049:            private String _theme;
050:            private String _iFrameUrl = null;
051:            private HtmlInlineFrame _iFrame = null;
052:            private String _dispNameLocaleKey = null;
053:            private boolean _updateLocale = false;
054:            private boolean _enabled = true;
055:            private String _buttonBgColor = null;
056:            private String _buttonFontStyle = null;
057:            private Integer _tabIndex;
058:            private String _accessKey;
059:
060:            /**
061:             * Constructs a new Submit Button.
062:             * @param name Each component on a page must have a unique name.
063:             * @param dispName The text to appear on the button.
064:             * @param p A Props object that will be used to initialize any properties in the object.
065:             */
066:            public HtmlSubmitButton(String name, String dispName, HtmlPage p) {
067:                this (name, dispName, null, p);
068:
069:            }
070:
071:            /**
072:             * Constructs a new Submit Button.
073:             * @param name Each component on a page must have a unique name.
074:             * @param dispName The text to appear on the button.
075:             * @param theme The theme to use for loading properties
076:             * @param p A Props object that will be used to initialize any properties in the object.
077:             */
078:            public HtmlSubmitButton(String name, String dispName, String theme,
079:                    HtmlPage p) {
080:                super (name, p);
081:                _dispName = dispName;
082:                setTheme(theme);
083:            }
084:
085:            /**
086:             * This method adds a listener the will be notified when this button causes the page to be submitted.
087:             * @param l The listener to add.
088:             */
089:            public void addSubmitListener(SubmitListener l) {
090:                if (_listeners == null)
091:                    _listeners = new Vector();
092:
093:                for (int i = 0; i < _listeners.size(); i++) {
094:                    if (((SubmitListener) _listeners.elementAt(i)) == l)
095:                        return;
096:                }
097:
098:                _listeners.addElement(l);
099:            }
100:
101:            /**
102:             * This method inserts a listener at the beginning of the the listener list. It will be notified first when this button causes the page to be submitted.
103:             * @param l The listener to add.
104:             */
105:            public void insertSubmitListener(SubmitListener l) {
106:                if (_listeners == null)
107:                    _listeners = new Vector();
108:
109:                for (int i = 0; i < _listeners.size(); i++) {
110:                    if (((SubmitListener) _listeners.elementAt(i)) == l)
111:                        return;
112:                }
113:
114:                _listeners.insertElementAt(l, 0);
115:            }
116:
117:            public boolean executeEvent(int type) throws Exception {
118:                if (type != EVENT_SUBMIT)
119:                    return true;
120:
121:                if (_listeners == null)
122:                    return true;
123:
124:                SubmitEvent e = new SubmitEvent(getPage(), this , getName(),
125:                        getFullName(), _rowNo);
126:
127:                for (int i = 0; i < _listeners.size(); i++) {
128:                    SubmitListener l = (SubmitListener) _listeners.elementAt(i);
129:                    e.setNextListener(_listeners.size() > (i + 1) ? _listeners
130:                            .elementAt(i + 1) : null);
131:                    if (!l.submitPerformed(e))
132:                        return false;
133:                }
134:
135:                return true;
136:            }
137:
138:            public void generateHTML(java.io.PrintWriter p, int rowNo)
139:                    throws Exception {
140:                if (!getVisible())
141:                    return;
142:
143:                processLocaleInfo();
144:
145:                String name = getFullName();
146:                if (rowNo > -1)
147:                    name += "_" + rowNo;
148:
149:                String out = "";
150:                String jScript = null;
151:                if (_iFrame != null && _iFrameUrl == null) {
152:                    String uName = getPage().getClass().getName();
153:                    int pos = uName.lastIndexOf(".");
154:                    if (pos > -1)
155:                        uName = uName.substring(pos + 1);
156:                    uName += "-" + _iFrame.getName() + "FrameComponent";
157:                    _iFrameUrl = uName;
158:                }
159:
160:                String style = null;
161:                if (_buttonBgColor != null || _buttonFontStyle != null) {
162:                    style = " style=\"";
163:                    if (_buttonBgColor != null)
164:                        style += "background-color:" + _buttonBgColor + ";";
165:                    if (_buttonFontStyle != null)
166:                        style += _buttonFontStyle;
167:                    style += "\"";
168:                }
169:
170:                String onClick = _onClick;
171:                String valScript = HtmlValidatorText
172:                        .generateOnClickJavaScriptForButtons(_onClick,
173:                                _listeners, getFullName());
174:                if (valScript != null) {
175:                    out += valScript;
176:                    onClick = "return "
177:                            + HtmlValidatorText
178:                                    .generateOnClickJavaScriptFunctionName(getFullName())
179:                            + ";";
180:                }
181:
182:                if (_iFrame == null
183:                        || ((jScript = getPage().getSubmitJavaScript(this ,
184:                                _iFrameUrl, _iFrame)) == null)) {
185:                    out += "<INPUT TYPE=\"SUBMIT\" name=\"" + name
186:                            + "\" value=\"" + _dispName + "\"";
187:                    if (onClick != null && !onClick.trim().equals(""))
188:                        out += " onClick=\"" + onClick + "\"";
189:                    if (_class != null && !_class.trim().equals(""))
190:                        out += " class=\"" + _class + "\"";
191:                    if ((!_enabled) && useDisabledAttribute())
192:                        out += " disabled=\"true\"";
193:                    if (_tabIndex != null)
194:                        out += " tabindex=\"" + _tabIndex + "\"";
195:                    if (_accessKey != null)
196:                        out += " accesskey=\"" + _accessKey + "\"";
197:                    if (style != null)
198:                        out += style;
199:                    out += ">";
200:                } else {
201:                    out += "<INPUT TYPE=\"BUTTON\" name=\"" + name
202:                            + "\" value=\"" + _dispName + "\" onClick=\""
203:                            + jScript + "\"";
204:                    if (_class != null && !_class.trim().equals(""))
205:                        out += " class=\"" + _class + "\"";
206:                    if ((!_enabled) && useDisabledAttribute())
207:                        out += " disabled=\"true\"";
208:                    if (style != null)
209:                        out += style;
210:                    if (_tabIndex != null)
211:                        out += " tabindex=\"" + _tabIndex + "\"";
212:                    if (_accessKey != null)
213:                        out += " accesskey=\"" + _accessKey + "\"";
214:
215:                    out += ">";
216:                }
217:
218:                if (_fontTagStart != null)
219:                    out = _fontTagStart + out + _fontTagEnd;
220:
221:                p.println(out);
222:            }
223:
224:            /**
225:             * This method returns the text that will be displayed on the button in the browser.
226:             * @return java.lang.String
227:             */
228:            public String getDisplayName() {
229:                return _dispName;
230:            }
231:
232:            /**
233:             * This method gets the end font tag for the component.
234:             */
235:            public String getFontEndTag() {
236:                return _fontTagEnd;
237:            }
238:
239:            /**
240:             * This method gets the start font tag for the component.
241:             */
242:            public String getFontStartTag() {
243:                return _fontTagStart;
244:            }
245:
246:            /**
247:             * This method gets the javascript that will be executed when the button is clicked.
248:             */
249:            public String getOnClick() {
250:                return _onClick;
251:            }
252:
253:            /**
254:             * This method returns the property theme for the component.
255:             */
256:            public String getTheme() {
257:                return _theme;
258:            }
259:
260:            public boolean processParms(Hashtable parms, int rowNo)
261:                    throws Exception {
262:                String name = getFullName();
263:                if (rowNo > -1)
264:                    name += "_" + rowNo;
265:
266:                if (parms.get(name) != null) {
267:                    _rowNo = rowNo;
268:                    return true;
269:                }
270:
271:                return false;
272:            }
273:
274:            /**
275:             * This method removes a listener from the list that will be notified if this button causes the page to be submitted.
276:             * @param l The listener to remove.
277:             */
278:            public void removeSubmitListener(SubmitListener l) {
279:                if (_listeners == null)
280:                    return;
281:
282:                for (int i = 0; i < _listeners.size(); i++) {
283:                    if (((SubmitListener) _listeners.elementAt(i)) == l) {
284:                        _listeners.removeElementAt(i);
285:                        return;
286:                    }
287:                }
288:            }
289:
290:            /**
291:             * This method sets the text that will appear on the button in the browser.
292:             */
293:            public void setDisplayName(String name) {
294:                _dispName = name;
295:            }
296:
297:            /**
298:             * This method sets the end font tag for the component.
299:             */
300:            public void setFontEndTag(String value) {
301:                _fontTagEnd = value;
302:            }
303:
304:            /**
305:             * This method sets the start font tag for the component.
306:             */
307:            public void setFontStartTag(String value) {
308:                _fontTagStart = value;
309:            }
310:
311:            /**
312:             * Use this method if you want the button to submit only a layer of the page and not the whole page
313:             * @param iFrame The IFrame component that should be loaded
314:             */
315:            public void setIFrameSubmit(HtmlInlineFrame iFrame) {
316:                _iFrame = iFrame;
317:            }
318:
319:            /**
320:             * This method sets the javascript that will be executed when the button is clicked.
321:             */
322:            public void setOnClick(String onClick) {
323:                _onClick = onClick;
324:            }
325:
326:            /**
327:             * This method sets the property theme for the component.
328:             * @param theme The theme to use.
329:             */
330:            public void setTheme(String theme) {
331:                Props props = getPage().getPageProperties();
332:                _fontTagStart = props.getThemeProperty(theme, Props.FONT_BUTTON
333:                        + Props.TAG_START);
334:                _fontTagEnd = props.getThemeProperty(theme, Props.FONT_BUTTON
335:                        + Props.TAG_END);
336:                _buttonBgColor = props.getThemeProperty(theme,
337:                        Props.BUTTON_BG_COLOR);
338:                _buttonFontStyle = props.getThemeProperty(theme,
339:                        Props.BUTTON_FONT_STYLE);
340:                setClassName(props.getThemeProperty(theme,
341:                        Props.BUTTON_STYLE_CLASS));
342:                _theme = theme;
343:            }
344:
345:            /**
346:             * Returns the Locale key used for the text of this component
347:             */
348:            public String getDisplayNameLocaleKey() {
349:                return _dispNameLocaleKey;
350:            }
351:
352:            /**
353:             * Returns the Locale key used for text
354:             */
355:            public void setDisplayNameLocaleKey(String textLocaleKey) {
356:                _dispNameLocaleKey = textLocaleKey;
357:                _updateLocale = true;
358:            }
359:
360:            /**
361:             * Updates the Display Name for the current local
362:             */
363:            public void updateLocale() {
364:                _updateLocale = true;
365:            }
366:
367:            private void processLocaleInfo() {
368:                if (_updateLocale) {
369:                    _updateLocale = false;
370:                    LanguagePreferences p = getPage().getLanguagePreferences();
371:                    if (_dispNameLocaleKey != null) {
372:                        String newDisplayName = LanguageResourceFinder
373:                                .getResource(getPage().getApplicationName(),
374:                                        _dispNameLocaleKey, p);
375:                        if (newDisplayName != null)
376:                            setDisplayName(newDisplayName);
377:                    }
378:                }
379:            }
380:
381:            public boolean getEnabled() {
382:                return _enabled;
383:            }
384:
385:            public void setEnabled(boolean enabled) {
386:                _enabled = enabled;
387:            }
388:
389:            /**
390:             * Returns the background color for the button
391:             */
392:            public String getButtonBgColor() {
393:                return _buttonBgColor;
394:            }
395:
396:            /**
397:             * Sets the background color for the button
398:             */
399:            public void setButtonBgColor(String buttonBgColor) {
400:                _buttonBgColor = buttonBgColor;
401:            }
402:
403:            /**
404:             * Gets the foreground font style for a button
405:             */
406:            public String getButtonFontStyle() {
407:                return _buttonFontStyle;
408:            }
409:
410:            /**
411:             * Sets the foreground font style for a button
412:             */
413:
414:            public void setButtonFontStyle(String buttonFontStyle) {
415:                _buttonFontStyle = buttonFontStyle;
416:            }
417:
418:            /**
419:             * @returns the access key html attribute
420:             */
421:            public String getAccessKey() {
422:                return _accessKey;
423:            }
424:
425:            /**
426:             * @returns the tab index html attribute
427:             */
428:            public int getTabIndex() {
429:                if (_tabIndex == null)
430:                    return -1;
431:                return _tabIndex.intValue();
432:            }
433:
434:            /**
435:             * @param sets the access key html attribute
436:             */
437:            public void setAccessKey(String string) {
438:                _accessKey = string;
439:            }
440:
441:            /**
442:             * @param sets the tab index html attribute. You can also pass TAB_INDEX_DEFAULT to use the default tab index for the component or TAB_INDEX_NONE to keep this component from being tabbed to
443:             */
444:            public void setTabIndex(int val) {
445:                if (val == -1)
446:                    _tabIndex = null;
447:                else
448:                    _tabIndex = new Integer(val);
449:            }
450:
451:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.