private class OneTouchActionHandler implements ActionListener {
/**
* 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;
OneTouchActionHandler(boolean toMinimum) {
this.toMinimum = toMinimum;
}
public void actionPerformed(ActionEvent e) {
Insets insets = splitPaneUI.getSplitPane().getInsets();
int lastLoc = splitPaneUI.getSplitPane().getLastDividerLocation();
int currentLoc = splitPaneUI.getDividerLocation(splitPaneUI
.getSplitPane());
int newLoc;
// We use the location from the UI directly, as the location the
// JSplitPane itself maintains is not necessarly correct.
if (toMinimum) {
if (orientation == JSplitPane.VERTICAL_SPLIT) {
if (currentLoc >= (splitPaneUI.getSplitPane().getHeight()
- insets.bottom - getHeight())) {
int maxLoc = splitPaneUI.getSplitPane()
.getMaximumDividerLocation();
newLoc = Math.min(lastLoc, maxLoc);
splitPaneUI.setKeepHidden(false);
} else {
newLoc = insets.top;
// splitPaneUI.setKeepHidden(true);
}
} else {
if (currentLoc >= (splitPaneUI.getSplitPane().getWidth()
- insets.right - getWidth())) {
int maxLoc = splitPaneUI.getSplitPane()
.getMaximumDividerLocation();
newLoc = Math.min(lastLoc, maxLoc);
// splitPaneUI.setKeepHidden(false);
} else {
newLoc = insets.left;
// splitPaneUI.setKeepHidden(true);
}
}
} else {
if (orientation == JSplitPane.VERTICAL_SPLIT) {
if (currentLoc == insets.top) {
int maxLoc = splitPaneUI.getSplitPane()
.getMaximumDividerLocation();
newLoc = Math.min(lastLoc, maxLoc);
// splitPaneUI.setKeepHidden(false);
} else {
newLoc = splitPaneUI.getSplitPane().getHeight()
- getHeight() - insets.top;
// splitPaneUI.setKeepHidden(true);
}
} else {
if (currentLoc == insets.left) {
int maxLoc = splitPaneUI.getSplitPane()
.getMaximumDividerLocation();
newLoc = Math.min(lastLoc, maxLoc);
// splitPaneUI.setKeepHidden(false);
} else {
newLoc = splitPaneUI.getSplitPane().getWidth()
- getWidth() - insets.left;
// splitPaneUI.setKeepHidden(true);
}
}
}
if (currentLoc != newLoc) {
splitPaneUI.getSplitPane().setDividerLocation(newLoc);
// We do this in case the dividers notion of the location
// differs from the real location.
splitPaneUI.getSplitPane().setLastDividerLocation(currentLoc);
}
}
}