basicinternalframeui.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,620 行 · 第 1/4 页
JAVA
1,620 行
Insets i = frame.getInsets(); // Handle a MOVE if (dragging) { if (frame.isMaximum() || ((e.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK)) { // don't allow moving of frames if maximixed or left mouse // button was not used. return; } int pWidth, pHeight; Dimension s = frame.getParent().getSize(); pWidth = s.width; pHeight = s.height; newX = startingBounds.x - deltaX; newY = startingBounds.y - deltaY; // Make sure we stay in-bounds if(newX + i.left <= -__x) newX = -__x - i.left + 1; if(newY + i.top <= -__y) newY = -__y - i.top + 1; if(newX + __x + i.right >= pWidth) newX = pWidth - __x - i.right - 1; if(newY + __y + i.bottom >= pHeight) newY = pHeight - __y - i.bottom - 1; getDesktopManager().dragFrame(frame, newX, newY); return; } if(!frame.isResizable()) { return; } newX = frame.getX(); newY = frame.getY(); newW = frame.getWidth(); newH = frame.getHeight(); parentBounds = frame.getParent().getBounds(); switch(resizeDir) { case RESIZE_NONE: return; case NORTH: if(startingBounds.height + deltaY < min.height) deltaY = -(startingBounds.height - min.height); else if(startingBounds.height + deltaY > max.height) deltaY = max.height - startingBounds.height; if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;} newX = startingBounds.x; newY = startingBounds.y - deltaY; newW = startingBounds.width; newH = startingBounds.height + deltaY; break; case NORTH_EAST: if(startingBounds.height + deltaY < min.height) deltaY = -(startingBounds.height - min.height); else if(startingBounds.height + deltaY > max.height) deltaY = max.height - startingBounds.height; if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;} if(startingBounds.width - deltaX < min.width) deltaX = startingBounds.width - min.width; else if(startingBounds.width - deltaX > max.width) deltaX = -(max.width - startingBounds.width); if (startingBounds.x + startingBounds.width - deltaX > parentBounds.width) { deltaX = startingBounds.x + startingBounds.width - parentBounds.width; } newX = startingBounds.x; newY = startingBounds.y - deltaY; newW = startingBounds.width - deltaX; newH = startingBounds.height + deltaY; break; case EAST: if(startingBounds.width - deltaX < min.width) deltaX = startingBounds.width - min.width; else if(startingBounds.width - deltaX > max.width) deltaX = -(max.width - startingBounds.width); if (startingBounds.x + startingBounds.width - deltaX > parentBounds.width) { deltaX = startingBounds.x + startingBounds.width - parentBounds.width; } newW = startingBounds.width - deltaX; newH = startingBounds.height; break; case SOUTH_EAST: if(startingBounds.width - deltaX < min.width) deltaX = startingBounds.width - min.width; else if(startingBounds.width - deltaX > max.width) deltaX = -(max.width - startingBounds.width); if (startingBounds.x + startingBounds.width - deltaX > parentBounds.width) { deltaX = startingBounds.x + startingBounds.width - parentBounds.width; } if(startingBounds.height - deltaY < min.height) deltaY = startingBounds.height - min.height; else if(startingBounds.height - deltaY > max.height) deltaY = -(max.height - startingBounds.height); if (startingBounds.y + startingBounds.height - deltaY > parentBounds.height) { deltaY = startingBounds.y + startingBounds.height - parentBounds.height ; } newW = startingBounds.width - deltaX; newH = startingBounds.height - deltaY; break; case SOUTH: if(startingBounds.height - deltaY < min.height) deltaY = startingBounds.height - min.height; else if(startingBounds.height - deltaY > max.height) deltaY = -(max.height - startingBounds.height); if (startingBounds.y + startingBounds.height - deltaY > parentBounds.height) { deltaY = startingBounds.y + startingBounds.height - parentBounds.height ; } newW = startingBounds.width; newH = startingBounds.height - deltaY; break; case SOUTH_WEST: if(startingBounds.height - deltaY < min.height) deltaY = startingBounds.height - min.height; else if(startingBounds.height - deltaY > max.height) deltaY = -(max.height - startingBounds.height); if (startingBounds.y + startingBounds.height - deltaY > parentBounds.height) { deltaY = startingBounds.y + startingBounds.height - parentBounds.height ; } if(startingBounds.width + deltaX < min.width) deltaX = -(startingBounds.width - min.width); else if(startingBounds.width + deltaX > max.width) deltaX = max.width - startingBounds.width; if (startingBounds.x - deltaX < 0) { deltaX = startingBounds.x; } newX = startingBounds.x - deltaX; newY = startingBounds.y; newW = startingBounds.width + deltaX; newH = startingBounds.height - deltaY; break; case WEST: if(startingBounds.width + deltaX < min.width) deltaX = -(startingBounds.width - min.width); else if(startingBounds.width + deltaX > max.width) deltaX = max.width - startingBounds.width; if (startingBounds.x - deltaX < 0) { deltaX = startingBounds.x; } newX = startingBounds.x - deltaX; newY = startingBounds.y; newW = startingBounds.width + deltaX; newH = startingBounds.height; break; case NORTH_WEST: if(startingBounds.width + deltaX < min.width) deltaX = -(startingBounds.width - min.width); else if(startingBounds.width + deltaX > max.width) deltaX = max.width - startingBounds.width; if (startingBounds.x - deltaX < 0) { deltaX = startingBounds.x; } if(startingBounds.height + deltaY < min.height) deltaY = -(startingBounds.height - min.height); else if(startingBounds.height + deltaY > max.height) deltaY = max.height - startingBounds.height; if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;} newX = startingBounds.x - deltaX; newY = startingBounds.y - deltaY; newW = startingBounds.width + deltaX; newH = startingBounds.height + deltaY; break; default: return; } getDesktopManager().resizeFrame(frame, newX, newY, newW, newH); } public void mouseMoved(MouseEvent e) { if(!frame.isResizable()) return; if (e.getSource() == frame || e.getSource() == getNorthPane()) { Insets i = frame.getInsets(); Point ep = new Point(e.getX(), e.getY()); if (e.getSource() == getNorthPane()) { Point np = getNorthPane().getLocation(); ep.x += np.x; ep.y += np.y; } if(ep.x <= i.left) { if(ep.y < resizeCornerSize + i.top) frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR)); else if(ep.y > frame.getHeight() - resizeCornerSize - i.bottom) frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR)); else frame.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); } else if(ep.x >= frame.getWidth() - i.right) { if(e.getY() < resizeCornerSize + i.top) frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)); else if(ep.y > frame.getHeight() - resizeCornerSize - i.bottom) frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)); else frame.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); } else if(ep.y <= i.top) { if(ep.x < resizeCornerSize + i.left) frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR)); else if(ep.x > frame.getWidth() - resizeCornerSize - i.right) frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)); else frame.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR)); } else if(ep.y >= frame.getHeight() - i.bottom) { if(ep.x < resizeCornerSize + i.left) frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR)); else if(ep.x > frame.getWidth() - resizeCornerSize - i.right) frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)); else frame.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); } else frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; } frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } public void mouseExited(MouseEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }; /// End BorderListener Class protected class ComponentHandler implements ComponentListener { // NOTE: This class exists only for backward compatability. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. /** Invoked when a JInternalFrame's parent's size changes. */ public void componentResized(ComponentEvent e) { getHandler().componentResized(e); } public void componentMoved(ComponentEvent e) { getHandler().componentMoved(e); } public void componentShown(ComponentEvent e) { getHandler().componentShown(e); } public void componentHidden(ComponentEvent e) { getHandler().componentHidden(e); } } protected ComponentListener createComponentListener() { return getHandler(); } protected class GlassPaneDispatcher implements MouseInputListener { // NOTE: This class exists only for backward compatability. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. public void mousePressed(MouseEvent e) { getHandler().mousePressed(e); } public void mouseEntered(MouseEvent e) { getHandler().mouseEntered(e); } public void mouseMoved(MouseEvent e) { getHandler().mouseMoved(e); } public void mouseExited(MouseEvent e) { getHandler().mouseExited(e); } public void mouseClicked(MouseEvent e) { getHandler().mouseClicked(e); } public void mouseReleased(MouseEvent e) { getHandler().mouseReleased(e); } public void mouseDragged(MouseEvent e) { getHandler().mouseDragged(e); } } protected MouseInputListener createGlassPaneDispatcher() { return getHandler(); } protected class BasicInternalFrameListener implements InternalFrameListener { // NOTE: This class exists only for backward compatability. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. public void internalFrameClosing(InternalFrameEvent e) { getHandler().internalFrameClosing(e); } public void internalFrameClosed(InternalFrameEvent e) { getHandler().internalFrameClosed(e); } public void internalFrameOpened(InternalFrameEvent e) { getHandler().internalFrameOpened(e); } public void internalFrameIconified(InternalFrameEvent e) { getHandler().internalFrameIconified(e); } public void internalFrameDeiconified(InternalFrameEvent e) { getHandler().internalFrameDeiconified(e); } public void internalFrameActivated(InternalFrameEvent e) { getHandler().internalFrameActivated(e); } public void internalFrameDeactivated(InternalFrameEvent e) { getHandler().internalFrameDeactivated(e); } } private static boolean isDragging = false; private class Handler implements ComponentListener, InternalFrameListener, LayoutManager, MouseInputListener, PropertyChangeListener, WindowFocusListener, SwingConstants { public void windowGainedFocus(WindowEvent e) { } public void windowLostFocus(WindowEvent e) { cancelResize(); } // ComponentHandler methods /** Invoked when a JInternalFrame's parent's size changes. */ public void componentResized(ComponentEvent e) { // Get the JInternalFrame's parent container size Rectangle parentNewBounds = ((Component) e.getSource()).getBounds(); JInternalFrame.JDesktopIcon icon = null; if (frame != null) { icon = frame.getDesktopIcon(); // Resize the internal frame if it is maximized and relocate // the associated icon as well. if (frame.isMaximum()) { frame.setBounds(0, 0, parentNewBounds.width, parentNewBounds.height); } } // Relocate the icon base on the new parent bounds. if (icon != null) { Rectangle iconBounds = icon.getBounds(); int y = iconBounds.y + (parentNewBounds.height - parentBounds.height); icon.setBounds(iconBounds.x, y, iconBounds.width, iconBounds.height); } // Update the new parent bounds for next resize. if (!parentBounds.equals(parentNewBounds)) { parentBounds = parentNewBounds; } // Validate the component tree for this container. if (frame != null) frame.validate(); } public void componentMoved(ComponentEvent e) {} public void componentShown(ComponentEvent e) {} public void componentHidden(ComponentEvent e) {}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?