> hmmmm ok. Any sort of direction or quick framework you might be able
> to give me? Not quite sure how to start ths out. Thanks
hmmmm, I have new idea:
you can use simple JPanel instead of JViewport:
and you can have any shape - not only rectangular!
import javax.swing.*;
import java.awt.*;
import java.awt.image.RGBImageFilter;
import java.awt.image.FilteredImageSource;
import java.awt.geom.AffineTransform;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* @author Andrei Kouznetsov
* Date: 27.02.2004
* Time: 11:29:17
*/
public class ThumbnailPane extends JPanel {
ActionListener listener;
Image thumbnail;
Image thumbnail2; //better quality or color/grascale to draw inside
shape;
Shape shape, translatedShape;
private ZoomPane zoomPane;
public ThumbnailPane(Image thumbnail, Image thumbnail2, Shape shape) {
this.thumbnail = thumbnail;
this.thumbnail2 = thumbnail2;
this.shape = shape;
zoomPane = new ZoomPane();
listener = getZoomPane();
translate(0, 0);
}
public Shape getCurrentShape() {
return translatedShape;
}
public Dimension getPreferredSize() {
return new Dimension(thumbnail.getWidth(null),
thumbnail.getHeight(null));
}
//use it to move your "Viewport"
public void translate(int x, int y) {
translatedShape = AffineTransform.getTranslateInstance(x,
y).createTransformedShape(shape);
if (listener != null) {
listener.actionPerformed(new ActionEvent(this,
ActionEvent.ACTION_PERFORMED, "moved"));
}
}
public void paint(Graphics g) {
g.drawImage(thumbnail, 0, 0, null);
//use following if you want to draw thumbnail inside viewport
Graphics2D g2d = (Graphics2D) g;
g2d.clip(translatedShape);
g.drawImage(thumbnail2, 0, 0, null);
g2d.clip(null);
g.setColor(Color.blue);
g2d.draw(translatedShape);
}
public ZoomPane getZoomPane() {
return zoomPane;
}
class ZoomPane extends JPanel implements ActionListener {
Image currentView;
Shape shape;
AffineTransform transform; //zoom factor
//you have to implement it
Image getImageTile(Shape shape) {
return null;
}
public void actionPerformed(ActionEvent e) {
shape = transform.createTransformedShape(translatedShape);
currentView = getImageTile(shape);
repaint();
}
public Dimension getPreferredSize() {
if (shape != null) {
Rectangle r = shape.getBounds();
return new Dimension(r.width, r.height);
}
return super.getPreferredSize();
}
public void paintComponent(Graphics g) {
g.setColor(getBackground());
Dimension d = getSize();
g.fillRect(0, 0, d.width, d.height);
g.drawImage(currentView, 0, 0, this);
}
}
public static void main(String[] args) {
//create and load images here
Image thumbnail2 =
Toolkit.getDefaultToolkit().createImage("imagename");
RGBImageFilter filter = new GrayFilter(false, 50);
FilteredImageSource source = new
FilteredImageSource(thumbnail2.getSource(), filter);
Image thumbnail = Toolkit.getDefaultToolkit().createImage(source);
Shape shape = new Rectangle(0, 0, 100, 100);
ThumbnailPane tp = new ThumbnailPane(thumbnail, thumbnail2, shape);
JFrame frame = new JFrame();
frame.getContentPane().add(tp);
JDialog dialog = new JDialog(frame, false);
dialog.getContentPane().add(tp.getZoomPane());
frame.pack();
frame.show();
dialog.pack();
dialog.show();
}
}
____________
http://reader.imagero.com the best java image reader.