| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|