Source Code Cross Referenced for HtmlTable.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) 


0001:        //** Copyright Statement ***************************************************
0002:        //The Salmon Open Framework for Internet Applications (SOFIA)
0003:        // Copyright (C) 1999 - 2002, Salmon LLC
0004:        //
0005:        // This program is free software; you can redistribute it and/or
0006:        // modify it under the terms of the GNU General Public License version 2
0007:        // as published by the Free Software Foundation;
0008:        // 
0009:        // This program is distributed in the hope that it will be useful,
0010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012:        // GNU General Public License for more details.
0013:        // 
0014:        // You should have received a copy of the GNU General Public License
0015:        // along with this program; if not, write to the Free Software
0016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0017:        // 
0018:        // For more information please visit http://www.salmonllc.com
0019:        //** End Copyright Statement ***************************************************
0020:        package com.salmonllc.html;
0021:
0022:        /////////////////////////
0023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlTable.java $
0024:        //$Author: Dan $
0025:        //$Revision: 47 $
0026:        //$Modtime: 4/13/04 9:52a $
0027:        /////////////////////////
0028:
0029:        import com.salmonllc.properties.Props;
0030:        import com.salmonllc.util.MessageLog;
0031:        import com.salmonllc.util.TwoObjectContainer;
0032:        import com.salmonllc.util.Vector2D;
0033:
0034:        import java.util.Enumeration;
0035:        import java.util.Hashtable;
0036:        import java.util.Vector;
0037:
0038:        /**
0039:         * This component will generate an HTML table. It serves as a container and layout manager for other components.
0040:         */
0041:
0042:        public class HtmlTable extends HtmlContainer {
0043:            public static final int SIZE_PERCENT = 0;
0044:            public static final int SIZE_PIXELS = 1;
0045:
0046:            public static final String ALIGN_LEFT = "LEFT";
0047:            public static final String ALIGN_CENTER = "CENTER";
0048:            public static final String ALIGN_RIGHT = "RIGHT";
0049:            public static final String ALIGN_NONE = "";
0050:
0051:            public static final String VALIGN_BASELINE = "BASELINE";
0052:            public static final String VALIGN_BOTTOM = "BOTTOM";
0053:            public static final String VALIGN_MIDDLE = "MIDDLE";
0054:            public static final String VALIGN_TOP = "TOP";
0055:            public static final String VALIGN_NONE = "";
0056:
0057:            private int _sizeOption = SIZE_PERCENT;
0058:            private int _containerWidth = -1;
0059:            private int _containerHeight = -1;
0060:
0061:            private Vector2D _componentsVec2D = new Vector2D();
0062:            private Vector _columnWidth = new Vector();
0063:
0064:            private Vector _columnHeight = new Vector();
0065:
0066:            private Vector _rowProps;
0067:            private boolean _allowNullCells = true;
0068:            private String _align;
0069:            private int _border = -1;
0070:            private String _bgColor = "";
0071:            private int _cellPadding = -1;
0072:            private int _cellSpacing = -1;
0073:            private String _theme;
0074:            private boolean _correctColSpan = true;
0075:            private String _defaultRowStyleClassName;
0076:
0077:            // for addDisplay
0078:            private Hashtable _compLookUpHash = new Hashtable();
0079:            private int _currColVal = 0;
0080:            private int _currRowVal = -1;
0081:            private final static String CAPTION_COMP_HASH_KEY = "Caption_comp_";
0082:            private final static String SEARCH_COMP_HASH_KEY = "Search_comp_";
0083:
0084:            /**
0085:             * Constructs a new HTMLTable.
0086:             * @param name Each component on a page must have a unique name.
0087:             * @param p The page that the table will be added to.
0088:             */
0089:            public HtmlTable(String name, HtmlPage p) {
0090:                this (name, null, p);
0091:            }
0092:
0093:            /**
0094:             * Constructs a new HTMLTable.
0095:             * @param name Each component on a page must have a unique name.
0096:             * @param theme The theme to use for loading properties
0097:             * @param p The page that the table will be added to.
0098:             */
0099:            public HtmlTable(String name, String theme, HtmlPage p) {
0100:                super (name, p);
0101:                setTheme(theme);
0102:            }
0103:
0104:            /**
0105:             * This method should not be used in this type of container. Instead use setComponentAt().
0106:             */
0107:            public void add(HtmlComponent comp) {
0108:                return;
0109:            }
0110:
0111:            public boolean executeEvent(int eventType) throws Exception {
0112:                if (eventType == HtmlComponent.EVENT_OTHER) {
0113:                    // sr 10-15-2000
0114:                    int rowCount = _componentsVec2D.getRowCount();
0115:                    int colCount = _componentsVec2D.getColumnCount();
0116:                    Object o = null;
0117:                    HtmlComponent h = null;
0118:                    //
0119:                    for (int i = 0; i < rowCount; i++) {
0120:                        for (int j = 0; j < colCount; j++) {
0121:                            o = _componentsVec2D.elementAt(i, j);
0122:                            if (o != null) {
0123:                                if (o instanceof  TwoObjectContainer) {
0124:                                    h = (HtmlComponent) ((TwoObjectContainer) o)
0125:                                            .getObject1();
0126:                                } else {
0127:                                    h = (HtmlComponent) o;
0128:                                }
0129:                                if (h != null) {
0130:                                    if (!h.executeEvent(eventType)) {
0131:                                        return false;
0132:                                    }
0133:                                } else {
0134:                                    return true;
0135:                                }
0136:                            }
0137:                        }
0138:                    }
0139:                } else if (_submit != null
0140:                        && eventType == HtmlComponent.EVENT_SUBMIT) {
0141:                    boolean retVal = _submit.executeEvent(eventType);
0142:                    _submit = null;
0143:                    return retVal;
0144:                }
0145:                return true;
0146:            }
0147:
0148:            public void generateHTML(java.io.PrintWriter p, int rowNo)
0149:                    throws Exception {
0150:                if (!getVisible())
0151:                    return;
0152:                if (_center)
0153:                    p.print("<CENTER>");
0154:                String tableHeading = "<TABLE";
0155:                if (_containerWidth > -1) {
0156:                    tableHeading += " WIDTH=\"" + _containerWidth;
0157:                    if (_sizeOption == SIZE_PERCENT) {
0158:                        tableHeading += "%";
0159:                    }
0160:                    tableHeading += "\"";
0161:                }
0162:                if (_containerHeight > -1)
0163:                    tableHeading += " HEIGHT=\"" + _containerHeight + "\"";
0164:                if (_border > -1)
0165:                    tableHeading += " BORDER=\"" + _border + "\"";
0166:                if (_bgColor != null) {
0167:                    if (!_bgColor.equals("")) {
0168:                        tableHeading += " BGCOLOR=\"" + _bgColor + "\"";
0169:                    }
0170:                }
0171:                if (_cellPadding > -1)
0172:                    tableHeading += " CELLPADDING=\"" + _cellPadding + "\"";
0173:                if (_cellSpacing > -1)
0174:                    tableHeading += " CELLSPACING=\"" + _cellSpacing + "\"";
0175:                if (_align != null) {
0176:                    if (_align.equals(ALIGN_LEFT) || _align.equals(ALIGN_RIGHT)
0177:                            || _align.equals(ALIGN_CENTER))
0178:                        tableHeading += " align=\"" + _align + "\"";
0179:                }
0180:                tableHeading += ">";
0181:                p.println(tableHeading);
0182:                StringBuffer td = new StringBuffer();
0183:                StringBuffer tr = new StringBuffer();
0184:                HtmlTableRowProperties rowProps = null;
0185:                // sr 10-15-2000
0186:                int rowCount = _componentsVec2D.getRowCount();
0187:                int colCount = _componentsVec2D.getColumnCount();
0188:                Object o = null;
0189:                HtmlComponent comp = null;
0190:                HtmlTableCellProperties props = null;
0191:                TwoObjectContainer cont = null;
0192:                //
0193:                for (int i = 0; i < rowCount; i++) {
0194:                    tr.setLength(0);
0195:                    rowProps = getRowProperty(i);
0196:                    if (rowProps != null) {
0197:                        if (!rowProps.getVisible())
0198:                            continue;
0199:                        tr.append("\t<TR");
0200:                        if (rowProps.getAlign() != null)
0201:                            if (!rowProps.getAlign().equals(ALIGN_NONE))
0202:                                tr.append(" ALIGN=\"" + rowProps.getAlign()
0203:                                        + "\"");
0204:                        if (rowProps.getBackgroundColor() != null)
0205:                            if (!rowProps.getBackgroundColor().equals(""))
0206:                                tr.append(" BGCOLOR=\""
0207:                                        + rowProps.getBackgroundColor() + "\"");
0208:                        String rowClass = _defaultRowStyleClassName;
0209:                        if (rowProps.getRowClass() != null)
0210:                            if (!rowProps.getRowClass().equals(""))
0211:                                rowClass = rowProps.getRowClass();
0212:                        if (rowClass != null)
0213:                            tr.append(" CLASS=\"" + rowClass + "\"");
0214:                        if (!rowProps.getWrapStyle())
0215:                            tr.append(" NOWRAPSTYLE");
0216:                        tr.append(">");
0217:                    } else {
0218:
0219:                        tr.append("<TR");
0220:                        if (_defaultRowStyleClassName != null) {
0221:                            tr.append(" CLASS=\"");
0222:                            tr.append(_defaultRowStyleClassName);
0223:                            tr.append("\"");
0224:                        }
0225:                        tr.append(">");
0226:                    }
0227:
0228:                    //		p.println("<TR>");
0229:                    p.println(tr.toString());
0230:                    for (int j = 0; j < colCount; j++) {
0231:                        td.setLength(0);
0232:                        if (_allowNullCells) {
0233:                            td.append("\t\t<TD");
0234:                        }
0235:                        o = _componentsVec2D.elementAt(i, j);
0236:                        // clear values out
0237:                        comp = null;
0238:                        props = null;
0239:                        //
0240:                        if (o != null) {
0241:                            if (!_allowNullCells) {
0242:                                td.append("\t\t<TD");
0243:                            }
0244:                            if (o instanceof  HtmlComponent)
0245:                                comp = (HtmlComponent) o;
0246:                            else {
0247:                                cont = (TwoObjectContainer) o;
0248:                                comp = (HtmlComponent) cont.getObject1();
0249:                                props = (HtmlTableCellProperties) cont
0250:                                        .getObject2();
0251:                            }
0252:                        } else {
0253:                            if (!_allowNullCells) {
0254:                                continue;
0255:                            }
0256:                        }
0257:                        if (props != null) {
0258:                            if (props.getAlign() != null)
0259:                                if (!props.getAlign().equals(ALIGN_NONE))
0260:                                    td.append(" ALIGN=\"" + props.getAlign()
0261:                                            + "\"");
0262:                            if (props.getVertAlign() != null)
0263:                                if (!props.getVertAlign().equals(VALIGN_NONE))
0264:                                    td.append(" VALIGN=\""
0265:                                            + props.getVertAlign() + "\"");
0266:                            if (props.getBackgroundColor() != null)
0267:                                if (!props.getBackgroundColor().equals(""))
0268:                                    td
0269:                                            .append(" BGCOLOR=\""
0270:                                                    + props
0271:                                                            .getBackgroundColor()
0272:                                                    + "\"");
0273:                            if (props.getColumnSpan() != 1) {
0274:                                td.append(" COLSPAN=\"" + props.getColumnSpan()
0275:                                        + "\"");
0276:                                // BUG:
0277:                                // The code that follows increments j one too many because of
0278:                                // the j++ in the continuation of the loop.  The fix is
0279:                                //	j += props.getColumnSpan() - 1;
0280:                                // To avoid destabilization the bug is temporarily left in place.
0281:                                // Added 11/22/00: option to correct bug based on boolean flag
0282:                                if (_correctColSpan)
0283:                                    j += props.getColumnSpan() - 1;
0284:                                else
0285:                                    j += props.getColumnSpan();
0286:                            }
0287:                            if (props.getRowSpan() != 1) {
0288:                                td.append(" ROWSPAN=\"" + props.getRowSpan()
0289:                                        + "\"");
0290:                            }
0291:                            if (props.getCellHeight() != -1) {
0292:                                td.append(" HEIGHT=\"" + props.getCellHeight());
0293:                                // get column size option
0294:                                if (props.getCellHeightSizeOption() == SIZE_PERCENT)
0295:                                    td.append("%");
0296:                                td.append("\"");
0297:                            }
0298:                            if (props.getOnClick() != null)
0299:                                td.append(" ONCLICK=\"" + props.getOnClick()
0300:                                        + "\"");
0301:                            if (props.getOnMouseDown() != null)
0302:                                td.append(" ONMOUSEDOWN=\""
0303:                                        + props.getOnMouseDown() + "\"");
0304:                            if (props.getOnMouseOver() != null)
0305:                                td.append(" ONMOUSEOVER=\""
0306:                                        + props.getOnMouseOver() + "\"");
0307:                            if (props.getOnMouseOut() != null)
0308:                                td.append(" ONMOUSEOUT=\""
0309:                                        + props.getOnMouseOut() + "\"");
0310:                            if (props.getOnMouseUp() != null)
0311:                                td.append(" ONMOUSEUP=\""
0312:                                        + props.getOnMouseUp() + "\"");
0313:                            if (props.getStyle() != null
0314:                                    && props.getStyle().getStyleName() != null
0315:                                    && !props.getStyle().getStyleName().trim()
0316:                                            .equals("")) {
0317:                                td.append(" CLASS=\""
0318:                                        + props.getStyle().getStyleName()
0319:                                        + "\"");
0320:                            }
0321:                            if (props.getCellWidth() != -1) {
0322:                                td.append(" WIDTH=\"" + props.getCellWidth());
0323:                                // get column size option
0324:                                if (props.getCellWidthSizeOption() == SIZE_PERCENT)
0325:                                    td.append("%");
0326:                                td.append("\"");
0327:                            }
0328:                            if (!props.getWrap())
0329:                                td.append(" NOWRAP");
0330:                        }
0331:
0332:                        // column width
0333:                        int width = getColumnWidth(j);
0334:                        if (width > 0) {
0335:                            td.append(" WIDTH=\"" + width);
0336:                            // get size option
0337:                            if (_sizeOption == SIZE_PERCENT)
0338:                                td.append("%");
0339:                            td.append("\"");
0340:                        }
0341:                        // column height
0342:                        int height = getColumnHeight(j);
0343:                        if (height > 0) {
0344:                            td.append(" HEIGHT=\"" + height);
0345:                            // get size option
0346:                            if (_sizeOption == SIZE_PERCENT)
0347:                                td.append("%");
0348:                            td.append("\"");
0349:                        }
0350:                        td.append('>');
0351:                        p.println(td.toString());
0352:                        if (comp != null)
0353:                            comp.generateHTML(p, rowNo);
0354:                        //			else
0355:                        //	p.println("&nbsp;");
0356:                        p.println("</TD>");
0357:                    }
0358:                    p.println("</TR>");
0359:                }
0360:                p.print("</TABLE>");
0361:                if (_center)
0362:                    p.print("</CENTER>");
0363:                p.println("");
0364:            }
0365:
0366:            public void generateInitialHTML(java.io.PrintWriter p)
0367:                    throws Exception {
0368:                if (!getVisible())
0369:                    return;
0370:
0371:                // sr 10-15-2000
0372:                int rowCount = _componentsVec2D.getRowCount();
0373:                int colCount = _componentsVec2D.getColumnCount();
0374:                Object o = null;
0375:                HtmlComponent comp = null;
0376:                TwoObjectContainer cont = null;
0377:                //
0378:                for (int i = 0; i < rowCount; i++) {
0379:                    for (int j = 0; j < colCount; j++) {
0380:                        o = _componentsVec2D.elementAt(i, j);
0381:                        // clear values
0382:                        comp = null;
0383:                        if (o != null) {
0384:                            if (o instanceof  HtmlComponent)
0385:                                comp = (HtmlComponent) o;
0386:                            else {
0387:                                cont = (TwoObjectContainer) o;
0388:                                comp = (HtmlComponent) cont.getObject1();
0389:                            }
0390:                        }
0391:                        if (comp != null)
0392:                            comp.generateInitialHTML(p);
0393:                    }
0394:                }
0395:            }
0396:
0397:            /**
0398:             * Returns the alignment property for the table.
0399:             * @return align Valid values are ALIGN_LEFT,ALIGN_CENTER,ALIGN_RIGHT and ALIGN_NONE.
0400:             */
0401:            public String getAlign() {
0402:                return _align;
0403:            }
0404:
0405:            /**
0406:             * Gets the background color for the table.
0407:             */
0408:            public String getBackgroundColor() {
0409:                return _bgColor;
0410:            }
0411:
0412:            /**
0413:             * Gets the border thickness for the table.
0414:             */
0415:            public int getBorder() {
0416:                return _border;
0417:            }
0418:
0419:            /**
0420:             * Gets the cell padding for the table.
0421:             */
0422:            public int getCellPadding() {
0423:                return _cellPadding;
0424:            }
0425:
0426:            /**
0427:             * Gets the cell spacing for the table.
0428:             */
0429:            public int getCellSpacing() {
0430:                return _cellSpacing;
0431:            }
0432:
0433:            /**
0434:             * This method gets the minimum width for a particular column in the table or -1 if the column width has not been set
0435:             */
0436:            public int getColumnHeight(int column) {
0437:                if (column < 0)
0438:                    return -1;
0439:
0440:                if (column >= _columnHeight.size())
0441:                    return -1;
0442:
0443:                Object o = _columnHeight.elementAt(column);
0444:
0445:                if (o == null)
0446:                    return -1;
0447:
0448:                return ((Integer) o).intValue();
0449:            }
0450:
0451:            /**
0452:             * This method gets the minimum width for a particular column in the table or -1 if the column width has not been set
0453:             */
0454:            public int getColumnWidth(int column) {
0455:                if (column < 0)
0456:                    return -1;
0457:
0458:                if (column >= _columnWidth.size())
0459:                    return -1;
0460:
0461:                Object o = _columnWidth.elementAt(column);
0462:
0463:                if (o == null)
0464:                    return -1;
0465:
0466:                return ((Integer) o).intValue();
0467:            }
0468:
0469:            /**
0470:             * This method will return a list of all components in the container.
0471:             */
0472:            public Enumeration getComponents() {
0473:                Vector comps = new Vector();
0474:                //
0475:
0476:                int rowCount = _componentsVec2D.getRowCount();
0477:                int colCount = _componentsVec2D.getColumnCount();
0478:                Object o = null;
0479:                HtmlComponent h = null;
0480:                //
0481:                for (int i = 0; i < rowCount; i++) {
0482:                    for (int j = 0; j < colCount; j++) {
0483:                        o = _componentsVec2D.elementAt(i, j);
0484:                        if (o != null) {
0485:                            if (o instanceof  TwoObjectContainer)
0486:                                h = (HtmlComponent) ((TwoObjectContainer) o)
0487:                                        .getObject1();
0488:                            else
0489:                                h = (HtmlComponent) o;
0490:                            comps.addElement(h);
0491:                        }
0492:                    }
0493:                }
0494:                return comps.elements();
0495:            }
0496:
0497:            /**
0498:             * This method will return a single component if the
0499:             * name or a portion of the name is found in this HtmlContainer or any
0500:             * HtmlContainer contained in this container.
0501:             * @return HtmlComponent - if a component can not be found null is returned
0502:             * @param name - name of component being searched for
0503:             */
0504:            public HtmlComponent getComponent(String name) {
0505:		HtmlComponent ret = null;
0506:		HtmlComponent comp = null;
0507:		Enumeration enum = getComponents();
0508:		String compName = null;
0509:		// we will search all items in this enumeration
0510:		// recursivly calling the containers getComponent method
0511:		boolean breakout = enum.hasMoreElements();
0512:		while (breakout && enum.hasMoreElements()) {
0513:			ret = null;
0514:
0515:			comp = (HtmlComponent) enum.nextElement();
0516:			compName = comp.getName();
0517:
0518:			// if passed name or comparision name is null return earily because we can not go any further.
0519:			if (compName == null || name == null) {
0520:				MessageLog.writeInfoMessage("getComponent\n\t*** Looking for component named " + name + " but " + getFullName() + " contains a component with a null name. \nSolution may be to pass empty string instead of null. ***", 9, this );
0521:				return ret;
0522:			}
0523:
0524:			if (compName.indexOf(name) > -1) {
0525:				ret = comp;
0526:				breakout = false;
0527:			} else {
0528:				if (comp instanceof  HtmlTable) {
0529:					ret = ((HtmlTable) comp).getComponent(name);
0530:					// checking the value of the return value
0531:					breakout = (ret == null);
0532:				} else if (comp instanceof  HtmlContainer) {
0533:					ret = ((HtmlContainer) comp).getComponent(name);
0534:					// checking the value of the return value
0535:					breakout = (ret == null);
0536:				}
0537:			}
0538:		}
0539:
0540:		return ret;
0541:	}
0542:
0543:            /**
0544:             * This method gets the minimum height of the table in pixels.
0545:             */
0546:            public int getHeight() {
0547:                return _containerHeight;
0548:            }
0549:
0550:            /**
0551:             * Returns the number of rows currently in the table.
0552:             * @return int
0553:             */
0554:            public int getRowCount() {
0555:                return _componentsVec2D.getRowCount();
0556:            }
0557:
0558:            /**
0559:             * This method was created in VisualAge.
0560:             * @return com.salmonllc.html.HtmlTableRowProperties
0561:             * @param propertyRow int
0562:             */
0563:            public HtmlTableRowProperties getRowProperty(int propertyRow) {
0564:                if (_rowProps != null && propertyRow < _rowProps.size())
0565:                    return (HtmlTableRowProperties) _rowProps
0566:                            .elementAt(propertyRow);
0567:                else
0568:                    return null;
0569:            }
0570:
0571:            /**
0572:             * This method returns the size option for the table and each cell in it. Valid return values are SIZE_PIXELS or SIZE_PERCENT.
0573:             */
0574:            public int getSizeOption() {
0575:                return _sizeOption;
0576:            }
0577:
0578:            /**
0579:             * This method returns the property theme for the component.
0580:             */
0581:            public String getTheme() {
0582:                return _theme;
0583:            }
0584:
0585:            /**
0586:             * This method returns the width of the table.
0587:             */
0588:            public int getWidth() {
0589:                return _containerWidth;
0590:            }
0591:
0592:            /**
0593:             * Inserts an entire row before the specified one.
0594:             */
0595:            public void insertRow(int row) {
0596:                _componentsVec2D.insertRow(row);
0597:            }
0598:
0599:            public boolean processParms(Hashtable parms, int rowNo)
0600:                    throws Exception {
0601:                if (!getVisible())
0602:                    return false;
0603:                boolean retVal = false;
0604:                //
0605:
0606:                int rowCount = _componentsVec2D.getRowCount();
0607:                int colCount = _componentsVec2D.getColumnCount();
0608:                Object o = null;
0609:                HtmlComponent h = null;
0610:                //
0611:                for (int i = 0; i < rowCount; i++) {
0612:                    for (int j = 0; j < colCount; j++) {
0613:                        o = _componentsVec2D.elementAt(i, j);
0614:                        if (o != null) {
0615:                            if (o instanceof  TwoObjectContainer) {
0616:                                h = (HtmlComponent) ((TwoObjectContainer) o)
0617:                                        .getObject1();
0618:                            } else {
0619:                                h = (HtmlComponent) o;
0620:                            }
0621:
0622:                            // if you have a TwoObjectContainer with a null (HtmlComponent)Object1
0623:                            // then you have to check for null before you processParams
0624:                            if (h != null) {
0625:                                if (h.processParms(parms, rowNo)) {
0626:                                    _submit = h;
0627:                                    retVal = true;
0628:                                }
0629:                            }
0630:                        }
0631:                    }
0632:                }
0633:                return retVal;
0634:            }
0635:
0636:            /**
0637:             * Removes an html component from this container.
0638:             * @param comp The component to remove
0639:             */
0640:            public void remove(HtmlComponent comp) {
0641:                //
0642:
0643:                int rowCount = _componentsVec2D.getRowCount();
0644:                int colCount = _componentsVec2D.getColumnCount();
0645:                Object o = null;
0646:                HtmlComponent h = null;
0647:                //
0648:                for (int i = 0; i < rowCount; i++) {
0649:                    for (int j = 0; j < colCount; j++) {
0650:                        o = _componentsVec2D.elementAt(i, j);
0651:                        if (o != null) {
0652:                            if (o instanceof  TwoObjectContainer)
0653:                                h = (HtmlComponent) ((TwoObjectContainer) o)
0654:                                        .getObject1();
0655:                            else
0656:                                h = (HtmlComponent) o;
0657:                            if (h == comp) {
0658:                                _componentsVec2D.setElementAt(i, j, null);
0659:                                return;
0660:                            }
0661:                        }
0662:                    }
0663:                }
0664:            }
0665:
0666:            /**
0667:             * Removes an entire row from this container.
0668:             * @param row The row to remove
0669:             */
0670:            public void removeRow(int row) {
0671:                if (row < _componentsVec2D.getRowCount()) {
0672:                    _componentsVec2D.removeRow(row);
0673:                }
0674:            }
0675:
0676:            /**
0677:             * Sets the alignment property for the table.
0678:             * @param align Valid values are ALIGN_LEFT,ALIGN_CENTER,ALIGN_RIGHT and ALIGN_NONE.
0679:             */
0680:
0681:            public void setAlign(String align) {
0682:                _align = align;
0683:            }
0684:
0685:            /**
0686:             * Sets the border width for the table.
0687:             */
0688:            public void setAllowNullCells(boolean value) {
0689:                _allowNullCells = value;
0690:            }
0691:
0692:            /**
0693:             * Sets the background color for the table.
0694:             */
0695:            public void setBackgroundColor(String value) {
0696:                _bgColor = value;
0697:            }
0698:
0699:            /**
0700:             * Sets the border width for the table.
0701:             */
0702:            public void setBorder(int border) {
0703:                _border = border;
0704:            }
0705:
0706:            /**
0707:             * Sets the cell padding for the table.
0708:             */
0709:            public void setCellPadding(int value) {
0710:                _cellPadding = value;
0711:            }
0712:
0713:            /**
0714:             * Sets the cell spacing for the table.
0715:             */
0716:            public void setCellSpacing(int value) {
0717:                _cellSpacing = value;
0718:            }
0719:
0720:            /**
0721:             * Sets the column width for a particular column in the table.
0722:             */
0723:            public void setColumnWidth(int column, int width) {
0724:                if (column < 0)
0725:                    return;
0726:
0727:                if (column >= _columnWidth.size())
0728:                    _columnWidth.setSize(column + 1);
0729:
0730:                _columnWidth.setElementAt(new Integer(width), column);
0731:            }
0732:
0733:            /**
0734:             * Sets a component at a particular row column position in the table. The cell in the table will use the browsers default cell properties.
0735:             */
0736:            public void setComponentAt(int row, int column, HtmlComponent comp) {
0737:                if (column < 0)
0738:                    return;
0739:                if (row < 0)
0740:                    return;
0741:                if (column >= _componentsVec2D.getColumnCount())
0742:                    _componentsVec2D.addColumns((column - _componentsVec2D
0743:                            .getColumnCount()) + 1);
0744:                if (row >= _componentsVec2D.getRowCount())
0745:                    _componentsVec2D.addRows((row - _componentsVec2D
0746:                            .getRowCount()) + 1);
0747:                _componentsVec2D.setElementAt(row, column, comp);
0748:                if (comp != null) {
0749:                    comp.setParent(this );
0750:                }
0751:            }
0752:
0753:            /**
0754:             * Sets a component at a particular row column position in the table. The cell in the table will use properties specified in the props argument.
0755:             */
0756:            public void setComponentAt(int row, int column, HtmlComponent comp,
0757:                    HtmlTableCellProperties props) {
0758:                if (column < 0)
0759:                    return;
0760:                if (row < 0)
0761:                    return;
0762:                if (column >= _componentsVec2D.getColumnCount())
0763:                    _componentsVec2D.addColumns((column - _componentsVec2D
0764:                            .getColumnCount()) + 1);
0765:                if (row >= _componentsVec2D.getRowCount())
0766:                    _componentsVec2D.addRows((row - _componentsVec2D
0767:                            .getRowCount()) + 1);
0768:                TwoObjectContainer cont = new TwoObjectContainer(comp, props);
0769:                _componentsVec2D.setElementAt(row, column, cont);
0770:                if (comp != null) {
0771:                    comp.setParent(this );
0772:                }
0773:            }
0774:
0775:            /**
0776:             * Sets a 2D array  of components in the table. The cells in the table will use the browsers default cell properties.
0777:             * The routine works left to right, top to bottom.
0778:             * ex. comp[row][col]
0779:             */
0780:            public void setComponents(HtmlComponent comp[][]) {
0781:                int rows = comp.length;
0782:                int cols = 0;
0783:                // get the max number of cols in any row
0784:                for (int rowIndex = 0; rowIndex < comp.length; rowIndex++) {
0785:                    if (comp[rowIndex].length > cols) {
0786:                        cols = comp[rowIndex].length;
0787:                    }
0788:                }
0789:
0790:                // make sure that there are enough columns.
0791:                if (cols >= _componentsVec2D.getColumnCount())
0792:                    _componentsVec2D.addColumns((cols - _componentsVec2D
0793:                            .getColumnCount()));
0794:                // make sure that there are enough rows.
0795:                if (rows >= _componentsVec2D.getRowCount())
0796:                    _componentsVec2D.addRows((rows - _componentsVec2D
0797:                            .getRowCount()));
0798:                //
0799:                for (int rowIndex = 0; rowIndex < comp.length; rowIndex++) {
0800:                    for (int colIndex = 0; colIndex < comp[rowIndex].length; colIndex++) {
0801:                        _componentsVec2D.setElementAt(rowIndex, colIndex,
0802:                                comp[rowIndex][colIndex]);
0803:                        // This is to set the parent container of each item added.
0804:                        if (comp[rowIndex][colIndex] != null) {
0805:                            comp[rowIndex][colIndex].setParent(this );
0806:                        }
0807:                    }
0808:                }
0809:            }
0810:
0811:            /**
0812:             * Sets a 2D array  of components in the table. The cells in the table will use the cell properties from the 2D HtmlTableCellProperties array.
0813:             * The routine works left to right, top to bottom.
0814:             * ex. comp[row][col]
0815:             */
0816:            public void setComponents(HtmlComponent comp[][],
0817:                    HtmlTableCellProperties props[][]) {
0818:                int rows = comp.length;
0819:                int cols = 0;
0820:                // get the max number of cols in any row
0821:                for (int rowIndex = 0; rowIndex < comp.length; rowIndex++) {
0822:                    if (comp[rowIndex].length > cols) {
0823:                        cols = comp[rowIndex].length;
0824:                    }
0825:                }
0826:
0827:                // make sure that there are enough columns.
0828:                if (cols >= _componentsVec2D.getColumnCount())
0829:                    _componentsVec2D.addColumns((cols - _componentsVec2D
0830:                            .getColumnCount()));
0831:                // make sure that there are enough rows.
0832:                if (rows >= _componentsVec2D.getRowCount())
0833:                    _componentsVec2D.addRows((rows - _componentsVec2D
0834:                            .getRowCount()));
0835:                //
0836:                for (int rowIndex = 0; rowIndex < comp.length; rowIndex++) {
0837:                    for (int colIndex = 0; colIndex < comp[rowIndex].length; colIndex++) {
0838:                        TwoObjectContainer cont = new TwoObjectContainer(
0839:                                comp[rowIndex][colIndex],
0840:                                props[rowIndex][colIndex]);
0841:                        _componentsVec2D.setElementAt(rowIndex, colIndex, cont);
0842:                        // This is to set the parent container of each item added.
0843:                        if (comp[rowIndex][colIndex] != null) {
0844:                            comp[rowIndex][colIndex].setParent(this );
0845:                        }
0846:                    }
0847:                }
0848:            }
0849:
0850:            /**
0851:             * This method sets a flag indicating whether the bug related
0852:             * to COLSPAN has been fixed.
0853:             */
0854:            public void setCorrectColSpan(boolean correctColSpan) {
0855:                _correctColSpan = correctColSpan;
0856:            }
0857:
0858:            /**
0859:             * This method sets the minimum height of the table in pixels.
0860:             */
0861:            public void setHeight(int height) {
0862:                _containerHeight = height;
0863:            }
0864:
0865:            /**
0866:             * This method was created in VisualAge.
0867:             * @param row int
0868:             * @param rowProp com.salmonllc.html.HtmlTableRowProperties
0869:             */
0870:            public void setRowProperty(int row, HtmlTableRowProperties rowProp) {
0871:                if (_rowProps == null)
0872:                    _rowProps = new Vector();
0873:                int size = _rowProps.size();
0874:                for (int i = size; i <= row; i++)
0875:                    _rowProps.addElement(null);
0876:
0877:                _rowProps.setElementAt(rowProp, row);
0878:            }
0879:
0880:            /**
0881:             * This method sets the size option for the table and each cell in it. Valid return values are SIZE_PIXELS or SIZE_PERCENT.
0882:             * @param option
0883:             */
0884:            public void setSizeOption(int option) {
0885:                _sizeOption = option;
0886:            }
0887:
0888:            /**
0889:             * This method sets the property theme for the component.
0890:             * @param theme The theme to use.
0891:             */
0892:            public void setTheme(String theme) {
0893:                Props prop = getPage().getPageProperties();
0894:
0895:                _border = prop.getThemeIntProperty(theme, Props.TABLE_BORDER);
0896:                _bgColor = prop.getThemeProperty(theme,
0897:                        Props.TABLE_BACKGROUND_COLOR);
0898:                _cellPadding = prop.getThemeIntProperty(theme,
0899:                        Props.TABLE_CELLPADDING);
0900:                _cellSpacing = prop.getThemeIntProperty(theme,
0901:                        Props.TABLE_CELLSPACING);
0902:
0903:                _theme = theme;
0904:            }
0905:
0906:            /**
0907:             * This method sets the minimum width of the table in either pixels or percent depending on size option.
0908:             * @param width
0909:             */
0910:            public void setWidth(int width) {
0911:                _containerWidth = width;
0912:            }
0913:
0914:            /**
0915:             * Adds a component to the table a makes a caption comp.
0916:             *
0917:             * @param name		Name to associate internally with the search component.
0918:             * @param caption	Text of caption to put before the search component, or null.
0919:             * @param component	The search component.
0920:             */
0921:            public void addDisplay(String name, String caption,
0922:                    HtmlComponent component) throws Exception {
0923:
0924:                addDisplay(name, caption, component, false);
0925:            }
0926:
0927:            /**
0928:             * Adds a component to the table a makes a caption comp.
0929:             *
0930:             * @param name		Name to associate internally with the search component.
0931:             * @param caption	Text of caption to put before the search component, or null.
0932:             * @param component	The search component.
0933:             * @param sameRow	boolean specifies whether you want the next component on the same row.
0934:             */
0935:            public void addDisplay(String name, String caption,
0936:                    HtmlComponent component, boolean sameRow) throws Exception {
0937:
0938:                addDisplay(name, caption, component, sameRow, null, null);
0939:
0940:            }
0941:
0942:            /**
0943:             * Adds a component to the table a makes a caption comp.
0944:             *
0945:             * @param name		Name to associate internally with the search component.
0946:             * @param caption	Text of caption to put before the search component, or null.
0947:             * @param component	The search component.
0948:             * @param sameRow	boolean specifies whether you want the next component on the same row.
0949:             * @param propCaption	Table properties for caption, or null.
0950:             * @param propSearch	Table properties for search component, or null.
0951:             */
0952:            public void addDisplay(String name, String caption,
0953:                    HtmlComponent component, boolean sameRow,
0954:                    HtmlTableCellProperties propCaption,
0955:                    HtmlTableCellProperties propSearch) throws Exception {
0956:
0957:                if (sameRow == false || (_currRowVal == -1)) {
0958:                    _currRowVal++;
0959:                    _currColVal = -1;
0960:                }
0961:
0962:                if (name == null) {
0963:                    //  ROW_+rowindexCOL_+colindex
0964:                    name = "ROW_" + new Integer(_currRowVal).toString();
0965:                    name += "COL_" + new Integer(_currColVal).toString();
0966:
0967:                }
0968:
0969:                if (caption != null) {
0970:                    String s = caption;
0971:                    if (s.length() > 0) {
0972:                        switch (s.charAt(s.length() - 1)) {
0973:                        case ':':
0974:                        case '.':
0975:                        case '?':
0976:                            break;
0977:                        default:
0978:                            s += ":";
0979:                        }
0980:                    }
0981:                    HtmlComponent capComp = null;
0982:                    // save what caption goes with what search comp for later
0983:                    capComp = new HtmlText(s, HtmlText.FONT_COLUMN_CAPTION,
0984:                            getPage());
0985:
0986:                    // Put Caption in search table
0987:                    if (propCaption != null) {
0988:                        setComponentAt(_currRowVal, ++_currColVal, capComp,
0989:                                propCaption);
0990:                    } else {
0991:                        setComponentAt(_currRowVal, ++_currColVal, capComp);
0992:                    }
0993:                    _compLookUpHash.put(CAPTION_COMP_HASH_KEY + name, capComp);
0994:                }
0995:
0996:                //
0997:                if (component != null) {
0998:                    // Null component means caption only, perhaps.
0999:                    if (propSearch != null) {
1000:                        setComponentAt(_currRowVal, ++_currColVal, component,
1001:                                propSearch);
1002:                    } else {
1003:                        setComponentAt(_currRowVal, ++_currColVal, component);
1004:                    }
1005:                    _compLookUpHash.put(SEARCH_COMP_HASH_KEY + name, component);
1006:
1007:                }
1008:            }
1009:
1010:            /**
1011:             * This method will return a caption Component.
1012:             * @param name
1013:             * @return
1014:             */
1015:            public HtmlComponent getCaptionComp(String name) {
1016:                return (HtmlComponent) _compLookUpHash
1017:                        .get(CAPTION_COMP_HASH_KEY + name);
1018:            }
1019:
1020:            /**
1021:             * This method will return a serach component.
1022:             * @param name
1023:             * @return
1024:             */
1025:            public HtmlComponent getSearchComp(String name) {
1026:                return (HtmlComponent) _compLookUpHash.get(SEARCH_COMP_HASH_KEY
1027:                        + name);
1028:
1029:            }
1030:
1031:            /**
1032:             * This method removes all of the components out of the table.
1033:             */
1034:            public void removeAll() {
1035:                super .removeAll();
1036:
1037:                int colCount = _componentsVec2D.getColumnSize();
1038:                int rowCount = _componentsVec2D.getRowSize();
1039:
1040:                /** rows */
1041:                for (int i = 0; i < rowCount; i++) {
1042:                    /** cols */
1043:                    for (int j = 0; j < colCount; j++) {
1044:                        HtmlComponent hc = null;
1045:                        Object o = _componentsVec2D.elementAt(i, j);
1046:
1047:                        if (o instanceof  TwoObjectContainer)
1048:                            hc = (HtmlComponent) ((TwoObjectContainer) o)
1049:                                    .getObject1();
1050:                        else
1051:                            hc = (HtmlComponent) o;
1052:
1053:                        if (hc instanceof  HtmlTable) {
1054:                            ((HtmlTable) hc).removeAll();
1055:                        } else if (hc instanceof  HtmlContainer) {
1056:                            ((HtmlContainer) hc).removeAll();
1057:                        }
1058:
1059:                    }
1060:
1061:                }
1062:
1063:                // last cleanup
1064:                _componentsVec2D.removeAll();
1065:            }
1066:
1067:            /**
1068:             * Removes the row from the table containing a specific component
1069:             * @author Ian Booth
1070:             */
1071:            public void removeRow(HtmlComponent comp) {
1072:                int rowCount = _componentsVec2D.getRowCount();
1073:                int colCount = _componentsVec2D.getColumnCount();
1074:                Object o = null;
1075:                HtmlComponent h = null;
1076:
1077:                for (int i = 0; i < rowCount; i++) {
1078:                    for (int j = 0; j < colCount; j++) {
1079:                        o = _componentsVec2D.elementAt(i, j);
1080:                        if (o != null) {
1081:                            if (o instanceof  TwoObjectContainer)
1082:                                h = (HtmlComponent) ((TwoObjectContainer) o)
1083:                                        .getObject1();
1084:                            else
1085:                                h = (HtmlComponent) o;
1086:                            if (h == comp) {
1087:                                removeRow(i);
1088:                                return;
1089:                            }
1090:                        }
1091:                    }
1092:                }
1093:            }
1094:
1095:            /**
1096:             * @return the default style sheet class for table alternate rows
1097:             */
1098:            public String getRowStyleClassName() {
1099:                return _defaultRowStyleClassName;
1100:            }
1101:
1102:            /**
1103:             * @param string sets the default style sheet class for table rows 
1104:             */
1105:            public void setRowStyleClassName(String string) {
1106:                _defaultRowStyleClassName = string;
1107:            }
1108:
1109:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.