Example usage for com.jgoodies.binding.beans BeanAdapter BeanAdapter

List of usage examples for com.jgoodies.binding.beans BeanAdapter BeanAdapter

Introduction

In this page you can find the example usage for com.jgoodies.binding.beans BeanAdapter BeanAdapter.

Prototype

public BeanAdapter(ValueModel beanChannel) 

Source Link

Document

Constructs a BeanAdapter for the given bean channel; does not observe changes.

It is strongly recommended that the bean channel checks the identity not equity.

Usage

From source file:ambit2.db.results.test.AmbitRowsEventTest.java

License:Open Source License

public static void main(String[] args) {
    // http://www.java2s.com/Code/Java/Swing-Components/JGoodiesBindingSelectionInListModelExample.htm
    try {//from w  w  w . j  a va2 s.  com
        final AmbitRows<Dictionary> dictionary = new AmbitRows<Dictionary>() {
            /**
             * 
             */
            private static final long serialVersionUID = 6274513733204291475L;

            @Override
            protected synchronized IQueryRetrieval createNewQuery(Dictionary target) throws AmbitException {
                TemplateQuery q = new TemplateQuery();
                q.setValue(target.getTemplate());
                return q;
            }
        };

        final AmbitRows<Property> properties = new AmbitRows<Property>() {
            @Override
            protected synchronized IQueryRetrieval createNewQuery(Property target) throws AmbitException {
                QueryField q = new QueryField();
                q.setFieldname(target);
                return q;
            }

        };
        dictionary.addPropertyChangeListener(dictionary.getPropertyname(), properties);
        dictionary.addPropertyChangeListener("status", properties);

        AmbitRowsEventTest test = new AmbitRowsEventTest();
        test.setUpDatabase(test.getTestDatabase());
        IDatabaseConnection c = test.getConnection("localhost", "ambit2", "3306", "guest", "guest");
        dictionary.setConnection(c.getConnection());
        properties.setConnection(c.getConnection());

        DictionaryObjectQuery q = new DictionaryObjectQuery();
        q.setValue("Dataset");

        PropertyChangeSupport ps = new PropertyChangeSupport(test);
        ps.addPropertyChangeListener("topquery", dictionary);
        ps.firePropertyChange(new QueryChangeEvent(test, "topquery", null, q));

        final QueryField qf = new QueryField();
        properties.addPropertyChangeListener(properties.getPropertyname(), new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {

                try {
                    IQueryRetrieval r = properties.process((Property) evt.getNewValue());
                    qf.setFieldname(((QueryField) r).getFieldname());
                } catch (AmbitException x) {
                    x.printStackTrace();
                }
            }
        });

        ListModel listModel = new RowsModel<Dictionary>(dictionary);
        ValueModel selectedItemHolder1 = new ValueHolder();
        SelectionInList<Dictionary> selectionInList = new SelectionInList<Dictionary>(listModel,
                selectedItemHolder1);

        final JList jlist = new JList();
        Bindings.bind(jlist, selectionInList);

        BeanAdapter beanAdapter = new BeanAdapter(selectionInList);
        ValueModel nameModel = beanAdapter.getValueModel("template");
        ValueModel parentModel = beanAdapter.getValueModel("parentTemplate");

        ListModel listModel2 = new RowsModel<Property>(properties);
        ValueModel selectedItemHolder2 = new ValueHolder();
        SelectionInList<Property> selectionInList2 = new SelectionInList<Property>(listModel2,
                selectedItemHolder2);

        BeanAdapter beanAdapter2 = new BeanAdapter(qf);
        ValueModel fieldnameModel = beanAdapter2.getValueModel("fieldname");
        // ValueModel conditionModel =
        // beanAdapter2.getValueModel("condition");
        ValueModel valueModel = beanAdapter2.getValueModel("value");

        selectionInList.addPropertyChangeListener("value", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                try {
                    dictionary.process((Dictionary) evt.getNewValue());
                } catch (Exception x) {
                    x.printStackTrace();
                }

            }
        });

        selectionInList2.addPropertyChangeListener("value", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                try {

                } catch (Exception x) {
                    x.printStackTrace();
                }

            }
        });
        JPanel p = new JPanel();

        p.add(BasicComponentFactory.createTextField(nameModel));
        p.add(BasicComponentFactory.createTextField(parentModel));

        p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
        p.add(new JLabel("Dictionary"));
        p.add(new JScrollPane(jlist));
        // p.add(new JComboBox(new
        // ComboBoxAdapter<Dictionary>(selectionInList)));
        p.add(new JLabel("Properties"));
        final JComboBox combo = new JComboBox(new ComboBoxAdapter<Property>(selectionInList2));
        p.add(combo);
        p.add(BasicComponentFactory.createTextField(fieldnameModel));
        // p.add(BasicComponentFactory.createTextField(conditionModel));
        p.add(BasicComponentFactory.createIntegerField(valueModel));

        properties.addPropertyChangeListener("status", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                combo.setEnabled((Boolean) evt.getNewValue());
            }
        });
        JOptionPane.showMessageDialog(null, p);
        c.close();

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:ambit2.ui.editors.SelectFieldsPanel.java

