001 /*
002 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.swing.plaf.synth;
027
028 import java.awt.*;
029 import java.beans.*;
030 import javax.swing.*;
031 import javax.swing.plaf.basic.*;
032 import sun.swing.DefaultLookup;
033
034 /**
035 * Synth's SplitPaneDivider.
036 *
037 * @version 1.15, 05/05/07
038 * @author Scott Violet
039 */
040 class SynthSplitPaneDivider extends BasicSplitPaneDivider {
041 public SynthSplitPaneDivider(BasicSplitPaneUI ui) {
042 super (ui);
043 }
044
045 protected void setMouseOver(boolean mouseOver) {
046 if (isMouseOver() != mouseOver) {
047 repaint();
048 }
049 super .setMouseOver(mouseOver);
050 }
051
052 public void propertyChange(PropertyChangeEvent e) {
053 super .propertyChange(e);
054 if (e.getSource() == splitPane) {
055 if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) {
056 if (leftButton instanceof SynthArrowButton) {
057 ((SynthArrowButton) leftButton)
058 .setDirection(mapDirection(true));
059 }
060 if (rightButton instanceof SynthArrowButton) {
061 ((SynthArrowButton) rightButton)
062 .setDirection(mapDirection(false));
063 }
064 }
065 }
066 }
067
068 public void paint(Graphics g) {
069 Graphics g2 = g.create();
070
071 SynthContext context = ((SynthSplitPaneUI) splitPaneUI)
072 .getContext(splitPane, Region.SPLIT_PANE_DIVIDER);
073 Rectangle bounds = getBounds();
074 bounds.x = bounds.y = 0;
075 SynthLookAndFeel.updateSubregion(context, g, bounds);
076 context.getPainter().paintSplitPaneDividerBackground(context,
077 g, 0, 0, bounds.width, bounds.height,
078 splitPane.getOrientation());
079
080 SynthPainter foreground = null;
081
082 context.getPainter().paintSplitPaneDividerForeground(context,
083 g, 0, 0, getWidth(), getHeight(),
084 splitPane.getOrientation());
085 context.dispose();
086
087 // super.paint(g2);
088 for (int counter = 0; counter < getComponentCount(); counter++) {
089 Component child = getComponent(counter);
090 Rectangle childBounds = child.getBounds();
091 Graphics childG = g.create(childBounds.x, childBounds.y,
092 childBounds.width, childBounds.height);
093 child.paint(childG);
094 childG.dispose();
095 }
096 g2.dispose();
097 }
098
099 private int mapDirection(boolean isLeft) {
100 if (isLeft) {
101 if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
102 return SwingConstants.WEST;
103 }
104 return SwingConstants.NORTH;
105 }
106 if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
107 return SwingConstants.EAST;
108 }
109 return SwingConstants.SOUTH;
110 }
111
112 /**
113 * Creates and return an instance of JButton that can be used to
114 * collapse the left component in the split pane.
115 */
116 protected JButton createLeftOneTouchButton() {
117 SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH);
118 int oneTouchSize = lookupOneTouchSize();
119
120 b.setName("SplitPaneDivider.leftOneTouchButton");
121 b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
122 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
123 b.setFocusPainted(false);
124 b.setBorderPainted(false);
125 b.setRequestFocusEnabled(false);
126 b.setDirection(mapDirection(true));
127 return b;
128 }
129
130 private int lookupOneTouchSize() {
131 return DefaultLookup.getInt(splitPaneUI.getSplitPane(),
132 splitPaneUI, "SplitPaneDivider.oneTouchButtonSize",
133 ONE_TOUCH_SIZE);
134 }
135
136 /**
137 * Creates and return an instance of JButton that can be used to
138 * collapse the right component in the split pane.
139 */
140 protected JButton createRightOneTouchButton() {
141 SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH);
142 int oneTouchSize = lookupOneTouchSize();
143
144 b.setName("SplitPaneDivider.rightOneTouchButton");
145 b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
146 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
147 b.setFocusPainted(false);
148 b.setBorderPainted(false);
149 b.setRequestFocusEnabled(false);
150 b.setDirection(mapDirection(false));
151 return b;
152 }
153 }
|