Source Code Cross Referenced for HtmlMultiLineTextEdit.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/HtmlMultiLineTextEdit.java $
024:        //$Author: Dan $
025:        //$Revision: 31 $
026:        //$Modtime: 7/30/04 10:41a $
027:        /////////////////////////
028:
029:        import java.util.Hashtable;
030:        import java.util.StringTokenizer;
031:
032:        import com.salmonllc.html.events.ValueChangedEvent;
033:        import com.salmonllc.properties.Props;
034:        import com.salmonllc.util.Util;
035:
036:        /**
037:         * This class is used for multi line text input in a page.
038:         */
039:        public class HtmlMultiLineTextEdit extends HtmlFormComponent {
040:            public static final int WRAP_OFF = 0;
041:            public static final int WRAP_HARD = 1;
042:            public static final int WRAP_SOFT = 2;
043:
044:            private String _fontTagStart;
045:            private String _fontTagEnd;
046:            private int _maxLength = -1;
047:            private int _cols = 10;
048:            private int _rows = 3;
049:            private String _onChange;
050:            private String _onFocus;
051:            private String _onLoseFocus;
052:            private int _wrap = WRAP_SOFT;
053:            private boolean _readOnly = false;
054:            private Integer _tabIndex;
055:            private String _accessKey;
056:            private String _style;
057:
058:            /**
059:             * Constructs a new HTMLMultiLineTextEdit component.
060:             * @param name The name of the component
061:             * @param p The page the component will be placed in.
062:             */
063:            public HtmlMultiLineTextEdit(String name,
064:                    com.salmonllc.html.HtmlPage p) {
065:                this (name, null, p);
066:
067:            }
068:
069:            /**
070:             * Constructs a new HTMLMultiLineTextEdit component.
071:             * @param name The name of the component
072:             * @param theme The theme to use for loading properties.
073:             * @param p The page the component will be placed in.
074:             */
075:            public HtmlMultiLineTextEdit(String name, String theme,
076:                    com.salmonllc.html.HtmlPage p) {
077:                super (name, theme, p);
078:
079:            }
080:
081:            public void generateHTML(java.io.PrintWriter p, int rowNo)
082:                    throws Exception {
083:                if (!_visible)
084:                    return;
085:
086:                String name = getFullName();
087:                if (rowNo > -1)
088:                    name += "_" + rowNo;
089:
090:                String tag = "<TEXTAREA NAME=\"" + name + "\"";
091:
092:                if (_readOnly) {
093:                    tag += " readonly=\"true\"";
094:                }
095:
096:                if (!getEnabled()) {
097:                    if (useDisabledAttribute())
098:                        tag += " disabled=\"true\"";
099:                    else {
100:
101:                        if (_disabledFontStartTag != null)
102:                            p.print(_disabledFontStartTag);
103:                        String out = getValue(rowNo, true);
104:                        if (out != null) {
105:                            String buf = "";
106:                            StringTokenizer st = new StringTokenizer(out,
107:                                    " \t\n\r", true);
108:                            int n = 0;
109:                            String linebreak = "";
110:
111:                            //--------------------------------------------------------------------
112:                            // Added by BYD on 01/24/02 to properly handle page breaks in Netscape
113:                            int iNbrCols = _cols;
114:                            if (getPage().getBrowserType() == HtmlPage.BROWSER_NETSCAPE)
115:                                iNbrCols = (int) (iNbrCols * .70);
116:                            //--------------------------------------------------------------------
117:                            while (st.hasMoreTokens()) {
118:                                String next = st.nextToken();
119:                                if (next.equals("\r"))
120:                                    // We need to detect the \r\n sequence and this is a cheap way
121:                                    // to do it.  Strictly speaking, there could be isolated \r
122:                                    // characters but the possibility is remote.
123:                                    // We swallow the \r to avoid double line breaks.
124:                                    continue;
125:                                else if (next.equals("\n")) {
126:                                    p.print(linebreak);
127:                                    linebreak = "<BR>";
128:                                    p.print(fixSpecialHTMLCharacters(buf));
129:                                    next = ""; // Else we get double line breaks
130:                                    buf = "";
131:                                    n = 0;
132:                                }
133:                                //----------------------------------------------------------------------
134:                                // changed by BYD on 01/24/02 to properly handle page breaks in Netscape
135:                                //				else if ((n + next.length()) > _cols)
136:                                //----------------------------------------------------------------------
137:                                else if ((n + next.length()) > iNbrCols) {
138:                                    p.print(linebreak);
139:                                    linebreak = "<BR>";
140:                                    p.print(fixSpecialHTMLCharacters(buf));
141:                                    buf = "";
142:                                    n = 0;
143:                                }
144:                                buf += next;
145:                                n += next.length();
146:                            }
147:                            if (buf.length() > 0) {
148:                                p.print(linebreak);
149:                                p.print(fixSpecialHTMLCharacters(buf));
150:                            }
151:                        }
152:                        p.print("&nbsp;");
153:                        if (_disabledFontStartTag != null)
154:                            p.print(_disabledFontEndTag);
155:                        return;
156:                    }
157:                }
158:
159:                if (_tabIndex != null)
160:                    tag += " tabindex=\"" + _tabIndex + "\"";
161:
162:                if (_accessKey != null)
163:                    tag += " accesskey=\"" + _accessKey + "\"";
164:
165:                String lengthFunctions = null;
166:                if (_maxLength > -1) {
167:
168:                    tag += " MAXLENGTH=\"" + _maxLength + "\"";
169:                    tag += " onKeyDown=\"javascript:" + _fullName
170:                            + "textCounter(" + _fullName + "," + _maxLength
171:                            + ", event)\"";
172:                    tag += " onKeyUp=\"javascript:" + _fullName
173:                            + "textCounter(" + _fullName + "," + _maxLength
174:                            + ", event)\"";
175:                    tag += " onpaste=\"javascript:" + _fullName + "textPaste("
176:                            + _fullName + "," + _maxLength + ", event)\"";
177:                    lengthFunctions = " <SCRIPT language=\"javascript\">"
178:                            + "\nfunction "
179:                            + _fullName
180:                            + "textCounter(field,maxlimit, event) {\n"
181:                            + " if ((event.keyCode != 8 && event.keyCode != 46 && \n"
182:                            + "	event.keyCode != 37 && event.keyCode != 38 \n"
183:                            + "	&& event.keyCode != 39 && event.keyCode != 40) \n"
184:                            + "	&& field.value.length >= maxlimit ) \n"
185:                            + "       { \n"
186:                            + "         event.returnValue=false; \n"
187:                            + "       } \n"
188:                            + "}\n"
189:                            + "function "
190:                            + _fullName
191:                            + "textPaste(field,maxlimit, event)\n"
192:                            + "{\n"
193:                            + "	allowed = maxlimit - field.value.length;\n"
194:                            + "	window.clipboardData.setData(\"Text\", window.clipboardData.getData(\"Text\").substring(0, allowed));\n"
195:                            + "	event.returnValue = true;\n" + "}\n"
196:                            + "</SCRIPT>";
197:                }
198:
199:                if (_cols > -1) {
200:                    int size = _cols;
201:                    if (getPage().getBrowserType() == HtmlPage.BROWSER_NETSCAPE)
202:                        size = (int) (size * .70);
203:                    tag += " COLS=\"" + size + "\"";
204:                }
205:
206:                if (_rows > -1)
207:                    tag += " rows=\"" + _rows + "\"";
208:
209:                if (_onChange != null)
210:                    tag += " onChange=\"" + _onChange + "\"";
211:
212:                if (_onFocus != null)
213:                    tag += " onFocus=\"" + _onFocus + "\"";
214:
215:                if (_onLoseFocus != null)
216:                    tag += " onBlur=\"" + _onLoseFocus + "\"";
217:
218:                if (_wrap == WRAP_OFF)
219:                    tag += " WRAP=\"OFF\"";
220:                else if (_wrap == WRAP_HARD)
221:                    tag += " WRAP=\"HARD\"";
222:                else
223:                    tag += " WRAP=\"SOFT\"";
224:
225:                if (_class != null)
226:                    tag += " class=\"" + _class + "\"";
227:
228:                if (Util.isFilled(_style))
229:                    tag += " style=\"" + _style + "\"";
230:
231:                tag += ">";
232:
233:                String value = fixSpecialHTMLCharacters(getValue(rowNo, true));
234:
235:                if (value != null)
236:                    tag += value;
237:
238:                tag += "</TEXTAREA>";
239:
240:                if (_fontTagStart != null)
241:                    tag = _fontTagStart + tag + _fontTagEnd;
242:
243:                p.println(tag);
244:                if (lengthFunctions != null)
245:                    p.println(lengthFunctions);
246:
247:                writeFocusScript(p, rowNo);
248:            }
249:
250:            /**
251:             * This method gets the number of columns for the component in characters.
252:             */
253:            public int getColumns() {
254:                return _cols;
255:            }
256:
257:            /**
258:             * This method gets the end font tag for the component.
259:             */
260:            public String getFontEndTag() {
261:                return _fontTagEnd;
262:            }
263:
264:            /**
265:             * This method gets the start font tag for the component.
266:             */
267:            public String getFontStartTag() {
268:                return _fontTagStart;
269:            }
270:
271:            /**
272:             * This method gets the maximum length for the text in the component.
273:             */
274:            public int getMaxLength() {
275:                return _maxLength;
276:            }
277:
278:            /**
279:             * This method gets the readonly attribute of the component.
280:             */
281:            public boolean getReadOnly() {
282:                return _readOnly;
283:            }
284:
285:            /**
286:             * This method gets the javascript to be executed when the value of the text in the component changes.
287:             */
288:            public String getOnChange() {
289:                return _onChange;
290:            }
291:
292:            /**
293:             * This method gets the javascript to be executed when the component gets focus.
294:             */
295:            public String getOnFocus() {
296:                return _onFocus;
297:            }
298:
299:            /**
300:             * This method gets the javascript to be executed when the component loses focus.
301:             */
302:            public String getOnLoseFocus() {
303:                return _onLoseFocus;
304:            }
305:
306:            /**
307:             * This method gets the number of rows for the component.
308:             */
309:            public int getRows() {
310:                return _rows;
311:            }
312:
313:            /**
314:             * This method gets the word wrap property for the component (WRAP_OFF,WRAP_SOFT,WRAP_HARD).
315:             */
316:            public int getWrap() {
317:                return _wrap;
318:            }
319:
320:            public boolean processParms(Hashtable parms, int rowNo)
321:                    throws Exception {
322:                if (!getVisible() || !getEnabled())
323:                    return false;
324:
325:                Object oldValue = _value;
326:
327:                String name = getFullName();
328:                if (rowNo > -1) {
329:                    name += "_" + rowNo;
330:                    if (_dsBuff != null) {
331:                        try {
332:                            oldValue = _dsBuff.getFormattedString(rowNo,
333:                                    _dsColNo);
334:                        } catch (Exception e) {
335:                            oldValue = null;
336:                        }
337:                    }
338:                } else {
339:                    if (_dsBuff != null)
340:                        try {
341:                            oldValue = _dsBuff.getFormattedString(_dsColNo);
342:                        } catch (Exception e) {
343:                            oldValue = null;
344:                        }
345:                }
346:
347:                String val[] = (String[]) parms.get(name);
348:
349:                if (val != null) {
350:                    _value = val[0].trim();
351:                    if (_value.equals(""))
352:                        _value = null;
353:                } else
354:                    _value = null;
355:                convertValue();
356:
357:                if (!valuesEqual(oldValue, _value)) {
358:                    String s = null;
359:                    if (oldValue != null)
360:                        s = oldValue.toString();
361:                    ValueChangedEvent e = new ValueChangedEvent(getPage(),
362:                            this , getName(), getFullName(), s, _value, rowNo,
363:                            _dsColNo, _dsBuff);
364:                    addEvent(e);
365:                }
366:
367:                return false;
368:            }
369:
370:            /**
371:             * This method sets the number of columns for the component in characters.
372:             */
373:            public void setColumns(int size) {
374:                _cols = size;
375:            }
376:
377:            /**
378:             * This method sets the end font tag for the component.
379:             */
380:            public void setFontEndTag(String value) {
381:                _fontTagEnd = value;
382:            }
383:
384:            /**
385:             * This method sets the start font tag for the component.
386:             */
387:            public void setFontStartTag(String value) {
388:                _fontTagStart = value;
389:            }
390:
391:            /**
392:             * This method sets the maximum length for the text in the component.
393:             */
394:            public void setMaxLength(int maxLength) {
395:                _maxLength = maxLength;
396:            }
397:
398:            /**
399:             * This method sets the readonly attribute of the component.
400:             */
401:            public void setReadOnly(boolean readonly) {
402:                _readOnly = readonly;
403:            }
404:
405:            /**
406:             * This method sets the javascript to be executed when the value of the text in the component changes.
407:             */
408:            public void setOnChange(String value) {
409:                _onChange = value;
410:            }
411:
412:            /**
413:             * This method sets the javascript to be executed when the component gains focus.
414:             */
415:            public void setOnFocus(String value) {
416:                _onFocus = value;
417:            }
418:
419:            /**
420:             * This method sets the javascript to be executed when the component loses focus.
421:             */
422:            public void setOnLoseFocus(String value) {
423:                _onLoseFocus = value;
424:            }
425:
426:            /**
427:             * This method sets the number of rows for the component.
428:             */
429:            public void setRows(int rows) {
430:                _rows = rows;
431:            }
432:
433:            /**
434:             * This method sets the property theme for the component.
435:             * @param theme The theme to use.
436:             */
437:            public void setTheme(String theme) {
438:
439:                super .setTheme(theme);
440:                Props props = getPage().getPageProperties();
441:                _fontTagStart = props.getThemeProperty(theme,
442:                        Props.FONT_TEXT_EDIT + Props.TAG_START);
443:                _fontTagEnd = props.getThemeProperty(theme,
444:                        Props.FONT_TEXT_EDIT + Props.TAG_END);
445:            }
446:
447:            /**
448:             * This method sets the word wrap property for the component (WRAP_OFF,WRAP_SOFT,WRAP_HARD)
449:             */
450:            public void setWrap(int wrap) {
451:                _wrap = wrap;
452:            }
453:
454:            /**
455:             * This method sets the word wrap property for the component using the HTML values for the attribute
456:             */
457:            public void setWrap(String wrap) {
458:                int iWrap = WRAP_OFF;
459:                if (wrap != null) {
460:                    wrap = wrap.toUpperCase();
461:                    iWrap = wrap.equals("HARD") ? WRAP_HARD : (wrap
462:                            .equals("SOFT") ? WRAP_SOFT : WRAP_OFF);
463:                }
464:                setWrap(iWrap);
465:            }
466:
467:            /**
468:             * @returns the access key html attribute
469:             */
470:            public String getAccessKey() {
471:                return _accessKey;
472:            }
473:
474:            /**
475:             * @returns the tab index html attribute
476:             */
477:            public int getTabIndex() {
478:                if (_tabIndex == null)
479:                    return -1;
480:                return _tabIndex.intValue();
481:            }
482:
483:            /**
484:             * @param sets the access key html attribute
485:             */
486:            public void setAccessKey(String string) {
487:                _accessKey = string;
488:            }
489:
490:            /**
491:             * @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
492:             */
493:            public void setTabIndex(int val) {
494:                if (val == -1)
495:                    _tabIndex = null;
496:                else
497:                    _tabIndex = new Integer(val);
498:            }
499:
500:            /**
501:             * @return
502:             */
503:            public String getStyle() {
504:                return _style;
505:            }
506:
507:            /**
508:             * @param string
509:             */
510:            public void setStyle(String string) {
511:                _style = string;
512:            }
513:
514:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.