01: /*******************************************************************************
02: * Copyright (c) 2007-2008 Kirill Grouchnikov and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *******************************************************************************/package test;
08:
09: import java.awt.*;
10:
11: import javax.swing.*;
12:
13: import org.jvnet.substance.SubstanceLookAndFeel;
14: import org.jvnet.substance.border.BorderPainterChangeListener;
15: import org.jvnet.substance.painter.text.SubstanceTextPainter;
16: import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;
17:
18: public class VerticalTexts extends JFrame {
19: protected static class VerticalPanel extends JPanel {
20: private Font font;
21:
22: public VerticalPanel(Font font) {
23: this .font = font;
24: }
25:
26: @Override
27: protected void paintComponent(Graphics g) {
28: g.setColor(Color.white);
29: g.fillRect(0, 0, getWidth(), getHeight());
30:
31: SubstanceTextPainter textPainter = SubstanceLookAndFeel
32: .getCurrentTextPainter();
33: textPainter.init(this , null, true);
34: textPainter.setBackgroundFill(this , Color.lightGray, false,
35: 0, 0);
36: final Rectangle[] rectsT2B = new Rectangle[] {
37: new Rectangle(40, 10, 20, 100),
38: new Rectangle(130, 100, 20, 100),
39: new Rectangle(10, 40, 20, 100) };
40: final Rectangle[] rectsB2T = new Rectangle[] {
41: new Rectangle(80, 10, 20, 100),
42: new Rectangle(10, 150, 20, 100),
43: new Rectangle(50, 120, 20, 100) };
44: textPainter
45: .attachCallback(new SubstanceTextPainter.BackgroundPaintingCallback() {
46: public void paintBackground(Graphics g) {
47: g.setColor(Color.blue);
48: for (Rectangle rect : rectsT2B)
49: g.drawRect(rect.x, rect.y, rect.width,
50: rect.height);
51: g.setColor(Color.red);
52: for (Rectangle rect : rectsB2T)
53: g.drawRect(rect.x, rect.y, rect.width,
54: rect.height);
55: }
56: });
57: int count = 0;
58: for (Rectangle rect : rectsT2B) {
59: textPainter.attachVerticalText(this , rect, "Some text "
60: + (++count), -1, this .font, Color.red, null,
61: false);
62: }
63: for (Rectangle rect : rectsB2T) {
64: textPainter.attachVerticalText(this , rect, "Some text "
65: + (++count), -1, this .font, Color.blue, null,
66: true);
67: }
68: textPainter.renderSurface(g);
69: }
70: }
71:
72: public VerticalTexts() {
73: super ("Vertical SWT texts");
74: this .setLayout(new BorderLayout());
75: this
76: .add(new VerticalPanel(new Font("Segoe UI", Font.PLAIN,
77: 12)), BorderLayout.CENTER);
78:
79: this .setSize(400, 400);
80: this .setLocationRelativeTo(null);
81: this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
82: }
83:
84: public static void main(String[] args) throws Exception {
85: UIManager
86: .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
87: SwingUtilities.invokeLater(new Runnable() {
88: public void run() {
89: new VerticalTexts().setVisible(true);
90: }
91: });
92: }
93:
94: }
|