protected void applyWindowLevel(Window target) { if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) { CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel); } else if (target.getType() == Window.Type.POPUP) { CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSPopUpMenuWindowLevel); } }
public boolean focusAllowedFor() { Window window = (Window) this.target; if (!window.isVisible() || !window.isEnabled() || !window.isFocusableWindow()) { return false; } if (isModalBlocked()) { return false; } return true; }
private void updateWindow(boolean repaint) { Window w = (Window) target; synchronized (getStateLock()) { if (isOpaque || !w.isVisible() || (w.getWidth() <= 0) || (w.getHeight() <= 0)) { return; } TranslucentWindowPainter currentPainter = painter; if (currentPainter != null) { currentPainter.updateWindow(repaint); } else if (log.isLoggable(PlatformLogger.Level.FINER)) { log.finer("Translucent window painter is null in updateWindow"); } } }
public void putValue(String key, Object newValue) { super.putValue(key, newValue); if (key == Actions.SELECTED_KEY) { if (palette != null) { AbstractOSXApplication application = getApplication(); boolean b = (Boolean) newValue; if (b) { application.addPalette(palette); palette.setVisible(true); } else { application.removePalette(palette); palette.setVisible(false); } } } }
public void propertyChange(PropertyChangeEvent e) { Window w = (Window) e.getNewValue(); if (w == null) { return; } AppContext appContext = SunToolkit.targetToAppContext(w); synchronized (appContext) { WWindowPeer wp = (WWindowPeer) w.getPeer(); // add/move wp to the end of the list List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY); if (l != null) { l.remove(wp); l.add(wp); } } }
/* * Our focus model is synthetic and only non-simple window * may become natively focusable window. */ private boolean isNativelyFocusableWindow() { if (peer == null) { return false; } return !peer.isSimpleWindow() && target.getFocusableWindowState(); }
/** Updates the UI of the passed in window and all its children. */ private static void updateWindowUI(Window window) { SwingUtilities.updateComponentTreeUI(window); Window ownedWins[] = window.getOwnedWindows(); for (int i = 0; i < ownedWins.length; i++) { updateWindowUI(ownedWins[i]); } }
/** * Find image to install into Title or into Application icon. First try icons installed for * toplevel. Null is returned, if there is no icon and default Duke image should be used. */ private CImage getImageForTarget() { CImage icon = null; try { icon = CImage.getCreator().createFromImages(target.getIconImages()); } catch (Exception ignored) { // Perhaps the icon passed into Java is broken. Skipping this icon. } return icon; }
public void setPalette(Window newValue) { AbstractOSXApplication application = getApplication(); if (palette != null) { palette.removeWindowListener(windowHandler); } palette = newValue; if (palette != null) { palette.addWindowListener(windowHandler); if (getValue(Actions.SELECTED_KEY) == Boolean.TRUE) { application.addPalette(palette); palette.setVisible(true); } else { application.removePalette(palette); palette.setVisible(false); } } }
@Override public void setModalBlocked(boolean blocked) { if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) { return; } if (blocked) { // We are going to show a modal window. Previously displayed window will be // blocked/disabled. So we have to send mouse exited event to it now, since // all mouse events are discarded for blocked/disabled windows. nativeSynthesizeMouseEnteredExitedEvents(getNSWindowPtr(), CocoaConstants.NSMouseExited); } nativeSetEnabled(getNSWindowPtr(), !blocked); checkBlockingAndOrder(); }
public void setOpaque(boolean isOpaque) { synchronized (getStateLock()) { if (this.isOpaque == isOpaque) { return; } } Window target = (Window) getTarget(); if (!isOpaque) { SunToolkit sunToolkit = (SunToolkit) target.getToolkit(); if (!sunToolkit.isWindowTranslucencySupported() || !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration())) { return; } } boolean isVistaOS = Win32GraphicsEnvironment.isVistaOS(); if (this.isOpaque != isOpaque && !isVistaOS) { // non-Vista OS: only replace the surface data if the opacity // status changed (see WComponentPeer.isAccelCapable() for more) replaceSurfaceDataRecursively(target); } synchronized (getStateLock()) { this.isOpaque = isOpaque; setOpaqueImpl(isOpaque); if (isOpaque) { TranslucentWindowPainter currentPainter = painter; if (currentPainter != null) { currentPainter.flush(); painter = null; } } else { painter = TranslucentWindowPainter.createInstance(this); } } if (isVistaOS) { // On Vista: setting the window non-opaque makes the window look // rectangular, though still catching the mouse clicks within // its shape only. To restore the correct visual appearance // of the window (i.e. w/ the correct shape) we have to reset // the shape. Shape shape = target.getShape(); if (shape != null) { target.setShape(shape); } } if (target.isVisible()) { updateWindow(true); } }
/* * Delegate initialization (create native window and all the * related resources). */ @Override // PlatformWindow public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) { initializeBase(_target, _peer, _owner, new CPlatformView()); final int styleBits = getInitialStyleBits(); responder = createPlatformResponder(); contentView = createContentView(); contentView.initialize(peer, responder); final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L; Rectangle bounds; if (!IS(DECORATED, styleBits)) { // For undecorated frames the move/resize event does not come if the frame is centered on the // screen // so we need to set a stub location to force an initial move/resize. Real bounds would be set // later. bounds = new Rectangle(0, 0, 1, 1); } else { bounds = _peer.constrainBounds(_target.getBounds()); } final long nativeWindowPtr = nativeCreateNSWindow( contentView.getAWTView(), ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height); setPtr(nativeWindowPtr); if (target instanceof javax.swing.RootPaneContainer) { final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer) target).getRootPane(); if (rootpane != null) rootpane.addPropertyChangeListener( "ancestor", new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane); rootpane.removePropertyChangeListener("ancestor", this); } }); } validateSurface(); }
void initialize() { super.initialize(); updateInsets(insets_); Font f = ((Window) target).getFont(); if (f == null) { f = defaultFont; ((Window) target).setFont(f); setFont(f); } // Express our interest in display changes GraphicsConfiguration gc = getGraphicsConfiguration(); ((Win32GraphicsDevice) gc.getDevice()).addDisplayChangedListener(this); initActiveWindowsTracking((Window) target); updateIconImages(); Shape shape = ((Window) target).getShape(); if (shape != null) { applyShape(Region.getInstance(shape, null)); } float opacity = ((Window) target).getOpacity(); if (opacity < 1.0f) { setOpacity(opacity); } synchronized (getStateLock()) { // default value of a boolean field is 'false', so set isOpaque to // true here explicitly this.isOpaque = true; setOpaque(((Window) target).isOpaque()); } }
// ------------------------------------------- public static void centerWindow(Window w) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = w.getSize(); w.setLocation( (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); }
@Override // PlatformWindow public void setVisible(boolean visible) { final long nsWindowPtr = getNSWindowPtr(); // Configure stuff updateIconImages(); updateFocusabilityForAutoRequestFocus(false); boolean wasMaximized = isMaximized(); if (visible && target.isLocationByPlatform()) { nativeSetNSWindowLocationByPlatform(getNSWindowPtr()); } // Actually show or hide the window LWWindowPeer blocker = (peer == null) ? null : peer.getBlocker(); if (blocker == null || !visible) { // If it ain't blocked, or is being hidden, go regular way if (visible) { CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView()); boolean isPopup = (target.getType() == Window.Type.POPUP); if (isPopup) { // Popups in applets don't activate applet's process CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr); } else { CWrapper.NSWindow.orderFront(nsWindowPtr); } boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr); if (!isKeyWindow) { CWrapper.NSWindow.makeKeyWindow(nsWindowPtr); } } else { // immediately hide the window CWrapper.NSWindow.orderOut(nsWindowPtr); // process the close CWrapper.NSWindow.close(nsWindowPtr); } } else { // otherwise, put it in a proper z-order CWrapper.NSWindow.orderWindow( nsWindowPtr, CWrapper.NSWindow.NSWindowBelow, ((CPlatformWindow) blocker.getPlatformWindow()).getNSWindowPtr()); } this.visible = visible; // Manage the extended state when showing if (visible) { // Apply the extended state as expected in shared code if (target instanceof Frame) { if (!wasMaximized && isMaximized()) { // setVisible could have changed the native maximized state deliverZoom(true); } else { int frameState = ((Frame) target).getExtendedState(); if ((frameState & Frame.ICONIFIED) != 0) { // Treat all state bit masks with ICONIFIED bit as ICONIFIED state. frameState = Frame.ICONIFIED; } switch (frameState) { case Frame.ICONIFIED: CWrapper.NSWindow.miniaturize(nsWindowPtr); break; case Frame.MAXIMIZED_BOTH: maximize(); break; default: // NORMAL unmaximize(); // in case it was maximized, otherwise this is a no-op break; } } } } nativeSynthesizeMouseEnteredExitedEvents(); // Configure stuff #2 updateFocusabilityForAutoRequestFocus(true); // Manage parent-child relationship when showing final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); if (visible) { // Order myself above my parent if (owner != null && owner.isVisible()) { CWrapper.NSWindow.orderWindow( nsWindowPtr, CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr()); applyWindowLevel(target); } // Order my own children above myself for (Window w : target.getOwnedWindows()) { final Object p = acc.getPeer(w); if (p instanceof LWWindowPeer) { CPlatformWindow pw = (CPlatformWindow) ((LWWindowPeer) p).getPlatformWindow(); if (pw != null && pw.isVisible()) { CWrapper.NSWindow.orderWindow( pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove, nsWindowPtr); pw.applyWindowLevel(w); } } } } // Deal with the blocker of the window being shown if (blocker != null && visible) { // Make sure the blocker is above its siblings ((CPlatformWindow) blocker.getPlatformWindow()).orderAboveSiblings(); } }
protected int getInitialStyleBits() { // defaults style bits int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE; if (isNativelyFocusableWindow()) { styleBits = SET(styleBits, SHOULD_BECOME_KEY, true); styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true); } final boolean isFrame = (target instanceof Frame); final boolean isDialog = (target instanceof Dialog); final boolean isPopup = (target.getType() == Window.Type.POPUP); if (isDialog) { styleBits = SET(styleBits, MINIMIZABLE, false); } // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always // is undecorated. { this.undecorated = isFrame ? ((Frame) target).isUndecorated() : (isDialog ? ((Dialog) target).isUndecorated() : true); if (this.undecorated) styleBits = SET(styleBits, DECORATED, false); } // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never // resizable { final boolean resizable = isFrame ? ((Frame) target).isResizable() : (isDialog ? ((Dialog) target).isResizable() : false); styleBits = SET(styleBits, RESIZABLE, resizable); if (!resizable) { styleBits = SET(styleBits, ZOOMABLE, false); } else { setCanFullscreen(true); } } if (target.isAlwaysOnTop()) { styleBits = SET(styleBits, ALWAYS_ON_TOP, true); } if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) { styleBits = SET(styleBits, MODAL_EXCLUDED, true); } // If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look. if (isPopup) { styleBits = SET(styleBits, TEXTURED, false); // Popups in applets don't activate applet's process styleBits = SET(styleBits, NONACTIVATING, true); styleBits = SET(styleBits, IS_POPUP, true); } if (Window.Type.UTILITY.equals(target.getType())) { styleBits = SET(styleBits, UTILITY, true); } if (target instanceof javax.swing.RootPaneContainer) { javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer) target).getRootPane(); Object prop = null; prop = rootpane.getClientProperty(WINDOW_BRUSH_METAL_LOOK); if (prop != null) { styleBits = SET(styleBits, TEXTURED, Boolean.parseBoolean(prop.toString())); } if (isDialog && ((Dialog) target).getModalityType() == ModalityType.DOCUMENT_MODAL) { prop = rootpane.getClientProperty(WINDOW_DOC_MODAL_SHEET); if (prop != null) { styleBits = SET(styleBits, SHEET, Boolean.parseBoolean(prop.toString())); } } prop = rootpane.getClientProperty(WINDOW_STYLE); if (prop != null) { if ("small".equals(prop)) { styleBits = SET(styleBits, UTILITY, true); if (target.isAlwaysOnTop() && rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE) == null) { styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, true); } } if ("textured".equals(prop)) styleBits = SET(styleBits, TEXTURED, true); if ("unified".equals(prop)) styleBits = SET(styleBits, UNIFIED, true); if ("hud".equals(prop)) styleBits = SET(styleBits, HUD, true); } prop = rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE); if (prop != null) { styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, Boolean.parseBoolean(prop.toString())); } prop = rootpane.getClientProperty(WINDOW_CLOSEABLE); if (prop != null) { styleBits = SET(styleBits, CLOSEABLE, Boolean.parseBoolean(prop.toString())); } prop = rootpane.getClientProperty(WINDOW_MINIMIZABLE); if (prop != null) { styleBits = SET(styleBits, MINIMIZABLE, Boolean.parseBoolean(prop.toString())); } prop = rootpane.getClientProperty(WINDOW_ZOOMABLE); if (prop != null) { styleBits = SET(styleBits, ZOOMABLE, Boolean.parseBoolean(prop.toString())); } prop = rootpane.getClientProperty(WINDOW_FULLSCREENABLE); if (prop != null) { styleBits = SET(styleBits, FULLSCREENABLE, Boolean.parseBoolean(prop.toString())); } prop = rootpane.getClientProperty(WINDOW_SHADOW); if (prop != null) { styleBits = SET(styleBits, HAS_SHADOW, Boolean.parseBoolean(prop.toString())); } prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND); if (prop != null) { styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString())); } } if (isDialog) { styleBits = SET(styleBits, IS_DIALOG, true); if (((Dialog) target).isModal()) { styleBits = SET(styleBits, IS_MODAL, true); } } peer.setTextured(IS(TEXTURED, styleBits)); return styleBits; }
/* * An utility method for the support of the auto request focus. * Updates the focusable state of the window under certain * circumstances. */ private void updateFocusabilityForAutoRequestFocus(boolean isFocusable) { if (target.isAutoRequestFocus() || !isNativelyFocusableWindow()) return; setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once }
public void actionPerformed(ActionEvent e) { if (palette != null) { putValue(Actions.SELECTED_KEY, !palette.isVisible()); } }