1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.swing.interop; 27 28 import java.awt.Component; 29 import java.awt.dnd.DragGestureRecognizer; 30 import java.awt.dnd.DragGestureListener; 31 import java.awt.dnd.DragSource; 32 import java.awt.dnd.DragGestureEvent; 33 import java.awt.dnd.InvalidDnDOperationException; 34 import java.awt.dnd.peer.DragSourceContextPeer; 35 import java.awt.dnd.DropTarget; 36 import javax.swing.JComponent; 37 import sun.swing.LightweightContent; 38 39 /** 40 * This class provides a wrapper over inner LightweightContentProxy class 41 * which implements jdk internal sun.swing.LightweightContent interface 42 * and provides APIs to be used by FX swing interop to access and use LightweightContent APIs. 43 */ 44 public abstract class LightweightContentWrapper { 45 private LightweightContentProxy lwCnt; 46 47 public LightweightContentWrapper() { 48 lwCnt = new LightweightContentProxy(); 49 } 50 51 LightweightContentProxy getContent() { 52 return lwCnt; 53 } 54 55 public abstract void imageBufferReset(int[] data, int x, int y, int width, 56 int height, int linestride); 57 58 public abstract void imageBufferReset(int[] data, int x, int y, int width, int height, 59 int linestride, double scaleX, double scaleY); 60 61 public abstract JComponent getComponent(); 62 63 public abstract void paintLock(); 64 65 public abstract void paintUnlock(); 66 67 public abstract void imageReshaped(int x, int y, int width, int height); 68 69 public abstract void imageUpdated(int dirtyX, int dirtyY,int dirtyWidth, int dirtyHeight); 70 71 public abstract void focusGrabbed(); 72 73 public abstract void focusUngrabbed(); 74 75 public abstract void preferredSizeChanged(int width, int height); 76 77 public abstract void maximumSizeChanged(int width, int height); 78 79 public abstract void minimumSizeChanged(int width, int height); 80 81 public abstract <T extends DragGestureRecognizer> T createDragGestureRecognizer( 82 Class<T> abstractRecognizerClass, 83 DragSource ds, Component c, int srcActions, 84 DragGestureListener dgl); 85 86 public abstract DragSourceContextWrapper createDragSourceContext(DragGestureEvent dge) 87 throws InvalidDnDOperationException; 88 89 public abstract void addDropTarget(DropTarget dt); 90 91 public abstract void removeDropTarget(DropTarget dt); 92 93 private class LightweightContentProxy implements LightweightContent { 94 95 public JComponent getComponent() { 96 return LightweightContentWrapper.this.getComponent(); 97 } 98 99 public void paintLock() { 100 LightweightContentWrapper.this.paintLock(); 101 } 102 103 public void paintUnlock() { 104 LightweightContentWrapper.this.paintUnlock(); 105 } 106 107 public void imageBufferReset(int[] data, int x, int y, int width, int height, 108 int linestride) { 109 LightweightContentWrapper.this.imageBufferReset(data, x, y, width, 110 height, linestride); 111 } 112 113 public void imageBufferReset(int[] data, int x, int y, int width, int height, 114 int linestride, double scaleX, double scaleY) { 115 LightweightContentWrapper.this.imageBufferReset(data, x, y, width, height, 116 linestride, scaleX, scaleY); 117 } 118 119 public void imageReshaped(int x, int y, int width, int height) { 120 LightweightContentWrapper.this.imageReshaped(x, y, width, height); 121 } 122 123 public void imageUpdated(int dirtyX, int dirtyY,int dirtyWidth, int dirtyHeight) { 124 LightweightContentWrapper.this.imageUpdated(dirtyX, dirtyY, dirtyWidth, dirtyHeight); 125 } 126 127 public void focusGrabbed() { 128 LightweightContentWrapper.this.focusGrabbed(); 129 } 130 131 public void focusUngrabbed() { 132 LightweightContentWrapper.this.focusUngrabbed(); 133 } 134 135 public void preferredSizeChanged(int width, int height) { 136 LightweightContentWrapper.this.preferredSizeChanged(width, height); 137 } 138 139 public void maximumSizeChanged(int width, int height) { 140 LightweightContentWrapper.this.maximumSizeChanged(width, height); 141 } 142 143 public void minimumSizeChanged(int width, int height) { 144 LightweightContentWrapper.this.minimumSizeChanged(width, height); 145 } 146 147 public <T extends DragGestureRecognizer> T createDragGestureRecognizer( 148 Class<T> abstractRecognizerClass, 149 DragSource ds, Component c, int srcActions, 150 DragGestureListener dgl) { 151 return LightweightContentWrapper.this.createDragGestureRecognizer( 152 abstractRecognizerClass, ds, c, srcActions, dgl); 153 } 154 155 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) 156 throws InvalidDnDOperationException { 157 DragSourceContextWrapper peerWrapper = 158 LightweightContentWrapper.this.createDragSourceContext(dge); 159 return peerWrapper.getPeer(); 160 } 161 162 public void addDropTarget(DropTarget dt) { 163 LightweightContentWrapper.this.addDropTarget(dt); 164 } 165 166 public void removeDropTarget(DropTarget dt) { 167 LightweightContentWrapper.this.removeDropTarget(dt); 168 } 169 } 170 }