Source Code Cross Referenced for TreeIconDemo.java in  » Web-Framework » webonswing » examples » swingdemos » 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 » Web Framework » webonswing » examples.swingdemos 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package examples.swingdemos;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import java.io.*;
006:        import java.net.*;
007:
008:        import javax.swing.*;
009:        import javax.swing.event.*;
010:        import javax.swing.tree.*;
011:
012:        public class TreeIconDemo extends JFrame {
013:            private JEditorPane htmlPane;
014:            static boolean DEBUG = false;
015:            URL helpURL;
016:
017:            public TreeIconDemo() {
018:                super ("TreeIconDemo");
019:
020:                //Create the nodes.
021:                DefaultMutableTreeNode top = new DefaultMutableTreeNode(
022:                        "The Java Series");
023:                createNodes(top);
024:
025:                //Create a tree that allows one selection at a time.
026:                final JTree tree = new JTree(top);
027:                tree.getSelectionModel().setSelectionMode(
028:                        TreeSelectionModel.SINGLE_TREE_SELECTION);
029:
030:                /*
031:                 * Set the icon for leaf nodes.
032:                 * Note: In the Swing 1.0.x release, we used
033:                 * swing.plaf.basic.BasicTreeCellRenderer.
034:                 */
035:                DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
036:                renderer.setLeafIcon(new ImageIcon("images/middle.gif"));
037:                tree.setCellRenderer(renderer);
038:
039:                //Listen for when the selection changes.
040:                tree.addTreeSelectionListener(new TreeSelectionListener() {
041:                    public void valueChanged(TreeSelectionEvent e) {
042:                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
043:                                .getLastSelectedPathComponent();
044:
045:                        if (node == null)
046:                            return;
047:
048:                        Object nodeInfo = node.getUserObject();
049:                        if (node.isLeaf()) {
050:                            BookInfo book = (BookInfo) nodeInfo;
051:                            displayURL(book.bookURL);
052:                            if (DEBUG) {
053:                                System.out.print(book.bookURL + ":  \n    ");
054:                            }
055:                        } else {
056:                            displayURL(helpURL);
057:                        }
058:                        if (DEBUG) {
059:                            System.out.println(nodeInfo.toString());
060:                        }
061:                    }
062:                });
063:
064:                //Create the scroll pane and add the tree to it. 
065:                JScrollPane treeView = new JScrollPane(tree);
066:
067:                //Create the HTML viewing pane.
068:                htmlPane = new JEditorPane();
069:                htmlPane.setEditable(false);
070:                initHelp();
071:                JScrollPane htmlView = new JScrollPane(htmlPane);
072:
073:                //Add the scroll panes to a split pane.
074:                JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
075:                splitPane.setTopComponent(treeView);
076:                splitPane.setBottomComponent(htmlView);
077:                Dimension minimumSize = new Dimension(100, 50);
078:                htmlView.setMinimumSize(minimumSize);
079:                treeView.setMinimumSize(minimumSize);
080:                splitPane.setDividerLocation(100); //XXX: ignored in some releases
081:                //of Swing. bug 4101306
082:                //workaround for bug 4101306:
083:                //treeView.setPreferredSize(new Dimension(100, 100)); 
084:
085:                splitPane.setPreferredSize(new Dimension(500, 300));
086:
087:                //Add the split pane to this frame.
088:                getContentPane().add(splitPane, BorderLayout.CENTER);
089:            }
090:
091:            private class BookInfo {
092:                public String bookName;
093:                public URL bookURL;
094:                public String prefix = "file:" + System.getProperty("user.dir")
095:                        + System.getProperty("file.separator");
096:
097:                public BookInfo(String book, String filename) {
098:                    bookName = book;
099:                    try {
100:                        bookURL = new URL(prefix + filename);
101:                    } catch (java.net.MalformedURLException exc) {
102:                        System.err.println("Attempted to create a BookInfo "
103:                                + "with a bad URL: " + bookURL);
104:                        bookURL = null;
105:                    }
106:                }
107:
108:                public String toString() {
109:                    return bookName;
110:                }
111:            }
112:
113:            private void initHelp() {
114:                String s = null;
115:                try {
116:                    s = "file:" + System.getProperty("user.dir")
117:                            + System.getProperty("file.separator")
118:                            + "TreeDemoHelp.html";
119:                    if (DEBUG) {
120:                        System.out.println("Help URL is " + s);
121:                    }
122:                    helpURL = new URL(s);
123:                    displayURL(helpURL);
124:                } catch (Exception e) {
125:                    System.err.println("Couldn't create help URL: " + s);
126:                }
127:            }
128:
129:            void displayURL(URL url) {
130:                try {
131:                    htmlPane.setPage(url);
132:                } catch (IOException e) {
133:                    System.err.println("Attempted to read a bad URL: " + url);
134:                }
135:            }
136:
137:            private void createNodes(DefaultMutableTreeNode top) {
138:                DefaultMutableTreeNode category = null;
139:                DefaultMutableTreeNode book = null;
140:
141:                category = new DefaultMutableTreeNode(
142:                        "Books for Java Programmers");
143:                top.add(category);
144:
145:                //original Tutorial
146:                book = new DefaultMutableTreeNode(
147:                        new BookInfo(
148:                                "The Java Tutorial: Object-Oriented Programming for the Internet",
149:                                "tutorial.html"));
150:                category.add(book);
151:
152:                //Tutorial Continued
153:                book = new DefaultMutableTreeNode(new BookInfo(
154:                        "The Java Tutorial Continued: The Rest of the JDK",
155:                        "tutorialcont.html"));
156:                category.add(book);
157:
158:                //JFC Swing Tutorial
159:                book = new DefaultMutableTreeNode(new BookInfo(
160:                        "The JFC Swing Tutorial: A Guide to Constructing GUIs",
161:                        "swingtutorial.html"));
162:                category.add(book);
163:
164:                //Arnold/Gosling
165:                book = new DefaultMutableTreeNode(new BookInfo(
166:                        "The Java Programming Language", "arnold.html"));
167:                category.add(book);
168:
169:                //FAQ
170:                book = new DefaultMutableTreeNode(new BookInfo("The Java FAQ",
171:                        "faq.html"));
172:                category.add(book);
173:
174:                //Chan/Lee
175:                book = new DefaultMutableTreeNode(new BookInfo(
176:                        "The Java Class Libraries: An Annotated Reference",
177:                        "chanlee.html"));
178:                category.add(book);
179:
180:                //Threads
181:                book = new DefaultMutableTreeNode(
182:                        new BookInfo(
183:                                "Concurrent Programming in Java: Design Principles and Patterns",
184:                                "thread.html"));
185:                category.add(book);
186:
187:                category = new DefaultMutableTreeNode(
188:                        "Books for Java Implementers");
189:                top.add(category);
190:
191:                //VM
192:                book = new DefaultMutableTreeNode(new BookInfo(
193:                        "The Java Virtual Machine Specification", "vm.html"));
194:                category.add(book);
195:
196:                //Language Spec
197:                book = new DefaultMutableTreeNode(new BookInfo(
198:                        "The Java Language Specification", "jls.html"));
199:                category.add(book);
200:            }
201:
202:            public static void main(String[] args) {
203:                JFrame frame = new TreeIconDemo();
204:
205:                frame.addWindowListener(new WindowAdapter() {
206:                    public void windowClosing(WindowEvent e) {
207:                        System.exit(0);
208:                    }
209:                });
210:
211:                frame.pack();
212:                frame.setVisible(true);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.