jdk/src/solaris/classes/sun/awt/X11/XWarningWindow.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 2 90ce3da70b43
child 2472 b7aba00cabb6
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
class XWarningWindow extends XWindow {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
    final static int defaultHeight = 27;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    Window ownerWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    XWarningWindow(Window ownerWindow, long parentWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
        super(ownerWindow, parentWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        this.ownerWindow = ownerWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        return "Warning window";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        if ((surfaceData == null) || (ownerWindow == null)) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        return getGraphics(surfaceData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                                 getColor(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                                 getBackground(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                                 getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    void paint(Graphics g, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        String warningString = getWarningString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        bounds.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        bounds.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        Rectangle updateRect = new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (updateRect.intersects(bounds)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            Rectangle updateArea = updateRect.intersection(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            g.setClip(updateArea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            g.fillRect(updateArea.x, updateArea.y, updateArea.width, updateArea.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            g.setColor(getColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            g.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            int warningWidth = fm.stringWidth(warningString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            int w_x = (bounds.width - warningWidth)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            int w_y = (bounds.height + fm.getMaxAscent() - fm.getMaxDescent())/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            g.drawString(warningString, w_x, w_y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            g.drawLine(bounds.x, bounds.y+bounds.height-1, bounds.x+bounds.width-1, bounds.y+bounds.height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    String getWarningString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return ownerWindow.getWarningString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return defaultHeight; // should implement depending on Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return SystemColor.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    Color getColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return Color.black;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    Font getFont () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return ownerWindow.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            paint(g, 0, 0, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void handleExposeEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        super.handleExposeEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        XExposeEvent xe = xev.get_xexpose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        final int x = xe.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        final int y = xe.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        final int width = xe.get_width();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        final int height = xe.get_height();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    paint(g, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}