Source Code Cross Referenced for Test.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 class Test extends JFrame {
011:
012:            TestModel mod;
013:            SortableTableModel stm;
014:            JCheckBox simpleViewCB = new JCheckBox("Simple view", false);
015:
016:            public Test() {
017:                super ();
018:                this .setTitle("Test sortable table");
019:
020:                mod = new TestModel();
021:                stm = new SortableTableModel(mod, 0, true);
022:
023:                final JTable table = new JTable(stm) {
024:                    public Component _prepareEditor(TableCellEditor editor,
025:                            int row, int col) {
026:                        Component comp = editor.getTableCellEditorComponent(
027:                                this , "", true, row, col);
028:                        return comp;
029:                    }
030:                };
031:                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
032:                stm.installGUI(table);
033:
034:                UniversalTableCellRenderer utr = new UniversalTableCellRenderer(
035:                        stm);
036:                table.setDefaultRenderer(Object.class, utr);
037:                table.setDefaultRenderer(Double.class, utr);
038:                table.setDefaultRenderer(Integer.class, utr);
039:
040:                UniversalTableEditor ute = new UniversalTableEditor();
041:                table.setDefaultEditor(Object.class, ute);
042:                table.setDefaultEditor(Double.class, ute);
043:                table.setDefaultEditor(Integer.class, ute);
044:
045:                table.setFont(new Font("Dialog", Font.PLAIN, 14));
046:                table.setRowHeight(30);
047:
048:                JPanel content = new JPanel(new BorderLayout());
049:                setContentPane(content);
050:                content.add(new JScrollPane(table), BorderLayout.CENTER);
051:
052:                JPanel controlPanel = new JPanel();
053:                content.add(controlPanel, BorderLayout.SOUTH);
054:
055:                JButton addBT = new JButton("Add");
056:                controlPanel.add(addBT);
057:                addBT.addActionListener(new ActionListener() {
058:                    public void actionPerformed(ActionEvent e) {
059:                        mod.addRandom();
060:                    }
061:                });
062:
063:                JButton removeBT = new JButton("Remove Last");
064:                controlPanel.add(removeBT);
065:                removeBT.addActionListener(new ActionListener() {
066:                    public void actionPerformed(ActionEvent e) {
067:                        mod.removeLast();
068:                    }
069:                });
070:
071:                JButton removeSel = new JButton("Remove Selected");
072:                controlPanel.add(removeSel);
073:                removeSel.addActionListener(new ActionListener() {
074:                    public void actionPerformed(ActionEvent e) {
075:                        int[] sels = table.getSelectedRows();
076:                        // retrieve the selected items list
077:                        TestModelItem[] selit = new TestModelItem[sels.length];
078:                        for (int i = 0; i < sels.length; i++) {
079:                            int pos = stm
080:                                    .getIndexInUnsortedFromTablePos(sels[i]);
081:                            selit[i] = mod.getItemAt(pos);
082:                        }
083:
084:                        // remove them, per reference, to avoid index iteration conflicts
085:                        for (int i = 0; i < sels.length; i++) {
086:                            mod.remove(selit[i]);
087:                        }
088:                    }
089:                });
090:
091:                // search
092:                final MultiSearchPanel searchPanel = new MultiSearchPanel(
093:                        "Filter: ", null, stm);
094:                JPanel wrap = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
095:                //JPanel wrap = new JPanel();
096:                //wrap.setLayout(new BoxLayout(wrap, BoxLayout.X_AXIS)); //new FlowLayout(FlowLayout.LEFT,0,0));
097:                wrap.add(searchPanel);
098:                wrap.add(Box.createHorizontalStrut(40));
099:                wrap.add(simpleViewCB);
100:                simpleViewCB.setOpaque(false);
101:                simpleViewCB.addActionListener(new ActionListener() {
102:                    public void actionPerformed(ActionEvent e) {
103:                        if (!simpleViewCB.isSelected()) {
104:                            int[] allCols = new int[mod.getColumnCount()];
105:                            for (int i = 0; i < allCols.length; i++)
106:                                allCols[i] = i;
107:                            stm.setVisibleColumns(allCols);
108:                        } else {
109:                            stm.setVisibleColumns(new int[] { 0, 3 });
110:                        }
111:                        stm.setPreferredColumnSizesFromModel();
112:                    }
113:                });
114:
115:                add(wrap, BorderLayout.NORTH);
116:
117:                this .addWindowListener(new WindowAdapter() {
118:                    @Override
119:                    public void windowClosing(WindowEvent e) {
120:                        terminateFrame(); // calls System.exit();
121:                    }
122:
123:                    @Override
124:                    public void windowClosed(WindowEvent e) {
125:                        terminateFrame(); // calls System.exit();
126:                    }
127:                });
128:
129:                final Dimension screen = Toolkit.getDefaultToolkit()
130:                        .getScreenSize();
131:                this .setSize(800, 600);
132:                this .setLocation(180, 120);
133:                this .setVisible(true);
134:
135:                // must be visible
136:                EventQueue.invokeLater(new Runnable() {
137:                    public void run() {
138:                        searchPanel.getFirstTextField().requestFocus();
139:                        /*
140:                        table.setRowSelectionInterval(40, 40);
141:                        table.scrollRectToVisible(table.getCellRect(100, 0, true));*/
142:                    }
143:                });
144:
145:            } // Constructor
146:
147:            private void terminateFrame() {
148:                System.exit(0);
149:            }
150:
151:            public static void main(String[] arguments) {
152:                JFrame.setDefaultLookAndFeelDecorated(true);
153:                EventQueue.invokeLater(new Runnable() {
154:                    public void run() {
155:                        new Test();
156:                    }
157:                });
158:            }
159:
160:            public static void numericalTest() {
161:                // numerical test described by sun in an article, showing ULP and addition errors.
162:                //
163:                long t0 = System.currentTimeMillis();
164:                double f = 0.0;
165:                for (int i = 0; i <= 1000000000; i++) {
166:                    f += Math.sqrt(i);
167:                }
168:                System.out.println(f + ",  t="
169:                        + (t0 - System.currentTimeMillis()) / 1000 + " sec");
170:
171:                t0 = System.currentTimeMillis();
172:                double newsum;
173:                double sumerr = 0.0;
174:                double err, sum = 0;
175:                for (int i = 1; i <= 1000000000; i++) {
176:                    f = Math.sqrt(i);
177:                    newsum = sum + f;
178:                    err = (newsum - sum) - f;
179:                    sumerr += err;
180:                    sum = newsum;
181:                }
182:                System.out.println((sum - sumerr) + ",  t="
183:                        + (t0 - System.currentTimeMillis()) / 1000 + " sec");
184:
185:            } // main
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.