/** * Validate all of the components that have been marked invalid. * @see #addInvalidComponent */ public void validateInvalidComponents() { final java.util.List<Component> ic; synchronized(this) { if (invalidComponents == null) { return; } ic = invalidComponents; invalidComponents = null; } int n = ic.size(); for(int i = 0; i < n; i++) { final Component c = ic.get(i); AccessControlContext stack = AccessController.getContext(); AccessControlContext acc = AWTAccessor.getComponentAccessor().getAccessControlContext(c); javaSecurityAccess.doIntersectionPrivilege( new PrivilegedAction<Void>() { public Void run() { c.validate(); return null; } }, stack, acc); } }
public Component run() { try { final Component component = createNoPermsComponent(); // 6482575 - clear the appContext field so as not to leak it AWTAccessor.getComponentAccessor(). setAppContext(component, null); return component; } catch (Throwable e) { // We don't care about component. // So don't prevent class initialisation. e.printStackTrace(); return null; } }
private LWComponentPeer<?, ?> getNearestNativePeer(Component comp) { if (comp==null) return null; final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); ComponentPeer peer = acc.getPeer(comp); if (peer==null) return null; while (peer instanceof java.awt.peer.LightweightPeer) { comp = comp.getParent(); if (comp==null) return null; peer = acc.getPeer(comp); if (peer==null) return null; } if (peer instanceof LWComponentPeer) return (LWComponentPeer)peer; return null; }
boolean isFocusedWindowModalBlocker() { Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow(); XWindowPeer focusedWindowPeer = null; if (focusedWindow != null) { focusedWindowPeer = (XWindowPeer)AWTAccessor.getComponentAccessor().getPeer(focusedWindow); } else { /* * For the case when a potential blocked window is not yet focused * on the Java level (e.g. it's just been mapped) we're asking for the * focused window on the native level. */ focusedWindowPeer = getNativeFocusedWindowPeer(); } synchronized (getStateLock()) { if (focusedWindowPeer != null && focusedWindowPeer.modalBlocker == target) { return true; } } return super.isFocusedWindowModalBlocker(); }
void nativeQueueSurfaceDataRunnable(AppContext appContext, final Component c, final Runnable r) { synchronized(this) { if (runnableList == null) { runnableList = new LinkedList<Runnable>(); } runnableList.add(new Runnable() { public void run() { AccessControlContext stack = AccessController.getContext(); AccessControlContext acc = AWTAccessor.getComponentAccessor().getAccessControlContext(c); javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() { public Void run() { r.run(); return null; } }, stack, acc); } }); } scheduleProcessingRunnable(appContext); }
@Override public synchronized void showPopupMenu(final int x, final int y) { if (isDisposed()) return; SunToolkit.executeOnEventHandlerThread(target, () -> { PopupMenu newPopup = ((TrayIcon)target).getPopupMenu(); if (popup != newPopup) { if (popup != null) { popupParent.remove(popup); } if (newPopup != null) { popupParent.add(newPopup); } popup = newPopup; } if (popup != null) { WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor() .getPeer(popup); peer.show(popupParent, new Point(x, y)); } }); }
/** * Invokes a {@code Callable} in the {@code AppContext} mapped to the given {@code AccessibleContext} * and waits for it to finish blocking the caller thread. * * @param callable the {@code Callable} to invoke * @param accessibleContext the {@code AccessibleContext} which would be used to determine the right * context for the task execution. * @param <T> type parameter for the result value * * @return the result of the {@code Callable} execution */ public static <T> T invokeAndWait(final Callable<T> callable, final AccessibleContext accessibleContext) { AppContext targetContext = AWTAccessor.getAccessibleContextAccessor() .getAppContext(accessibleContext); if (targetContext != null) { return invokeAndWait(callable, targetContext); } else { // Normally this should not happen, unmapped context provided and // the target AppContext is unknown. // Try to recover in case the context is a translator. if (accessibleContext instanceof Translator) { Object source = ((Translator)accessibleContext).getSource(); if (source instanceof Component) { return invokeAndWait(callable, (Component)source); } } } throw new RuntimeException("Unmapped AccessibleContext used to dispatch event: " + accessibleContext); }
/** * handle the cancel event */ void handleCancel() { KeyboardFocusManager.getCurrentKeyboardFocusManager() .removeKeyEventDispatcher(this); setSelectionField(null); setFilterField(null); directoryList.clear(); fileList.clear(); AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor(); fileDialogAccessor.setDirectory(target, null); fileDialogAccessor.setFile(target, null); fileDialogAccessor.setFiles(target, null); handleQuitButton(); }
public void setBackground(Color c) { Component comp; int i; Container cont = (Container) target; final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); synchronized(target.getTreeLock()) { int n = cont.getComponentCount(); for(i=0; i < n; i++) { comp = cont.getComponent(i); ComponentPeer peer = acc.getPeer(comp); if (peer != null) { Color color = comp.getBackground(); if (color == null || color.equals(c)) { peer.setBackground(c); } } } } super.setBackground(c); }
/** * called from XFramePeer.setMenuBar */ public void init(Frame frame) { this.target = frame; this.framePeer = AWTAccessor.getComponentAccessor().getPeer(frame); XCreateWindowParams params = getDelayedParams(); params.remove(DELAYED); params.add(PARENT_WINDOW, framePeer.getShell()); params.add(TARGET, frame); init(params); }
/** * Gets the size of the security warning. * * The returned value is not valid until the peer has been created. Before * invoking this method a developer must call the {@link Window#pack()}, * {@link Window#setVisible()}, or some other method that creates the peer. * * @param window the window to get the security warning size for * * @throws NullPointerException if the window argument is null * @throws IllegalArgumentException if the window is trusted (i.e. * the {@code getWarningString()} returns null) */ public static Dimension getSize(Window window) { if (window == null) { throw new NullPointerException( "The window argument should not be null."); } if (window.getWarningString() == null) { throw new IllegalArgumentException( "The window must have a non-null warning string."); } // We don't check for a non-null peer since it may be destroyed // after assigning a valid value to the security warning size. return AWTAccessor.getWindowAccessor().getSecurityWarningSize(window); }
void setReparented(boolean newValue) { super.setReparented(newValue); XToolkit.awtLock(); try { if (isReparented() && delayedModalBlocking) { addToTransientFors((XDialogPeer) AWTAccessor.getComponentAccessor().getPeer(modalBlocker)); delayedModalBlocking = false; } } finally { XToolkit.awtUnlock(); } }
protected void setCursor(Component comp, Cursor cursor, boolean useCache) { if (comp == null) { return; } Cursor cur = useCache ? cursor : getCapableCursor(comp); Component nc = null; if (useCache) { synchronized (this) { nc = nativeContainer.get(); } } else { nc = SunToolkit.getHeavyweightComponent(comp); } if (nc != null) { ComponentPeer nc_peer = AWTAccessor.getComponentAccessor().getPeer(nc); if (nc_peer instanceof XComponentPeer) { synchronized (this) { nativeContainer = new WeakReference<Component>(nc); } //6431076. A subcomponents (a XTextArea in particular) //may want to override the cursor over some of their parts. ((XComponentPeer)nc_peer).pSetCursor(cur, false); // in case of grab we do for Swing we need to update keep cursor updated // (we don't need this in case of AWT menus). Window Manager consider // the grabber as a current window and use its cursor. So we need to // change cursor on the grabber too. updateGrabbedCursor(cur); } } }
private static void initialize() { Properties swingProps = loadSwingProperties(); initializeSystemDefaults(swingProps); initializeDefaultLAF(swingProps); initializeAuxiliaryLAFs(swingProps); initializeInstalledLAFs(swingProps); // Install Swing's PaintEventDispatcher if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) { sun.awt.PaintEventDispatcher.setPaintEventDispatcher( new SwingPaintEventDispatcher()); } // Install a hook that will be invoked if no one consumes the // KeyEvent. If the source isn't a JComponent this will process // key bindings, if the source is a JComponent it implies that // processKeyEvent was already invoked and thus no need to process // the bindings again, unless the Component is disabled, in which // case KeyEvents will no longer be dispatched to it so that we // handle it here. KeyboardFocusManager.getCurrentKeyboardFocusManager(). addKeyEventPostProcessor(new KeyEventPostProcessor() { public boolean postProcessKeyEvent(KeyEvent e) { Component c = e.getComponent(); if ((!(c instanceof JComponent) || (c != null && !c.isEnabled())) && JComponent.KeyboardState.shouldProcess(e) && SwingUtilities.processKeyBindings(e)) { e.consume(); return true; } return false; } }); AWTAccessor.getComponentAccessor(). setRequestFocusController(JComponent.focusController); }
private void updateIconSize() { int newSize = -1; if (ownerWindow != null) { Insets insets = ownerWindow.getInsets(); int max = Math.max(insets.top, Math.max(insets.bottom, Math.max(insets.left, insets.right))); if (max < 24) { newSize = 0; } else if (max < 32) { newSize = 1; } else if (max < 48) { newSize = 2; } else { newSize = 3; } } // Make sure we have a valid size if (newSize == -1) { newSize = 0; } synchronized (lock) { if (newSize != currentSize) { currentSize = newSize; IconInfo ico = getSecurityIconInfo(currentSize, 0); AWTAccessor.getWindowAccessor().setSecurityWarningSize( ownerWindow, ico.getWidth(), ico.getHeight()); } } }
public static CAccessible getCAccessible(final Accessible a) { if (a == null) return null; AccessibleContext context = a.getAccessibleContext(); AWTAccessor.AccessibleContextAccessor accessor = AWTAccessor.getAccessibleContextAccessor(); final CAccessible cachedCAX = (CAccessible) accessor.getNativeAXResource(context); if (cachedCAX != null) { return cachedCAX; } final CAccessible newCAX = new CAccessible(a); accessor.setNativeAXResource(context, newCAX); return newCAX; }
/** * Gets the size of the security warning. * * The returned value is not valid until the peer has been created. Before * invoking this method a developer must call the {@link Window#pack()}, * {@link Window#setVisible}, or some other method that creates the peer. * * @param window the window to get the security warning size for * * @throws NullPointerException if the window argument is null * @throws IllegalArgumentException if the window is trusted (i.e. * the {@code getWarningString()} returns null) */ public static Dimension getSize(Window window) { if (window == null) { throw new NullPointerException( "The window argument should not be null."); } if (window.getWarningString() == null) { throw new IllegalArgumentException( "The window must have a non-null warning string."); } // We don't check for a non-null peer since it may be destroyed // after assigning a valid value to the security warning size. return AWTAccessor.getWindowAccessor().getSecurityWarningSize(window); }
private static final boolean isContainingTopLevelAccelCapable(Component c) { while (c != null && !(c instanceof WEmbeddedFrame)) { c = c.getParent(); } if (c == null) { return true; } final WEmbeddedFramePeer peer = AWTAccessor.getComponentAccessor() .getPeer(c); return peer.isAccelCapable(); }
@Override public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER()); putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); }
void handleCancel() { final FileDialog fileDialog = (FileDialog)target; AWTAccessor.getFileDialogAccessor().setFile(fileDialog, null); AWTAccessor.getFileDialogAccessor().setFiles(fileDialog, null); AWTAccessor.getFileDialogAccessor().setDirectory(fileDialog, null); WToolkit.executeOnEventHandlerThread(fileDialog, new Runnable() { @Override public void run() { fileDialog.setVisible(false); } }); }
WPopupMenuPeer(PopupMenu target) { this.target = target; MenuContainer parent = null; // We can't use target.getParent() for TrayIcon popup // because this method should return null for the TrayIcon // popup regardless of that whether it has parent or not. boolean isTrayIconPopup = AWTAccessor.getPopupMenuAccessor().isTrayIconPopup(target); if (isTrayIconPopup) { parent = AWTAccessor.getMenuComponentAccessor().getParent(target); } else { parent = target.getParent(); } if (parent instanceof Component) { WComponentPeer parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent); if (parentPeer == null) { // because the menu isn't a component (sigh) we first have to wait // for a failure to map the peer which should only happen for a // lightweight container, then find the actual native parent from // that component. parent = WToolkit.getNativeContainer((Component)parent); parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent); } createMenu(parentPeer); // fix for 5088782: check if menu object is created successfully checkMenuCreation(); } else { throw new IllegalArgumentException( "illegal popup menu container class"); } }
public void instrumentPeer() { origPeer = AWTAccessor.getComponentAccessor().getPeer(this); InvocationHandler handler = new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) { if (method.getName().equals("requestFocus")) { Container parent = getParent(); parent.remove(TestButton.this); System.err.println("parent = " + parent); System.err.println("target = " + TestButton.this); System.err.println("new parent = " + TestButton.this.getParent()); } Object ret = null; try { ret = method.invoke(origPeer, args); } catch (IllegalAccessException iae) { throw new Error("Test error.", iae); } catch (InvocationTargetException ita) { throw new Error("Test error.", ita); } return ret; } }; proxiedPeer = (ButtonPeer) Proxy.newProxyInstance( ButtonPeer.class.getClassLoader(), new Class[] {ButtonPeer.class}, handler); setPeer(proxiedPeer); }
private void postPaintIfNecessary(int x, int y, int w, int h) { if ( !AWTAccessor.getComponentAccessor().getIgnoreRepaint( (Component) target) ) { PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher(). createPaintEvent((Component)target, x, y, w, h); if (event != null) { postEvent(event); } } }
@Override public boolean updateGraphicsData(GraphicsConfiguration gc) { boolean result = super.updateGraphicsData(gc); Rectangle bounds = AWTAccessor.getFrameAccessor(). getMaximizedBounds((Frame)target); if (bounds != null) { setMaximizedBounds(bounds); } return result; }
final void dumpTarget() { AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); int getWidth = compAccessor.getWidth(target); int getHeight = compAccessor.getHeight(target); int getTargetX = compAccessor.getX(target); int getTargetY = compAccessor.getY(target); System.err.println(">>> Target: " + getTargetX + ", " + getTargetY + ", " + getWidth + ", " + getHeight); }
@Override public void setCurrentFocusedWindow(Window win) { if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("Setting current focused window " + win); } XWindowPeer from = null, to = null; synchronized(this) { if (currentFocusedWindow != null) { from = (XWindowPeer)AWTAccessor.getComponentAccessor().getPeer(currentFocusedWindow); } currentFocusedWindow = win; if (currentFocusedWindow != null) { to = (XWindowPeer)AWTAccessor.getComponentAccessor().getPeer(currentFocusedWindow); } } if (from != null) { from.updateSecurityWarningVisibility(); } if (to != null) { to.updateSecurityWarningVisibility(); } }
@Override public void grab(Window w) { final Object peer = AWTAccessor.getComponentAccessor().getPeer(w); if (peer != null) { ((WWindowPeer) peer).grab(); } }
XAWTTextField(String text, XComponentPeer xwin, Container parent) { super(text); this.xwin = xwin; setDoubleBuffered(true); setFocusable(false); AWTAccessor.getComponentAccessor().setParent(this,parent); setBackground(xwin.getPeerBackground()); setForeground(xwin.getPeerForeground()); setFont(xwin.getPeerFont()); setCaretPosition(0); addActionListener(this); addNotify(); }
public void setIcon(final Icon i) { Object peer = AWTAccessor.getMenuComponentAccessor().getPeer(this); if (!(peer instanceof CMenuItem)) return; final CMenuItem cmi = (CMenuItem)peer; Image img = null; if (i != null) { if (i.getIconWidth() > 0 && i.getIconHeight() > 0) { img = AquaIcon.getImageForIcon(i); } } cmi.setImage(img); }
/** * Test fails if it throws any exception. * * @throws Exception */ private void init() throws Exception { if (!System.getProperty("os.name").startsWith("Windows")) { System.out.println("This is Windows only test."); return; } Frame frame = new Frame("AWT Frame"); frame.pack(); FramePeer frame_peer = AWTAccessor.getComponentAccessor() .getPeer(frame); Class comp_peer_class = Class.forName("sun.awt.windows.WComponentPeer"); Field hwnd_field = comp_peer_class.getDeclaredField("hwnd"); hwnd_field.setAccessible(true); long hwnd = hwnd_field.getLong(frame_peer); Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame"); Constructor constructor = clazz .getConstructor(new Class[]{long.class}); Frame embedded_frame = (Frame) constructor .newInstance(new Object[]{new Long(hwnd)}); frame.setVisible(true); ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer( embedded_frame); Class peerClass = peer.getClass(); Method displayChangedM = peerClass.getMethod("displayChanged", new Class[0]); displayChangedM.invoke(peer, null); embedded_frame.dispose(); frame.dispose(); }
String getTargetLabel() { if (target == null) { return ""; } String label = AWTAccessor.getMenuItemAccessor().getLabel(target); return (label == null) ? "" : label; }
protected boolean traverseOut(boolean direction) { XEmbeddedFramePeer xefp = AWTAccessor.getComponentAccessor() .getPeer(this); if (direction == FORWARD) { xefp.traverseOutForward(); } else { xefp.traverseOutBackward(); } return true; }
private void dispatch( MouseEvent event ) { switch( current.getType() ) { case TEXT: Point point = toViewportChildLocalSpace( outer.textPane.getViewport(), event.getPoint() ); XTextAreaPeer.AWTTextArea jtext = outer.jtext; MouseEvent newEvent = newMouseEvent( jtext, point, event ); int id = newEvent.getID(); if ( id==MouseEvent.MOUSE_MOVED || id==MouseEvent.MOUSE_DRAGGED ) { jtext.processMouseMotionEventPublic( newEvent ); } else { jtext.processMouseEventPublic( newEvent ); } break; // We perform (additional) dispatching of events to buttons of // scrollbar, instead of leaving it to JScrollbar. This is // required, because of different listeners in Swing and AWT, // which trigger scrolling (ArrowButtonListener vs. TrackListener, // accordingly). So we dispatch events to scroll-buttons, to // invoke a correct Swing button listener. // See CR 6175401 for more information. case BAR: case BUTTON: Component c = current.getBar(); Point p = toLocalSpace( c, event.getPoint() ); if ( current.getType()==Pointer.Type.BUTTON ) { c = current.getButton(); p = toLocalSpace( c, p ); } AWTAccessor.getComponentAccessor().processEvent( c, newMouseEvent( c, p, event ) ); break; } }
/** * Called exclusively by the native C code. */ private void setFileInternal(String directory, String[] filenames) { AWTAccessor.FileDialogAccessor accessor = AWTAccessor .getFileDialogAccessor(); if (filenames == null) { accessor.setDirectory(fd, null); accessor.setFile(fd, null); accessor.setFiles(fd, null); } else { // Fix 6987233: add the trailing slash if it's absent String with_separator = directory; if (directory != null) { with_separator = directory.endsWith(File.separator) ? directory : (directory + File.separator); } accessor.setDirectory(fd, with_separator); accessor.setFile(fd, filenames[0]); int filesNumber = (filenames != null) ? filenames.length : 0; File[] files = new File[filesNumber]; for (int i = 0; i < filesNumber; i++) { files[i] = new File(directory, filenames[i]); } accessor.setFiles(fd, files); } }
public Graphics getGraphics() { AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); return getGraphics(content.surfaceData, compAccessor.getForeground(target), compAccessor.getBackground(target), compAccessor.getFont(target)); }