/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* Divider used by BasicSplitPaneUI. Subclassers may wish to override
* paint to do something more interesting.
* The border effect is drawn in BasicSplitPaneUI, so if you don't like
* that border, reset it there.
* To conditionally drag from certain areas subclass mousePressed and
* call super when you wish the dragging to begin.
* <p>
* <strong>Warning:</strong>
* 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 JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Scott Violet
*/
implements PropertyChangeListener
{
/**
* Width or height of the divider based on orientation
* BasicSplitPaneUI adds two to this.
*/
/**
* Handles mouse dragging message to do the actual dragging.
*/
/**
* UI this instance was created from.
*/
/**
* Size of the divider.
*/
/**
* Divider that is used for noncontinuous layout mode.
*/
/**
* JSplitPane the receiver is contained in.
*/
/**
* Handles mouse events from both this class, and the split pane.
* Mouse events are handled for the splitpane since you want to be able
* to drag when clicking on the border of the divider, which is not
* drawn by the divider.
*/
/**
* Orientation of the JSplitPane.
*/
protected int orientation;
/**
* Button for quickly toggling the left component.
*/
/**
* Button for quickly toggling the right component.
*/
/** Border. */
/**
* Is the mouse over the divider?
*/
private boolean mouseOver;
private int oneTouchSize;
private int oneTouchOffset;
/**
* If true the one touch buttons are centered on the divider.
*/
private boolean centerOneTouchButtons;
/**
* Creates an instance of BasicSplitPaneDivider. Registers this
* instance for mouse events and mouse dragged events.
*/
"SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE);
"SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET);
ui, "SplitPane.centerOneTouchButtons", true);
setLayout(new DividerLayout());
}
private void revalidateSplitPane() {
invalidate();
}
}
/**
* Sets the SplitPaneUI that is using the receiver.
*/
if (mouseHandler != null) {
mouseHandler = null;
}
}
splitPaneUI = newUI;
if (splitPane.isOneTouchExpandable()) {
}
}
}
else {
}
}
/**
* Returns the <code>SplitPaneUI</code> the receiver is currently
* in.
*/
return splitPaneUI;
}
/**
* Sets the size of the divider to <code>newSize</code>. That is
* the width if the splitpane is <code>HORIZONTAL_SPLIT</code>, or
* the height of <code>VERTICAL_SPLIT</code>.
*/
}
/**
* Returns the size of the divider, that is the width if the splitpane
* is HORIZONTAL_SPLIT, or the height of VERTICAL_SPLIT.
*/
public int getDividerSize() {
return dividerSize;
}
/**
* Sets the border of this component.
* @since 1.3
*/
}
/**
* Returns the border of this component or null if no border is
* currently set.
*
* @return the border object for this component
* @see #setBorder
* @since 1.3
*/
return border;
}
/**
* If a border has been set on this component, returns the
* border's insets, else calls super.getInsets.
*
* @return the value of the insets property.
* @see #setBorder
*/
return border.getBorderInsets(this);
}
return super.getInsets();
}
/**
* Sets whether or not the mouse is currently over the divider.
*
* @param mouseOver whether or not the mouse is currently over the divider
* @since 1.5
*/
}
/**
* Returns whether or not the mouse is currently over the divider
*
* @return whether or not the mouse is currently over the divider
* @since 1.5
*/
public boolean isMouseOver() {
return mouseOver;
}
/**
* Returns dividerSize x dividerSize
*/
// Ideally this would return the size from the layout manager,
// but that could result in the layed out size being different from
// the dividerSize, which may break developers as well as
// BasicSplitPaneUI.
}
}
/**
* Returns dividerSize x dividerSize
*/
return getPreferredSize();
}
/**
* Property change event, presumably from the JSplitPane, will message
* updateOrientation if necessary.
*/
}
else if (e.getPropertyName() == JSplitPane.
}
}
}
/**
* Paints the divider.
*/
super.paint(g);
// Paint the border.
}
}
/**
* Messaged when the oneTouchExpandable value of the JSplitPane the
* receiver is contained in changes. Will create the
* <code>leftButton</code> and <code>rightButton</code> if they
* are null. invalidates the receiver as well.
*/
protected void oneTouchExpandableChanged() {
"SplitPane.supportsOneTouchButtons", true)) {
// Look and feel doesn't want to support one touch buttons, bail.
return;
}
if (splitPane.isOneTouchExpandable() &&
leftButton == null &&
rightButton == null) {
/* Create the left button and add an action listener to
if (leftButton != null)
/* Create the right button and add an action listener to
if (rightButton != null)
(false));
}
}
}
/**
* Creates and return an instance of JButton that can be used to
* collapse the left component in the split pane.
*/
}
int[] xs = new int[3];
int[] ys = new int[3];
int blockSize;
// Fill the background first ...
g.setColor(this.getBackground());
this.getHeight());
// ... then draw the arrow.
// arrows of equal size
}
else {
}
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable() {
return false;
}
};
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
}
/**
* Creates and return an instance of JButton that can be used to
* collapse the right component in the split pane.
*/
}
int[] xs = new int[3];
int[] ys = new int[3];
int blockSize;
// Fill the background first ...
g.setColor(this.getBackground());
this.getHeight());
// ... then draw the arrow.
}
else {
}
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable() {
return false;
}
};
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
}
/**
* Message to prepare for dragging. This messages the BasicSplitPaneUI
* with startDragging.
*/
protected void prepareForDragging() {
}
/**
* Messages the BasicSplitPaneUI with dragDividerTo that this instance
* is contained in.
*/
}
/**
* Messages the BasicSplitPaneUI with finishDraggingTo that this instance
* is contained in.
*/
}
/**
* MouseHandler is responsible for converting mouse events
* (released, dragged...) into the appropriate DragController
* methods.
* <p>
*/
implements MouseMotionListener
{
/**
* Starts the dragging session by creating the appropriate instance
* of DragController.
*/
if ((e.getSource() == BasicSplitPaneDivider.this ||
if (hiddenDivider != newHiddenDivider) {
if (hiddenDivider != null) {
hiddenDivider.removeMouseListener(this);
}
if (hiddenDivider != null) {
hiddenDivider.addMouseListener(this);
}
}
dragger = new DragController(e);
}
else {
dragger = new VerticalDragController(e);
}
}
else {
dragger.continueDrag(e);
}
}
e.consume();
}
}
/**
* If dragger is not null it is messaged with completeDrag.
*/
}
else if (e.getSource() == BasicSplitPaneDivider.this) {
}
else if (e.getSource() == hiddenDivider) {
}
e.consume();
}
}
//
// MouseMotionListener
//
/**
* If dragger is not null it is messaged with continueDrag.
*/
}
else if (e.getSource() == BasicSplitPaneDivider.this) {
}
else if (e.getSource() == hiddenDivider) {
}
e.consume();
}
}
/**
* Resets the cursor based on the orientation.
*/
}
/**
* Invoked when the mouse enters a component.
*
* @param e MouseEvent describing the details of the enter event.
* @since 1.5
*/
if (e.getSource() == BasicSplitPaneDivider.this) {
setMouseOver(true);
}
}
/**
* Invoked when the mouse exits a component.
*
* @param e MouseEvent describing the details of the exit event.
* @since 1.5
*/
if (e.getSource() == BasicSplitPaneDivider.this) {
setMouseOver(false);
}
}
}
/**
* Handles the events during a dragging session for a
* HORIZONTAL_SPLIT oriented split pane. This continually
* messages <code>dragDividerTo</code> and then when done messages
* <code>finishDraggingTo</code>. When an instance is created it should be
* messaged with <code>isValid</code> to insure that dragging can happen
* (dragging won't be allowed if the two views can not be resized).
* <p>
* <strong>Warning:</strong>
* 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 JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
protected class DragController
{
/**
* Initial location of the divider.
*/
int initialX;
/**
* Maximum and minimum positions to drag to.
*/
/**
* Initial location the mouse down happened at.
*/
int offset;
initialX = getLocation().x;
if (e.getSource() == BasicSplitPaneDivider.this) {
}
else { // splitPane
}
// Don't allow dragging.
maxX = -1;
}
else {
}
}
else {
minX = 0;
}
}
else {
}
}
}
/**
* Returns true if the dragging session is valid.
*/
protected boolean isValid() {
return (maxX > 0);
}
/**
* Returns the new position to put the divider at based on
* the passed in MouseEvent.
*/
return newX;
}
/**
* Returns the x argument, since this is used for horizontal
* splits.
*/
protected int getNeededLocation(int x, int y) {
int newX;
return newX;
}
}
/**
* Messages dragDividerTo with the new location for the mouse
* event.
*/
}
protected void completeDrag(int x, int y) {
finishDraggingTo(getNeededLocation(x, y));
}
/**
* Messages finishDraggingTo with the new location for the mouse
* event.
*/
}
} // End of BasicSplitPaneDivider.DragController
/**
* Handles the events during a dragging session for a
* VERTICAL_SPLIT oriented split pane. This continually
* messages <code>dragDividerTo</code> and then when done messages
* <code>finishDraggingTo</code>. When an instance is created it should be
* messaged with <code>isValid</code> to insure that dragging can happen
* (dragging won't be allowed if the two views can not be resized).
*/
{
/* DragControllers ivars are now in terms of y, not x. */
super(e);
initialX = getLocation().y;
if (e.getSource() == BasicSplitPaneDivider.this) {
}
else {
}
// Don't allow dragging.
maxX = -1;
}
else {
}
}
else {
minX = 0;
}
}
else {
}
}
}
/**
* Returns the y argument, since this is used for vertical
* splits.
*/
protected int getNeededLocation(int x, int y) {
int newY;
return newY;
}
/**
* Returns the new position to put the divider at based on
* the passed in MouseEvent.
*/
return newY;
}
} // End of BasicSplitPaneDividier.VerticalDragController
/**
* Used to layout a <code>BasicSplitPaneDivider</code>.
* Layout for the divider
* <p>
*/
{
c == BasicSplitPaneDivider.this) {
if (splitPane.isOneTouchExpandable()) {
}
if (!centerOneTouchButtons) {
extraX = 0;
}
oneTouchSize * 2, y,
}
else {
}
if (!centerOneTouchButtons) {
extraY = 0;
}
blockSize * 2);
}
}
else {
}
}
}
// NOTE: This isn't really used, refer to
// BasicSplitPaneDivider.getPreferredSize for the reason.
// I leave it in hopes of having this used at some point.
}
}
int width = getDividerSize();
if (buttonMinSize != null) {
}
}
width = 1;
}
else {
if (buttonMinSize != null) {
}
}
height = 1;
}
}
return minimumLayoutSize(c);
}
} // End of class BasicSplitPaneDivider.DividerLayout
/**
* Listeners installed on the one touch expandable buttons.
*/
/** True indicates the resize should go the minimum (top or left)
* vs false which indicates the resize should go to the maximum.
*/
private boolean toMinimum;
}
int newLoc;
// We use the location from the UI directly, as the location the
// JSplitPane itself maintains is not necessarly correct.
if (toMinimum) {
splitPaneUI.setKeepHidden(false);
}
else {
splitPaneUI.setKeepHidden(true);
}
}
else {
splitPaneUI.setKeepHidden(false);
}
else {
splitPaneUI.setKeepHidden(true);
}
}
}
else {
splitPaneUI.setKeepHidden(false);
}
else {
splitPaneUI.setKeepHidden(true);
}
}
else {
splitPaneUI.setKeepHidden(false);
}
else {
splitPaneUI.setKeepHidden(true);
}
}
}
if (currentLoc != newLoc) {
// We do this in case the dividers notion of the location
// differs from the real location.
}
}
} // End of class BasicSplitPaneDivider.LeftActionListener
}