Search in sources :

Example 61 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project jPOS by jpos.

the class ISOMsgPanel method createISOMsgTable.

private JComponent createISOMsgTable() {
    TableModel dataModel = new AbstractTableModel() {

        private static final long serialVersionUID = 8917029825751856951L;

        @Override
        public int getColumnCount() {
            return 3;
        }

        @Override
        public int getRowCount() {
            return validFields.size();
        }

        @Override
        public String getColumnName(int columnIndex) {
            switch(columnIndex) {
                case 0:
                    return "#";
                case 1:
                    return "Content";
                case 2:
                    return "Description";
                default:
                    return "";
            }
        }

        @Override
        public Object getValueAt(int row, int col) {
            switch(col) {
                case 0:
                    return validFields.elementAt(row);
                case 1:
                    int index = (Integer) validFields.elementAt(row);
                    Object obj = m.getValue(index);
                    if (obj instanceof String) {
                        String s = obj.toString();
                        switch(index) {
                            case 2:
                            case 35:
                            case 45:
                                s = ISOUtil.protect(s);
                                break;
                            case 14:
                                s = "----";
                        }
                        return s;
                    } else if (obj instanceof byte[])
                        return ISOUtil.hexString((byte[]) obj);
                    else if (obj instanceof ISOMsg)
                        return "<ISOMsg>";
                    break;
                case 2:
                    int i = (Integer) validFields.elementAt(row);
                    ISOPackager p = m.getPackager();
                    return p.getFieldDescription(m, i);
            }
            return "<???>";
        }
    };
    JTable table = new JTable(dataModel);
    table.getColumnModel().getColumn(0).setPreferredWidth(10);
    table.setPreferredScrollableViewportSize(new Dimension(500, table.getRowCount() * table.getRowHeight()));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    ListSelectionModel rowSM = table.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            ListSelectionModel lsm = (ListSelectionModel) e.getSource();
            if (!lsm.isSelectionEmpty()) {
                int selectedRow = lsm.getMinSelectionIndex();
                int index = (Integer) validFields.elementAt(selectedRow);
                Object obj = m.getValue(index);
                if (obj instanceof ISOMsg) {
                    ISOMsg sm = (ISOMsg) obj;
                    JFrame f = new JFrame("ISOMsg field " + index);
                    ISOMsgPanel p = new ISOMsgPanel(sm, false);
                    f.getContentPane().add(p);
                    f.pack();
                    f.show();
                }
            }
        }
    });
    return new JScrollPane(table);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ISOPackager(org.jpos.iso.ISOPackager) ISOMsg(org.jpos.iso.ISOMsg) AbstractTableModel(javax.swing.table.AbstractTableModel) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 62 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project knime-core by knime.

the class JSnippetPanel method initComponents.

