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.image;
021    
022    import org.apache.isis.applib.value.Image;
023    import org.apache.isis.core.commons.config.IsisConfiguration;
024    import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
025    import org.apache.isis.core.metamodel.facetapi.Facet;
026    import org.apache.isis.core.metamodel.facetapi.FacetHolder;
027    import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
028    
029    public class ImageValueSemanticsProvider extends ImageValueSemanticsProviderAbstract<Image> {
030    
031        public ImageValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration,
032            final ValueSemanticsProviderContext context) {
033            super(holder, Image.class, configuration, context);
034        }
035    
036        @Override
037        public int getHeight(final ObjectAdapter object) {
038            return image(object).getHeight();
039        }
040    
041        private Image image(final ObjectAdapter object) {
042            return (Image) object.getObject();
043        }
044    
045        @Override
046        public java.awt.Image getImage(final ObjectAdapter object) {
047            return createImage(image(object).getImage());
048        }
049    
050        @Override
051        protected int[][] getPixels(final Object object) {
052            return ((Image) object).getImage();
053        }
054    
055        public Class<?> getValueClass() {
056            return Image.class;
057        }
058    
059        @Override
060        public int getWidth(final ObjectAdapter object) {
061            return image(object).getWidth();
062        }
063    
064        @Override
065        protected Image setPixels(final int[][] pixels) {
066            return new Image(pixels);
067        }
068    
069        @Override
070        public Facet getUnderlyingFacet() {
071            return null;
072        }
073    
074        /**
075         * Not required because {@link #alwaysReplace()} is <tt>false</tt>.
076         */
077        @Override
078        public void setUnderlyingFacet(final Facet underlyingFacet) {
079            throw new UnsupportedOperationException();
080        }
081    
082        @Override
083        public boolean alwaysReplace() {
084            return false;
085        }
086    
087        @Override
088        public boolean isNoop() {
089            return false;
090        }
091    
092        @Override
093        public String toString() {
094            return "ImageValueSemanticsProvider: ";
095        }
096    
097        @Override
098        public ObjectAdapter createValue(final java.awt.Image image) {
099            return getAdapterMap().adapterFor(new Image(grabPixels(image)));
100        }
101    
102    }