KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifScrollPaneUI


1 /*
2  * @(#)MotifScrollPaneUI.java 1.19 04/03/03
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.motif;
9
10 import javax.swing.*;
11 import javax.swing.border.*;
12 import javax.swing.plaf.*;
13 import javax.swing.plaf.basic.BasicScrollPaneUI JavaDoc;
14
15 import java.beans.PropertyChangeEvent JavaDoc;
16 import java.beans.PropertyChangeListener JavaDoc;
17
18 /**
19  * A CDE/Motif L&F implementation of ScrollPaneUI.
20  * <p>
21  * <strong>Warning:</strong>
22  * Serialized objects of this class will not be compatible with
23  * future Swing releases. The current serialization support is appropriate
24  * for short term storage or RMI between applications running the same
25  * version of Swing. A future release of Swing will provide support for
26  * long term persistence.
27  *
28  * @version 1.10 08/28/98
29  * @author Hans Muller
30  */

31 public class MotifScrollPaneUI extends BasicScrollPaneUI JavaDoc
32 {
33     private final static Border vsbMarginBorderR = new EmptyBorder(0, 4, 0, 0);
34     private final static Border vsbMarginBorderL = new EmptyBorder(0, 0, 0, 4);
35     private final static Border hsbMarginBorder = new EmptyBorder(4, 0, 0, 0);
36
37     private CompoundBorder vsbBorder;
38     private CompoundBorder hsbBorder;
39
40     private PropertyChangeListener JavaDoc propertyChangeHandler;
41
42     protected void installListeners(JScrollPane scrollPane) {
43         super.installListeners(scrollPane);
44     propertyChangeHandler = createPropertyChangeHandler();
45     scrollPane.addPropertyChangeListener(propertyChangeHandler);
46     }
47
48     protected void uninstallListeners(JScrollPane scrollPane) {
49         super.uninstallListeners(scrollPane);
50     scrollPane.removePropertyChangeListener(propertyChangeHandler);
51     }
52
53     private PropertyChangeListener JavaDoc createPropertyChangeHandler() {
54         return new PropertyChangeListener JavaDoc() {
55         public void propertyChange(PropertyChangeEvent JavaDoc e) {
56           String JavaDoc propertyName = e.getPropertyName();
57
58           if (propertyName.equals("componentOrientation")) {
59             JScrollPane pane = (JScrollPane)e.getSource();
60             JScrollBar vsb = pane.getVerticalScrollBar();
61             if (vsb != null && vsbBorder != null &&
62                 vsb.getBorder() == vsbBorder) {
63                 // The Border on the verticall scrollbar matches
64
// what we installed, reset it.
65
if (MotifGraphicsUtils.isLeftToRight(pane)) {
66                 vsbBorder = new CompoundBorder(vsbMarginBorderR,
67                         vsbBorder.getInsideBorder());
68                 } else {
69                 vsbBorder = new CompoundBorder(vsbMarginBorderL,
70                         vsbBorder.getInsideBorder());
71                 }
72                 vsb.setBorder(vsbBorder);
73             }
74                   }
75     }};
76     }
77
78     protected void installDefaults(JScrollPane scrollpane) {
79     super.installDefaults(scrollpane);
80
81     JScrollBar vsb = scrollpane.getVerticalScrollBar();
82     if (vsb != null) {
83         if (MotifGraphicsUtils.isLeftToRight(scrollpane)) {
84             vsbBorder = new CompoundBorder(vsbMarginBorderR,
85                            vsb.getBorder());
86         }
87         else {
88             vsbBorder = new CompoundBorder(vsbMarginBorderL,
89                            vsb.getBorder());
90         }
91         vsb.setBorder(vsbBorder);
92     }
93
94     JScrollBar hsb = scrollpane.getHorizontalScrollBar();
95     if (hsb != null) {
96         hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
97         hsb.setBorder(hsbBorder);
98     }
99     }
100
101
102     protected void uninstallDefaults(JScrollPane c) {
103     super.uninstallDefaults(c);
104
105     JScrollBar vsb = scrollpane.getVerticalScrollBar();
106     if (vsb != null) {
107         if (vsb.getBorder() == vsbBorder) {
108         vsb.setBorder(null);
109         }
110         vsbBorder = null;
111     }
112
113     JScrollBar hsb = scrollpane.getHorizontalScrollBar();
114     if (hsb != null) {
115         if (hsb.getBorder() == hsbBorder) {
116         hsb.setBorder(null);
117         }
118         hsbBorder = null;
119     }
120     }
121
122
123     public static ComponentUI createUI(JComponent x) {
124     return new MotifScrollPaneUI();
125     }
126 }
127
128
Popular Tags