private void initComponents() {
    m_colList = new JList(new DefaultListModel());
    m_colList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_colList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_colList.getSelectedValue();
                if (selected != null) {
                    onSelectionInColumnList(selected);
                }
            }
        }
    });
    m_colList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_colList.getSelectedValue();
                if (selected != null) {
                    onSelectionInColumnList(selected);
                }
            }
        }
    });
    m_colList.setCellRenderer(new ListRenderer());
    m_flowVarsList = new JList(new DefaultListModel());
    m_flowVarsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // enable tooltip
    m_flowVarsList.setToolTipText("");
    m_flowVarsList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_flowVarsList.getSelectedValue();
                if (selected != null) {
                    onSelectionInVariableList(selected);
                }
            }
        }
    });
    m_flowVarsList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_flowVarsList.getSelectedValue();
                if (selected != null) {
                    onSelectionInVariableList(selected);
                }
            }
        }
    });
    m_flowVarsList.setCellRenderer(new FlowVariableListCellRenderer());
    m_categories = new JComboBox(m_manipProvider.getCategories().toArray());
    m_categories.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            String category = (String) cb.getSelectedItem();
            updateManipulatorList(category);
        }
    });
    m_manipulators = new JList(new DefaultListModel());
    m_manipulators.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_manipulators.setCellRenderer(new ManipulatorListCellRenderer());
    m_manipulators.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_manipulators.getSelectedValue();
                if (selected != null) {
                    onSelectionInManipulatorList(selected);
                }
            }
        }
    });
    m_manipulators.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_manipulators.getSelectedValue();
                if (selected != null) {
                    onSelectionInManipulatorList(selected);
                }
            }
        }
    });
    m_manipulators.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            Object selected = m_manipulators.getSelectedValue();
            if (selected != null) {
                Manipulator manipulator = (Manipulator) selected;
                m_description.setText(manipulator.getDescription());
                m_description.setCaretPosition(0);
            } else {
                m_description.setText("");
            }
        }
    });
    HTMLEditorKit kit = new HTMLEditorKit();
    StyleSheet css = new StyleSheet();
    css.addRule("* { font-family: sans-serif; }");
    kit.setStyleSheet(css);
    m_description = new JTextPane();
    m_description.setEditorKit(kit);
    m_description.setEditable(false);
    m_description.setBackground(getBackground());
    updateManipulatorList(ManipulatorProvider.ALL_CATEGORY);
    initSubComponents();
}
Also used : MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DefaultListModel(javax.swing.DefaultListModel) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) ListSelectionListener(javax.swing.event.ListSelectionListener) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator) KeyEvent(java.awt.event.KeyEvent) FlowVariableListCellRenderer(org.knime.core.node.util.FlowVariableListCellRenderer) JTextPane(javax.swing.JTextPane) StyleSheet(javax.swing.text.html.StyleSheet) ActionListener(java.awt.event.ActionListener) JList(javax.swing.JList)

Example 63 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project knime-core by knime.

the class MissingValueHandling2Panel method createWestLayout.

/**
 * @param setting
 * @param tabPanel
 * @param icon
 * @param name
 * @param spec
 */
private void createWestLayout(final MissingValueHandling2ColSetting setting, final JPanel tabPanel, final Icon icon, final String name, final DataColumnSpec... spec) {
    String shortName = name;
    if (setting.isMetaConfig()) {
        if (name.length() > 15) {
            shortName = name.substring(0, 14).concat("...");
        }
        JLabel jLabel = new JLabel(shortName, icon, SwingConstants.LEFT);
        jLabel.setToolTipText(name);
        JPanel typePanel = new JPanel(new BorderLayout());
        typePanel.add(jLabel, BorderLayout.NORTH);
        tabPanel.add(typePanel, BorderLayout.WEST);
    } else {
        final JList jList = new JList(spec);
        jList.setCellRenderer(new DataColumnSpecListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
                // The super method will reset the icon if we call this method
                // last. So we let super do its job first and then we take care
                // that everything is properly set.
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                String text = null;
                if (value instanceof DataColumnSpec && MissingValueHandling2NodeDialogPane.isIncompatible((DataColumnSpec) value)) {
                    setBorder(BorderFactory.createLineBorder(Color.YELLOW));
                    text = "Column " + ((DataColumnSpec) value).getName() + " is incompatible to the current settings";
                }
                setToolTipText(text);
                return this;
            }
        });
        jList.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(final ListSelectionEvent e) {
                jList.setSelectedIndices(new int[0]);
            }
        });
        // jList.setSE
        JScrollPane columns = new JScrollPane(jList);
        columns.setMaximumSize(new Dimension(150, 150));
        columns.setPreferredSize(new Dimension(100, 150));
        tabPanel.add(columns, BorderLayout.WEST);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) DataColumnSpec(org.knime.core.data.DataColumnSpec) BorderLayout(java.awt.BorderLayout) JComponent(javax.swing.JComponent) Component(java.awt.Component) JList(javax.swing.JList)

Example 64 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project knime-core by knime.

the class RuleEngineNodeDialog method createTopPart.

/*
     * top part (from left to right) = variable list, operator list, editor box
     */
