Source Code Cross Referenced for jxcomponentCTL.java in  » Swing-Library » OpenJX » org » openjx » jx » 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 » Swing Library » OpenJX » org.openjx.jx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2007 Jared Alexander Spigner
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
017:         *
018:         * jspigner@openjx.org
019:         *
020:         * jxcomponentCTL.java
021:         *
022:         * Created on June 8, 2007, 8:47 PM
023:         *
024:         */
025:
026:        package org.openjx.jx;
027:
028:        import java.awt.Color;
029:        import java.awt.Font;
030:
031:        import java.awt.event.ComponentEvent;
032:        import java.awt.event.ComponentAdapter;
033:
034:        import java.beans.PropertyChangeEvent;
035:
036:        import javax.swing.border.Border;
037:        import javax.swing.border.EtchedBorder;
038:        import javax.swing.border.TitledBorder;
039:        import javax.swing.BorderFactory;
040:
041:        import javax.swing.JComponent;
042:
043:        import org.openjx.core.JXObject;
044:        import org.openjx.core.VirtualMachine;
045:
046:        /**
047:         * This is the control class for the jxcomponent otherwise known as the 
048:         * JComponent.
049:         *
050:         * @author Jared Spigner
051:         */
052:        public class jxcomponentCTL extends JXControl {
053:
054:            /** 
055:             * This is the constructor for the jxcomponentCTL class.  It creates a new 
056:             * instance of jxcomponentCTL.
057:             *
058:             * @param vm points to an instance of the Virtual Machine.
059:             */
060:            public jxcomponentCTL(VirtualMachine vm) {
061:                super (vm);
062:            }
063:
064:            /**
065:             * This method is called when the compiler wishes to compile the
066:             * component into Java code.
067:             *
068:             * @param jxObject points to the JXObject in the stack we wish to compile
069:             * into Java.
070:             *
071:             * @return true on success, else false on failure.
072:             */
073:            public boolean Compile(JXObject jxObject) {
074:                if (jxObject.getObjectLink() == null) {
075:                    if (!this .instantiateObject(jxObject,
076:                            "javax.swing.JComponent", new Class[] {},
077:                            new Object[] {}))
078:                        return false;
079:                }
080:
081:                JComponent jComponent = (JComponent) jxObject.getObjectLink();
082:
083:                jComponent.setName(jxObject.getProperty("name"));
084:                jComponent.setBackground(this .jxTranslator
085:                        .ColorJX2Java(jxObject.getProperty("bgcolor")));
086:                jComponent.setForeground(this .jxTranslator
087:                        .ColorJX2Java(jxObject.getProperty("fgcolor")));
088:                jComponent.setSize(Integer.parseInt(jxObject
089:                        .getProperty("width")), Integer.parseInt(jxObject
090:                        .getProperty("height")));
091:                jComponent.setLocation(Integer.parseInt(jxObject
092:                        .getProperty("x")), Integer.parseInt(jxObject
093:                        .getProperty("y")));
094:                jComponent.setFont(new Font(jxObject.getProperty("fontFamily"),
095:                        this .jxTranslator.FontStyleJX2Java(jxObject
096:                                .getProperty("fontWeight")), Integer
097:                                .parseInt(jxObject.getProperty("fontSize"))));
098:
099:                if (!jxObject.getProperty("border").equals("none")) {
100:                    Color borderColor = this .jxTranslator.ColorJX2Java(jxObject
101:                            .getProperty("borderColor"));
102:                    String borderTitle = jxObject.getProperty("borderTitle");
103:                    String borderFontFamily = jxObject
104:                            .getProperty("borderTitleFontFamily");
105:                    int borderFontSize = Integer.parseInt(jxObject
106:                            .getProperty("borderTitleFontSize"));
107:                    int borderFontWeight = this .jxTranslator
108:                            .FontStyleJX2Java(jxObject
109:                                    .getProperty("borderTitleFontWeight"));
110:                    int borderTitleAlign = this .jxTranslator
111:                            .BorderTitleHAlignJX2Java(jxObject
112:                                    .getProperty("borderTitleAlign"));
113:                    int borderTitleVAlign = this .jxTranslator
114:                            .BorderTitleVAlignJX2Java(jxObject
115:                                    .getProperty("borderTitleVAlign"));
116:
117:                    if (jxObject.getProperty("border").equals("line"))
118:                        jComponent.setBorder(BorderFactory
119:                                .createLineBorder(borderColor));
120:                    else if (jxObject.getProperty("border").equals("raised"))
121:                        jComponent.setBorder(BorderFactory
122:                                .createEtchedBorder(EtchedBorder.RAISED));
123:                    else if (jxObject.getProperty("border").equals("lowered"))
124:                        jComponent.setBorder(BorderFactory
125:                                .createEtchedBorder(EtchedBorder.LOWERED));
126:                    else if (jxObject.getProperty("border").equals("titled")) {
127:                        jComponent.setBorder(BorderFactory.createTitledBorder(
128:                                BorderFactory.createLineBorder(borderColor),
129:                                borderTitle, borderTitleAlign,
130:                                borderTitleVAlign, new Font(borderFontFamily,
131:                                        borderFontWeight, borderFontSize)));
132:                    } else if (jxObject.getProperty("border").equals(
133:                            "raised-lowered")) {
134:                        jComponent
135:                                .setBorder(BorderFactory
136:                                        .createCompoundBorder(
137:                                                BorderFactory
138:                                                        .createEtchedBorder(EtchedBorder.RAISED),
139:                                                BorderFactory
140:                                                        .createEtchedBorder(EtchedBorder.LOWERED)));
141:                    }
142:                }
143:
144:                final JXObject bindObject = jxObject;
145:                final JComponent bindComponent = jComponent;
146:
147:                /** bind JXObject properties to this JComponent. */
148:                jxObject.addPropertyChangeListener(new JXPropertyAdapter() {
149:                    public void propertyChange(PropertyChangeEvent evt) {
150:                        if (evt.getPropertyName().equals("name")) {
151:                            bindComponent.setName((String) evt.getNewValue());
152:                        } else if (evt.getPropertyName().equals("bgcolor")) {
153:                            bindComponent.setBackground(this .jxTranslator
154:                                    .ColorJX2Java((String) evt.getNewValue()));
155:                        } else if (evt.getPropertyName().equals("fgcolor")) {
156:                            bindComponent.setForeground(this .jxTranslator
157:                                    .ColorJX2Java((String) evt.getNewValue()));
158:                        } else if (evt.getPropertyName().equals("fontFamily")) {
159:                            bindComponent.setFont(new Font((String) evt
160:                                    .getNewValue(), bindComponent.getFont()
161:                                    .getStyle(), bindComponent.getFont()
162:                                    .getSize()));
163:                        } else if (evt.getPropertyName().equals("fontWeight")) {
164:                            bindComponent.setFont(new Font(bindComponent
165:                                    .getFont().getFamily(), this .jxTranslator
166:                                    .FontStyleJX2Java(((String) evt
167:                                            .getNewValue())), bindComponent
168:                                    .getFont().getSize()));
169:                        } else if (evt.getPropertyName().equals("fontSize")) {
170:                            bindComponent.setFont(new Font(bindComponent
171:                                    .getFont().getFamily(), bindComponent
172:                                    .getFont().getStyle(), Integer
173:                                    .parseInt(((String) evt.getNewValue()))));
174:                        }
175:                    }
176:                });
177:
178:                /** bind JComponent properties to this JXObject. */
179:                jComponent.addPropertyChangeListener(new JXPropertyAdapter() {
180:                    public void propertyChange(PropertyChangeEvent evt) {
181:                        if (evt.getPropertyName().equals("background")) {
182:                            bindObject.setProperty("background",
183:                                    this .jxTranslator
184:                                            .ColorJava2JX(bindComponent
185:                                                    .getBackground()));
186:                        } else if (evt.getPropertyName().equals("foreground")) {
187:                            bindObject.setProperty("background",
188:                                    this .jxTranslator
189:                                            .ColorJava2JX(bindComponent
190:                                                    .getForeground()));
191:                        } else if (evt.getPropertyName().equals("font")) {
192:                            bindObject.setProperty("fontFamily", bindComponent
193:                                    .getFont().getFamily());
194:                            bindObject.setProperty("fontSize", ""
195:                                    + bindComponent.getFont().getSize());
196:                            bindObject.setProperty("fontWeight",
197:                                    this .jxTranslator
198:                                            .FontStyleJava2JX(bindComponent
199:                                                    .getFont()));
200:                        } else if (evt.getPropertyName().equals("name")) {
201:                            bindObject.setProperty("name", bindComponent
202:                                    .getName());
203:                        }
204:                    }
205:                });
206:
207:                jComponent.addComponentListener(new ComponentAdapter() {
208:                    public void componentMoved(ComponentEvent e) {
209:                        bindObject.setProperty("x", String
210:                                .valueOf(bindComponent.getX()));
211:                        bindObject.setProperty("y", String
212:                                .valueOf(bindComponent.getY()));
213:                    }
214:
215:                    public void componentResized(ComponentEvent e) {
216:                        bindObject.setProperty("width", String
217:                                .valueOf(bindComponent.getWidth()));
218:                        bindObject.setProperty("height", String
219:                                .valueOf(bindComponent.getHeight()));
220:                    }
221:
222:                    public void componentShown(ComponentEvent e) {
223:                        System.out.println("Shown");
224:                    }
225:
226:                    public void componentHidden(ComponentEvent e) {
227:                        System.out.println("Hidden");
228:                    }
229:                });
230:
231:                this .virtualMachine.getJXCompiler().scriptEngine.put(jComponent
232:                        .getName(), jComponent);
233:
234:                return true;
235:            }
236:
237:            /**
238:             * This method is called when the interpreter wishes to interpret the
239:             * component's script into Java code.
240:             *
241:             * @param jxObject points to the JXObject in the stack we wish to interpret
242:             * into Java.
243:             *
244:             * @return true on success, else false on failure.
245:             */
246:            public boolean Interpret(JXObject jxObject) {
247:                return true;
248:            }
249:
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.