01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.crm.report.tests;
15:
16: import org.jetbrains.annotations.NonNls;
17: import org.jetbrains.annotations.NotNull;
18: import org.pentaho.reportdesigner.lib.client.components.docking.IconCreator;
19: import org.pentaho.reportdesigner.lib.client.components.docking.RotateTextIcon;
20:
21: import javax.swing.*;
22: import java.awt.*;
23:
24: /**
25: * User: Martin
26: * Date: 27.01.2006
27: * Time: 13:14:26
28: */
29: @SuppressWarnings({"ALL"})
30: public class DrawRotatedTextTester {
31:
32: public static void main(@NotNull
33: String[] args) {
34: JFrame frame = new JFrame();
35: Toolkit.getDefaultToolkit().setDynamicLayout(true);
36: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
37:
38: frame.getContentPane().setLayout(null);
39: Label label = new Label();
40: frame.getContentPane().add(label);
41: label.setBounds(10, 10, 101, 101);
42: frame.setBounds(100, 100, 200, 200);
43: frame.setVisible(true);
44: }
45:
46: @NonNls
47: private static class Label extends JComponent {
48: @NotNull
49: private static final String DEFAULT_FONT_FACE = "dialog";
50:
51: @NotNull
52: private Font font;
53:
54: public Label() {
55: font = new Font(DEFAULT_FONT_FACE, Font.BOLD, 14);
56: }
57:
58: public Dimension getPreferredSize() {
59: return new Dimension(100, 100);
60: }
61:
62: protected void paintComponent(@NotNull
63: Graphics g) {
64: g.drawRect(0, 0, 100, 100);
65: g.setColor(Color.WHITE);
66: g.fillRect(1, 1, 98, 98);
67:
68: g.setColor(Color.BLACK);
69:
70: //Graphics2D g2d = (Graphics2D) g;
71: //AffineTransform transform = g2d.getTransform();
72: //AffineTransform at = new AffineTransform();
73: //at.setToRotation(-Math.PI / 2.0);
74: //g.setFont(font);
75: //Rectangle2D stringBounds = g.getFont().getStringBounds("aString", new FontRenderContext(null, false, false));
76: //System.out.println("stringBounds = " + stringBounds);
77: //g2d.setTransform(at);
78: //g2d.drawString("aString", (int) -stringBounds.getWidth() - 10, (int) (stringBounds.getHeight() + 0.5));
79: //g2d.setTransform(transform);
80: long l1 = System.nanoTime();
81: IconCreator
82: .drawRotatedText((Graphics2D) g, 0, 0, Color.BLACK,
83: RotateTextIcon.CCW, g.getFont(), "123");
84: long l2 = System.nanoTime();
85: System.out.println("l2-l1 = " + (l2 - l1) / 1000.);
86: }
87: }
88:
89: }
|