Source Code Cross Referenced for ViewConfigParser.java in  » Science » Cougaar12_4 » org » cougaar » core » qos » frame » visualizer » util » 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 » Science » Cougaar12_4 » org.cougaar.core.qos.frame.visualizer.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.cougaar.core.qos.frame.visualizer.util;
002:
003:        import java.awt.Color;
004:        import java.awt.Dimension;
005:        import java.awt.Paint;
006:        import java.awt.geom.RectangularShape;
007:        import java.lang.reflect.Constructor;
008:        import java.util.HashMap;
009:        import java.util.StringTokenizer;
010:        import java.util.Vector;
011:
012:        import org.cougaar.core.qos.frame.visualizer.ContainerLabelRenderer;
013:        import org.cougaar.core.qos.frame.visualizer.LabelRenderer;
014:        import org.cougaar.core.qos.frame.visualizer.LabelRenderers;
015:        import org.cougaar.core.qos.frame.visualizer.ShapeContainer;
016:        import org.cougaar.core.qos.frame.visualizer.ShapeGraphic;
017:        import org.cougaar.core.qos.frame.visualizer.ShapeRenderer;
018:        import org.cougaar.core.qos.frame.visualizer.ShapeRenderers;
019:        import org.cougaar.core.qos.frame.visualizer.Shapes;
020:        import org.cougaar.core.qos.frame.visualizer.layout.ShapeLayout;
021:        import org.cougaar.core.qos.frame.visualizer.shapes.RoundRectangle;
022:        import org.cougaar.core.qos.frame.visualizer.test.FramePredicate;
023:        import org.xml.sax.Attributes;
024:
025:        /**
026:         * Created by IntelliJ IDEA.
027:         * User: mwalczak
028:         * Date: Apr 13, 2005
029:         * Time: 11:43:06 AM
030:         * To change this template use File | Settings | File Templates.
031:         */
032:
033:        /*
034:
035:         <window title="SiteA Viewer" w="800" h="700">
036:
037:         <shape name="circle1" class="java.awt.geom.Ellipse2D.Double" x="0" y="0" w="10" h="10"/>
038:         <shape name="circle2" class="java.awt.geom.Ellipse2D.Double" x="0" y="0" w="12" h="12"/>
039:         <shape name="Rect1" class="java.awt.geom.Rectangle2D.Double" x="0" y="0" w="10" h="10" />
040:         <shape name="RoundRect1" class="java.awt.geom.RoundRectangle2D.Double" x="0" y="0" w="10" h="10" arcw="3" arch="3" />>
041:
042:
043:         <labelrenderer name="defaultLabelRenderer" xoff="+2" yoff="+5" font="default" color="Color.blue"/>
044:         <labelrenderer name="jobLabelRenderer" xoff="+2" yoff="+5" font="default" color="Color.blue"/>
045:         <labelrenderer name="taskLabelRenderer" xoff="+2" yoff="+5" font="default" color="Color.blue"/>
046:         <labelrenderer name="hostLabelRenderer" xoff="+2" yoff="+5" font="default" color="Color.blue"/>
047:         <containerlabelrenderer name="queueLabelRenderer" xoff="+2" yoff="+2" font="default" color="Color.blue"/>
048:         <labelrenderer name="customerLabelRenderer" xoff="+2" yoff="+5" font="default" color="Color.blue"/>
049:
050:         <shaperenderer name="defaultRenderer" paint="Color.green" selectedpaint="Color.yellow" linewidth="2" bordered="true" filled="true"/>
051:         <shaperenderer name="processedJobRenderer" paint="Color.megenta" selectedpaint="Color.yellow" linewidth="2" bordered="true" filled="true" />
052:         <shaperenderer name="doneJobRenderer" paint="Color.green" selectedpaint="Color.yellow" linewidth="1" bordered="true" filled="true"/>
053:         <shaperenderer name="failedJobRenderer" paint="Color.red" selectedpaint="Color.yellow" linewidth="1" bordered="true" filled="true"/>
054:
055:
056:         <slotChangeListener name="jobWatcher" slot="status">
057:         <trigger value="busy" action="setrenderer" name="processedJobRenderer"/>
058:         <trigger value="busy" action="setshape" shape="circle2"/>
059:         <trigger value="idle" action="setrenderer" name="defaultRenderer"/>
060:         <trigger value="idle" action="setshape" shape="circle1"/>
061:         </slotChangeListener>
062:
063:
064:         <container id="root" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" shape="Rect1">
065:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.HorizontalLayout" left="2" right="2" bottom="5" top="10" hpadding="15" vpadding="5"/>
066:
067:         <container id="customer" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" shape="Rect1">
068:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.VerticalLayout" left="5" right="5" bottom="5" top="30" hpadding="5" vpadding="5"/>
069:         <framepredicate isa="customer" frameset="simulator" parentRelationship="contains"/>
070:
071:         <container id="job-queue" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" prototype="true" shape="RoundRect1">
072:
073:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.HorizontalBoxLayout" left="5" right="5" bottom="5" top="20" hpadding="10" vpadding="10"/>
074:         <framepredicate isa="queue" frameset="simulator" parentRelationship="contains"/>
075:
076:         <component id="job" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.ShapeGraphic" prototype="true" shape="circle1">
077:         <framepredicate isa="job" frameset="simulator" parentRelationship="ServicedAt"/>
078:         </component>
079:
080:         </container>
081:
082:         </container>
083:
084:
085:         <container id="siteContainer" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" shape="Rect1">
086:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.VerticalLayout" left="5" right="5" bottom="10" top="30" hpadding="10" vpadding="10"/>
087:         <framepredicate isa="site" frameset="simulator" name="Local"  parentRelationship="contains"/>
088:
089:
090:
091:         <container id="hostContainer" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" shape="Rect1" visible="false">
092:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.HorizontalLayout" left="5" right="5" bottom="5" top="15" hpadding="5" vpadding="5"/>
093:
094:         <container id="host" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.RectangularContainer" prototype="true" shape="Rect1">
095:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.HorizontalLayout" left="5" right="5" bottom="0" top="15" hpadding="5" vpadding="5"/>
096:         <framepredicate isa="host" frameset="simulator"  parentRelationship="contains"/>
097:
098:
099:
100:         <container id="queue" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" prototype="true" shape="RoundRect1">
101:
102:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.VerticalBoxLayout" left="5" right="5" bottom="2" top="20" hpadding="1" vpadding="1"/>
103:         <framepredicate isa="queue" frameset="simulator" parentRelationship="contains"/>
104:
105:         <component id="task" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.ShapeGraphic" prototype="true" shape="circle1">
106:         <framepredicate isa="task" frameset="simulator"  parentRelationship="ServicedAt"/>
107:         </component>
108:         </container>
109:         </container>
110:         </container>
111:
112:
113:
114:         <container id="queueGroup" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" shape="Rect1" visible="false">
115:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.VerticalLayout" left="2" right="2" bottom="2" top="2" hpadding="5" vpadding="5"/>
116:
117:         <container id="task-queue" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.ShapeContainer" shape="RoundRect1" prototype="true">
118:         <layout class="org.cougaar.core.qos.frame.visualizer.layout.HorizontalBoxLayout" left="2" right="2" bottom="2" top="20" hpadding="5" vpadding="5"/>
119:         <framepredicate isa="queue" frameset="simulator" parentRelationship="contains"/>
120:         <component id="task" idframeslot="name" class="org.cougaar.core.qos.frame.visualizer.ShapeGraphic" prototype="true" shape="circle1">
121:         <framepredicate isa="task" frameset="simulator"  parentRelationship="ServicedAt"/>
122:         </component>
123:         </container>
124:         </container>
125:         </container>
126:
127:
128:         </container>
129:
130:         </window>
131:         */
132:        public class ViewConfigParser extends XMLParser {
133:            public WindowSpec windowSpec;
134:            Vector containerStack;
135:            public ShapeContainer root;
136:            protected static HashMap colorNameMap = null;
137:            protected static SlotChangeListener lastSlotChangeListener = null;
138:
139:            Shapes shapes;
140:            LabelRenderers labelRenderers;
141:            ShapeRenderers shapeRenderers;
142:            SlotChangeListeners slotListeners;
143:
144:            public static class WindowSpec {
145:                String title = "";
146:                Dimension size;
147:
148:                public WindowSpec(String title, Dimension d) {
149:                    this .title = title;
150:                    this .size = d;
151:                }
152:
153:                public String getTitle() {
154:                    return title;
155:                }
156:
157:                public Dimension getSize() {
158:                    return size;
159:                }
160:            }
161:
162:            public ViewConfigParser() {
163:                super ();
164:                shapes = new Shapes();
165:                labelRenderers = new LabelRenderers();
166:                shapeRenderers = new ShapeRenderers();
167:                slotListeners = new SlotChangeListeners();
168:                containerStack = new Vector();
169:                if (colorNameMap == null)
170:                    initColorNameMap();
171:            }
172:
173:            public Shapes getShapes() {
174:                return shapes;
175:            }
176:
177:            public LabelRenderers getLabelRenderers() {
178:                return labelRenderers;
179:            }
180:
181:            public ShapeRenderers getShapeRenderers() {
182:                return shapeRenderers;
183:            }
184:
185:            public SlotChangeListeners getSlotListeners() {
186:                return slotListeners;
187:            }
188:
189:            protected void initColorNameMap() {
190:                colorNameMap = new HashMap();
191:                colorNameMap.put("Color.black", Color.black);
192:                colorNameMap.put("Color.BLACK", Color.BLACK);
193:                colorNameMap.put("Color.blue", Color.blue);
194:                colorNameMap.put("Color.BLUE", Color.BLUE);
195:                colorNameMap.put("Color.cyan", Color.cyan);
196:                colorNameMap.put("Color.CYAN", Color.CYAN);
197:                colorNameMap.put("Color.DARK_GRAY", Color.DARK_GRAY);
198:                colorNameMap.put("Color.darkGray", Color.darkGray);
199:                colorNameMap.put("Color.gray", Color.gray);
200:                colorNameMap.put("Color.GRAY", Color.GRAY);
201:                colorNameMap.put("Color.green", Color.green);
202:                colorNameMap.put("Color.GREEN", Color.GREEN);
203:                colorNameMap.put("Color.LIGHT_GRAY", Color.LIGHT_GRAY);
204:                colorNameMap.put("Color.magenta", Color.magenta);
205:                colorNameMap.put("Color.MAGENTA", Color.MAGENTA);
206:                colorNameMap.put("Color.orange", Color.orange);
207:                colorNameMap.put("Color.ORANGE", Color.ORANGE);
208:                colorNameMap.put("Color.pink", Color.pink);
209:                colorNameMap.put("Color.PINK", Color.PINK);
210:                colorNameMap.put("Color.red", Color.red);
211:                colorNameMap.put("Color.RED", Color.RED);
212:                colorNameMap.put("Color.white", Color.white);
213:                colorNameMap.put("Color.WHITE", Color.WHITE);
214:                colorNameMap.put("Color.yellow", Color.yellow);
215:                colorNameMap.put("Color.YELLOW", Color.YELLOW);
216:            }
217:
218:            public void startElement(String uri, String local, String name,
219:                    Attributes attrs) {
220:                if (name.equals("shape")) {
221:                    createShape(attrs);
222:                } else if (name.equals("labelrenderer")) {
223:                    createLabelRenderer(attrs);
224:                } else if (name.equals("containerlabelrenderer")) {
225:                    createContainerLabelRenderer(attrs);
226:                } else if (name.equals("shaperenderer")) {
227:                    createShapeRenderer(attrs);
228:                } else if (name.equals("slotChangeListener")) {
229:                    lastSlotChangeListener = createSlotChangeListener(attrs);
230:                } else if (name.equals("trigger")) {
231:                    createTrigger(attrs);
232:                } else if (name.equals("window"))
233:                    windowSpec = createWindow(attrs);
234:                else if (name.equals("container")) {
235:                    ShapeContainer c = createContainer(attrs);
236:                    if (root == null && containerStack.size() == 0)
237:                        root = c;
238:                    containerStack.add(c);
239:
240:                } else if (name.equals("layout")) {
241:                    ShapeGraphic c = (ShapeGraphic) containerStack
242:                            .get(containerStack.size() - 1);
243:                    if (c instanceof  ShapeContainer)
244:                        ((ShapeContainer) c)
245:                                .setLayout(createShapeLayout(attrs));
246:                } else if (name.equals("framepredicate")) {
247:                    ShapeGraphic c = (ShapeGraphic) containerStack
248:                            .get(containerStack.size() - 1);
249:                    c.setFramePredicate(createFramePredicate(attrs));
250:                } else if (name.equals("slotlistener")) {
251:                    ShapeGraphic c = (ShapeGraphic) containerStack
252:                            .get(containerStack.size() - 1);
253:                    String nm = attrs.getValue("name");
254:                    SlotChangeListener l = slotListeners.get(nm);
255:                    if (c != null && l != null)
256:                        c.addSlotListener(l);
257:                } else if (name.equals("component")) {
258:                    //ShapeGraphic c = (ShapeGraphic) containerStack.get(containerStack.size()-1);
259:                    ShapeGraphic g = createComponent(attrs);
260:                    //if (c instanceof ShapeContainer)
261:                    //  ((ShapeContainer)c).add(g);
262:                    containerStack.add(g);
263:                }
264:            }
265:
266:            public void endElement(String uri, String local, String name) {
267:                ShapeGraphic shg = null;
268:
269:                if (name.equals("slotChangeListener"))
270:                    lastSlotChangeListener = null;
271:                else if (name.equals("window"))
272:                    ;
273:                else if (name.equals("container")) {
274:                    if (containerStack.size() > 0) {
275:                        shg = (ShapeGraphic) containerStack
276:                                .remove(containerStack.size() - 1);
277:                        ShapeGraphic parent = ((containerStack.size() > 0) ? ((ShapeGraphic) containerStack
278:                                .get(containerStack.size() - 1))
279:                                : null);
280:                        if (parent != null && parent instanceof  ShapeContainer)
281:                            ((ShapeContainer) parent).add(shg);
282:                    }
283:                } else if (name.equals("layout"))
284:                    ;
285:                else if (name.equals("framepredicate"))
286:                    ;
287:                else if (name.equals("component")) {
288:                    if (containerStack.size() > 0) {
289:                        shg = (ShapeGraphic) containerStack
290:                                .remove(containerStack.size() - 1);
291:                        ShapeGraphic parent = ((containerStack.size() > 0) ? ((ShapeGraphic) containerStack
292:                                .get(containerStack.size() - 1))
293:                                : null);
294:                        if (parent != null && parent instanceof  ShapeContainer)
295:                            ((ShapeContainer) parent).add(shg);
296:                    }
297:                }
298:            }
299:
300:            // utiltity
301:
302:            public SlotChangeListener createSlotChangeListener(Attributes attrs) {
303:                String name = attrs.getValue("name");
304:                String slot = attrs.getValue("slot");
305:                SlotChangeListener sl = new SlotChangeListener(name, slot);
306:                slotListeners.add(name, sl);
307:                return sl;
308:            }
309:
310:            public void createTrigger(Attributes attrs) {
311:                if (lastSlotChangeListener == null)
312:                    return;
313:                // <trigger value="busy" action="setrenderer" name="processedJobRenderer"/>
314:                // <trigger value="busy" action="setshape" shape="circle2"/>
315:                String value = attrs.getValue("value");
316:                String action = attrs.getValue("action");
317:
318:                if (action.equals("setrenderer")) {
319:                    String nm = attrs.getValue("name");
320:                    ShapeRenderer sr = shapeRenderers.get(nm);
321:                    lastSlotChangeListener.setRendererTrigger(nm, sr, value);
322:                } else if (action.equals("setshape")) {
323:                    String shp = attrs.getValue("shape");
324:                    RectangularShape shape = shapes.get(shp);
325:                    lastSlotChangeListener.setShapeTrigger(shp, shape, value);
326:                } else if (action.equals("setlabelrenderer")) {
327:                    String nm = attrs.getValue("name");
328:                    LabelRenderer lblr = labelRenderers.get(nm);
329:                    lastSlotChangeListener.setLabelRendererTrigger(nm, lblr,
330:                            value);
331:                }
332:            }
333:
334:            public RectangularShape createShape(Attributes attrs) {
335:                // <shape name="circle1" class="java.awt.geom.Ellipse2D.Double" x="0" y="0" w="10" h="10"/>
336:                double x = Double.parseDouble(attrs.getValue("x"));
337:                double y = Double.parseDouble(attrs.getValue("y"));
338:                double w = Double.parseDouble(attrs.getValue("w"));
339:                double h = Double.parseDouble(attrs.getValue("h"));
340:                double arcw = 0d, arch = 0d;
341:                String klass = attrs.getValue("class");
342:                String name = attrs.getValue("name");
343:                RectangularShape shape = (RectangularShape) createInstance(klass);
344:                if (shape == null)
345:                    throw new NullPointerException("could not create shape '"
346:                            + name + "'");
347:                if (klass.endsWith("RoundRectangle")) {
348:                    arcw = Double.parseDouble(attrs.getValue("arcw"));
349:                    arch = Double.parseDouble(attrs.getValue("arch"));
350:                    ((RoundRectangle) shape).setRoundRect(x, y, w, h, arcw,
351:                            arch);
352:                } else
353:                    shape.setFrame(x, y, w, h);
354:                shapes.add(name, shape);
355:                return shape;
356:            }
357:
358:            public LabelRenderer createLabelRenderer(Attributes attrs) {
359:                //<labelrenderer name="defaultLabelRenderer" xoff="+2" yoff="+5" font="default" color="Color.blue"/>
360:                String x = attrs.getValue("xoff");
361:                String y = attrs.getValue("yoff");
362:                String xo = (x.startsWith("+") ? x
363:                        .substring(x.lastIndexOf("+")) : (x.startsWith("-") ? x
364:                        .substring(x.lastIndexOf("-")) : x));
365:                String yo = (y.startsWith("+") ? y
366:                        .substring(y.lastIndexOf("+")) : (y.startsWith("-") ? y
367:                        .substring(y.lastIndexOf("-")) : y));
368:                double xoff = Double.parseDouble(xo);
369:                double yoff = Double.parseDouble(yo);
370:                String col = attrs.getValue("color");
371:                Color color = getColor(col);
372:                String name = attrs.getValue("name");
373:
374:                LabelRenderer lblr = new LabelRenderer(name, xoff, yoff, null,
375:                        color);
376:                labelRenderers.add(lblr);
377:                String mouseOver = attrs.getValue("mouseover");
378:                if (mouseOver != null && mouseOver.equals("true"))
379:                    lblr.setMouseOverOnly(true);
380:                return lblr;
381:            }
382:
383:            public LabelRenderer createContainerLabelRenderer(Attributes attrs) {
384:                double xoff = Double.parseDouble(attrs.getValue("xoff"));
385:                double yoff = Double.parseDouble(attrs.getValue("yoff"));
386:                String col = attrs.getValue("color");
387:                Color color = getColor(col);
388:                String name = attrs.getValue("name");
389:                ContainerLabelRenderer lblr = new ContainerLabelRenderer(name,
390:                        xoff, yoff, null, color);
391:                labelRenderers.add(lblr);
392:                return lblr;
393:            }
394:
395:            public static Color getColor(String colorDesc) {
396:                if (colorDesc == null)
397:                    return null;
398:
399:                Color color = null;
400:                if (colorDesc.startsWith("Color."))
401:                    color = getJavaColor(colorDesc);
402:                else if (colorDesc.startsWith("#"))
403:                    color = Color.decode(colorDesc);
404:                else if (colorDesc.startsWith("(") && colorDesc.endsWith(")"))
405:                    color = getRGBColor(colorDesc);
406:                return color;
407:            }
408:
409:            public static Color getJavaColor(String colorDesc) {
410:                Color c = (Color) colorNameMap.get(colorDesc);
411:                if (c == null) {
412:                    // TODO: take care of cases such as Color.red.brighter
413:                    ;
414:                }
415:                return c;
416:            }
417:
418:            public static Color getRGBColor(String colorName) {
419:                int startIndex = colorName.indexOf("(");
420:                int endIndex = colorName.indexOf(")");
421:                StringTokenizer st = new StringTokenizer(colorName.substring(
422:                        startIndex, endIndex), ",");
423:                String rs = (st.hasMoreTokens() ? st.nextToken().trim() : "0");
424:                String gs = (st.hasMoreTokens() ? st.nextToken().trim() : "0");
425:                String bs = (st.hasMoreTokens() ? st.nextToken().trim() : "0");
426:                int r = Integer.parseInt((rs.startsWith("(") ? rs.substring(rs
427:                        .indexOf("(") + 1) : rs));
428:                int g = Integer.parseInt(gs);
429:                int b = Integer.parseInt((bs.endsWith(")") ? rs.substring(0, rs
430:                        .indexOf(")") - 1) : bs));
431:                return new Color(r, g, b);
432:            }
433:
434:            public static Paint getPaint(String paintDesc) {
435:                Paint p = getColor(paintDesc);
436:                // for now return p, TODO: in future take care of textures and gradients
437:                return p;
438:            }
439:
440:            public ShapeRenderer createShapeRenderer(Attributes attrs) {
441:                //<shaperenderer name="defaultRenderer" paint="Color.green" selectedpaint="Color.yellow" linewidth="2" bordered="true" filled="true"/>
442:                String name = attrs.getValue("name");
443:                Paint paint = getPaint(attrs.getValue("paint"));
444:                Paint selectedPaint = getPaint(attrs.getValue("selectedpaint"));
445:                Paint fillPaint = getPaint(attrs.getValue("fillpaint"));
446:                Paint selfillPaint = getPaint(attrs.getValue("selfillpaint"));
447:                int linewidth = Integer.parseInt(attrs.getValue("linewidth"));
448:                boolean bordered = "true".equals(attrs.getValue("bordered"));
449:                boolean filled = "true".equals(attrs.getValue("filled"));
450:                ShapeRenderer sh = new ShapeRenderer(name, paint,
451:                        selectedPaint, fillPaint, selfillPaint, linewidth,
452:                        bordered, filled);
453:                shapeRenderers.add(sh);
454:                return sh;
455:            }
456:
457:            public static WindowSpec createWindow(Attributes attrs) {
458:                String title = attrs.getValue("title");
459:                int width = Integer.parseInt(attrs.getValue("w"));
460:                int height = Integer.parseInt(attrs.getValue("h"));
461:                return new WindowSpec(title, new Dimension(width, height));
462:            }
463:
464:            protected static Object createInstance(String classname) {
465:                try {
466:                    Class c = Class.forName(classname);
467:                    Constructor constructor = c.getConstructor(new Class[0]);
468:                    return constructor.newInstance(new Object[0]);
469:                } catch (Exception ee) {
470:                    ee.printStackTrace();
471:                }
472:                return null;
473:            }
474:
475:            protected static ShapeLayout createShapeLayout(Attributes attrs) {
476:                String classname = attrs.getValue("class");
477:                String leftMargin = attrs.getValue("left");
478:                String rightMargin = attrs.getValue("right");
479:                String topMargin = attrs.getValue("top");
480:                String bottomMargin = attrs.getValue("bottom");
481:                String hpadding = attrs.getValue("hpadding");
482:                String vpadding = attrs.getValue("vpadding");
483:
484:                ShapeLayout sl = (ShapeLayout) createInstance(classname);
485:                if (sl != null)
486:                    sl
487:                            .setMargins(
488:                                    ((leftMargin != null && leftMargin.length() > 0) ? Double
489:                                            .parseDouble(leftMargin)
490:                                            : 0d),
491:                                    ((rightMargin != null && rightMargin
492:                                            .length() > 0) ? Double
493:                                            .parseDouble(rightMargin) : 0d),
494:                                    ((bottomMargin != null && bottomMargin
495:                                            .length() > 0) ? Double
496:                                            .parseDouble(bottomMargin) : 0d),
497:                                    ((topMargin != null && topMargin.length() > 0) ? Double
498:                                            .parseDouble(topMargin)
499:                                            : 0d),
500:                                    ((hpadding != null && hpadding.length() > 0) ? Double
501:                                            .parseDouble(hpadding)
502:                                            : 0d),
503:                                    ((vpadding != null && vpadding.length() > 0) ? Double
504:                                            .parseDouble(vpadding)
505:                                            : 0d));
506:                return sl;
507:            }
508:
509:            protected static FramePredicate createFramePredicate(
510:                    Attributes attrs) {
511:                if (attrs == null)
512:                    return null;
513:                String kind = attrs.getValue("isa");
514:                String name = attrs.getValue("name");
515:                String parentRelationship = attrs
516:                        .getValue("parentRelationship");
517:                return new FramePredicate(kind, name, parentRelationship);
518:            }
519:
520:            protected ShapeGraphic createComponent(Attributes attrs) {
521:                String classname = attrs.getValue("class");
522:                ShapeGraphic shape = (ShapeGraphic) createInstance(classname);
523:                shape.setId(attrs.getValue("id"));
524:                shape.setLabel(attrs.getValue("label"));
525:                String frameIdSlotName = attrs.getValue("idframeslot");
526:                String prototypeBool = attrs.getValue("prototype");
527:                String vis = attrs.getValue("visible");
528:                String shapeName = attrs.getValue("shape");
529:                if (shapeName != null)
530:                    shape.setShapePrototype(shapes.get(shapeName));
531:                String labelrender = attrs.getValue("labelrender");
532:                String shaperender = attrs.getValue("shaperender");
533:                if (labelrender != null)
534:                    shape.setLabelRenderer(labelRenderers.get(labelrender));
535:                if (shaperender != null)
536:                    shape.setRenderer(shapeRenderers.get(shaperender));
537:
538:                boolean visible = true;
539:                if (vis != null)
540:                    visible = "true".equals(vis);
541:                //if (visible && (labelrender == null ||  shaperender == null)) {
542:                //}
543:
544:                boolean isprototype = false;
545:                if (prototypeBool != null && prototypeBool.equals("true"))
546:                    isprototype = true;
547:                if (frameIdSlotName != null)
548:                    shape.setFrameIdSlotName(frameIdSlotName);
549:                shape.setPrototype(isprototype);
550:                shape.setVisible(visible);
551:                return shape;
552:            }
553:
554:            protected ShapeContainer createContainer(Attributes attrs) {
555:                // container
556:                String classname = attrs.getValue("class");
557:                ShapeContainer container = (ShapeContainer) createInstance(classname);
558:                container.setId(attrs.getValue("id"));
559:                container.setLabel(attrs.getValue("label"));
560:                String frameIdSlotName = attrs.getValue("idframeslot");
561:                String prototypeBool = attrs.getValue("prototype");
562:                String vis = attrs.getValue("visible");
563:                String shapeName = attrs.getValue("shape");
564:                if (shapeName != null)
565:                    container.setShapePrototype(shapes.get(shapeName));
566:                String labelrender = attrs.getValue("labelrender");
567:                String shaperender = attrs.getValue("shaperender");
568:                if (labelrender != null)
569:                    container.setLabelRenderer(labelRenderers.get(labelrender));
570:                if (shaperender != null)
571:                    container.setRenderer(shapeRenderers.get(shaperender));
572:
573:                boolean visible = true;
574:                if (vis != null)
575:                    visible = "true".equals(vis);
576:                boolean isprototype = false;
577:                if (prototypeBool != null && prototypeBool.equals("true"))
578:                    isprototype = true;
579:                if (frameIdSlotName != null)
580:                    container.setFrameIdSlotName(frameIdSlotName);
581:                container.setPrototype(isprototype);
582:                container.setVisible(visible);
583:                return container;
584:            }
585:        }
w_ww.__j__av__a2___s_.__c__o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.