Source Code Cross Referenced for DimensionAdapter.java in  » XML-UI » xmlgui » org » beryl » gui » builder » 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 » XML UI » xmlgui » org.beryl.gui.builder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Beryl - A web platform based on XML, XSLT and Java
003:         * This file is part of the Beryl XML GUI
004:         *
005:         * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
020:         */
021:
022:        package org.beryl.gui.builder;
023:
024:        import java.awt.Dimension;
025:        import java.awt.GridLayout;
026:        import java.awt.Point;
027:
028:        import org.beryl.gui.GUIException;
029:        import org.beryl.gui.Widget;
030:        import org.beryl.gui.model.MapDataModel;
031:        import org.beryl.gui.model.ModelChangeEvent;
032:        import org.beryl.gui.model.ModelChangeListener;
033:        import org.beryl.gui.model.TableRow;
034:        import org.beryl.gui.table.TableEditor;
035:        import org.beryl.gui.table.TableRenderer;
036:        import org.beryl.gui.validators.IntegerValidator;
037:        import org.beryl.gui.widgets.Label;
038:        import org.beryl.gui.widgets.Panel;
039:        import org.beryl.gui.widgets.Table;
040:        import org.beryl.gui.widgets.TextField;
041:        import org.w3c.dom.Document;
042:        import org.w3c.dom.Element;
043:
044:        public class DimensionAdapter implements  PropertyAdapter {
045:            private TableRenderer dimensionRenderer = null;
046:            private TableEditor dimensionEditor = null;
047:
048:            private class DimensionRenderer implements  TableRenderer {
049:                public Widget getRenderer(Table table, Object value,
050:                        boolean isSelected, boolean hasFocus, TableRow row,
051:                        String key) throws GUIException {
052:                    Label label = new Label(null, null);
053:                    if (value instanceof  Dimension) {
054:                        Dimension dimension = (Dimension) value;
055:                        label.setProperty("text", (int) dimension.getWidth()
056:                                + ", " + (int) dimension.getHeight());
057:                    } else {
058:                        Point point = (Point) value;
059:                        label.setProperty("text", point.x + ", " + point.y);
060:                    }
061:
062:                    return label;
063:                }
064:            };
065:
066:            private class DimensionEditor implements  TableEditor {
067:                public Widget getEditor(Table table, Object value,
068:                        TableRow row, String key) throws GUIException {
069:                    final MapDataModel dataModel = new MapDataModel();
070:
071:                    if (value instanceof  Dimension) {
072:                        final Dimension dimension = (Dimension) value;
073:
074:                        dataModel.setValue("width", String
075:                                .valueOf((int) dimension.getWidth()));
076:                        dataModel.setValue("height", String
077:                                .valueOf((int) dimension.getHeight()));
078:                        dataModel.setValue("value", value);
079:
080:                        dataModel
081:                                .addModelChangeListener(new ModelChangeListener() {
082:                                    public void modelChanged(ModelChangeEvent e)
083:                                            throws GUIException {
084:                                        try {
085:                                            int width = Integer
086:                                                    .parseInt((String) dataModel
087:                                                            .getValue("width"));
088:                                            int height = Integer
089:                                                    .parseInt((String) dataModel
090:                                                            .getValue("height"));
091:
092:                                            dimension.setSize(width, height);
093:                                        } catch (NumberFormatException ex) {
094:                                            /* Ignore */
095:                                        }
096:                                    }
097:                                });
098:                    } else {
099:                        final Point point = (Point) value;
100:
101:                        dataModel.setValue("width", String.valueOf(point.x));
102:                        dataModel.setValue("height", String.valueOf(point.y));
103:                        dataModel.setValue("value", value);
104:
105:                        dataModel
106:                                .addModelChangeListener(new ModelChangeListener() {
107:                                    public void modelChanged(ModelChangeEvent e)
108:                                            throws GUIException {
109:                                        try {
110:                                            int x = Integer
111:                                                    .parseInt((String) dataModel
112:                                                            .getValue("width"));
113:                                            int y = Integer
114:                                                    .parseInt((String) dataModel
115:                                                            .getValue("height"));
116:
117:                                            point.setLocation(x, y);
118:                                        } catch (NumberFormatException ex) {
119:                                            /* Ignore */
120:                                        }
121:                                    }
122:                                });
123:                    }
124:
125:                    Panel panel = new Panel(null, null);
126:                    panel.setProperty("layout", new GridLayout(1, 2));
127:                    TextField widthField = new TextField(panel, null);
128:                    widthField.addValidator(new IntegerValidator());
129:                    widthField.setProperty("key", "width");
130:                    TextField heightField = new TextField(panel, null);
131:                    heightField.addValidator(new IntegerValidator());
132:                    heightField.setProperty("key", "height");
133:                    panel.addChild(widthField, null);
134:                    panel.addChild(heightField, null);
135:                    panel.recursiveSetDataModel(dataModel);
136:
137:                    widthField.finalizeConstruction();
138:                    heightField.finalizeConstruction();
139:
140:                    return panel;
141:                }
142:            };
143:
144:            public DimensionAdapter() {
145:                dimensionRenderer = new DimensionRenderer();
146:                dimensionEditor = new DimensionEditor();
147:            }
148:
149:            public TableEditor getEditor() {
150:                return dimensionEditor;
151:            }
152:
153:            public TableRenderer getRenderer() {
154:                return dimensionRenderer;
155:            }
156:
157:            public Object toValue(Object value, Element propertyNode) {
158:                return value;
159:            }
160:
161:            public void toDOM(Object value, Element propertyNode) {
162:                Document document = propertyNode.getOwnerDocument();
163:
164:                if (value instanceof  Dimension) {
165:                    Dimension dimension = (Dimension) value;
166:
167:                    Element widthNode = document.createElement("width");
168:                    Element heightNode = document.createElement("height");
169:                    propertyNode.appendChild(widthNode);
170:                    propertyNode.appendChild(heightNode);
171:                    widthNode.appendChild(document.createTextNode(String
172:                            .valueOf((int) dimension.getWidth())));
173:                    heightNode.appendChild(document.createTextNode(String
174:                            .valueOf((int) dimension.getHeight())));
175:                } else {
176:                    Point point = (Point) value;
177:
178:                    Element xNode = document.createElement("x");
179:                    Element yNode = document.createElement("y");
180:                    propertyNode.appendChild(xNode);
181:                    propertyNode.appendChild(yNode);
182:                    xNode.appendChild(document.createTextNode(String
183:                            .valueOf(point.x)));
184:                    yNode.appendChild(document.createTextNode(String
185:                            .valueOf(point.y)));
186:                }
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.