License:Open Source License

protected void buildPanel(String help) {
    FormLayout layout = new FormLayout(
            "3dlu,fill:40dlu:grow,fill:120dlu:grow,3dlu,32dlu, 3dlu, fill:40dlu:grow,fill:120dlu:grow,3dlu", //columns
            "3dlu,12dlu,3dlu,top:[pref,36dlu], 24dlu,3dlu,24dlu,3dlu,24dlu,3dlu,24dlu,bottom:[pref,72dlu]:grow,1dlu,pref,pref,pref,pref,pref"); //rows
    setLayout(layout);//from  www. j  a  v  a 2s . c om
    CellConstraints cc = new CellConstraints();

    add(createSeparator("Available"), cc.xywh(2, 2, 2, 1));
    add(createSeparator("Selected"), cc.xywh(7, 2, 2, 1));

    tables = new JList[fieldsModel.length];
    for (int i = 0; i < fieldsModel.length; i++) {
        tables[i] = new JList(fieldsModel[i]);

        SelectionInList<Property> selectionInList = new SelectionInList<Property>(fieldsModel[i]);
        Bindings.bind(tables[i], selectionInList);
        JScrollPane p = new JScrollPane(tables[i]);
        p.setBorder(BorderFactory.createEtchedBorder());
        p.setPreferredSize(new Dimension(160, 280));
        int offset = 2 + i * 5;
        add(p, cc.xywh(offset, 4, 2, 9));

        BeanAdapter beanAdapter = new BeanAdapter(selectionInList);

        String[][] config = { { "name", "Name" }, { "label", "Alias" }, { "units", "Units" },
                { "title", "url" }, { "url", "WWW" } };
        for (int j = 0; j < config.length; j++) {
            String[] c = config[j];
            ValueModel model = beanAdapter.getValueModel(c[0]);
            add(BasicComponentFactory.createLabel(new ValueHolder(c[1])), cc.xywh(offset, j + 14, 1, 1));
            JTextField t = BasicComponentFactory.createTextField(model);
            t.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseEntered(MouseEvent e) {
                    super.mouseEntered(e);
                    ((JTextField) e.getSource()).setToolTipText(((JTextField) e.getSource()).getText());
                }
            });
            add(t, cc.xywh(offset + 1, j + 14, 1, 1));
        }
        /*
        ValueModel nameModel = beanAdapter.getValueModel("name");
        ValueModel commentsModel = beanAdapter.getValueModel("label");
        ValueModel titleModel = beanAdapter.getValueModel("title");
        ValueModel urlModel = beanAdapter.getValueModel("url");           
        //p.add(BasicComponentFactory.createTextField(parentModel));         
        add(BasicComponentFactory.createLabel(new ValueHolder("Name")),cc.xywh(offset,14,1,1));
        add(BasicComponentFactory.createTextField(nameModel),cc.xywh(offset+1,14,1,1));
        add(BasicComponentFactory.createLabel(new ValueHolder("Alias")),cc.xywh(offset,15,1,1));
        add(BasicComponentFactory.createTextField(commentsModel),cc.xywh(offset+1,15,1,1));
        add(BasicComponentFactory.createLabel(new ValueHolder("Reference")),cc.xywh(offset,16,1,1));
        add(BasicComponentFactory.createTextField(titleModel),cc.xywh(offset+1,16,1,1));         
        add(BasicComponentFactory.createLabel(new ValueHolder("WWW")),cc.xywh(offset,17,1,1));
        add(BasicComponentFactory.createTextField(urlModel),cc.xywh(offset+1,17,1,1));     
        */
    }

    buttons = new ArrayList<JButton>();
    int i = 0;
    for (MOVE op : MOVE.values()) {
        JButton button = new JButton(op.display());
        button.setPreferredSize(new Dimension(24, 24));
        button.setMaximumSize(new Dimension(24, 24));
        add(button, cc.xywh(5, 5 + (i * 2), 1, 1));
        button.addActionListener(this);
        button.setActionCommand(op.toString());
        i++;
    }

    /*
    JToolBar toolBar[] = new JToolBar[2];
    toolBar[0] = new JToolBar();
    toolBar[0].add(new JButton("Find"));
    toolBar[0].add(new JToolBar.Separator());
    toolBar[0].add(new JButton("Select all"));
    toolBar[0].add(new JButton("Unselect all"));
    toolBar[0].setFloatable(false);
    add(toolBar[0],cc.xywh(2,14,1,1));
            
    toolBar[1] = new JToolBar();
    toolBar[1].add(new JButton("Move Up"));
    toolBar[1].add(new JButton("Move Down"));
    toolBar[1].add(new JToolBar.Separator());
    toolBar[1].add(new JButton("Select all"));
    toolBar[1].add(new JButton("Unselect all"));
    toolBar[1].setFloatable(false);
    add(toolBar[1],cc.xywh(6,14,1,1));
    */
    /*
    helpArea = new JTextPane();
    helpArea.setText(help);
    helpArea.setEditable(false);
    helpArea.setBackground(new Color(255,255,225));
    helpArea.setPreferredSize(new Dimension(288,48));
    add(new JScrollPane(helpArea),cc.xywh(2,16,5,1));
    */

}

