1 /* 2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package sun.awt.X11; 26 27 import java.awt.AWTEvent; 28 import java.awt.AWTException; 29 import java.awt.BufferCapabilities; 30 import java.awt.Color; 31 import java.awt.Component; 32 import java.awt.Container; 33 import java.awt.Cursor; 34 import java.awt.Dimension; 35 import java.awt.Font; 36 import java.awt.FontMetrics; 37 import java.awt.Graphics; 38 import java.awt.GraphicsConfiguration; 39 import java.awt.Image; 40 import java.awt.Insets; 41 import java.awt.KeyboardFocusManager; 42 import java.awt.Rectangle; 43 import java.awt.SystemColor; 44 import java.awt.Toolkit; 45 import java.awt.Window; 46 import java.awt.dnd.DropTarget; 47 import java.awt.dnd.peer.DropTargetPeer; 48 import java.awt.event.FocusEvent; 49 import java.awt.event.InputEvent; 50 import java.awt.event.InputMethodEvent; 51 import java.awt.event.KeyEvent; 52 import java.awt.event.MouseEvent; 53 import java.awt.event.MouseWheelEvent; 54 import java.awt.event.PaintEvent; 55 import java.awt.event.WindowEvent; 56 import java.awt.event.InvocationEvent; 57 import java.awt.image.ImageObserver; 58 import java.awt.image.ImageProducer; 59 import java.awt.image.VolatileImage; 60 import java.awt.peer.ComponentPeer; 61 import java.awt.peer.ContainerPeer; 62 import java.awt.peer.LightweightPeer; 63 import java.lang.reflect.*; 64 import java.security.*; 65 import java.util.Collection; 66 import java.util.HashSet; 67 import java.util.Set; 68 import java.util.Vector; 69 import sun.util.logging.PlatformLogger; 70 71 import sun.awt.*; 72 import sun.awt.event.IgnorePaintEvent; 73 import sun.awt.image.SunVolatileImage; 74 import sun.awt.image.ToolkitImage; 75 import sun.java2d.BackBufferCapsProvider; 76 import sun.java2d.pipe.Region; 77 78 public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer, 79 BackBufferCapsProvider 80 { 81 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer"); 82 private static final PlatformLogger buffersLog = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer.multibuffer"); 83 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XComponentPeer"); 84 private static final PlatformLogger fontLog = PlatformLogger.getLogger("sun.awt.X11.font.XComponentPeer"); 85 private static final PlatformLogger enableLog = PlatformLogger.getLogger("sun.awt.X11.enable.XComponentPeer"); 86 private static final PlatformLogger shapeLog = PlatformLogger.getLogger("sun.awt.X11.shape.XComponentPeer"); 87 88 boolean paintPending = false; 89 boolean isLayouting = false; 90 boolean enabled; 91 92 // Actually used only by XDecoratedPeer 93 protected int boundsOperation; 94 95 Color foreground; 96 Color background; 97 98 // Colors calculated as on Motif using MotifColorUtilties. 99 // If you use these, call updateMotifColors() in the peer's Constructor and 100 // setBackground(). Examples are XCheckboxPeer and XButtonPeer. 101 Color darkShadow; 102 Color lightShadow; 103 Color selectColor; 104 105 Font font; 106 private long backBuffer = 0; 107 private VolatileImage xBackBuffer = null; 108 109 static Color[] systemColors; 110 111 XComponentPeer() { 112 } 113 114 XComponentPeer (XCreateWindowParams params) { 115 super(params); 116 } 117 118 XComponentPeer(Component target, long parentWindow, Rectangle bounds) { 119 super(target, parentWindow, bounds); 120 } 121 122 /** 123 * Standard peer constructor, with corresponding Component 124 */ 125 XComponentPeer(Component target) { 126 super(target); 127 } 128 129 130 void preInit(XCreateWindowParams params) { 131 super.preInit(params); 132 boundsOperation = DEFAULT_OPERATION; 133 } 134 void postInit(XCreateWindowParams params) { 135 super.postInit(params); 136 Color c; 137 Font f; 138 Cursor cursor; 139 140 pSetCursor(target.getCursor()); 141 142 foreground = target.getForeground(); 143 background = target.getBackground(); 144 font = target.getFont(); 145 146 if (isInitialReshape()) { 147 Rectangle r = target.getBounds(); 148 reshape(r.x, r.y, r.width, r.height); 149 } 150 151 enabled = target.isEnabled(); 152 153 // If any of our heavyweight ancestors are disable, we should be too 154 // See 6176875 for more information 155 Component comp = target; 156 while( !(comp == null || comp instanceof Window) ) { 157 comp = comp.getParent(); 158 if( comp != null && !comp.isEnabled() && !comp.isLightweight() ){ 159 setEnabled(false); 160 break; 161 } 162 } 163 enableLog.fine("Initial enable state: {0}", Boolean.valueOf(enabled)); 164 165 if (target.isVisible()) { 166 setVisible(true); 167 } 168 } 169 170 protected boolean isInitialReshape() { 171 return true; 172 } 173 174 public void reparent(ContainerPeer newNativeParent) { 175 XComponentPeer newPeer = (XComponentPeer)newNativeParent; 176 XToolkit.awtLock(); 177 try { 178 XlibWrapper.XReparentWindow(XToolkit.getDisplay(), getWindow(), newPeer.getContentWindow(), x, y); 179 parentWindow = newPeer; 180 } finally { 181 XToolkit.awtUnlock(); 182 } 183 } 184 public boolean isReparentSupported() { 185 return System.getProperty("sun.awt.X11.XComponentPeer.reparentNotSupported", "false").equals("false"); 186 } 187 188 public boolean isObscured() { 189 Container container = (target instanceof Container) ? 190 (Container)target : target.getParent(); 191 192 if (container == null) { 193 return true; 194 } 195 196 Container parent; 197 while ((parent = container.getParent()) != null) { 198 container = parent; 199 } 200 201 if (container instanceof Window) { 202 XWindowPeer wpeer = (XWindowPeer)(container.getPeer()); 203 if (wpeer != null) { 204 return (wpeer.winAttr.visibilityState != 205 wpeer.winAttr.AWT_UNOBSCURED); 206 } 207 } 208 return true; 209 } 210 211 public boolean canDetermineObscurity() { 212 return true; 213 } 214 215 /************************************************* 216 * FOCUS STUFF 217 *************************************************/ 218 219 /** 220 * Keeps the track of focused state of the _NATIVE_ window 221 */ 222 boolean bHasFocus = false; 223 224 /** 225 * Descendants should use this method to determine whether or not native window 226 * has focus. 227 */ 228 final public boolean hasFocus() { 229 return bHasFocus; 230 } 231 232 /** 233 * Called when component receives focus 234 */ 235 public void focusGained(FocusEvent e) { 236 focusLog.fine("{0}", e); 237 bHasFocus = true; 238 } 239 240 /** 241 * Called when component loses focus 242 */ 243 public void focusLost(FocusEvent e) { 244 focusLog.fine("{0}", e); 245 bHasFocus = false; 246 } 247 248 public boolean isFocusable() { 249 /* should be implemented by other sub-classes */ 250 return false; 251 } 252 253 private static Class seClass; 254 private static Constructor seCtor; 255 256 final static AWTEvent wrapInSequenced(AWTEvent event) { 257 try { 258 if (seClass == null) { 259 seClass = Class.forName("java.awt.SequencedEvent"); 260 } 261 262 if (seCtor == null) { 263 seCtor = (Constructor) AccessController.doPrivileged(new PrivilegedExceptionAction() { 264 public Object run() throws Exception { 265 Constructor ctor = seClass.getConstructor(new Class[] { AWTEvent.class }); 266 ctor.setAccessible(true); 267 return ctor; 268 } 269 }); 270 } 271 272 return (AWTEvent) seCtor.newInstance(new Object[] { event }); 273 } 274 catch (ClassNotFoundException e) { 275 throw new NoClassDefFoundError("java.awt.SequencedEvent."); 276 } 277 catch (PrivilegedActionException ex) { 278 throw new NoClassDefFoundError("java.awt.SequencedEvent."); 279 } 280 catch (InstantiationException e) { 281 assert false; 282 } 283 catch (IllegalAccessException e) { 284 assert false; 285 } 286 catch (InvocationTargetException e) { 287 assert false; 288 } 289 290 return null; 291 } 292 293 // TODO: consider moving it to KeyboardFocusManagerPeerImpl 294 final public boolean requestFocus(Component lightweightChild, boolean temporary, 295 boolean focusedWindowChangeAllowed, long time, 296 CausedFocusEvent.Cause cause) 297 { 298 if (XKeyboardFocusManagerPeer. 299 processSynchronousLightweightTransfer(target, lightweightChild, temporary, 300 focusedWindowChangeAllowed, time)) 301 { 302 return true; 303 } 304 305 int result = XKeyboardFocusManagerPeer. 306 shouldNativelyFocusHeavyweight(target, lightweightChild, 307 temporary, focusedWindowChangeAllowed, 308 time, cause); 309 310 switch (result) { 311 case XKeyboardFocusManagerPeer.SNFH_FAILURE: 312 return false; 313 case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED: 314 // Currently we just generate focus events like we deal with lightweight instead of calling 315 // XSetInputFocus on native window 316 if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Proceeding with request to " + 317 lightweightChild + " in " + target); 318 /** 319 * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight 320 * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet 321 * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record 322 * in requests list - and it breaks our requests sequence as first record on WGF should be the last 323 * focus owner which had focus before WLF. So, we should not add request record for such requests 324 * but store this component in mostRecent - and return true as before for compatibility. 325 */ 326 Window parentWindow = SunToolkit.getContainingWindow(target); 327 if (parentWindow == null) { 328 return rejectFocusRequestHelper("WARNING: Parent window is null"); 329 } 330 XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer(); 331 if (wpeer == null) { 332 return rejectFocusRequestHelper("WARNING: Parent window's peer is null"); 333 } 334 /* 335 * Passing null 'actualFocusedWindow' as we don't want to restore focus on it 336 * when a component inside a Frame is requesting focus. 337 * See 6314575 for details. 338 */ 339 boolean res = wpeer.requestWindowFocus(null); 340 341 if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Requested window focus: " + res); 342 // If parent window can be made focused and has been made focused(synchronously) 343 // then we can proceed with children, otherwise we retreat. 344 if (!(res && parentWindow.isFocused())) { 345 return rejectFocusRequestHelper("Waiting for asynchronous processing of the request"); 346 } 347 return XKeyboardFocusManagerPeer.deliverFocus(lightweightChild, 348 (Component)target, 349 temporary, 350 focusedWindowChangeAllowed, 351 time, cause); 352 // Motif compatibility code 353 case XKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED: 354 // Either lightweight or excessive request - all events are generated. 355 return true; 356 } 357 return false; 358 } 359 360 private boolean rejectFocusRequestHelper(String logMsg) { 361 if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(logMsg); 362 XKeyboardFocusManagerPeer.removeLastFocusRequest(target); 363 return false; 364 } 365 366 void handleJavaFocusEvent(AWTEvent e) { 367 if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(e.toString()); 368 if (e.getID() == FocusEvent.FOCUS_GAINED) { 369 focusGained((FocusEvent)e); 370 } else { 371 focusLost((FocusEvent)e); 372 } 373 } 374 375 void handleJavaWindowFocusEvent(AWTEvent e) { 376 } 377 378 /************************************************* 379 * END OF FOCUS STUFF 380 *************************************************/ 381 382 383 384 public void setVisible(boolean b) { 385 xSetVisible(b); 386 } 387 388 public void hide() { 389 setVisible(false); 390 } 391 392 393 /** 394 * @see java.awt.peer.ComponentPeer 395 */ 396 public void setEnabled(boolean value) { 397 enableLog.fine("{0}ing {1}", (value?"Enabl":"Disabl"), this); 398 boolean repaintNeeded = (enabled != value); 399 enabled = value; 400 if (target instanceof Container) { 401 Component list[] = ((Container)target).getComponents(); 402 for (int i = 0; i < list.length; ++i) { 403 boolean childEnabled = list[i].isEnabled(); 404 ComponentPeer p = list[i].getPeer(); 405 if ( p != null ) { 406 p.setEnabled(value && childEnabled); 407 } 408 } 409 } 410 if (repaintNeeded) { 411 repaint(); 412 } 413 } 414 415 // 416 // public so aw/Window can call it 417 // 418 public boolean isEnabled() { 419 return enabled; 420 } 421 422 423 424 public void enable() { 425 setEnabled(true); 426 } 427 428 public void disable() { 429 setEnabled(false); 430 } 431 432 public void paint(Graphics g) { 433 } 434 public void repaint(long tm, int x, int y, int width, int height) { 435 repaint(); 436 } 437 438 439 public Graphics getGraphics() { 440 return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont()); 441 } 442 443 444 445 public void print(Graphics g) { 446 // clear rect here to emulate X clears rect before Expose 447 g.setColor(target.getBackground()); 448 g.fillRect(0, 0, target.getWidth(), target.getHeight()); 449 g.setColor(target.getForeground()); 450 // paint peer 451 paint(g); 452 // allow target to change the picture 453 target.print(g); 454 } 455 456 public void setBounds(int x, int y, int width, int height, int op) { 457 this.x = x; 458 this.y = y; 459 this.width = width; 460 this.height = height; 461 xSetBounds(x,y,width,height); 462 validateSurface(); 463 layout(); 464 } 465 466 public void reshape(int x, int y, int width, int height) { 467 setBounds(x, y, width, height, SET_BOUNDS); 468 } 469 470 public void coalescePaintEvent(PaintEvent e) { 471 Rectangle r = e.getUpdateRect(); 472 if (!(e instanceof IgnorePaintEvent)) { 473 paintArea.add(r, e.getID()); 474 } 475 if (true) { 476 switch(e.getID()) { 477 case PaintEvent.UPDATE: 478 log.finer("XCP coalescePaintEvent : UPDATE : add : x = " + 479 r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); 480 return; 481 case PaintEvent.PAINT: 482 log.finer("XCP coalescePaintEvent : PAINT : add : x = " + 483 r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); 484 return; 485 } 486 } 487 } 488 489 XWindowPeer getParentTopLevel() { 490 AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); 491 Container parent = (target instanceof Container) ? ((Container)target) : (compAccessor.getParent(target)); 492 // Search for parent window 493 while (parent != null && !(parent instanceof Window)) { 494 parent = compAccessor.getParent(parent); 495 } 496 if (parent != null) { 497 return (XWindowPeer)compAccessor.getPeer(parent); 498 } else { 499 return null; 500 } 501 } 502 503 /* This method is intended to be over-ridden by peers to perform user interaction */ 504 void handleJavaMouseEvent(MouseEvent e) { 505 switch (e.getID()) { 506 case MouseEvent.MOUSE_PRESSED: 507 if (target == e.getSource() && 508 !target.isFocusOwner() && 509 XKeyboardFocusManagerPeer.shouldFocusOnClick(target)) 510 { 511 XWindowPeer parentXWindow = getParentTopLevel(); 512 Window parentWindow = ((Window)parentXWindow.getTarget()); 513 // Simple windows are non-focusable in X terms but focusable in Java terms. 514 // As X-non-focusable they don't receive any focus events - we should generate them 515 // by ourselfves. 516 // if (parentXWindow.isFocusableWindow() /*&& parentXWindow.isSimpleWindow()*/ && 517 // !(getCurrentNativeFocusedWindow() == parentWindow)) 518 // { 519 // setCurrentNativeFocusedWindow(parentWindow); 520 // WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS); 521 // parentWindow.dispatchEvent(wfg); 522 // } 523 XKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT); 524 } 525 break; 526 } 527 } 528 529 /* This method is intended to be over-ridden by peers to perform user interaction */ 530 void handleJavaKeyEvent(KeyEvent e) { 531 } 532 533 /* This method is intended to be over-ridden by peers to perform user interaction */ 534 void handleJavaMouseWheelEvent(MouseWheelEvent e) { 535 } 536 537 538 /* This method is intended to be over-ridden by peers to perform user interaction */ 539 void handleJavaInputMethodEvent(InputMethodEvent e) { 540 } 541 542 void handleF10JavaKeyEvent(KeyEvent e) { 543 if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_F10) { 544 XWindowPeer winPeer = this.getToplevelXWindow(); 545 if (winPeer instanceof XFramePeer) { 546 XMenuBarPeer mPeer = ((XFramePeer)winPeer).getMenubarPeer(); 547 if (mPeer != null) { 548 mPeer.handleF10KeyPress(e); 549 } 550 } 551 } 552 } 553 554 public void handleEvent(java.awt.AWTEvent e) { 555 if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() && target.isEnabled()) { 556 if (e instanceof MouseEvent) { 557 if (e instanceof MouseWheelEvent) { 558 handleJavaMouseWheelEvent((MouseWheelEvent) e); 559 } 560 else 561 handleJavaMouseEvent((MouseEvent) e); 562 } 563 else if (e instanceof KeyEvent) { 564 handleF10JavaKeyEvent((KeyEvent)e); 565 handleJavaKeyEvent((KeyEvent)e); 566 } 567 } 568 else if (e instanceof KeyEvent && !((InputEvent)e).isConsumed()) { 569 // even if target is disabled. 570 handleF10JavaKeyEvent((KeyEvent)e); 571 } 572 else if (e instanceof InputMethodEvent) { 573 handleJavaInputMethodEvent((InputMethodEvent) e); 574 } 575 576 int id = e.getID(); 577 578 switch(id) { 579 case PaintEvent.PAINT: 580 // Got native painting 581 paintPending = false; 582 // Fallthrough to next statement 583 case PaintEvent.UPDATE: 584 // Skip all painting while layouting and all UPDATEs 585 // while waiting for native paint 586 if (!isLayouting && !paintPending) { 587 paintArea.paint(target,false); 588 } 589 return; 590 case FocusEvent.FOCUS_LOST: 591 case FocusEvent.FOCUS_GAINED: 592 handleJavaFocusEvent(e); 593 break; 594 case WindowEvent.WINDOW_LOST_FOCUS: 595 case WindowEvent.WINDOW_GAINED_FOCUS: 596 handleJavaWindowFocusEvent(e); 597 break; 598 default: 599 break; 600 } 601 602 } 603 604 public void handleButtonPressRelease(XEvent xev) { 605 /* 606 * Fix for 6385277. 607 * We request focus on simple Window by click in order 608 * to make it behave like Frame/Dialog in this case and also to unify 609 * the behaviour with what we have on MS Windows. 610 * handleJavaMouseEvent() would be more suitable place to do this 611 * but we want Swing to have this functionality also. 612 */ 613 if (xev.get_type() == XConstants.ButtonPress) { 614 final XWindowPeer parentXWindow = getParentTopLevel(); 615 Window parentWindow = (Window)parentXWindow.getTarget(); 616 if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() && 617 XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow) 618 { 619 postEvent(new InvocationEvent(parentWindow, new Runnable() { 620 public void run() { 621 // Request focus on the EDT of 'parentWindow' because 622 // XDecoratedPeer.requestWindowFocus() calls client code. 623 parentXWindow.requestXFocus(); 624 } 625 })); 626 } 627 } 628 super.handleButtonPressRelease(xev); 629 } 630 631 public Dimension getMinimumSize() { 632 return target.getSize(); 633 } 634 635 public Dimension getPreferredSize() { 636 return getMinimumSize(); 637 } 638 639 public void layout() {} 640 641 public java.awt.Toolkit getToolkit() { 642 return Toolkit.getDefaultToolkit(); 643 } 644 645 void updateMotifColors(Color bg) { 646 int red = bg.getRed(); 647 int green = bg.getGreen(); 648 int blue = bg.getBlue(); 649 650 darkShadow = new Color(MotifColorUtilities.calculateBottomShadowFromBackground(red,green,blue)); 651 lightShadow = new Color(MotifColorUtilities.calculateTopShadowFromBackground(red,green,blue)); 652 selectColor= new Color(MotifColorUtilities.calculateSelectFromBackground(red,green,blue)); 653 } 654 655 /* 656 * Draw a 3D rectangle using the Motif colors. 657 * "Normal" rectangles have shadows on the bottom. 658 * "Depressed" rectangles (such as pressed buttons) have shadows on the top, 659 * in which case true should be passed for topShadow. 660 */ 661 public void drawMotif3DRect(Graphics g, 662 int x, int y, int width, int height, 663 boolean topShadow) { 664 g.setColor(topShadow ? darkShadow : lightShadow); 665 g.drawLine(x, y, x+width, y); // top 666 g.drawLine(x, y+height, x, y); // left 667 668 g.setColor(topShadow ? lightShadow : darkShadow ); 669 g.drawLine(x+1, y+height, x+width, y+height); // bottom 670 g.drawLine(x+width, y+height, x+width, y+1); // right 671 } 672 673 public void setBackground(Color c) { 674 if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set background to " + c); 675 synchronized (getStateLock()) { 676 background = c; 677 } 678 super.setBackground(c); 679 repaint(); 680 } 681 682 public void setForeground(Color c) { 683 if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set foreground to " + c); 684 synchronized (getStateLock()) { 685 foreground = c; 686 } 687 repaint(); 688 } 689 690 /** 691 * Gets the font metrics for the specified font. 692 * @param font the font for which font metrics is to be 693 * obtained 694 * @return the font metrics for <code>font</code> 695 * @see #getFont 696 * @see #getPeer 697 * @see java.awt.peer.ComponentPeer#getFontMetrics(Font) 698 * @see Toolkit#getFontMetrics(Font) 699 * @since JDK1.0 700 */ 701 public FontMetrics getFontMetrics(Font font) { 702 if (fontLog.isLoggable(PlatformLogger.FINE)) fontLog.fine("Getting font metrics for " + font); 703 return sun.font.FontDesignMetrics.getMetrics(font); 704 } 705 706 public void setFont(Font f) { 707 synchronized (getStateLock()) { 708 if (f == null) { 709 f = XWindow.getDefaultFont(); 710 } 711 font = f; 712 } 713 // as it stands currently we dont need to do layout or repaint since 714 // layout is done in the Component upon setFont. 715 //layout(); 716 // target.repaint(); 717 //repaint()? 718 } 719 720 public Font getFont() { 721 return font; 722 } 723 724 public void updateCursorImmediately() { 725 XGlobalCursorManager.getCursorManager().updateCursorImmediately(); 726 } 727 728 public final void pSetCursor(Cursor cursor) { 729 this.pSetCursor(cursor, true); 730 } 731 732 /* 733 * The method changes the cursor. 734 * @param cursor - a new cursor to change to. 735 * @param ignoreSubComponents - if {@code true} is passed then 736 * the new cursor will be installed on window. 737 * if {@code false} is passed then 738 * subsequent components will try to handle 739 * this request and install their cursor. 740 */ 741 //ignoreSubComponents not used here 742 public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) { 743 XToolkit.awtLock(); 744 try { 745 long xcursor = XGlobalCursorManager.getCursor(cursor); 746 747 XSetWindowAttributes xwa = new XSetWindowAttributes(); 748 xwa.set_cursor(xcursor); 749 750 long valuemask = XConstants.CWCursor; 751 752 XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),getWindow(),valuemask,xwa.pData); 753 XlibWrapper.XFlush(XToolkit.getDisplay()); 754 xwa.dispose(); 755 } finally { 756 XToolkit.awtUnlock(); 757 } 758 } 759 760 public Image createImage(ImageProducer producer) { 761 return new ToolkitImage(producer); 762 } 763 764 public Image createImage(int width, int height) { 765 return graphicsConfig.createAcceleratedImage(target, width, height); 766 } 767 768 public VolatileImage createVolatileImage(int width, int height) { 769 return new SunVolatileImage(target, width, height); 770 } 771 772 public boolean prepareImage(Image img, int w, int h, ImageObserver o) { 773 return getToolkit().prepareImage(img, w, h, o); 774 } 775 776 public int checkImage(Image img, int w, int h, ImageObserver o) { 777 return getToolkit().checkImage(img, w, h, o); 778 } 779 780 public Dimension preferredSize() { 781 return getPreferredSize(); 782 } 783 784 public Dimension minimumSize() { 785 return getMinimumSize(); 786 } 787 788 public Insets getInsets() { 789 return new Insets(0, 0, 0, 0); 790 } 791 792 public void beginValidate() { 793 } 794 795 public void endValidate() { 796 } 797 798 799 /** 800 * DEPRECATED: Replaced by getInsets(). 801 */ 802 803 public Insets insets() { 804 return getInsets(); 805 } 806 807 // Returns true if we are inside begin/endLayout and 808 // are waiting for native painting 809 public boolean isPaintPending() { 810 return paintPending && isLayouting; 811 } 812 813 public boolean handlesWheelScrolling() { 814 return false; 815 } 816 817 public void beginLayout() { 818 // Skip all painting till endLayout 819 isLayouting = true; 820 821 } 822 823 public void endLayout() { 824 if (!paintPending && !paintArea.isEmpty() 825 && !AWTAccessor.getComponentAccessor().getIgnoreRepaint(target)) 826 { 827 // if not waiting for native painting repaint damaged area 828 postEvent(new PaintEvent(target, PaintEvent.PAINT, 829 new Rectangle())); 830 } 831 isLayouting = false; 832 } 833 834 public Color getWinBackground() { 835 return getPeerBackground(); 836 } 837 838 static int[] getRGBvals(Color c) { 839 840 int rgbvals[] = new int[3]; 841 842 rgbvals[0] = c.getRed(); 843 rgbvals[1] = c.getGreen(); 844 rgbvals[2] = c.getBlue(); 845 846 return rgbvals; 847 } 848 849 static final int BACKGROUND_COLOR = 0; 850 static final int HIGHLIGHT_COLOR = 1; 851 static final int SHADOW_COLOR = 2; 852 static final int FOREGROUND_COLOR = 3; 853 854 public Color[] getGUIcolors() { 855 Color c[] = new Color[4]; 856 float backb, highb, shadowb, hue, saturation; 857 c[BACKGROUND_COLOR] = getWinBackground(); 858 if (c[BACKGROUND_COLOR] == null) { 859 c[BACKGROUND_COLOR] = super.getWinBackground(); 860 } 861 if (c[BACKGROUND_COLOR] == null) { 862 c[BACKGROUND_COLOR] = Color.lightGray; 863 } 864 865 int[] rgb = getRGBvals(c[BACKGROUND_COLOR]); 866 867 float[] hsb = Color.RGBtoHSB(rgb[0],rgb[1],rgb[2],null); 868 869 hue = hsb[0]; 870 saturation = hsb[1]; 871 backb = hsb[2]; 872 873 874 /* Calculate Highlight Brightness */ 875 876 highb = backb + 0.2f; 877 shadowb = backb - 0.4f; 878 if ((highb > 1.0) ) { 879 if ((1.0 - backb) < 0.05) { 880 highb = shadowb + 0.25f; 881 } else { 882 highb = 1.0f; 883 } 884 } else { 885 if (shadowb < 0.0) { 886 if ((backb - 0.0) < 0.25) { 887 highb = backb + 0.75f; 888 shadowb = highb - 0.2f; 889 } else { 890 shadowb = 0.0f; 891 } 892 } 893 } 894 c[HIGHLIGHT_COLOR] = Color.getHSBColor(hue,saturation,highb); 895 c[SHADOW_COLOR] = Color.getHSBColor(hue,saturation,shadowb); 896 897 898 /* 899 c[SHADOW_COLOR] = c[BACKGROUND_COLOR].darker(); 900 int r2 = c[SHADOW_COLOR].getRed(); 901 int g2 = c[SHADOW_COLOR].getGreen(); 902 int b2 = c[SHADOW_COLOR].getBlue(); 903 */ 904 905 c[FOREGROUND_COLOR] = getPeerForeground(); 906 if (c[FOREGROUND_COLOR] == null) { 907 c[FOREGROUND_COLOR] = Color.black; 908 } 909 /* 910 if ((c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR])) 911 && (c[BACKGROUND_COLOR].equals(c[SHADOW_COLOR]))) { 912 c[SHADOW_COLOR] = new Color(c[BACKGROUND_COLOR].getRed() + 75, 913 c[BACKGROUND_COLOR].getGreen() + 75, 914 c[BACKGROUND_COLOR].getBlue() + 75); 915 c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR].brighter(); 916 } else if (c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR])) { 917 c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR]; 918 c[SHADOW_COLOR] = c[SHADOW_COLOR].darker(); 919 } 920 */ 921 if (! isEnabled()) { 922 c[BACKGROUND_COLOR] = c[BACKGROUND_COLOR].darker(); 923 // Reduce the contrast 924 // Calculate the NTSC gray (NB: REC709 L* might be better!) 925 // for foreground and background; then multiply the foreground 926 // by the average lightness 927 928 929 Color tc = c[BACKGROUND_COLOR]; 930 int bg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11; 931 932 tc = c[FOREGROUND_COLOR]; 933 int fg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11; 934 935 float ave = (float) ((fg + bg) / 51000.0); 936 // 255 * 100 * 2 937 938 Color newForeground = new Color((int) (tc.getRed() * ave), 939 (int) (tc.getGreen() * ave), 940 (int) (tc.getBlue() * ave)); 941 942 if (newForeground.equals(c[FOREGROUND_COLOR])) { 943 // This probably means the foreground color is black or white 944 newForeground = new Color(ave, ave, ave); 945 } 946 c[FOREGROUND_COLOR] = newForeground; 947 948 } 949 950 951 return c; 952 } 953 954 /** 955 * Returns an array of Colors similar to getGUIcolors(), but using the 956 * System colors. This is useful if pieces of a Component (such as 957 * the integrated scrollbars of a List) should retain the System color 958 * instead of the background color set by Component.setBackground(). 959 */ 960 static Color[] getSystemColors() { 961 if (systemColors == null) { 962 systemColors = new Color[4]; 963 systemColors[BACKGROUND_COLOR] = SystemColor.window; 964 systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight; 965 systemColors[SHADOW_COLOR] = SystemColor.controlShadow; 966 systemColors[FOREGROUND_COLOR] = SystemColor.windowText; 967 } 968 return systemColors; 969 } 970 971 /** 972 * Draw a 3D oval. 973 */ 974 public void draw3DOval(Graphics g, Color colors[], 975 int x, int y, int w, int h, boolean raised) 976 { 977 Color c = g.getColor(); 978 g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); 979 g.drawArc(x, y, w, h, 45, 180); 980 g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); 981 g.drawArc(x, y, w, h, 225, 180); 982 g.setColor(c); 983 } 984 985 public void draw3DRect(Graphics g, Color colors[], 986 int x, int y, int width, int height, boolean raised) 987 { 988 Color c = g.getColor(); 989 g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); 990 g.drawLine(x, y, x, y + height); 991 g.drawLine(x + 1, y, x + width - 1, y); 992 g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); 993 g.drawLine(x + 1, y + height, x + width, y + height); 994 g.drawLine(x + width, y, x + width, y + height - 1); 995 g.setColor(c); 996 } 997 998 /* 999 * drawXXX() methods are used to print the native components by 1000 * rendering the Motif look ourselves. 1001 * ToDo(aim): needs to query native motif for more accurate color 1002 * information. 1003 */ 1004 void draw3DOval(Graphics g, Color bg, 1005 int x, int y, int w, int h, boolean raised) 1006 { 1007 Color c = g.getColor(); 1008 Color shadow = bg.darker(); 1009 Color highlight = bg.brighter(); 1010 1011 g.setColor(raised ? highlight : shadow); 1012 g.drawArc(x, y, w, h, 45, 180); 1013 g.setColor(raised ? shadow : highlight); 1014 g.drawArc(x, y, w, h, 225, 180); 1015 g.setColor(c); 1016 } 1017 1018 void draw3DRect(Graphics g, Color bg, 1019 int x, int y, int width, int height, 1020 boolean raised) { 1021 Color c = g.getColor(); 1022 Color shadow = bg.darker(); 1023 Color highlight = bg.brighter(); 1024 1025 g.setColor(raised ? highlight : shadow); 1026 g.drawLine(x, y, x, y + height); 1027 g.drawLine(x + 1, y, x + width - 1, y); 1028 g.setColor(raised ? shadow : highlight); 1029 g.drawLine(x + 1, y + height, x + width, y + height); 1030 g.drawLine(x + width, y, x + width, y + height - 1); 1031 g.setColor(c); 1032 } 1033 1034 void drawScrollbar(Graphics g, Color bg, int thickness, int length, 1035 int min, int max, int val, int vis, boolean horizontal) { 1036 Color c = g.getColor(); 1037 double f = (double)(length - 2*(thickness-1)) / Math.max(1, ((max - min) + vis)); 1038 int v1 = thickness + (int)(f * (val - min)); 1039 int v2 = (int)(f * vis); 1040 int w2 = thickness-4; 1041 int tpts_x[] = new int[3]; 1042 int tpts_y[] = new int[3]; 1043 1044 if (length < 3*w2 ) { 1045 v1 = v2 = 0; 1046 if (length < 2*w2 + 2) { 1047 w2 = (length-2)/2; 1048 } 1049 } else if (v2 < 7) { 1050 // enforce a minimum handle size 1051 v1 = Math.max(0, v1 - ((7 - v2)>>1)); 1052 v2 = 7; 1053 } 1054 1055 int ctr = thickness/2; 1056 int sbmin = ctr - w2/2; 1057 int sbmax = ctr + w2/2; 1058 1059 // paint the background slightly darker 1060 { 1061 Color d = new Color((int) (bg.getRed() * 0.85), 1062 (int) (bg.getGreen() * 0.85), 1063 (int) (bg.getBlue() * 0.85)); 1064 1065 g.setColor(d); 1066 if (horizontal) { 1067 g.fillRect(0, 0, length, thickness); 1068 } else { 1069 g.fillRect(0, 0, thickness, length); 1070 } 1071 } 1072 1073 // paint the thumb and arrows in the normal background color 1074 g.setColor(bg); 1075 if (v1 > 0) { 1076 if (horizontal) { 1077 g.fillRect(v1, 3, v2, thickness-3); 1078 } else { 1079 g.fillRect(3, v1, thickness-3, v2); 1080 } 1081 } 1082 1083 tpts_x[0] = ctr; tpts_y[0] = 2; 1084 tpts_x[1] = sbmin; tpts_y[1] = w2; 1085 tpts_x[2] = sbmax; tpts_y[2] = w2; 1086 if (horizontal) { 1087 g.fillPolygon(tpts_y, tpts_x, 3); 1088 } else { 1089 g.fillPolygon(tpts_x, tpts_y, 3); 1090 } 1091 1092 tpts_y[0] = length-2; 1093 tpts_y[1] = length-w2; 1094 tpts_y[2] = length-w2; 1095 if (horizontal) { 1096 g.fillPolygon(tpts_y, tpts_x, 3); 1097 } else { 1098 g.fillPolygon(tpts_x, tpts_y, 3); 1099 } 1100 1101 Color highlight = bg.brighter(); 1102 1103 // // // // draw the "highlighted" edges 1104 g.setColor(highlight); 1105 1106 // outline & arrows 1107 if (horizontal) { 1108 g.drawLine(1, thickness, length - 1, thickness); 1109 g.drawLine(length - 1, 1, length - 1, thickness); 1110 1111 // arrows 1112 g.drawLine(1, ctr, w2, sbmin); 1113 g.drawLine(length - w2, sbmin, length - w2, sbmax); 1114 g.drawLine(length - w2, sbmin, length - 2, ctr); 1115 1116 } else { 1117 g.drawLine(thickness, 1, thickness, length - 1); 1118 g.drawLine(1, length - 1, thickness, length - 1); 1119 1120 // arrows 1121 g.drawLine(ctr, 1, sbmin, w2); 1122 g.drawLine(sbmin, length - w2, sbmax, length - w2); 1123 g.drawLine(sbmin, length - w2, ctr, length - 2); 1124 } 1125 1126 // thumb 1127 if (v1 > 0) { 1128 if (horizontal) { 1129 g.drawLine(v1, 2, v1 + v2, 2); 1130 g.drawLine(v1, 2, v1, thickness-3); 1131 } else { 1132 g.drawLine(2, v1, 2, v1 + v2); 1133 g.drawLine(2, v1, thickness-3, v1); 1134 } 1135 } 1136 1137 Color shadow = bg.darker(); 1138 1139 // // // // draw the "shadowed" edges 1140 g.setColor(shadow); 1141 1142 // outline && arrows 1143 if (horizontal) { 1144 g.drawLine(0, 0, 0, thickness); 1145 g.drawLine(0, 0, length - 1, 0); 1146 1147 // arrows 1148 g.drawLine(w2, sbmin, w2, sbmax); 1149 g.drawLine(w2, sbmax, 1, ctr); 1150 g.drawLine(length-2, ctr, length-w2, sbmax); 1151 1152 } else { 1153 g.drawLine(0, 0, thickness, 0); 1154 g.drawLine(0, 0, 0, length - 1); 1155 1156 // arrows 1157 g.drawLine(sbmin, w2, sbmax, w2); 1158 g.drawLine(sbmax, w2, ctr, 1); 1159 g.drawLine(ctr, length-2, sbmax, length-w2); 1160 } 1161 1162 // thumb 1163 if (v1 > 0) { 1164 if (horizontal) { 1165 g.drawLine(v1 + v2, 2, v1 + v2, thickness-2); 1166 g.drawLine(v1, thickness-2, v1 + v2, thickness-2); 1167 } else { 1168 g.drawLine(2, v1 + v2, thickness-2, v1 + v2); 1169 g.drawLine(thickness-2, v1, thickness-2, v1 + v2); 1170 } 1171 } 1172 g.setColor(c); 1173 } 1174 1175 /** 1176 * The following multibuffering-related methods delegate to our 1177 * associated GraphicsConfig (X11 or GLX) to handle the appropriate 1178 * native windowing system specific actions. 1179 */ 1180 1181 private BufferCapabilities backBufferCaps; 1182 1183 public void createBuffers(int numBuffers, BufferCapabilities caps) 1184 throws AWTException 1185 { 1186 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1187 buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")"); 1188 } 1189 // set the caps first, they're used when creating the bb 1190 backBufferCaps = caps; 1191 backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps); 1192 xBackBuffer = graphicsConfig.createBackBufferImage(target, 1193 backBuffer); 1194 } 1195 1196 @Override 1197 public BufferCapabilities getBackBufferCaps() { 1198 return backBufferCaps; 1199 } 1200 1201 public void flip(int x1, int y1, int x2, int y2, 1202 BufferCapabilities.FlipContents flipAction) 1203 { 1204 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1205 buffersLog.fine("flip(" + flipAction + ")"); 1206 } 1207 if (backBuffer == 0) { 1208 throw new IllegalStateException("Buffers have not been created"); 1209 } 1210 graphicsConfig.flip(this, target, xBackBuffer, 1211 x1, y1, x2, y2, flipAction); 1212 } 1213 1214 public Image getBackBuffer() { 1215 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1216 buffersLog.fine("getBackBuffer()"); 1217 } 1218 if (backBuffer == 0) { 1219 throw new IllegalStateException("Buffers have not been created"); 1220 } 1221 return xBackBuffer; 1222 } 1223 1224 public void destroyBuffers() { 1225 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1226 buffersLog.fine("destroyBuffers()"); 1227 } 1228 graphicsConfig.destroyBackBuffer(backBuffer); 1229 backBuffer = 0; 1230 xBackBuffer = null; 1231 } 1232 1233 // End of multi-buffering 1234 1235 public void notifyTextComponentChange(boolean add){ 1236 Container parent = AWTAccessor.getComponentAccessor().getParent(target); 1237 while(!(parent == null || 1238 parent instanceof java.awt.Frame || 1239 parent instanceof java.awt.Dialog)) { 1240 parent = AWTAccessor.getComponentAccessor().getParent(parent); 1241 } 1242 1243 /* FIX ME - FIX ME need to implement InputMethods 1244 if (parent instanceof java.awt.Frame || 1245 parent instanceof java.awt.Dialog) { 1246 if (add) 1247 ((MInputMethodControl)parent.getPeer()).addTextComponent((MComponentPeer)this); 1248 else 1249 ((MInputMethodControl)parent.getPeer()).removeTextComponent((MComponentPeer)this); 1250 } 1251 */ 1252 } 1253 1254 /** 1255 * Returns true if this event is disabled and shouldn't be processed by window 1256 * Currently if target component is disabled the following event will be disabled on window: 1257 * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify 1258 */ 1259 protected boolean isEventDisabled(XEvent e) { 1260 enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable")); 1261 if (!isEnabled()) { 1262 switch (e.get_type()) { 1263 case XConstants.ButtonPress: 1264 case XConstants.ButtonRelease: 1265 case XConstants.KeyPress: 1266 case XConstants.KeyRelease: 1267 case XConstants.EnterNotify: 1268 case XConstants.LeaveNotify: 1269 case XConstants.MotionNotify: 1270 enableLog.finer("Event {0} is disable", e); 1271 return true; 1272 } 1273 } 1274 switch(e.get_type()) { 1275 case XConstants.MapNotify: 1276 case XConstants.UnmapNotify: 1277 return true; 1278 } 1279 return super.isEventDisabled(e); 1280 } 1281 1282 Color getPeerBackground() { 1283 return background; 1284 } 1285 1286 Color getPeerForeground() { 1287 return foreground; 1288 } 1289 1290 Font getPeerFont() { 1291 return font; 1292 } 1293 1294 Dimension getPeerSize() { 1295 return new Dimension(width,height); 1296 } 1297 1298 public void setBoundsOperation(int operation) { 1299 synchronized(getStateLock()) { 1300 if (boundsOperation == DEFAULT_OPERATION) { 1301 boundsOperation = operation; 1302 } else if (operation == RESET_OPERATION) { 1303 boundsOperation = DEFAULT_OPERATION; 1304 } 1305 } 1306 } 1307 1308 static String operationToString(int operation) { 1309 switch (operation) { 1310 case SET_LOCATION: 1311 return "SET_LOCATION"; 1312 case SET_SIZE: 1313 return "SET_SIZE"; 1314 case SET_CLIENT_SIZE: 1315 return "SET_CLIENT_SIZE"; 1316 default: 1317 case SET_BOUNDS: 1318 return "SET_BOUNDS"; 1319 } 1320 } 1321 1322 /** 1323 * Lowers this component at the bottom of the above HW peer. If the above parameter 1324 * is null then the method places this component at the top of the Z-order. 1325 */ 1326 public void setZOrder(ComponentPeer above) { 1327 long aboveWindow = (above != null) ? ((XComponentPeer)above).getWindow() : 0; 1328 1329 XToolkit.awtLock(); 1330 try{ 1331 XlibWrapper.SetZOrder(XToolkit.getDisplay(), getWindow(), aboveWindow); 1332 }finally{ 1333 XToolkit.awtUnlock(); 1334 } 1335 } 1336 1337 private void addTree(Collection order, Set set, Container cont) { 1338 for (int i = 0; i < cont.getComponentCount(); i++) { 1339 Component comp = cont.getComponent(i); 1340 ComponentPeer peer = comp.getPeer(); 1341 if (peer instanceof XComponentPeer) { 1342 Long window = Long.valueOf(((XComponentPeer)peer).getWindow()); 1343 if (!set.contains(window)) { 1344 set.add(window); 1345 order.add(window); 1346 } 1347 } else if (comp instanceof Container) { 1348 // It is lightweight container, it might contain heavyweight components attached to this 1349 // peer 1350 addTree(order, set, (Container)comp); 1351 } 1352 } 1353 } 1354 1355 /****** DropTargetPeer implementation ********************/ 1356 1357 public void addDropTarget(DropTarget dt) { 1358 Component comp = target; 1359 while(!(comp == null || comp instanceof Window)) { 1360 comp = comp.getParent(); 1361 } 1362 1363 if (comp instanceof Window) { 1364 XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); 1365 if (wpeer != null) { 1366 wpeer.addDropTarget(); 1367 } 1368 } 1369 } 1370 1371 public void removeDropTarget(DropTarget dt) { 1372 Component comp = target; 1373 while(!(comp == null || comp instanceof Window)) { 1374 comp = comp.getParent(); 1375 } 1376 1377 if (comp instanceof Window) { 1378 XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); 1379 if (wpeer != null) { 1380 wpeer.removeDropTarget(); 1381 } 1382 } 1383 } 1384 1385 /** 1386 * Applies the shape to the X-window. 1387 * @since 1.7 1388 */ 1389 public void applyShape(Region shape) { 1390 if (XlibUtil.isShapingSupported()) { 1391 if (shapeLog.isLoggable(PlatformLogger.FINER)) { 1392 shapeLog.finer( 1393 "*** INFO: Setting shape: PEER: " + this 1394 + "; WINDOW: " + getWindow() 1395 + "; TARGET: " + target 1396 + "; SHAPE: " + shape); 1397 } 1398 XToolkit.awtLock(); 1399 try { 1400 if (shape != null) { 1401 XlibWrapper.SetRectangularShape( 1402 XToolkit.getDisplay(), 1403 getWindow(), 1404 shape.getLoX(), shape.getLoY(), 1405 shape.getHiX(), shape.getHiY(), 1406 (shape.isRectangular() ? null : shape) 1407 ); 1408 } else { 1409 XlibWrapper.SetRectangularShape( 1410 XToolkit.getDisplay(), 1411 getWindow(), 1412 0, 0, 1413 0, 0, 1414 null 1415 ); 1416 } 1417 } finally { 1418 XToolkit.awtUnlock(); 1419 } 1420 } else { 1421 if (shapeLog.isLoggable(PlatformLogger.FINER)) { 1422 shapeLog.finer("*** WARNING: Shaping is NOT supported!"); 1423 } 1424 } 1425 } 1426 1427 public boolean updateGraphicsData(GraphicsConfiguration gc) { 1428 int oldVisual = -1, newVisual = -1; 1429 1430 if (graphicsConfig != null) { 1431 oldVisual = graphicsConfig.getVisual(); 1432 } 1433 if (gc != null && gc instanceof X11GraphicsConfig) { 1434 newVisual = ((X11GraphicsConfig)gc).getVisual(); 1435 } 1436 1437 // If the new visual differs from the old one, the peer must be 1438 // recreated because X11 does not allow changing the visual on the fly. 1439 // So we even skip the initGraphicsConfiguration() call. 1440 // The initial assignment should happen though, hence the != -1 thing. 1441 if (oldVisual != -1 && oldVisual != newVisual) { 1442 return true; 1443 } 1444 1445 initGraphicsConfiguration(); 1446 doValidateSurface(); 1447 return false; 1448 } 1449 }