|
Java example source code file (AquaSplitPaneDividerUI.java)
The AquaSplitPaneDividerUI.java Java example source code
/*
* Copyright (c) 2011, 2012, 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 com.apple.laf;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import apple.laf.*;
import apple.laf.JRSUIConstants.State;
import com.apple.laf.AquaUtils.LazyKeyedSingleton;
import com.apple.laf.AquaUtils.RecyclableSingleton;
import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
public class AquaSplitPaneDividerUI extends BasicSplitPaneDivider {
final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIStateFactory.getSplitPaneDivider());
public AquaSplitPaneDividerUI(final AquaSplitPaneUI ui) {
super(ui);
setLayout(new AquaSplitPaneDividerUI.DividerLayout());
}
/**
* Property change event, presumably from the JSplitPane, will message
* updateOrientation if necessary.
*/
public void propertyChange(final PropertyChangeEvent e) {
if (e.getSource() == splitPane) {
final String propName = e.getPropertyName();
if ("enabled".equals(propName)) {
final boolean enabled = splitPane.isEnabled();
if (leftButton != null) leftButton.setEnabled(enabled);
if (rightButton != null) rightButton.setEnabled(enabled);
} else if (JSplitPane.ORIENTATION_PROPERTY.equals(propName)) {
// need to regenerate the buttons, since we bake the orientation into them
if (rightButton != null) {
remove(rightButton); rightButton = null;
}
if (leftButton != null) {
remove(leftButton); leftButton = null;
}
oneTouchExpandableChanged();
}
}
super.propertyChange(e);
}
public int getMaxDividerSize() {
return 10;
}
/**
* Paints the divider.
*/
public void paint(final Graphics g) {
final Dimension size = getSize();
int x = 0;
int y = 0;
final boolean horizontal = splitPane.getOrientation() == SwingConstants.HORIZONTAL;
//System.err.println("Size = " + size + " orientation horiz = " + horizontal);
// size determines orientation
final int maxSize = getMaxDividerSize();
boolean doPaint = true;
if (horizontal) {
if (size.height > maxSize) {
final int diff = size.height - maxSize;
y = diff / 2;
size.height = maxSize;
}
if (size.height < 4) doPaint = false;
} else {
if (size.width > maxSize) {
final int diff = size.width - maxSize;
x = diff / 2;
size.width = maxSize;
}
if (size.width < 4) doPaint = false;
}
if (doPaint) {
painter.state.set(getState());
painter.paint(g, splitPane, x, y, size.width, size.height);
}
super.paint(g); // Ends up at Container.paint, which paints our JButton children
}
protected State getState() {
return splitPane.isEnabled() ? State.ACTIVE : State.DISABLED;
}
protected JButton createLeftOneTouchButton() {
return createButtonForDirection(getDirection(true));
}
protected JButton createRightOneTouchButton() {
return createButtonForDirection(getDirection(false));
}
static final LazyKeyedSingleton<Integer, Image> directionArrows = new LazyKeyedSingleton
Other Java examples (source code examples)Here is a short list of links related to this Java AquaSplitPaneDividerUI.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.