From source file:eu.europa.ec.markt.dss.applet.view.DSSAppletView.java

License:Open Source License

/**
 * //w  w w.j a v  a  2 s.  c om
 * The default constructor for DSSAppletView.
 * 
 * @param core
 * @param controller
 * @param model
 */
public DSSAppletView(final AppletCore core, final C controller, final M model) {
    super(core, controller, model);
    final BeanAdapter<M> beanAdapter = new BeanAdapter<M>(model);
    beanAdapter.addBeanPropertyChangeListener(this);
}

From source file:eu.europa.ec.markt.dss.applet.view.extension.SignatureView.java

License:Open Source License

/**
 * The default constructor for SignatureView.
 *
 * @param core//from  w w  w.j  a  va 2s.c o  m
 * @param controller
 * @param model
 */
public SignatureView(final AppletCore core, final ExtensionWizardController controller,
        final ExtendSignatureModel model) {
    super(core, controller, model);

    final BeanAdapter<ExtendSignatureModel> beanAdapter = new BeanAdapter<ExtendSignatureModel>(model);

    formatValueHolder = new ValueHolder(model.getFormat());
    formatValueHolder.addPropertyChangeListener(new FormatEventListener());

    cadesButton = ComponentFactory.createRadioButton(FormatType.CADES, formatValueHolder, FormatType.CADES);
    xadesButton = ComponentFactory.createRadioButton(FormatType.XADES, formatValueHolder, FormatType.XADES);
    padesButton = ComponentFactory.createRadioButton(FormatType.PADES, formatValueHolder, FormatType.PADES);
    asicsButton = ComponentFactory.createRadioButton(FormatType.ASICS, formatValueHolder, FormatType.ASICS);
    asiceButton = ComponentFactory.createRadioButton(FormatType.ASICE, formatValueHolder, FormatType.ASICE);

    packagingValueHolder = new ValueHolder(model.getPackaging());
    packagingValueHolder.addPropertyChangeListener(new PackagingEventListener());

    envelopingButton = ComponentFactory.createRadioButton(I18N_ENVELOPING, packagingValueHolder,
            SignaturePackaging.ENVELOPING);
    envelopedButton = ComponentFactory.createRadioButton(I18N_ENVELOPED, packagingValueHolder,
            SignaturePackaging.ENVELOPED);
    detachedButton = ComponentFactory.createRadioButton(I18N_DETACHED, packagingValueHolder,
            SignaturePackaging.DETACHED);

    final ValueModel levelValueModel = beanAdapter.getValueModel(ExtendSignatureModel.PROPERTY_LEVEL);
    levels = new SelectionInList<String>(new LevelComboBoxModel(), levelValueModel);
    levelComboBox = ComponentFactory.createComboBox(levels);
}

