4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage com.apple.laf;
4632N/A
4632N/Aimport java.awt.*;
4632N/Aimport java.awt.event.*;
4632N/Aimport java.beans.*;
4632N/A
4632N/Aimport javax.swing.*;
4632N/Aimport javax.swing.border.*;
4632N/Aimport javax.swing.event.MouseInputAdapter;
4632N/Aimport javax.swing.plaf.*;
4632N/Aimport javax.swing.plaf.basic.BasicInternalFrameUI;
4632N/A
4632N/Aimport apple.laf.*;
4632N/Aimport apple.laf.JRSUIConstants.*;
4632N/A
4632N/Aimport com.apple.laf.AquaUtils.*;
4632N/Aimport com.apple.laf.AquaUtils.Painter;
4632N/A
4632N/Aimport sun.lwawt.macosx.CPlatformWindow;
4632N/A
4632N/A/**
4632N/A * From AquaInternalFrameUI
4632N/A *
4632N/A * InternalFrame implementation for Aqua LAF
4632N/A *
4632N/A * We want to inherit most of the inner classes, but not the base class,
4632N/A * so be very careful about subclassing so you know you get what you want
4632N/A *
4632N/A */
4632N/Apublic class AquaInternalFrameUI extends BasicInternalFrameUI implements SwingConstants {
4632N/A protected static final String IS_PALETTE_PROPERTY = "JInternalFrame.isPalette";
4632N/A private static final String FRAME_TYPE = "JInternalFrame.frameType";
4632N/A private static final String NORMAL_FRAME = "normal";
4632N/A private static final String PALETTE_FRAME = "palette";
4632N/A private static final String OPTION_DIALOG = "optionDialog";
4632N/A
4632N/A // Instance variables
4632N/A PropertyChangeListener fPropertyListener;
4632N/A
4632N/A protected Color fSelectedTextColor;
4632N/A protected Color fNotSelectedTextColor;
4632N/A
4632N/A AquaInternalFrameBorder fAquaBorder;
4632N/A
4632N/A // for button tracking
4632N/A boolean fMouseOverPressedButton;
4632N/A int fWhichButtonPressed = -1;
4632N/A boolean fRollover = false;
4632N/A boolean fDocumentEdited = false; // to indicate whether we should use the dirty document red dot.
4632N/A boolean fIsPallet;
4632N/A
4632N/A public int getWhichButtonPressed() {
4632N/A return fWhichButtonPressed;
4632N/A }
4632N/A
4632N/A public boolean getMouseOverPressedButton() {
4632N/A return fMouseOverPressedButton;
4632N/A }
4632N/A
4632N/A public boolean getRollover() {
4632N/A return fRollover;
4632N/A }
4632N/A
4632N/A // ComponentUI Interface Implementation methods
4632N/A public static ComponentUI createUI(final JComponent b) {
4632N/A return new AquaInternalFrameUI((JInternalFrame)b);
4632N/A }
4632N/A
4632N/A public AquaInternalFrameUI(final JInternalFrame b) {
4632N/A super(b);
4632N/A }
4632N/A
4632N/A /// Inherit (but be careful to check everything they call):
4632N/A public void installUI(final JComponent c) {
4632N/A// super.installUI(c); // Swing 1.1.1 has a bug in installUI - it doesn't check for null northPane
4632N/A frame = (JInternalFrame)c;
4632N/A frame.add(frame.getRootPane(), "Center");
4632N/A
4632N/A installDefaults();
4632N/A installListeners();
4632N/A installComponents();
4632N/A installKeyboardActions();
4632N/A
4632N/A Object paletteProp = c.getClientProperty(IS_PALETTE_PROPERTY);
4632N/A if (paletteProp != null) {
4632N/A setPalette(((Boolean)paletteProp).booleanValue());
4632N/A } else {
4632N/A paletteProp = c.getClientProperty(FRAME_TYPE);
4632N/A if (paletteProp != null) {
4632N/A setFrameType((String)paletteProp);
4632N/A } else {
4632N/A setFrameType(NORMAL_FRAME);
4632N/A }
4632N/A }
4632N/A
4632N/A // We only have a southPane, for grow box room, created in setFrameType
4632N/A frame.setMinimumSize(new Dimension(fIsPallet ? 120 : 150, fIsPallet ? 39 : 65));
4632N/A frame.setOpaque(false);
4632N/A
4632N/A c.setBorder(new CompoundUIBorder(fIsPallet ? paletteWindowShadow.get() : documentWindowShadow.get(), c.getBorder()));
4632N/A }
4632N/A
4632N/A protected void installDefaults() {
4632N/A super.installDefaults();
4632N/A fSelectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
4632N/A fNotSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
4632N/A }
4632N/A
4632N/A public void setSouthPane(final JComponent c) {
4632N/A if (southPane != null) {
4632N/A frame.remove(southPane);
4632N/A deinstallMouseHandlers(southPane);
4632N/A }
4632N/A if (c != null) {
4632N/A frame.add(c);
4632N/A installMouseHandlers(c);
4632N/A }
4632N/A southPane = c;
4632N/A }
4632N/A
4632N/A static final RecyclableSingleton<Icon> closeIcon = new RecyclableSingleton<Icon>() {
4632N/A protected Icon getInstance() {
4632N/A return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_CLOSE_BOX);
4632N/A }
4632N/A };
4632N/A public static Icon exportCloseIcon() {
4632N/A return closeIcon.get();
4632N/A }
4632N/A
4632N/A static final RecyclableSingleton<Icon> minimizeIcon = new RecyclableSingleton<Icon>() {
4632N/A protected Icon getInstance() {
4632N/A return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_COLLAPSE_BOX);
4632N/A }
4632N/A };
4632N/A public static Icon exportMinimizeIcon() {
4632N/A return minimizeIcon.get();
4632N/A }
4632N/A
4632N/A static final RecyclableSingleton<Icon> zoomIcon = new RecyclableSingleton<Icon>() {
4632N/A protected Icon getInstance() {
4632N/A return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_ZOOM_BOX);
4632N/A }
4632N/A };
4632N/A public static Icon exportZoomIcon() {
4632N/A return zoomIcon.get();
4632N/A }
4632N/A
4632N/A static class AquaInternalFrameButtonIcon extends AquaIcon.JRSUIIcon {
4632N/A public AquaInternalFrameButtonIcon(final Widget widget) {
4632N/A painter.state.set(widget);
4632N/A }
4632N/A
4632N/A public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
4632N/A painter.state.set(getStateFor(c));
4632N/A super.paintIcon(c, g, x, y);
4632N/A }
4632N/A
4632N/A State getStateFor(final Component c) {
4632N/A return State.ROLLOVER;
4632N/A }
4632N/A
4632N/A public int getIconWidth() {
4632N/A return 19;
4632N/A }
4632N/A
4632N/A public int getIconHeight() {
4632N/A return 19;
4632N/A }
4632N/A }
4632N/A
4632N/A protected void installKeyboardActions() {
4632N/A } //$ Not Mac-ish - should we support?
4632N/A
4632N/A protected ResizeBox resizeBox;
4632N/A protected void installComponents() {
4632N/A final JLayeredPane layeredPane = frame.getLayeredPane();
4632N/A if (resizeBox != null) {
4632N/A resizeBox.removeListeners();
4632N/A layeredPane.removeComponentListener(resizeBox);
4632N/A layeredPane.remove(resizeBox);
4632N/A resizeBox = null;
4632N/A }
4632N/A
4632N/A resizeBox = new ResizeBox(layeredPane);
4632N/A resizeBox.repositionResizeBox();
4632N/A
4632N/A layeredPane.add(resizeBox);
4632N/A layeredPane.setLayer(resizeBox, JLayeredPane.DRAG_LAYER);
4632N/A layeredPane.addComponentListener(resizeBox);
4632N/A
4632N/A resizeBox.addListeners();
4632N/A resizeBox.setVisible(frame.isResizable());
4632N/A }
4632N/A
4632N/A /// Inherit all the listeners - that's the main reason we subclass Basic!
4632N/A protected void installListeners() {
4632N/A fPropertyListener = new PropertyListener();
4632N/A frame.addPropertyChangeListener(fPropertyListener);
4632N/A super.installListeners();
4632N/A }
4632N/A
4632N/A // uninstallDefaults
4632N/A // uninstallComponents
4632N/A protected void uninstallListeners() {
4632N/A super.uninstallListeners();
4632N/A frame.removePropertyChangeListener(fPropertyListener);
4632N/A }
4632N/A
4632N/A protected void uninstallKeyboardActions() {
4632N/A }
4632N/A
4632N/A // Called when a DesktopIcon replaces an InternalFrame & vice versa
4632N/A //protected void replacePane(JComponent currentPane, JComponent newPane) {}
4632N/A protected void installMouseHandlers(final JComponent c) {
4632N/A c.addMouseListener(borderListener);
4632N/A c.addMouseMotionListener(borderListener);
4632N/A }
4632N/A
4632N/A protected void deinstallMouseHandlers(final JComponent c) {
4632N/A c.removeMouseListener(borderListener);
4632N/A c.removeMouseMotionListener(borderListener);
4632N/A }
4632N/A
4632N/A ActionMap createActionMap() {
4632N/A final ActionMap map = new ActionMapUIResource();
4632N/A // add action for the system menu
4632N/A // Set the ActionMap's parent to the Auditory Feedback Action Map
4632N/A final AquaLookAndFeel lf = (AquaLookAndFeel)UIManager.getLookAndFeel();
4632N/A final ActionMap audioMap = lf.getAudioActionMap();
4632N/A map.setParent(audioMap);
4632N/A return map;
4632N/A }
4632N/A
4725N/A public Dimension getPreferredSize(JComponent x) {
4827N/A Dimension preferredSize = super.getPreferredSize(x);
4725N/A Dimension minimumSize = frame.getMinimumSize();
4725N/A if (preferredSize.width < minimumSize.width) {
4725N/A preferredSize.width = minimumSize.width;
4632N/A }
4725N/A if (preferredSize.height < minimumSize.height) {
4725N/A preferredSize.height = minimumSize.height;
4725N/A }
4725N/A return preferredSize;
4632N/A }
4632N/A
4632N/A public void setNorthPane(final JComponent c) {
4632N/A replacePane(northPane, c);
4632N/A northPane = c;
4632N/A }
4632N/A
4632N/A /**
4632N/A * Installs necessary mouse handlers on <code>newPane</code>
4632N/A * and adds it to the frame.
4632N/A * Reverse process for the <code>currentPane</code>.
4632N/A */
4632N/A protected void replacePane(final JComponent currentPane, final JComponent newPane) {
4632N/A if (currentPane != null) {
4632N/A deinstallMouseHandlers(currentPane);
4632N/A frame.remove(currentPane);
4632N/A }
4632N/A if (newPane != null) {
4632N/A frame.add(newPane);
4632N/A installMouseHandlers(newPane);
4632N/A }
4632N/A }
4632N/A
4632N/A // Our "Border" listener is shared by the AquaDesktopIcon
4632N/A protected MouseInputAdapter createBorderListener(final JInternalFrame w) {
4632N/A return new AquaBorderListener();
4632N/A }
4632N/A
4632N/A /**
4632N/A * Mac-specific stuff begins here
4632N/A */
4632N/A void setFrameType(final String frameType) {
4632N/A // Basic sets the background of the contentPane to null so it can inherit JInternalFrame.setBackground
4632N/A // but if *that's* null, we get the JDesktop, which makes ours look invisible!
4632N/A // So JInternalFrame has to have a background color
4632N/A // See Sun bugs 4268949 & 4320889
4632N/A final Color bg = frame.getBackground();
4632N/A final boolean replaceColor = (bg == null || bg instanceof UIResource);
4632N/A
4632N/A final Font font = frame.getFont();
4632N/A final boolean replaceFont = (font == null || font instanceof UIResource);
4632N/A
4632N/A boolean isPalette = false;
4632N/A if (frameType.equals(OPTION_DIALOG)) {
4632N/A fAquaBorder = AquaInternalFrameBorder.dialog();
4632N/A if (replaceColor) frame.setBackground(UIManager.getColor("InternalFrame.optionDialogBackground"));
4632N/A if (replaceFont) frame.setFont(UIManager.getFont("InternalFrame.optionDialogTitleFont"));
4632N/A } else if (frameType.equals(PALETTE_FRAME)) {
4632N/A fAquaBorder = AquaInternalFrameBorder.utility();
4632N/A if (replaceColor) frame.setBackground(UIManager.getColor("InternalFrame.paletteBackground"));
4632N/A if (replaceFont) frame.setFont(UIManager.getFont("InternalFrame.paletteTitleFont"));
4632N/A isPalette = true;
4632N/A } else {
4632N/A fAquaBorder = AquaInternalFrameBorder.window();
4632N/A if (replaceColor) frame.setBackground(UIManager.getColor("InternalFrame.background"));
4632N/A if (replaceFont) frame.setFont(UIManager.getFont("InternalFrame.titleFont"));
4632N/A }
4632N/A // We don't get the borders from UIManager, in case someone changes them - this class will not work with
4632N/A // different borders. If they want different ones, they have to make their own InternalFrameUI class
4632N/A
4632N/A fAquaBorder.setColors(fSelectedTextColor, fNotSelectedTextColor);
4632N/A frame.setBorder(fAquaBorder);
4632N/A
4632N/A fIsPallet = isPalette;
4632N/A }
4632N/A
4632N/A public void setPalette(final boolean isPalette) {
4632N/A setFrameType(isPalette ? PALETTE_FRAME : NORMAL_FRAME);
4632N/A }
4632N/A
4632N/A public boolean isDocumentEdited() {
4632N/A return fDocumentEdited;
4632N/A }
4632N/A
4632N/A public void setDocumentEdited(final boolean flag) {
4632N/A fDocumentEdited = flag;
4632N/A }
4632N/A
4632N/A/*
4632N/A // helpful debug drawing, shows component and content bounds
4632N/A public void paint(final Graphics g, final JComponent c) {
4632N/A super.paint(g, c);
4632N/A
4632N/A g.setColor(Color.green);
4632N/A g.drawRect(0, 0, frame.getWidth() - 1, frame.getHeight() - 1);
4632N/A
4632N/A final Insets insets = frame.getInsets();
4632N/A g.setColor(Color.orange);
4632N/A g.drawRect(insets.left - 2, insets.top - 2, frame.getWidth() - insets.left - insets.right + 4, frame.getHeight() - insets.top - insets.bottom + 4);
4632N/A }
4632N/A*/
4632N/A
4632N/A // Border Listener Class
4632N/A /**
4632N/A * Listens for border adjustments.
4632N/A */
4632N/A protected class AquaBorderListener extends MouseInputAdapter {
4632N/A // _x & _y are the mousePressed location in absolute coordinate system
4632N/A int _x, _y;
4632N/A // __x & __y are the mousePressed location in source view's coordinate system
4632N/A int __x, __y;
4632N/A Rectangle startingBounds;
4632N/A boolean fDraggingFrame;
4632N/A int resizeDir;
4632N/A
4632N/A protected final int RESIZE_NONE = 0;
4632N/A private boolean discardRelease = false;
4632N/A
4632N/A public void mouseClicked(final MouseEvent e) {
4632N/A if (didForwardEvent(e)) return;
4632N/A
4632N/A if (e.getClickCount() <= 1 || e.getSource() != getNorthPane()) return;
4632N/A
4632N/A if (frame.isIconifiable() && frame.isIcon()) {
4632N/A try {
4632N/A frame.setIcon(false);
4632N/A } catch(final PropertyVetoException e2) {}
4632N/A } else if (frame.isMaximizable()) {
4632N/A if (!frame.isMaximum()) try {
4632N/A frame.setMaximum(true);
4632N/A } catch(final PropertyVetoException e2) {}
4632N/A else try {
4632N/A frame.setMaximum(false);
4632N/A } catch(final PropertyVetoException e3) {}
4632N/A }
4632N/A }
4632N/A
4632N/A public void updateRollover(final MouseEvent e) {
4632N/A final boolean oldRollover = fRollover;
4632N/A final Insets i = frame.getInsets();
4632N/A fRollover = (isTitleBarDraggableArea(e) && fAquaBorder.getWithinRolloverArea(i, e.getX(), e.getY()));
4632N/A if (fRollover != oldRollover) {
4632N/A repaintButtons();
4632N/A }
4632N/A }
4632N/A
4632N/A public void repaintButtons() {
4632N/A fAquaBorder.repaintButtonArea(frame);
4632N/A }
4632N/A
4632N/A public void mouseReleased(final MouseEvent e) {
4632N/A if (didForwardEvent(e)) return;
4632N/A
4632N/A fDraggingFrame = false;
4632N/A
4632N/A if (fWhichButtonPressed != -1) {
4632N/A final int newButton = fAquaBorder.getWhichButtonHit(frame, e.getX(), e.getY());
4632N/A
4632N/A final int buttonPresed = fWhichButtonPressed;
4632N/A fWhichButtonPressed = -1;
4632N/A fMouseOverPressedButton = false;
4632N/A
4632N/A if (buttonPresed == newButton) {
4632N/A fMouseOverPressedButton = false;
4632N/A fRollover = false; // not sure if this is needed?
4632N/A
4632N/A fAquaBorder.doButtonAction(frame, buttonPresed);
4632N/A }
4632N/A
4632N/A updateRollover(e);
4632N/A repaintButtons();
4632N/A return;
4632N/A }
4632N/A
4632N/A if (discardRelease) {
4632N/A discardRelease = false;
4632N/A return;
4632N/A }
4632N/A if (resizeDir == RESIZE_NONE) getDesktopManager().endDraggingFrame(frame);
4632N/A else {
4632N/A final Container c = frame.getTopLevelAncestor();
4632N/A if (c instanceof JFrame) {
4632N/A ((JFrame)frame.getTopLevelAncestor()).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4632N/A
4632N/A ((JFrame)frame.getTopLevelAncestor()).getGlassPane().setVisible(false);
4632N/A } else if (c instanceof JApplet) {
4632N/A ((JApplet)c).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4632N/A ((JApplet)c).getGlassPane().setVisible(false);
4632N/A } else if (c instanceof JWindow) {
4632N/A ((JWindow)c).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4632N/A ((JWindow)c).getGlassPane().setVisible(false);
4632N/A } else if (c instanceof JDialog) {
4632N/A ((JDialog)c).getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
4632N/A ((JDialog)c).getGlassPane().setVisible(false);
4632N/A }
4632N/A getDesktopManager().endResizingFrame(frame);
4632N/A }
4632N/A _x = 0;
4632N/A _y = 0;
4632N/A __x = 0;
4632N/A __y = 0;
4632N/A startingBounds = null;
4632N/A resizeDir = RESIZE_NONE;
4632N/A }
4632N/A
4632N/A public void mousePressed(final MouseEvent e) {
4632N/A if (didForwardEvent(e)) return;
4632N/A
4632N/A final Point p = SwingUtilities.convertPoint((Component)e.getSource(), e.getX(), e.getY(), null);
4632N/A __x = e.getX();
4632N/A __y = e.getY();
4632N/A _x = p.x;
4632N/A _y = p.y;
4632N/A startingBounds = frame.getBounds();
4632N/A resizeDir = RESIZE_NONE;
4632N/A
4632N/A if (updatePressed(e)) { return; }
4632N/A
4632N/A if (!frame.isSelected()) {
4632N/A try {
4632N/A frame.setSelected(true);
4632N/A } catch(final PropertyVetoException e1) {}
4632N/A }
4632N/A
4632N/A if (isTitleBarDraggableArea(e)) {
4632N/A getDesktopManager().beginDraggingFrame(frame);
4632N/A fDraggingFrame = true;
4632N/A return;
4632N/A }
4632N/A
4632N/A if (e.getSource() == getNorthPane()) {
4632N/A getDesktopManager().beginDraggingFrame(frame);
4632N/A return;
4632N/A }
4632N/A
4632N/A if (!frame.isResizable()) { return; }
4632N/A
4632N/A if (e.getSource() == frame) {
4632N/A discardRelease = true;
4632N/A return;
4632N/A }
4632N/A }
4632N/A
4632N/A // returns true if we have handled the pressed
4632N/A public boolean updatePressed(final MouseEvent e) {
4632N/A // get the component.
4632N/A fWhichButtonPressed = getButtonHit(e);
4632N/A fMouseOverPressedButton = true;
4632N/A repaintButtons();
4632N/A return (fWhichButtonPressed >= 0);
4632N/A // e.getX(), e.getY()
4632N/A }
4632N/A
4632N/A public int getButtonHit(final MouseEvent e) {
4632N/A return fAquaBorder.getWhichButtonHit(frame, e.getX(), e.getY());
4632N/A }
4632N/A
4632N/A public boolean isTitleBarDraggableArea(final MouseEvent e) {
4632N/A if (e.getSource() != frame) return false;
4632N/A
4632N/A final Point point = e.getPoint();
4632N/A final Insets insets = frame.getInsets();
4632N/A
4632N/A if (point.y < insets.top - fAquaBorder.getTitleHeight()) return false;
4632N/A if (point.y > insets.top) return false;
4632N/A if (point.x < insets.left) return false;
4632N/A if (point.x > frame.getWidth() - insets.left - insets.right) return false;
4632N/A
4632N/A return true;
4632N/A }
4632N/A
4632N/A public void mouseDragged(final MouseEvent e) {
4632N/A// do not forward drags
4632N/A// if (didForwardEvent(e)) return;
4632N/A
4632N/A if (startingBounds == null) {
4632N/A // (STEVE) Yucky work around for bug ID 4106552
4632N/A return;
4632N/A }
4632N/A
4632N/A if (fWhichButtonPressed != -1) {
4632N/A // track the button we started on.
4632N/A final int newButton = getButtonHit(e);
4632N/A fMouseOverPressedButton = (fWhichButtonPressed == newButton);
4632N/A repaintButtons();
4632N/A return;
4632N/A }
4632N/A
4632N/A final Point p = SwingUtilities.convertPoint((Component)e.getSource(), e.getX(), e.getY(), null);
4632N/A final int deltaX = _x - p.x;
4632N/A final int deltaY = _y - p.y;
4632N/A int newX, newY;
4632N/A
4632N/A // Handle a MOVE
4632N/A if (!fDraggingFrame && e.getSource() != getNorthPane()) return;
4632N/A
4632N/A if (frame.isMaximum() || ((e.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK)) {
4632N/A // don't allow moving of frames if maximixed or left mouse
4632N/A // button was not used.
4632N/A return;
4632N/A }
4632N/A
4632N/A final Dimension s = frame.getParent().getSize();
4632N/A final int pWidth = s.width;
4632N/A final int pHeight = s.height;
4632N/A
4632N/A final Insets i = frame.getInsets();
4632N/A newX = startingBounds.x - deltaX;
4632N/A newY = startingBounds.y - deltaY;
4632N/A
4632N/A // Make sure we stay in-bounds
4632N/A if (newX + i.left <= -__x) newX = -__x - i.left;
4632N/A if (newY + i.top <= -__y) newY = -__y - i.top;
4632N/A if (newX + __x + i.right > pWidth) newX = pWidth - __x - i.right;
4632N/A if (newY + __y + i.bottom > pHeight) newY = pHeight - __y - i.bottom;
4632N/A
4632N/A getDesktopManager().dragFrame(frame, newX, newY);
4632N/A return;
4632N/A }
4632N/A
4632N/A public void mouseMoved(final MouseEvent e) {
4632N/A if (didForwardEvent(e)) return;
4632N/A updateRollover(e);
4632N/A }
4632N/A
4632N/A // guards against accidental infinite recursion
4632N/A boolean isTryingToForwardEvent = false;
4632N/A boolean didForwardEvent(final MouseEvent e) {
4632N/A if (isTryingToForwardEvent) return true; // we didn't actually...but we wound up back where we started.
4632N/A
4632N/A isTryingToForwardEvent = true;
4632N/A final boolean didForwardEvent = didForwardEventInternal(e);
4632N/A isTryingToForwardEvent = false;
4632N/A
4632N/A return didForwardEvent;
4632N/A }
4632N/A
4632N/A boolean didForwardEventInternal(final MouseEvent e) {
4632N/A if (fDraggingFrame) return false;
4632N/A
4632N/A final Point originalPoint = e.getPoint();
4632N/A if (!isEventInWindowShadow(originalPoint)) return false;
4632N/A
4632N/A final Container parent = frame.getParent();
4632N/A if (!(parent instanceof JDesktopPane)) return false;
4632N/A final JDesktopPane pane = (JDesktopPane)parent;
4632N/A final Point parentPoint = SwingUtilities.convertPoint(frame, originalPoint, parent);
4632N/A
4632N/A /* // debug drawing
4632N/A Graphics g = parent.getGraphics();
4632N/A g.setColor(Color.red);
4632N/A g.drawLine(parentPoint.x, parentPoint.y, parentPoint.x, parentPoint.y);
4632N/A */
4632N/A
4632N/A final Component hitComponent = findComponentToHitBehindMe(pane, parentPoint);
4632N/A if (hitComponent == null || hitComponent == frame) return false;
4632N/A
4632N/A final Point hitComponentPoint = SwingUtilities.convertPoint(pane, parentPoint, hitComponent);
4632N/A hitComponent.dispatchEvent(new MouseEvent(hitComponent, e.getID(), e.getWhen(), e.getModifiers(), hitComponentPoint.x, hitComponentPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getButton()));
4632N/A return true;
4632N/A }
4632N/A
4632N/A Component findComponentToHitBehindMe(final JDesktopPane pane, final Point parentPoint) {
4632N/A final JInternalFrame[] allFrames = pane.getAllFrames();
4632N/A
4632N/A boolean foundSelf = false;
4632N/A for (final JInternalFrame f : allFrames) {
4632N/A if (f == frame) { foundSelf = true; continue; }
4632N/A if (!foundSelf) continue;
4632N/A
4632N/A final Rectangle bounds = f.getBounds();
4632N/A if (bounds.contains(parentPoint)) return f;
4632N/A }
4632N/A
4632N/A return pane;
4632N/A }
4632N/A
4632N/A boolean isEventInWindowShadow(final Point point) {
4632N/A final Rectangle bounds = frame.getBounds();
4632N/A final Insets insets = frame.getInsets();
4632N/A insets.top -= fAquaBorder.getTitleHeight();
4632N/A
4632N/A if (point.x < insets.left) return true;
4632N/A if (point.x > bounds.width - insets.right) return true;
4632N/A if (point.y < insets.top) return true;
4632N/A if (point.y > bounds.height - insets.bottom) return true;
4632N/A
4632N/A return false;
4632N/A }
4632N/A }
4632N/A
4632N/A static void updateComponentTreeUIActivation(final Component c, final Object active) {
4632N/A if (c instanceof javax.swing.JComponent) {
4632N/A ((javax.swing.JComponent)c).putClientProperty(AquaFocusHandler.FRAME_ACTIVE_PROPERTY, active);
4632N/A }
4632N/A
4632N/A Component[] children = null;
4632N/A
4632N/A if (c instanceof javax.swing.JMenu) {
4632N/A children = ((javax.swing.JMenu)c).getMenuComponents();
4632N/A } else if (c instanceof Container) {
4632N/A children = ((Container)c).getComponents();
4632N/A }
4632N/A
4632N/A if (children != null) {
4632N/A for (final Component element : children) {
4632N/A updateComponentTreeUIActivation(element, active);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A class PropertyListener implements PropertyChangeListener {
4632N/A public void propertyChange(final PropertyChangeEvent e) {
4632N/A final String name = e.getPropertyName();
4632N/A if (FRAME_TYPE.equals(name)) {
4632N/A if (e.getNewValue() instanceof String) {
4632N/A setFrameType((String)e.getNewValue());
4632N/A }
4632N/A } else if (IS_PALETTE_PROPERTY.equals(name)) {
4632N/A if (e.getNewValue() != null) {
4632N/A setPalette(((Boolean)e.getNewValue()).booleanValue());
4632N/A } else {
4632N/A setPalette(false);
4632N/A }
4632N/A // TODO: CPlatformWindow?
4632N/A } else if ("windowModified".equals(name) || CPlatformWindow.WINDOW_DOCUMENT_MODIFIED.equals(name)) {
4632N/A // repaint title bar
4632N/A setDocumentEdited(((Boolean)e.getNewValue()).booleanValue());
4632N/A frame.repaint(0, 0, frame.getWidth(), frame.getBorder().getBorderInsets(frame).top);
4632N/A } else if ("resizable".equals(name) || "state".equals(name) || "iconable".equals(name) || "maximizable".equals(name) || "closable".equals(name)) {
4632N/A if ("resizable".equals(name)) {
4632N/A frame.revalidate();
4632N/A }
4632N/A frame.repaint();
4632N/A } else if ("title".equals(name)) {
4632N/A frame.repaint();
4632N/A } else if ("componentOrientation".equals(name)) {
4632N/A frame.revalidate();
4632N/A frame.repaint();
4632N/A } else if (JInternalFrame.IS_SELECTED_PROPERTY.equals(name)) {
4632N/A final Component source = (Component)(e.getSource());
4632N/A updateComponentTreeUIActivation(source, frame.isSelected() ? Boolean.TRUE : Boolean.FALSE);
4632N/A }
4632N/A
4632N/A }
4632N/A } // end class PaletteListener
4632N/A
4632N/A static final InternalFrameShadow documentWindowShadow = new InternalFrameShadow() {
4632N/A Border getForegroundShadowBorder() {
4632N/A return new AquaUtils.SlicedShadowBorder(new Painter() {
4632N/A public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
4632N/A g.setColor(new Color(0, 0, 0, 196));
4632N/A g.fillRoundRect(x, y, w, h, 16, 16);
4632N/A g.fillRect(x, y + h - 16, w, 16);
4632N/A }
4632N/A }, new Painter() {
4632N/A public void paint(final Graphics g, int x, int y, int w, int h) {
4632N/A g.setColor(new Color(0, 0, 0, 64));
4632N/A g.drawLine(x + 2, y - 8, x + w - 2, y - 8);
4632N/A }
4632N/A },
4632N/A 0, 7, 1.1f, 1.0f, 24, 51, 51, 25, 25, 25, 25);
4632N/A }
4632N/A
4632N/A Border getBackgroundShadowBorder() {
4632N/A return new AquaUtils.SlicedShadowBorder(new Painter() {
4632N/A public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
4632N/A g.setColor(new Color(0, 0, 0, 128));
4632N/A g.fillRoundRect(x - 3, y - 8, w + 6, h, 16, 16);
4632N/A g.fillRect(x - 3, y + h - 20, w + 6, 19);
4632N/A }
4632N/A }, new Painter() {
4632N/A public void paint(final Graphics g, int x, int y, int w, int h) {
4632N/A g.setColor(new Color(0, 0, 0, 32));
4632N/A g.drawLine(x, y - 11, x + w - 1, y - 11);
4632N/A }
4632N/A },
4632N/A 0, 0, 3.0f, 1.0f, 10, 51, 51, 25, 25, 25, 25);
4632N/A }
4632N/A };
4632N/A
4632N/A static final InternalFrameShadow paletteWindowShadow = new InternalFrameShadow() {
4632N/A Border getForegroundShadowBorder() {
4632N/A return new AquaUtils.SlicedShadowBorder(new Painter() {
4632N/A public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
4632N/A g.setColor(new Color(0, 0, 0, 128));
4632N/A g.fillRect(x, y + 3, w, h - 3);
4632N/A }
4632N/A }, null,
4632N/A 0, 3, 1.0f, 1.0f, 10, 25, 25, 12, 12, 12, 12);
4632N/A }
4632N/A
4632N/A Border getBackgroundShadowBorder() {
4632N/A return getForegroundShadowBorder();
4632N/A }
4632N/A };
4632N/A
4632N/A static class CompoundUIBorder extends CompoundBorder implements UIResource {
4632N/A public CompoundUIBorder(final Border inside, final Border outside) { super(inside, outside); }
4632N/A }
4632N/A
4632N/A abstract static class InternalFrameShadow extends RecyclableSingleton<Border> {
4632N/A abstract Border getForegroundShadowBorder();
4632N/A abstract Border getBackgroundShadowBorder();
4632N/A
4632N/A protected Border getInstance() {
4632N/A final Border fgShadow = getForegroundShadowBorder();
4632N/A final Border bgShadow = getBackgroundShadowBorder();
4632N/A
4632N/A return new Border() {
4632N/A public Insets getBorderInsets(final Component c) {
4632N/A return fgShadow.getBorderInsets(c);
4632N/A }
4632N/A
4632N/A public boolean isBorderOpaque() {
4632N/A return false;
4632N/A }
4632N/A
4632N/A public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
4632N/A if (((JInternalFrame)c).isSelected()) {
4632N/A fgShadow.paintBorder(c, g, x, y, w, h);
4632N/A } else {
4632N/A bgShadow.paintBorder(c, g, x, y, w, h);
4632N/A }
4632N/A }
4632N/A };
4632N/A }
4632N/A }
4632N/A
4632N/A static final RecyclableSingleton<Icon> RESIZE_ICON = new RecyclableSingleton<Icon>() {
4632N/A protected Icon getInstance() {
4632N/A return new AquaIcon.CachableJRSUIIcon(11, 11) {
4632N/A public void initIconPainter(final AquaPainter<JRSUIState> iconState) {
4632N/A iconState.state.set(Widget.GROW_BOX_TEXTURED);
4632N/A iconState.state.set(WindowType.UTILITY);
4632N/A }
4632N/A };
4632N/A }
4632N/A };
4632N/A
4632N/A class ResizeBox extends JLabel implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener, PropertyChangeListener, UIResource {
4632N/A final JLayeredPane layeredPane;
4632N/A Dimension originalSize;
4632N/A Point originalLocation;
4632N/A
4632N/A public ResizeBox(final JLayeredPane layeredPane) {
4632N/A super(RESIZE_ICON.get());
4632N/A setSize(11, 11);
4632N/A this.layeredPane = layeredPane;
4632N/A
4632N/A addMouseListener(this);
4632N/A addMouseMotionListener(this);
4632N/A addMouseWheelListener(this);
4632N/A }
4632N/A
4632N/A void addListeners() {
4632N/A frame.addPropertyChangeListener("resizable", this);
4632N/A }
4632N/A
4632N/A void removeListeners() {
4632N/A frame.removePropertyChangeListener("resizable", this);
4632N/A }
4632N/A
4632N/A void repositionResizeBox() {
4632N/A if (frame == null) { setSize(0, 0); } else { setSize(11, 11); }
4632N/A setLocation(layeredPane.getWidth() - 12, layeredPane.getHeight() - 12);
4632N/A }
4632N/A
4632N/A void resizeInternalFrame(final Point pt) {
4632N/A if (originalLocation == null || frame == null) return;
4632N/A
4632N/A final Container parent = frame.getParent();
4632N/A if (!(parent instanceof JDesktopPane)) return;
4632N/A
4632N/A final Point newPoint = SwingUtilities.convertPoint(this, pt, frame);
4632N/A int deltaX = originalLocation.x - newPoint.x;
4632N/A int deltaY = originalLocation.y - newPoint.y;
4632N/A final Dimension min = frame.getMinimumSize();
4632N/A final Dimension max = frame.getMaximumSize();
4632N/A
4632N/A final int newX = frame.getX();
4632N/A final int newY = frame.getY();
4632N/A int newW = frame.getWidth();
4632N/A int newH = frame.getHeight();
4632N/A
4632N/A final Rectangle parentBounds = parent.getBounds();
4632N/A
4632N/A if (originalSize.width - deltaX < min.width) {
4632N/A deltaX = originalSize.width - min.width;
4632N/A } else if (originalSize.width - deltaX > max.width) {
4632N/A deltaX = -(max.width - originalSize.width);
4632N/A }
4632N/A
4632N/A if (newX + originalSize.width - deltaX > parentBounds.width) {
4632N/A deltaX = newX + originalSize.width - parentBounds.width;
4632N/A }
4632N/A
4632N/A if (originalSize.height - deltaY < min.height) {
4632N/A deltaY = originalSize.height - min.height;
4632N/A } else if (originalSize.height - deltaY > max.height) {
4632N/A deltaY = -(max.height - originalSize.height);
4632N/A }
4632N/A
4632N/A if (newY + originalSize.height - deltaY > parentBounds.height) {
4632N/A deltaY = newY + originalSize.height - parentBounds.height;
4632N/A }
4632N/A
4632N/A newW = originalSize.width - deltaX;
4632N/A newH = originalSize.height - deltaY;
4632N/A
4632N/A getDesktopManager().resizeFrame(frame, newX, newY, newW, newH);
4632N/A }
4632N/A
4632N/A boolean testGrowboxPoint(final int x, final int y, final int w, final int h) {
4632N/A return (w - x) + (h - y) < 12;
4632N/A }
4632N/A
4632N/A void forwardEventToFrame(final MouseEvent e) {
4632N/A final Point pt = new Point();
4632N/A final Component c = getComponentToForwardTo(e, pt);
4632N/A if (c == null) return;
4632N/A c.dispatchEvent(new MouseEvent(c, e.getID(), e.getWhen(), e.getModifiers(), pt.x, pt.y, e.getClickCount(), e.isPopupTrigger(), e.getButton()));
4632N/A }
4632N/A
4632N/A Component getComponentToForwardTo(final MouseEvent e, final Point dst) {
4632N/A if (frame == null) return null;
4632N/A final Container contentPane = frame.getContentPane();
4632N/A if (contentPane == null) return null;
4632N/A Point pt = SwingUtilities.convertPoint(this, e.getPoint(), contentPane);
4632N/A final Component c = SwingUtilities.getDeepestComponentAt(contentPane, pt.x, pt.y);
4632N/A if (c == null) return null;
4632N/A pt = SwingUtilities.convertPoint(contentPane, pt, c);
4632N/A if (dst != null) dst.setLocation(pt);
4632N/A return c;
4632N/A }
4632N/A
4632N/A public void mouseClicked(final MouseEvent e) {
4632N/A forwardEventToFrame(e);
4632N/A }
4632N/A
4632N/A public void mouseEntered(final MouseEvent e) { }
4632N/A
4632N/A public void mouseExited(final MouseEvent e) { }
4632N/A
4632N/A public void mousePressed(final MouseEvent e) {
4632N/A if (frame == null) return;
4632N/A
4632N/A if (frame.isResizable() && !frame.isMaximum() && testGrowboxPoint(e.getX(), e.getY(), getWidth(), getHeight())) {
4632N/A originalLocation = SwingUtilities.convertPoint(this, e.getPoint(), frame);
4632N/A originalSize = frame.getSize();
4632N/A getDesktopManager().beginResizingFrame(frame, SwingConstants.SOUTH_EAST);
4632N/A return;
4632N/A }
4632N/A
4632N/A forwardEventToFrame(e);
4632N/A }
4632N/A
4632N/A public void mouseReleased(final MouseEvent e) {
4632N/A if (originalLocation != null) {
4632N/A resizeInternalFrame(e.getPoint());
4632N/A originalLocation = null;
4632N/A getDesktopManager().endResizingFrame(frame);
4632N/A return;
4632N/A }
4632N/A
4632N/A forwardEventToFrame(e);
4632N/A }
4632N/A
4632N/A public void mouseDragged(final MouseEvent e) {
4632N/A resizeInternalFrame(e.getPoint());
4632N/A repositionResizeBox();
4632N/A }
4632N/A
4632N/A public void mouseMoved(final MouseEvent e) { }
4632N/A
4632N/A public void mouseWheelMoved(final MouseWheelEvent e) {
4632N/A final Point pt = new Point();
4632N/A final Component c = getComponentToForwardTo(e, pt);
4632N/A if (c == null) return;
4632N/A c.dispatchEvent(new MouseWheelEvent(c, e.getID(), e.getWhen(), e.getModifiers(), pt.x, pt.y, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation()));
4632N/A }
4632N/A
4632N/A public void componentResized(final ComponentEvent e) {
4632N/A repositionResizeBox();
4632N/A }
4632N/A
4632N/A public void componentShown(final ComponentEvent e) {
4632N/A repositionResizeBox();
4632N/A }
4632N/A
4632N/A public void componentMoved(final ComponentEvent e) {
4632N/A repositionResizeBox();
4632N/A }
4632N/A
4632N/A public void componentHidden(final ComponentEvent e) { }
4632N/A
4632N/A public void propertyChange(final PropertyChangeEvent evt) {
4632N/A if (!"resizable".equals(evt.getPropertyName())) return;
4632N/A setVisible(Boolean.TRUE.equals(evt.getNewValue()));
4632N/A }
4632N/A }
4632N/A}