Source Code Cross Referenced for WingSet.java in  » Web-Framework » wingS » com » javujavu » javux » demo » 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 » Web Framework » wingS » com.javujavu.javux.demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *	Javu WingS - Lightweight Java Component Set
003:         *	Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004:         *	e-mail: ksadlocha@programics.com
005:         *
006:         *	This library is free software; you can redistribute it and/or
007:         *	modify it under the terms of the GNU Lesser General Public
008:         *	License as published by the Free Software Foundation; either
009:         *	version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *	This library is distributed in the hope that it will be useful,
012:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *	Lesser General Public License for more details.
015:         *
016:         *	You should have received a copy of the GNU Lesser General Public
017:         *	License along with this library; if not, write to the Free Software
018:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        package com.javujavu.javux.demo;
022:
023:        import java.awt.AWTEvent;
024:        import java.awt.Color;
025:        import java.awt.Dimension;
026:        import java.awt.Font;
027:        import java.awt.GridBagConstraints;
028:        import java.awt.GridBagLayout;
029:        import java.awt.Insets;
030:        import java.awt.Toolkit;
031:        import java.awt.event.WindowEvent;
032:        import java.io.File;
033:        import java.io.IOException;
034:        import java.util.Vector;
035:
036:        import com.javujavu.javux.app.JarPath;
037:        import com.javujavu.javux.wings.Style;
038:        import com.javujavu.javux.wings.WingComponent;
039:        import com.javujavu.javux.wings.WingFont;
040:        import com.javujavu.javux.wings.WingFrame;
041:        import com.javujavu.javux.wings.WingImage;
042:        import com.javujavu.javux.wings.WingLabel;
043:        import com.javujavu.javux.wings.WingPanel;
044:        import com.javujavu.javux.wings.WingProgress;
045:        import com.javujavu.javux.wings.WingRootPane;
046:        import com.javujavu.javux.wings.WingSkin;
047:
048:        public class WingSet {
049:            protected static final String defaultSkin = "green";
050:            protected static final String[] skinNames = { "blue", "brown",
051:                    "gold", "green", "lite", "olive", "orange", "silver",
052:                    "substance", "substance-green", "vista", "vista-green",
053:                    "vista-red" };
054:            protected static int currentSkin;
055:            protected static Vector skins;
056:
057:            //	static WingSetPanel panel;
058:            static WingRootPane rootPane;
059:            public static int skinDelay;
060:            static boolean isApplet;
061:            static boolean isSkinExt;
062:
063:            private static String skinPath;
064:            private static Class refClass;
065:            private static String skinPath0;
066:            private static Class refClass0;
067:            private static String skinPathE;
068:
069:            public static void initApplet(String appSkinPath,
070:                    WingRootPane rootPane, String initSkin) {
071:                skinPath0 = "/skin/";
072:                refClass0 = WingSet.class;
073:
074:                skinPath = appSkinPath;
075:
076:                skinPath += "skin/";
077:                skinPathE = skinPath;
078:                refClass = null;
079:                isApplet = true;
080:                lookForSkinExt();
081:                WingSet.rootPane = rootPane;
082:
083:                if (loadFirstSkin(initSkin)) {
084:                    WingSetPanel panel;
085:                    rootPane.setContentPane(panel = new WingSetPanel());
086:                    rootPane.setMenuBar(panel.getMenu());
087:                    WingComponent.updateSkin(rootPane);
088:                    rootPane.revalidateAndRepaint();
089:                    panel.startThread();
090:                }
091:            }
092:
093:            public static void main(String[] args) {
094:                skinPath0 = "/skin/";
095:                refClass0 = WingSet.class;
096:
097:                skinPath = JarPath.getJarPath();
098:                if (skinPath == null) {
099:                    try {
100:                        File f = new File(".");
101:                        skinPath = f.getCanonicalPath();
102:                    } catch (IOException e) {
103:                    }
104:                    ;
105:                }
106:                if (!skinPath.endsWith(File.separator))
107:                    skinPath += File.separator;
108:                skinPath += "skin" + File.separator;
109:                skinPathE = skinPath;
110:                refClass = null;
111:                lookForSkinExt();
112:
113:                boolean isSkin = loadFirstSkin(null);
114:                WingSetFrame s;
115:                WingSetPanel panel = null;
116:                if (isSkin) {
117:                    s = new WingSetFrame(panel = new WingSetPanel());
118:                    s.setMenuBar(panel.getMenu());
119:                } else {
120:                    s = new WingSetFrame(getNoSkinLabel());
121:                }
122:
123:                s.pack();
124:                rootPane = s.getRootPane();
125:
126:                Dimension screenSize = Toolkit.getDefaultToolkit()
127:                        .getScreenSize();
128:                int x, y, w, h;
129:                w = 640;
130:                h = 500;
131:                //		w= (d.width*4)/5;
132:                //		h= (d.height*4)/5;
133:                if (w > screenSize.width)
134:                    w = screenSize.width;
135:                if (h > screenSize.height)
136:                    h = screenSize.height;
137:                x = (screenSize.width - w) / 2;
138:                y = (screenSize.height - h) / 2;
139:                s.setBounds(x, y, w, h);
140:
141:                s.setVisible(true);
142:                if (isSkin)
143:                    panel.startThread();
144:            }
145:
146:            public static WingLabel getNoSkinLabel() {
147:                WingLabel lx = new WingLabel(
148:                        "WingSet Demo 2007\n* * *\ncan't load skin resources",
149:                        WingLabel.CENTER);
150:                Style stx = new Style();
151:                stx.background = new Color(0xff0000);
152:                stx.foreground = new Color(0x000000);
153:                stx.border = new Color(0x000000);
154:                stx.image = WingSkin.getImage("not", "found");
155:                stx.font = new WingFont("Dialog", Font.BOLD, 30, false, true);
156:                stx.state = -1;
157:                lx.setTopStyle(stx);
158:                return lx;
159:            }
160:
161:            protected static boolean loadSkin(String skin) {
162:                boolean skin0 = defaultSkin.equals(skin)
163:                        || "_startup".equals(skin);
164:                String path = ((skin0) ? skinPath0 : skinPath) + skin;
165:                Class ref = ((skin0) ? refClass0 : refClass);
166:                WingSkin.removeAllSkins();
167:                boolean r = true;
168:                if (!loadSkin(skinPath0 + "_common", isApplet, refClass0)
169:                        || !loadSkin(path, isApplet, ref)) {
170:                    WingSkin.removeAllSkins();
171:                    r &= loadSkin(skinPathE + "_common", isApplet, null);
172:                    r &= loadSkin(skinPathE + skin, isApplet, null);
173:                }
174:                return r;
175:            }
176:
177:            protected static boolean loadSkin(String path, boolean pathUrl,
178:                    Class pathRef) {
179:                boolean r = WingSkin.loadSkin(path, pathUrl, pathRef);
180:                System.out.println(((r) ? "Skin loaded " : "Skin not found ")
181:                        + path + " isUrl " + pathUrl + " ref " + pathRef);
182:                return r;
183:            }
184:
185:            public static void lookForSkinExt() {
186:                try {
187:                    refClass = Class
188:                            .forName("com.javujavu.javux.demo.WingSetSkinExt");
189:                    skinPath = "/skin/";
190:                    isSkinExt = true;
191:                } catch (ClassNotFoundException e) {
192:                }
193:            }
194:
195:            protected static boolean loadFirstSkin(String initSkin) {
196:                WingSkin.registerStyleSheet("skinsamples");
197:                WingSkin.registerStyleSheet("wingsetdemo");
198:
199:                skins = new Vector();
200:                for (int i = 0; i < skinNames.length; i++) {
201:                    skins.addElement(skinNames[i]);
202:                }
203:                currentSkin = -1;
204:                if (initSkin != null)
205:                    currentSkin = skins.indexOf(initSkin);
206:                if (currentSkin == -1)
207:                    currentSkin = skins.indexOf(defaultSkin);
208:                try {
209:                    return doLoadSkin(true);
210:                } catch (InterruptedException e) {
211:                    return false;
212:                }
213:            }
214:
215:            protected static boolean doLoadSkin(boolean first)
216:                    throws InterruptedException {
217:                WingPanel loadPanel = new WingPanel(new GridBagLayout());
218:                WingProgress progress;
219:
220:                GridBagConstraints c = new GridBagConstraints();
221:                c.insets = new Insets(10, 20, 10, 20);
222:                c.anchor = GridBagConstraints.CENTER;
223:                c.fill = GridBagConstraints.HORIZONTAL;
224:                c.weightx = 1.0;
225:                c.weighty = 1.0;
226:                loadPanel.add(progress = new WingProgress(
227:                        WingProgress.HORIZONTAL), c);
228:
229:                if (rootPane != null) {
230:                    if (first) {
231:                        WingSet.loadSkin("_startup");
232:                        WingComponent.updateSkin(WingSet.rootPane);
233:                        progress.setStyleId("noimage");
234:                        rootPane.setStyleId("noimage");
235:                    }
236:
237:                    rootPane.setContentPane(loadPanel);
238:                    rootPane.setMenuBar(null);
239:                }
240:
241:                while (true) {
242:                    if (skins.size() == 0) {
243:                        if (rootPane != null) {
244:                            rootPane.setContentPane(WingSet.getNoSkinLabel());
245:                            rootPane.revalidateAndRepaint();
246:                        }
247:                        return false;
248:                    }
249:                    currentSkin = currentSkin % skins.size();
250:                    String skin = (String) skins.elementAt(currentSkin);
251:                    if (!doLoadSkin(skin, progress)) {
252:                        skins.removeElementAt(currentSkin);
253:                        WingSetPanel panel = WingSetPanel.the;
254:                        if (panel != null)
255:                            panel.removeSkin(currentSkin);
256:                    } else
257:                        break;
258:                }
259:
260:                WingSetPanel panel = WingSetPanel.the;
261:                if (rootPane != null && panel != null) {
262:                    rootPane.setContentPane(panel);
263:                    rootPane.setMenuBar(panel.getMenu());
264:                    panel.transferFocus();
265:                }
266:                return true;
267:            }
268:
269:            private static boolean doLoadSkin(String skin, WingProgress progress)
270:                    throws InterruptedException {
271:                boolean r = true;
272:
273:                progress.setText("loading skin: " + skin);
274:                progress.setValue(0);
275:
276:                r = WingSet.loadSkin(skin);
277:                if (r) {
278:                    delay();
279:                    progress.setValue(10);
280:
281:                    delay();
282:                    String[] pp0 = WingSkin.listImages();
283:                    String[] pp = new String[pp0.length + 2];
284:                    pp[0] = "h.progress.normal";
285:                    pp[1] = "h.progress.bar.normal";
286:                    System.arraycopy(pp0, 0, pp, 2, pp0.length);
287:
288:                    for (int i = 0; i < pp.length && r; i++) {
289:                        progress.setValue(10 + (80 * i) / pp.length);
290:                        progress.setText("loading image: " + (i + 1) + "/"
291:                                + pp.length);
292:                        r &= (WingSkin.getImage(pp[i], null, null) != null);
293:                        if (i == 1) {
294:                            progress.setStyleId(null);
295:                        }
296:                        delay();
297:                    }
298:                }
299:                if (r) {
300:                    progress.setValue(90);
301:                    progress.setText("updating components");
302:
303:                    if (rootPane != null) {
304:                        rootPane.setStyleId(null);
305:                        WingComponent.updateSkin(rootPane);
306:                        WingSetPanel panel = WingSetPanel.the;
307:                        if (panel != null) {
308:                            WingComponent.updateSkin(panel);
309:                            WingComponent.updateSkin(panel.eventTracer);
310:                        }
311:                    }
312:                    loadImages();
313:                    delay();
314:
315:                    progress.setValue(100);
316:                } else
317:                    progress.setText("error: skin not loaded");
318:
319:                return r;
320:            }
321:
322:            private static void delay() throws InterruptedException {
323:                if (WingSet.skinDelay > 0) {
324:                    synchronized (skinNames) {
325:                        skinNames.wait(WingSet.skinDelay);
326:                    }
327:                }
328:            }
329:
330:            public static WingImage imgAngel;
331:            public static WingImage imgBomb;
332:            public static WingImage imgConfused;
333:            public static WingImage imgCrying;
334:            public static WingImage imgDrink;
335:            public static WingImage imgEye;
336:            public static WingImage imgGlasses;
337:            public static WingImage imgGnash;
338:            public static WingImage imgJokingly;
339:            public static WingImage imgLaughing;
340:            public static WingImage imgMusic;
341:            public static WingImage imgSad;
342:            public static WingImage imgScared;
343:            public static WingImage imgSeek;
344:            public static WingImage imgSilence;
345:            public static WingImage imgSmile;
346:            public static WingImage imgStop;
347:            public static WingImage imgThumbsup;
348:            public static WingImage imgTired;
349:            public static WingImage imgTongue;
350:            public static WingImage imgUgly;
351:            public static WingImage imgYawn;
352:            public static WingImage imgAnim;
353:            public static WingImage imgBigsmileA;
354:            public static WingImage imgIcon;
355:
356:            private static void loadImages() {
357:                WingSet.imgAngel = WingSkin.getImage("imgAngel", null, null);
358:                WingSet.imgBomb = WingSkin.getImage("imgBomb", null, null);
359:                WingSet.imgConfused = WingSkin.getImage("imgConfused", null,
360:                        null);
361:                WingSet.imgCrying = WingSkin.getImage("imgCrying", null, null);
362:                WingSet.imgDrink = WingSkin.getImage("imgDrink", null, null);
363:                WingSet.imgEye = WingSkin.getImage("imgEye", null, null);
364:                WingSet.imgGlasses = WingSkin
365:                        .getImage("imgGlasses", null, null);
366:                WingSet.imgGnash = WingSkin.getImage("imgGnash", null, null);
367:                WingSet.imgJokingly = WingSkin.getImage("imgJokingly", null,
368:                        null);
369:                WingSet.imgLaughing = WingSkin.getImage("imgLaughing", null,
370:                        null);
371:                WingSet.imgMusic = WingSkin.getImage("imgMusic", null, null);
372:                WingSet.imgSad = WingSkin.getImage("imgSad", null, null);
373:                WingSet.imgScared = WingSkin.getImage("imgScared", null, null);
374:                WingSet.imgSeek = WingSkin.getImage("imgSeek", null, null);
375:                WingSet.imgSilence = WingSkin
376:                        .getImage("imgSilence", null, null);
377:                WingSet.imgSmile = WingSkin.getImage("imgSmile", null, null);
378:                WingSet.imgStop = WingSkin.getImage("imgStop", null, null);
379:                WingSet.imgThumbsup = WingSkin.getImage("imgThumbsup", null,
380:                        null);
381:                WingSet.imgTired = WingSkin.getImage("imgTired", null, null);
382:                WingSet.imgTongue = WingSkin.getImage("imgTongue", null, null);
383:                WingSet.imgUgly = WingSkin.getImage("imgUgly", null, null);
384:                WingSet.imgYawn = WingSkin.getImage("imgYawn", null, null);
385:                WingSet.imgAnim = WingSkin.getImage("imgAnim", null, null);
386:                WingSet.imgBigsmileA = WingSkin.getImage("imgBigsmileA", null,
387:                        null);
388:                WingSet.imgIcon = WingSkin.getImage("imgIcon", null, null);
389:            }
390:
391:            private static class WingSetFrame extends WingFrame {
392:                private WingSetFrame(WingComponent panel) {
393:                    setContentPane(panel);
394:                    setTitle("WingSetDemo 2007");
395:                    WingImage ico = WingSkin.getImage("imgIcon", null, null);
396:                    if (ico != null)
397:                        setIconImage(ico.getImage());
398:                    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
399:                }
400:
401:                protected void processWindowEvent(WindowEvent e) {
402:                    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
403:                        setVisible(false);
404:                        WingSetPanel panel = WingSetPanel.the;
405:                        if (panel != null)
406:                            panel.stopThread();
407:                        dispose();
408:                        System.exit(0);
409:                    }
410:                }
411:            }
412:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.