/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public final class JRSUIControl {
private static native int initNativeJRSUI();
// private static native int paint(long cfDictionaryPtr, long oldProperties, long newProperties, OSXSurfaceData osxsd, double x, double y, double w, double h);
// private static native int paintChanges(long cfDictionaryPtr, long byteBufferPtr, long oldProperties, long newProperties, OSXSurfaceData osxsd, double x, double y, double w, double h);
private static native int paintToCGContext (long cgContext, long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h);
private static native int paintChangesToCGContext (long cgContext, long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, long byteBufferPtr);
private static native int paintImage (int[] data, int imgW, int imgH, long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h);
private static native int paintChangesImage (int[] data, int imgW, int imgH, long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, long byteBufferPtr);
private static native int getNativeHitPart( long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, double hitX, double hitY);
private static native void getNativePartBounds(final double[] rect, long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, int part);
private static native double getNativeScrollBarOffsetChange( long cfDictionaryPtr, long oldProperties, long newProperties, double x, double y, double w, double h, int offset, int visibleAmount, int extent);
public static void initJRSUI() {
if (nativeJRSInitialized == SUCCESS) return;
if (nativeJRSInitialized != SUCCESS) throw new RuntimeException("JRSUI could not be initialized (" + nativeJRSInitialized + ").");
}
private static class ThreadLocalByteBuffer {
final long ptr;
public ThreadLocalByteBuffer() {
}
}
private static final ThreadLocal<ThreadLocalByteBuffer> threadLocal = new ThreadLocal<ThreadLocalByteBuffer>();
byteBuffer = new ThreadLocalByteBuffer();
return byteBuffer;
}
private long cfDictionaryPtr;
private long priorEncodedProperties;
private long currentEncodedProperties;
private final boolean flipped;
}
}
if (cfDictionaryPtr == 0) return;
cfDictionaryPtr = 0;
}
enum BufferState {
}
try {
} catch (final BufferOverflowException e) {
} catch (final RuntimeException e) {
throw e;
}
}
}
return BufferState.ALL_CHANGES_IN_BUFFER;
}
if (changeIndex == 0) {
return BufferState.CHANGE_WONT_FIT_IN_BUFFER;
}
return BufferState.SOME_CHANGES_IN_BUFFER;
}
private synchronized void set(final JRSUIConstants.Key key, final JRSUIConstants.DoubleValue value) {
return;
}
}
}
}
}
// private static final Color blue = new Color(0x00, 0x00, 0xFF, 0x40);
// private static void paintDebug(Graphics2D g, double x, double y, double w, double h) {
// final Color prev = g.getColor();
// g.setColor(blue);
// g.drawRect((int)x, (int)y, (int)w, (int)h);
// g.setColor(prev);
// }
// private static int paintsWithNoChange = 0;
// private static int paintsWithChangesThatFit = 0;
// private static int paintsWithChangesThatOverflowed = 0;
public void paint(final int[] data, final int imgW, final int imgH, final double x, final double y, final double w, final double h) {
}
private synchronized int paintImage(final int[] data, final int imgW, final int imgH, final double x, final double y, final double w, final double h) {
// paintsWithNoChange++;
return paintImage(data, imgW, imgH, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h);
}
// fast tracking this, since it's the likely scenario
// paintsWithChangesThatFit++;
return paintChangesImage(data, imgW, imgH, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
}
if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
}
throw new RuntimeException("JRSUI failed to sync changes to the native buffer, because some change was too big: " + this);
}
// implicitly ALL_CHANGES_IN_BUFFER, now that we sync'd the buffer down to native a few times
// paintsWithChangesThatOverflowed++;
return paintChangesImage(data, imgW, imgH, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
}
public void paint(final long cgContext, final double x, final double y, final double w, final double h) {
paintToCGContext(cgContext, x, y, w, h);
}
private synchronized int paintToCGContext(final long cgContext, final double x, final double y, final double w, final double h) {
// paintsWithNoChange++;
return paintToCGContext(cgContext, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h);
}
// fast tracking this, since it's the likely scenario
// paintsWithChangesThatFit++;
return paintChangesToCGContext(cgContext, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
}
if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
}
throw new RuntimeException("JRSUI failed to sync changes to the native buffer, because some change was too big: " + this);
}
// implicitly ALL_CHANGES_IN_BUFFER, now that we sync'd the buffer down to native a few times
// paintsWithChangesThatOverflowed++;
return paintChangesToCGContext(cgContext, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, localByteBuffer.ptr);
}
Hit getHitForPoint(final double x, final double y, final double w, final double h, final double hitX, final double hitY) {
sync();
// reflect hitY about the midline of the control before sending to native
final Hit hit = JRSUIConstants.getHit(getNativeHitPart(cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, hitX, 2 * y + h - hitY));
return hit;
}
void getPartBounds(final double[] rect, final double x, final double y, final double w, final double h, final int part) {
sync();
getNativePartBounds(rect, cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, part);
}
double getScrollBarOffsetChange(final double x, final double y, final double w, final double h, final int offset, final int visibleAmount, final int extent) {
sync();
final double offsetChange = getNativeScrollBarOffsetChange(cfDictionaryPtr, priorEncodedProperties, currentEncodedProperties, x, y, w, h, offset, visibleAmount, extent);
return offsetChange;
}
private void sync() {
if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
return;
}
if (status != SUCCESS) throw new RuntimeException("JRSUI failed to sync changes into the native buffer: " + this);
}
throw new RuntimeException("JRSUI failed to sync changes to the native buffer, because some change was too big: " + this);
}
}
public int hashCode() {
return bits;
}
if (!(obj instanceof JRSUIControl)) return false;
return true;
}
}
}