Source Code Cross Referenced for GuiBuilder.java in  » GIS » geonetwork » org » fao » gast » gui » 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 » GIS » geonetwork » org.fao.gast.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //==============================================================================
002:        //===	Copyright (C) 2001-2007 Food and Agriculture Organization of the
003:        //===	United Nations (FAO-UN), United Nations World Food Programme (WFP)
004:        //===	and United Nations Environment Programme (UNEP)
005:        //===
006:        //===	This program is free software; you can redistribute it and/or modify
007:        //===	it under the terms of the GNU General Public License as published by
008:        //===	the Free Software Foundation; either version 2 of the License, or (at
009:        //===	your option) any later version.
010:        //===
011:        //===	This program is distributed in the hope that it will be useful, but
012:        //===	WITHOUT ANY WARRANTY; without even the implied warranty of
013:        //===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:        //===	General Public License for more details.
015:        //===
016:        //===	You should have received a copy of the GNU General Public License
017:        //===	along with this program; if not, write to the Free Software
018:        //===	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019:        //===
020:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021:        //===	Rome - Italy. email: geonetwork@osgeo.org
022:        //==============================================================================
023:
024:        package org.fao.gast.gui;
025:
026:        import java.io.File;
027:        import java.util.ArrayList;
028:        import java.util.HashMap;
029:        import java.util.List;
030:        import javax.swing.Icon;
031:        import javax.swing.ImageIcon;
032:        import javax.swing.JButton;
033:        import jeeves.utils.Xml;
034:        import org.fao.gast.gui.panels.FormPanel;
035:        import org.jdom.Element;
036:
037:        //==============================================================================
038:
039:        public class GuiBuilder {
040:            //---------------------------------------------------------------------------
041:            //---
042:            //--- Constructor
043:            //---
044:            //---------------------------------------------------------------------------
045:
046:            public GuiBuilder(String appPath, ViewPanel view, WorkPanel work) {
047:                this .appPath = appPath;
048:
049:                viewPanel = view;
050:                workPanel = work;
051:            }
052:
053:            //---------------------------------------------------------------------------
054:            //---
055:            //--- API methods
056:            //---
057:            //---------------------------------------------------------------------------
058:
059:            public void build(String guiFile) throws Exception {
060:                Element root = Xml.loadFile(appPath + File.separator + guiFile);
061:
062:                packag = root.getChild("class").getAttributeValue("package");
063:
064:                for (Object precon : root.getChildren("precon"))
065:                    addPrecon((Element) precon);
066:
067:                for (Object cont : root.getChildren("container"))
068:                    addContainer((Element) cont);
069:            }
070:
071:            //---------------------------------------------------------------------------
072:            //---
073:            //--- Private methods
074:            //---
075:            //---------------------------------------------------------------------------
076:
077:            private void addPrecon(Element precon) {
078:                Precon p = new Precon();
079:
080:                p.type = precon.getAttributeValue("type");
081:                p.image = retrieveImage(precon.getChildText("image"));
082:                p.tip = precon.getChildText("tip");
083:
084:                hmPrecons.put(p.type, p);
085:            }
086:
087:            //---------------------------------------------------------------------------
088:
089:            private void addContainer(Element cont) throws Exception {
090:                String image = cont.getChildText("image");
091:                String label = cont.getChildText("label");
092:
093:                Object node = viewPanel.addContainer(label,
094:                        retrieveImage(image));
095:
096:                for (Object form : cont.getChildren("form"))
097:                    addForm(node, (Element) form);
098:            }
099:
100:            //---------------------------------------------------------------------------
101:
102:            private void addForm(Object cont, Element form) throws Exception {
103:                String id = form.getChildText("id");
104:                String image = form.getChildText("image");
105:                String label = form.getChildText("label");
106:                String title = form.getChildText("title");
107:                String clazz = form.getChildText("class");
108:                String descr = form.getChildText("description");
109:
110:                FormPanel formPanel = buildForm(clazz);
111:                List<JButton> buttons = buildButtons(
112:                        form.getChildren("button"), formPanel);
113:                Precon precon = getPrecon(form.getChild("precon"));
114:
115:                formPanel.init(title, descr, buttons, precon.image, precon.tip);
116:                workPanel.add(id, formPanel);
117:                viewPanel.addForm(cont, id, label, retrieveImage(image));
118:            }
119:
120:            //---------------------------------------------------------------------------
121:
122:            private FormPanel buildForm(String className) throws Exception {
123:                Class clazz = Class.forName(packag + "." + className);
124:
125:                return (FormPanel) clazz.newInstance();
126:            }
127:
128:            //---------------------------------------------------------------------------
129:
130:            private List<JButton> buildButtons(List buttons, FormPanel form) {
131:                ArrayList<JButton> al = new ArrayList<JButton>();
132:
133:                for (Object button : buttons)
134:                    al.add(buildButton((Element) button, form));
135:
136:                return al;
137:            }
138:
139:            //---------------------------------------------------------------------------
140:
141:            private JButton buildButton(Element button, FormPanel form) {
142:                String image = button.getChildText("image");
143:                String label = button.getChildText("label");
144:                String action = button.getChildText("action");
145:
146:                JButton btn = new JButton(label, retrieveImage(image));
147:                btn.setActionCommand(action);
148:                btn.addActionListener(form);
149:
150:                return btn;
151:            }
152:
153:            //---------------------------------------------------------------------------
154:
155:            private Precon getPrecon(Element precon) {
156:                String type = precon.getAttributeValue("type");
157:                Precon p = hmPrecons.get(type);
158:
159:                return p;
160:            }
161:
162:            //---------------------------------------------------------------------------
163:
164:            private Icon retrieveImage(String image) {
165:                if (image == null)
166:                    return null;
167:
168:                if (hmImages.containsKey(image))
169:                    return hmImages.get(image);
170:
171:                ImageIcon icon = new ImageIcon(appPath + "/gast/images/"
172:                        + image);
173:                hmImages.put(image, icon);
174:
175:                return icon;
176:            }
177:
178:            //---------------------------------------------------------------------------
179:            //---
180:            //--- Variables
181:            //---
182:            //---------------------------------------------------------------------------
183:
184:            private String appPath;
185:            private String packag;
186:
187:            private ViewPanel viewPanel;
188:            private WorkPanel workPanel;
189:
190:            private HashMap<String, Icon> hmImages = new HashMap<String, Icon>();
191:            private HashMap<String, Precon> hmPrecons = new HashMap<String, Precon>();
192:        }
193:
194:        //==============================================================================
195:
196:        class Precon {
197:            public String type;
198:            public Icon image;
199:            public String tip;
200:        }
201:
202:        //==============================================================================
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.