01: package net.ar.webonswing.petstore;
02:
03: import javax.swing.*;
04:
05: import net.ar.webonswing.petstore.helpers.*;
06: import net.ar.webonswing.petstore.model.*;
07:
08: public class AddressView extends JPanel {
09: protected Address address;
10: protected Binder binder = new Binder();
11: private boolean editing = true;
12:
13: public AddressView() {
14: init();
15: }
16:
17: public AddressView(Address anAddress, boolean isEditing) {
18: editing = isEditing;
19: init();
20: setAddress(anAddress);
21: }
22:
23: protected void init() {
24: binder.add(getTextComponent(), "street1");
25: binder.add(getTextComponent(), "street2");
26: binder.add(getTextComponent(), "city");
27: binder.add(getTextComponent(), "state");
28: binder.add(getTextComponent(), "zipcode");
29: binder.add(getTextComponent(), "country");
30:
31: binder.addViewsToContainer(this );
32: binder.modelToView();
33: }
34:
35: protected JComponent getTextComponent() {
36: if (editing)
37: return new JTextField();
38: else
39: return new JLabel();
40: }
41:
42: public Address getAddress() {
43: binder.viewToModel();
44: return address;
45: }
46:
47: public void setAddress(Address anAddress) {
48: this.address = anAddress;
49: binder.setModel(anAddress);
50: binder.modelToView();
51: }
52: }
|