Package client.ws.milanas.gui

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

/*
* File: ResultInternalFrame.java
* Created on 24 / desembre / 2007, 15:51
*
* 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.CustomerReview;
import client.ws.milanas.helpers.beans.Offer;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDesktopPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

/**
*
* @author milana
*/
public class ResultInternalFrame extends ClosableTab implements MouseListener, ActionListener
{
    protected String urlString;
    protected JButton addCart;
    protected ArrayList<JCheckBox> checkGroup;
    protected ResourceBundle messages;
   
    /** Creates a new instance of ResultInternalFrame */
    public ResultInternalFrame(String frameTitle, MilanasWSClientGUI parent, int indexTab, ResourceBundle messages)
    {
        super(frameTitle, parent, indexTab);
    }
   
    public void mouseEntered (MouseEvent me){}
   
    public void mouseExited (MouseEvent me){}
   
    public void mouseReleased (MouseEvent me){}
   
    public void mousePressed (MouseEvent me){}
   
    public void mouseClicked (MouseEvent me)
    {
        try
        {
            Runtime.getRuntime().exec("firefox " + urlString);
        }
        catch(IOException e)
        {
            JOptionPane.showMessageDialog(null, messages.getString("label.buy.dialog"),
                        messages.getString("label.buy.dialog.title"),
                        JOptionPane.ERROR_MESSAGE);
        }
       
    }
   
    public void mouseDragged (MouseEvent me){}
   
    public void mouseMoved (MouseEvent me){}
   
    public void actionPerformed (ActionEvent event)
    {
        if (event.getSource ().getClass ().getName ().equals ("javax.swing.JButton"))
        {
            if((JButton) event.getSource() == addCart)
            {
                for(JCheckBox button : checkGroup)
                {
                    if(button.isSelected())
                    {
                        parent.addCart(button.getActionCommand());
                    }
                }
            }
        }
    }
   
