basicdesktoppaneui.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 798 行 · 第 1/2 页
JAVA
798 行
c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height); } } else if (RIGHT == key) { if (moving) { c.setLocation(loc.x + MOVE_RESIZE_INCREMENT, loc.y); } else if (resizing) { c.setLocation(loc.x, loc.y); c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height); } } else if (UP == key) { if (moving) { c.setLocation(loc.x, loc.y - MOVE_RESIZE_INCREMENT); } else if (resizing) { c.setLocation(loc.x, loc.y - MOVE_RESIZE_INCREMENT); c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT); } } else if (DOWN == key) { if (moving) { c.setLocation(loc.x, loc.y + MOVE_RESIZE_INCREMENT); } else if (resizing) { c.setLocation(loc.x, loc.y); c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT); } } else if (SHRINK_LEFT == key && resizing) { if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) { c.setLocation(loc.x, loc.y); c.setSize(size.width - MOVE_RESIZE_INCREMENT, size.height); } else { c.setSize(minSize.width, size.height); } } else if (SHRINK_RIGHT == key && resizing) { if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) { c.setLocation(loc.x + MOVE_RESIZE_INCREMENT, loc.y); c.setSize(size.width - MOVE_RESIZE_INCREMENT, size.height); } else { c.setLocation(loc.x - minSize.width + size.width, loc.y); c.setSize(minSize.width, size.height); } } else if (SHRINK_UP == key && resizing) { if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) { c.setLocation(loc.x, loc.y); c.setSize(size.width, size.height - MOVE_RESIZE_INCREMENT); } else { c.setSize(size.width, minSize.height); } } else if (SHRINK_DOWN == key && resizing) { if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) { c.setLocation(loc.x, loc.y + MOVE_RESIZE_INCREMENT); c.setSize(size.width, size.height - MOVE_RESIZE_INCREMENT); } else { c.setLocation(loc.x, loc.y - minSize.height + size.height); c.setSize(size.width, minSize.height); } } } else if (NEXT_FRAME == key || PREVIOUS_FRAME == key) { selectFrame(dp, (key == NEXT_FRAME) ? true : false); } else if (NAVIGATE_NEXT == key || NAVIGATE_PREVIOUS == key) { boolean moveForward = true; if (NAVIGATE_PREVIOUS == key) { moveForward = false; } Container cycleRoot = dp.getFocusCycleRootAncestor(); if (cycleRoot != null) { FocusTraversalPolicy policy = cycleRoot.getFocusTraversalPolicy(); if (policy != null && policy instanceof SortingFocusTraversalPolicy) { SortingFocusTraversalPolicy sPolicy = (SortingFocusTraversalPolicy)policy; boolean idc = sPolicy.getImplicitDownCycleTraversal(); try { sPolicy.setImplicitDownCycleTraversal(false); if (moveForward) { KeyboardFocusManager. getCurrentKeyboardFocusManager(). focusNextComponent(dp); } else { KeyboardFocusManager. getCurrentKeyboardFocusManager(). focusPreviousComponent(dp); } } finally { sPolicy.setImplicitDownCycleTraversal(idc); } } } } } private void selectFrame(JDesktopPane dp, boolean forward) { Vector framesCache = getCurrentFramesCache(); if (forward) { // navigate to the next frame int i = 0; verifyFramesCache(dp); if (framesCache.size() == 0) { return; } JInternalFrame f = dp.getSelectedFrame(); if (f != null) { i = framesCache.indexOf(f); } if (i == -1) { /* if the frame is not there, its icon may be */ i = framesCache.indexOf(f.getDesktopIcon()); if (i == -1) { /* error */ return; } } if (++i == framesCache.size()) { /* wrap */ i = 0; } JComponent c = (JComponent) framesCache.elementAt(i); if (c instanceof JInternalFrame) { try { ((JInternalFrame)c).setSelected(true); dp.getDesktopManager().activateFrame((JInternalFrame)c); } catch (PropertyVetoException pve) {} } else { /* it had better be an icon! */ if (!(c instanceof JInternalFrame.JDesktopIcon)){ /* error */ return; } try { ((JInternalFrame)((JInternalFrame.JDesktopIcon)c). getInternalFrame()).setSelected(true); dp.getDesktopManager().activateFrame( ((JInternalFrame.JDesktopIcon)c). getInternalFrame()); } catch (PropertyVetoException pve) {} } } else { // navigate to the previous internal frame int i = 0; verifyFramesCache(dp); if (framesCache.size() == 0) { return; } JInternalFrame f = dp.getSelectedFrame(); if (f != null) { i = framesCache.indexOf(f); } if (i == -1) { /* if the frame is not there, its icon may be */ i = framesCache.indexOf(f.getDesktopIcon()); if (i == -1) { /* error */ return; } } if (--i == -1) { /* wrap */ i = framesCache.size() - 1; } JComponent c = (JComponent) framesCache.elementAt(i); if (c instanceof JInternalFrame) { try { ((JInternalFrame)c).setSelected(true); } catch (PropertyVetoException pve) {} } else { /* it had better be an icon! */ if (!(c instanceof JInternalFrame.JDesktopIcon)) { /* error */ return; } try { ((JInternalFrame)((JInternalFrame.JDesktopIcon)c). getInternalFrame()).setSelected(true); } catch (PropertyVetoException pve) {} } } } private void setState(JDesktopPane dp, String state) { if (state == CLOSE) { JInternalFrame f = dp.getSelectedFrame(); if (f == null) { return; } f.doDefaultCloseAction(); } else if (state == MAXIMIZE) { // maximize the selected frame JInternalFrame f = dp.getSelectedFrame(); if (f == null) { return; } if (!f.isMaximum()) { if (f.isIcon()) { try { f.setIcon(false); f.setMaximum(true); } catch (PropertyVetoException pve) {} } else { try { f.setMaximum(true); } catch (PropertyVetoException pve) { } } } } else if (state == MINIMIZE) { // minimize the selected frame JInternalFrame f = dp.getSelectedFrame(); if (f == null) { return; } if (!f.isIcon()) { try { f.setIcon(true); } catch (PropertyVetoException pve) { } } } else if (state == RESTORE) { // restore the selected minimized or maximized frame JInternalFrame f = dp.getSelectedFrame(); if (f == null) { return; } try { if (f.isIcon()) { f.setIcon(false); } else if (f.isMaximum()) { f.setMaximum(false); } f.setSelected(true); } catch (PropertyVetoException pve) { } } } public boolean isEnabled(Object sender) { if (sender instanceof JDesktopPane) { JDesktopPane dp = (JDesktopPane)sender; JInternalFrame iFrame = dp.getSelectedFrame(); if (iFrame == null) { return false; } String action = getName(); if (action == Actions.CLOSE) { return iFrame.isClosable(); } else if (action == Actions.MINIMIZE) { return iFrame.isIconifiable(); } else if (action == Actions.MAXIMIZE) { return iFrame.isMaximizable(); } return true; } return false; } } /* * Handles restoring a minimized or maximized internal frame. */ protected class OpenAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.RESTORE); } public boolean isEnabled() { return true; } } /* * Handles closing an internal frame */ protected class CloseAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.CLOSE); } public boolean isEnabled() { JInternalFrame iFrame = desktop.getSelectedFrame(); if (iFrame != null) { return iFrame.isClosable(); } return false; } } /* * Handles minimizing an internal frame */ protected class MinimizeAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.MINIMIZE); } public boolean isEnabled() { JInternalFrame iFrame = desktop.getSelectedFrame(); if (iFrame != null) { return iFrame.isIconifiable(); } return false; } } /* * Handles maximizing an internal frame */ protected class MaximizeAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.MAXIMIZE); } public boolean isEnabled() { JInternalFrame iFrame = desktop.getSelectedFrame(); if (iFrame != null) { return iFrame.isMaximizable(); } return false; } } /* * Handles navigating to the next internal frame. */ protected class NavigateAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.selectFrame(dp, true); } public boolean isEnabled() { return true; } } private static void verifyFramesCache(JDesktopPane dp) { Vector framesCache = getCurrentFramesCache(); // Check whether any internal frames have closed in // which case we have to refresh the frames cache. boolean framesHaveClosed = false; int len = framesCache.size(); for (int i = 0; i < len; i++) { JComponent c = (JComponent)framesCache.elementAt(i); if (c instanceof JInternalFrame) { JInternalFrame f = (JInternalFrame)c; if (f.isClosed()) { framesHaveClosed = true; break; } } else if (c instanceof JInternalFrame.JDesktopIcon) { JInternalFrame.JDesktopIcon icon = (JInternalFrame.JDesktopIcon)c; JInternalFrame f = (JInternalFrame)icon.getInternalFrame(); if (f.isClosed()) { framesHaveClosed = true; break; } } } JInternalFrame [] allFrames = dp.getAllFrames(); if (framesHaveClosed || allFrames.length != framesCache.size()) { // Cache frames starting at the lowest layer. framesCache.clear(); int low = dp.lowestLayer(); int high = dp.highestLayer(); for (int i = high; i >= low; i--) { Component [] comp = dp.getComponentsInLayer(i); if (comp.length > 0) { for (int j = 0; j < comp.length; j++) { framesCache.addElement(comp[j]); } } } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?