Search in sources :

Example 6 with TableModelListener

use of javax.swing.event.TableModelListener in project libgdx by libgdx.

the class EditorPanel method setValue.

protected static void setValue(DefaultTableModel tableModel, Object value, int row, int column) {
    TableModelListener[] listeners = tableModel.getTableModelListeners();
    TableModelListener listener = null;
    if (listeners != null && listeners.length > 0) {
        listener = listeners[0];
        tableModel.removeTableModelListener(listener);
    }
    tableModel.setValueAt(value, row, column);
    if (listener != null)
        tableModel.addTableModelListener(listener);
}
Also used : TableModelListener(javax.swing.event.TableModelListener)

Example 7 with TableModelListener

use of javax.swing.event.TableModelListener in project libgdx by libgdx.

the class EffectPanel method initializeComponents.

private void initializeComponents() {
    setLayout(new GridBagLayout());
    {
        JPanel sideButtons = new JPanel(new GridBagLayout());
        add(sideButtons, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        {
            JButton newButton = new JButton("New");
            sideButtons.add(newButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            newButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    newEmitter("Untitled", true);
                }
            });
        }
        {
            JButton newButton = new JButton("Duplicate");
            sideButtons.add(newButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            newButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    duplicateEmitter();
                }
            });
        }
        {
            JButton deleteButton = new JButton("Delete");
            sideButtons.add(deleteButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            deleteButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    deleteEmitter();
                }
            });
        }
        {
            sideButtons.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
        }
        {
            JButton saveButton = new JButton("Save");
            sideButtons.add(saveButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            saveButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    saveEffect();
                }
            });
        }
        {
            JButton openButton = new JButton("Open");
            sideButtons.add(openButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            openButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    openEffect(false);
                }
            });
        }
        {
            JButton mergeButton = new JButton("Merge");
            sideButtons.add(mergeButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            mergeButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    openEffect(true);
                }
            });
        }
        {
            JButton upButton = new JButton("Up");
            sideButtons.add(upButton, new GridBagConstraints(0, -1, 1, 1, 0, 1, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            upButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    move(-1);
                }
            });
        }
        {
            JButton downButton = new JButton("Down");
            sideButtons.add(downButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            downButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    move(1);
                }
            });
        }
    }
    {
        JScrollPane scroll = new JScrollPane();
        add(scroll, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
        {
            emitterTable = new JTable() {

                public Class getColumnClass(int column) {
                    return column == 1 ? Boolean.class : super.getColumnClass(column);
                }
            };
            emitterTable.getTableHeader().setReorderingAllowed(false);
            emitterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            scroll.setViewportView(emitterTable);
            emitterTableModel = new DefaultTableModel(new String[0][0], new String[] { "Emitter", "" });
            emitterTable.setModel(emitterTableModel);
            emitterTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent event) {
                    if (event.getValueIsAdjusting())
                        return;
                    emitterSelected();
                }
            });
            emitterTableModel.addTableModelListener(new TableModelListener() {

                public void tableChanged(TableModelEvent event) {
                    if (event.getColumn() != 1)
                        return;
                    emitterChecked(event.getFirstRow(), (Boolean) emitterTable.getValueAt(event.getFirstRow(), 1));
                }
            });
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) TableModelEvent(javax.swing.event.TableModelEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) TableModelListener(javax.swing.event.TableModelListener)

Example 8 with TableModelListener

use of javax.swing.event.TableModelListener in project smile by haifengl.

the class PageTableModel method initToolBar.

/**
     * Initialize context menu and toolbar.
     */
