?? basicsplitpaneui.java
字號:
containerSize.height - (insets.top + insets.bottom)); } else { c.setBounds(insets.left, location, containerSize.width - (insets.left + insets.right), size); } } else { if (axis == 0) { c.setBounds(location, 0, size, containerSize.height); } else { c.setBounds(0, location, containerSize.width, size); } } } /** * If the axis == 0, the width is returned, otherwise the height. */ int getSizeForPrimaryAxis(Dimension size) { if (axis == 0) { return size.width; } return size.height; } /** * If the axis == 0, the width is returned, otherwise the height. */ int getSizeForSecondaryAxis(Dimension size) { if (axis == 0) { return size.height; } return size.width; } /** * Returns a particular value of the inset identified by the * axis and <code>isTop</code><p> * axis isTop * 0 true - left * 0 false - right * 1 true - top * 1 false - bottom */ int getSizeForPrimaryAxis(Insets insets, boolean isTop) { if (axis == 0) { if (isTop) { return insets.left; } return insets.right; } if (isTop) { return insets.top; } return insets.bottom; } /** * Returns a particular value of the inset identified by the * axis and <code>isTop</code><p> * axis isTop * 0 true - left * 0 false - right * 1 true - top * 1 false - bottom */ int getSizeForSecondaryAxis(Insets insets, boolean isTop) { if (axis == 0) { if (isTop) { return insets.top; } return insets.bottom; } if (isTop) { return insets.left; } return insets.right; } /** * Determines the components. This should be called whenever * a new instance of this is installed into an existing * SplitPane. */ protected void updateComponents() { Component comp; comp = splitPane.getLeftComponent(); if(components[0] != comp) { components[0] = comp; if(comp == null) { sizes[0] = 0; } else { sizes[0] = -1; } } comp = splitPane.getRightComponent(); if(components[1] != comp) { components[1] = comp; if(comp == null) { sizes[1] = 0; } else { sizes[1] = -1; } } /* Find the divider. */ Component[] children = splitPane.getComponents(); Component oldDivider = components[2]; components[2] = null; for(int counter = children.length - 1; counter >= 0; counter--) { if(children[counter] != components[0] && children[counter] != components[1] && children[counter] != nonContinuousLayoutDivider) { if(oldDivider != children[counter]) { components[2] = children[counter]; } else { components[2] = oldDivider; } break; } } if(components[2] == null) { sizes[2] = 0; } else { sizes[2] = getSizeForPrimaryAxis(components[2].getPreferredSize()); } } /** * Resets the size of the first component to <code>leftSize</code>, * and the right component to the remainder of the space. */ void setDividerLocation(int leftSize, int availableSize) { boolean lValid = (components[0] != null && components[0].isVisible()); boolean rValid = (components[1] != null && components[1].isVisible()); boolean dValid = (components[2] != null && components[2].isVisible()); int max = availableSize; if (dValid) { max -= sizes[2]; } leftSize = Math.max(0, Math.min(leftSize, max)); if (lValid) { if (rValid) { sizes[0] = leftSize; sizes[1] = max - leftSize; } else { sizes[0] = max; sizes[1] = 0; } } else if (rValid) { sizes[1] = max; sizes[0] = 0; } } /** * Returns an array of the minimum sizes of the components. */ int[] getPreferredSizes() { int[] retValue = new int[3]; for (int counter = 0; counter < 3; counter++) { if (components[counter] != null && components[counter].isVisible()) { retValue[counter] = getPreferredSizeOfComponent (components[counter]); } else { retValue[counter] = -1; } } return retValue; } /** * Returns an array of the minimum sizes of the components. */ int[] getMinimumSizes() { int[] retValue = new int[3]; for (int counter = 0; counter < 2; counter++) { if (components[counter] != null && components[counter].isVisible()) { retValue[counter] = getMinimumSizeOfComponent (components[counter]); } else { retValue[counter] = -1; } } retValue[2] = (components[2] != null) ? getMinimumSizeOfComponent(components[2]) : -1; return retValue; } /** * Resets the components to their preferred sizes. */ void resetToPreferredSizes(int availableSize) { // Set the sizes to the preferred sizes (if fits), otherwise // set to min sizes and distribute any extra space. int[] testSizes = getPreferredSizes(); int totalSize = 0; for (int counter = 0; counter < 3; counter++) { if (testSizes[counter] != -1) { totalSize += testSizes[counter]; } } if (totalSize > availableSize) { testSizes = getMinimumSizes(); totalSize = 0; for (int counter = 0; counter < 3; counter++) { if (testSizes[counter] != -1) { totalSize += testSizes[counter]; } } } setSizes(testSizes); distributeSpace(availableSize - totalSize, false); } /** * Distributes <code>space</code> between the two components * (divider won't get any extra space) based on the weighting. This * attempts to honor the min size of the components. * * @param keepHidden if true and one of the components is 0x0 * it gets none of the extra space */ void distributeSpace(int space, boolean keepHidden) { boolean lValid = (components[0] != null && components[0].isVisible()); boolean rValid = (components[1] != null && components[1].isVisible()); if (keepHidden) { if (lValid && getSizeForPrimaryAxis( components[0].getSize()) == 0) { lValid = false; if (rValid && getSizeForPrimaryAxis( components[1].getSize()) == 0) { // Both aren't valid, force them both to be valid lValid = true; } } else if (rValid && getSizeForPrimaryAxis( components[1].getSize()) == 0) { rValid = false; } } if (lValid && rValid) { double weight = splitPane.getResizeWeight(); int lExtra = (int)(weight * (double)space); int rExtra = (space - lExtra); sizes[0] += lExtra; sizes[1] += rExtra; int lMin = getMinimumSizeOfComponent(components[0]); int rMin = getMinimumSizeOfComponent(components[1]); boolean lMinValid = (sizes[0] >= lMin); boolean rMinValid = (sizes[1] >= rMin); if (!lMinValid && !rMinValid) { if (sizes[0] < 0) { sizes[1] += sizes[0]; sizes[0] = 0; } else if (sizes[1] < 0) { sizes[0] += sizes[1]; sizes[1] = 0; } } else if (!lMinValid) { if (sizes[1] - (lMin - sizes[0]) < rMin) { // both below min, just make sure > 0 if (sizes[0] < 0) { sizes[1] += sizes[0]; sizes[0] = 0; } } else { sizes[1] -= (lMin - sizes[0]); sizes[0] = lMin; } } else if (!rMinValid) { if (sizes[0] - (rMin - sizes[1]) < lMin) { // both below min, just make sure > 0 if (sizes[1] < 0) { sizes[0] += sizes[1]; sizes[1] = 0; } } else { sizes[0] -= (rMin - sizes[1]); sizes[1] = rMin; } } if (sizes[0] < 0) { sizes[0] = 0; } if (sizes[1] < 0) { sizes[1] = 0; } } else if (lValid) { sizes[0] = Math.max(0, sizes[0] + space); } else if (rValid) { sizes[1] = Math.max(0, sizes[1] + space); } } } /** * LayoutManager used for JSplitPanes with an orientation of * VERTICAL_SPLIT. * <p> */ public class BasicVerticalLayoutManager extends BasicHorizontalLayoutManager { public BasicVerticalLayoutManager() { super(1); } } private class Handler implements FocusListener, PropertyChangeListener { // // PropertyChangeListener // /** * Messaged from the <code>JSplitPane</code> the receiver is * contained in. May potentially reset the layout manager and cause a * <code>validate</code> to be sent. */ public void propertyChange(PropertyChangeEvent e) { if(e.getSource() == splitPane) { String changeName = e.getPropertyName(); if(changeName == JSplitPane.ORIENTATION_PROPERTY) { orientation = splitPane.getOrientation(); resetLayoutManager(); } else if(changeName == JSplitPane.CONTINUOUS_LAYOUT_PROPERTY){ setContinuousLayout(splitPane.isContinuousLayout()); if(!isContinuousLayout()) { if(nonContinuousLayoutDivider == null) { setNonContinuousLayoutDivider( createDefaultNonContinuousLayoutDivider(), true); } else if(nonContinuousLayoutDivider.getParent() == null) { setNonContinuousLayoutDivider( nonContinuousLayoutDivider, true); } } } else if(changeName == JSplitPane.DIVIDER_SIZE_PROPERTY){ divider.setDividerSize(splitPane.getDividerSize()); dividerSize = divider.getDividerSize(); splitPane.revalidate(); splitPane.repaint(); } } } // // FocusListener // public void focusGained(FocusEvent ev) { dividerKeyboardResize = true; splitPane.repaint(); } public void focusLost(FocusEvent ev) { dividerKeyboardResize = false; splitPane.repaint(); } } private static class Actions extends UIAction { private static final String NEGATIVE_INCREMENT = "negativeIncrement"; private static final String POSITIVE_INCREMENT = "positiveIncrement"; private static final String SELECT_MIN = "selectMin"; private static final String SELECT_MAX = "selectMax"; private static final String START_RESIZE = "startResize"; private static final String TOGGLE_FOCUS = "toggleFocus"; private static final String FOCUS_OUT_FORWARD = "focusOutForward"; private static final String FOCUS_OUT_BACKWARD = "focusOutBackward"; Actions(String key) { super(key); } p
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -