Debian Codegraph @

laf-widget/src/main/java/org/pushingpixels/lafwidget/tabbed/TabOverviewDialogWidget.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.*;
34 import java.beans.PropertyChangeEvent;
35 import java.beans.PropertyChangeListener;
36
37 import javax.swing.*;
38
39 import org.pushingpixels.lafwidget.*;
40
41 /**
42 * Adds tab overview dialog to tabbed panes.
43 *
44 * @author Kirill Grouchnikov
45 */
46 public class TabOverviewDialogWidget extends LafWidgetAdapter<JTabbedPane> {
47 /**
48 * Tab overview button.
49 */
50 protected TabOverviewButton overviewButton;
51
52 /**
53 * Listens on changes to relevant tabbed pane properties.
54 */
55 protected PropertyChangeListener propertyListener;
56
57 /**
58 * Listens on tabs being added or removed.
59 */
60 protected ContainerListener containerListener;
61
62 /*
63 * (non-Javadoc)
64 *
65 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#installComponents()
66 */
67 @Override
68 public void installComponents() {
69 this.overviewButton = new TabOverviewButton(this.jcomp);
70 }
71
72 /*
73 * (non-Javadoc)
74 *
75 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#installDefaults()
76 */
77 @Override
78 public void installDefaults() {
79 TabPreviewPainter previewPainter = LafWidgetUtilities2
80 .getTabPreviewPainter(this.jcomp);
81 if ((previewPainter != null)
82 && previewPainter.hasOverviewDialog(this.jcomp)) {
83
84 LafWidgetSupport lafSupport = LafWidgetRepository.getRepository()
85 .getLafSupport();
86
87 Insets currTabAreaInsets = lafSupport.getTabAreaInsets(this.jcomp);
88 if (currTabAreaInsets == null)
89 currTabAreaInsets = UIManager
90 .getInsets("TabbedPane.tabAreaInsets");
91
92 Insets tabAreaInsets = new Insets(currTabAreaInsets.top,
93 LafWidgetRepository.getRepository().getLafSupport()
94 .getLookupButtonSize()
95 + 2 + currTabAreaInsets.left,
96 currTabAreaInsets.bottom, currTabAreaInsets.right);
97 lafSupport.setTabAreaInsets(this.jcomp, tabAreaInsets);
98
99 this.jcomp.add(this.overviewButton);
100 this.overviewButton.setVisible(true);
101 this.jcomp.setComponentZOrder(this.overviewButton, 0);
102 this.overviewButton.updateLocation(this.jcomp, tabAreaInsets);
103 }
104 }
105
106 /*
107 * (non-Javadoc)
108 *
109 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#uninstallComponents()
110 */
111 @Override
112 public void uninstallComponents() {
113 if (this.overviewButton.getParent() == this.jcomp)
114 this.jcomp.remove(this.overviewButton);
115 }
116
117 /*
118 * (non-Javadoc)
119 *
120 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#installListeners()
121 */
122 @Override
123 public void installListeners() {
124 this.propertyListener = new PropertyChangeListener() {
125 @Override
126 public void propertyChange(PropertyChangeEvent evt) {
127 LafWidgetSupport lafSupport = LafWidgetRepository
128 .getRepository().getLafSupport();
129
130 Insets lafInsets = lafSupport
131 .getTabAreaInsets(TabOverviewDialogWidget.this.jcomp);
132 final Insets currTabAreaInsets = (lafInsets == null) ? UIManager
133 .getInsets("TabbedPane.tabAreaInsets")
134 : lafInsets;
135
136 if (LafWidget.TABBED_PANE_PREVIEW_PAINTER.equals(evt
137 .getPropertyName())) {
138 TabPreviewPainter previewPainter = LafWidgetUtilities2
139 .getTabPreviewPainter(TabOverviewDialogWidget.this.jcomp);
140
141 if ((previewPainter != null)
142 && previewPainter
143 .hasOverviewDialog(TabOverviewDialogWidget.this.jcomp)) {
144 Insets tabAreaInsets = new Insets(
145 currTabAreaInsets.top, LafWidgetRepository
146 .getRepository().getLafSupport()
147 .getLookupButtonSize()
148 + 2 + currTabAreaInsets.left,
149 currTabAreaInsets.bottom,
150 currTabAreaInsets.right);
151 lafSupport.setTabAreaInsets(
152 TabOverviewDialogWidget.this.jcomp,
153 tabAreaInsets);
154 TabOverviewDialogWidget.this.jcomp
155 .add(TabOverviewDialogWidget.this.overviewButton);
156 TabOverviewDialogWidget.this.overviewButton
157 .setVisible(true);
158 // jtp.setComponentZOrder(overviewButton, 0);
159 TabOverviewDialogWidget.this.overviewButton
160 .updateLocation(
161 TabOverviewDialogWidget.this.jcomp,
162 tabAreaInsets);
163 } else {
164 TabOverviewDialogWidget.this.jcomp
165 .remove(TabOverviewDialogWidget.this.overviewButton);
166 }
167 }
168 if ("tabPlacement".equals(evt.getPropertyName())
169 || "componentOrientation".equals(evt.getPropertyName())
170 || "tabAreaInsets".equals(evt.getPropertyName())) {
171 SwingUtilities.invokeLater(new Runnable() {
172 @Override
173 public void run() {
174 if (TabOverviewDialogWidget.this.overviewButton
175 .getParent() == TabOverviewDialogWidget.this.jcomp)
176 TabOverviewDialogWidget.this.overviewButton
177 .updateLocation(
178 TabOverviewDialogWidget.this.jcomp,
179 currTabAreaInsets);
180 }
181 });
182 }
183 }
184 };
185 this.jcomp.addPropertyChangeListener(this.propertyListener);
186
187 this.containerListener = new ContainerAdapter() {
188 @Override
189 public void componentAdded(ContainerEvent e) {
190 syncOverviewButtonVisibility();
191 }
192
193 @Override
194 public void componentRemoved(ContainerEvent e) {
195 syncOverviewButtonVisibility();
196 }
197
198 /**
199 * Syncs the visibility of the tab overview button.
200 */
201 private void syncOverviewButtonVisibility() {
202 if (overviewButton.getParent() != jcomp)
203 return;
204 // fix for issue 12 - hide the overview button when
205 // there are no tabs
206 overviewButton.setVisible(jcomp.getTabCount() > 0);
207 }
208 };
209 this.jcomp.addContainerListener(this.containerListener);
210 }
211
212 /*
213 * (non-Javadoc)
214 *
215 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#uninstallListeners()
216 */
217 @Override
218 public void uninstallListeners() {
219 this.jcomp.removePropertyChangeListener(this.propertyListener);
220 this.propertyListener = null;
221
222 this.jcomp.removeContainerListener(this.containerListener);
223 this.containerListener = null;
224 }
225
226 /*
227 * (non-Javadoc)
228 *
229 * @see org.pushingpixels.lafwidget.LafWidget#requiresCustomLafSupport()
230 */
231 @Override
232 public boolean requiresCustomLafSupport() {
233 return false;
234 }
235 }