Source Code Cross Referenced for AddInputText.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » sc » 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 » Ajax » Laszlo 4.0.10 » org.openlaszlo.sc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* *****************************************************************************
002:         * addinputtext.java
003:         * ****************************************************************************/
004:
005:        /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006:         * Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
007:         * Use is subject to license terms.                                            *
008:         * J_LZ_COPYRIGHT_END *********************************************************/
009:
010:        package org.openlaszlo.sc;
011:
012:        import org.openlaszlo.utils.FileUtils;
013:        import org.openlaszlo.utils.StringUtils;
014:        import org.openlaszlo.compiler.FontInfo;
015:        import org.openlaszlo.iv.flash.api.*;
016:        import org.openlaszlo.iv.flash.api.action.*;
017:        import org.openlaszlo.iv.flash.api.image.*;
018:        import org.openlaszlo.iv.flash.api.sound.*;
019:        import org.openlaszlo.iv.flash.api.text.*;
020:        import org.openlaszlo.iv.flash.util.*;
021:        import org.openlaszlo.iv.flash.cache.*;
022:        import org.apache.log4j.*;
023:
024:        import java.io.*;
025:        import java.util.*;
026:
027:        // jgen 1.4
028:        import java.awt.geom.Rectangle2D;
029:
030:        /** Add in fixed-size input text resource with specified dimensions.
031:         * 
032:         * We get a list of resource names like this:
033:         * 
034:         * 'lzinputtext/lztahoe8/8/plain/398/157'
035:         *
036:         *  We need to parse out font name, size ,style, and width/height, and
037:         *  create a new textfield for them with the WORDWRAP flag asserted.
038:         */
039:
040:        public class AddInputText {
041:            private static Logger mLogger = Logger
042:                    .getLogger(AddInputText.class);
043:
044:            /** Constant */
045:            private static final int TWIP = 20;
046:
047:            /** Leading for text and input text */
048:            private static int mTextLeading = 2;
049:
050:            static public void main(String args[]) {
051:                addtext(args[0], args[1], new String[] { args[2], args[3] });
052:            }
053:
054:            static public void addtext(String infile, String outfile,
055:                    String resourceNames[]) {
056:                try {
057:                    FlashFile f = FlashFile.parse(infile);
058:                    OutputStream out = new FileOutputStream(outfile);
059:
060:                    java.util.Enumeration defs = f.definitions();
061:                    FontsCollector fc = new FontsCollector();
062:
063:                    HashMap fontsTable = new HashMap();
064:
065:                    while (defs.hasMoreElements()) {
066:                        FlashDef def = (FlashDef) defs.nextElement();
067:                        if (def instanceof  FontDef) {
068:                            FontDef fontDef = (FontDef) def;
069:                            Font font = fontDef.getFont();
070:                            String bold = ((font.BOLD & font.flags) > 0 ? "bold"
071:                                    : "");
072:                            String italic = ((font.ITALIC & font.flags) > 0 ? "italic"
073:                                    : "");
074:                            //System.out.println("Copying font " + font.getFontName() 
075:                            //+ bold + italic);
076:                            FontDef fdef = fc.addFont(font, null);
077:                            fdef.setWriteAllChars(true);
078:                            fdef.setWriteLayout(true);
079:                            fontsTable.put(font.getFontName() + "::" + bold
080:                                    + italic, font);
081:                        }
082:                    }
083:
084:                    // Look up fonts for resources, add custom input text fields
085:                    for (int i = 0; i < resourceNames.length; i++) {
086:                        String rsrc = resourceNames[i];
087:                        System.out.println("addinputtext: processing " + rsrc);
088:                        // parse string of form  'lzinputtext/lztahoe8/8/plain/398/157[/html][/passwd]/(m|s)' into FontInfo, w/h
089:                        String path[] = StringUtils.split(rsrc, "/");
090:                        if (path.length < 7) {
091:                            Exception e = new RuntimeException(
092:                            /* (non-Javadoc)
093:                             * @i18n.test
094:                             * @org-mes="inputtext resource name '" + p[0] + "' couldn't be parsed into a form like lzinputtext/lztahoe8/8/plain/398/157[/html][/passwd]/(m|s)"
095:                             */
096:                            org.openlaszlo.i18n.LaszloMessages.getMessage(
097:                                    AddInputText.class.getName(), "051018-94",
098:                                    new Object[] { rsrc }));
099:                            e.printStackTrace();
100:                            throw e;
101:                        }
102:                        String fname = path[1];
103:                        String fsize = path[2];
104:                        String fstyle = path[3];
105:                        int width = (int) Double.parseDouble(path[4]);
106:                        int height = (int) Double.parseDouble(path[5]);
107:                        Font font = (Font) fontsTable.get(fname + "::"
108:                                + (fstyle.equals("plain") ? "" : fstyle));
109:                        if (font == null) {
110:                            Exception e = new RuntimeException(
111:                            /* (non-Javadoc)
112:                             * @i18n.test
113:                             * @org-mes="could not find font " + p[0] + " " + p[1] + " for inputtext resource named '" + p[2]
114:                             */
115:                            org.openlaszlo.i18n.LaszloMessages.getMessage(
116:                                    AddInputText.class.getName(), "051018-112",
117:                                    new Object[] { fname, fstyle, rsrc }));
118:                            e.printStackTrace();
119:                            throw e;
120:                        }
121:                        boolean multiline = false;
122:                        boolean password = false;
123:
124:                        // look for "passwd" or "m" tokens
125:                        for (int j = 6; j < path.length; j++) {
126:                            if (path[j].equals("passwd")) {
127:                                password = true;
128:                            } else if (path[j].equals("m")) {
129:                                multiline = true;
130:                            }
131:                        }
132:
133:                        FontInfo finfo = new FontInfo(fname, fsize, fstyle);
134:                        addCustomInputText(f, font, finfo, width, height,
135:                                multiline, password);
136:                    }
137:
138:                    writeFlashFile(f, fc, out);
139:
140:                } catch (Exception e) {
141:                    mLogger.error(
142:                    /* (non-Javadoc)
143:                     * @i18n.test
144:                     * @org-mes="exception in AddInputText.addtext"
145:                     */
146:                    org.openlaszlo.i18n.LaszloMessages.getMessage(
147:                            AddInputText.class.getName(), "051018-142"), e);
148:                }
149:            }
150:
151:            static void writeFlashFile(FlashFile f, FontsCollector fc,
152:                    OutputStream out) {
153:                try {
154:                    InputStream input;
155:                    input = f.generate(fc, null, false).getInputStream();
156:                    FileUtils.send(input, out);
157:                    input.close();
158:                    out.close();
159:                } catch (Exception e) {
160:                    mLogger.error(
161:                    /* (non-Javadoc)
162:                     * @i18n.test
163:                     * @org-mes="exception in AddInputText.writeFlashFile"
164:                     */
165:                    org.openlaszlo.i18n.LaszloMessages.getMessage(
166:                            AddInputText.class.getName(), "051018-161"), e);
167:                }
168:            }
169:
170:            /** Create a custom text input field that will correspond to a specific lzx input text view.
171:             */
172:            static public void addCustomInputText(FlashFile f, Font font,
173:                    FontInfo fontInfo, int width, int height,
174:                    boolean multiline, boolean password) {
175:                String fontName = fontInfo.getName();
176:                String mstring;
177:                mstring = multiline ? "/m" : "/s";
178:
179:                String name = "lzinputtext/" + fontName + "/"
180:                        + fontInfo.getSize() + "/" + fontInfo.getStyle() + "/"
181:                        + width + "/" + height + (password ? "/passwd" : "")
182:                        + mstring;
183:
184:                // Create a movieclip with a single frame with
185:                // a text field of the correct size.
186:                Script movieClip = new Script(1);
187:                Frame frame = movieClip.newFrame();
188:
189:                TextField input = new TextField("", "text", font, fontInfo
190:                        .getSize()
191:                        * TWIP, AlphaColor.black);
192:
193:                int flags = input.getFlags();
194:
195:                if (password) {
196:                    flags |= TextField.PASSWORD;
197:                }
198:
199:                input.setFlags(flags | TextField.USEOUTLINES
200:                        | TextField.HASFONT
201:                        | (multiline ? TextField.MULTILINE : 0)
202:                        | (multiline ? TextField.WORDWRAP : 0));
203:
204:                // left, right, indent, and align don't make sense 
205:                // when we do all input text wrapping ourselves.
206:                // Leading still matters though!
207:                input.setLayout(0, 0, 0, 0, mTextLeading * TWIP);
208:
209:                input.setBounds(new Rectangle2D.Double(0, 0, width * TWIP,
210:                        height * TWIP));
211:
212:                frame.addInstance(input, 1, null, null);
213:                frame.addStopAction();
214:
215:                // Add movieClip to library
216:                f.addDefToLibrary(name, movieClip);
217:                // Export it.
218:                ExportAssets ea = new ExportAssets();
219:                ea.addAsset(name, movieClip);
220:                System.out.println("addCustomInputText: added " + name);
221:                Timeline timeline = f.getMainScript().getTimeline();
222:                frame = timeline.getFrameAt(timeline.getFrameCount() - 1);
223:                frame.addFlashObject(ea);
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.