Source Code Cross Referenced for JPanelStyleSample.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » gui » style » 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 » Report » iReport 2.0.5 » it.businesslogic.ireport.gui.style 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 - 2008 JasperSoft Corporation.  All rights reserved. 
003:         * http://www.jaspersoft.com.
004:         *
005:         * Unless you have purchased a commercial license agreement from JasperSoft,
006:         * the following license terms apply:
007:         *
008:         * This program is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License version 2 as published by
010:         * the Free Software Foundation.
011:         *
012:         * This program is distributed WITHOUT ANY WARRANTY; and without the
013:         * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014:         * See the GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018:         * or write to:
019:         *
020:         * Free Software Foundation, Inc.,
021:         * 59 Temple Place - Suite 330,
022:         * Boston, MA  USA  02111-1307
023:         *
024:         *
025:         *
026:         *
027:         * JPanelStyleSample.java
028:         * 
029:         * Created on February 18, 2006, 12:46 PM
030:         *
031:         */
032:
033:        package it.businesslogic.ireport.gui.style;
034:
035:        import it.businesslogic.ireport.Box;
036:        import it.businesslogic.ireport.IReportFont;
037:        import it.businesslogic.ireport.ReportElement;
038:        import it.businesslogic.ireport.Style;
039:        import it.businesslogic.ireport.gui.MainFrame;
040:        import it.businesslogic.ireport.util.Java2DUtil;
041:        import it.businesslogic.ireport.util.Misc;
042:        import java.awt.Color;
043:        import java.awt.Font;
044:        import java.awt.Graphics;
045:        import java.awt.Graphics2D;
046:        import java.awt.Point;
047:        import java.awt.RenderingHints;
048:        import java.awt.Stroke;
049:        import java.awt.font.FontRenderContext;
050:        import java.awt.font.LineBreakMeasurer;
051:        import java.awt.font.TextAttribute;
052:        import java.awt.font.TextLayout;
053:        import java.awt.geom.AffineTransform;
054:        import java.text.AttributedCharacterIterator;
055:        import java.text.AttributedString;
056:        import java.util.ArrayList;
057:        import java.util.Iterator;
058:        import java.util.List;
059:        import java.util.StringTokenizer;
060:        import it.businesslogic.ireport.util.I18n;
061:        import java.awt.BasicStroke;
062:
063:        /**
064:         *
065:         * @author  gtoffoli
066:         */
067:        public class JPanelStyleSample extends javax.swing.JPanel {
068:
069:            private Style style = null;
070:
071:            static public Rotation ROTATION_NONE;
072:            static public Rotation ROTATION_LEFT;
073:            static public Rotation ROTATION_RIGHT;
074:
075:            static {
076:                ROTATION_NONE = new Rotation("None", 0);
077:                ROTATION_LEFT = new Rotation("Left", 1);
078:                ROTATION_RIGHT = new Rotation("Right", 2);
079:            }
080:
081:            /** Creates new form JPanelStyleSample */
082:            public JPanelStyleSample() {
083:                initComponents();
084:            }
085:
086:            public Style getStyle() {
087:                return style;
088:            }
089:
090:            public void setStyle(Style style) {
091:                this .style = style;
092:                this .repaint();
093:            }
094:
095:            /** This method is called from within the constructor to
096:             * initialize the form.
097:             * WARNING: Do NOT modify this code. The content of this method is
098:             * always regenerated by the Form Editor.
099:             */
100:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
101:            private void initComponents() {
102:
103:                setLayout(null);
104:
105:            }// </editor-fold>//GEN-END:initComponents
106:
107:            // Variables declaration - do not modify//GEN-BEGIN:variables
108:            // End of variables declaration//GEN-END:variables
109:
110:            public void paint(Graphics g) {
111:                super .paint(g);
112:                Graphics2D g2 = (Graphics2D) g;
113:
114:                if (getStyle() == null)
115:                    return;
116:
117:                if (this .getSize().getWidth() <= 10)
118:                    return;
119:                if (this .getSize().getHeight() <= 10)
120:                    return;
121:
122:                int x = 5;
123:                int y = 5;
124:                int width = (int) this .getSize().getWidth() - 10;
125:                int heigth = (int) this .getSize().getHeight() - 10;
126:
127:                if (MainFrame.getMainInstance().getProperties().getProperty(
128:                        "Antialias", "true").equals("false")) {
129:
130:                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
131:                            RenderingHints.VALUE_ANTIALIAS_OFF);
132:                    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
133:                            RenderingHints.VALUE_STROKE_PURE);
134:                    g2.setRenderingHint(RenderingHints.KEY_DITHERING,
135:                            RenderingHints.VALUE_DITHER_DISABLE);
136:                } else {
137:
138:                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
139:                            RenderingHints.VALUE_ANTIALIAS_ON);
140:                    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
141:                            RenderingHints.VALUE_STROKE_DEFAULT);
142:                    g2.setRenderingHint(RenderingHints.KEY_DITHERING,
143:                            RenderingHints.VALUE_DITHER_ENABLE);
144:                }
145:
146:                int round = Integer.parseInt(getStyle().getAttributeString(
147:                        Style.ATTRIBUTE_radius, "0"));
148:                round *= 2;
149:
150:                // 1. Draw backgrouns...
151:                Color c = getStyle().getAttributeColor(
152:                        Style.ATTRIBUTE_backcolor, null);
153:                String transparent = getStyle().getAttributeString(
154:                        Style.ATTRIBUTE_mode, "Transparent");
155:                if (c != null && !transparent.equals("Transparent")) {
156:                    g2.setColor(c);
157:                    g2.fillRoundRect(x, y, width, heigth, round, round);
158:                }
159:
160:                // 1. Draw border...
161:                c = getStyle().getAttributeColor(Style.ATTRIBUTE_forecolor,
162:                        null);
163:                Stroke stroke = ReportElement.getPenStroke(getStyle()
164:                        .getAttributeString(Style.ATTRIBUTE_pen, "Thin"), null,
165:                        1);
166:
167:                if (c != null && stroke != null) {
168:                    g2.setStroke(stroke);
169:                    g2.setColor(c);
170:                    g2.drawRoundRect(x, y, width, heigth, round, round);
171:                }
172:
173:                Box box = new Box();
174:                if (style.getBox() != null) {
175:                    box = style.getBox();
176:                }
177:
178:                /*
179:                if (style.getAttributeString(style.ATTRIBUTE_border, null, true) != null) 
180:                    box.setBorder(  style.getAttributeString(style.ATTRIBUTE_border, null, true) );
181:                if (style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true) != null) 
182:                    box.setBorderColor(  style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true));
183:                if (style.getAttributeString(style.ATTRIBUTE_padding, null, true) != null) 
184:                    box.setPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_padding, null, true) ));
185:
186:                if (style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) != null) 
187:                    box.setTopBorder(  style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) );
188:                if (style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true) != null) 
189:                    box.setTopBorderColor(  style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true));
190:                if (style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) != null) 
191:                    box.setTopPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) ));
192:
193:                if (style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) != null) 
194:                    box.setLeftBorder(  style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) );
195:                if (style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true) != null) 
196:                    box.setLeftBorderColor(  style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true));
197:                if (style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) != null) 
198:                    box.setLeftPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) ));
199:
200:                if (style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) != null) 
201:                    box.setRightBorder(  style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) );
202:                if (style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true) != null) 
203:                    box.setRightBorderColor(  style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true));
204:                if (style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) != null) 
205:                    box.setRightPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) ));
206:
207:                if (style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) != null) 
208:                    box.setBottomBorder(  style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) );
209:                if (style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true) != null) 
210:                    box.setBottomBorderColor(  style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true));
211:                if (style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) != null) 
212:                    box.setBottomPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) ));
213:                 */
214:
215:                int ax = x;
216:                int ay = y;
217:                int bx = x + width;
218:                int by = y + heigth;
219:
220:                Stroke newBoxStroke = null;
221:
222:                writeBorders(g2, box, x, y, width, heigth);
223:
224:                //        
225:                //        if (box.getLeftBorderColor() != null)
226:                //        {
227:                //            g2.setColor(box.getLeftBorderColor());
228:                //        }
229:                //        else
230:                //        {
231:                //            g2.setColor( g2.getBackground());
232:                //        }
233:                //
234:                //        if ((newBoxStroke = ReportElement.getPenStroke(box.getLeftBorder(), box.getLeftPen(),1)) != null)
235:                //        {
236:                //            g2.setStroke(newBoxStroke);
237:                //            g2.drawLine(x, y, x, y+heigth);
238:                //        }
239:                //
240:                //        //else g.setStroke(oldStroke);
241:                //        if (box.getTopBorderColor() != null)
242:                //        {
243:                //            g2.setColor(box.getTopBorderColor());
244:                //        }
245:                //        else
246:                //        {
247:                //            g2.setColor(g2.getBackground());
248:                //        }
249:                //
250:                //        if ((newBoxStroke = ReportElement.getPenStroke(box.getTopBorder(),box.getTopPen(), 1)) != null)
251:                //        {
252:                //            g2.setStroke(newBoxStroke);
253:                //            g2.drawLine(ax, ay, bx, ay);
254:                //        }
255:                //
256:                //        if (box.getRightBorderColor() != null)
257:                //        {
258:                //            g2.setColor(box.getRightBorderColor());
259:                //        }
260:                //        else
261:                //        {
262:                //            g2.setColor( g2.getBackground());
263:                //        }
264:                //
265:                //        if ((newBoxStroke = ReportElement.getPenStroke(box.getRightBorder(),box.getRightPen(), 1)) != null)
266:                //        {
267:                //            g2.setStroke(newBoxStroke);
268:                //            g2.drawLine(bx, ay, bx, by);
269:                //        }
270:                //
271:                //        if (box.getBottomBorderColor() != null)
272:                //        {
273:                //            g2.setColor(box.getBottomBorderColor());
274:                //        }
275:                //        else
276:                //        {
277:                //            g2.setColor(g2.getBackground());
278:                //        }
279:                //
280:                //        if ((newBoxStroke = ReportElement.getPenStroke(box.getBottomBorder(),box.getBottomPen(), 1)) != null)
281:                //        {
282:                //            g2.setStroke(newBoxStroke);
283:                //            g2.drawLine(ax, by, bx, by);
284:                //        }
285:
286:                //renderText(g2, "This is a\ntest", getStyle(), new Box(), width, heigth);
287:                renderText(g2, I18n.getString("jPanelStyleSample.testText",
288:                        "This is a test"),
289:                //"This is a test", 
290:                        getStyle(), box, width, heigth);
291:            }
292:
293:            public void writeBorders(Graphics2D g2d, Box box, int x, int y,
294:                    int width, int heigth) {
295:                int ax = x;
296:                int ay = y;
297:                int bx = x + width;
298:                int by = y + heigth;
299:
300:                boolean defaultPaint = false;
301:                Color defaultColor = Color.BLACK;
302:
303:                Stroke defaultStroke = new BasicStroke(9f);
304:
305:                // Draw the rectangle, border by border...
306:                g2d.setStroke(defaultStroke);
307:                g2d.setColor(Color.LIGHT_GRAY);
308:
309:                if (box != null && box.getPen() != null) {
310:                    Stroke stroke = ReportElement.getPenStroke("",
311:                            box.getPen(), 1f);
312:                    if (stroke != null)
313:                        defaultStroke = stroke;
314:                    defaultPaint = box.getPen().getLineWidth() != 0;
315:                    if (box.getPen().getLineColor() != null) {
316:                        defaultColor = box.getPen().getLineColor();
317:                    }
318:                }
319:
320:                g2d.setStroke(defaultStroke);
321:                g2d.setColor(defaultColor);
322:
323:                boolean paint = defaultPaint;
324:                if (box != null && box.getTopPen() != null) {
325:                    if (box.getTopPen().getLineColor() != null)
326:                        g2d.setColor(box.getTopPen().getLineColor());
327:                    Stroke stroke = ReportElement.getPenStroke("", box
328:                            .getTopPen(), 1f);
329:                    if (stroke != null)
330:                        g2d.setStroke(stroke);
331:                    paint = box.getTopPen().getLineWidth() != 0;
332:                }
333:                if (paint)
334:                    g2d.drawLine(ax, ay, bx, ay);
335:                paint = defaultPaint;
336:
337:                // Draw the rectangle, border by border...
338:                g2d.setStroke(defaultStroke);
339:                g2d.setColor(defaultColor);
340:                if (box != null && box.getRightPen() != null) {
341:                    if (box.getRightPen().getLineColor() != null)
342:                        g2d.setColor(box.getRightPen().getLineColor());
343:                    Stroke stroke = ReportElement.getPenStroke("", box
344:                            .getRightPen(), 1f);
345:                    if (stroke != null)
346:                        g2d.setStroke(stroke);
347:                    paint = box.getRightPen().getLineWidth() != 0;
348:                }
349:                if (paint)
350:                    g2d.drawLine(ax, ay, ax, by);
351:                paint = defaultPaint;
352:
353:                // Draw the rectangle, border by border...
354:                g2d.setStroke(defaultStroke);
355:                g2d.setColor(defaultColor);
356:                if (box != null && box.getBottomPen() != null) {
357:                    if (box.getBottomPen().getLineColor() != null)
358:                        g2d.setColor(box.getBottomPen().getLineColor());
359:                    Stroke stroke = ReportElement.getPenStroke("", box
360:                            .getBottomPen(), 1f);
361:                    if (stroke != null)
362:                        g2d.setStroke(stroke);
363:                    paint = box.getBottomPen().getLineWidth() != 0;
364:                }
365:
366:                if (paint)
367:                    g2d.drawLine(ax, by, bx, by);
368:                paint = defaultPaint;
369:
370:                // Draw the rectangle, border by border...
371:                g2d.setStroke(defaultStroke);
372:                g2d.setColor(defaultColor);
373:                if (box != null && box.getLeftPen() != null) {
374:                    if (box.getLeftPen().getLineColor() != null)
375:                        g2d.setColor(box.getLeftPen().getLineColor());
376:                    Stroke stroke = ReportElement.getPenStroke("", box
377:                            .getLeftPen(), 1f);
378:                    if (stroke != null)
379:                        g2d.setStroke(stroke);
380:                    paint = box.getLeftPen().getLineWidth() != 0;
381:                }
382:                if (paint)
383:                    g2d.drawLine(bx, ay, bx, by);
384:            }
385:
386:            public static IReportFont createIreportFont(Style myStyle) {
387:
388:                if (myStyle.getAttribute("style.font") != null) {
389:                    return (IReportFont) myStyle.getAttribute("style.font");
390:                }
391:
392:                IReportFont ir = new IReportFont();
393:
394:                if (!myStyle.getAttributes().containsKey("style.font")) {
395:                    ir.setBold(myStyle.getAttributeBoolean(
396:                            myStyle.ATTRIBUTE_isBold, false));
397:                    ir.setFontName(myStyle.getAttributeString(
398:                            myStyle.ATTRIBUTE_fontName, ir.getFontName()));
399:                    ir.setFontSize(myStyle.getAttributeInteger(
400:                            myStyle.ATTRIBUTE_fontSize, ir.getFontSize()));
401:                    ir.setItalic(myStyle.getAttributeBoolean(
402:                            myStyle.ATTRIBUTE_isItalic, false));
403:
404:                    ir.setPdfEmbedded(myStyle.getAttributeBoolean(
405:                            myStyle.ATTRIBUTE_isPdfEmbedded, false));
406:                    ir
407:                            .setPdfEncoding(myStyle.getAttributeString(
408:                                    myStyle.ATTRIBUTE_pdfEncoding, ir
409:                                            .getPdfEncoding()));
410:                    ir.setStrikeTrought(myStyle.getAttributeBoolean(
411:                            myStyle.ATTRIBUTE_isStrikeThrough, false));
412:
413:                    // TODO = We have to understand what kind of font is this...
414:                    ir
415:                            .setPDFFontName(myStyle.getAttributeString(
416:                                    myStyle.ATTRIBUTE_pdfFontName, ir
417:                                            .getPDFFontName()));
418:                    ir.setUnderline(myStyle.getAttributeBoolean(
419:                            myStyle.ATTRIBUTE_isUnderline, false));
420:                }
421:                return ir;
422:            }
423:
424:            private class TextReportElementLayout {
425:                private TextLayout layout;
426:                private float x;
427:                private float y;
428:
429:                private TextReportElementLayout(TextLayout layout, float x,
430:                        float y) {
431:                    this .layout = layout;
432:                    this .x = x;
433:                    this .y = y;
434:                }
435:
436:                void drawWithOffset(Graphics2D g2, float yOffset) {
437:                    layout.draw(g2, x, y + yOffset);
438:                }
439:            }
440:
441:            /**
442:             * Render text
443:             */
444:
445:            public void renderText(Graphics2D g, String str, Style s, Box box,
446:                    int width, int height) {
447:
448:                IReportFont ir = createIreportFont(s);
449:                Font font = ir.getJavaAWTFont();
450:
451:                double zoom_factor = 1.0;
452:                int x_shift_origin = 0;
453:                int y_shift_origin = 0;
454:
455:                //System.out.println(new java.util.Date() + " Print text " + this.getText() + " " +  x_shift_origin +" " +y_shift_origin);
456:                ArrayList textLayouts;
457:                float x, y;
458:                TextReportElementLayout textReportElementLayout;
459:                AffineTransform transform;
460:
461:                Point position = new Point(5, 5);
462:                //x_shift_origin -= 10;
463:                //y_shift_origin -= 10;      
464:
465:                g.setColor(s.getAttributeColor(s.ATTRIBUTE_forecolor,
466:                        Color.BLACK));
467:
468:                // Set font to default font....
469:                //Font oldFont = g.getFont();
470:
471:                // Code for rotation by gt (taked by jasperreports...
472:
473:                int gfx_x = position.x + box.getLeftPadding() - x_shift_origin;
474:                int gfx_y = position.y + box.getTopPadding() - y_shift_origin;
475:                int gfx_width = width - box.getLeftPadding()
476:                        - box.getRightPadding();
477:                int gfx_height = height - box.getTopPadding()
478:                        - box.getBottomPadding();
479:
480:                Java2DUtil.setClip(g,
481:                //     0,0, 3000,3000);      
482:                        gfx_x, gfx_y, gfx_width, gfx_height);
483:
484:                double angle = 0;
485:                double angle_restore = 0;
486:
487:                // Apply the transformation "rotation"
488:                // - Do nothing when rotate = "none"
489:                transform = null;
490:                if (s.getAttributeString(s.ATTRIBUTE_rotation, "None").equals(
491:                        ROTATION_LEFT.getName())) {
492:                    transform = new AffineTransform();
493:                    transform.rotate(-Math.PI / 2, gfx_x, gfx_y);
494:                    transform.translate(-gfx_height, -gfx_height);
495:                    gfx_y = position.y - y_shift_origin + height;
496:                    gfx_width = height;
497:                    gfx_height = width;
498:                    Java2DUtil.setTransform(g, transform);
499:                } else if (s.getAttributeString(s.ATTRIBUTE_rotation, "None")
500:                        .equals(ROTATION_RIGHT.getName())) {
501:                    transform = new AffineTransform();
502:                    transform.rotate(Math.PI / 2, gfx_x, gfx_y);
503:                    transform.translate(0, -gfx_width);
504:                    gfx_x = position.x - x_shift_origin + width;
505:                    gfx_width = height;
506:                    gfx_height = width;
507:
508:                    Java2DUtil.setTransform(g, transform);
509:                }
510:
511:                // End code for rotation by gt
512:
513:                // We must center the text..
514:
515:                /*
516:                 Rectangle orgClipBounds = g.getClipBounds();
517:                 g.setClip(getZoomedDim(position.x)-x_shift_origin,
518:                 getZoomedDim(position.y)-y_shift_origin,
519:                 getZoomedDim(width),
520:                 getZoomedDim(height));
521:                 */
522:
523:                if (str != null && str.length() > 0) {
524:                    int zoomedFieldHeight = gfx_height;
525:                    String allText = Misc.treatNewLineChars(str);
526:                    float formatWidth = (float) gfx_width;
527:                    float verticalOffset = 0f;
528:
529:                    FontRenderContext fontRenderContext = g
530:                            .getFontRenderContext();
531:                    java.util.Map fontAttributes = font.getAttributes();
532:                    fontAttributes.put(TextAttribute.SIZE, new Float(ir
533:                            .getFontSize()));
534:                    fontAttributes.put(TextAttribute.FAMILY, ir.getFontName());
535:                    if (ir.isBold()) {
536:                        fontAttributes.put(TextAttribute.WEIGHT,
537:                                TextAttribute.WEIGHT_BOLD);
538:                    }
539:                    if (ir.isItalic()) {
540:                        fontAttributes.put(TextAttribute.POSTURE,
541:                                TextAttribute.POSTURE_OBLIQUE);
542:                    }
543:                    if (ir.isUnderline()) {
544:                        fontAttributes.put(TextAttribute.UNDERLINE,
545:                                TextAttribute.UNDERLINE_ON);
546:                    }
547:                    if (ir.isStrikeTrought()) {
548:                        fontAttributes.put(TextAttribute.STRIKETHROUGH,
549:                                TextAttribute.STRIKETHROUGH_ON);
550:                    }
551:
552:                    float lineSpacing = 1f;
553:                    String lineSpacingName = s.getAttributeString(
554:                            s.ATTRIBUTE_lineSpacing, "Single");
555:                    if (lineSpacingName.equals("Single"))
556:                        lineSpacing = 1f;
557:                    else if (lineSpacingName.equals("1_1_2"))
558:                        lineSpacing = 1.5f;
559:                    else if (lineSpacingName.equals("Double"))
560:                        lineSpacing = 2f;
561:
562:                    AttributedString atext;
563:                    AttributedCharacterIterator paragraph;
564:                    int paragraphStart;
565:                    int paragraphEnd;
566:                    LineBreakMeasurer lineMeasurer;
567:                    TextLayout layout = null;
568:
569:                    String paragr_text = "";
570:                    boolean isMaxHeightReached = false;
571:
572:                    StringTokenizer tkzer = new StringTokenizer(allText, "\n");
573:
574:                    float drawPosY = 0;
575:                    float drawPosX = 0;
576:
577:                    paragr_text = "";
578:                    isMaxHeightReached = false;
579:
580:                    tkzer = new StringTokenizer(allText, "\n");
581:
582:                    textLayouts = new ArrayList();
583:
584:                    // Calculate the layouts. (But don't draw yet because we don't know yet
585:                    //   the offset which is needed if we align the text "middle" or "bottom")
586:                    while (tkzer.hasMoreTokens() && !isMaxHeightReached) {
587:                        paragr_text = tkzer.nextToken();
588:
589:                        atext = new AttributedString(paragr_text,
590:                                fontAttributes);
591:                        paragraph = atext.getIterator();
592:                        paragraphStart = paragraph.getBeginIndex();
593:                        paragraphEnd = paragraph.getEndIndex();
594:                        lineMeasurer = new LineBreakMeasurer(paragraph,
595:                                fontRenderContext);
596:                        lineMeasurer.setPosition(paragraphStart);
597:
598:                        layout = null;
599:                        while (lineMeasurer.getPosition() < paragraphEnd
600:                                && !isMaxHeightReached) {
601:                            layout = lineMeasurer.nextLayout(formatWidth);
602:
603:                            drawPosY += layout.getLeading() + lineSpacing
604:                                    * layout.getAscent();
605:
606:                            if (drawPosY + layout.getDescent() <= zoomedFieldHeight + 1) {
607:                                if (s.getAttributeString(s.ATTRIBUTE_hAlign,
608:                                        "Left").equals("Justify")) {
609:                                    if (layout.isLeftToRight()) {
610:                                        drawPosX = 0;
611:                                    } else {
612:                                        drawPosX = formatWidth
613:                                                - layout.getAdvance();
614:                                    }
615:                                    if (lineMeasurer.getPosition() < paragraphEnd) {
616:                                        layout = layout
617:                                                .getJustifiedLayout(formatWidth);
618:                                    }
619:                                } else if (s.getAttributeString(
620:                                        s.ATTRIBUTE_hAlign, "Left").equals(
621:                                        "Right")) {
622:                                    if (layout.isLeftToRight()) {
623:                                        drawPosX = formatWidth
624:                                                - layout.getAdvance();
625:                                    } else {
626:                                        drawPosX = formatWidth;
627:                                    }
628:                                } else if (s.getAttributeString(
629:                                        s.ATTRIBUTE_hAlign, "Left").equals(
630:                                        "Center")) {
631:                                    drawPosX = (formatWidth - layout
632:                                            .getAdvance()) / 2;
633:                                } else //if (this.getAlign().equals("Left"))
634:                                {
635:                                    if (layout.isLeftToRight()) {
636:                                        drawPosX = 0;
637:                                    } else {
638:                                        drawPosX = formatWidth
639:                                                - layout.getAdvance();
640:                                    }
641:                                }
642:
643:                                x = drawPosX + gfx_x; //getZoomedDim(position.x)-x_shift_origin;
644:                                y = drawPosY + gfx_y; //getZoomedDim(position.y)-y_shift_origin;
645:                                textReportElementLayout = new TextReportElementLayout(
646:                                        layout, x, y);
647:                                textLayouts.add(textReportElementLayout);
648:
649:                                drawPosY += layout.getDescent();
650:                            } else {
651:                                drawPosY -= layout.getLeading() + lineSpacing
652:                                        * layout.getAscent();
653:                                isMaxHeightReached = true;
654:                            }
655:                        }
656:                    }
657:
658:                    // Calculate the offset when aligning the text.
659:                    float textHeight = drawPosY;
660:                    if (s.getAttributeString(s.ATTRIBUTE_vAlign, "Top").equals(
661:                            "Top")) {
662:                        verticalOffset = 0f;
663:                    } else if (s.getAttributeString(s.ATTRIBUTE_vAlign, "Top")
664:                            .equals("Middle")) {
665:                        verticalOffset = ((float) zoomedFieldHeight - textHeight) / 2f;
666:                    } else if (s.getAttributeString(s.ATTRIBUTE_vAlign, "Top")
667:                            .equals("Bottom")) {
668:                        verticalOffset = (float) zoomedFieldHeight
669:                                - (float) textHeight;
670:                    }
671:
672:                    /*
673:                    
674:                     */
675:
676:                    // Now draw the text according to the calculated layouts.
677:                    for (Iterator i = textLayouts.iterator(); i.hasNext();) {
678:                        textReportElementLayout = (TextReportElementLayout) i
679:                                .next();
680:                        textReportElementLayout.drawWithOffset(g,
681:                                verticalOffset);
682:                    }
683:
684:                    if (transform != null) {
685:                        // Undo the transformation "rotation"
686:                        Java2DUtil.resetTransform(g);
687:                    }
688:
689:                    /*
690:                    int txt_width = g.getFontMetrics().stringWidth( this.getText() )/2;
691:                    int txt_height = g.getFontMetrics().getHeight();
692:                     
693:                    StringTokenizer st = new StringTokenizer(getText(),"\n");
694:                    while( st.hasMoreElements())
695:                    {
696:                     String line = st.nextToken();
697:                      float formatWidth = (float) this.getWidth();
698:                     g.drawString(line,
699:                        (float)(getZoomedDim(position.x)-x_shift_origin),
700:                        getZoomedDim(position.y)-y_shift_origin +  verticalOffset); //, zoomed_width, getZoomedDim(band.getHeight()
701:                     
702:                        verticalOffset += g.getFontMetrics().getHeight();
703:                    }
704:                     */
705:                    //g.drawLine(0, getZoomedDim(y)+10-vertical_scroll -  txt_height - getZoomedDim(band.getHeight()/2),  700,getZoomedDim(y)+10-vertical_scroll -  txt_height - getZoomedDim(band.getHeight()/2));
706:                    //g.drawLine(0, getZoomedDim(y)+10-vertical_scroll +  txt_height - getZoomedDim(band.getHeight()/2),  700,getZoomedDim(y)+10-vertical_scroll +  txt_height - getZoomedDim(band.getHeight()/2));
707:                }
708:
709:                //g.setClip(null);
710:                //g.setClip(orgClipBounds);
711:
712:                Java2DUtil.resetClip(g);
713:
714:            }
715:
716:            static class Rotation {
717:                static private ArrayList rotations;
718:                private String name;
719:                private int number;
720:
721:                Rotation(String name, int number) {
722:                    this .name = name;
723:                    this .number = number;
724:                    rotations = new ArrayList();
725:                    rotations.add(this );
726:                }
727:
728:                public int getNumber() {
729:                    return number;
730:                }
731:
732:                public String getName() {
733:                    return name;
734:                }
735:
736:                public String toString() {
737:                    return getName();
738:                }
739:            }
740:
741:            static List getRotations() {
742:                return Rotation.rotations;
743:            }
744:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.