0N/A/*
2362N/A * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.java.swing.plaf.motif;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport javax.swing.JSplitPane;
0N/Aimport javax.swing.UIManager;
0N/Aimport javax.swing.plaf.basic.BasicSplitPaneUI;
0N/Aimport javax.swing.plaf.basic.BasicSplitPaneDivider;
0N/A
0N/A
0N/A/**
0N/A * Divider used for Motif split pane.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is appropriate
0N/A * for short term storage or RMI between applications running the same
0N/A * version of Swing. A future release of Swing will provide support for
0N/A * long term persistence.
0N/A *
0N/A * @author Jeff Dinkins
0N/A */
0N/Apublic class MotifSplitPaneDivider extends BasicSplitPaneDivider
0N/A{
0N/A /**
0N/A * Default cursor, supers is package private, so we have to have one
0N/A * too.
0N/A */
0N/A private static final Cursor defaultCursor =
0N/A Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
0N/A
0N/A
0N/A public static final int minimumThumbSize = 6;
0N/A public static final int defaultDividerSize = 18;
0N/A
0N/A protected static final int pad = 6;
0N/A
0N/A private int hThumbOffset = 30;
0N/A private int vThumbOffset = 40;
0N/A protected int hThumbWidth = 12;
0N/A protected int hThumbHeight = 18;
0N/A protected int vThumbWidth = 18;
0N/A protected int vThumbHeight = 12;
0N/A
0N/A protected Color highlightColor;
0N/A protected Color shadowColor;
0N/A protected Color focusedColor;
0N/A
0N/A /**
0N/A * Creates a new Motif SplitPaneDivider
0N/A */
0N/A public MotifSplitPaneDivider(BasicSplitPaneUI ui) {
0N/A super(ui);
0N/A highlightColor = UIManager.getColor("SplitPane.highlight");
0N/A shadowColor = UIManager.getColor("SplitPane.shadow");
0N/A focusedColor = UIManager.getColor("SplitPane.activeThumb");
0N/A setDividerSize(hThumbWidth + pad);
0N/A }
0N/A
0N/A /**
0N/A * overrides to hardcode the size of the divider
0N/A * PENDING(jeff) - rewrite JSplitPane so that this ins't needed
0N/A */
0N/A public void setDividerSize(int newSize) {
0N/A Insets insets = getInsets();
0N/A int borderSize = 0;
0N/A if (getBasicSplitPaneUI().getOrientation() ==
0N/A JSplitPane.HORIZONTAL_SPLIT) {
0N/A if (insets != null) {
0N/A borderSize = insets.left + insets.right;
0N/A }
0N/A }
0N/A else if (insets != null) {
0N/A borderSize = insets.top + insets.bottom;
0N/A }
0N/A if (newSize < pad + minimumThumbSize + borderSize) {
0N/A setDividerSize(pad + minimumThumbSize + borderSize);
0N/A } else {
0N/A vThumbHeight = hThumbWidth = newSize - pad - borderSize;
0N/A super.setDividerSize(newSize);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Paints the divider.
0N/A */
0N/A // PENDING(jeff) - the thumb's location and size is currently hard coded.
0N/A // It should be dynamic.
0N/A public void paint(Graphics g) {
0N/A Color bgColor = getBackground();
0N/A Dimension size = getSize();
0N/A
0N/A // fill
0N/A g.setColor(getBackground());
0N/A g.fillRect(0, 0, size.width, size.height);
0N/A
0N/A if(getBasicSplitPaneUI().getOrientation() ==
0N/A JSplitPane.HORIZONTAL_SPLIT) {
0N/A int center = size.width/2;
0N/A int x = center - hThumbWidth/2;
0N/A int y = hThumbOffset;
0N/A
0N/A // split line
0N/A g.setColor(shadowColor);
0N/A g.drawLine(center-1, 0, center-1, size.height);
0N/A
0N/A g.setColor(highlightColor);
0N/A g.drawLine(center, 0, center, size.height);
0N/A
0N/A // draw thumb
0N/A g.setColor((splitPane.hasFocus()) ? focusedColor :
0N/A getBackground());
0N/A g.fillRect(x+1, y+1, hThumbWidth-2, hThumbHeight-1);
0N/A
0N/A g.setColor(highlightColor);
0N/A g.drawLine(x, y, x+hThumbWidth-1, y); // top
0N/A g.drawLine(x, y+1, x, y+hThumbHeight-1); // left
0N/A
0N/A g.setColor(shadowColor);
0N/A g.drawLine(x+1, y+hThumbHeight-1,
0N/A x+hThumbWidth-1, y+hThumbHeight-1); // bottom
0N/A g.drawLine(x+hThumbWidth-1, y+1,
0N/A x+hThumbWidth-1, y+hThumbHeight-2); // right
0N/A
0N/A } else {
0N/A int center = size.height/2;
0N/A int x = size.width - vThumbOffset;
0N/A int y = size.height/2 - vThumbHeight/2;
0N/A
0N/A // split line
0N/A g.setColor(shadowColor);
0N/A g.drawLine(0, center-1, size.width, center-1);
0N/A
0N/A g.setColor(highlightColor);
0N/A g.drawLine(0, center, size.width, center);
0N/A
0N/A // draw thumb
0N/A g.setColor((splitPane.hasFocus()) ? focusedColor :
0N/A getBackground());
0N/A g.fillRect(x+1, y+1, vThumbWidth-1, vThumbHeight-1);
0N/A
0N/A g.setColor(highlightColor);
0N/A g.drawLine(x, y, x+vThumbWidth, y); // top
0N/A g.drawLine(x, y+1, x, y+vThumbHeight); // left
0N/A
0N/A g.setColor(shadowColor);
0N/A g.drawLine(x+1, y+vThumbHeight,
0N/A x+vThumbWidth, y+vThumbHeight); // bottom
0N/A g.drawLine(x+vThumbWidth, y+1,
0N/A x+vThumbWidth, y+vThumbHeight-1); // right
0N/A }
0N/A super.paint(g);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * The minimums size is the same as the preferredSize
0N/A */
0N/A public Dimension getMinimumSize() {
0N/A return getPreferredSize();
0N/A }
0N/A
0N/A /**
0N/A * Sets the SplitPaneUI that is using the receiver. This is completely
0N/A * overriden from super to create a different MouseHandler.
0N/A */
0N/A public void setBasicSplitPaneUI(BasicSplitPaneUI newUI) {
0N/A if (splitPane != null) {
0N/A splitPane.removePropertyChangeListener(this);
0N/A if (mouseHandler != null) {
0N/A splitPane.removeMouseListener(mouseHandler);
0N/A splitPane.removeMouseMotionListener(mouseHandler);
0N/A removeMouseListener(mouseHandler);
0N/A removeMouseMotionListener(mouseHandler);
0N/A mouseHandler = null;
0N/A }
0N/A }
0N/A splitPaneUI = newUI;
0N/A if (newUI != null) {
0N/A splitPane = newUI.getSplitPane();
0N/A if (splitPane != null) {
0N/A if (mouseHandler == null) mouseHandler=new MotifMouseHandler();
0N/A splitPane.addMouseListener(mouseHandler);
0N/A splitPane.addMouseMotionListener(mouseHandler);
0N/A addMouseListener(mouseHandler);
0N/A addMouseMotionListener(mouseHandler);
0N/A splitPane.addPropertyChangeListener(this);
0N/A if (splitPane.isOneTouchExpandable()) {
0N/A oneTouchExpandableChanged();
0N/A }
0N/A }
0N/A }
0N/A else {
0N/A splitPane = null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the point at <code>x</code>, <code>y</code>
0N/A * is inside the thumb.
0N/A */
0N/A private boolean isInThumb(int x, int y) {
0N/A Dimension size = getSize();
0N/A int thumbX;
0N/A int thumbY;
0N/A int thumbWidth;
0N/A int thumbHeight;
0N/A
0N/A if (getBasicSplitPaneUI().getOrientation() ==
0N/A JSplitPane.HORIZONTAL_SPLIT) {
0N/A int center = size.width/2;
0N/A thumbX = center - hThumbWidth/2;
0N/A thumbY = hThumbOffset;
0N/A thumbWidth = hThumbWidth;
0N/A thumbHeight = hThumbHeight;
0N/A }
0N/A else {
0N/A int center = size.height/2;
0N/A thumbX = size.width - vThumbOffset;
0N/A thumbY = size.height/2 - vThumbHeight/2;
0N/A thumbWidth = vThumbWidth;
0N/A thumbHeight = vThumbHeight;
0N/A }
0N/A return (x >= thumbX && x < (thumbX + thumbWidth) &&
0N/A y >= thumbY && y < (thumbY + thumbHeight));
0N/A }
0N/A
0N/A //
0N/A // Two methods are exposed so that MotifMouseHandler can see the
0N/A // superclass protected ivars
0N/A //
0N/A
0N/A private DragController getDragger() {
0N/A return dragger;
0N/A }
0N/A
0N/A private JSplitPane getSplitPane() {
0N/A return splitPane;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * MouseHandler is subclassed to only pass off to super if the mouse
0N/A * is in the thumb. Motif only allows dragging when the thumb is clicked
0N/A * in.
0N/A */
0N/A private class MotifMouseHandler extends MouseHandler {
0N/A public void mousePressed(MouseEvent e) {
0N/A // Constrain the mouse pressed to the thumb.
0N/A if (e.getSource() == MotifSplitPaneDivider.this &&
0N/A getDragger() == null && getSplitPane().isEnabled() &&
0N/A isInThumb(e.getX(), e.getY())) {
0N/A super.mousePressed(e);
0N/A }
0N/A }
0N/A
0N/A public void mouseMoved(MouseEvent e) {
0N/A if (getDragger() != null) {
0N/A return;
0N/A }
0N/A if (!isInThumb(e.getX(), e.getY())) {
0N/A if (getCursor() != defaultCursor) {
0N/A setCursor(defaultCursor);
0N/A }
0N/A return;
0N/A }
0N/A super.mouseMoved(e);
0N/A }
0N/A }
0N/A}