package view;

import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.util.Observer;
import java.util.Observable;
import java.awt.Graphics;
import model.Image;
import model.Thumbnail;
import model.Language;
import controller.Controller;

public class ViewerView extends BaseView implements Observer {
	private Language language;
	private Image image;
	private Controller controller;
	private JLabel label;
	private JButton rename;
	private JButton hide;

	public ViewerView(final Controller controller) {
		super();
		this.controller = controller;
		label = new JLabel();
		add(label);
		controller.init(this);
	}

	public void setImage(Image image) {
		this.image = image;
		if(image.getBufferedImage() != null) {
			super.setTitle(image.getName());
			label = new JLabel(new ImageIcon(image.getBufferedImage()));
			repaint();
		} else {
			super.setTitle(language.getString("viewer"));
		}
	}

	public void setLanguage(Language language) {
		this.language = language;
		super.setTitle(language.getString("viewer"));
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		int x, y, width, height, maxWidth, maxHeight;
		maxWidth = getWidth();
		maxHeight = getHeight();
		width = image.getWidth();
		height = image.getHeight();
		if(width>maxWidth*0.80) {  // Double condition pour conserver les ratios
			width = (int)(maxWidth*0.80);
			height = (int)(maxHeight*0.80);
		}
		if(height>maxHeight*0.80) {
			width = (int)(maxWidth*0.80);
			height = (int)(maxHeight*0.80);
		}
		x = (maxWidth-width)/2; // On place l'image au milieu
		y = (maxHeight-height)/2;
		g.drawImage(image.getBufferedImage(), x, y, width, height, this);
	}

	public void update (Observable o, Object arg) {
		String tmp = (String)arg;
		if(tmp.equals("language"))
			setLanguage((Language)o);
		else if(tmp.equals("image"))
			setImage((Image)o);
	}
}

@@ -89,24 +89,54 @@
 .ImageIcon;%0A
+import javax.swing.BoxLayout;%0A
 import java.
@@ -205,16 +205,43 @@
 aphics;%0A
+import java.awt.Component;%0A
 import m
@@ -491,17 +491,47 @@
  JLabel 
-l
+imgLabel;%0A%09private JLabel nameL
 abel;%0A%09p
@@ -676,44 +676,207 @@
 ;%0A%09%09
-label = new JLabel();%0A%09%09add(l
+imgLabel = new JLabel();%0A%09%09nameLabel = new JLabel();%0A%09%09nameLabel.setAlignmentX(Component.CENTER_ALIGNMENT);%0A%09%09setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));%0A%09%09add(imgLabel);%0A%09%09add(nameL
 abel);%0A
+%0A
 %09%09co
@@ -1003,30 +1003,33 @@
 l) %7B%0A%09%09%09
-super
+nameLabel
 .setT
-itle
+ext
 (image.g
@@ -1042,17 +1042,20 @@
 ());%0A%09%09%09
-l
+imgL
 abel = n
@@ -1124,68 +1124,8 @@
 ();%0A
-%09%09%7D else %7B%0A%09%09%09super.setTitle(language.getString(%22viewer%22));%0A
 %09%09%7D%0A

put image name in viewer instead of title