openjpeg/j2kviewer/src/MML.java

86 lines
1.7 KiB
Java
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import java.awt.event.*;
class MML implements MouseMotionListener, MouseListener
{
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
private ImageViewer applet;
private int x1, y1, x2, y2, zf, btn;
private boolean zoomrq;
public MML(ImageViewer iv)
{
x1 = y1 = -1;
applet = iv;
zoomrq = false;
zf = 0;
}
private boolean isInside(int x, int y)
{
x -= applet.getX();
y -= applet.getY();
return (x >= 0) && (x < applet.getWidth())
&& (y >= 0) && (y < applet.getHeight());
}
public void mousePressed(MouseEvent e)
{
btn = e.getButton();
if (applet.isInsideRect(e.getX(), e.getY())) {
applet.setSelected(2);
applet.repaint();
zoomrq = true;
} else {
applet.setRGeom(0, 0, 0, 0);
applet.setSelected(0);
applet.repaint();
x1 = y1 = -1;
}
}
public void mouseReleased(MouseEvent e)
{
if (zoomrq && (e.getButton() == 1)) {
applet.zoomIn();
zoomrq = false;
} else if (e.getButton() == 3) {
applet.zoomOut();
zoomrq = false;
}
}
public void mouseMoved(MouseEvent e)
{
applet.setSelected(applet.isInsideRect(e.getX(), e.getY()) ? 1 : 0);
}
public void mouseDragged(MouseEvent e)
{
String str;
if (btn == 1) {
x2 = e.getX();
y2 = e.getY();
applet.setSelected(0);
zoomrq = false;
if (isInside(x2, y2)) {
str = "[IN ]";
if (x1 == -1) {
x1 = x2;
y1 = y2;
} else {
applet.setRGeom(x1, y1, x2, y2);
applet.repaint();
}
} else {
str = "[OUT]";
}
}
}
}