Source Code Cross Referenced for Demo.java in  » Swing-Library » thinlet » thinlet » 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 » Swing Library » thinlet » thinlet.demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package thinlet.demo;
002:
003:        import java.awt.*;
004:        import java.io.*;
005:
006:        import thinlet.*;
007:
008:        /**
009:         * Simple demonstration of widgets and events
010:         */
011:        public class Demo extends Thinlet {
012:
013:            /**
014:             * Loads the xml file
015:             */
016:            public Demo() throws Exception {
017:                add(parse("demo.xml"));
018:            }
019:
020:            /**
021:             * Creates a frame including this thinlet demo
022:             */
023:            public static void main(String[] args) throws Exception {
024:                new FrameLauncher("Demo", new Demo(), 320, 320);
025:            }
026:
027:            /**
028:             * Called if the demo.xml was loaded,
029:             * it fills the textarea from a resource file
030:             */
031:            public void loadText(Object textarea) throws Exception {
032:                BufferedReader reader = new BufferedReader(
033:                        new InputStreamReader(getClass().getResourceAsStream(
034:                                "demodialog.xml")));
035:                StringBuffer text = new StringBuffer();
036:                for (int c = reader.read(); c != -1; c = reader.read()) {
037:                    if (((c > 0x1f) && (c < 0x7f))
038:                            || ((c > 0x9f) && (c < 0xffff)) || (c == '\n')) {
039:                        text.append((char) c);
040:                    } else if (c == '\t') {
041:                        text.append("  ");
042:                    }
043:                }
044:                reader.close();
045:                setString(textarea, "text", text.toString());
046:            }
047:
048:            /**
049:             * Updates textarea's editable property depending on a checkbox state
050:             */
051:            public void changeEditable(boolean editable, Object textarea) {
052:                setBoolean(textarea, "editable", editable);
053:            }
054:
055:            /**
056:             * Updates textarea's enabled property
057:             */
058:            public void changeEnabled(boolean enabled, Object textarea) {
059:                setBoolean(textarea, "enabled", enabled);
060:            }
061:
062:            Object dialog;
063:
064:            /**
065:             * Shows the modal find dialog, creates only one dialog instance
066:             */
067:            public void showDialog() throws Exception {
068:                if (dialog == null) {
069:                    dialog = parse("demodialog.xml");
070:                }
071:                add(dialog);
072:            }
073:
074:            /**
075:             * Updates the textarea's selection range,
076:             * and add the search string to the history 
077:             */
078:            public void findText(Object combobox, String what, boolean match,
079:                    boolean down) {
080:                closeDialog();
081:                if (what.length() == 0) {
082:                    return;
083:                }
084:
085:                boolean cacheditem = false;
086:                for (int i = getCount(combobox) - 1; i >= 0; i--) {
087:                    String choicetext = getString(getItem(combobox, i), "text");
088:                    if (what.equals(choicetext)) {
089:                        cacheditem = true;
090:                        break;
091:                    }
092:                }
093:                if (!cacheditem) {
094:                    Object choice = create("choice");
095:                    setString(choice, "text", what);
096:                    add(combobox, choice);
097:                }
098:
099:                Object textarea = find("textarea");
100:                int end = getInteger(textarea, "end");
101:                String text = getString(textarea, "text");
102:
103:                if (!match) {
104:                    what = what.toLowerCase();
105:                    text = text.toLowerCase();
106:                }
107:
108:                int index = text.indexOf(what, down ? end : 0);
109:                if (!down && (index != -1) && (index >= end)) {
110:                    index = -1;
111:                }
112:                if (index != -1) {
113:                    setInteger(textarea, "start", index);
114:                    setInteger(textarea, "end", index + what.length());
115:                    requestFocus(textarea);
116:                } else {
117:                    getToolkit().beep();
118:                }
119:            }
120:
121:            /**
122:             * Closes the dialog
123:             */
124:            public void closeDialog() {
125:                remove(dialog);
126:            }
127:
128:            /**
129:             * Insert a new item into the list
130:             */
131:            public void insertList(Object list) {
132:                Object item = create("item");
133:                setString(item, "text", "New item");
134:                setIcon(item, "icon", getIcon("/icon/library.gif"));
135:                add(list, item, 0);
136:                //		System.out.println("> click " + System.currentTimeMillis());
137:                //		try { Thread.sleep(5000); } catch (InterruptedException ie) {}
138:            }
139:
140:            /**
141:             * Removes the selected items from the list
142:             */
143:            public void deleteList(Object delete, Object list) {
144:                for (int i = getCount(list) - 1; i >= 0; i--) {
145:                    Object item = getItem(list, i);
146:                    if (getBoolean(item, "selected")) {
147:                        remove(item);
148:                    }
149:                }
150:                setBoolean(delete, "enabled", false);
151:            }
152:
153:            /**
154:             * Delete button's state depends on the list selection
155:             */
156:            public void changeSelection(Object list, Object delete) {
157:                setBoolean(delete, "enabled", getSelectedIndex(list) != -1);
158:            }
159:
160:            /**
161:             * Clears list selection and updates the selection model
162:             */
163:            public void setSelection(Object list, String selection,
164:                    Object delete) {
165:                for (int i = getCount(list) - 1; i >= 0; i--) {
166:                    setBoolean(getItem(list, i), "selected", false);
167:                }
168:                setChoice(list, "selection", selection);
169:                setBoolean(delete, "enabled", false);
170:            }
171:
172:            /**
173:             *
174:             */
175:            public void sliderChanged(int value, Object spinbox) {
176:                setString(spinbox, "text", String.valueOf(value));
177:                hsbChanged();
178:            }
179:
180:            /**
181:             *
182:             */
183:            public void spinboxChanged(String text, Object slider) {
184:                try {
185:                    int value = Integer.parseInt(text);
186:                    if ((value >= 0) && (value <= 255)) {
187:                        setInteger(slider, "value", value);
188:                        hsbChanged();
189:                    }
190:                } catch (NumberFormatException nfe) {
191:                    getToolkit().beep();
192:                }
193:            }
194:
195:            private Object sl_red, sl_green, sl_blue;
196:            private Object tf_hue, tf_saturation, tf_brightness;
197:            private Object pb_hue, pb_saturation, pb_brightness;
198:            private Object rgb_label;
199:
200:            /**
201:             *
202:             */
203:            public void storeWidgets(Object sl_red, Object sl_green,
204:                    Object sl_blue, Object tf_hue, Object tf_saturation,
205:                    Object tf_brightness, Object pb_hue, Object pb_saturation,
206:                    Object pb_brightness, Object rgb_label) {
207:                this .sl_red = sl_red;
208:                this .sl_green = sl_green;
209:                this .sl_blue = sl_blue;
210:                this .tf_hue = tf_hue;
211:                this .tf_saturation = tf_saturation;
212:                this .tf_brightness = tf_brightness;
213:                this .pb_hue = pb_hue;
214:                this .pb_saturation = pb_saturation;
215:                this .pb_brightness = pb_brightness;
216:                this .rgb_label = rgb_label;
217:            }
218:
219:            /**
220:             *
221:             */
222:            private void hsbChanged() {
223:                int red = getInteger(sl_red, "value");
224:                int green = getInteger(sl_green, "value");
225:                int blue = getInteger(sl_blue, "value");
226:
227:                float[] hsb = Color.RGBtoHSB(red, green, blue, null);
228:
229:                setString(tf_hue, "text", String.valueOf(hsb[0]));
230:                setString(tf_saturation, "text", String.valueOf(hsb[1]));
231:                setString(tf_brightness, "text", String.valueOf(hsb[2]));
232:
233:                setInteger(pb_hue, "value", (int) (100f * hsb[0]));
234:                setInteger(pb_saturation, "value", (int) (100f * hsb[1]));
235:                setInteger(pb_brightness, "value", (int) (100f * hsb[2]));
236:
237:                setColor(rgb_label, "background", new Color(red, green, blue));
238:                setColor(rgb_label, "foreground", new Color(255 - red,
239:                        255 - green, 255 - blue));
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.