36 import sun.java2d.*;
37 import sun.java2d.loops.Blit;
38 import sun.java2d.loops.CompositeType;
39 import sun.java2d.pipe.Region;
40 import sun.util.logging.PlatformLogger;
41
42 public class LWWindowPeer
43 extends LWContainerPeer<Window, JComponent>
44 implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
45 {
46 public static enum PeerType {
47 SIMPLEWINDOW,
48 FRAME,
49 DIALOG,
50 EMBEDDED_FRAME,
51 VIEW_EMBEDDED_FRAME
52 }
53
54 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
55
56 private PlatformWindow platformWindow;
57
58 // Window bounds reported by the native system (as opposed to
59 // regular bounds inherited from LWComponentPeer which are
60 // requested by user and may haven't been applied yet because
61 // of asynchronous requests to the windowing system)
62 private int sysX;
63 private int sysY;
64 private int sysW;
65 private int sysH;
66
67 private static final int MINIMUM_WIDTH = 1;
68 private static final int MINIMUM_HEIGHT = 1;
69
70 private Insets insets = new Insets(0, 0, 0, 0);
71
72 private GraphicsDevice graphicsDevice;
73 private GraphicsConfiguration graphicsConfig;
74
75 private SurfaceData surfaceData;
76 private final Object surfaceDataLock = new Object();
537 if (!iconify) {
538 repaintPeer();
539 }
540 }
541
542 public void notifyZoom(boolean isZoomed) {
543 int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL;
544 postWindowStateChangedEvent(newWindowState);
545 }
546
547 /**
548 * Called by the {@code PlatformWindow} when any part of the window should
549 * be repainted.
550 */
551 public final void notifyExpose(final Rectangle r) {
552 repaintPeer(r);
553 }
554
555 /**
556 * Called by the {@code PlatformWindow} when this window is moved/resized by
557 * user. There's no notifyReshape() in LWComponentPeer as the only
558 * components which could be resized by user are top-level windows.
559 */
560 public final void notifyReshape(int x, int y, int w, int h) {
561 final boolean moved;
562 final boolean resized;
563 synchronized (getStateLock()) {
564 moved = (x != sysX) || (y != sysY);
565 resized = (w != sysW) || (h != sysH);
566 sysX = x;
567 sysY = y;
568 sysW = w;
569 sysH = h;
570 }
571
572 // Check if anything changed
573 if (!moved && !resized) {
574 return;
575 }
576 // First, update peer's bounds
577 setBounds(x, y, w, h, SET_BOUNDS, false, false);
578
579 // Second, update the graphics config and surface data
580 checkIfOnNewScreen();
581 if (resized) {
582 replaceSurfaceData();
583 flushOnscreenGraphics();
584 }
585
586 // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
587 if (moved) {
588 handleMove(x, y, true);
589 }
590 if (resized) {
591 handleResize(w, h, true);
592 repaintPeer();
593 }
594 }
595
596 private void clearBackground(final int w, final int h) {
597 final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
598 getFont());
599 if (g != null) {
600 try {
601 if (g instanceof Graphics2D) {
602 ((Graphics2D) g).setComposite(AlphaComposite.Src);
603 }
604 if (isTranslucent()) {
605 g.setColor(nonOpaqueBackground);
606 g.fillRect(0, 0, w, h);
607 }
608 if (!isTextured()) {
609 if (g instanceof SunGraphics2D) {
610 SG2DConstraint((SunGraphics2D) g, getRegion());
982 }
983 }
984
985 private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
986 //TODO blit. proof-of-concept
987 if (src != dst && src != null && dst != null
988 && !(dst instanceof NullSurfaceData)
989 && !(src instanceof NullSurfaceData)
990 && src.getSurfaceType().equals(dst.getSurfaceType())) {
991 final Rectangle size = getSize();
992 final Blit blit = Blit.locate(src.getSurfaceType(),
993 CompositeType.Src,
994 dst.getSurfaceType());
995 if (blit != null) {
996 blit.Blit(src, dst, AlphaComposite.Src,
997 getRegion(), 0, 0, 0, 0, size.width, size.height);
998 }
999 }
1000 }
1001
1002 /*
1003 * Request the window insets from the delegate and compares it
1004 * with the current one. This method is mostly called by the
1005 * delegate, e.g. when the window state is changed and insets
1006 * should be recalculated.
1007 *
1008 * This method may be called on the toolkit thread.
1009 */
1010 public boolean updateInsets(Insets newInsets) {
1011 boolean changed = false;
1012 synchronized (getStateLock()) {
1013 changed = (insets.equals(newInsets));
1014 insets = newInsets;
1015 }
1016
1017 if (changed) {
1018 replaceSurfaceData();
1019 repaintPeer();
1020 }
1021
1022 return changed;
1023 }
1024
1025 public static LWWindowPeer getWindowUnderCursor() {
1026 return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null;
1027 }
1028
1029 public static LWComponentPeer<?, ?> getPeerUnderCursor() {
1030 return lastCommonMouseEventPeer;
1031 }
1032
1033 /*
1034 * Requests platform to set native focus on a frame/dialog.
1035 * In case of a simple window, triggers appropriate java focus change.
1036 */
1037 public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
1038 if (focusLog.isLoggable(PlatformLogger.FINE)) {
1039 focusLog.fine("requesting native focus to " + this);
1040 }
1041
1042 if (!focusAllowedFor()) {
|
36 import sun.java2d.*;
37 import sun.java2d.loops.Blit;
38 import sun.java2d.loops.CompositeType;
39 import sun.java2d.pipe.Region;
40 import sun.util.logging.PlatformLogger;
41
42 public class LWWindowPeer
43 extends LWContainerPeer<Window, JComponent>
44 implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
45 {
46 public static enum PeerType {
47 SIMPLEWINDOW,
48 FRAME,
49 DIALOG,
50 EMBEDDED_FRAME,
51 VIEW_EMBEDDED_FRAME
52 }
53
54 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
55
56 private final PlatformWindow platformWindow;
57
58 // Window bounds reported by the native system (as opposed to
59 // regular bounds inherited from LWComponentPeer which are
60 // requested by user and may haven't been applied yet because
61 // of asynchronous requests to the windowing system)
62 private int sysX;
63 private int sysY;
64 private int sysW;
65 private int sysH;
66
67 private static final int MINIMUM_WIDTH = 1;
68 private static final int MINIMUM_HEIGHT = 1;
69
70 private Insets insets = new Insets(0, 0, 0, 0);
71
72 private GraphicsDevice graphicsDevice;
73 private GraphicsConfiguration graphicsConfig;
74
75 private SurfaceData surfaceData;
76 private final Object surfaceDataLock = new Object();
537 if (!iconify) {
538 repaintPeer();
539 }
540 }
541
542 public void notifyZoom(boolean isZoomed) {
543 int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL;
544 postWindowStateChangedEvent(newWindowState);
545 }
546
547 /**
548 * Called by the {@code PlatformWindow} when any part of the window should
549 * be repainted.
550 */
551 public final void notifyExpose(final Rectangle r) {
552 repaintPeer(r);
553 }
554
555 /**
556 * Called by the {@code PlatformWindow} when this window is moved/resized by
557 * user or window insets are changed. There's no notifyReshape() in
558 * LWComponentPeer as the only components which could be resized by user are
559 * top-level windows.
560 */
561 public final void notifyReshape(int x, int y, int w, int h) {
562 final boolean moved;
563 final boolean resized;
564 final boolean invalid = updateInsets(platformWindow.getInsets());
565 synchronized (getStateLock()) {
566 moved = (x != sysX) || (y != sysY);
567 resized = (w != sysW) || (h != sysH);
568 sysX = x;
569 sysY = y;
570 sysW = w;
571 sysH = h;
572 }
573
574 // Check if anything changed
575 if (!moved && !resized && !invalid) {
576 return;
577 }
578 // First, update peer's bounds
579 setBounds(x, y, w, h, SET_BOUNDS, false, false);
580
581 // Second, update the graphics config and surface data
582 checkIfOnNewScreen();
583 if (resized) {
584 replaceSurfaceData();
585 flushOnscreenGraphics();
586 }
587
588 // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
589 if (moved || invalid) {
590 handleMove(x, y, true);
591 }
592 if (resized || invalid) {
593 handleResize(w, h, true);
594 repaintPeer();
595 }
596 }
597
598 private void clearBackground(final int w, final int h) {
599 final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
600 getFont());
601 if (g != null) {
602 try {
603 if (g instanceof Graphics2D) {
604 ((Graphics2D) g).setComposite(AlphaComposite.Src);
605 }
606 if (isTranslucent()) {
607 g.setColor(nonOpaqueBackground);
608 g.fillRect(0, 0, w, h);
609 }
610 if (!isTextured()) {
611 if (g instanceof SunGraphics2D) {
612 SG2DConstraint((SunGraphics2D) g, getRegion());
984 }
985 }
986
987 private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
988 //TODO blit. proof-of-concept
989 if (src != dst && src != null && dst != null
990 && !(dst instanceof NullSurfaceData)
991 && !(src instanceof NullSurfaceData)
992 && src.getSurfaceType().equals(dst.getSurfaceType())) {
993 final Rectangle size = getSize();
994 final Blit blit = Blit.locate(src.getSurfaceType(),
995 CompositeType.Src,
996 dst.getSurfaceType());
997 if (blit != null) {
998 blit.Blit(src, dst, AlphaComposite.Src,
999 getRegion(), 0, 0, 0, 0, size.width, size.height);
1000 }
1001 }
1002 }
1003
1004 /**
1005 * Request the window insets from the delegate and compares it with the
1006 * current one. This method is mostly called by the delegate, e.g. when the
1007 * window state is changed and insets should be recalculated.
1008 * <p/>
1009 * This method may be called on the toolkit thread.
1010 */
1011 public final boolean updateInsets(final Insets newInsets) {
1012 synchronized (getStateLock()) {
1013 if (insets.equals(newInsets)) {
1014 return false;
1015 }
1016 insets = newInsets;
1017 }
1018 return true;
1019 }
1020
1021 public static LWWindowPeer getWindowUnderCursor() {
1022 return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null;
1023 }
1024
1025 public static LWComponentPeer<?, ?> getPeerUnderCursor() {
1026 return lastCommonMouseEventPeer;
1027 }
1028
1029 /*
1030 * Requests platform to set native focus on a frame/dialog.
1031 * In case of a simple window, triggers appropriate java focus change.
1032 */
1033 public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
1034 if (focusLog.isLoggable(PlatformLogger.FINE)) {
1035 focusLog.fine("requesting native focus to " + this);
1036 }
1037
1038 if (!focusAllowedFor()) {
|