    protected JDesktopPane getReviewsPanel(ArrayList<CustomerReview> reviews, int width, ResourceBundle messages, MessageFormat formatter)
    {
        String aux = null;
        Font reviewFont = null;
        JDesktopPane panel = new JDesktopPane();
        int i, y = 20;
        int x = 10;
        int numReviews = reviews.size();
        for (i = 0; i < numReviews; i++)
        {
            JLabel sumRevLab = new JLabel(reviews.get(i).getSummary());
            sumRevLab.setSize((int) sumRevLab.getPreferredSize().getWidth(), 30);
            sumRevLab.setLocation(x, y);
            panel.add(sumRevLab);
            reviewFont = new Font("SansSerif", Font.ITALIC, 9);
           
            formatter.applyPattern(messages.getString("label.review.info"));
            Object[] messageArguments1 = {reviews.get(i).getCustomerNick(), reviews.get(i).getDate()};           
            JLabel revLab = new JLabel(formatter.format(messageArguments1));
            revLab.setFont(reviewFont);
            revLab.setSize((int) revLab.getPreferredSize().getWidth(), (int) revLab.getPreferredSize().getHeight());
            revLab.setLocation(x, y + (int) sumRevLab.getSize().getHeight());
            panel.add(revLab);
            formatter.applyPattern(messages.getString("label.customer"));
            Object[] messageArguments2 = {reviews.get(i).getCustomerName(), reviews.get(i).getCustomerLocation(), reviews.get(i).getCustomerId()};      
            JLabel custLab = new JLabel(formatter.format(messageArguments2));
            custLab.setFont(reviewFont);
            custLab.setSize((int) custLab.getPreferredSize().getWidth(), (int) custLab.getPreferredSize().getHeight());
            custLab.setLocation(x, y + (int) (revLab.getSize().getHeight() + sumRevLab.getSize().getHeight()));
            panel.add(custLab);
            formatter.applyPattern(messages.getString("label.rating.info"));
            Object[] messageArguments3 = {reviews.get(i).getRating()};      
            JLabel ratLab = new JLabel(formatter.format(messageArguments3));
            ratLab.setSize((int) ratLab.getPreferredSize().getWidth(), 30);
            ratLab.setLocation(x, y + 50);
            panel.add(ratLab);
            JTextPane sumRev = new JTextPane();
            aux = reviews.get(i).getContent();
            aux = aux.replaceAll("<P>", "\n\n").replaceAll("<BR>", "\n").replaceAll("<.*>", "");
            sumRev.setText(aux);
            sumRev.setEditable(false);
            sumRev.setSize(width - 50, 75);
            sumRev.setPreferredSize(new Dimension(width - 50, 75));
            sumRev.setOpaque(true);
            JScrollPane sumRevScroll = new JScrollPane(sumRev, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            sumRevScroll.setLocation(x, y + 30 * 3);
            sumRevScroll.setSize(width - 50, 85);
            sumRevScroll.setPreferredSize(new Dimension(width - 50, 85));
            panel.add(sumRevScroll);
            formatter.applyPattern(messages.getString("label.asin.info"));
            Object[] messageArguments4 = {reviews.get(i).getAsin()};  
            JLabel asinRevLab = new JLabel(formatter.format(messageArguments4));
            asinRevLab.setSize((int) asinRevLab.getPreferredSize().getWidth(), 30);
            asinRevLab.setLocation(x, y + 30 * 3 + 85);
            panel.add(asinRevLab);
            formatter.applyPattern(messages.getString("label.review.votes"));
            Object[] messageArguments5 = {reviews.get(i).getReviewVotes()};  
            JLabel votesLab = new JLabel(formatter.format(messageArguments5));
            votesLab.setSize((int) votesLab.getPreferredSize().getWidth(), 30);
            votesLab.setLocation(x, y + 30 * 4 + 85);
            panel.add(votesLab);
            y = y + 30 * 6 + 85;
        }
        panel.setBorder(BorderFactory.createTitledBorder(messages.getString("label.review.title")));
        panel.setSize(width - 35, y);
        panel.setPreferredSize(panel.getSize());
        panel.setMinimumSize(panel.getSize());
        panel.setMaximumSize(panel.getSize());
        return panel;
    }
   
    protected JDesktopPane getOffersPanel(ArrayList<Offer> offers, int width, ResourceBundle messages)
    {
        JDesktopPane panel = new JDesktopPane();
        checkGroup = new ArrayList<JCheckBox>();
        int numOffers = offers.size();
        int x = 10;
        int y = 20;
        int i = 0;
        for (i = 0; i < numOffers; i++)
        {
            JCheckBox offerLab = new JCheckBox(messages.getString("label.offer"));
            offerLab.setSize((int) offerLab.getPreferredSize().getWidth(), 30);
            offerLab.setLocation(x, y);
            offerLab.setBackground(Color.WHITE);
            offerLab.setActionCommand(offers.get(i).getId());
            checkGroup.add(offerLab);
            panel.add(offerLab);
            JLabel offerPrice = new JLabel(offers.get(i).getPrice());
            offerPrice.setSize((int) offerPrice.getPreferredSize().getWidth(), 30);
            offerPrice.setLocation((width - 310) / 3, y);
            panel.add(offerPrice);
            JLabel offerCond = new JLabel(offers.get(i).getCondition());
            offerCond.setSize((int) offerCond.getPreferredSize().getWidth(), 30);
            offerCond.setLocation(2 * (width - 310) / 3, y);
            panel.add(offerCond);
            y = y + 40;    
        }
        addCart = new JButton(messages.getString("button.cart"));
        addCart.setSize((int) addCart.getPreferredSize().getWidth(), 50);
        addCart.setLocation(width - 200,  y);
        addCart.addActionListener(this);
        panel.add(addCart);
       
        panel.setBorder(BorderFactory.createTitledBorder(messages.getString("offer.title")));
        panel.setSize(width - 35, y + 60);
        panel.setPreferredSize(panel.getSize());
        panel.setMinimumSize(panel.getSize());
        panel.setMaximumSize(panel.getSize());
        return panel;
    }
   
}
TOP

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

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.