From source file:eu.europa.ec.markt.dss.applet.view.signature.PKCS11View.java

License:Open Source License

/**
 * /*  w ww.  j  ava2  s .  c  o m*/
 * The default constructor for PKCS11View.
 * 
 * @param core
 * @param controller
 * @param model
 */
public PKCS11View(final AppletCore core, final SignatureWizardController controller,
        final SignatureModel model) {
    super(core, controller, model);
    final BeanAdapter<SignatureModel> beanAdapter = new BeanAdapter<SignatureModel>(model);
    fileSourceLabel = ComponentFactory.createLabel(I18N_NO_FILE_SELECTED);
    selectFileSource = ComponentFactory.createFileChooser(I18N_BROWSE, true, new SelectPKCSFileEventListener());
    valueModel = beanAdapter.getValueModel(SignatureModel.PROPERTY_PKCS11_PASSWORD);
    passwordField = ComponentFactory.createPasswordField(valueModel, false);
}

From source file:eu.europa.ec.markt.dss.applet.view.signature.PKCS12View.java

License:Open Source License

/**
 * The default constructor for PKCS12View.
 *
 * @param core//from  w ww.  ja va2s  . c  o  m
 * @param controller
 * @param model
 */
public PKCS12View(final AppletCore core, final SignatureWizardController controller,
        final SignatureModel model) {
    super(core, controller, model);
    final BeanAdapter<SignatureModel> beanAdapter = new BeanAdapter<SignatureModel>(model);
    fileSourceLabel = ComponentFactory.createLabel(I18N_NO_FILE_SELECTED);
    selectFileSource = ComponentFactory.createFileChooser(I18N_BROWSE, true, new SelectPKCSFileEventListener());
    passwordField = ComponentFactory
            .createPasswordField(beanAdapter.getValueModel(SignatureModel.PROPERTY_PKCS12_PASSWORD), false);
}

From source file:eu.europa.ec.markt.dss.applet.view.signature.SignatureView.java

License:Open Source License

/**
 * The default constructor for SignatureView.
 *
 * @param core// www .j a  va  2s  .c  o m
 * @param controller
 * @param model
 */
