Source Code Cross Referenced for XOptionsTableModel.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.Option;
004:        import com.xoetrope.survey.Question;
005:        import java.awt.event.ActionEvent;
006:        import java.awt.event.ActionListener;
007:        import java.util.Observable;
008:        import java.util.Observer;
009:        import java.util.Vector;
010:        import java.awt.Component;
011:        import java.awt.Point;
012:        import java.awt.event.MouseEvent;
013:        import java.awt.event.MouseListener;
014:        import javax.swing.JLabel;
015:        import javax.swing.JMenuItem;
016:        import javax.swing.JPopupMenu;
017:        import javax.swing.JTextField;
018:        import javax.swing.JFormattedTextField;
019:        import javax.swing.event.ListSelectionEvent;
020:        import javax.swing.event.ListSelectionListener;
021:        import javax.swing.table.AbstractTableModel;
022:        import net.xoetrope.editor.project.XEditorProject;
023:        import net.xoetrope.xui.XProject;
024:        import net.xoetrope.xui.XProjectManager;
025:
026:        //import org.netbeans.api.debugger.jpda.This;
027:
028:        /**
029:         * A model for options table
030:         *
031:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
032:         * the GNU Public License (GPL), please see license.txt for more details. If
033:         * you make commercial use of this software you must purchase a commercial
034:         * license from Xoetrope.</p>
035:         * <p> $Revision: 1.5 $</p>
036:         */
037:        public class XOptionsTableModel extends AbstractTableModel implements 
038:                MouseListener, Observer, ListSelectionListener {
039:            public static final int COL_RESPONSE = 0;
040:            public static final int COL_VALUE = 1;
041:
042:            protected XTable table;
043:            protected JPopupMenu popupMenu;
044:            protected NewOptionDialog newOptionDialog;
045:            protected XNotifier notifier;
046:            protected ActionListener addOption, deleteOption, moveUpOption,
047:                    moveDownOption;
048:
049:            protected Question question;
050:
051:            protected XTableColumn[] columns = new XTableColumn[2];
052:
053:            public XOptionsTableModel(XTable t) {
054:                table = t;
055:                XProject project = XProjectManager.getCurrentProject();
056:                XEditorProject editorProject = (project instanceof  XEditorProject ? (XEditorProject) project
057:                        : null);
058:                notifier = new XNotifier(editorProject, true);
059:
060:                JFormattedTextField ft = new JFormattedTextField();
061:                ft.setValue(new Integer(100));
062:                columns[0] = new XTableColumn("Response", 300, JLabel.LEFT,
063:                        new JTextField());
064:                columns[1] = new XTableColumn("ID", 20, JLabel.LEFT, ft);
065:
066:                table.setModel(this , columns, this );
067:                table.getSelectionModel().addListSelectionListener(this );
068:                question = null;
069:
070:                addOption = new AddOption();
071:                deleteOption = new DeleteOption();
072:                moveUpOption = new MoveUpOption();
073:                moveDownOption = new MoveDownOption();
074:
075:                newOptionDialog = new NewOptionDialog();
076:                createPopupMenu();
077:            }
078:
079:            public Observable getNotifier() {
080:                return notifier;
081:            }
082:
083:            public void refresh() {
084:                table.clearSelection();
085:                table.revalidate();
086:                table.repaint();
087:            }
088:
089:            public ActionListener getAddOption() {
090:                return addOption;
091:            }
092:
093:            public ActionListener getDeleteOption() {
094:                return deleteOption;
095:            }
096:
097:            public ActionListener getMoveOptionUp() {
098:                return moveUpOption;
099:            }
100:
101:            public ActionListener getMoveOptionDown() {
102:                return moveDownOption;
103:            }
104:
105:            private void createPopupMenu() {
106:                JMenuItem menuItem;
107:                popupMenu = new JPopupMenu();
108:                popupMenu.add(new JLabel("Question Option"));
109:                popupMenu.addSeparator();
110:                menuItem = new JMenuItem("Move up");
111:                popupMenu.add(menuItem);
112:                menuItem.addActionListener(moveUpOption);
113:                menuItem = new JMenuItem("Move down");
114:                popupMenu.add(menuItem);
115:                menuItem.addActionListener(moveDownOption);
116:                popupMenu.addSeparator();
117:                menuItem = new JMenuItem("Add..");
118:                popupMenu.add(menuItem);
119:                menuItem.addActionListener(addOption);
120:                menuItem = new JMenuItem("Delete..");
121:                popupMenu.add(menuItem);
122:                menuItem.addActionListener(deleteOption);
123:            }
124:
125:            public XTableColumn[] getColumns() {
126:                return columns;
127:            }
128:
129:            public String getColumnName(int col) {
130:                return columns[col].getName();
131:            }
132:
133:            public boolean isCellEditable(int row, int col) {
134:                return (columns[col].getCellEditor() != null);
135:            }
136:
137:            public int getRowCount() {
138:                if (question == null)
139:                    return 0;
140:
141:                Vector options = question.getOptions();
142:                return (options != null ? options.size() : 0);
143:            }
144:
145:            public int getColumnCount() {
146:                return columns.length;
147:            }
148:
149:            public Object getValueAt(int rowIndex, int columnIndex) {
150:                if (question == null || rowIndex < 0
151:                        || rowIndex > getRowCount())
152:                    return "";
153:                Option option = (Option) question.getOptions().get(rowIndex);
154:
155:                switch (columnIndex) {
156:                case COL_RESPONSE:
157:                    return option.getText();
158:                case COL_VALUE:
159:                    return String.valueOf(option.getId());
160:                }
161:
162:                return "";
163:            }
164:
165:            public void setValueAt(Object value, int rowIndex, int columnIndex) {
166:                if (question == null)
167:                    return;
168:                Option option = (Option) question.getOptions().get(rowIndex);
169:
170:                switch (columnIndex) {
171:                case COL_RESPONSE:
172:                    String newResponse = value.toString();
173:                    if (!newResponse.equals(option.getText()))
174:                        XSurvey.setProjectModified(true);
175:                    option.setText(newResponse);
176:                    notifier.notifyObservers(option);
177:                    break;
178:                case COL_VALUE:
179:                    int newId = new Integer(value.toString()).intValue();
180:                    boolean state = (newId != option.getId());
181:                    if (newId != option.getId())
182:                        XSurvey.setProjectModified(true);
183:                    option.setId(newId);
184:                    notifier.notifyObservers(option);
185:                    break;
186:                }
187:            }
188:
189:            private void showPopupMenu(MouseEvent e) {
190:                if (e.isPopupTrigger()) {
191:                    Component source = (Component) e.getSource();
192:                    boolean isQuestionOption = (source instanceof  XTable || source instanceof  JTextField);
193:                    Point p = e.getPoint();
194:                    if (!isQuestionOption) {
195:                        System.out.println(source.getParent().getParent()
196:                                .getParent().getParent());
197:                        // table->viewport->scrollpane->XPopupPanel
198:                        //((XResponseSetEditor)( ( XPopupPanel )source.getParent().getParent().getParent() ).getOwner()).addPopupActions();
199:                    } else
200:                        popupMenu.show(source, p.x, p.y);
201:                }
202:            }
203:
204:            public void mouseClicked(MouseEvent e) {
205:            }
206:
207:            public void mousePressed(MouseEvent e) {
208:                showPopupMenu(e);
209:            }
210:
211:            public void mouseReleased(MouseEvent e) {
212:                showPopupMenu(e);
213:            }
214:
215:            public void mouseEntered(MouseEvent e) {
216:            }
217:
218:            public void mouseExited(MouseEvent e) {
219:            }
220:
221:            public void update(Observable o, Object arg) {
222:                question = (Question) arg;
223:                table.clearSelection();
224:                table.revalidate();
225:                table.repaint();
226:            }
227:
228:            public void valueChanged(ListSelectionEvent e) {
229:                Option option = null;
230:                int row = table.getSelectedRow();
231:                if (row >= 0 && row < getRowCount())
232:                    option = question.getOption(row);
233:                notifier.notifyObservers(option);
234:            }
235:
236:            private class AddOption implements  ActionListener {
237:                public void actionPerformed(ActionEvent e) {
238:                    if (newOptionDialog.showDialog()) {
239:                        String response = newOptionDialog.getResponse();
240:                        int optionId = newOptionDialog.getOptionId();
241:                        Option option = new Option(optionId, response);
242:                        question.addOption(option);
243:                        int idx = question.getOptions().size() - 1;
244:                        table.getSelectionModel()
245:                                .setSelectionInterval(idx, idx);
246:                        table.revalidate();
247:                        table.repaint();
248:                        notifier.notifyObservers(option);
249:                    }
250:                }
251:            }
252:
253:            private class DeleteOption implements  ActionListener {
254:                public void actionPerformed(ActionEvent e) {
255:                    int idx = table.getSelectedRow();
256:                    question.deleteOption(idx);
257:                    table.clearSelection();
258:                    table.revalidate();
259:                    table.repaint();
260:                    notifier.notifyObservers(null);
261:                }
262:            }
263:
264:            private class MoveUpOption implements  ActionListener {
265:                public void actionPerformed(ActionEvent e) {
266:                    int idx = table.getSelectedRow();
267:                    if (idx <= 0 || idx >= getRowCount())
268:                        return;
269:                    Vector options = question.getOptions();
270:                    if (options == null)
271:                        return;
272:
273:                    Option option = (Option) options.get(idx);
274:                    options.remove(option);
275:                    options.add(--idx, option);
276:                    table.getSelectionModel().setSelectionInterval(idx, idx);
277:                    table.revalidate();
278:                    table.repaint();
279:                    notifier.notifyObservers(option);
280:                }
281:            }
282:
283:            private class MoveDownOption implements  ActionListener {
284:                public void actionPerformed(ActionEvent e) {
285:                    int idx = table.getSelectedRow();
286:                    if (idx < 0 || idx >= getRowCount() - 1)
287:                        return;
288:                    Vector options = question.getOptions();
289:                    if (options == null)
290:                        return;
291:                    Option option = (Option) options.get(idx);
292:                    options.remove(option);
293:                    options.add(++idx, option);
294:                    table.getSelectionModel().setSelectionInterval(idx, idx);
295:                    table.revalidate();
296:                    table.repaint();
297:                    notifier.notifyObservers(option);
298:                }
299:            }
300:
301:            private class OptionChangeNotifier extends Observable {
302:                public void notifyObservers(Object o) {
303:                    setChanged();
304:                    super.notifyObservers(o);
305:                }
306:            }
307:
308:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.