16 package net.squiz.matrix.ui;
19 import java.awt.event.*;
20 import java.awt.image.*;
23 import javax.swing.event.*;
24 import javax.swing.tree.TreePath;
25 import javax.swing.plaf.metal.*;
27 import net.squiz.matrix.assetmap.*;
28 import net.squiz.matrix.matrixtree.*;
29 import net.squiz.matrix.plaf.*;
30 import com.sun.java.swing.plaf.windows.*;
34 private boolean tabsVertical;
50 tabsVertical = (tabPlacement == LEFT || tabPlacement == RIGHT);
55 setUI(
new VerticalTabbedPaneUI(tabsVertical));
81 public void addTab(String s, Icon icon, Component c) {
82 Icon textIcon =
new VerticalTextIcon(s, getTabPlacement() == RIGHT);
83 VerticalCompoundIcon compoundIcon =
new VerticalCompoundIcon(textIcon, icon, 0, 0);
86 tabsVertical ? null : s,
87 tabsVertical ? compoundIcon : null,
93 BufferedImage image =
new BufferedImage(
94 compoundIcon.getIconWidth(),
95 compoundIcon.getIconHeight(),
96 BufferedImage.TYPE_INT_ARGB_PRE
98 Graphics2D g = image.createGraphics();
99 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
100 compoundIcon.paintIcon(null, g, 0, 0);
102 setDisabledIconAt(indexOfComponent(c),
new ImageIcon(GrayFilter.createDisabledImage(image)));
105 private class VerticalCompoundIcon
extends CompoundIcon
108 public VerticalCompoundIcon (Icon mainIcon, Icon decorator,
int xAlignment,
int yAlignment)
110 if (!isLegalValue(xAlignment, VALID_X)) {
111 throw new IllegalArgumentException(
112 "xAlignment must be LEFT, RIGHT or CENTER");
114 if (!isLegalValue(yAlignment, VALID_Y)) {
115 throw new IllegalArgumentException(
116 "yAlignment must be TOP, BOTTOM or CENTER");
119 this.mainIcon = mainIcon;
120 this.decorator = decorator;
121 this.xAlignment = xAlignment;
122 this.yAlignment = yAlignment;
131 public int getIconWidth() {
132 if (mainIcon.getIconWidth() > decorator.getIconWidth()) {
133 return mainIcon.getIconWidth() - 7;
135 return decorator.getIconWidth() - 7;
144 public int getIconHeight() {
145 return mainIcon.getIconHeight() + decorator.getIconHeight();
156 public void paintIcon(Component c, Graphics g,
int x,
int y) {
158 int middleX = (x + x + getIconWidth()) / 2;
159 int middleY = (y + y + getIconHeight()) / 2;
161 Graphics2D g2 = (Graphics2D) g.create();
163 int mainIconX = middleX - (mainIcon.getIconWidth() / 2);
164 mainIcon.paintIcon(c, g2, mainIconX, y);
166 g2.rotate(Math.toRadians(-90), middleX, middleY);
168 int decoratorX = middleX - (getIconHeight() / 2);
169 int decoratorY = middleY - (decorator.getIconHeight() / 2);
174 decoratorX + (mainIcon.getIconWidth() / 2) + 2,
182 private class VerticalTextIcon
implements Icon {
183 private String tabText;
184 private boolean clockwise;
191 public VerticalTextIcon(String tabText,
boolean clockwise) {
192 this.tabText = tabText;
193 this.clockwise = clockwise;
204 public void paintIcon(Component c, Graphics g,
int x,
int y) {
205 Graphics2D g2 = (Graphics2D) g;
207 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
211 g2.rotate(Math.toRadians(clockwise ? 90 : -90), x, y);
212 g2.setFont((Font)UIManager.get(
"VerticalTextIcon.font"));
216 x - (clockwise ? 0 : getIconHeight()) + 8,
217 y + (clockwise ? 0 : getIconWidth()));
218 g2.rotate (Math.toRadians(clockwise ? - 90 : 90), x, y
226 public int getIconWidth() {
234 public int getIconHeight() {
235 return getFontMetrics(getFont()).stringWidth(tabText) + 20;