Source Code Cross Referenced for XAnswersTableModel.java in  » XML-UI » xui32 » com » xoetrope » carousel » survey » 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 » xui32 » com.xoetrope.carousel.survey 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.survey;
002:
003:        import com.xoetrope.survey.Condition;
004:        import com.xoetrope.survey.Option;
005:        import com.xoetrope.survey.Question;
006:        import java.awt.event.MouseEvent;
007:        import java.awt.event.MouseListener;
008:        import java.util.Observable;
009:        import java.util.Observer;
010:        import java.util.Vector;
011:        import javax.swing.JCheckBox;
012:        import javax.swing.JComboBox;
013:        import javax.swing.JLabel;
014:        import javax.swing.JTextField;
015:        import javax.swing.table.AbstractTableModel;
016:
017:        /**
018:         * A model for the user's answer table.
019:         *
020:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
021:         * the GNU Public License (GPL), please see license.txt for more details. If
022:         * you make commercial use of this software you must purchase a commercial
023:         * license from Xoetrope.</p>
024:         * <p> $Revision: 1.5 $</p>
025:         */
026:        public class XAnswersTableModel extends AbstractTableModel implements 
027:                MouseListener {
028:            public static final int COL_OPTIONID = 0;
029:            public static final int COL_OPTION = 1;
030:            public static final int COL_ANSWER = 2;
031:
032:            protected XTable table;
033:            protected XTableColumn[] columns = new XTableColumn[3];
034:
035:            protected Condition condition;
036:
037:            /**
038:             * Creates a new instance of XAnswersTableModel
039:             */
040:            public XAnswersTableModel() {
041:                super ();
042:                condition = null;
043:            }
044:
045:            /**
046:             * Creates a new instance of XAnswersTableModel
047:             * @param t the table component wich will visualize
048:             * the data held by this model.
049:             */
050:            public XAnswersTableModel(XTable t) {
051:                table = t;
052:                columns[0] = new XTableColumn("id", 20, JLabel.LEFT);
053:                columns[1] = new XTableColumn("option", 20, JLabel.LEFT);
054:                columns[2] = new XTableColumn("answer", 20, JLabel.LEFT,
055:                        new JCheckBox());
056:                table.setModel(this , columns, this );
057:            }
058:
059:            /**
060:             * Gets the columns of this model.
061:             * @return table containing the columns.
062:             */
063:            public XTableColumn[] getColumns() {
064:                return columns;
065:            }
066:
067:            /**
068:             * Gets the number of columns in this model
069:             * @return the number of columns.
070:             */
071:            public int getColumnCount() {
072:                return columns.length;
073:            }
074:
075:            /**
076:             * Gets the name of the column located at the
077:             * specified index
078:             * @param the index of the requested column
079:             * @return the name of the column
080:             */
081:            public String getColumnName(int col) {
082:                return columns[col].getName();
083:            }
084:
085:            /**
086:             * Gets the number of rows in the model. 
087:             * @return the number of rows
088:             */
089:            public int getRowCount() {
090:                return (condition != null ? condition.getQuestion()
091:                        .getOptions().size() : 0);
092:            }
093:
094:            /**
095:             * Gets the type of the column located at
096:             * the specified index
097:             * @param idx the index of the column being queried
098:             * @return the Class representing the column
099:             */
100:            public Class getColumnClass(int idx) {
101:                return (idx == COL_ANSWER ? Boolean.class : super 
102:                        .getColumnClass(idx));
103:            }
104:
105:            /**
106:             * Returns an attribute value for the cell at the specified rowIndex
107:             * and columnIndex
108:             * @param rowIndex the row whose value is to be queried
109:             * @param columnIndex the index wshose value is to be queried
110:             * @return the value Object at the specified cell.
111:             */
112:            public Object getValueAt(int rowIndex, int columnIndex) {
113:                if (condition == null || rowIndex < 0
114:                        || rowIndex > getRowCount())
115:                    return "";
116:                Vector options = condition.getQuestion().getOptions();
117:                Option option = (Option) options.get(rowIndex);
118:                switch (columnIndex) {
119:                case COL_OPTIONID:
120:                    return String.valueOf(option.getId());
121:                case COL_OPTION:
122:                    return option.getText();
123:                case COL_ANSWER:
124:                    return new Boolean(condition.getOptions().contains(option));
125:                }
126:                return "";
127:            }
128:
129:            /**
130:             * Adds the new questin option to this model
131:             * @param option to option to be added
132:             */
133:            protected void addOption(Option option) {
134:                Question question = condition.getQuestion();
135:                if (question.getQuestionType() == Question.MUTUALLY_EXCLUSIVE) {
136:                    condition.getOptions().removeAllElements();
137:                    condition.getAnswers().removeAllElements();
138:                    condition.addAnswer(option, "<checked>");
139:                } else if (question.getQuestionType() == Question.MULTIPLE_CHOICE) {
140:                    condition.addAnswer(option, "<checked>");
141:                }
142:            }
143:
144:            /**
145:             * Removes the specified option from this model
146:             * @param option the option to be removed
147:             */
148:            protected void removeOption(Option option) {
149:                condition.removeAnswer(option);
150:            }
151:
152:            /**
153:             * Sets the value of an attribute at the specified rowIndex and columnIndex
154:             * @param value the new value
155:             * @pram rowIndex the row whose value is to be changed
156:             * @param columnIndex the column whose value is to be changed
157:             */
158:            public void setValueAt(Object value, int rowIndex, int columnIndex) {
159:                if (condition == null || columnIndex != COL_ANSWER)
160:                    return;
161:                XSurvey.setProjectModified(true);
162:                Vector options = condition.getQuestion().getOptions();
163:                Option option = (Option) options.get(rowIndex);
164:                Boolean answer = (Boolean) value;
165:                if (answer.booleanValue())
166:                    addOption(option);
167:                else
168:                    condition.removeAnswer(option);
169:                table.revalidate();
170:                table.repaint();
171:            }
172:
173:            /**
174:             * Indicates whether the specified cell is editable
175:             * @param row of the cell being queried
176:             * @param col the column of the cell being queried
177:             * @return true if the cell editable, false otherwise
178:             */
179:            public boolean isCellEditable(int row, int col) {
180:                return (columns[col].getCellEditor() != null);
181:            }
182:
183:            /*
184:             * Sets the new Condition object of this model.
185:             * @param c the new Condition object.
186:             */
187:            public void setCondition(Condition c) {
188:                condition = c;
189:                table.clearSelection();
190:                table.revalidate();
191:                table.repaint();
192:            }
193:
194:            public void mouseClicked(MouseEvent e) {
195:            }
196:
197:            public void mousePressed(MouseEvent e) {
198:            }
199:
200:            public void mouseReleased(MouseEvent e) {
201:            }
202:
203:            public void mouseEntered(MouseEvent e) {
204:            }
205:
206:            public void mouseExited(MouseEvent e) {
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.