2
* Copyright (c) 2005-2010 Laf-Widget Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
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.
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.
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.
30
package org.pushingpixels.lafwidget.scroll;
32
import java.awt.event.HierarchyEvent;
33
import java.awt.event.HierarchyListener;
34
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeListener;
37
import javax.swing.JScrollPane;
38
import javax.swing.plaf.basic.ComboPopup;
40
import org.pushingpixels.lafwidget.*;
41
import org.pushingpixels.lafwidget.preview.PreviewPainter;
44
* Widget that decorates scroll panes with selector.
46
* @author Kirill Grouchnikov
48
public class ScrollPaneSelectorWidget extends LafWidgetAdapter<JScrollPane> {
50
* The scroll pane selector for the associated scroll pane.
52
protected ScrollPaneSelector scrollPaneSelector;
55
* Hierarchy listener - remove the selector in the scroll pane of a combo
58
protected HierarchyListener hierarchyListener;
61
* Property change listener - listens on the changes to
62
* {@link LafWidget#COMPONENT_PREVIEW_PAINTER} property.
64
protected PropertyChangeListener propertyChangeListener;
69
* @see org.pushingpixels.lafwidget.LafWidget#requiresCustomLafSupport()
72
public boolean requiresCustomLafSupport() {
79
* @see org.pushingpixels.lafwidget.LafWidgetAdapter#installUI()
82
public void installUI() {
83
if (LafWidgetRepository.getRepository().getLafSupport()
84
.toInstallExtraElements(this.jcomp)) {
86
PreviewPainter pPainter = LafWidgetUtilities2
87
.getComponentPreviewPainter(this.jcomp);
90
this.scrollPaneSelector = new ScrollPaneSelector();
91
this.scrollPaneSelector.installOnScrollPane(this.jcomp);
98
* @see org.pushingpixels.lafwidget.LafWidgetAdapter#uninstallUI()
101
public void uninstallUI() {
102
if (this.scrollPaneSelector != null) {
103
this.scrollPaneSelector.uninstallFromScrollPane();
104
this.scrollPaneSelector = null;
109
public void installListeners() {
110
this.hierarchyListener = new HierarchyListener() {
115
* java.awt.event.HierarchyListener#hierarchyChanged(java.awt.event
119
public void hierarchyChanged(HierarchyEvent e) {
120
if (jcomp.getParent() instanceof ComboPopup) {
121
if (scrollPaneSelector != null) {
122
scrollPaneSelector.uninstallFromScrollPane();
123
scrollPaneSelector = null;
128
this.jcomp.addHierarchyListener(this.hierarchyListener);
130
this.propertyChangeListener = new PropertyChangeListener() {
132
public void propertyChange(PropertyChangeEvent evt) {
133
if (LafWidget.COMPONENT_PREVIEW_PAINTER.equals(evt
134
.getPropertyName())) {
135
PreviewPainter pPainter = LafWidgetUtilities2
136
.getComponentPreviewPainter(jcomp);
137
// Uninstall old scroll pane selector
138
if (scrollPaneSelector != null) {
139
scrollPaneSelector.uninstallFromScrollPane();
140
scrollPaneSelector = null;
142
// Install new scroll pane selector
144
&& LafWidgetRepository.getRepository()
145
.getLafSupport().toInstallExtraElements(
147
scrollPaneSelector = new ScrollPaneSelector();
148
scrollPaneSelector.installOnScrollPane(jcomp);
153
this.jcomp.addPropertyChangeListener(this.propertyChangeListener);
159
* @see org.pushingpixels.lafwidget.LafWidgetAdapter#uninstallListeners()
162
public void uninstallListeners() {
163
this.jcomp.removeHierarchyListener(this.hierarchyListener);
164
this.hierarchyListener = null;
166
this.jcomp.removePropertyChangeListener(this.propertyChangeListener);
167
this.propertyChangeListener = null;