Source Code Cross Referenced for ElementStyle.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » gui » old » 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 » rife 1.6.1 » com.uwyn.rife.gui.old 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: ElementStyle.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.gui.old;
009:
010:        import java.awt.*;
011:
012:        import com.uwyn.rife.config.Config;
013:        import com.uwyn.rife.gui.Rife;
014:        import com.uwyn.rife.swing.JDialogSystemError;
015:        import com.uwyn.rife.tools.ExceptionUtils;
016:        import java.awt.font.FontRenderContext;
017:        import java.awt.font.LineMetrics;
018:        import java.awt.geom.AffineTransform;
019:        import java.awt.geom.Rectangle2D;
020:        import java.awt.image.AffineTransformOp;
021:        import java.awt.image.BufferedImage;
022:        import java.awt.image.BufferedImageOp;
023:        import java.awt.image.RasterFormatException;
024:        import java.io.IOException;
025:        import java.io.InputStream;
026:        import java.io.InputStreamReader;
027:        import java.io.UnsupportedEncodingException;
028:
029:        public class ElementStyle {
030:            public static final String MAX_PROPERTY_STRING = "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM";
031:            public static final int MAX_PROPERTY_STRING_LENGTH = MAX_PROPERTY_STRING
032:                    .length();
033:
034:            private BufferedImage mParamImage = null;
035:            private BufferedImageOp mParamImageOp = null;
036:            private Graphics2D mParamGraphics = null;
037:
038:            private Font mPlainFont = null;
039:            private Font mBoldFont = null;
040:
041:            public FontRenderContext mFontRenderContext = null;
042:
043:            public Color mBodyBackgroundColor = null;
044:            public Color mBodyBackgroundColorSelected = null;
045:            public Color mElementBorderColor = null;
046:            public Color mElementBorderColorSelected = null;
047:            public Color mTitleBorderColor = null;
048:            public Color mTitleTextColor = null;
049:            public Color mExitTextColor = null;
050:            public Color mParamBorderColor = null;
051:            public Color mParamTextColor = null;
052:            public Font mTitleFont = null;
053:            public LineMetrics mTitleFontLineMetrics = null;
054:            public Font mParamFont = null;
055:            public LineMetrics mParamFontLineMetrics = null;
056:            public Font mExitFont = null;
057:            public LineMetrics mExitFontLineMetrics = null;
058:            public float mElementBorderWidth = 0;
059:            public float mTitleMarginWidth = 0;
060:            public float mTitleMarginHeight = 0;
061:            public float mExitMarginWidth = 0;
062:            public float mExitMarginHeight = 0;
063:            public float mParamMarginWidth = 0;
064:            public float mParamMarginHeight = 0;
065:            public float mParamLineWidth = 0;
066:            public float mParamLineLength = 0;
067:            public float mParamLineDashedWidth = 0;
068:            public BasicStroke mParamLineDashedStroke = null;
069:
070:            public ElementStyle(float scaleFactor) {
071:                getBaseFonts();
072:                setColors();
073:                calculateStyle(scaleFactor);
074:            }
075:
076:            public static void setRenderingHints(Graphics2D g2d,
077:                    float scaleFactor) {
078:                g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
079:                        RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
080:                if (scaleFactor < 1) {
081:                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
082:                            RenderingHints.VALUE_ANTIALIAS_ON);
083:                    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
084:                            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
085:                } else {
086:                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
087:                            RenderingHints.VALUE_ANTIALIAS_OFF);
088:                    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
089:                            RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
090:                }
091:                g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
092:                        RenderingHints.VALUE_STROKE_PURE);
093:                g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
094:                        RenderingHints.VALUE_RENDER_SPEED);
095:            }
096:
097:            private void getBaseFonts() {
098:                mPlainFont = loadFont("/fonts/trebuchet.ttf");
099:                mBoldFont = loadFont("/fonts/trebuchetbold.ttf");
100:            }
101:
102:            private Font loadFont(String path) {
103:                InputStream input_stream = null;
104:                InputStreamReader input_stream_reader = null;
105:                Font font = null;
106:
107:                input_stream = this .getClass().getResourceAsStream(path);
108:
109:                if (input_stream != null) {
110:                    try {
111:                        input_stream_reader = new InputStreamReader(
112:                                input_stream, "ISO8859_1");
113:
114:                        if (input_stream_reader != null) {
115:                            try {
116:                                font = Font.createFont(Font.TRUETYPE_FONT,
117:                                        input_stream);
118:                            } catch (IOException e) {
119:                                (new JDialogSystemError(
120:                                        Rife.getMainFrame(),
121:                                        "ElementStyle.loadFont() : IO error while creating the font from resource at '"
122:                                                + path
123:                                                + "' : "
124:                                                + ExceptionUtils
125:                                                        .getExceptionStackTrace(e)))
126:                                        .setVisible(true);
127:                            } catch (FontFormatException e) {
128:                                (new JDialogSystemError(
129:                                        Rife.getMainFrame(),
130:                                        "ElementStyle.loadFont() : Font format error while creating the font from resource at '"
131:                                                + path
132:                                                + "' : "
133:                                                + ExceptionUtils
134:                                                        .getExceptionStackTrace(e)))
135:                                        .setVisible(true);
136:                            }
137:                        } else {
138:                            (new JDialogSystemError(
139:                                    Rife.getMainFrame(),
140:                                    "ElementStyle.loadFont() : Couldn't create the inputstream reader for the font resource at '"
141:                                            + path + "'.")).setVisible(true);
142:                        }
143:                    } catch (UnsupportedEncodingException e) {
144:                        (new JDialogSystemError(
145:                                Rife.getMainFrame(),
146:                                "ElementStyle.loadFont() : Error while creating the inputstream reader for the font resource at '"
147:                                        + path
148:                                        + "' : "
149:                                        + ExceptionUtils
150:                                                .getExceptionStackTrace(e)))
151:                                .setVisible(true);
152:                    }
153:                } else {
154:                    (new JDialogSystemError(Rife.getMainFrame(),
155:                            "ElementStyle.loadFont() : Couldn't open the font resource at '"
156:                                    + path + "'.")).setVisible(true);
157:                }
158:
159:                return font;
160:            }
161:
162:            public void drawParameterText(Graphics2D g2d, String text,
163:                    Color backgroundColor, int x, int y) {
164:                mParamGraphics.setBackground(backgroundColor);
165:                Rectangle2D text_size = mParamFont.getStringBounds(text,
166:                        mFontRenderContext);
167:                int baseline = (int) (mParamFontLineMetrics.getAscent());
168:                mParamGraphics.setClip(0, 0, (int) text_size.getWidth(),
169:                        mParamImage.getHeight());
170:                mParamGraphics.clearRect(0, 0, (int) text_size.getWidth(),
171:                        mParamImage.getHeight());
172:                mParamGraphics.drawString(text, 0, baseline);
173:                Shape previous_clip = g2d.getClip();
174:                g2d.clipRect(x - baseline, y - (int) text_size.getWidth(), x
175:                        - baseline + mParamImage.getHeight(), (int) text_size
176:                        .getWidth());
177:                try {
178:                    g2d.drawImage(mParamImage, mParamImageOp, x, y);
179:                } catch (RasterFormatException e) {
180:                    // do nothing
181:                }
182:                g2d.setClip(previous_clip);
183:            }
184:
185:            private void setColors() {
186:                mBodyBackgroundColor = new Color(220, 255, 200);
187:                mBodyBackgroundColorSelected = new Color(255, 255, 200);
188:                mElementBorderColor = new Color(0, 0, 0);
189:                mElementBorderColorSelected = new Color(0, 0, 0);
190:                mTitleTextColor = new Color(0, 0, 0);
191:                mTitleBorderColor = new Color(0, 0, 0);
192:                mExitTextColor = new Color(0, 0, 0);
193:                mParamTextColor = new Color(0, 0, 0);
194:                mParamBorderColor = new Color(0, 0, 0);
195:            }
196:
197:            public void calculateStyle(float scaleFactor) {
198:                mFontRenderContext = new FontRenderContext(null, false, false);
199:
200:                mTitleFont = mBoldFont.deriveFont(Font.PLAIN,
201:                        (int) (13 * scaleFactor));
202:                mTitleFontLineMetrics = mTitleFont.getLineMetrics(
203:                        MAX_PROPERTY_STRING, mFontRenderContext);
204:                mParamFont = mPlainFont.deriveFont(Font.PLAIN,
205:                        (int) (11 * scaleFactor));
206:                mParamFontLineMetrics = mParamFont.getLineMetrics(
207:                        MAX_PROPERTY_STRING, mFontRenderContext);
208:                mExitFont = mPlainFont.deriveFont(Font.PLAIN,
209:                        (int) (11 * scaleFactor));
210:                mExitFontLineMetrics = mExitFont.getLineMetrics(
211:                        MAX_PROPERTY_STRING, mFontRenderContext);
212:                mElementBorderWidth = Math.round(scaleFactor);
213:                mTitleMarginWidth = Math.round(5 * scaleFactor);
214:                mTitleMarginHeight = Math.round(3 * scaleFactor);
215:                mExitMarginWidth = Math.round(2 * scaleFactor);
216:                mExitMarginHeight = Math.round(2 * scaleFactor);
217:
218:                mParamMarginWidth = Math.round(scaleFactor);
219:                mParamMarginHeight = Math.round(5 * scaleFactor);
220:                mParamLineWidth = Math.round(3 * scaleFactor);
221:                mParamLineLength = Math.round(Config.getRepInstance().getInt(
222:                        "GRID_SIZE")
223:                        * 2 * scaleFactor);
224:                mParamLineDashedWidth = Math.round(scaleFactor);
225:                mParamLineDashedStroke = new BasicStroke(mParamLineDashedWidth,
226:                        BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0f,
227:                        new float[] { 3f * scaleFactor }, 0f);
228:
229:                Rectangle2D work_image_size = mParamFont.getStringBounds(
230:                        MAX_PROPERTY_STRING, mFontRenderContext);
231:                mParamImage = new BufferedImage((int) work_image_size
232:                        .getWidth(), (int) work_image_size.getHeight(),
233:                        BufferedImage.TYPE_INT_RGB);
234:                mParamGraphics = mParamImage.createGraphics();
235:                setRenderingHints(mParamGraphics, scaleFactor);
236:                mParamGraphics.setColor(mParamTextColor);
237:                mParamGraphics.setFont(mParamFont);
238:                AffineTransform image_op_transform = AffineTransform
239:                        .getRotateInstance(Math.toRadians(-90));
240:                image_op_transform.concatenate(AffineTransform
241:                        .getTranslateInstance(0, -1
242:                                * (mParamFontLineMetrics.getAscent())));
243:                mParamImageOp = new AffineTransformOp(image_op_transform,
244:                        mParamGraphics.getRenderingHints());
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.