📄 basicsplitpaneui.java
字号:
* * @return A new PropertyChangeListener. */ protected PropertyChangeListener createPropertyChangeListener() { return new PropertyHandler(); } /** * This method creates a new FocusListener. * * @return A new FocusListener. */ protected FocusListener createFocusListener() { return new FocusHandler(); } /** * This method creates a new ActionListener for up and left key presses. * * @return A new ActionListener for up and left keys. * * @deprecated 1.3 */ protected ActionListener createKeyboardUpLeftListener() { return new KeyboardUpLeftHandler(); } /** * This method creates a new ActionListener for down and right key presses. * * @return A new ActionListener for down and right keys. * * @deprecated 1.3 */ protected ActionListener createKeyboardDownRightListener() { return new KeyboardDownRightHandler(); } /** * This method creates a new ActionListener for home key presses. * * @return A new ActionListener for home keys. * * @deprecated */ protected ActionListener createKeyboardHomeListener() { return new KeyboardHomeHandler(); } /** * This method creates a new ActionListener for end key presses.i * * @return A new ActionListener for end keys. * * @deprecated 1.3 */ protected ActionListener createKeyboardEndListener() { return new KeyboardEndHandler(); } /** * This method creates a new ActionListener for resize toggle key events. * * @return A new ActionListener for resize toggle keys. * * @deprecated 1.3 */ protected ActionListener createKeyboardResizeToggleListener() { return new KeyboardResizeToggleHandler(); } /** * This method returns the orientation of the JSplitPane. * * @return The orientation of the JSplitPane. */ public int getOrientation() { return splitPane.getOrientation(); } /** * This method sets the orientation of the JSplitPane. * * @param orientation The new orientation of the JSplitPane. */ public void setOrientation(int orientation) { splitPane.setOrientation(orientation); } /** * This method returns true if the JSplitPane is using continuous layout. * * @return True if the JSplitPane is using continuous layout. */ public boolean isContinuousLayout() { return splitPane.isContinuousLayout(); } /** * This method sets the continuous layout property of the JSplitPane. * * @param b True if the JsplitPane is to use continuous layout. */ public void setContinuousLayout(boolean b) { splitPane.setContinuousLayout(b); } /** * This method returns the last location the divider was dragged to. * * @return The last location the divider was dragged to. */ public int getLastDragLocation() { return lastDragLocation; } /** * This method sets the last location the divider was dragged to. * * @param l The last location the divider was dragged to. */ public void setLastDragLocation(int l) { lastDragLocation = l; } /** * This method returns the BasicSplitPaneDivider that divides this * JSplitPane. * * @return The divider for the JSplitPane. */ public BasicSplitPaneDivider getDivider() { return divider; } /** * This method creates a nonContinuousLayoutDivider for use with the * JSplitPane in nonContinousLayout mode. The default divider is a gray * Canvas. * * @return The default nonContinousLayoutDivider. */ protected Component createDefaultNonContinuousLayoutDivider() { if (nonContinuousLayoutDivider == null) { nonContinuousLayoutDivider = new Canvas(); nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY); } return nonContinuousLayoutDivider; } /** * This method sets the component to use as the nonContinuousLayoutDivider. * * @param newDivider The component to use as the nonContinuousLayoutDivider. */ protected void setNonContinuousLayoutDivider(Component newDivider) { setNonContinuousLayoutDivider(newDivider, true); } /** * This method sets the component to use as the nonContinuousLayoutDivider. * * @param newDivider The component to use as the nonContinuousLayoutDivider. * @param rememberSizes FIXME: document. */ protected void setNonContinuousLayoutDivider(Component newDivider, boolean rememberSizes) { // FIXME: use rememberSizes for something nonContinuousLayoutDivider = newDivider; } /** * This method returns the nonContinuousLayoutDivider. * * @return The nonContinuousLayoutDivider. */ public Component getNonContinuousLayoutDivider() { return nonContinuousLayoutDivider; } /** * This method returns the JSplitPane that this BasicSplitPaneUI draws. * * @return The JSplitPane. */ public JSplitPane getSplitPane() { return splitPane; } /** * This method creates the divider used normally with the JSplitPane. * * @return The default divider. */ public BasicSplitPaneDivider createDefaultDivider() { if (divider == null) divider = new BasicSplitPaneDivider(this); return divider; } /** * This method is called when JSplitPane's resetToPreferredSizes is called. * It resets the sizes of all components in the JSplitPane. * * @param jc The JSplitPane to reset. */ public void resetToPreferredSizes(JSplitPane jc) { layoutManager.resetToPreferredSizes(); } /** * This method sets the location of the divider. * * @param jc The JSplitPane to set the divider location in. * @param location The new location of the divider. */ public void setDividerLocation(JSplitPane jc, int location) { location = validLocation(location); Container p = jc.getParent(); Component right = jc.getRightComponent(); Dimension rightPrefSize = right == null ? new Dimension(0, 0) : right.getPreferredSize(); Dimension size = jc.getSize(); // check if the size has been set for the splitpane if (size.width == 0 && size.height == 0) size = jc.getPreferredSize(); if (getOrientation() == 0 && location > size.height) { location = size.height; while (p != null) { p.setSize(p.getWidth(), p.getHeight() + rightPrefSize.height); p = p.getParent(); } } else if (location > size.width) { location = size.width; while (p != null) { p.setSize(p.getWidth() + rightPrefSize.width, p.getHeight()); p = p.getParent(); } } setLastDragLocation(getDividerLocation(splitPane)); splitPane.setLastDividerLocation(getDividerLocation(splitPane)); int[] tmpSizes = layoutManager.getSizes(); tmpSizes[0] = location - layoutManager.getInitialLocation(splitPane.getInsets()); tmpSizes[1] = layoutManager.getAvailableSize(splitPane.getSize(), splitPane.getInsets()) - tmpSizes[0]; layoutManager.setSizes(tmpSizes); splitPane.revalidate(); splitPane.repaint(); } /** * This method returns the location of the divider. * * @param jc The JSplitPane to retrieve the location for. * * @return The location of the divider. */ public int getDividerLocation(JSplitPane jc) { return layoutManager.sizes[0] + layoutManager.getInitialLocation(splitPane.getInsets()); } /** * This method returns the smallest value possible for the location of the * divider. * * @param jc The JSplitPane. * * @return The minimum divider location. */ public int getMinimumDividerLocation(JSplitPane jc) { int value = layoutManager.getInitialLocation(jc.getInsets()); if (layoutManager.components[0] != null) value -= layoutManager.minimumSizeOfComponent(0); return value; } /** * This method returns the largest value possible for the location of the * divider. * * @param jc The JSplitPane. * * @return The maximum divider location. */ public int getMaximumDividerLocation(JSplitPane jc) { int value = layoutManager.getInitialLocation(jc.getInsets()) + layoutManager.getAvailableSize(jc.getSize(), jc.getInsets()) - splitPane.getDividerSize(); if (layoutManager.components[1] != null) value -= layoutManager.minimumSizeOfComponent(1); return value; } /** * This method is called after the children of the JSplitPane are painted. * * @param jc The JSplitPane. * @param g The Graphics object to paint with. */ public void finishedPaintingChildren(JSplitPane jc, Graphics g) { if (! splitPane.isContinuousLayout() && nonContinuousLayoutDivider != null && nonContinuousLayoutDivider.isVisible()) javax.swing.SwingUtilities.paintComponent(g, nonContinuousLayoutDivider, null, nonContinuousLayoutDivider .getBounds()); } /** * This method is called to paint the JSplitPane. * * @param g The Graphics object to paint with. * @param jc The JSplitPane to paint. */ public void paint(Graphics g, JComponent jc) { // TODO: What should be done here? } /** * This method returns the preferred size of the JSplitPane. * * @param jc The JSplitPane. * * @return The preferred size of the JSplitPane. */ public Dimension getPreferredSize(JComponent jc) { return layoutManager.preferredLayoutSize((Container) jc); } /** * This method returns the minimum size of the JSplitPane. * * @param jc The JSplitPane. * * @return The minimum size of the JSplitPane. */ public Dimension getMinimumSize(JComponent jc) { return layoutManager.minimumLayoutSize((Container) jc); } /** * This method returns the maximum size of the JSplitPane. * * @param jc The JSplitPane. * * @return The maximum size of the JSplitPane. */ public Dimension getMaximumSize(JComponent jc) { return layoutManager.maximumLayoutSize((Container) jc); } /** * This method returns the border insets of the current border. * * @param jc The JSplitPane. * * @return The current border insets. */ public Insets getInsets(JComponent jc) { return splitPane.getBorder().getBorderInsets(splitPane); } /** * This method resets the current layout manager. The type of layout manager * is dependent on the current orientation. */ protected void resetLayoutManager() { if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) layoutManager = new BasicHorizontalLayoutManager(); else layoutManager = new BasicVerticalLayoutManager(); getSplitPane().setLayout(layoutManager); layoutManager.updateComponents(); // invalidating by itself does not invalidate the layout. getSplitPane().revalidate(); } /** * This method is called when dragging starts. It resets lastDragLocation * and dividerSize. */ protected void startDragging() { Component left = splitPane.getLeftComponent(); Component right = splitPane.getRightComponent(); dividerSize = divider.getDividerSize(); setLastDragLocation(-1); if ((left != null && !left.isLightweight()) || (right != null && !right.isLightweight())) draggingHW = true; if (splitPane.isContinuousLayout()) nonContinuousLayoutDivider.setVisible(false); else { nonContinuousLayoutDivider.setVisible(true); nonContinuousLayoutDivider.setBounds(divider.getBounds()); } splitPane.revalidate(); splitPane.repaint(); } /** * This method is called whenever the divider is dragged. If the JSplitPane * is in continuousLayout mode, the divider needs to be moved and the * JSplitPane needs to be laid out. * * @param location The new location of the divider. */ protected void dragDividerTo(int location) { location = validLocation(location); if (beginDragDividerLocation == -1) beginDragDividerLocation = location; if (splitPane.isContinuousLayout()) splitPane.setDividerLocation(location); else { Point p = nonContinuousLayoutDivider.getLocation(); if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) p.x = location; else p.y = location; nonContinuousLayoutDivider.setLocation(p); } setLastDragLocation(location); splitPane.repaint(); } /** * This method is called when the dragging is finished. * * @param location The location where the drag finished. */ protected void finishDraggingTo(int location) { if (nonContinuousLayoutDivider != null) nonContinuousLayoutDivider.setVisible(false); draggingHW = false; location = validLocation(location); dragDividerTo(location); splitPane.setDividerLocation(location); splitPane.setLastDividerLocation(beginDragDividerLocation); beginDragDividerLocation = -1; splitPane.repaint(); } /** * This method returns the width of one of the sides of the divider's border. * * @return The width of one side of the divider's border. * * @deprecated 1.3 */ protected int getDividerBorderSize() { if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) return divider.getBorder().getBorderInsets(divider).left; else return divider.getBorder().getBorderInsets(divider).top; } /** * This is a helper method that returns a valid location for the divider * when dragging. * * @param location The location to check. * * @return A valid location. */ private int validLocation(int location) { int min = getMinimumDividerLocation(splitPane); int max = getMaximumDividerLocation(splitPane); if (min > 0 && location < min) return min; if (max > 0 && location > max) return max; return location; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -