44 extends LWContainerPeer<Window, JComponent>
45 implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier
46 {
47 public enum PeerType {
48 SIMPLEWINDOW,
49 FRAME,
50 DIALOG,
51 EMBEDDED_FRAME,
52 VIEW_EMBEDDED_FRAME,
53 LW_FRAME
54 }
55
56 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
57
58 private final PlatformWindow platformWindow;
59
60 private static final int MINIMUM_WIDTH = 1;
61 private static final int MINIMUM_HEIGHT = 1;
62
63 private Insets insets = new Insets(0, 0, 0, 0);
64
65 private GraphicsDevice graphicsDevice;
66 private GraphicsConfiguration graphicsConfig;
67
68 private SurfaceData surfaceData;
69 private final Object surfaceDataLock = new Object();
70
71 private volatile int windowState = Frame.NORMAL;
72
73 // check that the mouse is over the window
74 private volatile boolean isMouseOver = false;
75
76 // A peer where the last mouse event came to. Used by cursor manager to
77 // find the component under cursor
78 private static volatile LWComponentPeer<?, ?> lastCommonMouseEventPeer;
79
80 // A peer where the last mouse event came to. Used to generate
81 // MOUSE_ENTERED/EXITED notifications
82 private volatile LWComponentPeer<?, ?> lastMouseEventPeer;
83
159 // Init warning window(for applets)
160 SecurityWarningWindow warn = null;
161 if (target.getWarningString() != null) {
162 // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
163 // and TrayIcon balloon windows without a warning window.
164 if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) {
165 LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
166 warn = toolkit.createSecurityWarning(target, this);
167 }
168 }
169
170 warningWindow = warn;
171 }
172
173 @Override
174 void initializeImpl() {
175 super.initializeImpl();
176
177
178 if (getTarget() instanceof Frame) {
179 setTitle(((Frame) getTarget()).getTitle());
180 setState(((Frame) getTarget()).getExtendedState());
181 } else if (getTarget() instanceof Dialog) {
182 setTitle(((Dialog) getTarget()).getTitle());
183 }
184
185 updateAlwaysOnTopState();
186 updateMinimumSize();
187
188 final Shape shape = getTarget().getShape();
189 if (shape != null) {
190 applyShape(Region.getInstance(shape, null));
191 }
192
193 final float opacity = getTarget().getOpacity();
194 if (opacity < 1.0f) {
195 setOpacity(opacity);
196 }
197
198 setOpaque(getTarget().isOpaque());
199
200 updateInsets(platformWindow.getInsets());
526 @Override
527 public void setMenuBar(MenuBar mb) {
528 platformWindow.setMenuBar(mb);
529 }
530
531 @Override // FramePeer and DialogPeer
532 public void setResizable(boolean resizable) {
533 platformWindow.setResizable(resizable);
534 }
535
536 @Override
537 public void setState(int state) {
538 platformWindow.setWindowState(state);
539 }
540
541 @Override
542 public int getState() {
543 return windowState;
544 }
545
546 @Override
547 public void setMaximizedBounds(Rectangle bounds) {
548 // TODO: not implemented
549 }
550
551 @Override
552 public void setBoundsPrivate(int x, int y, int width, int height) {
553 setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
554 }
555
556 @Override
557 public Rectangle getBoundsPrivate() {
558 throw new RuntimeException("not implemented");
559 }
560
561 // ---- DIALOG PEER METHODS ---- //
562
563 @Override
564 public void blockWindows(List<Window> windows) {
565 //TODO: LWX will probably need some collectJavaToplevels to speed this up
566 for (Window w : windows) {
567 WindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);
568 if (wp != null) {
618 * user or window insets are changed. There's no notifyReshape() in
619 * LWComponentPeer as the only components which could be resized by user are
620 * top-level windows.
621 */
622 @Override
623 public void notifyReshape(int x, int y, int w, int h) {
624 Rectangle oldBounds = getBounds();
625 final boolean invalid = updateInsets(platformWindow.getInsets());
626 final boolean moved = (x != oldBounds.x) || (y != oldBounds.y);
627 final boolean resized = (w != oldBounds.width) || (h != oldBounds.height);
628
629 // Check if anything changed
630 if (!moved && !resized && !invalid) {
631 return;
632 }
633 // First, update peer's bounds
634 setBounds(x, y, w, h, SET_BOUNDS, false, false);
635
636 // Second, update the graphics config and surface data
637 final boolean isNewDevice = updateGraphicsDevice();
638 if (resized || isNewDevice) {
639 replaceSurfaceData();
640 updateMinimumSize();
641 }
642
643 // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
644 if (moved || invalid) {
645 handleMove(x, y, true);
646 }
647 if (resized || invalid || isNewDevice) {
648 handleResize(w, h, true);
649 repaintPeer();
650 }
651
652 repositionSecurityWarning();
653 }
654
655 private void clearBackground(final int w, final int h) {
656 final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
657 getFont());
1040 }
1041 graphicsDevice = newGraphicsDevice;
1042 }
1043
1044 final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
1045
1046 if (!setGraphicsConfig(newGC)) return false;
1047
1048 SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
1049 public void run() {
1050 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
1051 }
1052 });
1053 return true;
1054 }
1055
1056 @Override
1057 public final void displayChanged() {
1058 if (updateGraphicsDevice()) {
1059 updateMinimumSize();
1060 }
1061 // Replace surface unconditionally, because internal state of the
1062 // GraphicsDevice could be changed.
1063 replaceSurfaceData();
1064 repaintPeer();
1065 }
1066
1067 @Override
1068 public final void paletteChanged() {
1069 // components do not need to react to this event.
1070 }
1071
1072 /*
1073 * May be called by delegate to provide SD to Java2D code.
1074 */
1075 public SurfaceData getSurfaceData() {
1076 synchronized (surfaceDataLock) {
1077 return surfaceData;
1078 }
1079 }
|
44 extends LWContainerPeer<Window, JComponent>
45 implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier
46 {
47 public enum PeerType {
48 SIMPLEWINDOW,
49 FRAME,
50 DIALOG,
51 EMBEDDED_FRAME,
52 VIEW_EMBEDDED_FRAME,
53 LW_FRAME
54 }
55
56 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
57
58 private final PlatformWindow platformWindow;
59
60 private static final int MINIMUM_WIDTH = 1;
61 private static final int MINIMUM_HEIGHT = 1;
62
63 private Insets insets = new Insets(0, 0, 0, 0);
64 private Rectangle maximizedBounds;
65
66 private GraphicsDevice graphicsDevice;
67 private GraphicsConfiguration graphicsConfig;
68
69 private SurfaceData surfaceData;
70 private final Object surfaceDataLock = new Object();
71
72 private volatile int windowState = Frame.NORMAL;
73
74 // check that the mouse is over the window
75 private volatile boolean isMouseOver = false;
76
77 // A peer where the last mouse event came to. Used by cursor manager to
78 // find the component under cursor
79 private static volatile LWComponentPeer<?, ?> lastCommonMouseEventPeer;
80
81 // A peer where the last mouse event came to. Used to generate
82 // MOUSE_ENTERED/EXITED notifications
83 private volatile LWComponentPeer<?, ?> lastMouseEventPeer;
84
160 // Init warning window(for applets)
161 SecurityWarningWindow warn = null;
162 if (target.getWarningString() != null) {
163 // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
164 // and TrayIcon balloon windows without a warning window.
165 if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) {
166 LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
167 warn = toolkit.createSecurityWarning(target, this);
168 }
169 }
170
171 warningWindow = warn;
172 }
173
174 @Override
175 void initializeImpl() {
176 super.initializeImpl();
177
178
179 if (getTarget() instanceof Frame) {
180 Frame frame = (Frame) getTarget();
181 setTitle(frame.getTitle());
182 setState(frame.getExtendedState());
183 setMaximizedBounds(frame.getMaximizedBounds());
184 } else if (getTarget() instanceof Dialog) {
185 setTitle(((Dialog) getTarget()).getTitle());
186 }
187
188 updateAlwaysOnTopState();
189 updateMinimumSize();
190
191 final Shape shape = getTarget().getShape();
192 if (shape != null) {
193 applyShape(Region.getInstance(shape, null));
194 }
195
196 final float opacity = getTarget().getOpacity();
197 if (opacity < 1.0f) {
198 setOpacity(opacity);
199 }
200
201 setOpaque(getTarget().isOpaque());
202
203 updateInsets(platformWindow.getInsets());
529 @Override
530 public void setMenuBar(MenuBar mb) {
531 platformWindow.setMenuBar(mb);
532 }
533
534 @Override // FramePeer and DialogPeer
535 public void setResizable(boolean resizable) {
536 platformWindow.setResizable(resizable);
537 }
538
539 @Override
540 public void setState(int state) {
541 platformWindow.setWindowState(state);
542 }
543
544 @Override
545 public int getState() {
546 return windowState;
547 }
548
549 private boolean isMaximizedBoundsSet() {
550 synchronized (getStateLock()) {
551 return maximizedBounds != null;
552 }
553 }
554
555 private Rectangle getDefaultMaximizedBounds() {
556 GraphicsConfiguration config = getGraphicsConfiguration();
557 Insets screenInsets = ((CGraphicsDevice) config.getDevice())
558 .getScreenInsets();
559 Rectangle gcBounds = config.getBounds();
560 return new Rectangle(
561 gcBounds.x + screenInsets.left,
562 gcBounds.y + screenInsets.top,
563 gcBounds.width - screenInsets.left - screenInsets.right,
564 gcBounds.height - screenInsets.top - screenInsets.bottom);
565 }
566
567 @Override
568 public void setMaximizedBounds(Rectangle bounds) {
569 boolean isMaximizedBoundsSet;
570 synchronized (getStateLock()) {
571 this.maximizedBounds = (isMaximizedBoundsSet = (bounds != null))
572 ? constrainBounds(bounds) : null;
573 }
574
575 setPlatformMaximizedBounds(isMaximizedBoundsSet ? maximizedBounds
576 : getDefaultMaximizedBounds());
577 }
578
579 private void setPlatformMaximizedBounds(Rectangle bounds) {
580 platformWindow.setMaximizedBounds(
581 bounds.x, bounds.y,
582 bounds.width, bounds.height);
583 }
584
585 @Override
586 public void setBoundsPrivate(int x, int y, int width, int height) {
587 setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
588 }
589
590 @Override
591 public Rectangle getBoundsPrivate() {
592 throw new RuntimeException("not implemented");
593 }
594
595 // ---- DIALOG PEER METHODS ---- //
596
597 @Override
598 public void blockWindows(List<Window> windows) {
599 //TODO: LWX will probably need some collectJavaToplevels to speed this up
600 for (Window w : windows) {
601 WindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);
602 if (wp != null) {
652 * user or window insets are changed. There's no notifyReshape() in
653 * LWComponentPeer as the only components which could be resized by user are
654 * top-level windows.
655 */
656 @Override
657 public void notifyReshape(int x, int y, int w, int h) {
658 Rectangle oldBounds = getBounds();
659 final boolean invalid = updateInsets(platformWindow.getInsets());
660 final boolean moved = (x != oldBounds.x) || (y != oldBounds.y);
661 final boolean resized = (w != oldBounds.width) || (h != oldBounds.height);
662
663 // Check if anything changed
664 if (!moved && !resized && !invalid) {
665 return;
666 }
667 // First, update peer's bounds
668 setBounds(x, y, w, h, SET_BOUNDS, false, false);
669
670 // Second, update the graphics config and surface data
671 final boolean isNewDevice = updateGraphicsDevice();
672 if (isNewDevice && !isMaximizedBoundsSet()) {
673 setPlatformMaximizedBounds(getDefaultMaximizedBounds());
674 }
675
676 if (resized || isNewDevice) {
677 replaceSurfaceData();
678 updateMinimumSize();
679 }
680
681 // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
682 if (moved || invalid) {
683 handleMove(x, y, true);
684 }
685 if (resized || invalid || isNewDevice) {
686 handleResize(w, h, true);
687 repaintPeer();
688 }
689
690 repositionSecurityWarning();
691 }
692
693 private void clearBackground(final int w, final int h) {
694 final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
695 getFont());
1078 }
1079 graphicsDevice = newGraphicsDevice;
1080 }
1081
1082 final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
1083
1084 if (!setGraphicsConfig(newGC)) return false;
1085
1086 SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
1087 public void run() {
1088 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
1089 }
1090 });
1091 return true;
1092 }
1093
1094 @Override
1095 public final void displayChanged() {
1096 if (updateGraphicsDevice()) {
1097 updateMinimumSize();
1098 if (!isMaximizedBoundsSet()) {
1099 setPlatformMaximizedBounds(getDefaultMaximizedBounds());
1100 }
1101 }
1102 // Replace surface unconditionally, because internal state of the
1103 // GraphicsDevice could be changed.
1104 replaceSurfaceData();
1105 repaintPeer();
1106 }
1107
1108 @Override
1109 public final void paletteChanged() {
1110 // components do not need to react to this event.
1111 }
1112
1113 /*
1114 * May be called by delegate to provide SD to Java2D code.
1115 */
1116 public SurfaceData getSurfaceData() {
1117 synchronized (surfaceDataLock) {
1118 return surfaceData;
1119 }
1120 }
|