Debian Codegraph @

src/dr/app/gui/components/JVerticalLabel.java

raw symbols SCIP
1 /*
2 * JVerticalLabel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.gui.components;
27
28 import javax.swing.*;
29
30 public class JVerticalLabel extends JLabel {
31 private boolean clockwise;
32
33 public JVerticalLabel(boolean clockwise) {
34 super();
35 this.clockwise = clockwise;
36 }
37
38 public JVerticalLabel(Icon image, boolean clockwise) {
39 super(image);
40 this.clockwise = clockwise;
41 }
42
43 public JVerticalLabel(Icon image, int horizontalAlignment, boolean clockwise) {
44 super(image, horizontalAlignment);
45 this.clockwise = clockwise;
46 }
47
48 public JVerticalLabel(String text, boolean clockwise) {
49 super(text);
50 this.clockwise = clockwise;
51 }
52
53 public JVerticalLabel(String text, Icon image, int horizontalAlignment, boolean clockwise) {
54 super(text, image, horizontalAlignment);
55 this.clockwise = clockwise;
56 }
57
58 public JVerticalLabel(String text, int horizontalAlignment, boolean clockwise) {
59 super(text, horizontalAlignment);
60 this.clockwise = clockwise;
61 }
62
63 public java.awt.Dimension getPreferredSize() {
64 java.awt.Insets ins = getInsets();
65 java.awt.FontMetrics fm = getFontMetrics(getFont());
66 String text = getText();
67 int h = fm.stringWidth(text), descent = fm.getDescent(),
68 ascent = fm.getAscent();
69 return new java.awt.Dimension(ins.top + ascent + descent + ins.bottom,
70 ins.right + h + ins.left);
71 }
72
73 public void paint(java.awt.Graphics g) {
74 java.awt.Graphics2D g2d = (java.awt.Graphics2D) g.create();
75
76 String text = getText();
77 java.awt.Dimension size = getSize();
78 java.awt.Insets ins = getInsets();
79
80 java.awt.FontMetrics fm = g2d.getFontMetrics(getFont());
81 int h = fm.stringWidth(text), x = ins.right;
82
83 switch (getHorizontalAlignment()) {
84 case SwingConstants.CENTER:
85 x = (size.height - h + ins.right - ins.left) / 2;
86 break;
87 case SwingConstants.TOP:
88 x = size.height - h - ins.left;
89 break;
90 }
91 int descent = fm.getDescent(), ascent = fm.getAscent(),
92 y = ins.top + ascent;
93 switch (getVerticalAlignment()) {
94 case SwingConstants.CENTER:
95 y = (size.width + ascent - descent + ins.top - ins.bottom) / 2;
96 break;
97 case SwingConstants.RIGHT:
98 y = size.width - descent - ins.bottom;
99 break;
100 }
101
102 java.awt.geom.AffineTransform trans;
103
104 if (clockwise) {
105 trans = new java.awt.geom.AffineTransform(0, 1, -1, 0, -size.height, 0);
106 } else {
107 trans = new java.awt.geom.AffineTransform(0, -1, 1, 0, 0, size.height);
108 }
109 g2d.transform(trans);
110 g2d.setPaintMode();
111 if (isOpaque() && (getBackground() != null)) {
112 g2d.setColor(getBackground());
113 g2d.fillRect(0, 0, size.height, size.width);
114 }
115 g2d.setFont(getFont());
116 g2d.setColor(getForeground());
117 g2d.drawString(text, x, y);
118 trans = null;
119 g2d = null;
120 }
121 }
122
123
124