407 public GraphicsConfiguration getGraphicsConfiguration() {
408 // Don't check windowPeer for null as it can only happen
409 // for windows, but this method is overridden in
410 // LWWindowPeer and doesn't call super()
411 return getWindowPeer().getGraphicsConfiguration();
412 }
413
414 /*
415 * Overridden in LWWindowPeer to replace its surface
416 * data and back buffer.
417 */
418 @Override
419 public boolean updateGraphicsData(GraphicsConfiguration gc) {
420 // TODO: not implemented
421 // throw new RuntimeException("Has not been implemented yet.");
422 return false;
423 }
424
425 @Override
426 public final Graphics getGraphics() {
427 Graphics g = getWindowPeerOrSelf().isOpaque() ? getOnscreenGraphics()
428 : getOffscreenGraphics();
429 if (g != null) {
430 synchronized (getPeerTreeLock()){
431 applyConstrain(g);
432 }
433 }
434 return g;
435 }
436
437 /*
438 * Peer Graphics is borrowed from the parent peer, while
439 * foreground and background colors and font are specific to
440 * this peer.
441 */
442 public final Graphics getOnscreenGraphics() {
443 final LWWindowPeer wp = getWindowPeerOrSelf();
444 return wp.getOnscreenGraphics(getForeground(), getBackground(),
445 getFont());
446 }
447
448 public final Graphics getOffscreenGraphics() {
449 final LWWindowPeer wp = getWindowPeerOrSelf();
450
451 return wp.getOffscreenGraphics(getForeground(), getBackground(),
452 getFont());
453 }
454
455 private void applyConstrain(final Graphics g) {
456 final SunGraphics2D sg2d = (SunGraphics2D) g;
457 final Rectangle constr = localToWindow(getSize());
458 // translate and set rectangle constrain.
459 sg2d.constrain(constr.x, constr.y, constr.width, constr.height);
460 // set region constrain.
461 //sg2d.constrain(getVisibleRegion());
462 SG2DConstraint(sg2d, getVisibleRegion());
463 }
464
465 //TODO Move this method to SG2D?
466 private void SG2DConstraint(final SunGraphics2D sg2d, Region r) {
467 sg2d.constrainX = sg2d.transX;
468 sg2d.constrainY = sg2d.transY;
469
470 Region c = sg2d.constrainClip;
471 if ((sg2d.constrainX | sg2d.constrainY) != 0) {
472 r = r.getTranslatedRegion(sg2d.constrainX, sg2d.constrainY);
473 }
474 if (c == null) {
475 c = r;
476 } else {
477 c = c.getIntersection(r);
478 if (c == sg2d.constrainClip) {
479 // Common case to ignore
480 return;
481 }
482 }
483 sg2d.constrainClip = c;
484 //validateCompClip() forced call.
485 sg2d.setDevClip(r.getLoX(), r.getLoY(), r.getWidth(), r.getHeight());
486 }
693 delegate.setFont(f);
694 }
695 } else {
696 repaintPeer();
697 }
698 }
699
700 protected final Font getFont() {
701 synchronized (getStateLock()) {
702 return font;
703 }
704 }
705
706 @Override
707 public FontMetrics getFontMetrics(Font f) {
708 // Borrow the metrics from the top-level window
709 // return getWindowPeer().getFontMetrics(f);
710 // Obtain the metrics from the offscreen window where this peer is
711 // mostly drawn to.
712 // TODO: check for "use platform metrics" settings
713 Graphics g = getWindowPeer().getOffscreenGraphics();
714 try {
715 if (g != null) {
716 return g.getFontMetrics(f);
717 } else {
718 synchronized (getDelegateLock()) {
719 return delegateContainer.getFontMetrics(f);
720 }
721 }
722 } finally {
723 if (g != null) {
724 g.dispose();
725 }
726 }
727 }
728
729 @Override
730 public void setEnabled(final boolean e) {
731 boolean status = e;
732 final LWComponentPeer cp = getContainerPeer();
733 if (cp != null) {
994 public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
995 // TODO: is it a right/complete implementation?
996 return getToolkit().prepareImage(img, w, h, o);
997 }
998
999 @Override
1000 public int checkImage(Image img, int w, int h, ImageObserver o) {
1001 // TODO: is it a right/complete implementation?
1002 return getToolkit().checkImage(img, w, h, o);
1003 }
1004
1005 @Override
1006 public boolean handlesWheelScrolling() {
1007 // TODO: not implemented
1008 return false;
1009 }
1010
1011 @Override
1012 public final void applyShape(final Region shape) {
1013 synchronized (getStateLock()) {
1014 region = shape;
1015 }
1016 repaintParent(getBounds());
1017 }
1018
1019 protected final Region getRegion() {
1020 synchronized (getStateLock()) {
1021 return region == null ? Region.getInstance(getSize()) : region;
1022 }
1023 }
1024
1025 // DropTargetPeer Method
1026 @Override
1027 public void addDropTarget(DropTarget dt) {
1028 LWWindowPeer winPeer = getWindowPeerOrSelf();
1029 if (winPeer != null && winPeer != this) {
1030 // We need to register the DropTarget in the
1031 // peer of the window ancestor of the component
1032 winPeer.addDropTarget(dt);
1033 } else {
1034 synchronized (dropTargetLock) {
1035 // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
1036 // if it's the first (or last) one for the component. Otherwise this call is a no-op.
1037 if (++fNumDropTargets == 1) {
1038 // Having a non-null drop target would be an error but let's check just in case:
1039 if (fDropTarget != null)
1040 System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
1041
1369 return false;
1370 }
1371
1372 /**
1373 * Paints the peer. Overridden in subclasses to delegate the actual painting
1374 * to Swing components.
1375 */
1376 protected final void paintPeer(final Graphics g) {
1377 final D delegate = getDelegate();
1378 if (delegate != null) {
1379 if (!SwingUtilities.isEventDispatchThread()) {
1380 throw new InternalError("Painting must be done on EDT");
1381 }
1382 synchronized (getDelegateLock()) {
1383 // JComponent.print() is guaranteed to not affect the double buffer
1384 getDelegate().print(g);
1385 }
1386 }
1387 }
1388
1389 // Just a helper method, thus final
1390 protected final void flushOffscreenGraphics() {
1391 flushOffscreenGraphics(getSize());
1392 }
1393
1394 protected static final void flushOnscreenGraphics(){
1395 final OGLRenderQueue rq = OGLRenderQueue.getInstance();
1396 rq.lock();
1397 try {
1398 rq.flushNow();
1399 } finally {
1400 rq.unlock();
1401 }
1402 }
1403
1404 /*
1405 * Flushes the given rectangle from the back buffer to the screen.
1406 */
1407 protected void flushOffscreenGraphics(Rectangle r) {
1408 flushOffscreenGraphics(r.x, r.y, r.width, r.height);
1409 }
1410
1411 private void flushOffscreenGraphics(int x, int y, int width, int height) {
1412 Image bb = getWindowPeerOrSelf().getBackBuffer();
1413 if (bb != null) {
1414 // g is a screen Graphics from the delegate
1415 final Graphics g = getOnscreenGraphics();
1416
1417 if (g != null && g instanceof Graphics2D) {
1418 try {
1419 Graphics2D g2d = (Graphics2D)g;
1420 Point p = localToWindow(new Point(0, 0));
1421 Composite composite = g2d.getComposite();
1422 g2d.setComposite(AlphaComposite.Src);
1423 g.drawImage(bb, x, y, x + width, y + height, p.x + x,
1424 p.y + y, p.x + x + width, p.y + y + height,
1425 null);
1426 g2d.setComposite(composite);
1427 } finally {
1428 g.dispose();
1429 }
1430 }
1431 }
1432 }
1433
1434 /**
1435 * Used by ContainerPeer to skip all the paint events during layout.
1436 *
1437 * @param isLayouting layouting state.
1438 */
1439 protected final void setLayouting(final boolean isLayouting) {
1440 this.isLayouting = isLayouting;
1441 }
1442
1443 /**
1444 * Returns layouting state. Used by ComponentPeer to skip all the paint
1445 * events during layout.
1446 *
1447 * @return true during layout, false otherwise.
1448 */
1449 private final boolean isLayouting() {
1450 return isLayouting;
|
407 public GraphicsConfiguration getGraphicsConfiguration() {
408 // Don't check windowPeer for null as it can only happen
409 // for windows, but this method is overridden in
410 // LWWindowPeer and doesn't call super()
411 return getWindowPeer().getGraphicsConfiguration();
412 }
413
414 /*
415 * Overridden in LWWindowPeer to replace its surface
416 * data and back buffer.
417 */
418 @Override
419 public boolean updateGraphicsData(GraphicsConfiguration gc) {
420 // TODO: not implemented
421 // throw new RuntimeException("Has not been implemented yet.");
422 return false;
423 }
424
425 @Override
426 public final Graphics getGraphics() {
427 final Graphics g = getOnscreenGraphics();
428 if (g != null) {
429 synchronized (getPeerTreeLock()){
430 applyConstrain(g);
431 }
432 }
433 return g;
434 }
435
436 /*
437 * Peer Graphics is borrowed from the parent peer, while
438 * foreground and background colors and font are specific to
439 * this peer.
440 */
441 public final Graphics getOnscreenGraphics() {
442 final LWWindowPeer wp = getWindowPeerOrSelf();
443 return wp.getOnscreenGraphics(getForeground(), getBackground(),
444 getFont());
445
446 }
447
448 private void applyConstrain(final Graphics g) {
449 final SunGraphics2D sg2d = (SunGraphics2D) g;
450 final Rectangle constr = localToWindow(getSize());
451 // translate and set rectangle constrain.
452 sg2d.constrain(constr.x, constr.y, constr.width, constr.height);
453 // set region constrain.
454 //sg2d.constrain(getVisibleRegion());
455 SG2DConstraint(sg2d, getVisibleRegion());
456 }
457
458 //TODO Move this method to SG2D?
459 void SG2DConstraint(final SunGraphics2D sg2d, Region r) {
460 sg2d.constrainX = sg2d.transX;
461 sg2d.constrainY = sg2d.transY;
462
463 Region c = sg2d.constrainClip;
464 if ((sg2d.constrainX | sg2d.constrainY) != 0) {
465 r = r.getTranslatedRegion(sg2d.constrainX, sg2d.constrainY);
466 }
467 if (c == null) {
468 c = r;
469 } else {
470 c = c.getIntersection(r);
471 if (c == sg2d.constrainClip) {
472 // Common case to ignore
473 return;
474 }
475 }
476 sg2d.constrainClip = c;
477 //validateCompClip() forced call.
478 sg2d.setDevClip(r.getLoX(), r.getLoY(), r.getWidth(), r.getHeight());
479 }
686 delegate.setFont(f);
687 }
688 } else {
689 repaintPeer();
690 }
691 }
692
693 protected final Font getFont() {
694 synchronized (getStateLock()) {
695 return font;
696 }
697 }
698
699 @Override
700 public FontMetrics getFontMetrics(Font f) {
701 // Borrow the metrics from the top-level window
702 // return getWindowPeer().getFontMetrics(f);
703 // Obtain the metrics from the offscreen window where this peer is
704 // mostly drawn to.
705 // TODO: check for "use platform metrics" settings
706 Graphics g = getWindowPeer().getGraphics();
707 try {
708 if (g != null) {
709 return g.getFontMetrics(f);
710 } else {
711 synchronized (getDelegateLock()) {
712 return delegateContainer.getFontMetrics(f);
713 }
714 }
715 } finally {
716 if (g != null) {
717 g.dispose();
718 }
719 }
720 }
721
722 @Override
723 public void setEnabled(final boolean e) {
724 boolean status = e;
725 final LWComponentPeer cp = getContainerPeer();
726 if (cp != null) {
987 public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
988 // TODO: is it a right/complete implementation?
989 return getToolkit().prepareImage(img, w, h, o);
990 }
991
992 @Override
993 public int checkImage(Image img, int w, int h, ImageObserver o) {
994 // TODO: is it a right/complete implementation?
995 return getToolkit().checkImage(img, w, h, o);
996 }
997
998 @Override
999 public boolean handlesWheelScrolling() {
1000 // TODO: not implemented
1001 return false;
1002 }
1003
1004 @Override
1005 public final void applyShape(final Region shape) {
1006 synchronized (getStateLock()) {
1007 if (region == shape || (region != null && region.equals(shape))) {
1008 return;
1009 }
1010 }
1011 applyShapeImpl(shape);
1012 }
1013
1014 void applyShapeImpl(final Region shape) {
1015 synchronized (getStateLock()) {
1016 region = shape;
1017 }
1018 repaintParent(getBounds());
1019 }
1020
1021 protected final Region getRegion() {
1022 synchronized (getStateLock()) {
1023 return isShaped() ? region : Region.getInstance(getSize());
1024 }
1025 }
1026
1027 public boolean isShaped() {
1028 synchronized (getStateLock()) {
1029 return region != null;
1030 }
1031 }
1032
1033 // DropTargetPeer Method
1034 @Override
1035 public void addDropTarget(DropTarget dt) {
1036 LWWindowPeer winPeer = getWindowPeerOrSelf();
1037 if (winPeer != null && winPeer != this) {
1038 // We need to register the DropTarget in the
1039 // peer of the window ancestor of the component
1040 winPeer.addDropTarget(dt);
1041 } else {
1042 synchronized (dropTargetLock) {
1043 // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
1044 // if it's the first (or last) one for the component. Otherwise this call is a no-op.
1045 if (++fNumDropTargets == 1) {
1046 // Having a non-null drop target would be an error but let's check just in case:
1047 if (fDropTarget != null)
1048 System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
1049
1377 return false;
1378 }
1379
1380 /**
1381 * Paints the peer. Overridden in subclasses to delegate the actual painting
1382 * to Swing components.
1383 */
1384 protected final void paintPeer(final Graphics g) {
1385 final D delegate = getDelegate();
1386 if (delegate != null) {
1387 if (!SwingUtilities.isEventDispatchThread()) {
1388 throw new InternalError("Painting must be done on EDT");
1389 }
1390 synchronized (getDelegateLock()) {
1391 // JComponent.print() is guaranteed to not affect the double buffer
1392 getDelegate().print(g);
1393 }
1394 }
1395 }
1396
1397 protected static final void flushOnscreenGraphics(){
1398 final OGLRenderQueue rq = OGLRenderQueue.getInstance();
1399 rq.lock();
1400 try {
1401 rq.flushNow();
1402 } finally {
1403 rq.unlock();
1404 }
1405 }
1406
1407 /**
1408 * Used by ContainerPeer to skip all the paint events during layout.
1409 *
1410 * @param isLayouting layouting state.
1411 */
1412 protected final void setLayouting(final boolean isLayouting) {
1413 this.isLayouting = isLayouting;
1414 }
1415
1416 /**
1417 * Returns layouting state. Used by ComponentPeer to skip all the paint
1418 * events during layout.
1419 *
1420 * @return true during layout, false otherwise.
1421 */
1422 private final boolean isLayouting() {
1423 return isLayouting;
|