📄 basicinternalframeui.java
字号:
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(ep.y < 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 { /** * 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(); } /* Unused */ public void componentMoved(ComponentEvent e) {} /* Unused */ public void componentShown(ComponentEvent e) {} /* Unused */ public void componentHidden(ComponentEvent e) {} } protected ComponentListener createComponentListener() { return new ComponentHandler(); } private static boolean isDragging = false; protected class GlassPaneDispatcher implements MouseInputListener { private Component mouseEventTarget = null; private Component dragSource = null; /** * When inactive, mouse events are forwarded as appropriate either to * the UI to activate the frame or to the underlying child component. */ public void mousePressed(MouseEvent e) { // what is going on here is the GlassPane is up on the inactive // internalframe and want's to "catch" the first mousePressed on // the frame in order to give it to the BorderLister (and not the // underlying component) and let it activate the frame if (borderListener != null){ borderListener.mousePressed(e); } forwardMouseEvent(e); } /** * Forward the mouseEntered event to the underlying child container. * @see #mousePressed */ public void mouseEntered(MouseEvent e) { forwardMouseEvent(e); } /** * Forward the mouseMoved event to the underlying child container. * @see #mousePressed */ public void mouseMoved(MouseEvent e) { forwardMouseEvent(e); } /** * Forward the mouseExited event to the underlying child container. * @see #mousePressed */ public void mouseExited(MouseEvent e) { forwardMouseEvent(e); } /** * Ignore mouseClicked events. * @see #mousePressed */ public void mouseClicked(MouseEvent e) { } /** * Forward the mouseReleased event to the underlying child container. * @see #mousePressed */ public void mouseReleased(MouseEvent e) { forwardMouseEvent(e); } /** * Forward the mouseDragged event to the underlying child container. * @see #mousePressed */ public void mouseDragged(MouseEvent e) { forwardMouseEvent(e); } /** * Forward a mouse event to the current mouse target, setting it * if necessary. */ private void forwardMouseEvent(MouseEvent e) { // We only want to do this for the selected internal frame. Component target = findComponentAt(frame.getRootPane().getLayeredPane(), e.getX(), e.getY()); int id = e.getID(); switch(id) { case MouseEvent.MOUSE_ENTERED: if (isDragging && !frame.isSelected()) { return; } if (target != mouseEventTarget) { mouseEventTarget = target; } retargetMouseEvent(id, e, mouseEventTarget); break; case MouseEvent.MOUSE_PRESSED: if (target != mouseEventTarget) { mouseEventTarget = target; } retargetMouseEvent(id, e, mouseEventTarget); // Set the drag source in case we start dragging. dragSource = target; break; case MouseEvent.MOUSE_EXITED: if (isDragging && !frame.isSelected()) { return; } retargetMouseEvent(id, e, mouseEventTarget); break; case MouseEvent.MOUSE_CLICKED: retargetMouseEvent(id, e, mouseEventTarget); break; case MouseEvent.MOUSE_MOVED: if (target != mouseEventTarget) { retargetMouseEvent(MouseEvent.MOUSE_EXITED, e, mouseEventTarget); mouseEventTarget = target; retargetMouseEvent(MouseEvent.MOUSE_ENTERED, e, mouseEventTarget); } retargetMouseEvent(id, e, mouseEventTarget); break; case MouseEvent.MOUSE_DRAGGED: if (!isDragging) { isDragging = true; } retargetMouseEvent(id, e, dragSource); break; case MouseEvent.MOUSE_RELEASED: if (isDragging) { retargetMouseEvent(id, e, dragSource); isDragging = false; } else { retargetMouseEvent(id, e, mouseEventTarget); } } } /* * Find the lightweight child component which corresponds to the * specified location. This is similar to the new 1.2 API in * Container, but we need to run on 1.1. The other changes are * due to Container.findComponentAt's use of package-private data. */ private Component findComponentAt(Container c, int x, int y) { if (!c.contains(x, y)) { return c; } int ncomponents = c.getComponentCount(); Component component[] = c.getComponents(); for (int i = 0 ; i < ncomponents ; i++) { Component comp = component[i]; Point loc = comp.getLocation(); if ((comp != null) && (comp.contains(x - loc.x, y - loc.y)) && (comp.getPeer() instanceof LightweightPeer) && (comp.isVisible() == true)) { // found a component that intersects the point, see if there // is a deeper possibility. if (comp instanceof Container) { Container child = (Container) comp; Point childLoc = child.getLocation(); Component deeper = findComponentAt(child, x - childLoc.x, y - childLoc.y); if (deeper != null) { return deeper; } } else { return comp; } } } return c; } /* * Dispatch an event clone, retargeted for the specified target. */ private void retargetMouseEvent(int id, MouseEvent e, Component target) { if (target == null) { return; } // fix for bug #4202966 -- hania // When retargetting a mouse event, we need to translate // the event's coordinates relative to the target. Point p = SwingUtilities.convertPoint(frame.getLayeredPane(), e.getX(), e.getY(), target); MouseEvent retargeted = new MouseEvent(target, id, e.getWhen(), e.getModifiers() | e.getModifiersEx(), p.x, p.y, e.getClickCount(), e.isPopupTrigger()); target.dispatchEvent(retargeted); } } protected MouseInputListener createGlassPaneDispatcher(){ return new GlassPaneDispatcher(); } protected class BasicInternalFrameListener implements InternalFrameListener { public void internalFrameClosing(InternalFrameEvent e) { } public void internalFrameClosed(InternalFrameEvent e) { frame.removeInternalFrameListener(internalFrameListener); } public void internalFrameOpened(InternalFrameEvent e) { } public void internalFrameIconified(InternalFrameEvent e) { } public void internalFrameDeiconified(InternalFrameEvent e) { } public void internalFrameActivated(InternalFrameEvent e) { if (!isKeyBindingRegistered()){ setKeyBindingRegistered(true); setupMenuOpenKey(); setupMenuCloseKey(); } if (isKeyBindingRegistered()) setKeyBindingActive(true); } public void internalFrameDeactivated(InternalFrameEvent e) { setKeyBindingActive(false); } } } /// End BasicInternalFrameUI Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -