?? basicsplitpanedivider.java
字號:
} } revalidate(); } /** * Creates and return an instance of JButton that can be used to * collapse the left component in the split pane. */ protected JButton createLeftOneTouchButton() { JButton b = new JButton() { public void setBorder(Border b) { } public void paint(Graphics g) { if (splitPane != null) { int[] xs = new int[3]; int[] ys = new int[3]; int blockSize; // Fill the background first ... g.setColor(this.getBackground()); g.fillRect(0, 0, this.getWidth(), this.getHeight()); // ... then draw the arrow. g.setColor(Color.black); if (orientation == JSplitPane.VERTICAL_SPLIT) { blockSize = Math.min(getHeight(), oneTouchSize); xs[0] = blockSize; xs[1] = 0; xs[2] = blockSize << 1; ys[0] = 0; ys[1] = ys[2] = blockSize; g.drawPolygon(xs, ys, 3); // Little trick to make the // arrows of equal size } else { blockSize = Math.min(getWidth(), oneTouchSize); xs[0] = xs[2] = blockSize; xs[1] = 0; ys[0] = 0; ys[1] = blockSize; ys[2] = blockSize << 1; } g.fillPolygon(xs, ys, 3); } } // Don't want the button to participate in focus traversable. public boolean isFocusTraversable() { return false; } }; b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); b.setFocusPainted(false); b.setBorderPainted(false); b.setRequestFocusEnabled(false); return b; } /** * Creates and return an instance of JButton that can be used to * collapse the right component in the split pane. */ protected JButton createRightOneTouchButton() { JButton b = new JButton() { public void setBorder(Border border) { } public void paint(Graphics g) { if (splitPane != null) { int[] xs = new int[3]; int[] ys = new int[3]; int blockSize; // Fill the background first ... g.setColor(this.getBackground()); g.fillRect(0, 0, this.getWidth(), this.getHeight()); // ... then draw the arrow. if (orientation == JSplitPane.VERTICAL_SPLIT) { blockSize = Math.min(getHeight(), oneTouchSize); xs[0] = blockSize; xs[1] = blockSize << 1; xs[2] = 0; ys[0] = blockSize; ys[1] = ys[2] = 0; } else { blockSize = Math.min(getWidth(), oneTouchSize); xs[0] = xs[2] = 0; xs[1] = blockSize; ys[0] = 0; ys[1] = blockSize; ys[2] = blockSize << 1; } g.setColor(Color.black); g.fillPolygon(xs, ys, 3); } } // Don't want the button to participate in focus traversable. public boolean isFocusTraversable() { return false; } }; b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); b.setFocusPainted(false); b.setBorderPainted(false); b.setRequestFocusEnabled(false); return b; } /** * Message to prepare for dragging. This messages the BasicSplitPaneUI * with startDragging. */ protected void prepareForDragging() { splitPaneUI.startDragging(); } /** * Messages the BasicSplitPaneUI with dragDividerTo that this instance * is contained in. */ protected void dragDividerTo(int location) { splitPaneUI.dragDividerTo(location); } /** * Messages the BasicSplitPaneUI with finishDraggingTo that this instance * is contained in. */ protected void finishDraggingTo(int location) { splitPaneUI.finishDraggingTo(location); } /** * MouseHandler is responsible for converting mouse events * (released, dragged...) into the appropriate DragController * methods. * <p> */ protected class MouseHandler extends MouseAdapter implements MouseMotionListener { /** * Starts the dragging session by creating the appropriate instance * of DragController. */ public void mousePressed(MouseEvent e) { if ((e.getSource() == BasicSplitPaneDivider.this || e.getSource() == splitPane) && dragger == null &&splitPane.isEnabled()) { Component newHiddenDivider = splitPaneUI. getNonContinuousLayoutDivider(); if (hiddenDivider != newHiddenDivider) { if (hiddenDivider != null) { hiddenDivider.removeMouseListener(this); hiddenDivider.removeMouseMotionListener(this); } hiddenDivider = newHiddenDivider; if (hiddenDivider != null) { hiddenDivider.addMouseMotionListener(this); hiddenDivider.addMouseListener(this); } } if (splitPane.getLeftComponent() != null && splitPane.getRightComponent() != null) { if (orientation == JSplitPane.HORIZONTAL_SPLIT) { dragger = new DragController(e); } else { dragger = new VerticalDragController(e); } if (!dragger.isValid()) { dragger = null; } else { prepareForDragging(); dragger.continueDrag(e); } } e.consume(); } } /** * If dragger is not null it is messaged with completeDrag. */ public void mouseReleased(MouseEvent e) { if (dragger != null) { if (e.getSource() == splitPane) { dragger.completeDrag(e.getX(), e.getY()); } else if (e.getSource() == BasicSplitPaneDivider.this) { Point ourLoc = getLocation(); dragger.completeDrag(e.getX() + ourLoc.x, e.getY() + ourLoc.y); } else if (e.getSource() == hiddenDivider) { Point hDividerLoc = hiddenDivider.getLocation(); int ourX = e.getX() + hDividerLoc.x; int ourY = e.getY() + hDividerLoc.y; dragger.completeDrag(ourX, ourY); } dragger = null; e.consume(); } } // // MouseMotionListener // /** * If dragger is not null it is messaged with continueDrag. */ public void mouseDragged(MouseEvent e) { if (dragger != null) { if (e.getSource() == splitPane) { dragger.continueDrag(e.getX(), e.getY()); } else if (e.getSource() == BasicSplitPaneDivider.this) { Point ourLoc = getLocation(); dragger.continueDrag(e.getX() + ourLoc.x, e.getY() + ourLoc.y); } else if (e.getSource() == hiddenDivider) { Point hDividerLoc = hiddenDivider.getLocation(); int ourX = e.getX() + hDividerLoc.x; int ourY = e.getY() + hDividerLoc.y; dragger.continueDrag(ourX, ourY); } e.consume(); } } /** * Resets the cursor based on the orientation. */ public void mouseMoved(MouseEvent e) { } /** * Invoked when the mouse enters a component. * * @param e MouseEvent describing the details of the enter event. * @since 1.5 */ public void mouseEntered(MouseEvent e) { if (e.getSource() == BasicSplitPaneDivider.this) { setMouseOver(true); } } /** * Invoked when the mouse exits a component. * * @param e MouseEvent describing the details of the exit event. * @since 1.5 */ public void mouseExited(MouseEvent e) { if (e.getSource() == BasicSplitPaneDivider.this) { setMouseOver(false); } } } /** * Handles the events during a dragging session for a * HORIZONTAL_SPLIT oriented split pane. This continually * messages <code>dragDividerTo</code> and then when done messages * <code>finishDraggingTo</code>. When an instance is created it should be * messaged with <code>isValid</code> to insure that dragging can happen * (dragging won't be allowed if the two views can not be resized). * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ protected class DragController { /** * Initial location of the divider. */ int initialX; /** * Maximum and minimum positions to drag to. */ int maxX, minX; /** * Initial location the mouse down happened at. */ int offset; protected DragController(MouseEvent e) { JSplitPane splitPane = splitPaneUI.getSplitPane(); Component leftC = splitPane.getLeftComponent(); Component rightC = splitPane.getRightComponent(); initialX = getLocation().x; if (e.getSource() == BasicSplitPaneDivider.this) { offset = e.getX(); } else { // splitPane offset = e.getX() - initialX; } if (leftC == null || rightC == null || offset < -1 || offset >= getSize().width) { // Don't allow dragging. maxX = -1; } else { Insets insets = splitPane.getInsets(); if (leftC.isVisible()) { minX = leftC.getMinimumSize().width; if (insets != null) { minX += insets.left; } } else { minX = 0; } if (rightC.isVisible()) { int right = (insets != null) ? insets.right : 0; maxX = Math.max(0, splitPane.getSize().width - (getSize().width + right) - rightC.getMinimumSize().width); } else { int right = (insets != null) ? insets.right : 0; maxX = Math.max(0, splitPane.getSize().width - (getSize().width + right));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -