下面列出了javax.swing.JSplitPane#getOrientation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* TODO: to remove? doesn't seems to be used anywhere.
*/
protected void updateSplitLocation(JSplitPane split, int foo) {
Component left = split.getLeftComponent();
Component right = split.getRightComponent();
if(left == null) {
split.setDividerLocation(0);
return;
}
if(right == null) {
split.setDividerLocation(1);
return;
}
Dimension leftPS = left.getPreferredSize();
Dimension rightPS = right.getPreferredSize();
double location =
split.getOrientation() == JSplitPane.HORIZONTAL_SPLIT
? (double)leftPS.width / (leftPS.width + rightPS.width)
: (double)leftPS.height / (leftPS.height + rightPS.height);
split.setDividerLocation(location);
}
@Override
public int getMinimumDividerLocation(JSplitPane pane) {
int leftMin = super.getMinimumDividerLocation(pane);
Component second = pane.getRightComponent();
if ((second != null) && second.isVisible()) {
Dimension paneSize = splitPane.getSize();
Dimension maxSize = second.getMaximumSize();
Insets insets = pane.getInsets();
if (pane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
leftMin = Math.max(leftMin, paneSize.width - insets.right - maxSize.width);
} else {
leftMin = Math.max(leftMin, paneSize.height - insets.bottom - maxSize.height);
}
/*
* To avoid inconsistency with the maximum location, it would seem
* reasonable to do:
*
* leftMin = Math.min(leftMin, getMaximumDividerLocation(pane));
*
* however, the parent already calls getMinimumDividerLocation()
* in getMaximumDividerLocation(), so that would be a good way
* to get a stack overflow.
*/
}
return leftMin;
}
private Component getFirstComponent(JSplitPane splitPane) {
if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
return splitPane.getLeftComponent();
} else {
return splitPane.getTopComponent();
}
}
private Component getSecondComponent(JSplitPane splitPane) {
if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
return splitPane.getRightComponent();
} else {
return splitPane.getBottomComponent();
}
}
/**
* Sets the layout orientation of the contained result pane.
*
* @param orientation the orientation (see {@link JSplitPane#VERTICAL_SPLIT}
* and {@link JSplitPane#HORIZONTAL_SPLIT}) to set.
*/
public void setOrientation(int orientation) {
for(JSplitPane view: viewMap.values()){
if (view.getOrientation() != orientation) {
view.setOrientation(orientation);
}
}
}
private Component getFirstComponent(JSplitPane splitPane) {
if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
return splitPane.getLeftComponent();
} else {
return splitPane.getTopComponent();
}
}
public void finishedPaintingChildren(JSplitPane jc, Graphics g) {
if (jc == splitPane && getLastDragLocation() != -1 && !isContinuousLayout() && !draggingHW) {
if (jc.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
paintDragDivider(g, getLastDragLocation(), 0, dividerSize - 1, splitPane.getHeight() - 1);
} else {
paintDragDivider(g, 0, getLastDragLocation(), splitPane.getWidth() - 1, dividerSize - 1);
}
}
}
private void changeLayout() {
int selIndex = getTabIndex();
if(selIndex < 0){
return;
}
TabData selTabData = tabDataModel.getTab(selIndex);
JSplitPane splitPane = (JSplitPane)selTabData.getComponent();
if (splitPane.getOrientation() == JSplitPane.VERTICAL_SPLIT) {
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setDividerLocation(0.45);
} else {
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitPane.setDividerLocation(0.45);
}
}
public Insets getBorderInsets(Component c)
{
Insets insets = new Insets(0, 0, 0, 0);
if (c instanceof BasicSplitPaneDivider)
{
BasicSplitPaneUI bspui = ((BasicSplitPaneDivider) c)
.getBasicSplitPaneUI();
if (bspui != null)
{
JSplitPane splitPane = bspui.getSplitPane();
if (splitPane != null)
{
if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
{
insets.top = insets.bottom = 0;
insets.left = insets.right = 1;
return insets;
}
// VERTICAL_SPLIT
insets.top = insets.bottom = 1;
insets.left = insets.right = 0;
return insets;
}
}
}
insets.top = insets.bottom = insets.left = insets.right = 1;
return insets;
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
/** This method calculates layout constraints for a component dragged
* over a container (or just for mouse cursor being moved over container,
* without any component).
* @param container instance of a real container over/in which the
* component is dragged
* @param containerDelegate effective container delegate of the container
* @param component the real component being dragged, not needed here
* @param index position (index) of the component in its container;
* not needed here
* @param posInCont position of mouse in the container
* @param posInComp position of mouse in the dragged component; not needed
* @return new LayoutConstraints object corresponding to the position of
* the component in the container
*/
@Override
public LayoutConstraints getNewConstraints(Container container,
Container containerDelegate,
Component component,
int index,
Point posInCont,
Point posInComp)
{
if (!(container instanceof JSplitPane))
return null;
JSplitPane splitPane = (JSplitPane) container;
Dimension sz = splitPane.getSize();
int orientation = splitPane.getOrientation();
JButton left = (JButton) splitPane.getClientProperty(LEFT_TOP_BUTTON);
JButton right = (JButton) splitPane.getClientProperty(RIGHT_BOTTOM_BUTTON);
if ( (left == null && right == null) ||
(left != null && right != null) )
{
String freePosition;
if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
if (posInCont.x <= sz.width / 2)
freePosition = JSplitPane.LEFT;
else
freePosition = JSplitPane.RIGHT;
}
else {
if (posInCont.y <= sz.height / 2)
freePosition = JSplitPane.TOP;
else
freePosition = JSplitPane.BOTTOM;
}
assistantParams = freePosition;
return new SplitConstraints(freePosition);
}
assistantParams = findFreePosition();
return new SplitConstraints(assistantParams);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}
protected void validate(JSplitPane before, JSplitPane after) {
int orientation = after.getOrientation();
if (orientation != before.getOrientation())
throw new Error("Invalid orientation: " + orientation);
}