/* * $Id$ * * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2010-2011, Kaori Hagihara * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.image.*; import java.awt.geom.*; import java.net.URL; import javax.swing.border.*; import java.util.*; import java.io.*; public class ImageViewer extends JPanel { private ImageManager imgmanager; private int vw, vh; private int iw, ih; private int selected = 0; private Image img; private String cmdline = new String(); private boolean fullRefresh = false; private Point offset = new Point(0,0); private Rectangle rect = new Rectangle(); private Rectangle roirect[] = null; private String roiname[] = null; public ImageViewer( String j2kfilename, ImageManager manager, boolean session, boolean jppstream, int aux) { String str; MML myMML; this.setSize( 170, 170); Dimension asz = this.getSize(); vw = asz.width; vh = asz.height; setBackground(Color.black); myMML = new MML(this); imgmanager = manager; img = imgmanager.getImage( j2kfilename, vw, vh, session, aux, jppstream, !jppstream); addMouseListener(myMML); addMouseMotionListener(myMML); addComponentListener( new ResizeListener(this)); } public Image getImage() { return img; } public void zoomIn() { roirect = null; roiname = null; double scalex = (double)vw/(double)rect.width; double scaley = (double)vh/(double)rect.height; int fw = (int)(imgmanager.getFw()*scalex); int fh = (int)(imgmanager.getFh()*scaley); int rx = (int)((imgmanager.getRx()+rect.x)*scalex); int ry = (int)((imgmanager.getRy()+rect.y)*scaley); img = imgmanager.getImage( fw, fh, rx, ry, vw, vh); rect.x = rect.y = rect.width = rect.height = 0; selected = 0; fullRefresh = true; repaint(); } public void enlarge() { roirect = null; roiname = null; Dimension asz = this.getSize(); vw = asz.width; vh = asz.height; double scalex = vw/(double)imgmanager.getRw(); double scaley = vh/(double)imgmanager.getRh(); int fw = (int)(imgmanager.getFw()*scalex); int fh = (int)(imgmanager.getFh()*scaley); int rx = (int)(imgmanager.getRx()*scalex); int ry = (int)(imgmanager.getRy()*scaley); img = imgmanager.getImage( fw, fh, rx, ry, vw, vh); fullRefresh = true; repaint(); } public void setSelected(int state) { roirect = null; roiname = null; if (state != selected) { selected = state; repaint(); } } public boolean isInsideRect(int x, int y) { return rect.contains(x - offset.x, y - offset.y); } public void setRGeom(int x1, int y1, int x2, int y2) { rect.x = Math.min(x1,x2) - offset.x; rect.y = Math.min(y1,y2) - offset.y; rect.width = Math.abs(x2-x1); rect.height = Math.abs(y2-y1); } // public void annotate( JP2XMLparser.ROIparams roi[]) // { // int numofroi = roi.length; // roirect = new Rectangle [numofroi]; // roiname = new String [numofroi]; // double scale_x = imgmanager.getFw()/(double)imgmanager.getOrigWidth(); // double scale_y = imgmanager.getFh()/(double)imgmanager.getOrigHeight(); // int rx = imgmanager.getRx(); // int ry = imgmanager.getRy(); // int rw = imgmanager.getRw(); // int rh = imgmanager.getRh(); // for( int i=0; i 0) && (rect.height > 0)) big.draw(rect); if( roirect != null){ for( int i=0; i