001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.rGUI.client.UIHelper;
020
021/*
022 * %W% %E% %U%
023 *
024 * Copyright (c) 2000 Sun Microsystems, Inc. All Rights Reserved.
025 *
026 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
027 * modify and redistribute this software in source and binary code form,
028 * provided that i) this copyright notice and license appear on all copies of
029 * the software; and ii) Licensee does not utilize the software in a manner
030 * which is disparaging to Sun.
031 *
032 * This software is provided "AS IS," without a warranty of any kind. ALL
033 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
034 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
035 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
036 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
037 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
038 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
039 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
040 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
041 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
042 * POSSIBILITY OF SUCH DAMAGES.
043 *
044 * This software is not designed or intended for use in on-line control of
045 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
046 * the design, construction, operation or maintenance of any nuclear
047 * facility. Licensee represents and warrants that it will not use or
048 * redistribute the Software for such purposes.
049 */
050
051/**
052 *  Example display class Swing Component that is able
053 *  to contain an image.  The size of the image
054 *  and size of the container can be different.
055 *  The image can be positioned within the
056 *  container.  This class extends JPanel in order
057 *  to support layout management.  Tiling is supported
058 *  as of JDK1.3 via drawRenderedImage().
059 *
060 *  @author Dennis Sigel
061 *
062 *  @see javax.swing.JPanel
063 *  @see javax.swing.JComponent
064 *  @see java.awt.image.RenderedImage
065 */
066
067
068import java.awt.Insets;
069import java.awt.Point;
070import java.awt.Rectangle;
071import java.awt.Graphics;
072import java.awt.Graphics2D;
073import java.awt.Dimension;
074import java.awt.geom.AffineTransform;
075import java.awt.image.RenderedImage;
076import javax.swing.JPanel;
077
078@Deprecated
079public class DisplayJAI extends JPanel {
080
081    /** image to display */
082    protected RenderedImage source = null;
083
084    /** image origin relative to panel origin */
085    protected int originX = 0;
086    protected int originY = 0;
087
088
089    /** default constructor */
090    public DisplayJAI() {
091        super();
092        setLayout(null);
093    }
094
095    /** constructor with given image */
096    public DisplayJAI(RenderedImage image) {
097        super();
098        setLayout(null);
099        source = image;
100        setPreferredSize(new Dimension(source.getWidth(),
101                                       source.getHeight()));
102    }
103
104    /** move image within it's container */
105    public void setOrigin(int x, int y) {
106        originX = x;
107        originY = y;
108        repaint();
109    }
110
111    /** get the image origin */
112    public Point getOrigin() {
113        return new Point(originX, originY);
114    }
115
116    /** use to display a new image */
117    public void setImage(RenderedImage im) {
118        source = im;
119        repaint();
120    }
121
122    /** @return the Image */
123    public RenderedImage getImage() {
124        return source;
125    }
126
127    /** paint routine */
128    public synchronized void paintComponent(Graphics g) {
129
130        Graphics2D g2d = (Graphics2D)g;
131
132        // empty component (no image)
133        if ( source == null ) {
134            g2d.setColor(getBackground());
135            g2d.fillRect(0, 0, getWidth(), getHeight());
136            return;
137        }
138
139        // account for borders
140        Insets insets = getInsets();
141        int tx = insets.left + originX;
142        int ty = insets.top  + originY;
143
144        // clear damaged component area
145        Rectangle clipBounds = g2d.getClipBounds();
146        g2d.setColor(getBackground());
147        g2d.fillRect(clipBounds.x,
148                     clipBounds.y,
149                     clipBounds.width,
150                     clipBounds.height);
151
152        /**
153            Translation moves the entire image within the container
154        */
155        g2d.drawRenderedImage(source,
156                              AffineTransform.getTranslateInstance(tx, ty));
157    }
158}
159