Search in sources :

Example 86 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project eclipse-pmd by acanda.

the class WorkspaceModelTest method addFiresAnAddElementPropertyChangeEvent.

/**
 * Verifies that an event is fired when adding a project model.
 */
@Test
public void addFiresAnAddElementPropertyChangeEvent() {
    final WorkspaceModel model = new WorkspaceModel();
    final boolean[] eventFired = new boolean[1];
    final ProjectModel element = new ProjectModel("Foo");
    model.addPropertyChangeListener(WorkspaceModel.PROJECTS_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            eventFired[0] = true;
            assertTrue("The event should be an AddElementPropertyChangeEvent", event instanceof AddElementPropertyChangeEvent);
            assertSame("Event's added element", element, ((AddElementPropertyChangeEvent) event).getAddedElement());
            assertNull("Event's old value should be null", event.getOldValue());
            assertSame("Event's new value should be the added element", element, event.getNewValue());
        }
    });
    model.add(element);
    assertTrue("An event should be fired when adding a project model", eventFired[0]);
}
Also used : RemoveElementPropertyChangeEvent(ch.acanda.eclipse.pmd.domain.DomainModel.RemoveElementPropertyChangeEvent) AddElementPropertyChangeEvent(ch.acanda.eclipse.pmd.domain.DomainModel.AddElementPropertyChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) AddElementPropertyChangeEvent(ch.acanda.eclipse.pmd.domain.DomainModel.AddElementPropertyChangeEvent) Test(org.junit.Test)

Example 87 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project knime-core by knime.

the class DropPane method createColumnList.

/**
 */
protected void createColumnList() {
    m_columnListModel = new DefaultListModel<String>();
    m_columnList = new JList<String>(m_columnListModel);
    m_columnList.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mousePressed(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mouseExited(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() > 1) {
                int i = m_columnList.getSelectedIndex();
                getConfig().addElement(m_columnListModel.get(i));
                m_columnListModel.remove(i);
            }
        }
    });
    m_columnList.setCellRenderer(new ListCellRenderer<String>() {

        @Override
        public Component getListCellRendererComponent(final JList<? extends String> list, final String value, final int index, final boolean isSelected, final boolean cellHasFocus) {
            if (value.endsWith(" ")) {
                JLabel l = new JLabel(value.trim());
                l.setBorder(BorderFactory.createLineBorder(Color.RED));
                return l;
            } else {
                return new JLabel(value);
            }
        }
    });
    m_columnList.setAutoscrolls(true);
    m_columnList.addPropertyChangeListener("dropLocation", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            DropLocation dropLocation = (DropLocation) (evt.getNewValue());
            if (dropLocation != null) {
                int mouseY = getParent().getMousePosition().y;
                int mouseX = getParent().getMousePosition().x;
                getParent().dispatchEvent(new MouseEvent(getParent(), MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, mouseX, mouseY, mouseX, mouseY, 1, false, MouseEvent.BUTTON1));
            }
        }
    });
    m_columnList.setDragEnabled(true);
    m_columnList.setTransferHandler(new ListTransferHandler());
    m_columnList.getModel().addListDataListener(new ListDataListener() {

        @Override
        public void intervalRemoved(final ListDataEvent e) {
            if (m_columnList.getModel().getSize() == 0) {
                getParent().remove(getComponentPanel());
                getParent().repaint();
                setParent(null);
                getConfig().removePanel(getPosition());
            } else if (!m_loading) {
                getConfig().getData().get(getPosition()).getSelection().clear();
                for (int i = 0; i < m_columnListModel.getSize(); i++) {
                    getConfig().getData().get(getPosition()).getSelection().add(m_columnListModel.getElementAt(i));
                }
            }
        }

        @Override
        public void intervalAdded(final ListDataEvent e) {
            if (!m_loading) {
                getConfig().getData().get(getPosition()).getSelection().clear();
                for (int i = 0; i < m_columnListModel.getSize(); i++) {
                    getConfig().getData().get(getPosition()).getSelection().add(m_columnListModel.getElementAt(i));
                }
            }
        }

        @Override
        public void contentsChanged(final ListDataEvent e) {
        // nothing
        }
    });
    m_columnList.setPreferredSize(new Dimension(100, 100));
    List<String> columns = getConfig().getData().get(getPosition()).getSelection();
    for (int i = 0; i < columns.size(); i++) {
        m_columnListModel.add(i, columns.get(i));
    }
    m_columnList.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) MouseEvent(java.awt.event.MouseEvent) PropertyChangeListener(java.beans.PropertyChangeListener) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ListDataListener(javax.swing.event.ListDataListener) ListDataEvent(javax.swing.event.ListDataEvent) MouseListener(java.awt.event.MouseListener) ListTransferHandler(org.knime.base.node.preproc.draganddroppanel.transferhandler.ListTransferHandler) Component(java.awt.Component) DropLocation(javax.swing.JList.DropLocation)

