Source Code Cross Referenced for HtmlTabFolder.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/HtmlTabFolder.java $
024:        //$Author: Deepak $
025:        //$Revision: 21 $
026:        //$Modtime: 10/31/03 11:54a $
027:        /////////////////////////
028:        import java.util.*;
029:        import com.salmonllc.properties.*;
030:
031:        /**
032:         * This type implements a navigation bar which resembles a tab folder.  Each tab entry contains a display
033:         * component, typically text, and an HTML link.
034:         */
035:        public class HtmlTabFolder extends HtmlComponent {
036:            class TabInfo {
037:                String _href;
038:                HtmlComponent _item;
039:                String _target;
040:                boolean _active;
041:
042:                TabInfo(HtmlComponent item, String href, String target,
043:                        boolean active) {
044:                    _href = href;
045:                    _item = item;
046:                    _target = target;
047:                    _active = active;
048:                }
049:            };
050:
051:            private Vector _tabItems;
052:            protected String _imagePath;
053:            private String _bgColor, _bgColorActive; // Background colors
054:            private String _tabImageLeft, _tabImageRight;
055:            private String _tabImageBorder;
056:            private String _tabFontStartTag, _tabFontEndTag,
057:                    _tabFontActiveStartTag, _tabFontActiveEndTag;
058:            private int _height;
059:            private boolean _showStripe;
060:            private HtmlStyle _tabStyle;
061:            private String _width = "100%";
062:            String _theme = null;
063:            boolean enabledTab = true;
064:
065:            /**
066:             * Constructs a new HtmlTabFolder to place in the given page.
067:             * @param name java.lang.String
068:             * @param p com.salmonllc.html.HtmlPage
069:             */
070:            public HtmlTabFolder(String name, HtmlPage p) {
071:                this (name, null, p);
072:            }
073:
074:            /**
075:             * Constructs a new HtmlTabFolder to place in the given page.
076:             * @param name java.lang.String
077:             * @param theme The theme to use for loading properties
078:             * @param p com.salmonllc.html.HtmlPage
079:             */
080:            public HtmlTabFolder(String name, String theme, HtmlPage p) {
081:                super (name, p);
082:                // Initialize properties with default values.
083:                _tabItems = new Vector();
084:                _imagePath = "../../Objectstore/Images/";
085:                _tabImageLeft = _imagePath + "TabLeft3D.gif";
086:                _tabImageRight = _imagePath + "TabRight3D.gif";
087:                _tabImageBorder = _imagePath + "999999_1x1.gif"; // a kind of grey
088:                _bgColor = "#000066";
089:                _bgColorActive = "#c9c2a2"; // light beige
090:                _tabFontStartTag = "<FONT FACE=\"Helvetica\" SIZE=\"2\" COLOR=\"ORANGE\"><B>";
091:                _tabFontEndTag = "</B></FONT>";
092:                _tabFontActiveStartTag = "<FONT FACE=\"Helvetica\" SIZE=\"2\" COLOR=\"BLACK\"><B>";
093:                _tabFontActiveEndTag = "</B></FONT>";
094:                _height = 20;
095:                setTheme(theme);
096:            }
097:
098:            /**
099:             * This method adds a tab entry to the folder.
100:             * @param item HtmlComponent The component that will appear in the tab
101:             * @param href java.lang.String The href for the tab link
102:             * @param target java.lang.String Target for the href, optionally null
103:             * @param is_active boolean True if this tab is active (displayed in the active color).
104:             */
105:            public void addTab(HtmlComponent item, String href, String target,
106:                    boolean is_active) {
107:                _tabItems
108:                        .addElement(new TabInfo(item, href, target, is_active));
109:            }
110:
111:            /**
112:             * This method adds a tab entry to the folder.  Text is displayed; target of the href is null; tab is not active.
113:             * @param text Text to display in the tab
114:             * @param href Href to use in the link
115:             */
116:            public void addTab(String text, String href) {
117:                addTab(text, href, null, false);
118:            }
119:
120:            /**
121:             * This method adds a tab to the folder.
122:             * @param text java.lang.String The text that will appear in the tab
123:             * @param href java.lang.String The href for the tab link
124:             * @param target java.lang.String Target for the href, optionally null
125:             * @param is_active boolean True if this tab is active (use active color)
126:             */
127:            public void addTab(String text, String href, String target,
128:                    boolean is_active) {
129:                HtmlText item = new HtmlText(text, getPage());
130:                if (is_active) {
131:                    item.setFontStartTag(_tabFontActiveStartTag);
132:                    item.setFontEndTag(_tabFontActiveEndTag);
133:                } else {
134:                    item.setFontStartTag(_tabFontStartTag);
135:                    item.setFontEndTag(_tabFontEndTag);
136:                }
137:                _tabItems
138:                        .addElement(new TabInfo(item, href, target, is_active));
139:            }
140:
141:            public void generateHTML(java.io.PrintWriter p, int rowNo)
142:                    throws Exception {
143:                if (!getVisible() || (_tabItems.size() == 0))
144:                    return;
145:
146:                p.print("<TABLE cellspacing=0 cellpadding=0 border=0 ");
147:                p.println(" width=" + getWidth() + ">");
148:                p.println("<TR>");
149:                for (int i = 0; i < _tabItems.size(); i++) {
150:                    TabInfo info = (TabInfo) _tabItems.elementAt(i);
151:                    p
152:                            .print("<TD align=middle bgColor=\""
153:                                    + (info._active ? _bgColorActive : _bgColor)
154:                                    + "\"");
155:                    p.print(" vAlign=top>");
156:                    p.print("<IMG align=left height=5 hspace=0 src=\""
157:                            + _tabImageLeft + "\" width=5>");
158:                    p.print("<IMG align=right height=5 hspace=0 src=\""
159:                            + _tabImageRight + "\" width=5>");
160:                    p.print("<IMG height=1 hspace=0 src=\"" + _tabImageBorder
161:                            + "\" width=\"100%\">");
162:                    p.print("<BR clear=all>");
163:                    // We would like to put 100% for the height.  However this only seems to work for table
164:                    // cells other than the first. i..e the browser requires that a specific height be given
165:                    // first.
166:                    p.print("<IMG align=right height=" + _height
167:                            + " hspace=0 src=\"" + _tabImageBorder
168:                            + "\" width=2>");
169:                    if (enabledTab) {
170:                        p.print("<A href=\"" + info._href + "\"");
171:                        if (info._target != null)
172:                            p.print(" target=\"" + info._target + "\"");
173:                        if (_tabStyle != null)
174:                            p.print(" class=\"" + _tabStyle.getStyleName()
175:                                    + "\"");
176:                        p.print(">");
177:                    }
178:                    info._item.generateHTML(p, rowNo);
179:                    p.println("</A></TD>");
180:                }
181:                p.println("</TR>");
182:                if (_showStripe) {
183:                    p.print("<TR><TD colspan=" + _tabItems.size() + " height="
184:                            + (_height + 5));
185:                    p.println(" bgColor=" + _bgColorActive + "></TD></TR>");
186:                }
187:                p.println("</TABLE>");
188:            }
189:
190:            public void setEnabledTab(boolean enabled) {
191:                enabledTab = enabled;
192:            }
193:
194:            /**
195:             * This method returns the href corresponding to active tab, or null if no active tab.
196:             */
197:            public String getActiveHref() {
198:                int i;
199:                int n = _tabItems.size();
200:                for (i = 0; i < n; i++) {
201:                    TabInfo info = (TabInfo) _tabItems.elementAt(i);
202:                    if (info._active)
203:                        return info._href;
204:                }
205:                return null;
206:            }
207:
208:            /**
209:             * This method returns the HTML color value for the active tab background.
210:             */
211:            public String getTabActiveColor() {
212:                return _bgColorActive;
213:            }
214:
215:            /**
216:             * This method returns the name of the image file used to display the tab border.
217:             */
218:            public String getTabBorderImage() {
219:                return _tabImageBorder;
220:            }
221:
222:            /**
223:             * This method returns the HTML color value used for the (non-active) tab background.
224:             * @return java.lang.String
225:             */
226:            public String getTabColor() {
227:                return _bgColor;
228:            }
229:
230:            /**
231:             * This method returns the height in pixels of the tab folder, not counting the optional stripe.
232:             */
233:            public int getTabHeight() {
234:                return _height;
235:            }
236:
237:            /**
238:             * This method returns the name of the image file for the left side of each tab.
239:             * @return java.lang.String
240:             */
241:            public String getTabLeftImage() {
242:                return _tabImageLeft;
243:            }
244:
245:            /**
246:             * This method returns the name of the image file for the right side of each tab.
247:             * @return java.lang.String
248:             */
249:            public String getTabRightImage() {
250:                return _tabImageRight;
251:            }
252:
253:            /**
254:             * This method returns the HTML color value used for the (non-active) tab background.
255:             * @return java.lang.String
256:             */
257:            public HtmlStyle getTabStyle() {
258:                return _tabStyle;
259:            }
260:
261:            /**
262:             * This method returns the property theme for the component.
263:             */
264:            public String getTheme() {
265:                return _theme;
266:            }
267:
268:            /**
269:             * This method sets the tab with the given href to be "active", i.e. displayed using the active display attributes.
270:             * @param href java.lang.String
271:             */
272:            public void setActiveHref(String href) {
273:                int i;
274:                int n = _tabItems.size();
275:                int j;
276:                // Strip trailing parameters from string to compare.
277:                if ((j = href.indexOf('?')) >= 0)
278:                    href = href.substring(0, j);
279:                for (i = 0; i < n; i++) {
280:                    TabInfo info = (TabInfo) _tabItems.elementAt(i);
281:                    HtmlText ht;
282:                    // Strip trailing parameters from string to compare.
283:                    String prefix;
284:                    if ((j = info._href.indexOf('?')) >= 0)
285:                        prefix = info._href.substring(0, j);
286:                    else
287:                        prefix = info._href;
288:                    if (info._active) {
289:                        if (prefix.equals(href))
290:                            // Nothing to do.
291:                            return;
292:                        // Clear active attributes
293:                        info._active = false;
294:                        if (info._item instanceof  HtmlText) {
295:                            ht = (HtmlText) info._item;
296:                            ht.setFontStartTag(_tabFontStartTag);
297:                            ht.setFontEndTag(_tabFontEndTag);
298:                        }
299:                    } else if (prefix.equals(href)) {
300:                        info._active = true;
301:                        if (info._item instanceof  HtmlText) {
302:                            ht = (HtmlText) info._item;
303:                            ht.setFontStartTag(_tabFontActiveStartTag);
304:                            ht.setFontEndTag(_tabFontActiveEndTag);
305:                        }
306:                    }
307:                }
308:            }
309:
310:            /**
311:             * This method sets the HTML color value for the active tab background.
312:             * @param value java.lang.String
313:             */
314:            public void setTabActiveColor(String value) {
315:                _bgColorActive = value;
316:            }
317:
318:            /**
319:             * This method sets the HTML font tags to use for text in the active tab.
320:             * @param tagStart java.lang.String Start font tag
321:             * @param tagEnd java.lang.String End font tag
322:             */
323:            public void setTabActiveFont(String tagStart, String tagEnd) {
324:                _tabFontActiveStartTag = tagStart;
325:                _tabFontActiveEndTag = tagEnd;
326:            }
327:
328:            /**
329:             * This method sets the image file used for tab borders.
330:             * @param image java.lang.String
331:             */
332:            public void setTabBorderImage(String image) {
333:                _tabImageBorder = image;
334:            }
335:
336:            /**
337:             * This method sets the HTML color value for the (non-active) tab background.
338:             * @param value java.lang.String
339:             */
340:            public void setTabColor(String value) {
341:                _bgColor = value;
342:            }
343:
344:            /**
345:             * This method sets the HTML font tags for text in each (non-active) tab.
346:             * @param tagStart java.lang.String Start font tag
347:             * @param tagEnd java.lang.String End font tag
348:             */
349:            public void setTabFont(String tagStart, String tagEnd) {
350:                _tabFontStartTag = tagStart;
351:                _tabFontEndTag = tagEnd;
352:            }
353:
354:            /**
355:             * This method sets the height in pixels of the tab folder, not counting the optional stripe.
356:             * @param height int
357:             */
358:            public void setTabHeight(int height) {
359:                _height = height;
360:            }
361:
362:            /**
363:             * This method sets the image file for the left side of each tab.
364:             * @param image java.lang.String
365:             */
366:            public void setTabLeftImage(String image) {
367:                _tabImageLeft = image;
368:            }
369:
370:            /**
371:             * This method sets the image file for the right side of each tab.
372:             * @param image java.lang.String
373:             */
374:            public void setTabRightImage(String image) {
375:                _tabImageRight = image;
376:            }
377:
378:            /**
379:             * This method sets the HTML color value for the active tab background.
380:             */
381:            public void setTabStyle(String sStyle) {
382:                _tabStyle = new HtmlStyle(getName() + "Style",
383:                        HtmlStyle.ANCHOR_TYPE, sStyle, getPage());
384:                getPage().add(_tabStyle);
385:            }
386:
387:            /**
388:             * This method sets the property theme for the component.
389:             * @param theme The theme to use.
390:             */
391:            public void setTheme(String theme) {
392:                Props props = getPage().getPageProperties();
393:                // Now overload defaults as necessary.
394:                String s;
395:                if ((s = props.getThemeProperty(theme, Props.TAB_COLOR)) != null)
396:                    _bgColor = s;
397:                if ((s = props.getThemeProperty(theme, Props.TAB_ACTIVE_COLOR)) != null)
398:                    _bgColorActive = s;
399:                if ((s = props
400:                        .getThemeProperty(theme, Props.TAB_FONT_START_TAG)) != null)
401:                    _tabFontStartTag = s;
402:                if ((s = props.getThemeProperty(theme, Props.TAB_FONT_END_TAG)) != null)
403:                    _tabFontEndTag = s;
404:                if ((s = props.getThemeProperty(theme,
405:                        Props.TAB_ACTIVE_FONT_START_TAG)) != null)
406:                    _tabFontActiveStartTag = s;
407:                if ((s = props.getThemeProperty(theme,
408:                        Props.TAB_ACTIVE_FONT_END_TAG)) != null)
409:                    _tabFontActiveEndTag = s;
410:                if ((s = props.getThemeProperty(theme, Props.TAB_LEFT_IMAGE)) != null)
411:                    _tabImageLeft = s;
412:                if ((s = props.getThemeProperty(theme, Props.TAB_RIGHT_IMAGE)) != null)
413:                    _tabImageRight = s;
414:                if ((s = props.getThemeProperty(theme, Props.TAB_BORDER_IMAGE)) != null)
415:                    _tabImageBorder = s;
416:                if ((s = props.getThemeProperty(theme, Props.ALL_TAB_WIDTH)) != null)
417:                    _width = s;
418:
419:                int n = props.getThemeIntProperty(theme, Props.TAB_HEIGHT);
420:                if (n != -1)
421:                    _height = n;
422:                // NOTE: we can use getBooleanProperty here because the default for _showStripe is false.
423:                _showStripe = props.getThemeBooleanProperty(theme,
424:                        Props.TAB_SHOW_STRIPE);
425:
426:                _theme = theme;
427:            }
428:
429:            /**
430:             * This method determines whether a horizontal stripe below the tab folder,  in the same color as the active
431:             * background, is displayed.
432:             * @param show boolean
433:             */
434:            public void showStripe(boolean show) {
435:                _showStripe = show;
436:            }
437:
438:            /**
439:             * Set active tab number
440:             * @ author Ian Booth
441:             */
442:            public void setActiveTab(int tabNr) {
443:                int i;
444:                int n = _tabItems.size();
445:                for (i = 0; i < n; i++) {
446:                    TabInfo info = (TabInfo) _tabItems.elementAt(i);
447:                    info._active = i + 1 == tabNr;
448:                    if (info._item instanceof  HtmlText) {
449:                        HtmlText ht = (HtmlText) info._item;
450:                        if (info._active) {
451:                            ht.setFontStartTag(_tabFontActiveStartTag);
452:                            ht.setFontEndTag(_tabFontActiveEndTag);
453:                        } else {
454:                            ht.setFontStartTag(_tabFontStartTag);
455:                            ht.setFontEndTag(_tabFontEndTag);
456:                        }
457:                    }
458:                }
459:            }
460:
461:            /**
462:             * get active tab number
463:             * @ author Ian Booth
464:             */
465:            public int getActiveTab() {
466:                int n = _tabItems.size();
467:                for (int i = 0; i < n; i++) {
468:                    TabInfo info = (TabInfo) _tabItems.elementAt(i);
469:                    if (info._active) {
470:                        return i + 1;
471:                    }
472:                }
473:                return 1;
474:            }
475:
476:            public String getImagePath() {
477:                return _imagePath;
478:            }
479:
480:            public void setImagePath(String _imagePath) {
481:                this ._imagePath = _imagePath;
482:            }
483:
484:            public String getWidth() {
485:                return _width;
486:            }
487:
488:            public void setWidth(String _width) {
489:                this._width = _width;
490:            }
491:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.