private Box createTopPart() {
    /*
         * Variable list (column names)
         */
    m_variableModel = new DefaultListModel();
    m_variableList = new JList(m_variableModel);
    m_variableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_variableList.setCellRenderer(new DataColumnSpecListCellRenderer());
    m_variableList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent arg0) {
            if (arg0.getValueIsAdjusting()) {
                return;
            }
            if (m_lastUsedTextfield != null) {
                String existingText = m_lastUsedTextfield.getText();
                if (existingText.equals(RULE_LABEL)) {
                    existingText = "";
                }
                if (!m_variableList.isSelectionEmpty()) {
                    String newText = ((DataColumnSpec) m_variableList.getSelectedValue()).getName();
                    m_lastUsedTextfield.setText((existingText + " $" + newText + "$").trim());
                    m_lastUsedTextfield.requestFocusInWindow();
                    if (m_lastUsedTextfield == m_ruleLabelEditor) {
                        m_outcomeIsColumn.setSelected(true);
                    }
                }
            }
            m_variableList.clearSelection();
        }
    });
    /*
         * Operators (<, >, <=, >=, =, AND, OR, etc)
         */
    m_operatorModel = new DefaultListModel();
    m_operatorList = new JList(m_operatorModel);
    m_operatorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_operatorList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent arg0) {
            if (!arg0.getValueIsAdjusting() && !m_operatorList.isSelectionEmpty()) {
                String existingText = m_ruleEditor.getText();
                if (existingText.equals(RULE_LABEL)) {
                    existingText = "";
                }
                String newText = (String) m_operatorList.getSelectedValue();
                m_ruleEditor.setText(existingText + " " + newText);
                m_ruleEditor.requestFocusInWindow();
                m_operatorList.clearSelection();
            }
        }
    });
    Box editorBox = createEditorPart();
    Box listBox = Box.createHorizontalBox();
    JScrollPane variableScroller = new JScrollPane(m_variableList);
    variableScroller.setBorder(BorderFactory.createTitledBorder("Columns"));
    JScrollPane operatorScroller = new JScrollPane(m_operatorList);
    operatorScroller.setBorder(BorderFactory.createTitledBorder("Operators"));
    listBox.add(variableScroller);
    listBox.add(operatorScroller);
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listBox, editorBox);
    Dimension minimumSize = new Dimension(200, 50);
    listBox.setMinimumSize(minimumSize);
    editorBox.setMinimumSize(minimumSize);
    Box topBox = Box.createHorizontalBox();
    topBox.add(splitPane);
    topBox.add(Box.createHorizontalGlue());
    return topBox;
}
Also used : JScrollPane(javax.swing.JScrollPane) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DefaultListModel(javax.swing.DefaultListModel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) JSplitPane(javax.swing.JSplitPane) JList(javax.swing.JList) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 65 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project knime-core by knime.

the class ColumnSelectionSearchableListPanel method addKeyMouseSelectionListerersToColumnList.

private void addKeyMouseSelectionListerersToColumnList() {
    m_columnList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyChar()) {
                fireConfigurationRequested(Type.CREATION);
            } else if (KeyEvent.VK_DELETE == e.getKeyChar()) {
                fireConfigurationRequested(Type.DELETION);
            }
        }
    });
    m_columnList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                fireConfigurationRequested(Type.CREATION);
            }
        }
    });
    m_columnList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            fireConfigurationRequested(Type.SELECTION);
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

ListSelectionEvent (javax.swing.event.ListSelectionEvent)129 ListSelectionListener (javax.swing.event.ListSelectionListener)120 ActionEvent (java.awt.event.ActionEvent)35 JScrollPane (javax.swing.JScrollPane)32 ActionListener (java.awt.event.ActionListener)29 JPanel (javax.swing.JPanel)28 MouseEvent (java.awt.event.MouseEvent)25 BorderLayout (java.awt.BorderLayout)21 JButton (javax.swing.JButton)20 Dimension (java.awt.Dimension)18 JLabel (javax.swing.JLabel)18 JBList (com.intellij.ui.components.JBList)16 MouseAdapter (java.awt.event.MouseAdapter)15 FlowLayout (java.awt.FlowLayout)11 Insets (java.awt.Insets)11 JList (javax.swing.JList)11 NotNull (org.jetbrains.annotations.NotNull)11 KeyAdapter (java.awt.event.KeyAdapter)10 KeyEvent (java.awt.event.KeyEvent)10 ArrayList (java.util.ArrayList)10