KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthSplitPaneDivider


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

7
8 package javax.swing.plaf.synth;
9
10 import java.awt.*;
11 import java.beans.*;
12 import javax.swing.*;
13 import javax.swing.plaf.basic.*;
14 import sun.swing.DefaultLookup;
15
16 /**
17  * Synth's SplitPaneDivider.
18  *
19  * @version 1.7, 12/19/03
20  * @author Scott Violet
21  */

22 class SynthSplitPaneDivider extends BasicSplitPaneDivider {
23     public SynthSplitPaneDivider(BasicSplitPaneUI ui) {
24         super(ui);
25     }
26
27     protected void setMouseOver(boolean mouseOver) {
28         if (isMouseOver() != mouseOver) {
29             repaint();
30         }
31         super.setMouseOver(mouseOver);
32     }
33
34     public void propertyChange(PropertyChangeEvent e) {
35         super.propertyChange(e);
36         if (e.getSource() == splitPane) {
37             if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) {
38                 if (leftButton instanceof SynthArrowButton JavaDoc) {
39                     ((SynthArrowButton JavaDoc)leftButton).setDirection(
40                                        mapDirection(true));
41                 }
42                 if (rightButton instanceof SynthArrowButton JavaDoc) {
43                     ((SynthArrowButton JavaDoc)rightButton).setDirection(
44                                        mapDirection(false));
45                 }
46             }
47         }
48     }
49
50     public void paint(Graphics g) {
51         Graphics g2 = g.create();
52
53         SynthContext JavaDoc context = ((SynthSplitPaneUI JavaDoc)splitPaneUI).getContext(
54                                splitPane, Region.SPLIT_PANE_DIVIDER);
55         Rectangle bounds = getBounds();
56         bounds.x = bounds.y = 0;
57         SynthLookAndFeel.updateSubregion(context, g, bounds);
58         context.getPainter().paintSplitPaneDividerBackground(context,
59                           g, 0, 0, bounds.width, bounds.height);
60
61         SynthPainter JavaDoc foreground = null;
62
63         context.getPainter().paintSplitPaneDividerForeground(context, g, 0, 0,
64                 getWidth(), getHeight(), splitPane.getOrientation());
65         context.dispose();
66
67         // super.paint(g2);
68
for (int counter = 0; counter < getComponentCount(); counter++) {
69             Component child = getComponent(counter);
70             Rectangle childBounds = child.getBounds();
71             Graphics childG = g.create(childBounds.x, childBounds.y,
72                                        childBounds.width, childBounds.height);
73             child.paint(childG);
74             childG.dispose();
75         }
76         g2.dispose();
77     }
78
79     private int mapDirection(boolean isLeft) {
80         if (isLeft) {
81             if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){
82                 return SwingConstants.WEST;
83             }
84             return SwingConstants.NORTH;
85         }
86         if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){
87             return SwingConstants.EAST;
88         }
89         return SwingConstants.SOUTH;
90     }
91
92
93     /**
94      * Creates and return an instance of JButton that can be used to
95      * collapse the left component in the split pane.
96      */

97     protected JButton createLeftOneTouchButton() {
98         SynthArrowButton JavaDoc b = new SynthArrowButton JavaDoc(SwingConstants.NORTH);
99         int oneTouchSize = lookupOneTouchSize();
100
101         b.setName("SplitPaneDivider.leftOneTouchButton");
102         b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
103         b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
104         b.setFocusPainted(false);
105         b.setBorderPainted(false);
106         b.setRequestFocusEnabled(false);
107         b.setDirection(mapDirection(true));
108         return b;
109     }
110
111     private int lookupOneTouchSize() {
112         return DefaultLookup.getInt(splitPaneUI.getSplitPane(), splitPaneUI,
113               "SplitPaneDivider.oneTouchButtonSize", ONE_TOUCH_SIZE);
114     }
115
116     /**
117      * Creates and return an instance of JButton that can be used to
118      * collapse the right component in the split pane.
119      */

120     protected JButton createRightOneTouchButton() {
121         SynthArrowButton JavaDoc b = new SynthArrowButton JavaDoc(SwingConstants.NORTH);
122         int oneTouchSize = lookupOneTouchSize();
123
124         b.setName("SplitPaneDivider.rightOneTouchButton");
125         b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
126         b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
127         b.setFocusPainted(false);
128         b.setBorderPainted(false);
129         b.setRequestFocusEnabled(false);
130         b.setDirection(mapDirection(false));
131         return b;
132     }
133 }
134
Popular Tags