示例#1
0
  /*
   * Tracks changes of available formats.
   * NOTE: This method may be called by privileged threads.
   *       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
   */
  private void checkChange(XSelectionEvent xse) {
    final long propertyAtom = xse.get_property();
    if (propertyAtom != getTargetsPropertyAtom().getAtom()) {
      // wrong atom
      return;
    }

    final XAtom selectionAtom = XAtom.get(xse.get_selection());
    final XSelection changedSelection = XSelection.getSelection(selectionAtom);

    if (null == changedSelection || changedSelection != selection) {
      // unknown selection - do nothing
      return;
    }

    isSelectionNotifyProcessed = true;

    if (selection.isOwner()) {
      // selection is owner - do not need formats
      return;
    }

    long[] formats = null;

    if (propertyAtom == XConstants.None) {
      // We treat None property atom as "empty selection".
      formats = new long[0];
    } else {
      WindowPropertyGetter targetsGetter =
          new WindowPropertyGetter(
              XWindow.getXAWTRootWindow().getWindow(),
              XAtom.get(propertyAtom),
              0,
              XSelection.MAX_LENGTH,
              true,
              XConstants.AnyPropertyType);
      try {
        targetsGetter.execute();
        formats = XSelection.getFormats(targetsGetter);
      } finally {
        targetsGetter.dispose();
      }
    }

    checkChange(formats);
  }
示例#2
0
 public void dispatchEvent(XEvent ev) {
   if (ev.get_type() == XConstants.SelectionNotify) {
     final XSelectionEvent xse = ev.get_xselection();
     XClipboard clipboard = null;
     synchronized (XClipboard.classLock) {
       if (targetsAtom2Clipboard != null && !targetsAtom2Clipboard.isEmpty()) {
         XToolkit.removeEventDispatcher(XWindow.getXAWTRootWindow().getWindow(), this);
         return;
       }
       final long propertyAtom = xse.get_property();
       clipboard = targetsAtom2Clipboard.get(propertyAtom);
     }
     if (null != clipboard) {
       clipboard.checkChange(xse);
     }
   }
 }