{
super(frameTitle, parent, indexTab, messages);
double imgHeight, imgWidth, imgProp = 0.0;
int iniPosition, i, y, x = 0;
int fontSize = 32;
Music music = (Music) item;
Font titleFont = new Font("SansSerif", Font.BOLD, fontSize);
Font labelsFont = new Font("SansSerif", Font.BOLD, 12);
Font urlFont = null;
Map fontAttrs = null;
ArrayList<String> artists = null;
String art = new String();
String aux = null;
ArrayList<CustomerReview> reviews = null;
ArrayList<Offer> offers = null;
JDesktopPane panel = new JDesktopPane();
JScrollPane scroll = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container content = getContentPane();
JLabel title = new JLabel(music.getTitle());
title.setFont(titleFont);
title.setSize((int) title.getPreferredSize().getWidth(), (int) title.getPreferredSize().getHeight());
while(title.getSize().getWidth() > (width - 17))
{
fontSize--;
titleFont = new Font("SansSerif", Font.BOLD, fontSize);
title.setFont(titleFont);
title.setSize((int) title.getPreferredSize().getWidth(), (int) title.getPreferredSize().getHeight());
}
iniPosition = (int) (((width - 17) - title.getSize().getWidth()) / 2);
title.setLocation(iniPosition, 0);
panel.add(title);
JLabel imgLabel = new JLabel();
ImageIcon image = null;
Image img = null;
try
{
URL imgUrl = new URL(music.getImage());
image = new ImageIcon(new URL(music.getImage()));
}
catch(MalformedURLException mue)
{
image = new ImageIcon("");
}
img = image.getImage();
imgHeight = img.getHeight(image.getImageObserver());
imgWidth = img.getWidth(image.getImageObserver());
imgProp = imgHeight/imgWidth;
if(imgHeight > 300)
{
imgHeight = 300;
imgWidth = imgHeight / imgProp;
}
if(imgWidth > 300)
{
imgWidth = 300;
imgHeight = imgWidth * imgProp;
}
img = img.getScaledInstance((int) imgWidth, (int) imgHeight, Image.SCALE_SMOOTH);
image.setImage(img);
imgLabel.setIcon(image);
imgLabel.setSize((int) imgWidth, (int) imgHeight);
y = (int) title.getPreferredSize().getHeight() + 10;
imgLabel.setLocation(10, y);
panel.add(imgLabel);
x = (int) imgLabel.getSize().getWidth() + 200;
asin = new JLabel(music.getAsin());
asin.setSize((int) asin.getPreferredSize().getWidth(), 30);
asin.setLocation(x, y);
panel.add(asin);
JLabel price = new JLabel(music.getPrice());
price.setSize((int) price.getPreferredSize().getWidth(), 30);
price.setLocation(x, y + 30);
panel.add(price);
JLabel sales = new JLabel(music.getSalesRank());
sales.setSize((int) sales.getPreferredSize().getWidth(), 30);
sales.setLocation(x, y + 30 * 2);
panel.add(sales);
JLabel average = null;
if(music.getAverageRating().equals(""))
{
average = new JLabel(music.getAverageRating());
}
else
{
formatter.applyPattern(messages.getString("content.rating"));
Object[] messageArguments = {music.getAverageRating()};
average = new JLabel(formatter.format(messageArguments));
}
average.setSize((int) average.getPreferredSize().getWidth(), 30);
average.setLocation(x, y + 30 * 3);
panel.add(average);
JLabel ean = new JLabel(music.getEan());
ean.setSize((int) ean.getPreferredSize().getWidth(), 30);
ean.setLocation(x, y + 30 * 4);
panel.add(ean);
artists = music.getArtists();
int line = 1;
art = "<html>";
for(i = 0; i < artists.size(); i++)
{
if((i % 2) == 0 && !art.equals("<html>"))
{
art = art + "<br/>";
line++;
}
if(i != artists.size() - 1)
{
art = art + artists.get(i) + ", ";
}
else
{
art = art + artists.get(i);
}
}
art = art + "</html>";
JLabel artist = new JLabel(art);
artist.setSize((int) artist.getPreferredSize().getWidth(), (int) artist.getPreferredSize().getHeight() + 30);
artist.setLocation(x, y + 30 * 5);
panel.add(artist);
JLabel studio = new JLabel(music.getStudio());
studio.setSize((int) studio.getPreferredSize().getWidth(), 30);
studio.setLocation(x, y + 30 * 5 + (int) artist.getSize().getHeight());
panel.add(studio);
JLabel publisher = new JLabel(music.getPublisher());
publisher.setSize((int) publisher.getPreferredSize().getWidth(), 30);
publisher.setLocation(x, y + 30 * 6 + (int) artist.getSize().getHeight());
panel.add(publisher);
JLabel pubDate = new JLabel(music.getPublicationDate());
pubDate.setSize((int) pubDate.getPreferredSize().getWidth(), 30);
pubDate.setLocation(x, y + 30 * 7 + (int) artist.getSize().getHeight());
panel.add(pubDate);
JTextPane sum = new JTextPane();
aux = music.getSummary();
aux = aux.replaceAll("<P>", "\n\n").replaceAll("<BR>", "\n").replaceAll("<.*>", "");
sum.setText(aux);
sum.setEditable(false);
sum.setSize(width - (x + 50), 100);
sum.setPreferredSize(new Dimension(width - (x + 50), 100));
sum.setOpaque(true);
JScrollPane sumScroll = new JScrollPane(sum, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
sumScroll.setLocation(x, y + 30 * 8 + (int) artist.getSize().getHeight());
sumScroll.setSize(width - (x + 50), 110);
sumScroll.setPreferredSize(new Dimension(width - (x + 50), 110));
sumScroll.setBorder(BorderFactory.createLineBorder(Color.WHITE, 0));
panel.add(sumScroll);
x = (int) imgLabel.getSize().getWidth() + 50;
JLabel asinLab = new JLabel(messages.getString("label.music.id"));
asinLab.setFont(labelsFont);
asinLab.setSize(150, 30);
asinLab.setLocation(x, y);
panel.add(asinLab);
JLabel priceLab = new JLabel(messages.getString("label.price"));
priceLab.setFont(labelsFont);
priceLab.setSize(150, 30);
priceLab.setLocation(x, y + 30);
panel.add(priceLab);
JLabel salesLab = new JLabel(messages.getString("label.rank"));
salesLab.setFont(labelsFont);
salesLab.setSize(150, 30);
salesLab.setLocation(x, y + 30 * 2);
panel.add(salesLab);
JLabel averageLab = new JLabel(messages.getString("label.rating"));
averageLab.setFont(labelsFont);
averageLab.setSize(150, 30);
averageLab.setLocation(x, y + 30 * 3);
panel.add(averageLab);
JLabel eanLab = new JLabel(messages.getString("label.ean"));
eanLab.setFont(labelsFont);
eanLab.setSize(150, 30);
eanLab.setLocation(x, y + 30 * 4);
panel.add(eanLab);
JLabel artistLab = new JLabel(messages.getString("label.artist"));
artistLab.setFont(labelsFont);
artistLab.setSize(150, 30);
artistLab.setLocation(x, y + 30 * 5);
panel.add(artistLab);
JLabel studioLab = new JLabel(messages.getString("label.studio"));
studioLab.setFont(labelsFont);
studioLab.setSize(150, 30);
studioLab.setLocation(x, y + 30 * 5 + (int) artist.getSize().getHeight());
panel.add(studioLab);
JLabel publisherLab = new JLabel(messages.getString("label.publisher"));
publisherLab.setFont(labelsFont);
publisherLab.setSize(150, 30);
publisherLab.setLocation(x, y + 30 * 6 + (int) artist.getSize().getHeight());
panel.add(publisherLab);
JLabel pubDateLab = new JLabel(messages.getString("label.pub.date"));
pubDateLab.setFont(labelsFont);
pubDateLab.setSize(150, 30);
pubDateLab.setLocation(x, y + 30 * 7 + (int) artist.getSize().getHeight());
panel.add(pubDateLab);
JLabel sumLab = new JLabel(messages.getString("label.summary"));
sumLab.setFont(labelsFont);
sumLab.setSize(150, 30);
sumLab.setLocation(x, y + 30 * 8 + (int) artist.getSize().getHeight());
panel.add(sumLab);
x = (int) imgLabel.getSize().getWidth() + 200;
y = y + (30 * 10 + (int) artist.getSize().getHeight()) + 110;
reviews = music.getReviews();
offers = music.getOffers();
if(reviews.size() > 0 || offers.size() > 0)
{
JLabel infoLab = new JLabel(messages.getString("label.info"));
infoLab.setSize((int) infoLab.getPreferredSize().getWidth(), 30);
infoLab.setLocation(10, y);
panel.add(infoLab);
}
y = y + 30;
if(reviews.size() > 0)
{
JDesktopPane reviewsPanel = getReviewsPanel(reviews, width, messages, formatter);
reviewsPanel.setLocation(0, y);
panel.add(reviewsPanel);
y = y + (int) reviewsPanel.getSize().getHeight() + 30;
}
if(offers.size() > 0)
{
JDesktopPane offersPanel = getOffersPanel(offers, width, messages);
offersPanel.setLocation(0, y);
panel.add(offersPanel);
y = y + (int) offersPanel.getSize().getHeight() + 30;
}
JLabel urlLab = new JLabel(messages.getString("label.info.music.url"));
urlLab.setSize((int) urlLab.getPreferredSize().getWidth(), 30);
urlLab.setLocation(10, y);
panel.add(urlLab);
//url = new JLabel(music.getUrl());
JLabel url = new JLabel(messages.getString("label.music.url"));
urlString = music.getUrl();
urlFont = url.getFont();
fontAttrs = urlFont.getAttributes();
fontAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
fontAttrs.put(TextAttribute.FOREGROUND, Color.BLUE);
urlFont = urlFont.deriveFont(fontAttrs);