01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.lib.client.components.docking;
15:
16: import org.jetbrains.annotations.NotNull;
17: import org.jetbrains.annotations.Nullable;
18:
19: import javax.swing.*;
20: import javax.swing.plaf.ButtonUI;
21: import java.awt.*;
22:
23: /**
24: * User: Martin
25: * Date: 24.03.2005
26: * Time: 13:50:20
27: */
28: public class ImageToggleButton extends JToggleButton {
29:
30: @NotNull
31: private ImageIcon imageIcon;
32: @NotNull
33: private String text;
34: @Nullable
35: private ToolWindow.Alignment alignment;
36:
37: public ImageToggleButton(@NotNull
38: ImageIcon icon, @NotNull
39: String text) {
40: super ();
41: this .imageIcon = icon;
42: this .text = text;
43:
44: setMargin(new Insets(1, 1, 1, 1));
45:
46: setFont(getFont().deriveFont(Font.PLAIN));
47:
48: alignment = ToolWindow.Alignment.LEFT;
49: setAlignmentX(ToolWindow.Alignment.LEFT);
50:
51: setFocusable(false);
52: }
53:
54: public void setAlignmentX(@NotNull
55: ToolWindow.Alignment alignment) {
56: this .alignment = alignment;
57:
58: switch (alignment) {
59: case TOP:
60: case BOTTOM: {
61: ImageIcon icon = IconCreator.createRotatedTextIcon(
62: getForeground(), RotateTextIcon.NONE, getFont(),
63: text);
64: icon = IconCreator.createComposedImageIcon(this .imageIcon,
65: icon, IconCreator.FirstIconAlignment.LEFT);
66: setIcon(icon);
67: break;
68: }
69: case LEFT: {
70: ImageIcon icon = IconCreator.createRotatedTextIcon(
71: getForeground(), RotateTextIcon.CCW, getFont(),
72: text);
73: icon = IconCreator.createComposedImageIcon(this .imageIcon,
74: icon, IconCreator.FirstIconAlignment.BOTTOM);
75: setIcon(icon);
76: break;
77: }
78: case RIGHT: {
79: ImageIcon icon = IconCreator
80: .createRotatedTextIcon(getForeground(),
81: RotateTextIcon.CW, getFont(), text);
82: icon = IconCreator.createComposedImageIcon(this .imageIcon,
83: icon, IconCreator.FirstIconAlignment.TOP);
84: setIcon(icon);
85: break;
86: }
87: }
88: }
89:
90: public void setUI(@NotNull
91: ButtonUI ui) {
92: super.setUI(ui);
93:
94: if (alignment != null) {
95: setAlignmentX(alignment);
96: }
97: }
98: }
|