private void initToolBar() {
    toolbar = new JToolBar();
    toolbar.add(new Button(firstPageAction));
    toolbar.add(new Button(pageUpAction));
    toolbar.add(new Button(pageDownAction));
    toolbar.add(new Button(lastPageAction));
    toolbar.addSeparator();
    toolbar.add(pageSizeLabel);
    toolbar.add(pageSizeField);
    pageSizeField.setText(Integer.toString(getPageSize()));
    pageSizeField.setHorizontalAlignment(JTextField.RIGHT);
    pageSizeField.setAction(pageSizeAction);
    pageSizeField.setMaximumSize(pageSizeField.getPreferredSize());
    toolbar.addSeparator();
    totalRowCountLabel.setText(String.format(totalRowCountLabelFormat, getRealRowCount()));
    toolbar.add(totalRowCountLabel);
    toolbar.add(pageField);
    pageField.setText(Integer.toString(getPage() + 1));
    pageField.setHorizontalAlignment(JTextField.RIGHT);
    pageField.setAction(gotoPageAction);
    pageField.setMaximumSize(pageField.getPreferredSize());
    pageCountLabel.setText(String.format(pageCountLabelFormat, getPageCount()));
    toolbar.add(pageCountLabel);
    setActionEnabled();
    TableModelListener listener = new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent tme) {
            if (tme.getType() == TableModelEvent.INSERT || tme.getType() == TableModelEvent.DELETE) {
                if (getPage() >= getPageCount()) {
                    setPage(getPageCount() - 1);
                }
                totalRowCountLabel.setText(String.format(totalRowCountLabelFormat, getRealRowCount()));
                pageField.setText(Integer.toString(getPage() + 1));
                pageCountLabel.setText(String.format(pageCountLabelFormat, getPageCount()));
            }
        }
    };
    addTableModelListener(listener);
}
Also used : Button(smile.swing.Button) TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener)

Example 9 with TableModelListener

use of javax.swing.event.TableModelListener in project gephi by gephi.

the class ImportCSVUIVisualPanel1 method refreshPreviewTable.

public void refreshPreviewTable() {
    if (selectedFile != null && selectedFile.exists()) {
        try {
            CsvReader reader = new CsvReader(new FileInputStream(selectedFile), getSelectedSeparator(), getSelectedCharset());
            reader.setTrimWhitespace(false);
            String[] headers;
            try {
                reader.readHeaders();
                headers = reader.getHeaders();
            } catch (Exception ex) {
                //Some charsets can be problematic with unreal columns lenght. Don't show table when there are problems
                headers = new String[0];
            }
            columnCount = headers.length;
            //Check for repeated column names:
            Set<String> columnNamesSet = new HashSet<>();
            hasColumnNamesRepeated = false;
            hasSourceNodeColumn = false;
            hasTargetNodeColumn = false;
            int sourceColumnIndex = 0, targetColumnIndex = 0, currentColumn = 0;
            for (String header : headers) {
                if (header.equalsIgnoreCase("source")) {
                    hasSourceNodeColumn = true;
                    sourceColumnIndex = currentColumn;
                }
                if (header.equalsIgnoreCase("target")) {
                    hasTargetNodeColumn = true;
                    targetColumnIndex = currentColumn;
                }
                if (columnNamesSet.contains(header)) {
                    hasColumnNamesRepeated = true;
                    break;
                }
                columnNamesSet.add(header);
                currentColumn++;
            }
            ArrayList<String[]> records = new ArrayList<>();
            hasRowsMissingSourcesOrTargets = false;
            ImportCSVUIWizardAction.Mode mode = getMode();
            if (columnCount > 0) {
                String[] currentRecord;
                while (reader.readRecord()) {
                    int recordColumnCount = reader.getColumnCount();
                    currentRecord = new String[recordColumnCount];
                    for (int i = 0; i < currentRecord.length; i++) {
                        currentRecord[i] = reader.get(i);
                    }
                    // Search for missing source or target columns for edges table
                    if (mode == ImportCSVUIWizardAction.Mode.EDGES_TABLE) {
                        if (recordColumnCount < sourceColumnIndex || currentRecord[sourceColumnIndex].trim().isEmpty() || recordColumnCount < targetColumnIndex || currentRecord[targetColumnIndex].trim().isEmpty()) {
                            hasRowsMissingSourcesOrTargets = true;
                        }
                    }
                    if (records.size() < MAX_ROWS_PREVIEW) {
                        records.add(currentRecord);
                    }
                }
            }
            reader.close();
            final String[] columnNames = headers;
            final String[][] values = records.toArray(new String[0][]);
            previewTable.setModel(new TableModel() {

                @Override
                public int getRowCount() {
                    return values.length;
                }

                @Override
                public int getColumnCount() {
                    return columnNames.length;
                }

                @Override
                public String getColumnName(int columnIndex) {
                    return columnNames[columnIndex];
                }

                @Override
                public Class<?> getColumnClass(int columnIndex) {
                    return String.class;
                }

                @Override
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return false;
                }

                @Override
                public Object getValueAt(int rowIndex, int columnIndex) {
                    if (values[rowIndex].length > columnIndex) {
                        return values[rowIndex][columnIndex];
                    } else {
                        return null;
                    }
                }

                @Override
                public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
                }

                @Override
                public void addTableModelListener(TableModelListener l) {
                }

                @Override
                public void removeTableModelListener(TableModelListener l) {
                }
            });
        } catch (FileNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, getMessage("ImportCSVUIVisualPanel1.validation.error"), getMessage("ImportCSVUIVisualPanel1.validation.file-permissions-error"), JOptionPane.ERROR_MESSAGE);
        }
    }
    wizard1.fireChangeEvent();
    //To fire validation panel messages.
    pathTextField.setText(pathTextField.getText());
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CsvReader(com.csvreader.CsvReader) TableModelListener(javax.swing.event.TableModelListener) TableModel(javax.swing.table.TableModel) HashSet(java.util.HashSet)

