2
|
1 |
/*
|
|
2 |
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package sun.awt.X11;
|
|
26 |
|
|
27 |
import java.awt.*;
|
|
28 |
|
|
29 |
class XWarningWindow extends XWindow {
|
|
30 |
final static int defaultHeight = 27;
|
|
31 |
|
|
32 |
Window ownerWindow;
|
|
33 |
XWarningWindow(Window ownerWindow, long parentWindow) {
|
|
34 |
super(ownerWindow, parentWindow);
|
|
35 |
this.ownerWindow = ownerWindow;
|
|
36 |
xSetVisible(true);
|
|
37 |
toFront();
|
|
38 |
}
|
|
39 |
|
|
40 |
protected String getWMName() {
|
|
41 |
return "Warning window";
|
|
42 |
}
|
|
43 |
|
|
44 |
public Graphics getGraphics() {
|
|
45 |
if ((surfaceData == null) || (ownerWindow == null)) return null;
|
|
46 |
return getGraphics(surfaceData,
|
|
47 |
getColor(),
|
|
48 |
getBackground(),
|
|
49 |
getFont());
|
|
50 |
}
|
|
51 |
void paint(Graphics g, int x, int y, int width, int height) {
|
|
52 |
String warningString = getWarningString();
|
|
53 |
Rectangle bounds = getBounds();
|
|
54 |
bounds.x = 0;
|
|
55 |
bounds.y = 0;
|
|
56 |
Rectangle updateRect = new Rectangle(x, y, width, height);
|
|
57 |
if (updateRect.intersects(bounds)) {
|
|
58 |
Rectangle updateArea = updateRect.intersection(bounds);
|
|
59 |
g.setClip(updateArea);
|
|
60 |
g.setColor(getBackground());
|
|
61 |
g.fillRect(updateArea.x, updateArea.y, updateArea.width, updateArea.height);
|
|
62 |
g.setColor(getColor());
|
|
63 |
g.setFont(getFont());
|
|
64 |
FontMetrics fm = g.getFontMetrics();
|
|
65 |
int warningWidth = fm.stringWidth(warningString);
|
|
66 |
int w_x = (bounds.width - warningWidth)/2;
|
|
67 |
int w_y = (bounds.height + fm.getMaxAscent() - fm.getMaxDescent())/2;
|
|
68 |
g.drawString(warningString, w_x, w_y);
|
|
69 |
g.drawLine(bounds.x, bounds.y+bounds.height-1, bounds.x+bounds.width-1, bounds.y+bounds.height-1);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
String getWarningString() {
|
|
74 |
return ownerWindow.getWarningString();
|
|
75 |
}
|
|
76 |
|
|
77 |
int getHeight() {
|
|
78 |
return defaultHeight; // should implement depending on Font
|
|
79 |
}
|
|
80 |
|
|
81 |
Color getBackground() {
|
|
82 |
return SystemColor.window;
|
|
83 |
}
|
|
84 |
Color getColor() {
|
|
85 |
return Color.black;
|
|
86 |
}
|
|
87 |
Font getFont () {
|
|
88 |
return ownerWindow.getFont();
|
|
89 |
}
|
|
90 |
public void repaint() {
|
|
91 |
Rectangle bounds = getBounds();
|
|
92 |
Graphics g = getGraphics();
|
|
93 |
try {
|
|
94 |
paint(g, 0, 0, bounds.width, bounds.height);
|
|
95 |
} finally {
|
|
96 |
g.dispose();
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
public void handleExposeEvent(XEvent xev) {
|
|
101 |
super.handleExposeEvent(xev);
|
|
102 |
|
|
103 |
XExposeEvent xe = xev.get_xexpose();
|
|
104 |
final int x = xe.get_x();
|
|
105 |
final int y = xe.get_y();
|
|
106 |
final int width = xe.get_width();
|
|
107 |
final int height = xe.get_height();
|
|
108 |
EventQueue.invokeLater(new Runnable() {
|
|
109 |
public void run() {
|
|
110 |
Graphics g = getGraphics();
|
|
111 |
try {
|
|
112 |
paint(g, x, y, width, height);
|
|
113 |
} finally {
|
|
114 |
g.dispose();
|
|
115 |
}
|
|
116 |
}
|
|
117 |
});
|
|
118 |
}
|
|
119 |
protected boolean isEventDisabled(XEvent e) {
|
|
120 |
return true;
|
|
121 |
}
|
|
122 |
}
|