KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > CustPanel


1 package sellwin.gui;
2
3 import sellwin.domain.*;
4 import sellwin.utils.*;
5
6 import javax.swing.*;
7 import javax.swing.table.*;
8 import javax.swing.event.*;
9 import javax.swing.border.*;
10 import java.rmi.*;
11 import java.awt.*;
12 import java.awt.event.*;
13 import java.util.*;
14
15 // SellWin http://sourceforge.net/projects/sellwincrm
16
//Contact support@open-app.com for commercial help with SellWin
17
//This software is provided "AS IS", without a warranty of any kind.
18

19 /**
20  * This class implements the Customer panel a user
21  * sees when they select the 'Customer' tab
22  * from the main window GUI.
23  */

24 public class CustPanel extends JPanel implements GUIChars {
25
26     private final static int TABLE_WIDTH=400;
27     private final static int TABLE_HEIGHT=150;
28
29     private JPopupMenu popup = new JPopupMenu();
30
31     private JPanel buttonPanel;
32     private JMenuItem newMenuItem;
33     private JMenuItem deleteMenuItem;
34     private JButton refreshButton;
35     private JMenuItem addProdMenuItem;
36     private final javax.swing.JPanel JavaDoc mainPanel = new JPanel();
37     private JLabel custLabel;
38     private JTextField custField;
39     private JLabel salesLabel;
40     private JTextField salesField;
41     private JLabel industryLabel;
42     private JTextField industryField;
43     private JLabel channelLabel;
44     private JTextField channelField;
45     private JLabel contactLabel;
46     private JTextField contactField;
47     private JLabel invLabel;
48     private JPanel invPanel;
49     private JScrollPane jScrollPane1;
50     private final javax.swing.JTable JavaDoc products = new JTable();
51
52     private Whiteboard wb;
53     private JPanel parent = null;
54     private ProductTableModel currentModel = null;
55     private ProductSelectionDialog addProductSelectionDialog = null;
56
57     private final static int STRUT_LEN=3;
58
59     /**
60      * construct a CustPanel
61      */

62     public CustPanel() {
63         super();
64         parent = this;
65         wb = MainWindow.getWhiteboard();
66         setLayout(new BorderLayout());
67
68         initComponents();
69         setFonts();
70         setColors();
71
72         setEditable(false);
73
74         refreshButton.addActionListener(
75             new ActionListener() {
76                 public void actionPerformed(ActionEvent e) {
77                     try {
78                         ArrayList inv = wb.getCustomerInventory();
79                         System.out.println(inv.size() + " = inv cnt");
80                         Customer cust = wb.getCurrentOpportunity().getCustomer();
81                         cust.setInventory(inv);
82                         if (inv.size() > 0)
83                             putCustomerOnScreen(cust);
84                     } catch (Exception JavaDoc x) {
85                         ErrorHandler.show(parent, x);
86                     }
87                 }
88             });
89
90         deleteMenuItem.addActionListener(
91             new ActionListener() {
92                 public void actionPerformed(ActionEvent e) {
93                     try {
94                         String JavaDoc custName = custField.getText();
95                         clearScreen();
96                         wb.deleteCustomer(custName);
97                         custField.setText("");
98                     } catch (Exception JavaDoc x) {
99                         ErrorHandler.show(parent, x);
100                     }
101                 }
102             });
103
104         addProdMenuItem.addActionListener(
105             new ActionListener() {
106                 public void actionPerformed(ActionEvent e) {
107                     try {
108                         if (addProductSelectionDialog == null)
109                             addProductSelectionDialog = new ProductSelectionDialog((InventoryListener)parent);
110                         addProductSelectionDialog.show();
111                         addProductSelectionDialog.requestFocus();
112                     } catch (Exception JavaDoc x) {
113                         ErrorHandler.show(parent, x);
114                     }
115                 }
116             });
117
118         setColor();
119     
120         createPopup();
121
122         mainPanel.addMouseListener(new MouseAdapter() {
123             public void mousePressed(MouseEvent e) {
124                 if (e.isPopupTrigger())
125                     popup.show(products, e.getX(), e.getY());
126             }
127             public void mouseReleased(MouseEvent e) {
128                 if (e.isPopupTrigger())
129                     popup.show(products, e.getX(), e.getY());
130             }
131             public void mouseClicked(MouseEvent e) {
132                 if (e.isPopupTrigger())
133                     popup.show(products, e.getX(), e.getY());
134             }
135         });
136         products.getTableHeader().addMouseListener(new MouseAdapter() {
137             public void mousePressed(MouseEvent e) {
138                 if (e.isPopupTrigger())
139                     popup.show(products, e.getX(), e.getY());
140             }
141             public void mouseReleased(MouseEvent e) {
142                 if (e.isPopupTrigger())
143                     popup.show(products, e.getX(), e.getY());
144             }
145             public void mouseClicked(MouseEvent e) {
146                 if (e.isPopupTrigger())
147                     popup.show(products, e.getX(), e.getY());
148             }
149         });
150         currentModel = new ProductTableModel(new ArrayList());
151         products.setModel(currentModel);
152         setLang();
153     }
154
155     /**
156      * construct the popup menu
157      */

158     public final void createPopup() {
159         popup.add(new JMenuItem("one"));
160     }
161
162     /**
163      * load the customer list into this panel
164      */

165     public final void loadCustomerList()
166         throws RemoteException, AngError {
167
168         custField.setText(wb.getCurrentOpportunity().getCustomer().getName());
169     }
170
171     /**
172      * enable or disable the panel's fields
173      * @param t true or false
174      */

175     public final void setEnabled(boolean t) {
176         custField.setEnabled(t);
177         salesField.setEnabled(t);
178         industryField.setEnabled(t);
179         channelField.setEnabled(t);
180         contactField.setEnabled(t);
181         products.setEnabled(t);
182     }
183
184     /**
185      * get a Customer from the screen's fields
186      * @return the Customer from the screen's fields
187      */

188     public final void getCustomerFromScreen() {
189         Customer cust = wb.getCustomer();
190         String JavaDoc custName = custField.getText();
191         cust.setName(custName);
192         cust.setAnnualSales(Integer.parseInt(salesField.getText()));
193         cust.setIndustry(industryField.getText());
194         cust.setChannel(channelField.getText());
195     }
196
197     /**
198      * clear the screen's fields
199      */

200     public final void clearScreen() {
201         salesField.setText("");
202         channelField.setText("");
203         contactField.setText("");
204         industryField.setText("");
205     }
206
207     /**
208      * put a Customer onto the screen
209      * @param c the Customer to display
210      */

211     public final void putCustomerOnScreen(Customer c) {
212         Utility.strSet(custField, c.getName());
213         Utility.strSet(salesField, Prefs.wholeMoney.format(c.getAnnualSales()));
214         Utility.strSet(channelField, c.getChannel());
215         Utility.strSet(industryField, c.getIndustry());
216         Utility.strSet(contactField, c.getContact().getFormattedName());
217         currentModel = new ProductTableModel(c.getInventory());
218         products.setModel(currentModel);
219         products.tableChanged(new TableModelEvent(currentModel));
220     }
221
222
223     /**
224      * set the screen's label colors
225      */

226     public final void setColor() {
227         custLabel.setForeground(MainWindow.LETTERS);
228         salesLabel.setForeground(MainWindow.LETTERS);
229         industryLabel.setForeground(MainWindow.LETTERS);
230         channelLabel.setForeground(MainWindow.LETTERS);
231         contactLabel.setForeground(MainWindow.LETTERS);
232         invLabel.setForeground(MainWindow.LETTERS);
233         products.setBackground(getBackground());
234     }
235
236     /**
237      * set the screen's fonts
238      */

239     public final void setFonts() {
240         custLabel.setFont(MainWindow.LABEL_FONT);
241         custField.setFont(MainWindow.FIELD_FONT);
242         salesLabel.setFont(MainWindow.LABEL_FONT);
243         salesField.setFont(MainWindow.FIELD_FONT);
244         industryLabel.setFont(MainWindow.LABEL_FONT);
245         industryField.setFont(MainWindow.FIELD_FONT);
246         channelLabel.setFont(MainWindow.LABEL_FONT);
247         channelField.setFont(MainWindow.FIELD_FONT);
248         contactLabel.setFont(MainWindow.LABEL_FONT);
249         invLabel.setFont(MainWindow.LABEL_FONT);
250         contactField.setFont(MainWindow.FIELD_FONT);
251         products.setFont(MainWindow.FIELD_FONT);
252         newMenuItem.setFont(MainWindow.LABEL_FONT);
253         deleteMenuItem.setFont(MainWindow.LABEL_FONT);
254         refreshButton.setFont(MainWindow.LABEL_FONT);
255         addProdMenuItem.setFont(MainWindow.LABEL_FONT);
256     }
257
258
259     /** This method is called from within the constructor to
260      * initialize the form.
261      */

262     private final void initComponents() {
263         buttonPanel = new JPanel();
264         newMenuItem = new JMenuItem();
265         deleteMenuItem = new JMenuItem();
266         refreshButton = new JButton();
267         addProdMenuItem = new JMenuItem();
268         custLabel = new JLabel();
269         custField = new JTextField();
270         salesLabel = new JLabel();
271         salesField = new JTextField();
272         industryLabel = new JLabel();
273         industryField = new JTextField();
274         channelLabel = new JLabel();
275         channelField = new JTextField();
276         contactLabel = new JLabel();
277         invPanel = new JPanel();
278         invLabel = new JLabel();
279         contactField = new JTextField();
280         jScrollPane1 = new JScrollPane();
281         
282         setLayout(new java.awt.BorderLayout JavaDoc());
283         
284         newMenuItem.setText("New");
285         
286         deleteMenuItem.setText("Delete");
287         
288         refreshButton.setText("Update");
289         buttonPanel.add(refreshButton);
290         
291         addProdMenuItem.setText("Add Product");
292        
293         //for the admin version, show this button panel
294
//and add the popup menu
295
add(buttonPanel, java.awt.BorderLayout.SOUTH);
296         
297         mainPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
298         java.awt.GridBagConstraints JavaDoc gridBagConstraints1;
299         
300         mainPanel.setBorder(new javax.swing.border.EtchedBorder JavaDoc());
301         custLabel.setText("Name");
302         custLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
303         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
304         gridBagConstraints1.gridx = 0;
305         gridBagConstraints1.gridy = 0;
306         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
307         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
308         mainPanel.add(custLabel, gridBagConstraints1);
309         
310         custField.setText("custField");
311         custField.setMinimumSize(new Dimension(120, Prefs.FIELD_HEIGHT));
312         custField.setPreferredSize(new Dimension(120, Prefs.FIELD_HEIGHT));
313         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
314         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
315         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
316         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
317         mainPanel.add(custField, gridBagConstraints1);
318         
319         salesLabel.setText("Annual Sales");
320         salesLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
321         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
322         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
323         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
324         mainPanel.add(salesLabel, gridBagConstraints1);
325         
326         salesField.setText("");
327         salesField.setMinimumSize(new Dimension(120, Prefs.FIELD_HEIGHT));
328         salesField.setPreferredSize(new Dimension(120, Prefs.FIELD_HEIGHT));
329         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
330         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
331         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
332         mainPanel.add(salesField, gridBagConstraints1);
333         
334         industryLabel.setText("Industry");
335         industryLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
336         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
337         gridBagConstraints1.gridx = 0;
338         gridBagConstraints1.gridy = 1;
339         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
340         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
341         mainPanel.add(industryLabel, gridBagConstraints1);
342         
343         industryField.setText("");
344         industryField.setMinimumSize(new Dimension(120, Prefs.FIELD_HEIGHT));
345         industryField.setPreferredSize(new Dimension(120, Prefs.FIELD_HEIGHT));
346         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
347         gridBagConstraints1.gridx = 1;
348         gridBagConstraints1.gridy = 1;
349         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
350         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
351         mainPanel.add(industryField, gridBagConstraints1);
352         
353         channelLabel.setText("Channel");
354         channelLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
355         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
356         gridBagConstraints1.gridx = 2;
357         gridBagConstraints1.gridy = 1;
358         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
359         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
360         mainPanel.add(channelLabel, gridBagConstraints1);
361         
362         channelField.setText("");
363         channelField.setMinimumSize(new Dimension(120, Prefs.FIELD_HEIGHT));
364         channelField.setPreferredSize(new Dimension(120, Prefs.FIELD_HEIGHT));
365         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
366         gridBagConstraints1.gridx = 3;
367         gridBagConstraints1.gridy = 1;
368         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
369         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
370         mainPanel.add(channelField, gridBagConstraints1);
371         
372         contactLabel.setText("Contact");
373         contactLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
374         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
375         gridBagConstraints1.gridx = 0;
376         gridBagConstraints1.gridy = 2;
377         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
378         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
379         mainPanel.add(contactLabel, gridBagConstraints1);
380
381         contactField.setText("");
382         contactField.setMinimumSize(new Dimension(120, Prefs.FIELD_HEIGHT));
383         contactField.setPreferredSize(new Dimension(120, Prefs.FIELD_HEIGHT));
384         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
385         gridBagConstraints1.gridx = 1;
386         gridBagConstraints1.gridy = 2;
387         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
388         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
389         mainPanel.add(contactField, gridBagConstraints1);
390       
391         jScrollPane1.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
392         jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
393         jScrollPane1.setPreferredSize(new Dimension(TABLE_WIDTH, TABLE_HEIGHT));
394         jScrollPane1.setMinimumSize(new Dimension(TABLE_WIDTH, TABLE_HEIGHT));
395         products.setModel(new javax.swing.table.DefaultTableModel JavaDoc(
396         new Object JavaDoc [][] {
397             {null, null, null, null},
398             {null, null, null, null},
399             {null, null, null, null},
400             {null, null, null, null}
401         },
402         new String JavaDoc [] {
403             "Title 1", "Title 2", "Title 3", "Title 4"
404         }
405         ) {
406             Class JavaDoc[] types = new Class JavaDoc [] {
407                 java.lang.Object JavaDoc.class, java.lang.Object JavaDoc.class, java.lang.Object JavaDoc.class, java.lang.Object JavaDoc.class
408             };
409             
410             public Class JavaDoc getColumnClass(int columnIndex) {
411                 return types [columnIndex];
412             }
413         });
414         products.setPreferredSize(new Dimension(TABLE_WIDTH, TABLE_HEIGHT));
415         products.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
416         products.setMinimumSize(new Dimension(TABLE_WIDTH, TABLE_HEIGHT));
417         jScrollPane1.setViewportView(products);
418         
419         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
420         gridBagConstraints1.gridx = 0;
421         gridBagConstraints1.gridy = 4;
422         gridBagConstraints1.gridwidth = 5;
423         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
424         gridBagConstraints1.insets = new Insets(Prefs.I_TOP,Prefs.I_LF,Prefs.I_BOTT,Prefs.I_RT);
425         gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
426         invPanel.add(jScrollPane1);
427         mainPanel.add(invPanel, gridBagConstraints1);
428         
429         add(mainPanel, java.awt.BorderLayout.CENTER);
430         
431     }
432
433     /**
434      * set the screen's fields to editable or not
435      * @param b true means editable
436      */

437     private final void setEditable(boolean b) {
438         custField.setEditable(b);
439         salesField.setEditable(b);
440         industryField.setEditable(b);
441         channelField.setEditable(b);
442         contactField.setEditable(b);
443     }
444
445     /**
446      * update the screen with the current opportunity
447      */

448     public final void refreshOpportunity() {
449         Opportunity opp = wb.getCurrentOpportunity();
450         Customer c = opp.getCustomer();
451         putCustomerOnScreen(c);
452     }
453
454     /**
455      * clear the screen
456      */

457     public final void clearOpportunity() {
458         Utility.strSet(custField, null);
459         Utility.strSet(salesField, null);
460         Utility.strSet(channelField, null);
461         Utility.strSet(industryField, null);
462         Utility.strSet(contactField, null);
463         currentModel = new ProductTableModel(new ArrayList());
464         products.setModel(currentModel);
465     }
466
467     /**
468      * set the screen's text to a language
469      */

470     public final void setLang() {
471         currentModel.setLang();
472         newMenuItem.setText(wb.getLang().getString("new"));
473         deleteMenuItem.setText(wb.getLang().getString("delete"));
474         refreshButton.setText(wb.getLang().getString("refresh"));
475         addProdMenuItem.setText(wb.getLang().getString("addProduct"));
476         custLabel.setText(wb.getLang().getString("name"));
477         salesLabel.setText(wb.getLang().getString("annualSales"));
478         industryLabel.setText(wb.getLang().getString("industry"));
479         channelLabel.setText(wb.getLang().getString("channel"));
480         contactLabel.setText(wb.getLang().getString("contact"));
481         invPanel.setBorder(
482             new TitledBorder(
483                 null,
484                 wb.getLang().getString("currInv"),
485                 TitledBorder.DEFAULT_JUSTIFICATION,
486                 TitledBorder.DEFAULT_POSITION,
487                 MainWindow.LABEL_FONT,
488                 MainWindow.LETTERS
489             )
490         );
491     }
492
493     public final void setColors() {
494     }
495 }
496
Popular Tags