package jbrickbreaker.view;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import jbrickbreaker.JBrickBreaker;
import net.miginfocom.swing.MigLayout;
/**
* This class represents the about view
*
* @author Christophe
*
*/
public class AboutView extends JDialog implements ILanguage {
private JBrickBreaker jBrickBreaker;
String desktopNotSupportedString;
JLabel jlLink;
public AboutView(JBrickBreaker jBrickBreaker) {
super();
this.jBrickBreaker = jBrickBreaker;
createView();
}
private void createView() {
setModal(true);
setLayout(new MigLayout());
setResizable(false);
getContentPane().setBackground(Color.WHITE);
final String strURL = "http://javabrickbreake.sourceforge.net/"; //$NON-NLS-1$
jlLink = new JLabel();
add(new JLabel("Brick Breaker 2010 v1.0"), "cell 2 1"); //$NON-NLS-1$ //$NON-NLS-2$
add(new JLabel(
"<html>Dorthe Christophe<br/>Reymond Maxime<br/>Michel Thomas</html>"), //$NON-NLS-1$
"cell 2 2"); //$NON-NLS-1$
// add(new JLabel(new ImageIcon("img/logo_BrickBreaker.png")), //$NON-NLS-1$
// "cell 1 1, spany 2"); //$NON-NLS-1$
add(new JLabel(new ImageIcon(getClass().getResource("/resources/logo_BrickBreaker.png"))), //$NON-NLS-1$
"cell 1 1, spany 2"); //$NON-NLS-1$
add(jlLink, "cell 1 4, spanx 2"); //$NON-NLS-1$
updateLanguage(jBrickBreaker.getLanguage());
jlLink.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent me) {
jlLink.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseExited(MouseEvent me) {
jlLink.setCursor(Cursor.getDefaultCursor());
}
@Override
public void mouseClicked(MouseEvent me) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(strURL));
} catch (IOException e1) {
e1.printStackTrace();
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(AboutView.this,
desktopNotSupportedString);
}
}
});
}
@Override
public void updateLanguage(Locale lang) {
setTitle(jBrickBreaker.getString("AboutView.0")); //$NON-NLS-1$
jlLink.setText("<html><a href=\"\">" + jBrickBreaker.getString("AboutView.1") + "</a></html>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
desktopNotSupportedString = jBrickBreaker.getString("AboutView.2"); //$NON-NLS-1$)
repaint();
}
}