Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/com/apple/laf/AquaInternalFrameManager.java
38831 views
/*1* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.apple.laf;2627import java.awt.*;28import java.beans.PropertyVetoException;29import java.util.Vector;3031import javax.swing.*;3233/**34* Based on AquaInternalFrameManager35*36* DesktopManager implementation for Aqua37*38* Mac is more like Windows than it's like Motif/Basic39*40* From WindowsDesktopManager:41*42* This class implements a DesktopManager which more closely follows43* the MDI model than the DefaultDesktopManager. Unlike the44* DefaultDesktopManager policy, MDI requires that the selected45* and activated child frames are the same, and that that frame46* always be the top-most window.47* <p>48* The maximized state is managed by the DesktopManager with MDI,49* instead of just being a property of the individual child frame.50* This means that if the currently selected window is maximized51* and another window is selected, that new window will be maximized.52*53* @see com.sun.java.swing.plaf.windows.WindowsDesktopManager54*/55public class AquaInternalFrameManager extends DefaultDesktopManager {56// Variables5758/* The frame which is currently selected/activated.59* We store this value to enforce Mac's single-selection model.60*/61JInternalFrame fCurrentFrame;62JInternalFrame fInitialFrame;63AquaInternalFramePaneUI fCurrentPaneUI;6465/* The list of frames, sorted by order of creation.66* This list is necessary because by default the order of67* child frames in the JDesktopPane changes during frame68* activation (the activated frame is moved to index 0).69* We preserve the creation order so that "next" and "previous"70* frame actions make sense.71*/72Vector<JInternalFrame> fChildFrames = new Vector<JInternalFrame>(1);7374public void closeFrame(final JInternalFrame f) {75if (f == fCurrentFrame) {76activateNextFrame();77}78fChildFrames.removeElement(f);79super.closeFrame(f);80}8182public void deiconifyFrame(final JInternalFrame f) {83JInternalFrame.JDesktopIcon desktopIcon;8485desktopIcon = f.getDesktopIcon();86// If the icon moved, move the frame to that spot before expanding it87// reshape does delta checks for us88f.reshape(desktopIcon.getX(), desktopIcon.getY(), f.getWidth(), f.getHeight());89super.deiconifyFrame(f);90}9192void addIcon(final Container c, final JInternalFrame.JDesktopIcon desktopIcon) {93c.add(desktopIcon);94}9596/** Removes the frame from its parent and adds its desktopIcon to the parent. */97public void iconifyFrame(final JInternalFrame f) {98// Same as super except doesn't deactivate it99JInternalFrame.JDesktopIcon desktopIcon;100Container c;101102desktopIcon = f.getDesktopIcon();103// Position depends on *current* position of frame, unlike super which reuses the first position104final Rectangle r = getBoundsForIconOf(f);105desktopIcon.setBounds(r.x, r.y, r.width, r.height);106107c = f.getParent();108if (c == null) return;109110c.remove(f);111addIcon(c, desktopIcon);112c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());113}114115// WindowsDesktopManager code116public void activateFrame(final JInternalFrame f) {117try {118if (f != null) super.activateFrame(f);119120// If this is the first activation, add to child list.121if (fChildFrames.indexOf(f) == -1) {122fChildFrames.addElement(f);123}124125if (fCurrentFrame != null && f != fCurrentFrame) {126if (fCurrentFrame.isSelected()) {127fCurrentFrame.setSelected(false);128}129}130131if (f != null && !f.isSelected()) {132f.setSelected(true);133}134135fCurrentFrame = f;136} catch(final PropertyVetoException e) {}137}138139private void switchFrame(final boolean next) {140if (fCurrentFrame == null) {141// initialize first frame we find142if (fInitialFrame != null) activateFrame(fInitialFrame);143return;144}145146final int count = fChildFrames.size();147if (count <= 1) {148// No other child frames.149return;150}151152final int currentIndex = fChildFrames.indexOf(fCurrentFrame);153if (currentIndex == -1) {154// the "current frame" is no longer in the list155fCurrentFrame = null;156return;157}158159int nextIndex;160if (next) {161nextIndex = currentIndex + 1;162if (nextIndex == count) {163nextIndex = 0;164}165} else {166nextIndex = currentIndex - 1;167if (nextIndex == -1) {168nextIndex = count - 1;169}170}171final JInternalFrame f = fChildFrames.elementAt(nextIndex);172activateFrame(f);173fCurrentFrame = f;174}175176/**177* Activate the next child JInternalFrame, as determined by178* the frames' Z-order. If there is only one child frame, it179* remains activated. If there are no child frames, nothing180* happens.181*/182public void activateNextFrame() {183switchFrame(true);184}185186/** same as above but will activate a frame if none187* have been selected188*/189public void activateNextFrame(final JInternalFrame f) {190fInitialFrame = f;191switchFrame(true);192}193194/**195* Activate the previous child JInternalFrame, as determined by196* the frames' Z-order. If there is only one child frame, it197* remains activated. If there are no child frames, nothing198* happens.199*/200public void activatePreviousFrame() {201switchFrame(false);202}203}204205206