basicinternalframeui.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,620 行 · 第 1/4 页
JAVA
1,620 行
// InternalFrameListener public void internalFrameClosed(InternalFrameEvent e) { frame.removeInternalFrameListener(getHandler()); } public void internalFrameActivated(InternalFrameEvent e) { if (!isKeyBindingRegistered()){ setKeyBindingRegistered(true); setupMenuOpenKey(); setupMenuCloseKey(); } if (isKeyBindingRegistered()) setKeyBindingActive(true); } public void internalFrameDeactivated(InternalFrameEvent e) { setKeyBindingActive(false); } public void internalFrameClosing(InternalFrameEvent e) { } public void internalFrameOpened(InternalFrameEvent e) { } public void internalFrameIconified(InternalFrameEvent e) { } public void internalFrameDeiconified(InternalFrameEvent e) { } // LayoutManager public void addLayoutComponent(String name, Component c) {} public void removeLayoutComponent(Component c) {} public Dimension preferredLayoutSize(Container c) { Dimension result; Insets i = frame.getInsets(); result = new Dimension(frame.getRootPane().getPreferredSize()); result.width += i.left + i.right; result.height += i.top + i.bottom; if(getNorthPane() != null) { Dimension d = getNorthPane().getPreferredSize(); result.width = Math.max(d.width, result.width); result.height += d.height; } if(getSouthPane() != null) { Dimension d = getSouthPane().getPreferredSize(); result.width = Math.max(d.width, result.width); result.height += d.height; } if(getEastPane() != null) { Dimension d = getEastPane().getPreferredSize(); result.width += d.width; result.height = Math.max(d.height, result.height); } if(getWestPane() != null) { Dimension d = getWestPane().getPreferredSize(); result.width += d.width; result.height = Math.max(d.height, result.height); } return result; } public Dimension minimumLayoutSize(Container c) { // The minimum size of the internal frame only takes into // account the title pane since you are allowed to resize // the frames to the point where just the title pane is visible. Dimension result = new Dimension(); if (getNorthPane() != null && getNorthPane() instanceof BasicInternalFrameTitlePane) { result = new Dimension(getNorthPane().getMinimumSize()); } Insets i = frame.getInsets(); result.width += i.left + i.right; result.height += i.top + i.bottom; return result; } public void layoutContainer(Container c) { Insets i = frame.getInsets(); int cx, cy, cw, ch; cx = i.left; cy = i.top; cw = frame.getWidth() - i.left - i.right; ch = frame.getHeight() - i.top - i.bottom; if(getNorthPane() != null) { Dimension size = getNorthPane().getPreferredSize(); if (DefaultLookup.getBoolean(frame, BasicInternalFrameUI.this, "InternalFrame.layoutTitlePaneAtOrigin", false)) { cy = 0; ch += i.top; getNorthPane().setBounds(0, 0, frame.getWidth(), size.height); } else { getNorthPane().setBounds(cx, cy, cw, size.height); } cy += size.height; ch -= size.height; } if(getSouthPane() != null) { Dimension size = getSouthPane().getPreferredSize(); getSouthPane().setBounds(cx, frame.getHeight() - i.bottom - size.height, cw, size.height); ch -= size.height; } if(getWestPane() != null) { Dimension size = getWestPane().getPreferredSize(); getWestPane().setBounds(cx, cy, size.width, ch); cw -= size.width; cx += size.width; } if(getEastPane() != null) { Dimension size = getEastPane().getPreferredSize(); getEastPane().setBounds(cw - size.width, cy, size.width, ch); cw -= size.width; } if(frame.getRootPane() != null) { frame.getRootPane().setBounds(cx, cy, cw, ch); } } // MouseInputListener private Component mouseEventTarget = null; private Component dragSource = null; 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()); // Search hierarchy for target with mouse listeners. while ((target != null) && ((target.getMouseListeners().length == 0) && (target.getMouseMotionListeners().length == 0) && (target.getMouseWheelListeners().length == 0))) { target = target.getParent(); } if (target == null) { // No target found with mouse listeners. return; } 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); } break; case MouseEvent.MOUSE_WHEEL: retargetMouseEvent(id, e, mouseEventTarget); break; } } /** * 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); } // PropertyChangeListener public void propertyChange(PropertyChangeEvent evt) { String prop = (String)evt.getPropertyName(); JInternalFrame f = (JInternalFrame)evt.getSource(); Object newValue = evt.getNewValue(); Object oldValue = evt.getOldValue(); if (JInternalFrame.IS_CLOSED_PROPERTY == prop) { if (newValue == Boolean.TRUE) { cancelResize(); if ((frame.getParent() != null) && componentListenerAdded) { frame.getParent().removeComponentListener( componentListener); } closeFrame(f); } } else if (JInternalFrame.IS_MAXIMUM_PROPERTY == prop) { if(newValue == Boolean.TRUE) { maximizeFrame(f); } else { minimizeFrame(f); } } else if(JInternalFrame.IS_ICON_PROPERTY == prop) { if (newValue == Boolean.TRUE) { iconifyFrame(f); } else { deiconifyFrame(f); } } else if (JInternalFrame.IS_SELECTED_PROPERTY == prop) { Component glassPane = f.getGlassPane(); if (newValue == Boolean.TRUE && oldValue == Boolean.FALSE) { activateFrame(f); glassPane.setVisible(false); } else if (newValue == Boolean.FALSE && oldValue == Boolean.TRUE) { deactivateFrame(f); glassPane.setVisible(true); } } else if (prop == "ancestor") { if (newValue == null) { cancelResize(); } if (frame.getParent() != null) { parentBounds = f.getParent().getBounds(); } else { parentBounds = null; } if ((frame.getParent() != null) && !componentListenerAdded) { f.getParent().addComponentListener(componentListener); componentListenerAdded = true; } else if ((newValue == null) && componentListenerAdded) { if (f.getParent() != null) { f.getParent().removeComponentListener( componentListener); } componentListenerAdded = false; } } else if (JInternalFrame.TITLE_PROPERTY == prop || prop == "closable" || prop == "iconable" || prop == "maximizable") { Dimension dim = frame.getMinimumSize(); Dimension frame_dim = frame.getSize(); if (dim.width > frame_dim.width) { frame.setSize(dim.width, frame_dim.height); } } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?