public WPopupMenuPeer(PopupMenu target) { this.target = target; MenuContainer parent = null; boolean isTrayIconPopup = false; 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 inquireCandidatePosition() { Component source = getClientComponent(); if (source == null) { return; } // This call should return immediately just to cause // InputMethodRequests.getTextLocation be called within // AWT Event thread. Otherwise, a potential deadlock // could happen. Runnable r = new Runnable() { public void run() { int x = 0; int y = 0; Component client = getClientComponent(); if (client != null) { if (haveActiveClient()) { Rectangle rc = inputContext.getTextLocation(TextHitInfo.leading(0)); x = rc.x; y = rc.y + rc.height; } else { Point pt = client.getLocationOnScreen(); Dimension size = client.getSize(); x = pt.x; y = pt.y + size.height; } } openCandidateWindow(awtFocussedComponentPeer, x, y); } }; WToolkit.postEvent(WToolkit.targetToAppContext(source), new InvocationEvent(source, r)); }
/* * This overloaded method is for TrayIcon. * Its popup has special parent. */ void show(Component origin, Point p) { WComponentPeer peer = (WComponentPeer) WToolkit.targetToPeer(origin); Event e = new Event(origin, 0, Event.MOUSE_DOWN, p.x, p.y, 0, 0); if (peer == null) { Component nativeOrigin = WToolkit.getNativeContainer(origin); e.target = nativeOrigin; } e.x = p.x; e.y = p.y; _show(e); }
// Toolkit & peer internals WMenuBarPeer(MenuBar target) { this.target = target; WFramePeer framePeer = (WFramePeer) WToolkit.targetToPeer(target.getParent()); create(framePeer); // fix for 5088782: check if menu object is created successfully checkMenuCreation(); }
// Note: Because this method calls resize(), which may be overridden // by client code, this method must not be executed on the toolkit // thread. @Override public void setMenuBar(MenuBar mb) { WMenuBarPeer mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb); if (mbPeer != null) { if (mbPeer.framePeer != this) { mb.removeNotify(); mb.addNotify(); mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb); if (mbPeer != null && mbPeer.framePeer != this) { throw new IllegalStateException("Wrong parent peer"); } } if (mbPeer != null) { addChildPeer(mbPeer); } } setMenuBar0(mbPeer); updateInsets(insets_); }
public void show(Event e) { Component origin = (Component) e.target; WComponentPeer peer = (WComponentPeer) WToolkit.targetToPeer(origin); if (peer == null) { // A failure to map the peer should only happen for a // lightweight component, then find the actual native parent from // that component. The event coorinates are going to have to be // remapped as well. Component nativeOrigin = WToolkit.getNativeContainer(origin); e.target = nativeOrigin; // remove the event coordinates for (Component c = origin; c != nativeOrigin; c = c.getParent()) { Point p = c.getLocation(); e.x += p.x; e.y += p.y; } } _show(e); }
void handleAction(final int index, final long when, final int modifiers) { final List l = (List) target; WToolkit.executeOnEventHandlerThread( l, new Runnable() { public void run() { l.select(index); postEvent( new ActionEvent( target, ActionEvent.ACTION_PERFORMED, l.getItem(index), when, modifiers)); } }); }
void handleListChanged(final int index) { final List l = (List) target; WToolkit.executeOnEventHandlerThread( l, new Runnable() { public void run() { postEvent( new ItemEvent( l, ItemEvent.ITEM_STATE_CHANGED, new Integer(index), isSelected(index) ? ItemEvent.SELECTED : ItemEvent.DESELECTED)); } }); }
public void sendInputMethodEvent( int id, long when, String text, int[] clauseBoundary, String[] clauseReading, int[] attributeBoundary, byte[] attributeValue, int commitedTextLength, int caretPos, int visiblePos) { AttributedCharacterIterator iterator = null; if (text != null) { // construct AttributedString AttributedString attrStr = new AttributedString(text); // set Language Information attrStr.addAttribute(Attribute.LANGUAGE, Locale.getDefault(), 0, text.length()); // set Clause and Reading Information if (clauseBoundary != null && clauseReading != null && clauseReading.length != 0 && clauseBoundary.length == clauseReading.length + 1 && clauseBoundary[0] == 0 && clauseBoundary[clauseReading.length] == text.length()) { for (int i = 0; i < clauseBoundary.length - 1; i++) { attrStr.addAttribute( Attribute.INPUT_METHOD_SEGMENT, new Annotation(null), clauseBoundary[i], clauseBoundary[i + 1]); attrStr.addAttribute( Attribute.READING, new Annotation(clauseReading[i]), clauseBoundary[i], clauseBoundary[i + 1]); } } else { // if (clauseBoundary != null) // System.out.println("Invalid clause information!"); attrStr.addAttribute( Attribute.INPUT_METHOD_SEGMENT, new Annotation(null), 0, text.length()); attrStr.addAttribute(Attribute.READING, new Annotation(""), 0, text.length()); } // set Hilight Information if (attributeBoundary != null && attributeValue != null && attributeValue.length != 0 && attributeBoundary.length == attributeValue.length + 1 && attributeBoundary[0] == 0 && attributeBoundary[attributeValue.length] == text.length()) { for (int i = 0; i < attributeBoundary.length - 1; i++) { InputMethodHighlight highlight; switch (attributeValue[i]) { case ATTR_TARGET_CONVERTED: highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT; break; case ATTR_CONVERTED: highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT; break; case ATTR_TARGET_NOTCONVERTED: highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT; break; case ATTR_INPUT: case ATTR_INPUT_ERROR: default: highlight = InputMethodHighlight.UNSELECTED_RAW_TEXT_HIGHLIGHT; break; } attrStr.addAttribute( TextAttribute.INPUT_METHOD_HIGHLIGHT, highlight, attributeBoundary[i], attributeBoundary[i + 1]); } } else { // if (attributeBoundary != null) // System.out.println("Invalid attribute information!"); attrStr.addAttribute( TextAttribute.INPUT_METHOD_HIGHLIGHT, InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT, 0, text.length()); } // get iterator iterator = attrStr.getIterator(); } Component source = getClientComponent(); if (source == null) return; InputMethodEvent event = new InputMethodEvent( source, id, when, iterator, commitedTextLength, TextHitInfo.leading(caretPos), TextHitInfo.leading(visiblePos)); WToolkit.postEvent(WToolkit.targetToAppContext(source), event); }
/* * Called from Windows in response to WM_VSCROLL/WM_HSCROLL message */ private void postScrollEvent(int orient, int type, int pos, boolean isAdjusting) { Runnable adjustor = new Adjustor(orient, type, pos, isAdjusting); WToolkit.executeOnEventHandlerThread(new ScrollEvent(target, adjustor)); }
@Override final WComponentPeer getNativeParent() { final Container owner = ((Window) target).getOwner(); return (WComponentPeer) WToolkit.targetToPeer(owner); }