jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifDesktopPaneUI.java
author darcy
Mon, 10 Mar 2014 13:54:25 -0700
changeset 23632 cd7a34d12e8c
parent 5506 202f599c92aa
permissions -rw-r--r--
8033908: Fix serial lint warnings in com.sun.java.swing.plaf Reviewed-by: serb, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class MotifDesktopPaneUI extends javax.swing.plaf.basic.BasicDesktopPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/// DesktopPaneUI methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static ComponentUI createUI(JComponent d)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return new MotifDesktopPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public MotifDesktopPaneUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected void installDesktopManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        desktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if(desktopManager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            desktopManager = new MotifDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            desktop.setDesktopManager(desktopManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            ((MotifDesktopManager)desktopManager).adjustIcons(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public Insets getInsets(JComponent c) {return new Insets(0,0,0,0);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
////////////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
///  DragPane class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
////////////////////////////////////////////////////////////////////////////////////
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
    75
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private class DragPane extends JComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            g.setColor(Color.darkGray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            g.drawRect(0, 0, getWidth()-1, getHeight()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
////////////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
///  MotifDesktopManager class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
////////////////////////////////////////////////////////////////////////////////////
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
    86
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private class MotifDesktopManager extends DefaultDesktopManager implements Serializable, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        JComponent dragPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        boolean usingDragPane = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        private transient JLayeredPane layeredPaneForDragPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        int iconWidth, iconHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // PENDING(klobad) this should be optimized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void setBoundsForFrame(JComponent f, int newX, int newY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if(!usingDragPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            boolean didResize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            didResize = (f.getWidth() != newWidth || f.getHeight() != newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            Rectangle r = f.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            f.setBounds(newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            f.getParent().repaint(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if(didResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                f.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            Rectangle r = dragPane.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            dragPane.setBounds(newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            dragPane.getParent().repaint(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void beginDraggingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        usingDragPane = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if(f.getParent() instanceof JLayeredPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if(dragPane == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                dragPane = new DragPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            layeredPaneForDragPane = (JLayeredPane)f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            layeredPaneForDragPane.setLayer(dragPane, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            dragPane.setBounds(f.getX(), f.getY(), f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            layeredPaneForDragPane.add(dragPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            usingDragPane = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public void dragFrame(JComponent f, int newX, int newY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void endDraggingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if(usingDragPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            layeredPaneForDragPane.remove(dragPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            usingDragPane = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (f instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                setBoundsForFrame(f, dragPane.getX(), dragPane.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        dragPane.getWidth(), dragPane.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            } else if (f instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                adjustBoundsForIcon((JInternalFrame.JDesktopIcon)f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        dragPane.getX(), dragPane.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public void beginResizingFrame(JComponent f, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        usingDragPane = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if(f.getParent() instanceof JLayeredPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if(dragPane == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                dragPane = new DragPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            JLayeredPane p = (JLayeredPane)f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            p.setLayer(dragPane, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            dragPane.setBounds(f.getX(), f.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            p.add(dragPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            usingDragPane = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public void resizeFrame(JComponent f, int newX, int newY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setBoundsForFrame(f, newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public void endResizingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if(usingDragPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            JLayeredPane p = (JLayeredPane)f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            p.remove(dragPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            usingDragPane = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            setBoundsForFrame(f, dragPane.getX(), dragPane.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                dragPane.getWidth(), dragPane.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        public void iconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            JInternalFrame.JDesktopIcon icon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            Point p = icon.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            adjustBoundsForIcon(icon, p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            super.iconifyFrame(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * Change positions of icons in the desktop pane so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * they do not overlap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        protected void adjustIcons(JDesktopPane desktop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // We need to know Motif icon size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            JInternalFrame.JDesktopIcon icon = new JInternalFrame.JDesktopIcon(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    new JInternalFrame());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            Dimension iconSize = icon.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            iconWidth = iconSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            iconHeight = iconSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            JInternalFrame[] frames = desktop.getAllFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            for (int i=0; i<frames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                icon = frames[i].getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                Point ip = icon.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                adjustBoundsForIcon(icon, ip.x, ip.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         * Change positions of icon so that it doesn't overlap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         * other icons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        protected void adjustBoundsForIcon(JInternalFrame.JDesktopIcon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            JDesktopPane c = icon.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            int maxy = c.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            int w = iconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            int h = iconHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            c.repaint(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            x = x < 0 ? 0 : x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            y = y < 0 ? 0 : y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            /* Fix for disappearing icons. If the y value is maxy then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             * algorithm would place the icon in a non-displayed cell.  Never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
             * to be ssen again.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            y = y >= maxy ? (maxy - 1) : y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            /* Compute the offset for the cell we are trying to go in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            int lx = (x / w) * w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            int ygap = maxy % h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            int ly = ((y-ygap) / h) * h + ygap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            /* How far are we into the cell we dropped the icon in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            int dx = x - lx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            int dy = y - ly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            /* Set coordinates for the icon. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            x = dx < w/2 ? lx: lx + w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            y = dy < h/2 ? ly: ((ly + h) < maxy ? ly + h: ly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            while (getIconAt(c, icon, x, y) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                x += w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            /* Cancel the move if the x value was moved off screen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (x > c.getWidth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (icon.getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                setBoundsForFrame(icon, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                icon.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            JInternalFrame.JDesktopIcon icon, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            JInternalFrame.JDesktopIcon currentIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            Component[] components = desktop.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            for (int i=0; i<components.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                Component comp = components[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                if (comp instanceof JInternalFrame.JDesktopIcon &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    comp != icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    Point p = comp.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    if (p.x == x && p.y == y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        return (JInternalFrame.JDesktopIcon)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }; /// END of MotifDesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}