Source Code Cross Referenced for ExpressionCellRenderer.java in  » J2EE » Sofia » com » salmonllc » swing » table » 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.swing.table 
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:
021:        package com.salmonllc.swing.table;
022:
023:        import com.salmonllc.sql.DataStoreBuffer;
024:        import com.salmonllc.sql.DataStoreException;
025:        import com.salmonllc.sql.DataStoreEvaluator;
026:        import com.salmonllc.sql.DataStoreExpression;
027:        import com.salmonllc.swing.STable;
028:
029:        import javax.swing.*;
030:        import javax.swing.table.DefaultTableCellRenderer;
031:        import java.awt.*;
032:        import java.util.Vector;
033:
034:        /**
035:         * A cell renderer that displays an icon and/or tooltip for a table column if a boolean expression is true for the row.
036:         */
037:        public class ExpressionCellRenderer extends DefaultTableCellRenderer {
038:            private DataStoreBuffer _ds;
039:            private Vector _eval;
040:            private DataStoreEvaluator _mainEval;
041:            protected STable _tab;
042:            private static String _colExp = "$col$";
043:            private String _colName = null;
044:
045:            /**
046:             * Creates a <code>SLabel</code> instance with
047:             * no image and with an empty string for the title.
048:             * The label is centered vertically
049:             * in its display area.
050:             * The label's contents, once set, will be displayed on the leading edge
051:             * of the label's display area.
052:             */
053:            public ExpressionCellRenderer(STable tab) {
054:                super ();
055:                _ds = ((DataStoreTableModel) tab.getModel()).getDataStore();
056:                _eval = new Vector();
057:                _tab = tab;
058:            }
059:
060:            /**
061:             * Sets the expression that will be computed to display this cell
062:             */
063:            public void setExpression(DataStoreEvaluator exp) {
064:                _mainEval = exp;
065:            }
066:
067:            /**
068:             * Sets the expression that will be computed to display this cell
069:             */
070:            public void setExpression(DataStoreExpression exp)
071:                    throws DataStoreException {
072:                setExpression(new DataStoreEvaluator(_ds, exp));
073:            }
074:
075:            /**
076:             * Sets the expression that will be computed to display this cell
077:             */
078:            public void setExpression(String exp) throws DataStoreException {
079:                if (_ds.getColumnIndex(exp) == -1)
080:                    setExpression(new DataStoreEvaluator(_ds, exp));
081:                else
082:                    _colName = exp;
083:            }
084:
085:            /**
086:             * Adds the validations for a column in the datastore to this renderer
087:             */
088:            public void addColumnValidations(String column, Icon icon) {
089:                Object o[] = new Object[3];
090:                o[0] = column;
091:                o[1] = _colExp;
092:                o[2] = icon;
093:                _eval.add(o);
094:            }
095:
096:            /**
097:             * Displays the icon and message expression for each cell where the expression evaluates to false
098:             * @throws DataStoreException
099:             */
100:            public void addValidateExpression(DataStoreEvaluator exp,
101:                    String message, Icon icon) throws DataStoreException {
102:                Object o[] = new Object[3];
103:                o[0] = exp;
104:                o[1] = message;
105:                o[2] = icon;
106:                _eval.add(o);
107:            }
108:
109:            /**
110:             * Displays the icon and message for each cell where the expression evaluates to false
111:             * @throws DataStoreException
112:             */
113:            public void addValidateExpression(String exp, String message,
114:                    Icon icon) throws DataStoreException {
115:                Object o[] = new Object[3];
116:                o[0] = new DataStoreEvaluator(_ds, exp);
117:                o[1] = message;
118:                o[2] = icon;
119:                _eval.add(o);
120:            }
121:
122:            /**
123:             * Displays the icon and message expression for each cell where the expression evaluates to false
124:             * @throws DataStoreException
125:             */
126:            public void addValidateExpression(DataStoreExpression exp,
127:                    String message, Icon icon) throws DataStoreException {
128:                Object o[] = new Object[3];
129:                o[0] = new DataStoreEvaluator(_ds, exp);
130:                o[1] = message;
131:                o[2] = icon;
132:                _eval.add(o);
133:            }
134:
135:            public Component getRenderer() {
136:                return getTableCellRendererComponent(_tab, null, false, false,
137:                        0, 0);
138:            }
139:
140:            public Component getTableCellRendererComponent(JTable table,
141:                    Object value, boolean isSelected, boolean hasFocus,
142:                    int row, int column) {
143:                Component comp = super .getTableCellRendererComponent(table,
144:                        value, isSelected, hasFocus, row, column);
145:                if (comp instanceof  JLabel) {
146:                    try {
147:                        if (_mainEval != null) {
148:                            String val = _mainEval.evaluateRowFormat(row);
149:                            ((JLabel) comp).setText(val);
150:                        }
151:                        Icon icon = null;
152:                        String toolTip = null;
153:
154:                        for (int i = 0; i < _eval.size(); i++) {
155:                            Object o[] = (Object[]) _eval.elementAt(i);
156:                            if (o[1] == _colExp) {
157:                                int colIndex = _ds
158:                                        .getColumnIndex((String) o[0]);
159:                                if (colIndex != -1) {
160:                                    DataStoreException ex[] = _ds
161:                                            .validateColumn(row, colIndex, null);
162:                                    if (ex.length > 0) {
163:                                        icon = (Icon) o[2];
164:                                        toolTip = ex[0].getMessage();
165:                                        break;
166:                                    }
167:                                }
168:                            } else if (o[0] != null) {
169:                                Object ret = ((DataStoreEvaluator) o[0])
170:                                        .evaluateRow(row);
171:                                if ((ret instanceof  Boolean)
172:                                        && !((Boolean) ret).booleanValue()) {
173:                                    icon = (Icon) o[2];
174:                                    toolTip = (String) o[1];
175:                                    break;
176:                                }
177:                            }
178:                        }
179:
180:                        ((JLabel) comp).setIcon(icon);
181:                        ((JLabel) comp).setToolTipText(toolTip);
182:                        if (!isSelected) {
183:                            ((JLabel) comp).setBackground(_tab
184:                                    .getBackground(row));
185:                            ((JLabel) comp).setForeground(_tab
186:                                    .getForeground(row));
187:                        } else {
188:                            ((JLabel) comp).setBackground(_tab
189:                                    .getSelectionBackground(row));
190:                            ((JLabel) comp).setForeground(_tab
191:                                    .getSelectionForeground(row));
192:                        }
193:                    } catch (DataStoreException ex) {
194:                    }
195:                }
196:                int col = _tab.getColumnModel().getColumn(column)
197:                        .getModelIndex();
198:                if (hasFocus && table.getModel().isCellEditable(row, col))
199:                    table.editCellAt(row, column);
200:                return comp;
201:            }
202:
203:            /**
204:             * Returns the DataStoreEvaluator for this cell
205:             */
206:            public DataStoreEvaluator getEvaluator() {
207:                return _mainEval;
208:            }
209:
210:            /**
211:             * If this renderer is bound to a particular column in a datastore then this returns the name of it
212:             * @return
213:             */
214:            public String getColName() {
215:                return _colName;
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.