/** * Permet de dessiner la gui active par rapport à la perspective de celle-ci * * @param g l'element graphic qui permet de dessiner les images. */ public void paint(Graphics g) { super.paint(g); g.drawImage( imageVueActive.getTheImage(), perspective.getCornerImageX(), perspective.getCornerImageY(), imageVueActive.getTheImage().getWidth(null) * perspective.getEchelle() + perspective.getCornerImageX(), imageVueActive.getTheImage().getHeight(null) * perspective.getEchelle() + perspective.getCornerImageY(), 0, 0, imageVueActive.getTheImage().getWidth(null), imageVueActive.getTheImage().getHeight(null), null); g.drawImage( VueOriginale.getVueOriginale().getImageOriginale().getTheImage(), this.getWidth() - 90, 15, 75, 75, null); g.drawRect(this.getWidth() - 90, 15, 75, 75); }
/** * Constructeur de la classe VueActive * * @param image Image */ public VueActive(ImageConcrete image) { this.imageVueActive = image; this.perspective = new Perspective(); this.perspective.addObserver(this); int hauteur = imageVueActive.getTheImage().getHeight(null); int largeur = imageVueActive.getTheImage().getWidth(null); Dimension dimensionImage = new Dimension(largeur, hauteur); this.setPreferredSize(dimensionImage); MouseAdapter myMouseAdapter = new MouseAdapter() { int premierX; int premierY; /** * Permet de mettre en mémoire la position lorsque la souris pèse sur la perspective * * @param mouseEvent Evenement de la souris */ @Override public void mousePressed(MouseEvent mouseEvent) { premierX = perspective.getCornerImageX() - mouseEvent.getX(); premierY = perspective.getCornerImageY() - mouseEvent.getY(); setPosition(mouseEvent); } /** * Change la position de la perspective lorsque la souris dragged l'image * * @param mouseEvent Evenement de la souris */ @Override public void mouseDragged(MouseEvent mouseEvent) { setPosition(mouseEvent); } /** * Change l'échelle de la perspective lors du WheelMoved de la souris * * @param mouseWheelEvent Mouvement de la roulette de la souris */ @Override public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) { Controleur.getControleur().zoomer(mouseWheelEvent.getWheelRotation()); } @Override public void mouseEntered(MouseEvent mouseEvent) { Cursor cursor = new Cursor(Cursor.HAND_CURSOR); setCursor(cursor); } /** * Setter permettant de placer la position de la perspective * * @param mouseEvent Evenement de la souris */ public void setPosition(MouseEvent mouseEvent) { Controleur.getControleur() .deplacer(premierX + mouseEvent.getX(), premierY + mouseEvent.getY()); repaint(); } }; this.addMouseListener(myMouseAdapter); this.addMouseMotionListener(myMouseAdapter); this.addMouseWheelListener(myMouseAdapter); }