Path: blob/master/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFramePaneUI.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.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, Integer.valueOf(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}117118@SuppressWarnings("serial") // Superclass is not serializable across versions119class Dock extends JComponent implements Border {120static final int DOCK_EDGE_SLACK = 8;121122Dock(final JComponent parent) {123setBorder(this);124setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));125setVisible(false);126}127128public void removeNotify() {129fDock = null;130super.removeNotify();131}132133void updateSize() {134final Dimension d = getPreferredSize();135setBounds((getParent().getWidth() - d.width) / 2, getParent().getHeight() - d.height, d.width, d.height);136}137138public Component add(final Component c) {139super.add(c);140if (!isVisible()) {141setVisible(true);142}143144updateSize();145validate();146return c;147}148149public void remove(final Component c) {150super.remove(c);151if (getComponentCount() == 0) {152setVisible(false);153} else {154updateSize();155validate();156}157}158159public Insets getBorderInsets(final Component c) {160return new Insets(DOCK_EDGE_SLACK / 4, DOCK_EDGE_SLACK, 0, DOCK_EDGE_SLACK);161}162163public boolean isBorderOpaque() {164return false;165}166167public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {168if (!(g instanceof Graphics2D)) return;169final Graphics2D g2d = (Graphics2D)g;170171final int height = getHeight();172final int width = getWidth();173174final Object priorAA = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);175g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);176177g2d.setColor(UIManager.getColor("DesktopIcon.borderColor"));178g2d.fillRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);179180g2d.setColor(UIManager.getColor("DesktopIcon.borderRimColor"));181g2d.setStroke(new BasicStroke(2.0f));182g2d.drawRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);183184if (priorAA != null) g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, priorAA);185}186}187188@SuppressWarnings("serial") // JDK implementation class189class AquaDockingDesktopManager extends AquaInternalFrameManager {190public void openFrame(final JInternalFrame f) {191final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();192final Container dock = desktopIcon.getParent();193if (dock == null) return;194195if (dock.getParent() != null) dock.getParent().add(f);196removeIconFor(f);197}198199public void deiconifyFrame(final JInternalFrame f) {200final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();201final Container dock = desktopIcon.getParent();202if (dock == null) return;203204if (dock.getParent() != null) dock.getParent().add(f);205removeIconFor(f);206// <rdar://problem/3712485> removed f.show(). show() is now deprecated and207// it wasn't sending our frame to front nor selecting it. Now, we move it208// to front and select it manualy. (vm)209f.moveToFront();210try {211f.setSelected(true);212} catch(final PropertyVetoException pve) { /* do nothing */ }213}214215public void iconifyFrame(final JInternalFrame f) {216final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();217// paint the frame onto the icon before hiding the frame, else the contents won't show218((AquaInternalFrameDockIconUI)desktopIcon.getUI()).updateIcon();219super.iconifyFrame(f);220}221222void addIcon(final Container c, final JInternalFrame.JDesktopIcon desktopIcon) {223final DesktopPaneUI ui = ((JDesktopPane)c).getUI();224((AquaInternalFramePaneUI)ui).getDock().add(desktopIcon);225}226}227228public void mousePressed(final MouseEvent e) {229JInternalFrame selectedFrame = desktop.getSelectedFrame();230if (selectedFrame != null) {231try {232selectedFrame.setSelected(false);233} catch (PropertyVetoException ex) {}234desktop.getDesktopManager().deactivateFrame(selectedFrame);235}236}237238public void mouseReleased(final MouseEvent e) { }239public void mouseClicked(final MouseEvent e) { }240public void mouseEntered(final MouseEvent e) { }241public void mouseExited(final MouseEvent e) { }242}243244245