src/share/classes/java/awt/datatransfer/Clipboard.java

Print this page

        

*** 65,75 **** /** * An aggregate of flavor listeners registered on this local clipboard. * * @since 1.5 */ ! private final Set<FlavorListener> flavorListeners = new HashSet<>(); /** * A set of <code>DataFlavor</code>s that is available on * this local clipboard. It is used for tracking changes * of <code>DataFlavor</code>s available on this clipboard. --- 65,75 ---- /** * An aggregate of flavor listeners registered on this local clipboard. * * @since 1.5 */ ! private Set<FlavorListener> flavorListeners; /** * A set of <code>DataFlavor</code>s that is available on * this local clipboard. It is used for tracking changes * of <code>DataFlavor</code>s available on this clipboard.
*** 83,93 **** * @param name for the clipboard * @see java.awt.Toolkit#getSystemClipboard */ public Clipboard(String name) { this.name = name; - currentDataFlavors = getAvailableDataFlavorSet(); } /** * Returns the name of this clipboard object. * @return the name of this clipboard object --- 83,92 ----
*** 255,264 **** --- 254,269 ---- */ public synchronized void addFlavorListener(FlavorListener listener) { if (listener == null) { return; } + + if (flavorListeners == null) { + flavorListeners = new HashSet<>(); + currentDataFlavors = getAvailableDataFlavorSet(); + } + flavorListeners.add(listener); } /** * Removes the specified <code>FlavorListener</code> so that it no longer
*** 276,286 **** * @see FlavorListener * @see FlavorEvent * @since 1.5 */ public synchronized void removeFlavorListener(FlavorListener listener) { ! if (listener == null) { return; } flavorListeners.remove(listener); } --- 281,291 ---- * @see FlavorListener * @see FlavorEvent * @since 1.5 */ public synchronized void removeFlavorListener(FlavorListener listener) { ! if (listener == null || flavorListeners == null) { return; } flavorListeners.remove(listener); }
*** 295,315 **** * @see FlavorListener * @see FlavorEvent * @since 1.5 */ public synchronized FlavorListener[] getFlavorListeners() { ! return flavorListeners.toArray(new FlavorListener[flavorListeners.size()]); } /** * Checks change of the <code>DataFlavor</code>s and, if necessary, * notifies all listeners that have registered interest for notification * on <code>FlavorEvent</code>s. * * @since 1.5 */ private void fireFlavorsChanged() { Set<DataFlavor> prevDataFlavors = currentDataFlavors; currentDataFlavors = getAvailableDataFlavorSet(); if (Objects.equals(prevDataFlavors, currentDataFlavors)) { return; } --- 300,325 ---- * @see FlavorListener * @see FlavorEvent * @since 1.5 */ public synchronized FlavorListener[] getFlavorListeners() { ! return flavorListeners == null ? new FlavorListener[0] : ! flavorListeners.toArray(new FlavorListener[flavorListeners.size()]); } /** * Checks change of the <code>DataFlavor</code>s and, if necessary, * notifies all listeners that have registered interest for notification * on <code>FlavorEvent</code>s. * * @since 1.5 */ private void fireFlavorsChanged() { + if (flavorListeners == null) { + return; + } + Set<DataFlavor> prevDataFlavors = currentDataFlavors; currentDataFlavors = getAvailableDataFlavorSet(); if (Objects.equals(prevDataFlavors, currentDataFlavors)) { return; }