/* * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.basic.*; /** * Metal's split pane divider *
* Warning:
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeansTM
* has been added to the java.beans
package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Steve Wilson
* @author Ralph kar
*/
class MetalSplitPaneDivider extends BasicSplitPaneDivider
{
private MetalBumps bumps = new MetalBumps(10, 10,
MetalLookAndFeel.getControlHighlight(),
MetalLookAndFeel.getControlDarkShadow(),
MetalLookAndFeel.getControl() );
private MetalBumps focusBumps = new MetalBumps(10, 10,
MetalLookAndFeel.getPrimaryControlHighlight(),
MetalLookAndFeel.getPrimaryControlDarkShadow(),
UIManager.getColor("SplitPane.dividerFocusColor"));
private int inset = 2;
private Color controlColor = MetalLookAndFeel.getControl();
private Color primaryControlColor = UIManager.getColor(
"SplitPane.dividerFocusColor");
public MetalSplitPaneDivider(BasicSplitPaneUI ui) {
super(ui);
}
public void paint(Graphics g) {
MetalBumps usedBumps;
if (splitPane.hasFocus()) {
usedBumps = focusBumps;
g.setColor(primaryControlColor);
}
else {
usedBumps = bumps;
g.setColor(controlColor);
}
Rectangle clip = g.getClipBounds();
Insets insets = getInsets();
g.fillRect(clip.x, clip.y, clip.width, clip.height);
Dimension size = getSize();
size.width -= inset * 2;
size.height -= inset * 2;
int drawX = inset;
int drawY = inset;
if (insets != null) {
size.width -= (insets.left + insets.right);
size.height -= (insets.top + insets.bottom);
drawX += insets.left;
drawY += insets.top;
}
usedBumps.setBumpArea(size);
usedBumps.paintIcon(this, g, drawX, drawY);
super.paint(g);
}
/**
* Creates and return an instance of JButton that can be used to
* collapse the left component in the metal split pane.
*/
protected JButton createLeftOneTouchButton() {
JButton b = new JButton() {
// Sprite buffer for the arrow image of the left button
int[][] buffer = {{0, 0, 0, 2, 2, 0, 0, 0, 0},
{0, 0, 2, 1, 1, 1, 0, 0, 0},
{0, 2, 1, 1, 1, 1, 1, 0, 0},
{2, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 3, 3, 3, 3, 3, 3, 3, 3}};
public void setBorder(Border b) {
}
public void paint(Graphics g) {
JSplitPane splitPane = getSplitPaneFromSuper();
if(splitPane != null) {
int oneTouchSize = getOneTouchSizeFromSuper();
int orientation = getOrientationFromSuper();
int blockSize = Math.min(getDividerSize(),
oneTouchSize);
// Initialize the color array
Color[] colors = {
this.getBackground(),
MetalLookAndFeel.getPrimaryControlDarkShadow(),
MetalLookAndFeel.getPrimaryControlInfo(),
MetalLookAndFeel.getPrimaryControlHighlight()};
// Fill the background first ...
g.setColor(this.getBackground());
if (isOpaque()) {
g.fillRect(0, 0, this.getWidth(),
this.getHeight());
}
// ... then draw the arrow.
if (getModel().isPressed()) {
// Adjust color mapping for pressed button state
colors[1] = colors[2];
}
if(orientation == JSplitPane.VERTICAL_SPLIT) {
// Draw the image for a vertical split
for (int i=1; i<=buffer[0].length; i++) {
for (int j=1; j