126 public boolean isAnimation(Image image) {
127 return image.isAnimation();
128 }
129
130 @Override
131 public ReadOnlyObjectProperty<PlatformImage>
132 getImageProperty(Image image)
133 {
134 return image.acc_platformImageProperty();
135 }
136
137 @Override
138 public int[] getPreColors(PixelFormat<ByteBuffer> pf) {
139 return ((PixelFormat.IndexedPixelFormat) pf).getPreColors();
140 }
141
142 @Override
143 public int[] getNonPreColors(PixelFormat<ByteBuffer> pf) {
144 return ((PixelFormat.IndexedPixelFormat) pf).getNonPreColors();
145 }
146 });
147 }
148
149 // Matches strings that start with a valid URI scheme
150 private static final Pattern URL_QUICKMATCH = Pattern.compile("^\\p{Alpha}[\\p{Alnum}+.-]*:.*$");
151 /**
152 * The string representing the URL to use in fetching the pixel data.
153 *
154 * @defaultValue empty string
155 */
156 private final String url;
157
158 /**
159 * Returns the url used to fetch the pixel data contained in the Image instance,
160 * if specified in the constructor. If no url is provided in the constructor (for
161 * instance, if the Image is constructed from an
162 * {@link #Image(InputStream) InputStream}), this method will return null.
163 *
164 * @return a String containing the URL used to fetch the pixel data for this
165 * Image instance.
510 public final ReadOnlyObjectProperty<Exception> exceptionProperty() {
511 return exceptionPropertyImpl().getReadOnlyProperty();
512 }
513
514 private ReadOnlyObjectWrapper<Exception> exceptionPropertyImpl() {
515 if (exception == null) {
516 exception = new ReadOnlyObjectWrapper<Exception>(this, "exception");
517 }
518 return exception;
519 }
520
521 /**
522 * The underlying platform representation of this Image object.
523 *
524 * @defaultValue null
525 * @treatAsPrivate implementation detail
526 * @deprecated This is an internal API that is not intended for use and will be removed in the next version
527 */
528 private ObjectPropertyImpl<PlatformImage> platformImage;
529
530 /**
531 * @treatAsPrivate implementation detail
532 */
533 // SB-dependency: RT-21219 has been filed to track this
534 // TODO: need to ensure that both SceneBuilder and JDevloper have migrated
535 // to new 2.2 public API before we remove this.
536 @Deprecated
537 public final Object impl_getPlatformImage() {
538 return platformImage == null ? null : platformImage.get();
539 }
540
541 final ReadOnlyObjectProperty<PlatformImage> acc_platformImageProperty() {
542 return platformImagePropertyImpl();
543 }
544
545 private ObjectPropertyImpl<PlatformImage> platformImagePropertyImpl() {
546 if (platformImage == null) {
547 platformImage = new ObjectPropertyImpl<PlatformImage>("platformImage");
548 }
549
550 return platformImage;
551 }
552
553 void pixelsDirty() {
554 platformImagePropertyImpl().fireValueChangedEvent();
555 }
556
557 private final class ObjectPropertyImpl<T>
932
933 private void loadInBackground() {
934 backgroundTask = new ImageTask();
935 // This is an artificial throttle on background image loading tasks.
936 // It has been shown that with large images, we can quickly use up the
937 // heap loading images, even if they result in thumbnails.
938 // The limit of MAX_RUNNING_TASKS is arbitrary, and was based on initial
939 // testing with
940 // about 60 2-6 megapixel images.
941 synchronized (pendingTasks) {
942 if (runningTasks >= MAX_RUNNING_TASKS) {
943 pendingTasks.offer(backgroundTask);
944 } else {
945 runningTasks++;
946 backgroundTask.start();
947 }
948 }
949 }
950
951 // Used by SwingUtils.toFXImage
952 /**
953 * @treatAsPrivate implementation detail
954 * @deprecated This is an internal API that is not intended for use and will be removed in the next version
955 */
956 // SB-dependency: RT-21217 has been filed to track this
957 // TODO: need to ensure that both SceneBuilder and JDevloper have migrated
958 // to new 2.2 public API before we remove this.
959 @Deprecated
960 public static Image impl_fromPlatformImage(Object image) {
961 return new Image(image);
962 }
963
964 private void setPlatformImageWH(final PlatformImage newPlatformImage,
965 final double newWidth,
966 final double newHeight) {
967 if ((impl_getPlatformImage() == newPlatformImage)
968 && (getWidth() == newWidth)
969 && (getHeight() == newHeight)) {
970 return;
971 }
972
973 final Object oldPlatformImage = impl_getPlatformImage();
974 final double oldWidth = getWidth();
975 final double oldHeight = getHeight();
976
977 storePlatformImageWH(newPlatformImage, newWidth, newHeight);
978
979 if (oldPlatformImage != newPlatformImage) {
980 platformImagePropertyImpl().fireValueChangedEvent();
981 }
982
983 if (oldWidth != newWidth) {
984 widthPropertyImpl().fireValueChangedEvent();
985 }
986
987 if (oldHeight != newHeight) {
988 heightPropertyImpl().fireValueChangedEvent();
989 }
990 }
991
992 private void storePlatformImageWH(final PlatformImage platformImage,
993 final double width,
|
126 public boolean isAnimation(Image image) {
127 return image.isAnimation();
128 }
129
130 @Override
131 public ReadOnlyObjectProperty<PlatformImage>
132 getImageProperty(Image image)
133 {
134 return image.acc_platformImageProperty();
135 }
136
137 @Override
138 public int[] getPreColors(PixelFormat<ByteBuffer> pf) {
139 return ((PixelFormat.IndexedPixelFormat) pf).getPreColors();
140 }
141
142 @Override
143 public int[] getNonPreColors(PixelFormat<ByteBuffer> pf) {
144 return ((PixelFormat.IndexedPixelFormat) pf).getNonPreColors();
145 }
146
147 @Override
148 public Object getPlatformImage(Image image) {
149 return image.getPlatformImage();
150 }
151
152 @Override
153 public Image fromPlatformImage(Object image) {
154 return Image.fromPlatformImage(image);
155 }
156 });
157 }
158
159 // Matches strings that start with a valid URI scheme
160 private static final Pattern URL_QUICKMATCH = Pattern.compile("^\\p{Alpha}[\\p{Alnum}+.-]*:.*$");
161 /**
162 * The string representing the URL to use in fetching the pixel data.
163 *
164 * @defaultValue empty string
165 */
166 private final String url;
167
168 /**
169 * Returns the url used to fetch the pixel data contained in the Image instance,
170 * if specified in the constructor. If no url is provided in the constructor (for
171 * instance, if the Image is constructed from an
172 * {@link #Image(InputStream) InputStream}), this method will return null.
173 *
174 * @return a String containing the URL used to fetch the pixel data for this
175 * Image instance.
520 public final ReadOnlyObjectProperty<Exception> exceptionProperty() {
521 return exceptionPropertyImpl().getReadOnlyProperty();
522 }
523
524 private ReadOnlyObjectWrapper<Exception> exceptionPropertyImpl() {
525 if (exception == null) {
526 exception = new ReadOnlyObjectWrapper<Exception>(this, "exception");
527 }
528 return exception;
529 }
530
531 /**
532 * The underlying platform representation of this Image object.
533 *
534 * @defaultValue null
535 * @treatAsPrivate implementation detail
536 * @deprecated This is an internal API that is not intended for use and will be removed in the next version
537 */
538 private ObjectPropertyImpl<PlatformImage> platformImage;
539
540 private final Object getPlatformImage() {
541 return platformImage == null ? null : platformImage.get();
542 }
543
544 final ReadOnlyObjectProperty<PlatformImage> acc_platformImageProperty() {
545 return platformImagePropertyImpl();
546 }
547
548 private ObjectPropertyImpl<PlatformImage> platformImagePropertyImpl() {
549 if (platformImage == null) {
550 platformImage = new ObjectPropertyImpl<PlatformImage>("platformImage");
551 }
552
553 return platformImage;
554 }
555
556 void pixelsDirty() {
557 platformImagePropertyImpl().fireValueChangedEvent();
558 }
559
560 private final class ObjectPropertyImpl<T>
935
936 private void loadInBackground() {
937 backgroundTask = new ImageTask();
938 // This is an artificial throttle on background image loading tasks.
939 // It has been shown that with large images, we can quickly use up the
940 // heap loading images, even if they result in thumbnails.
941 // The limit of MAX_RUNNING_TASKS is arbitrary, and was based on initial
942 // testing with
943 // about 60 2-6 megapixel images.
944 synchronized (pendingTasks) {
945 if (runningTasks >= MAX_RUNNING_TASKS) {
946 pendingTasks.offer(backgroundTask);
947 } else {
948 runningTasks++;
949 backgroundTask.start();
950 }
951 }
952 }
953
954 // Used by SwingUtils.toFXImage
955 static Image fromPlatformImage(Object image) {
956 return new Image(image);
957 }
958
959 private void setPlatformImageWH(final PlatformImage newPlatformImage,
960 final double newWidth,
961 final double newHeight) {
962 if ((Toolkit.getImageAccessor().getPlatformImage(this) == newPlatformImage)
963 && (getWidth() == newWidth)
964 && (getHeight() == newHeight)) {
965 return;
966 }
967
968 final Object oldPlatformImage = Toolkit.getImageAccessor().getPlatformImage(this);
969 final double oldWidth = getWidth();
970 final double oldHeight = getHeight();
971
972 storePlatformImageWH(newPlatformImage, newWidth, newHeight);
973
974 if (oldPlatformImage != newPlatformImage) {
975 platformImagePropertyImpl().fireValueChangedEvent();
976 }
977
978 if (oldWidth != newWidth) {
979 widthPropertyImpl().fireValueChangedEvent();
980 }
981
982 if (oldHeight != newHeight) {
983 heightPropertyImpl().fireValueChangedEvent();
984 }
985 }
986
987 private void storePlatformImageWH(final PlatformImage platformImage,
988 final double width,
|