use of org.qi4j.lib.swing.binding.SwingBindingAssembler in project qi4j-sdk by Qi4j.
the class Main method main.
public static void main(String[] args) throws Exception {
SingletonAssembler assembler = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.transients(BoundPersonComposite.class);
module.transients(AddressTransient.class);
module.values(CityValue.class, CountryValue.class);
new SwingBindingAssembler().assemble(module);
}
};
module = assembler.module();
Address address1 = createAddress("Vista Damai", "Jalan Tun Razak");
Address address2 = createAddress("Mutiara", "Jalan Ceylon");
TransientBuilder<BoundPersonComposite> builder = module.newTransientBuilder(BoundPersonComposite.class);
PersonComposite prototype = builder.prototype();
prototype.address().set(address1);
prototype.firstName().set("Niclas");
final BoundPersonComposite p1 = builder.newInstance();
prototype.address().set(address2);
prototype.firstName().set("Edward");
final BoundPersonComposite p2 = builder.newInstance();
final StateModel<BoundPersonComposite> model = module.newObject(StateModel.class, BoundPersonComposite.class);
Form form = new Form<BoundPersonComposite>(model);
JFrame frame = new JFrame("testing");
frame.add(form, BorderLayout.CENTER);
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.setFocusable(true);
checkBoxPanel.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
System.out.println("Gained!");
}
public void focusLost(FocusEvent e) {
System.out.println("LOst!");
}
});
JCheckBox sw = new JCheckBox("Toggle");
sw.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (((JCheckBox) e.getSource()).isSelected()) {
model.use(p1);
System.out.println(p1.firstName().get());
} else {
model.use(p2);
System.out.println(p2.firstName().get());
}
}
});
checkBoxPanel.add(sw);
frame.add(checkBoxPanel, BorderLayout.EAST);
frame.pack();
System.out.println(model);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
Aggregations