Search in sources :

Example 1 with FlavorEvent

use of java.awt.datatransfer.FlavorEvent in project jdk8u_jdk by JetBrains.

the class SunClipboard method checkChange.

/**
     * Checks change of the <code>DataFlavor</code>s and, if necessary,
     * posts notifications on <code>FlavorEvent</code>s to the
     * AppContexts' EDTs.
     * The parameter <code>formats</code> is null iff we have just
     * failed to get formats available on the clipboard.
     *
     * @param formats data formats that have just been retrieved from
     *        this clipboard
     */
protected final void checkChange(final long[] formats) {
    if (Arrays.equals(formats, currentFormats)) {
        // don't notify
        return;
    }
    currentFormats = formats;
    class SunFlavorChangeNotifier implements Runnable {

        private final FlavorListener flavorListener;

        SunFlavorChangeNotifier(FlavorListener flavorListener) {
            this.flavorListener = flavorListener;
        }

        public void run() {
            if (flavorListener != null) {
                flavorListener.flavorsChanged(new FlavorEvent(SunClipboard.this));
            }
        }
    }
    ;
    for (Iterator it = AppContext.getAppContexts().iterator(); it.hasNext(); ) {
        AppContext appContext = (AppContext) it.next();
        if (appContext == null || appContext.isDisposed()) {
            continue;
        }
        EventListenerAggregate flavorListeners = (EventListenerAggregate) appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
        if (flavorListeners != null) {
            FlavorListener[] flavorListenerArray = (FlavorListener[]) flavorListeners.getListenersInternal();
            for (int i = 0; i < flavorListenerArray.length; i++) {
                SunToolkit.postEvent(appContext, new PeerEvent(this, new SunFlavorChangeNotifier(flavorListenerArray[i]), PeerEvent.PRIORITY_EVENT));
            }
        }
    }
}
Also used : EventListenerAggregate(sun.awt.EventListenerAggregate) FlavorEvent(java.awt.datatransfer.FlavorEvent) PeerEvent(sun.awt.PeerEvent) AppContext(sun.awt.AppContext) Iterator(java.util.Iterator) FlavorListener(java.awt.datatransfer.FlavorListener)

Example 2 with FlavorEvent

use of java.awt.datatransfer.FlavorEvent in project deltahex-java by exbin.

the class DeltaHexEditorBasic method postInit.

private void postInit() {
    codeArea.setComponentPopupMenu(mainPopupMenu);
    setIconImage(new javax.swing.ImageIcon(getClass().getResource("/org/exbin/deltahex/editor/basic/resources/icons/icon.png")).getImage());
    undoHandler.addUndoUpdateListener(new BinaryDataUndoUpdateListener() {

        @Override
        public void undoCommandPositionChanged() {
            updateUndoState();
            codeArea.repaint();
        }

        @Override
        public void undoCommandAdded(@Nonnull BinaryDataCommand command) {
            updateUndoState();
            codeArea.repaint();
        }
    });
    ((EditationModeCapable) codeArea.getWorker()).addEditationModeChangedListener(new EditationModeChangedListener() {

        @Override
        public void editationModeChanged(EditationMode editationMode) {
            switch(editationMode) {
                case INSERT:
                    {
                        editationModeLabel.setText("INS");
                        break;
                    }
                case OVERWRITE:
                    {
                        editationModeLabel.setText("OVR");
                        break;
                    }
                default:
                    {
                        throw new IllegalStateException("Unexpected editation mode " + editationMode.name());
                    }
            }
        }
    });
    ((CaretCapable) codeArea.getWorker()).addCaretMovedListener(new CaretMovedListener() {

        @Override
        public void caretMoved(CaretPosition caretPosition) {
            positionLabel.setText(caretPosition.getDataPosition() + ":" + caretPosition.getCodeOffset());
        }
    });
    ((SelectionCapable) codeArea.getWorker()).addSelectionChangedListener(new SelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionRange selection) {
            updateClipboardState();
        }
    });
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.addFlavorListener(new FlavorListener() {

        @Override
        public void flavorsChanged(FlavorEvent e) {
            updateClipboardState();
        }
    });
    updateUndoState();
    updateClipboardState();
    openFileButton.setText("Open");
}
Also used : SelectionChangedListener(org.exbin.deltahex.SelectionChangedListener) FlavorEvent(java.awt.datatransfer.FlavorEvent) EditationModeCapable(org.exbin.deltahex.capability.EditationModeCapable) EditationMode(org.exbin.deltahex.EditationMode) BinaryDataCommand(org.exbin.deltahex.operation.BinaryDataCommand) CaretCapable(org.exbin.deltahex.capability.CaretCapable) BinaryDataUndoUpdateListener(org.exbin.deltahex.operation.undo.BinaryDataUndoUpdateListener) CaretMovedListener(org.exbin.deltahex.CaretMovedListener) SelectionRange(org.exbin.deltahex.SelectionRange) CaretPosition(org.exbin.deltahex.CaretPosition) Clipboard(java.awt.datatransfer.Clipboard) FlavorListener(java.awt.datatransfer.FlavorListener) EditationModeChangedListener(org.exbin.deltahex.EditationModeChangedListener) SelectionCapable(org.exbin.deltahex.capability.SelectionCapable)

Aggregations

FlavorEvent (java.awt.datatransfer.FlavorEvent)2 FlavorListener (java.awt.datatransfer.FlavorListener)2 Clipboard (java.awt.datatransfer.Clipboard)1 Iterator (java.util.Iterator)1 CaretMovedListener (org.exbin.deltahex.CaretMovedListener)1 CaretPosition (org.exbin.deltahex.CaretPosition)1 EditationMode (org.exbin.deltahex.EditationMode)1 EditationModeChangedListener (org.exbin.deltahex.EditationModeChangedListener)1 SelectionChangedListener (org.exbin.deltahex.SelectionChangedListener)1 SelectionRange (org.exbin.deltahex.SelectionRange)1 CaretCapable (org.exbin.deltahex.capability.CaretCapable)1 EditationModeCapable (org.exbin.deltahex.capability.EditationModeCapable)1 SelectionCapable (org.exbin.deltahex.capability.SelectionCapable)1 BinaryDataCommand (org.exbin.deltahex.operation.BinaryDataCommand)1 BinaryDataUndoUpdateListener (org.exbin.deltahex.operation.undo.BinaryDataUndoUpdateListener)1 AppContext (sun.awt.AppContext)1 EventListenerAggregate (sun.awt.EventListenerAggregate)1 PeerEvent (sun.awt.PeerEvent)1