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

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

Introduction

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

Prototype

public synchronized void addBeanPropertyChangeListener(String propertyName, PropertyChangeListener listener) 

Source Link

Document

Adds a PropertyChangeListener to the list of bean listeners for a specific property.

Usage

From source file:com.stefanbrenner.droplet.ui.DevicePanel.java

License:Open Source License

/**
 * Create the panel./*from   w  w w.  ja  va 2 s .  c  o  m*/
 */
public DevicePanel(final JComponent parent, final IDroplet droplet, final T device) {

    this.parent = parent;

    setDevice(device);

    setLayout(new BorderLayout(0, 5));
    setBorder(BorderFactory.createLineBorder(Color.BLACK));
    setBackground(DropletColors.getBackgroundColor(device));

    BeanAdapter<T> adapter = new BeanAdapter<T>(device, true);

    // device name textfield
    txtName = BasicComponentFactory.createTextField(adapter.getValueModel(IDevice.PROPERTY_NAME));
    txtName.setHorizontalAlignment(SwingConstants.CENTER);
    txtName.setColumns(1);
    txtName.setToolTipText(device.getName());
    adapter.addBeanPropertyChangeListener(IDevice.PROPERTY_NAME, new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            txtName.setToolTipText(device.getName());
        }
    });
    add(txtName, BorderLayout.NORTH);

    // actions panel with scroll pane
    actionsPanel = new JPanel();
    actionsPanel.setLayout(new BoxLayout(actionsPanel, BoxLayout.Y_AXIS));
    actionsPanel.setBackground(getBackground());

    JScrollPane scrollPane = new JScrollPane(actionsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    // resize vertical scrollbar
    scrollPane.getVerticalScrollBar().putClientProperty("JComponent.sizeVariant", "mini"); //$NON-NLS-1$ //$NON-NLS-2$
    SwingUtilities.updateComponentTreeUI(scrollPane);
    // we need no border
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    add(scrollPane, BorderLayout.CENTER);

    {
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));

        createAddButton(panel);

        // remove button
        JButton btnRemove = new JButton(Messages.getString("ActionDevicePanel.removeDevice")); //$NON-NLS-1$
        btnRemove.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent action) {
                int retVal = JOptionPane.showConfirmDialog(DevicePanel.this,
                        Messages.getString("ActionDevicePanel.removeDevice") + " '" + device.getName() + "'?", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                        StringUtils.EMPTY, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (retVal == JOptionPane.YES_OPTION) {
                    droplet.removeDevice(device);
                }
            }
        });
        btnRemove.setFocusable(false);
        panel.add(btnRemove);

        add(panel, BorderLayout.SOUTH);
    }

}

From source file:com.stefanbrenner.droplet.ui.DropletToolbar.java

License:Open Source License

/**
 * Create the panel./*from   w  ww .  j a v  a2  s .com*/
 */
public DropletToolbar(final JFrame frame, final IDropletContext dropletContext) {

    this.dropletContext = dropletContext;

    setLayout(new FlowLayout(FlowLayout.RIGHT));

    // show button
    JButton btnDirect = new JButton(new ControlDevcieAction(frame, dropletContext));
    add(btnDirect);

    // show button
    JButton btnShow = new JButton(new ShowAction(frame, dropletContext));
    add(btnShow);

    // send button
    JButton btnSend = new JButton(new SendAction(frame, dropletContext));
    add(btnSend);

    BeanAdapter<IDropletContext> adapter = new BeanAdapter<IDropletContext>(dropletContext, true);

    // rounds spinner
    add(new JLabel(Messages.getString("DropletToolbar.rounds"))); //$NON-NLS-1$
    spRounds = new MouseWheelSpinner(true);
    spRounds.setModel(SpinnerAdapterFactory
            .createNumberAdapter(adapter.getValueModel(IDropletContext.PROPERTY_ROUNDS), 1, 1, 9999, 1));
    ((JSpinner.DefaultEditor) spRounds.getEditor()).getTextField().setColumns(4);
    add(spRounds);

    // round delay spinner
    add(new JLabel(Messages.getString("DropletToolbar.delay"))); //$NON-NLS-1$
    spRoundDelay = new MouseWheelSpinner(true);
    spRoundDelay.setModel(SpinnerAdapterFactory.createNumberAdapter(
            adapter.getValueModel(IDropletContext.PROPERTY_ROUND_DELAY), 1000, 0, 99999999, 1));
    ((JSpinner.DefaultEditor) spRoundDelay.getEditor()).getTextField().setColumns(8);
    updateTooltip();
    adapter.addBeanPropertyChangeListener(IDropletContext.PROPERTY_ROUND_DELAY, new PropertyChangeListener() {
        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            updateTooltip();
        }
    });
    add(spRoundDelay);

    // start button
    JButton btnStart = new JButton(new StartAction(frame, dropletContext));
    add(btnStart);

    // cancel button
    JButton btnCancel = new JButton(new CancelAction(frame, dropletContext));
    add(btnCancel);

}