package com.apple.laf;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyVetoException;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicDesktopPaneUI;
public class AquaInternalFramePaneUI extends BasicDesktopPaneUI implements MouseListener {
JComponent fDock;
DockLayoutManager fLayoutMgr;
public static ComponentUI createUI(final JComponent c) {
return new AquaInternalFramePaneUI();
}
public void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
super.update(g, c);
return;
}
paint(g, c);
}
public void installUI(final JComponent c) {
super.installUI(c);
fLayoutMgr = new DockLayoutManager();
c.setLayout(fLayoutMgr);
c.addMouseListener(this);
}
public void uninstallUI(final JComponent c) {
c.removeMouseListener(this);
if (fDock != null) {
c.remove(fDock);
fDock = null;
}
if (fLayoutMgr != null) {
c.setLayout(null);
fLayoutMgr = null;
}
super.uninstallUI(c);
}
protected void installDesktopManager() {
if (desktop.getDesktopManager() == null) {
desktopManager = new AquaDockingDesktopManager();
desktop.setDesktopManager(desktopManager);
}
}
protected void uninstallDesktopManager() {
final DesktopManager manager = desktop.getDesktopManager();
if (manager instanceof AquaDockingDesktopManager) {
desktop.setDesktopManager(null);
}
}
JComponent getDock() {
if (fDock == null) {
fDock = new Dock(desktop);
desktop.add(fDock, Integer.valueOf(399));
}
return fDock;
}
class DockLayoutManager implements LayoutManager {
public void addLayoutComponent(final String name, final Component comp) {
}
public void removeLayoutComponent(final Component comp) {
}
public Dimension preferredLayoutSize(final Container parent) {
return parent.getSize();
}
public Dimension minimumLayoutSize(final Container parent) {
return parent.getSize();
}
public void layoutContainer(final Container parent) {
if (fDock != null) ((Dock)fDock).updateSize();
}
}
@SuppressWarnings("serial")
class Dock extends JComponent implements Border {
static final int DOCK_EDGE_SLACK = 8;
Dock(final JComponent parent) {
setBorder(this);
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
setVisible(false);
}
public void removeNotify() {
fDock = null;
super.removeNotify();
}
void updateSize() {
final Dimension d = getPreferredSize();
setBounds((getParent().getWidth() - d.width) / 2, getParent().getHeight() - d.height, d.width, d.height);
}
public Component add(final Component c) {
super.add(c);
if (!isVisible()) {
setVisible(true);
}
updateSize();
validate();
return c;
}
public void remove(final Component c) {
super.remove(c);
if (getComponentCount() == 0) {
setVisible(false);
} else {
updateSize();
validate();
}
}
public Insets getBorderInsets(final Component c) {
return new Insets(DOCK_EDGE_SLACK / 4, DOCK_EDGE_SLACK, 0, DOCK_EDGE_SLACK);
}
public boolean isBorderOpaque() {
return false;
}
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
if (!(g instanceof Graphics2D)) return;
final Graphics2D g2d = (Graphics2D)g;
final int height = getHeight();
final int width = getWidth();
final Object priorAA = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(UIManager.getColor("DesktopIcon.borderColor"));
g2d.fillRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);
g2d.setColor(UIManager.getColor("DesktopIcon.borderRimColor"));
g2d.setStroke(new BasicStroke(2.0f));
g2d.drawRoundRect(4, 4, width - 9, height + DOCK_EDGE_SLACK, DOCK_EDGE_SLACK, DOCK_EDGE_SLACK);
if (priorAA != null) g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, priorAA);
}
}
@SuppressWarnings("serial")
class AquaDockingDesktopManager extends AquaInternalFrameManager {
public void openFrame(final JInternalFrame f) {
final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
final Container dock = desktopIcon.getParent();
if (dock == null) return;
if (dock.getParent() != null) dock.getParent().add(f);
removeIconFor(f);
}
public void deiconifyFrame(final JInternalFrame f) {
final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
final Container dock = desktopIcon.getParent();
if (dock == null) return;
if (dock.getParent() != null) dock.getParent().add(f);
removeIconFor(f);
f.moveToFront();
try {
f.setSelected(true);
} catch(final PropertyVetoException pve) { }
}
public void iconifyFrame(final JInternalFrame f) {
final JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
((AquaInternalFrameDockIconUI)desktopIcon.getUI()).updateIcon();
super.iconifyFrame(f);
}
void addIcon(final Container c, final JInternalFrame.JDesktopIcon desktopIcon) {
final DesktopPaneUI ui = ((JDesktopPane)c).getUI();
((AquaInternalFramePaneUI)ui).getDock().add(desktopIcon);
}
}
public void mousePressed(final MouseEvent e) {
JInternalFrame selectedFrame = desktop.getSelectedFrame();
if (selectedFrame != null) {
try {
selectedFrame.setSelected(false);
} catch (PropertyVetoException ex) {}
desktop.getDesktopManager().deactivateFrame(selectedFrame);
}
}
public void mouseReleased(final MouseEvent e) { }
public void mouseClicked(final MouseEvent e) { }
public void mouseEntered(final MouseEvent e) { }
public void mouseExited(final MouseEvent e) { }
}