Source Code Cross Referenced for UniversalTableEditor.java in  » IDE » tIDE » snow » sortabletable » 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 » IDE » tIDE » snow.sortabletable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package snow.sortabletable;
002:
003:        import snow.utils.gui.FontSelector;
004:
005:        import javax.swing.table.*;
006:        import javax.swing.*;
007:        import javax.swing.event.*;
008:        import javax.swing.border.*;
009:        import java.awt.*;
010:        import java.text.*;
011:        import javax.swing.text.*;
012:        import java.awt.font.*;
013:        import java.awt.event.*;
014:        import java.awt.geom.*;
015:        import java.nio.*;
016:        import java.nio.charset.*;
017:        import java.util.*;
018:
019:        public class UniversalTableEditor extends AbstractCellEditor implements 
020:                TableCellEditor {
021:            protected final ColorCellEditor colorCellEditor = new ColorCellEditor();
022:            protected final DefaultCellEditor textFieldDefaultCellEditor = new DefaultCellEditor(
023:                    new JTextField());
024:            protected final DefaultCellEditor comboBoxDefaultCellEditor = new DefaultCellEditor(
025:                    new JComboBox());
026:            protected final DefaultCellEditor checkBoxDefaultCellEditor = new DefaultCellEditor(
027:                    new JCheckBox());
028:            protected final FontCellEditor fontCellEditor = new FontCellEditor();
029:            protected final NumberTableCellEditor numberTableCellEditor = new NumberTableCellEditor();
030:
031:            private CellEditor selectedEditor = null;
032:
033:            public UniversalTableEditor() {
034:
035:            } // Constructor
036:
037:            // CELL EDITOR INTERFACE
038:            //
039:            @Override
040:            public void addCellEditorListener(CellEditorListener l) { /*
041:            colorCellEditor.addCellEditorListener(l);
042:            textFieldDefaultCellEditor.addCellEditorListener(l);
043:            comboBoxDefaultCellEditor.addCellEditorListener(l);
044:            checkBoxDefaultCellEditor.addCellEditorListener(l);
045:            fontCellEditor.addCellEditorListener(l);
046:            numberTableCellEditor.addCellEditorListener(l);*/
047:
048:                if (selectedEditor != null) {
049:                    selectedEditor.addCellEditorListener(l);
050:                }
051:
052:            }
053:
054:            @Override
055:            public void removeCellEditorListener(CellEditorListener l) { /*
056:             colorCellEditor.removeCellEditorListener(l);
057:             textFieldDefaultCellEditor.removeCellEditorListener(l);
058:             comboBoxDefaultCellEditor.removeCellEditorListener(l);
059:             checkBoxDefaultCellEditor.removeCellEditorListener(l);
060:             fontCellEditor.removeCellEditorListener(l);
061:             numberTableCellEditor.removeCellEditorListener(l);  */
062:                if (selectedEditor != null) {
063:                    selectedEditor.removeCellEditorListener(l);
064:                }
065:
066:            }
067:
068:            @Override
069:            public void cancelCellEditing() { /*
070:            colorCellEditor.cancelCellEditing();
071:            textFieldDefaultCellEditor.cancelCellEditing();
072:            comboBoxDefaultCellEditor.cancelCellEditing();
073:            checkBoxDefaultCellEditor.cancelCellEditing();
074:            fontCellEditor.cancelCellEditing();
075:            numberTableCellEditor.cancelCellEditing();  */
076:                if (selectedEditor != null) {
077:                    selectedEditor.cancelCellEditing();
078:                }
079:
080:            }
081:
082:            @Override
083:            public boolean stopCellEditing() {
084:                /*
085:                  colorCellEditor.stopCellEditing();
086:                  textFieldDefaultCellEditor.stopCellEditing();
087:                  comboBoxDefaultCellEditor.stopCellEditing();
088:                  checkBoxDefaultCellEditor.stopCellEditing();
089:                  fontCellEditor.stopCellEditing();
090:                  numberTableCellEditor.stopCellEditing();
091:                  return true;
092:                 */
093:                if (selectedEditor != null) {
094:                    return selectedEditor.stopCellEditing();
095:                }
096:                return true;
097:            }
098:
099:            public Object getCellEditorValue() {
100:                if (selectedEditor != null) {
101:                    return selectedEditor.getCellEditorValue();
102:                }
103:                return null;
104:                //textFieldDefaultCellEditor.getCellEditorValue();
105:            }
106:
107:            @Override
108:            public boolean isCellEditable(EventObject anEvent) {
109:                //System.out.println(""+anEvent);
110:                if (selectedEditor != null) {
111:                    return selectedEditor.isCellEditable(anEvent);
112:                }
113:                // if false, nothing will be editable !!
114:                return true;
115:            }
116:
117:            @Override
118:            public boolean shouldSelectCell(EventObject anEvent) {
119:                if (selectedEditor != null) {
120:                    return selectedEditor.shouldSelectCell(anEvent);
121:                }
122:                return true; // normally true, maybe no for checkboxes...
123:            }
124:
125:            /** TableCellEditor interface impl
126:             */
127:            public Component getTableCellEditorComponent(JTable table,
128:                    Object value, boolean isSelected, int row, int column) {
129:                // is null allowed ?? yes, may be casted for example to color
130:                // if(value==null) return new JLabel("No editor for null value");
131:
132:                if (value instanceof  Color) {
133:                    selectedEditor = colorCellEditor;
134:                    return colorCellEditor.getTableCellEditorComponent(table,
135:                            (Color) value, isSelected, row, column);
136:                } else if (value instanceof  Boolean) {
137:                    selectedEditor = checkBoxDefaultCellEditor;
138:                    return checkBoxDefaultCellEditor
139:                            .getTableCellEditorComponent(table, value,
140:                                    isSelected, row, column);
141:                } else if (value instanceof  Font) {
142:                    selectedEditor = fontCellEditor;
143:                    return fontCellEditor.getTableCellEditorComponent(table,
144:                            value, isSelected, row, column);
145:                } else if (value instanceof  Double || value instanceof  Float
146:                        || value instanceof  Integer) {
147:                    selectedEditor = numberTableCellEditor;
148:                    return numberTableCellEditor.getTableCellEditorComponent(
149:                            table, value, isSelected, row, column);
150:                } else {
151:                    // default
152:                    selectedEditor = textFieldDefaultCellEditor;
153:                    return textFieldDefaultCellEditor
154:                            .getTableCellEditorComponent(table, value,
155:                                    isSelected, row, column);
156:                }
157:
158:                // return new JLabel("NO EDITOR FOR "+value.getClass().getName());
159:            }
160:
161:            class FontCellEditor extends AbstractCellEditor implements 
162:                    TableCellEditor, ActionListener {
163:                Font currentFont;
164:                JButton button;
165:                //FontSelector fontChooser;
166:                JDialog dialog;
167:                protected static final String EDIT = "edit";
168:
169:                public FontCellEditor() {
170:                    button = new JButton();
171:                    button.setActionCommand(EDIT);
172:                    button.addActionListener(this );
173:                    button.setBorderPainted(false);
174:
175:                    //Set up the dialog that the button brings up.
176:                    //fontChooser = new FontSelector.();
177:                }
178:
179:                public void actionPerformed(ActionEvent e) {
180:                    if (EDIT.equals(e.getActionCommand())) {
181:                        //The user has clicked the cell, so
182:                        //bring up the dialog.
183:                        //button.setBackground(currentColor);
184:                        //colorChooser.setColor(currentColor);
185:                        //dialog.setVisible(true);
186:
187:                        //fontChooser.setFont(currentFont);
188:                        currentFont = FontSelector.chooseFont(button,
189:                                currentFont);
190:
191:                        fireEditingStopped(); //Make the renderer reappear.
192:
193:                    } else { //User pressed dialog's "OK" button.
194:                        //currentFont = fontChooser.getFont();
195:                    }
196:                }
197:
198:                //Implement the one CellEditor method that AbstractCellEditor doesn't.
199:                public Object getCellEditorValue() {
200:                    return currentFont;
201:                }
202:
203:                //Implement the one method defined by TableCellEditor.
204:                public Component getTableCellEditorComponent(JTable table,
205:                        Object value, boolean isSelected, int row, int column) {
206:                    if (value instanceof  Font) {
207:                        currentFont = (Font) value;
208:                    }
209:                    return button;
210:                }
211:            }
212:
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.