Debian Codegraph @

laf-widget/src/main/java/org/pushingpixels/lafwidget/tabbed/TabOverviewButton.java

raw
1 /*
2 * Copyright (c) 2005-2010 Laf-Widget Kirill Grouchnikov. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * o Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * o Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * o Neither the name of Laf-Widget Kirill Grouchnikov nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package org.pushingpixels.lafwidget.tabbed;
31
32 import java.awt.Insets;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35
36 import javax.swing.*;
37 import javax.swing.plaf.UIResource;
38
39 import org.pushingpixels.lafwidget.*;
40
41 /**
42 * Button that activates the tab overview dialog.
43 *
44 * @author Kirill Grouchnikov
45 */
46 public class TabOverviewButton extends JButton implements UIResource {
47 /**
48 * Client property name for locking undesired bound set.
49 */
50 private static final String OWN_BOUNDS = "lafwidget.ownBounds";
51
52 /**
53 * Creates a new tab overview button.
54 *
55 * @param tabPane
56 * The owner tabbed pane.
57 */
58 public TabOverviewButton(final JTabbedPane tabPane) {
59 this.setFocusable(false);
60 LafWidgetSupport support = LafWidgetRepository.getRepository()
61 .getLafSupport();
62
63 if (support != null) {
64 Icon searchIcon = support.getSearchIcon(LafWidgetRepository
65 .getRepository().getLafSupport().getLookupIconSize(),
66 tabPane.getComponentOrientation());
67 this.setIcon(searchIcon);
68 support.markButtonAsFlat(this);
69 }
70 this.setToolTipText(LafWidgetUtilities.getResourceBundle(tabPane).getString(
71 "TabbedPane.overviewButtonTooltip"));
72
73 this.addActionListener(new ActionListener() {
74 @Override
75 public void actionPerformed(ActionEvent e) {
76 TabOverviewDialog.getOverviewDialog(tabPane).setVisible(true);
77 }
78 });
79 }
80
81 /*
82 * (non-Javadoc)
83 *
84 * @see java.awt.Component#setBounds(int, int, int, int)
85 */
86 @Override
87 public void setBounds(int x, int y, int width, int height) {
88 if (Boolean.TRUE.equals(this
89 .getClientProperty(TabOverviewButton.OWN_BOUNDS)))
90 super.setBounds(x, y, width, height);
91 }
92
93 /**
94 * Updates the location of <code>this</code> tab overview button.
95 *
96 * @param tabbedPane
97 * Tabbed pane.
98 * @param tabAreaInsets
99 * Tab area insets.
100 */
101 public void updateLocation(JTabbedPane tabbedPane, Insets tabAreaInsets) {
102 if (tabbedPane == null)
103 return;
104
105 // Lock the button for the bounds change
106 this.putClientProperty(TabOverviewButton.OWN_BOUNDS, Boolean.TRUE);
107 int buttonSize = LafWidgetRepository.getRepository().getLafSupport()
108 .getLookupButtonSize();
109
110 switch (tabbedPane.getTabPlacement()) {
111 case SwingConstants.TOP:
112 if (tabbedPane.getComponentOrientation().isLeftToRight())
113 this.setBounds(2, tabAreaInsets.top, buttonSize, buttonSize);
114 else
115 this.setBounds(tabbedPane.getBounds().width
116 - tabAreaInsets.right - buttonSize - 2,
117 tabAreaInsets.top, buttonSize, buttonSize);
118 break;
119 case SwingConstants.BOTTOM:
120 if (tabbedPane.getComponentOrientation().isLeftToRight())
121 this.setBounds(2, tabbedPane.getBounds().height
122 - tabAreaInsets.bottom - buttonSize - 4, buttonSize,
123 buttonSize);
124 else
125 this.setBounds(tabbedPane.getBounds().width
126 - tabAreaInsets.right - buttonSize - 2, tabbedPane
127 .getBounds().height
128 - tabAreaInsets.bottom - buttonSize - 4, buttonSize,
129 buttonSize);
130 break;
131 case SwingConstants.LEFT:
132 this.setBounds(2, tabAreaInsets.top - 1, buttonSize, buttonSize);
133 break;
134 case SwingConstants.RIGHT:
135 this.setBounds(tabbedPane.getBounds().width - tabAreaInsets.right
136 - buttonSize - 2, tabAreaInsets.top - 1, buttonSize,
137 buttonSize);
138 break;
139 }
140 // Unlock the button for the bounds change
141 this.putClientProperty(TabOverviewButton.OWN_BOUNDS, null);
142 }
143 }