Source Code Cross Referenced for TestModel.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 java.awt.*;
004:        import java.awt.event.*;
005:        import javax.swing.*;
006:        import javax.swing.event.*;
007:        import javax.swing.table.*;
008:        import java.util.*;
009:
010:        public final class TestModel extends FineGrainTableModel {
011:            private final Vector<TestModelItem> items = new Vector<TestModelItem>();
012:            private final String[] COLUMN_NAMES = new String[] { "Size",
013:                    "Name", "Index", "Index2", "Index3", "check" };
014:
015:            public TestModel() {
016:                for (int i = 0; i < 3; i++) {
017:                    addRandom();
018:                }
019:            }
020:
021:            int[] COLUMN_PREFERED_SIZES = new int[] { 6, 4, 4, 12, 12, 12 };
022:
023:            @Override
024:            public int getPreferredColumnWidth(int column) {
025:                if (column >= 0 && column < COLUMN_PREFERED_SIZES.length)
026:                    return COLUMN_PREFERED_SIZES[column];
027:                return -1;
028:            }
029:
030:            public void add(TestModelItem titm) {
031:                fireTableModelWillChange();
032:
033:                items.addElement(titm);
034:
035:                fireTableDataChanged();
036:                fireTableModelHasChanged();
037:            }
038:
039:            public void remove(TestModelItem titm) {
040:                fireTableModelWillChange();
041:                items.removeElement(titm);
042:                fireTableDataChanged();
043:                fireTableModelHasChanged();
044:            }
045:
046:            int n = 0;
047:
048:            public void addRandom() {
049:                n++;
050:
051:                TestModelItem titm = new TestModelItem();
052:                titm.col1 = Math.random() * 1e6;
053:                if (Math.random() < 0.1)
054:                    titm.col1 = Math.random() * 1e3;
055:                titm.col2 = "" + ((char) ('a' + (n % 26)));
056:                titm.col3 = n;
057:                titm.col4 = (int) (Math.random() * 1000);
058:                titm.col5 = (int) (Math.random() * 1000000);
059:                add(titm);
060:            }
061:
062:            public void removeLast() {
063:                if (items.isEmpty())
064:                    return;
065:
066:                fireTableModelWillChange();
067:                items.removeElementAt(items.size() - 1);
068:                fireTableDataChanged();
069:                fireTableModelHasChanged();
070:            }
071:
072:            public int getRowCount() {
073:                return items.size();
074:            }
075:
076:            public int getColumnCount() {
077:                return 6;
078:            }
079:
080:            public TestModelItem getItemAt(int pos) {
081:                return items.get(pos);
082:            }
083:
084:            public Object getValueAt(int row, int column) {
085:                TestModelItem item = getItemAt(row);
086:                if (column == 0)
087:                    return item.col1;
088:                if (column == 1)
089:                    return item.col2;
090:                if (column == 2)
091:                    return item.col3;
092:                if (column == 3)
093:                    return item.col4;
094:                if (column == 4)
095:                    return item.col5;
096:                if (column == 5)
097:                    return item.checked;
098:                return "??";
099:            }
100:
101:            @Override
102:            public boolean isCellEditable(int row, int col) {
103:                return col <= 2 || col == 5;
104:            }
105:
106:            @Override
107:            public void setValueAt(Object val, int row, int col) {
108:                if (val == null)
109:                    return;
110:
111:                fireTableModelWillChange();
112:                TestModelItem item = getItemAt(row);
113:                if (col == 0) {
114:                    try {
115:                        double vd = Double.parseDouble("" + val);
116:                        item.col1 = vd;
117:                    } catch (Exception e) {
118:                    }
119:                } else if (col == 1) {
120:                    item.col2 = (String) val;
121:                } else if (col == 2) {
122:                    item.col3 = (Integer) val;
123:                } else if (col == 5) {
124:                    item.checked = (Boolean) val;
125:                }
126:
127:                // must notify table that data has changed
128:                fireTableDataChanged();
129:                fireTableModelHasChanged();
130:            }
131:
132:            @Override
133:            public String getColumnName(int column) {
134:                if (column >= 0 && column < COLUMN_NAMES.length)
135:                    return COLUMN_NAMES[column];
136:                return "Bad column " + column;
137:            }
138:
139:            /*
140:            public int compareForColumnSort(int pos1, int pos2, int col)
141:            {
142:            if(col==0 || col>=2)
143:            {
144:             double v1 = Double.parseDouble(""+getValueAt(pos1, col));
145:             double v2 = Double.parseDouble(""+getValueAt(pos2, col));
146:             if(v1==v2) return 0;
147:             if(v1>v2) return 1;
148:             return -1;
149:            }
150:            else
151:            {
152:             String v1 = ""+getValueAt(pos1, col);
153:             String v2 = ""+getValueAt(pos2, col);
154:             return v1.compareTo(v2);
155:            }
156:            // return 0;
157:
158:            }*/
159:
160:            // Selection implementation
161:            //
162:            @Override
163:            public void setRowSelection(int row, boolean isSelected) {
164:                TestModelItem item = getItemAt(row);
165:                item.selected = isSelected;
166:            }
167:
168:            @Override
169:            public boolean isRowSelected(int row) {
170:                TestModelItem item = getItemAt(row);
171:                return item.selected;
172:            }
173:
174:            @Override
175:            public void clearRowSelection() {
176:                synchronized (items) {
177:                    for (int i = 0; i < getRowCount(); i++) {
178:                        TestModelItem item = getItemAt(i);
179:                        item.selected = false;
180:                    }
181:                }
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.