public SignatureView(final AppletCore core, final SignatureWizardController controller,
        final SignatureModel model) {
    super(core, controller, model);

    final BeanAdapter<SignatureModel> beanAdapter = new BeanAdapter<SignatureModel>(model);

    formatValueHolder = new ValueHolder(model.getFormat());
    formatValueHolder.addPropertyChangeListener(new FormatEventListener());

    cadesButton = ComponentFactory.createRadioButton(FormatType.CADES, formatValueHolder, FormatType.CADES);
    xadesButton = ComponentFactory.createRadioButton(FormatType.XADES, formatValueHolder, FormatType.XADES);
    padesButton = ComponentFactory.createRadioButton(FormatType.PADES, formatValueHolder, FormatType.PADES);
    asicsButton = ComponentFactory.createRadioButton(FormatType.ASICS, formatValueHolder, FormatType.ASICS);
    asiceButton = ComponentFactory.createRadioButton(FormatType.ASICE, formatValueHolder, FormatType.ASICE);

    packagingValueHolder = new ValueHolder(model.getPackaging());
    packagingValueHolder.addPropertyChangeListener(new PackagingEventListener());

    envelopingButton = ComponentFactory.createRadioButton(I18N_ENVELOPING, packagingValueHolder,
            SignaturePackaging.ENVELOPING);
    envelopedButton = ComponentFactory.createRadioButton(I18N_ENVELOPED, packagingValueHolder,
            SignaturePackaging.ENVELOPED);
    detachedButton = ComponentFactory.createRadioButton(I18N_DETACHED, packagingValueHolder,
            SignaturePackaging.DETACHED);

    levelValue = beanAdapter.getValueModel(SignatureModel.PROPERTY_LEVEL);
    final SelectionInList<String> levels = new SelectionInList<String>(new LevelComboBoxModel(), levelValue);
    levelComboBox = ComponentFactory.createComboBox(levels);
}

From source file:eu.europa.esig.dss.applet.view.signature.SignatureView.java

License:Open Source License

/**
 * The default constructor for SignatureView.
 *
 * @param core//ww  w.  j a  va 2s  .co m
 * @param controller
 * @param model
 */
public SignatureView(final AppletCore core, final SignatureWizardController controller,
        final SignatureModel model) {
    super(core, controller, model);

    final BeanAdapter<SignatureModel> beanAdapter = new BeanAdapter<SignatureModel>(model);

    formatValueHolder = new ValueHolder(model.getFormat());
    formatValueHolder.addPropertyChangeListener(new FormatEventListener());

    cadesButton = ComponentFactory.createRadioButton(SignatureForm.CAdES.name(), formatValueHolder,
            SignatureForm.CAdES);
    xadesButton = ComponentFactory.createRadioButton(SignatureForm.XAdES.name(), formatValueHolder,
            SignatureForm.XAdES);
    padesButton = ComponentFactory.createRadioButton(SignatureForm.PAdES.name(), formatValueHolder,
            SignatureForm.PAdES);
    asicsButton = ComponentFactory.createRadioButton(SignatureForm.ASiC_S.getReadable(), formatValueHolder,
            SignatureForm.ASiC_S);
    asiceButton = ComponentFactory.createRadioButton(SignatureForm.ASiC_E.getReadable(), formatValueHolder,
            SignatureForm.ASiC_E);

    packagingValueHolder = new ValueHolder(model.getPackaging());
    packagingValueHolder.addPropertyChangeListener(new PackagingEventListener());

    envelopingButton = ComponentFactory.createRadioButton(I18N_ENVELOPING, packagingValueHolder,
            SignaturePackaging.ENVELOPING);
    envelopedButton = ComponentFactory.createRadioButton(I18N_ENVELOPED, packagingValueHolder,
            SignaturePackaging.ENVELOPED);
    detachedButton = ComponentFactory.createRadioButton(I18N_DETACHED, packagingValueHolder,
            SignaturePackaging.DETACHED);

    levelValue = beanAdapter.getValueModel(SignatureModel.PROPERTY_LEVEL);
    final SelectionInList<String> levels = new SelectionInList<String>(new LevelComboBoxModel(), levelValue);
    levelComboBox = ComponentFactory.createComboBox(levels);
}

