01: package com.jidesoft.plaf.xerto;
02:
03: import javax.swing.*;
04: import javax.swing.plaf.basic.BasicLabelUI;
05: import java.awt.*;
06: import java.awt.geom.AffineTransform;
07:
08: /**
09: * VerticalLabelUI - used to replace the UI on a JLabel to make it vertical
10: *
11: * @author Created by Jasper Potts (10-Jun-2004)
12: * @version 1.0
13: */
14: public class VerticalLabelUI extends BasicLabelUI {
15: static {
16: labelUI = new VerticalLabelUI(false);
17: }
18:
19: protected boolean clockwise;
20:
21: public VerticalLabelUI(boolean clockwise) {
22: super ();
23: this .clockwise = clockwise;
24: }
25:
26: @Override
27: public Dimension getPreferredSize(JComponent c) {
28: Dimension dim = super .getPreferredSize(c);
29: return new Dimension(dim.height, dim.width);
30: }
31:
32: private static Rectangle s_oPaintIconRectangle = new Rectangle();
33: private static Rectangle s_oPaintTextRectangle = new Rectangle();
34: private static Rectangle s_oPaintViewRectangle = new Rectangle();
35: private static Insets s_oPaintViewInsets = new Insets(0, 0, 0, 0);
36:
37: @Override
38: public void paint(Graphics i_oGraphics, JComponent i_oComponent) {
39: JLabel oLabel = (JLabel) i_oComponent;
40: String oText = oLabel.getText();
41: Icon oIcon = (oLabel.isEnabled()) ? oLabel.getIcon() : oLabel
42: .getDisabledIcon();
43:
44: if ((oIcon == null) && (oText == null)) {
45: return;
46: }
47:
48: FontMetrics oFontMetrics = i_oGraphics.getFontMetrics();
49: s_oPaintViewInsets = i_oComponent.getInsets(s_oPaintViewInsets);
50:
51: s_oPaintViewRectangle.x = s_oPaintViewInsets.left;
52: s_oPaintViewRectangle.y = s_oPaintViewInsets.top;
53:
54: // Use inverted height & width
55: s_oPaintViewRectangle.height = i_oComponent.getWidth()
56: - (s_oPaintViewInsets.left + s_oPaintViewInsets.right);
57: s_oPaintViewRectangle.width = i_oComponent.getHeight()
58: - (s_oPaintViewInsets.top + s_oPaintViewInsets.bottom);
59:
60: s_oPaintIconRectangle.x = s_oPaintIconRectangle.y = s_oPaintIconRectangle.width = s_oPaintIconRectangle.height = 0;
61: s_oPaintTextRectangle.x = s_oPaintTextRectangle.y = s_oPaintTextRectangle.width = s_oPaintTextRectangle.height = 0;
62:
63: String sClippedText = layoutCL(oLabel, oFontMetrics, oText,
64: oIcon, s_oPaintViewRectangle, s_oPaintIconRectangle,
65: s_oPaintTextRectangle);
66:
67: Graphics2D g2 = (Graphics2D) i_oGraphics;
68: AffineTransform oTransform = g2.getTransform();
69: if (clockwise) {
70: g2.rotate(Math.PI / 2);
71: g2.translate(0, -i_oComponent.getWidth());
72: } else {
73: g2.rotate(-Math.PI / 2);
74: g2.translate(-i_oComponent.getHeight(), 0);
75: }
76:
77: if (oIcon != null) {
78: oIcon.paintIcon(i_oComponent, i_oGraphics,
79: s_oPaintIconRectangle.x, s_oPaintIconRectangle.y);
80: }
81:
82: if (oText != null) {
83: int iTextX = s_oPaintTextRectangle.x;
84: int iTextY = s_oPaintTextRectangle.y
85: + oFontMetrics.getAscent();
86:
87: if (oLabel.isEnabled()) {
88: paintEnabledText(oLabel, i_oGraphics, sClippedText,
89: iTextX, iTextY);
90: } else {
91: paintDisabledText(oLabel, i_oGraphics, sClippedText,
92: iTextX, iTextY);
93: }
94: }
95:
96: g2.setTransform(oTransform);
97: }
98: }
|