Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ZoomListener extends FractalListener implements MouseInputListener{
- private double startX, startY, finalX, finalY;
- private Rectangle selection;
- private Point anchor;
- @Override
- public void mousePressed(MouseEvent e){
- updateDetails();
- startX = e.getX();
- startY= e.getY();
- anchor = e.getPoint();
- selection = new Rectangle(anchor);
- drawingPanel.setIsZooming(true);
- drawingPanel.setZoomRect(selection);
- }
- @Override
- public void mouseReleased(MouseEvent e){
- finalX = e.getX();
- finalY = e.getY();
- double xScale = (xMaxVal - xMinVal) / size.getWidth();
- double yScale = (yMaxVal - yMinVal) / size.getHeight();
- startX = xMinVal + (startX * xScale);
- finalX = xMinVal + (finalX * xScale);
- startY = yMaxVal - (startY * yScale);
- finalY = yMaxVal - (finalY * yScale);
- if(startX != finalX && startY != finalY){
- imageDetails[0] = Math.min(startX, finalX);
- imageDetails[1] = Math.max(startX, finalX);
- imageDetails[2] = Math.min(startY, finalY);
- imageDetails[3] = Math.max(startY, finalY);
- String text = new String();
- text += imageDetails[0];
- realMin.setText(text);
- text = "";
- text += imageDetails[1];
- realMax.setText(text);
- text = "";
- text += imageDetails[2];
- imgMin.setText(text);
- text = "";
- text += imageDetails[3];
- imgMax.setText(text);
- drawingPanel.setIsZooming(false);
- selection = null;
- drawingPanel.setZoomRect(selection);
- repaint();
- }
- }
- @Override
- public void mouseDragged(MouseEvent e){
- selection.setBounds( (int)Math.min(anchor.x,e.getX()), (int)Math.min(anchor.y,e.getY()),
- (int)Math.abs(e.getX()-anchor.x), (int)Math.abs(e.getY()-anchor.y));
- drawingPanel.repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment