Source Code Cross Referenced for XTable.java in  » XML-UI » XUI » net » xoetrope » swing » 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 » XML UI » XUI » net.xoetrope.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.xoetrope.swing;
002:
003:        import java.awt.Dimension;
004:        import java.awt.ItemSelectable;
005:        import java.awt.event.ItemListener;
006:
007:        import net.xoetrope.xui.XAttributedComponent;
008:        import net.xoetrope.xui.XModelHolder;
009:        import net.xoetrope.xui.data.XModel;
010:        import net.xoetrope.xui.style.XStyleComponent;
011:        import java.awt.Container;
012:        import java.awt.event.MouseListener;
013:        import java.awt.event.MouseEvent;
014:        import net.xoetrope.xui.XHashCode;
015:        import net.xoetrope.xui.data.XRowSelector;
016:
017:        /**
018:         * <p>Provides a simple read-only tables/grid component.</p>
019:         * <p>Copyright (c) Xoetrope Ltd., 1998-2004<br>
020:         * License:      see license.txt
021:         * $Revision: 1.17 $
022:         */
023:        public class XTable extends XScrollPane implements 
024:                XAttributedComponent, XModelHolder, ItemSelectable,
025:                XStyleComponent, XHashCode, XRowSelector {
026:            private XTableRenderer content;
027:            private XModel model;
028:
029:            public XTable() {
030:                super ();
031:                content = new XTableRenderer(this );
032:                setViewportView(content);
033:            }
034:
035:            /**
036:             * Set the XModel which we will be generating the table from
037:             * @param xmodel The XModel of data
038:             */
039:            public void setModel(XModel xmodel) {
040:                model = xmodel;
041:                if (model != null) {
042:                    model.get();
043:                    content.setContent(xmodel);
044:                }
045:
046:                checkSize();
047:            }
048:
049:            /**
050:             * Get the underlying model.
051:             * @return the model
052:             */
053:            public XModel getModel() {
054:                return model;
055:            }
056:
057:            /**
058:             * Recalculate and check the size of the content
059:             */
060:            public void checkSize() {
061:                Dimension d = content.calcSize();
062:                content.setPreferredSize(d);
063:                content.revalidate();
064:
065:                repaint();
066:            }
067:
068:            /**
069:             * Get the container that holds the components
070:             * @return the viewport pane
071:             */
072:            public Container getComponentPanel() {
073:                return getViewport();
074:            }
075:
076:            /**
077:             * Set the type of component for a column
078:             * @param col the field index
079:             * @param className the class name
080:             */
081:            public void setComponentAt(int col, String className) {
082:                content.setComponentAt(col, className);
083:            }
084:
085:            /**
086:             * Set the model's name
087:             * @return the name
088:             */
089:            public String getContent() {
090:                return model.getId();
091:            }
092:
093:            /**
094:             * Creates the scroll pane's peer and sizes the child element.
095:             */
096:            public void addNotify() {
097:                super .addNotify();
098:                if (content != null) {
099:                    Dimension d = content.calcSize();
100:                    content.setBounds(0, 0, Math.max(
101:                            (this .getSize().width - 20), d.width), d.height);
102:                    doLayout();
103:                }
104:            }
105:
106:            /**
107:             * Set the general style of the XTable
108:             * @param style XStyle
109:             */
110:            public void setStyle(String style) {
111:                content.setStyle(style);
112:            }
113:
114:            /**
115:             * Set the style of the header data
116:             * @param style XStyle
117:             */
118:            public void setHeaderStyle(String style) {
119:                content.setHeaderStyle(style);
120:            }
121:
122:            /**
123:             * Set the style of the selected row
124:             * @param style XStyle
125:             */
126:            public void setSelectedStyle(String style) {
127:                content.setSelectedStyle(style);
128:            }
129:
130:            /**
131:             * Set the style of the border
132:             * @param style XStyle
133:             */
134:            public void setBorderStyle(String style) {
135:                content.setBorderStyle(style);
136:            }
137:
138:            /**
139:             * Check the if the table is interactive
140:             * @return true if the table supports user interaction
141:             */
142:            public boolean isInteractiveTable() {
143:                return content.isInteractiveTable();
144:            }
145:
146:            /**
147:             * Set the user interaction state
148:             * @param state true for an user interactive table.
149:             */
150:            public void setInteractiveTable(boolean state) {
151:                content.setInteractiveTable(state);
152:            }
153:
154:            /**
155:             * Sets the indexof the selected row
156:             * @param idx the new selected row
157:             */
158:            public void setSelectedRow(int idx) {
159:                content.setSelectedRow(idx);
160:            }
161:
162:            /**
163:             * Get the index of the selected row
164:             * @return the index of the selected row
165:             */
166:            public int getSelectedRow() {
167:                return content.getSelectedRow();
168:            }
169:
170:            /**
171:             * Move to the first row
172:             */
173:            public void first() {
174:                content.setSelectedRow(0);
175:            }
176:
177:            /**
178:             * Move to the previous row
179:             */
180:            public void prev() {
181:                content.setSelectedRow(content.getSelectedRow() - 1);
182:            }
183:
184:            /**
185:             * Move to the next row
186:             */
187:            public void next() {
188:                content.setSelectedRow(content.getSelectedRow() + 1);
189:            }
190:
191:            /**
192:             * Move to the last row
193:             */
194:            public void last() {
195:                content.setSelectedRow(model.getNumChildren() - 1);
196:            }
197:
198:            /**
199:             * Tie the model selection to this table's selection
200:             * @param doUpdate true to tie the selections together, false to ignore
201:             */
202:            public void setUpdateModelSelection(boolean doUpdate) {
203:                content.setUpdateModelSelection(doUpdate);
204:            }
205:
206:            /**
207:             * Sets the bounds for this component
208:             * @param x
209:             * @param y
210:             * @param w
211:             * @param h
212:             */
213:            public void setBounds(int x, int y, int w, int h) {
214:                Dimension d = content.calcSize();
215:                content.setPreferredSize(d);
216:                content.revalidate();
217:                super .setBounds(x, y, w, h);
218:                validate();
219:            }
220:
221:            /**
222:             * Set the table column width;
223:             * @param fieldIdx the field index
224:             * @param w the new column width
225:             */
226:            public void setColWidth(int fieldIdx, int w) {
227:                content.setColWidth(fieldIdx, w);
228:            }
229:
230:            /**
231:             * Set one or more attributes of the component. Currently this handles the
232:             * attributes
233:             * <OL>
234:             * <LI>headingStyle, value=the table header style</LI>
235:             * <LI>selectionStyle, value=the selected row style</LI>
236:             * <LI>interactive, value=true|false</LI>
237:             * <LI>updateModel, value=true|false update the underlying model selection (the selected row)</LI>
238:             * </OL>
239:             * @param attribName the attribute name
240:             * @param attribValue the attribute value
241:             */
242:            public void setAttribute(String attribName, String attribValue) {
243:                if (attribName.compareTo("headingStyle") == 0)
244:                    setHeaderStyle(attribValue);
245:                else if (attribName.compareTo("selectionStyle") == 0)
246:                    setSelectedStyle(attribValue);
247:                else if (attribName.compareTo("borderStyle") == 0)
248:                    setBorderStyle(attribValue);
249:                else if (attribName.compareTo("interactive") == 0)
250:                    setInteractiveTable(attribValue.compareTo("true") == 0);
251:                else if (attribName.compareTo("updateModel") == 0)
252:                    setUpdateModelSelection(attribValue.compareTo("true") == 0);
253:
254:                super .setAttribute(attribName, attribValue);
255:            }
256:
257:            /**
258:             * Gets a field value object from the currently selected row
259:             * @param fieldIdx the field offset
260:             * @return the value
261:             */
262:            public Object getValue(int fieldIdx) {
263:                int row = content.getCurrentRow();
264:                return getValue(row, fieldIdx);
265:            }
266:
267:            /**
268:             * Gets a field value object from the specified row
269:             * @param rowIdx the row offset
270:             * @param fieldIdx the field offset
271:             * @return the value
272:             */
273:            public Object getValue(int rowIdx, int fieldIdx) {
274:                XModel rowModel = model.get(rowIdx + content.getFirstRow());
275:                Object fieldModel = rowModel.get(fieldIdx);
276:                if (fieldModel instanceof  XModel)
277:                    return ((XModel) fieldModel).get();
278:                return fieldModel;
279:            }
280:
281:            /**
282:             * Gets a field value as a string from the currently selected row
283:             * @param fieldIdx the field offset
284:             * @return the value
285:             */
286:            public String getFieldValue(int fieldIdx) {
287:                return (String) getValue(fieldIdx);
288:
289:            }
290:
291:            /**
292:             * Gets a field value as a string from the specified row
293:             * @param rowIdx the row offset
294:             * @param fieldIdx the field offset
295:             * @return the value
296:             */
297:            public String getFieldValue(int rowIdx, int fieldIdx) {
298:                return (String) getValue(rowIdx, fieldIdx);
299:            }
300:
301:            /**
302:             * Adds the specified item listener to receive item events from
303:             * this list.  Item events are sent in response to user input, but not
304:             * in response to calls to <code>select</code> or <code>deselect</code>.
305:             * If listener <code>l</code> is <code>null</code>,
306:             * no exception is thrown and no action is performed.
307:             *
308:             * @param         l the item listener
309:             * @see           java.awt.event.ItemEvent
310:             * @see           java.awt.event.ItemListener
311:             * @since         JDK1.1
312:             */
313:            public synchronized void addItemListener(ItemListener l) {
314:                content.addItemListener(l);
315:            }
316:
317:            /**
318:             * Removes the specified item listener so that it no longer
319:             * receives item events from this list.
320:             * If listener <code>l</code> is <code>null</code>,
321:             * no exception is thrown and no action is performed.
322:             *
323:             * @param         	l the item listener
324:             * @see           	java.awt.event.ItemEvent
325:             * @see           	java.awt.event.ItemListener
326:             * @since         	JDK1.1
327:             */
328:            public synchronized void removeItemListener(ItemListener l) {
329:                content.removeItemListener(l);
330:            }
331:
332:            /**
333:             * Returns the selected items on the list in an array of objects.
334:             * @see ItemSelectable
335:             */
336:            public Object[] getSelectedObjects() {
337:                return content.getSelectedObjects();
338:            }
339:
340:            /**
341:             * Add a mouse listener
342:             * @param l the new mouse listener
343:             */
344:            public void addMouseListener(MouseListener l) {
345:                content.addMouseListener(l);
346:            }
347:
348:            /**
349:             * Get the hash code to be used by the event handler for this component
350:             * @return the hash code
351:             */
352:            public long getComponentHashCode() {
353:                return content.hashCode();
354:            }
355:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.