001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.isis.core.progmodel.facets.value.imageawt;
021
022 import java.awt.Image;
023
024 import org.apache.isis.core.commons.config.IsisConfiguration;
025 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
026 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
027 import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
028 import org.apache.isis.core.progmodel.facets.value.image.ImageValueSemanticsProviderAbstract;
029
030 public class JavaAwtImageValueSemanticsProvider extends ImageValueSemanticsProviderAbstract<Image> {
031
032 public JavaAwtImageValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration,
033 final ValueSemanticsProviderContext context) {
034 super(holder, Image.class, configuration, context);
035 }
036
037 @Override
038 public int getHeight(final ObjectAdapter object) {
039 return image(object).getHeight(null);
040 }
041
042 private Image image(final ObjectAdapter object) {
043 return (Image) object.getObject();
044 }
045
046 @Override
047 public Image getImage(final ObjectAdapter object) {
048 return image(object);
049 }
050
051 @Override
052 protected int[][] getPixels(final Object object) {
053 return grabPixels((Image) object);
054 }
055
056 public Class<?> getValueClass() {
057 return Image.class;
058 }
059
060 @Override
061 public int getWidth(final ObjectAdapter object) {
062 return image(object).getWidth(null);
063 }
064
065 @Override
066 protected Image setPixels(final int[][] pixels) {
067 return createImage(pixels);
068 }
069
070 @Override
071 public boolean isNoop() {
072 return false;
073 }
074
075 @Override
076 public String toString() {
077 return "JavaAwtImageValueSemanticsProvider: ";
078 }
079
080 @Override
081 public ObjectAdapter createValue(final Image image) {
082 return getAdapterMap().adapterFor(image);
083 }
084
085 }