Search in sources :

Example 1 with ListTransferHandler

use of org.knime.base.node.preproc.draganddroppanel.transferhandler.ListTransferHandler 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 2 with ListTransferHandler

use of org.knime.base.node.preproc.draganddroppanel.transferhandler.ListTransferHandler in project knime-core by knime.

the class SelectionPanel method createInputList.

private void createInputList() {
    m_inputList = new JList<String>(m_config.getInputListModel());
    m_inputList.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mousePressed(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mouseExited(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() > 1) {
                int selectedIndex = m_inputList.getSelectedIndex();
                int i = m_config.drop((String) ((DefaultListModel) m_inputList.getModel()).get(selectedIndex));
                Pane dp = getNewPane(m_includePanel, m_config, i);
                m_includePanel.add(dp.getComponentPanel(), m_gbc);
                m_gbc.gridy++;
                m_includePanel.setBackground(UIManager.getColor("Panel.background"));
                m_scrollPane.revalidate();
                ((DefaultListModel) m_inputList.getModel()).removeElementAt(selectedIndex);
            }
        }
    });
    m_inputList.setDragEnabled(true);
    m_inputList.setTransferHandler(new ListTransferHandler());
    m_inputList.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    m_inputListScroller = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    m_inputListScroller.setPreferredSize(new Dimension(150, 200));
    m_inputListScroller.setViewportView(m_inputList);
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) ListTransferHandler(org.knime.base.node.preproc.draganddroppanel.transferhandler.ListTransferHandler) Dimension(java.awt.Dimension) JSplitPane(javax.swing.JSplitPane) Pane(org.knime.base.node.preproc.draganddroppanel.droppanes.Pane) JScrollPane(javax.swing.JScrollPane)

Aggregations

Dimension (java.awt.Dimension)2 MouseEvent (java.awt.event.MouseEvent)2 MouseListener (java.awt.event.MouseListener)2 ListTransferHandler (org.knime.base.node.preproc.draganddroppanel.transferhandler.ListTransferHandler)2 Component (java.awt.Component)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 JLabel (javax.swing.JLabel)1 DropLocation (javax.swing.JList.DropLocation)1 JScrollPane (javax.swing.JScrollPane)1 JSplitPane (javax.swing.JSplitPane)1 ListDataEvent (javax.swing.event.ListDataEvent)1 ListDataListener (javax.swing.event.ListDataListener)1 Pane (org.knime.base.node.preproc.draganddroppanel.droppanes.Pane)1