001: /*
002: * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.awt.X11;
026:
027: import java.awt.*;
028:
029: class XWarningWindow extends XWindow {
030: final static int defaultHeight = 27;
031:
032: Window ownerWindow;
033:
034: XWarningWindow(Window ownerWindow, long parentWindow) {
035: super (ownerWindow, parentWindow);
036: this .ownerWindow = ownerWindow;
037: xSetVisible(true);
038: toFront();
039: }
040:
041: protected String getWMName() {
042: return "Warning window";
043: }
044:
045: public Graphics getGraphics() {
046: if ((surfaceData == null) || (ownerWindow == null))
047: return null;
048: return getGraphics(surfaceData, getColor(), getBackground(),
049: getFont());
050: }
051:
052: void paint(Graphics g, int x, int y, int width, int height) {
053: String warningString = getWarningString();
054: Rectangle bounds = getBounds();
055: bounds.x = 0;
056: bounds.y = 0;
057: Rectangle updateRect = new Rectangle(x, y, width, height);
058: if (updateRect.intersects(bounds)) {
059: Rectangle updateArea = updateRect.intersection(bounds);
060: g.setClip(updateArea);
061: g.setColor(getBackground());
062: g.fillRect(updateArea.x, updateArea.y, updateArea.width,
063: updateArea.height);
064: g.setColor(getColor());
065: g.setFont(getFont());
066: FontMetrics fm = g.getFontMetrics();
067: int warningWidth = fm.stringWidth(warningString);
068: int w_x = (bounds.width - warningWidth) / 2;
069: int w_y = (bounds.height + fm.getMaxAscent() - fm
070: .getMaxDescent()) / 2;
071: g.drawString(warningString, w_x, w_y);
072: g.drawLine(bounds.x, bounds.y + bounds.height - 1, bounds.x
073: + bounds.width - 1, bounds.y + bounds.height - 1);
074: }
075: }
076:
077: String getWarningString() {
078: return ownerWindow.getWarningString();
079: }
080:
081: int getHeight() {
082: return defaultHeight; // should implement depending on Font
083: }
084:
085: Color getBackground() {
086: return SystemColor.window;
087: }
088:
089: Color getColor() {
090: return Color.black;
091: }
092:
093: Font getFont() {
094: return ownerWindow.getFont();
095: }
096:
097: public void repaint() {
098: Rectangle bounds = getBounds();
099: Graphics g = getGraphics();
100: try {
101: paint(g, 0, 0, bounds.width, bounds.height);
102: } finally {
103: g.dispose();
104: }
105: }
106:
107: public void handleExposeEvent(XEvent xev) {
108: super .handleExposeEvent(xev);
109:
110: XExposeEvent xe = xev.get_xexpose();
111: final int x = xe.get_x();
112: final int y = xe.get_y();
113: final int width = xe.get_width();
114: final int height = xe.get_height();
115: EventQueue.invokeLater(new Runnable() {
116: public void run() {
117: Graphics g = getGraphics();
118: try {
119: paint(g, x, y, width, height);
120: } finally {
121: g.dispose();
122: }
123: }
124: });
125: }
126:
127: protected boolean isEventDisabled(XEvent e) {
128: return true;
129: }
130: }
|