From source file:org.mbari.aved.ui.classifier.ClassImageDirectoryFullView.java

License:Open Source License

private JPanel buildBottomPanel() {
    final JPanel panel = new JPanel(new FormLayout("2dlu, pref, 4dlu:grow, pref, 4dlu:grow, pref, 50dlu, 1dlu,",
            "pref, 3dlu:grow, pref"));
    CellConstraints cc = new CellConstraints();
    BeanAdapter adapter = new BeanAdapter(model);

    status = BasicComponentFactory.createLabel(adapter.getValueModel("status"));
    panel.add(status, cc.xy(2, 1));//from   w w  w  .j ava  2 s. c om
    panel.add(new JLabel("QuickKey = " + getQuickKey()), cc.xy(2, 3));

    int totalPages = (int) (model.getFileList().size() / MAX_FILES) + 1;
    PageComponent pc = new PageComponent(totalPages);

    pc.addPropertyChangeListener("currentPage", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            ClassImageDirectoryFullView.this.setPage((Integer) evt.getNewValue());
        }
    });
    panel.add(pc, cc.xy(4, 1));
    sizeSlider = new JSlider(SwingConstants.HORIZONTAL, 20, 400, gridSize);
    sizeSlider.setToolTipText("Slide to change image size");
    sizeSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            final JSlider source = (JSlider) e.getSource();

            if (!source.getValueIsAdjusting()) {
                source.setEnabled(false);

                try {
                    foxtrot.Worker.post(new foxtrot.Task() {
                        public void finish() {
                            source.setEnabled(true);
                        }

                        public Object run() throws Exception {
                            setGridSize(source.getValue());

                            return null;
                        }
                    });
                } catch (Exception ex) {
                    Logger.getLogger(ClassImageDirectoryFullView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });
    panel.add(new JLabel("Zoom:"), cc.xy(6, 1));
    panel.add(sizeSlider, cc.xy(7, 1));
    panel.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
        public void ancestorResized(HierarchyEvent e) {
            relayoutImagePanel();
        }
    });

    return panel;
}

From source file:org.mbari.aved.ui.classifier.ClassImageDirectorySynopsisView.java

License:Open Source License

private void init() {
    this.setLayout(new FormLayout("center:pref:grow", "center:pref:grow, max(20dlu;pref)"));

    CellConstraints ccMain = new CellConstraints();
    BeanAdapter modelAdapter = new BeanAdapter(model);
    JLabel mainLabel = new JLabel(model.getName());

    mainLabel.setFont(new Font("Serif", Font.BOLD, 24));
    mainLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
    mainLabel.setBorder(BorderFactory.createEmptyBorder());
    labelPanel = new JPanel();
    labelPanel.add(mainLabel);//from  ww  w  .  j a  va2  s  .  c  o m
    this.add(labelPanel, ccMain.xy(1, 1));

    JLabel dir = BasicComponentFactory.createLabel(modelAdapter.getValueModel("name"));

    bottomPanel = new JPanel(new FormLayout("2dlu, left:pref, fill:2dlu:grow, right:pref, 2dlu", "pref, pref"));

    CellConstraints cc = new CellConstraints();

    bottomPanel.add(dir, cc.xy(2, 2));

    final JLabel fileCount = new JLabel("Files: " + model.getFileList().size());

    model.addPropertyChangeListener("fileList", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    fileCount.setText("Files: " + model.getFileList().size());
                    fileCount.repaint();
                }
            });
        }
    });
    bottomPanel.add(fileCount, cc.xy(4, 2));

    if (getQuickKey() != 0) {
        bottomPanel.add(new JLabel("QuickKey = " + getQuickKey()), cc.xywh(2, 1, 3, 1));
    }

    this.add(bottomPanel, ccMain.xy(1, 2, CellConstraints.FILL, CellConstraints.BOTTOM));
}