01: package net.ar.webonswing.petstore;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05:
06: import javax.swing.*;
07:
08: import net.ar.webonswing.*;
09: import net.ar.webonswing.petstore.actions.*;
10: import net.ar.webonswing.petstore.model.*;
11:
12: public class Header extends JPanel {
13: public Header(Customer aCustomer, final Cart aCart,
14: final ApplicationFrame aFrame) {
15: JButton cartButton = new JButton("cart");
16: cartButton.addActionListener(new ActionListener() {
17: public void actionPerformed(ActionEvent e) {
18: WosFramework
19: .showChildWindow(Header.this
20: .getTopLevelAncestor(),
21: new CartViewPage(aCart));
22: }
23: });
24:
25: final JComboBox skinCombo = new JComboBox(ApplicationFrame
26: .getSkinManager().getSkins());
27:
28: JButton changeSkinButton = new JButton("change skin");
29: changeSkinButton.addActionListener(new ActionListener() {
30: public void actionPerformed(ActionEvent aE) {
31: aFrame.setCurrentSkin(skinCombo.getSelectedItem()
32: .toString());
33: }
34: });
35:
36: JButton searchButton = new JButton("search");
37: JTextField keyword = new JTextField();
38: SearchAction searchAction = new SearchAction(aFrame, keyword);
39: searchButton.addActionListener(searchAction);
40:
41: JPanel signBlock = new JPanel();
42: signBlock.setLayout(new GridLayout(0, 2));
43: JPanel conditional = new JPanel();
44: signBlock.add(conditional);
45:
46: if (aCustomer != null) {
47: JButton signOutButton = new JButton("sign out");
48: signOutButton.addActionListener(new ActionListener() {
49: public void actionPerformed(ActionEvent aE) {
50: aFrame.setCurrentCustomer(null);
51: WosFramework.showChildWindow(Header.this
52: .getTopLevelAncestor(), new Home());
53: }
54: });
55:
56: JButton myAccountButton = new JButton("my account");
57: myAccountButton.addActionListener(new ActionListener() {
58: public void actionPerformed(ActionEvent aE) {
59: WosFramework.showChildWindow(Header.this
60: .getTopLevelAncestor(), new AccountView(
61: aFrame.getCurrentCustomer()));
62: }
63: });
64:
65: conditional.add(signOutButton).setName("signOutButton");
66: conditional.add(myAccountButton).setName("myAccountButton");
67: conditional.setName("known");
68: } else {
69: JButton signInButton = new JButton("sign in");
70: signInButton.addActionListener(new ActionListener() {
71: public void actionPerformed(ActionEvent e) {
72: WosFramework.showChildWindow(Header.this
73: .getTopLevelAncestor(), new LoginPage());
74: }
75: });
76:
77: conditional.add(signInButton).setName("signInButton");
78: conditional.setName("anonymous");
79: }
80:
81: add(cartButton).setName("cartButton");
82: add(skinCombo).setName("skinCombo");
83: add(changeSkinButton).setName("changeSkinButton");
84: add(searchButton).setName("searchButton");
85: add(keyword).setName("keyword");
86: add(signBlock).setName("signBlock");
87: }
88: }
|