Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/com/apple/laf/AquaInternalFramePaneUI.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.awt.event.*;29import java.beans.PropertyVetoException;3031import javax.swing.*;32import javax.swing.border.Border;33import javax.swing.plaf.*;34import javax.swing.plaf.basic.BasicDesktopPaneUI;3536public class AquaInternalFramePaneUI extends BasicDesktopPaneUI implements MouseListener {3738JComponent fDock;39DockLayoutManager fLayoutMgr;4041public static ComponentUI createUI(final JComponent c) {42return new AquaInternalFramePaneUI();43}4445public void update(final Graphics g, final JComponent c) {46if (c.isOpaque()) {47super.update(g, c);48return;49}50paint(g, c);51}5253public void installUI(final JComponent c) {54super.installUI(c);55fLayoutMgr = new DockLayoutManager();56c.setLayout(fLayoutMgr);5758c.addMouseListener(this);59}6061public void uninstallUI(final JComponent c) {62c.removeMouseListener(this);6364if (fDock != null) {65c.remove(fDock);66fDock = null;67}68if (fLayoutMgr != null) {69c.setLayout(null);70fLayoutMgr = null;71}72super.uninstallUI(c);73}7475// Our superclass hardcodes DefaultDesktopManager - how rude!76protected void installDesktopManager() {77if (desktop.getDesktopManager() == null) {78desktopManager = new AquaDockingDesktopManager();79desktop.setDesktopManager(desktopManager);80}81}8283protected void uninstallDesktopManager() {84final DesktopManager manager = desktop.getDesktopManager();85if (manager instanceof AquaDockingDesktopManager) {86desktop.setDesktopManager(null);87}88}8990JComponent getDock() {91if (fDock == null) {92fDock = new Dock(desktop);93desktop.add(fDock, new Integer(399)); // Just below the DRAG_LAYER94}95return fDock;96}9798class DockLayoutManager implements LayoutManager {99public void addLayoutComponent(final String name, final Component comp) {100}101102public void removeLayoutComponent(final Component comp) {103}104105public Dimension preferredLayoutSize(final Container parent) {106return parent.getSize();107}108109public Dimension minimumLayoutSize(final Container parent) {110return parent.getSize();111}112113public void layoutContainer(final Container parent) {114if (fDock != null) ((Dock)fDock).updateSize();115}116}117118class Dock extends JComponent implements Border {119static final int DOCK_EDGE_SLACK = 8;120121Dock(final JComponent parent) {122setBorder(this);123setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));124setVisible(false);125}126127public void removeNotify() {128fDock = null;129super.removeNotify();130}131132void updateSize() {133final Dimension d = getPreferredSize();134setBounds((getParent().getWidth() - d.width) / 2, getParent().getHeight() - d.height, d.width, d.height);135}136137public Component add(final Component c) {138super.add(c);139if (!isVisible()) {140setVisible(true);141}142143updateSize();144validate();145return c;146}147148public void remove(final Component c) {149super.remove(c);150if (getComponentCount() == 0) {151setVisible(false);152} else {153updateSize();154validate();155}156}157158public Insets getBorderInsets(final Component c) {159return new Insets(DOCK_EDGE_SLACK / 4, DOCK_EDGE_SLACK, 0, DOCK_EDGE_SLACK);160}161162public boolean isBorderOpaque() {163return false;164}165166public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {167if (!(g instanceof Graphics2D)) return;168final Graphics2D g2d = (Graphics2D)g;169170final int height = getHeight();171final int width = getWidth();172173final Object priorAA = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);174g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);175176g2d.setColor(UIManager.getColor("DesktopIcon.borderColor"));177g2d.fillRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);178179g2d.setColor(UIManager.getColor("DesktopIcon.borderRimColor"));180g2d.setStroke(new BasicStroke(2.0f));181g2d.drawRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);182183if (priorAA != null) g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, priorAA);184}185}186187class AquaDockingDesktopManager extends AquaInternalFrameManager {188public void openFrame(final JInternalFrame f) {189final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();190final Container dock = desktopIcon.getParent();191if (dock == null) return;192193if (dock.getParent() != null) dock.getParent().add(f);194removeIconFor(f);195}196197public void deiconifyFrame(final JInternalFrame f) {198final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();199final Container dock = desktopIcon.getParent();200if (dock == null) return;201202if (dock.getParent() != null) dock.getParent().add(f);203removeIconFor(f);204// <rdar://problem/3712485> removed f.show(). show() is now deprecated and205// it wasn't sending our frame to front nor selecting it. Now, we move it206// to front and select it manualy. (vm)207f.moveToFront();208try {209f.setSelected(true);210} catch(final PropertyVetoException pve) { /* do nothing */ }211}212213public void iconifyFrame(final JInternalFrame f) {214final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();215// paint the frame onto the icon before hiding the frame, else the contents won't show216((AquaInternalFrameDockIconUI)desktopIcon.getUI()).updateIcon();217super.iconifyFrame(f);218}219220void addIcon(final Container c, final JInternalFrame.JDesktopIcon desktopIcon) {221final DesktopPaneUI ui = ((JDesktopPane)c).getUI();222((AquaInternalFramePaneUI)ui).getDock().add(desktopIcon);223}224}225226public void mousePressed(final MouseEvent e) {227JInternalFrame selectedFrame = desktop.getSelectedFrame();228if (selectedFrame != null) {229try {230selectedFrame.setSelected(false);231} catch (PropertyVetoException ex) {}232desktop.getDesktopManager().deactivateFrame(selectedFrame);233}234}235236public void mouseReleased(final MouseEvent e) { }237public void mouseClicked(final MouseEvent e) { }238public void mouseEntered(final MouseEvent e) { }239public void mouseExited(final MouseEvent e) { }240}241242243