Example 88 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project knime-core by knime.

the class RenameNodeDialogPane method addToIndividualPanel.

private void addToIndividualPanel(final RenameColumnPanel panel) {
    panel.addPropertyChangeListener(RenameColumnPanel.REMOVE_ACTION, new PropertyChangeListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            removeFromIndividualPanel(panel);
        }
    });
    m_individualsPanel.add(panel);
    m_individualsPanel.revalidate();
    m_individualsPanel.ensureLastVisible();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 89 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project knime-core by knime.

the class ConstantValueColumnNodeDialogPane method connectRadioAndComponent.

/**
 * @param replaceColumnRadio
 */
private void connectRadioAndComponent(final JRadioButton replaceColumnRadio, final Component panel) {
    replaceColumnRadio.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            panel.setEnabled(replaceColumnRadio.isSelected());
        }
    });
    panel.addPropertyChangeListener("enabled", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            replaceColumnRadio.setSelected(panel.isEnabled());
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ItemListener(java.awt.event.ItemListener)

Example 90 with PropertyChangeListener

use of java.beans.PropertyChangeListener in project knime-core by knime.

the class AbstractCorrelationComputeNodeView method getJMenu.

private JMenu getJMenu() {
    JMenu menu = new JMenu("View");
    JCheckBoxMenuItem useColorBox = new JCheckBoxMenuItem("Use Colors");
    useColorBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            if (((JCheckBoxMenuItem) e.getSource()).isSelected()) {
                changeRenderer(ColorRender.DESCRIPTION);
            } else {
                changeRenderer(DoubleValueRenderer.STANDARD_RENDERER.getDescription());
            }
        }
    });
    useColorBox.addPropertyChangeListener("ancestor", new PropertyChangeListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            ((JCheckBoxMenuItem) evt.getSource()).setSelected(m_currentRendererID.equals(ColorRender.DESCRIPTION));
        }
    });
    JMenuItem colWidthItem = new JMenuItem("Cell Size...");
    colWidthItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            int colWidth = m_tableView.getColumnWidth();
            JSpinner s = new JSpinner(new SpinnerNumberModel(colWidth, 1, Integer.MAX_VALUE, 1));
            int r = JOptionPane.showConfirmDialog(m_tableView, s, "Cell Size", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (r == JOptionPane.OK_OPTION) {
                m_tableView.setColumnWidth((Integer) s.getValue());
                m_tableView.setRowHeight((Integer) s.getValue());
            }
        }
    });
    menu.add(useColorBox);
    menu.add(colWidthItem);
    return menu;
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) PropertyChangeEvent(java.beans.PropertyChangeEvent) ActionListener(java.awt.event.ActionListener) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JSpinner(javax.swing.JSpinner) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Aggregations

PropertyChangeListener (java.beans.PropertyChangeListener)228 PropertyChangeEvent (java.beans.PropertyChangeEvent)197 ActionEvent (java.awt.event.ActionEvent)27 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)27 ActionListener (java.awt.event.ActionListener)26 IFigure (org.eclipse.draw2d.IFigure)25 JPanel (javax.swing.JPanel)21 ArrayList (java.util.ArrayList)16 JLabel (javax.swing.JLabel)13 BorderLayout (java.awt.BorderLayout)12 Dimension (java.awt.Dimension)12 JButton (javax.swing.JButton)12 BoxLayout (javax.swing.BoxLayout)10 GridData (org.eclipse.swt.layout.GridData)10 GridLayout (org.eclipse.swt.layout.GridLayout)10 File (java.io.File)9 Composite (org.eclipse.swt.widgets.Composite)9 Test (org.junit.Test)9 IOException (java.io.IOException)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8