Path: blob/master/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameManager.java
41154 views
/*1* Copyright (c) 2011, 2014, 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*/55@SuppressWarnings("serial") // JDK implementation class56public class AquaInternalFrameManager extends DefaultDesktopManager {57// Variables5859/* The frame which is currently selected/activated.60* We store this value to enforce Mac's single-selection model.61*/62JInternalFrame fCurrentFrame;63JInternalFrame fInitialFrame;64AquaInternalFramePaneUI fCurrentPaneUI;6566/* The list of frames, sorted by order of creation.67* This list is necessary because by default the order of68* child frames in the JDesktopPane changes during frame69* activation (the activated frame is moved to index 0).70* We preserve the creation order so that "next" and "previous"71* frame actions make sense.72*/73Vector<JInternalFrame> fChildFrames = new Vector<JInternalFrame>(1);7475public void closeFrame(final JInternalFrame f) {76if (f == fCurrentFrame) {77activateNextFrame();78}79fChildFrames.removeElement(f);80super.closeFrame(f);81}8283public void deiconifyFrame(final JInternalFrame f) {84JInternalFrame.JDesktopIcon desktopIcon;8586desktopIcon = f.getDesktopIcon();87// If the icon moved, move the frame to that spot before expanding it88// reshape does delta checks for us89f.reshape(desktopIcon.getX(), desktopIcon.getY(), f.getWidth(), f.getHeight());90super.deiconifyFrame(f);91}9293void addIcon(final Container c, final JInternalFrame.JDesktopIcon desktopIcon) {94c.add(desktopIcon);95}9697/** Removes the frame from its parent and adds its desktopIcon to the parent. */98public void iconifyFrame(final JInternalFrame f) {99// Same as super except doesn't deactivate it100JInternalFrame.JDesktopIcon desktopIcon;101Container c;102103desktopIcon = f.getDesktopIcon();104// Position depends on *current* position of frame, unlike super which reuses the first position105final Rectangle r = getBoundsForIconOf(f);106desktopIcon.setBounds(r.x, r.y, r.width, r.height);107if (!wasIcon(f)) {108setWasIcon(f, Boolean.TRUE);109}110c = f.getParent();111if (c == null) return;112113c.remove(f);114addIcon(c, desktopIcon);115c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());116}117118// WindowsDesktopManager code119public void activateFrame(final JInternalFrame f) {120try {121if (f != null) super.activateFrame(f);122123// If this is the first activation, add to child list.124if (fChildFrames.indexOf(f) == -1) {125fChildFrames.addElement(f);126}127128if (fCurrentFrame != null && f != fCurrentFrame) {129if (fCurrentFrame.isSelected()) {130fCurrentFrame.setSelected(false);131}132}133134if (f != null && !f.isSelected()) {135f.setSelected(true);136}137138fCurrentFrame = f;139} catch(final PropertyVetoException e) {}140}141142private void switchFrame(final boolean next) {143if (fCurrentFrame == null) {144// initialize first frame we find145if (fInitialFrame != null) activateFrame(fInitialFrame);146return;147}148149final int count = fChildFrames.size();150if (count <= 1) {151// No other child frames.152return;153}154155final int currentIndex = fChildFrames.indexOf(fCurrentFrame);156if (currentIndex == -1) {157// the "current frame" is no longer in the list158fCurrentFrame = null;159return;160}161162int nextIndex;163if (next) {164nextIndex = currentIndex + 1;165if (nextIndex == count) {166nextIndex = 0;167}168} else {169nextIndex = currentIndex - 1;170if (nextIndex == -1) {171nextIndex = count - 1;172}173}174final JInternalFrame f = fChildFrames.elementAt(nextIndex);175activateFrame(f);176fCurrentFrame = f;177}178179/**180* Activate the next child JInternalFrame, as determined by181* the frames' Z-order. If there is only one child frame, it182* remains activated. If there are no child frames, nothing183* happens.184*/185public void activateNextFrame() {186switchFrame(true);187}188189/** same as above but will activate a frame if none190* have been selected191*/192public void activateNextFrame(final JInternalFrame f) {193fInitialFrame = f;194switchFrame(true);195}196197/**198* Activate the previous child JInternalFrame, as determined by199* the frames' Z-order. If there is only one child frame, it200* remains activated. If there are no child frames, nothing201* happens.202*/203public void activatePreviousFrame() {204switchFrame(false);205}206}207208209