Package client.ws.milanas.gui

Source Code of client.ws.milanas.gui.BookResultInternalFrame

/*
* File: BookResultInternalFrame.java
* Created on 17 / desembre / 2007, 12:53
*
* Copyright (C) 2008 M.Àngels Cerveró Abelló
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package client.ws.milanas.gui;

import client.ws.milanas.helpers.beans.Book;
import client.ws.milanas.helpers.beans.CustomerReview;
import client.ws.milanas.helpers.beans.Item;
import client.ws.milanas.helpers.beans.Offer;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.font.TextAttribute;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Map;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

/**
*
* @author milana
*/
public class BookResultInternalFrame extends ResultInternalFrame
{
    private JLabel asin;
   
    /** Creates a new instance of BookResultInternalFrame */
    public BookResultInternalFrame(String frameTitle, Item item, int width, MilanasWSClientGUI parent, int indexTab, ResourceBundle messages, MessageFormat formatter)
    {
        super(frameTitle, parent, indexTab, messages);
        double imgHeight, imgWidth, imgProp = 0.0;
        int iniPosition, i, y, x = 0;
        int fontSize = 32;
        Book book = (Book) 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> authors = null;
        String aut = 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(book.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(book.getImage());
            image = new ImageIcon(new URL(book.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() + 50;
        JLabel asinLab = new JLabel(messages.getString("label.book.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 isbnLab = new JLabel(messages.getString("label.isbn"));
        isbnLab.setFont(labelsFont);
        isbnLab.setSize(150, 30);
        isbnLab.setLocation(x, y + 30 * 5);
        panel.add(isbnLab);
        JLabel authorLab = new JLabel(messages.getString("label.author"));
        authorLab.setFont(labelsFont);
        authorLab.setSize(150, 30);
        authorLab.setLocation(x, y + 30 * 6);
        panel.add(authorLab);
        JLabel publisherLab = new JLabel(messages.getString("label.publisher"));
        publisherLab.setFont(labelsFont);
        publisherLab.setSize(150, 30);
        publisherLab.setLocation(x, y + 30 * 7);
        panel.add(publisherLab);
        JLabel pubDateLab = new JLabel(messages.getString("label.pub.date"));
        pubDateLab.setFont(labelsFont);
        pubDateLab.setSize(150, 30);
        pubDateLab.setLocation(x, y + 30 * 8);
        panel.add(pubDateLab);
        JLabel sumLab = new JLabel(messages.getString("label.summary"));
        sumLab.setFont(labelsFont);
        sumLab.setSize(150, 30);
        sumLab.setLocation(x, y + 30 * 9);
        panel.add(sumLab);
       
        x = x + 150;
       
        asin = new JLabel(book.getAsin());
        asin.setSize((int) asin.getPreferredSize().getWidth(), 30);
        asin.setLocation(x, y);
        panel.add(asin);
        JLabel price = new JLabel(book.getPrice());
        price.setSize((int) price.getPreferredSize().getWidth(), 30);
        price.setLocation(x, y + 30);
        panel.add(price);
        JLabel sales = new JLabel(book.getSalesRank());
        sales.setSize((int) sales.getPreferredSize().getWidth(), 30);
        sales.setLocation(x, y + 30 * 2);
        panel.add(sales);
        JLabel average = null;
        if(book.getAverageRating().equals(""))
        {
            average = new JLabel(book.getAverageRating());
        }
        else
        {
            formatter.applyPattern(messages.getString("content.rating"));
            Object[] messageArguments = {book.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(book.getEan());
        ean.setSize((int) ean.getPreferredSize().getWidth(), 30);
        ean.setLocation(x, y + 30 * 4);
        panel.add(ean);
        JLabel isbn = new JLabel(book.getIsbn());
        isbn.setSize((int) isbn.getPreferredSize().getWidth(), 30);
        isbn.setLocation(x, y + 30 * 5);
        panel.add(isbn);
        authors = book.getAuthors();
        for(i = 0; i < authors.size(); i++)
        {
            if(i < authors.size() - 1)
            {
                aut = aut + authors.get(i) + " " + messages.getString("content.author") + " ";
            }
            else
            {
                aut = aut + authors.get(i);
            }
        }
        JLabel author = new JLabel(aut);
        author.setSize((int) author.getPreferredSize().getWidth(), 30);
        author.setLocation(x, y + 30 * 6);
        panel.add(author);
        JLabel publisher = new JLabel(book.getPublisher());
        publisher.setSize((int) publisher.getPreferredSize().getWidth(), 30);
        publisher.setLocation(x, y + 30 * 7);
        panel.add(publisher);
        JLabel pubDate = new JLabel(book.getPublicationDate());
        pubDate.setSize((int) pubDate.getPreferredSize().getWidth(), 30);
        pubDate.setLocation(x, y + 30 * 8);
        panel.add(pubDate);
        JTextPane sum = new JTextPane();
        aux = book.getSummary();
        aux = aux.replaceAll("<P>", "\n\n").replaceAll("<BR>", "\n").replaceAll("<.*>", "");
        sum.setText(aux);
        sum.setEditable(false);
        sum.setSize(width - (x + 50), 200);
        sum.setPreferredSize(new Dimension(width - (x + 50), 200));
        sum.setOpaque(true);
        JScrollPane sumScroll = new JScrollPane(sum, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        sumScroll.setLocation(x, y + 30 * 9);
        sumScroll.setSize(width - (x + 50), 210);
        sumScroll.setPreferredSize(new Dimension(width - (x + 50), 210));
        sumScroll.setBorder(BorderFactory.createLineBorder(Color.WHITE, 0));
        panel.add(sumScroll);
       
        y = y + (30 * 10) + 210;
       
        reviews = book.getReviews();
        offers = book.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.book.url"));
        urlLab.setSize((int) urlLab.getPreferredSize().getWidth(), 30);
        urlLab.setLocation(10, y);
        panel.add(urlLab);
        //url = new JLabel(book.getUrl());
        JLabel url = new JLabel(messages.getString("label.book.url"));
        urlString = book.getUrl();
        urlFont = url.getFont();
        fontAttrs = urlFont.getAttributes();
        fontAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        fontAttrs.put(TextAttribute.FOREGROUND, Color.BLUE);
        urlFont = urlFont.deriveFont(fontAttrs);
        url.setFont(urlFont);
        url.setSize((int) url.getPreferredSize().getWidth(), 30);
        url.setLocation(10, y + 30);
        url.addMouseListener(this);
        panel.add(url);
        y = y + 30 * 3;
       
        panel.setPreferredSize(new Dimension (width, y));
        content.add(scroll);
    }
}
TOP

Related Classes of client.ws.milanas.gui.BookResultInternalFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.