Source Code Cross Referenced for SwingDisplay.java in  » Scripting » Kawa » gnu » kawa » swingviews » 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 » Scripting » Kawa » gnu.kawa.swingviews 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package gnu.kawa.swingviews;
002:
003:        import gnu.kawa.models.*;
004:        import gnu.kawa.models.Box;
005:        import javax.swing.*;
006:        import javax.swing.text.*;
007:        import java.awt.Component;
008:        import java.awt.event.*;
009:        import gnu.mapping.Procedure;
010:
011:        public class SwingDisplay extends Display {
012:            static final SwingDisplay instance = new SwingDisplay();
013:
014:            public static Display getInstance() {
015:                return instance;
016:            }
017:
018:            public Window makeWindow() {
019:                SwingFrame window = new SwingFrame(null, null, null);
020:                window.display = this ;
021:                return window;
022:            }
023:
024:            public void addButton(Button model, Object where) {
025:                addView(new SwingButton(model), where);
026:            }
027:
028:            public void addLabel(Label model, Object where) {
029:                addView(new SwingLabel(model), where);
030:            }
031:
032:            public void addImage(DrawImage model, Object where) {
033:                addView(new JLabel(new ImageIcon(model.getImage())), where);
034:            }
035:
036:            public void addText(Text model, Object where) {
037:                addView(new JTextField(getSwingDocument(model), null, 50),
038:                        where);
039:            }
040:
041:            private static java.util.WeakHashMap documents = null;
042:
043:            static synchronized javax.swing.text.Document getSwingDocument(
044:                    Text model) {
045:                if (documents == null)
046:                    documents = new java.util.WeakHashMap();
047:                Object existing = documents.get(model);
048:                if (existing != null)
049:                    return (javax.swing.text.Document) existing;
050:                javax.swing.text.Document doc = new javax.swing.text.PlainDocument(
051:                        new SwingContent(model.buffer));
052:                documents.put(model, doc);
053:                return doc;
054:            }
055:
056:            public void addBox(Box model, Object where) {
057:                addView(new SwingBox(model, this ), where);
058:            }
059:
060:            public void addSpacer(Spacer model, Object where) {
061:                addView(new javax.swing.Box.Filler(model.getMinimumSize(),
062:                        model.getPreferredSize(), model.getMaximumSize()),
063:                        where);
064:            }
065:
066:            public void addView(Object view, Object where) {
067:                ((java.awt.Container) where).add((Component) view);
068:            }
069:
070:            public static ActionListener makeActionListener(Object command) {
071:                if (command instanceof  ActionListener)
072:                    return (ActionListener) command;
073:                return new ProcActionListener((Procedure) command);
074:            }
075:
076:            public Model coerceToModel(Object component) {
077:                if (component instanceof  Component)
078:                    return new ComponentModel((Component) component);
079:                if (component instanceof  Paintable)
080:                    // Kludge - should create a Viewable.  FIXME.
081:                    return new ComponentModel(new SwingPaintable(
082:                            (Paintable) component));
083:                return super .coerceToModel(component);
084:            }
085:        }
086:
087:        class ProcActionListener implements  ActionListener {
088:            Procedure proc;
089:
090:            public ProcActionListener(Procedure proc) {
091:                this .proc = proc;
092:            }
093:
094:            public void actionPerformed(ActionEvent e) {
095:                try {
096:                    proc.apply1(e);
097:                } catch (Throwable ex) {
098:                    throw new gnu.mapping.WrappedException(ex);
099:                }
100:            }
101:        }
102:
103:        class SwingBox extends javax.swing.Box implements  ModelListener {
104:            Box model;
105:
106:            public SwingBox(Box model, Display display) {
107:                super (model.getAxis());
108:                model.addListener(this );
109:                Viewable cellSpacing = model.getCellSpacing();
110:                int n = model.getComponentCount();
111:                for (int i = 0; i < n; i++) {
112:                    if (i > 0 && cellSpacing != null)
113:                        cellSpacing.makeView(display, this );
114:                    model.getComponent(i).makeView(display, this );
115:                }
116:            }
117:
118:            public void modelUpdated(Model model, Object key) {
119:            }
120:        }
121:
122:        class SwingLabel extends JLabel implements  ModelListener {
123:            Label model;
124:
125:            public SwingLabel(Label model) {
126:                this .model = model;
127:                String text = model.getText();
128:                if (text != null)
129:                    super .setText(text);
130:                model.addListener(this );
131:            }
132:
133:            public void modelUpdated(Model model, Object key) {
134:                if (key == "text" && model == this .model)
135:                    super .setText(this .model.getText());
136:            }
137:
138:            public void setText(String text) {
139:                if (model == null)
140:                    super .setText(text);
141:                else
142:                    model.setText(text);
143:            }
144:        }
145:
146:        /** A Model wrapper around a Swing/AWT Component. */
147:
148:        class ComponentModel extends Model {
149:            Component component;
150:
151:            public ComponentModel(Component component) {
152:                this .component = component;
153:            }
154:
155:            public void makeView(Display display, Object where) {
156:                display.addView(component, where);
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.