Example 10 with TableModelListener

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

the class JavaSnippetNodeDialog method createPanel.

private JPanel createPanel(final boolean isPreview) {
    final JPanel p = new JPanel(new BorderLayout());
    final JComponent snippet = createSnippetPanel();
    final JComponent colsAndVars = createColsAndVarsPanel();
    final JPanel centerPanel = new JPanel(new GridLayout(0, 1));
    final JSplitPane centerSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    centerSplitPane.setLeftComponent(colsAndVars);
    centerSplitPane.setRightComponent(snippet);
    // colsAndVars expands to 0.3, the snippet to 0.7
    centerSplitPane.setResizeWeight(0.3);
    m_inFieldsTable = createInFieldsTable();
    m_outFieldsTable = createOutFieldsTable();
    final TableModelListener tableModelListener = e -> {
        if (e.getType() != TableModelEvent.DELETE) {
            // Updating completion can result in a small delay,
            // so we don't update when fields are removed.
            updateAutocompletion();
        }
    };
    m_inFieldsTable.getTable().getModel().addTableModelListener(tableModelListener);
    m_outFieldsTable.getTable().getModel().addTableModelListener(tableModelListener);
    // use split pane for fields
    m_inFieldsTable.setBorder(BorderFactory.createTitledBorder("Input"));
    m_outFieldsTable.setBorder(BorderFactory.createTitledBorder("Output"));
    final JSplitPane fieldsPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    fieldsPane.setTopComponent(m_inFieldsTable);
    fieldsPane.setBottomComponent(m_outFieldsTable);
    fieldsPane.setOneTouchExpandable(true);
    final JSplitPane mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    mainSplitPane.setTopComponent(centerSplitPane);
    // minimize size of tables at the bottom
    fieldsPane.setPreferredSize(fieldsPane.getMinimumSize());
    mainSplitPane.setBottomComponent(fieldsPane);
    mainSplitPane.setOneTouchExpandable(true);
    // snippet gets more space, table with in/out gets less extra space
    mainSplitPane.setResizeWeight(0.7);
    centerPanel.add(mainSplitPane);
    p.add(centerPanel, BorderLayout.CENTER);
    final JPanel templateInfoPanel = createTemplateInfoPanel(isPreview);
    p.add(templateInfoPanel, BorderLayout.NORTH);
    final JPanel optionsPanel = createOptionsPanel();
    if (optionsPanel != null) {
        p.add(optionsPanel, BorderLayout.SOUTH);
    }
    return p;
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) JavaSnippetSettings(org.knime.base.node.jsnippet.util.JavaSnippetSettings) FieldsTableModel(org.knime.base.node.jsnippet.ui.FieldsTableModel) JavaSnippetDocument(org.knime.base.node.jsnippet.guarded.JavaSnippetDocument) Border(javax.swing.border.Border) NodeDialogPane(org.knime.core.node.NodeDialogPane) ErrorStrip(org.fife.ui.rsyntaxtextarea.ErrorStrip) JarListPanel(org.knime.base.node.jsnippet.ui.JarListPanel) ByteArrayInputStream(java.io.ByteArrayInputStream) JSnippetTextArea(org.knime.base.node.jsnippet.ui.JSnippetTextArea) Map(java.util.Map) ListDataEvent(javax.swing.event.ListDataEvent) TitledBorder(javax.swing.border.TitledBorder) BorderLayout(java.awt.BorderLayout) DefaultTemplateController(org.knime.base.node.jsnippet.template.DefaultTemplateController) TableModelEvent(javax.swing.event.TableModelEvent) Frame(java.awt.Frame) TemplateNodeDialog(org.knime.base.node.jsnippet.template.TemplateNodeDialog) BorderFactory(javax.swing.BorderFactory) FlowVariableList(org.knime.base.node.jsnippet.ui.FlowVariableList) UUID(java.util.UUID) BadLocationException(javax.swing.text.BadLocationException) TemplatesPanel(org.knime.base.node.jsnippet.template.TemplatesPanel) InFieldsTable(org.knime.base.node.jsnippet.ui.InFieldsTable) TemplateProvider(org.knime.base.node.jsnippet.template.TemplateProvider) Dimension(java.awt.Dimension) LanguageSupportFactory(org.fife.rsta.ac.LanguageSupportFactory) JPanel(javax.swing.JPanel) JavaLanguageSupport(org.fife.rsta.ac.java.JavaLanguageSupport) JavaSnippetTemplateProvider(org.knime.base.node.jsnippet.template.JavaSnippetTemplateProvider) LanguageSupport(org.fife.rsta.ac.LanguageSupport) JSplitPane(javax.swing.JSplitPane) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TableColumnModel(javax.swing.table.TableColumnModel) JarManager(org.fife.rsta.ac.java.JarManager) DataTableSpec(org.knime.core.data.DataTableSpec) SyntaxConstants(org.fife.ui.rsyntaxtextarea.SyntaxConstants) FlowVariable(org.knime.core.node.workflow.FlowVariable) NodeSettings(org.knime.core.node.NodeSettings) TableModelListener(javax.swing.event.TableModelListener) JSnippetFieldsController(org.knime.base.node.jsnippet.ui.JSnippetFieldsController) GridLayout(java.awt.GridLayout) NotConfigurableException(org.knime.core.node.NotConfigurableException) SwingUtilities(javax.swing.SwingUtilities) OutFieldsTableModel(org.knime.base.node.jsnippet.ui.OutFieldsTableModel) NodeLogger(org.knime.core.node.NodeLogger) BundleListPanel(org.knime.base.node.jsnippet.ui.BundleListPanel) ViewUtils(org.knime.core.node.util.ViewUtils) AddTemplateDialog(org.knime.base.node.jsnippet.template.AddTemplateDialog) JComponent(javax.swing.JComponent) Column(org.knime.base.node.jsnippet.ui.FieldsTableModel.Column) JavaSnippetTemplate(org.knime.base.node.jsnippet.template.JavaSnippetTemplate) JButton(javax.swing.JButton) Fold(org.fife.ui.rsyntaxtextarea.folding.Fold) ColumnList(org.knime.base.node.jsnippet.ui.ColumnList) IOException(java.io.IOException) File(java.io.File) FoldManager(org.fife.ui.rsyntaxtextarea.folding.FoldManager) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) JScrollPane(javax.swing.JScrollPane) ListDataListener(javax.swing.event.ListDataListener) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane) OutFieldsTable(org.knime.base.node.jsnippet.ui.OutFieldsTable) JLabel(javax.swing.JLabel) GuardedDocument(org.knime.base.node.jsnippet.guarded.GuardedDocument) Collections(java.util.Collections) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) TableModelListener(javax.swing.event.TableModelListener) JComponent(javax.swing.JComponent) JSplitPane(javax.swing.JSplitPane)

Aggregations

TableModelListener (javax.swing.event.TableModelListener)68 TableModelEvent (javax.swing.event.TableModelEvent)54 JScrollPane (javax.swing.JScrollPane)11 Iterator (java.util.Iterator)9 JTable (javax.swing.JTable)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ActionEvent (java.awt.event.ActionEvent)8 ListSelectionListener (javax.swing.event.ListSelectionListener)8 Dimension (java.awt.Dimension)7 ActionListener (java.awt.event.ActionListener)7 JButton (javax.swing.JButton)7 JPanel (javax.swing.JPanel)7 DefaultTableModel (javax.swing.table.DefaultTableModel)6 TableColumn (javax.swing.table.TableColumn)6 ArrayList (java.util.ArrayList)5 GridBagConstraints (java.awt.GridBagConstraints)4 KeyShortcut (com.igormaznitsa.mindmap.swing.panel.utils.KeyShortcut)3 BorderLayout (java.awt.BorderLayout)3 Insets (java.awt.Insets)3 MouseAdapter (java.awt.event.MouseAdapter)3