Search in sources :

Example 36 with TableModelListener

use of javax.swing.event.TableModelListener in project WorldPainter by Captain-Chaos.

the class TerrainRangesTableModel method sortIfNeeded.

private void sortIfNeeded() {
    for (int i = 1; i < rows; i++) {
        if (levels[i] < levels[i - 1]) {
            SortedMap<Integer, Terrain> sortedMap = new TreeMap<>();
            for (int j = 0; j < rows; j++) {
                sortedMap.put(levels[j], terrains[j]);
            }
            int j = 0;
            for (Map.Entry<Integer, Terrain> row : sortedMap.entrySet()) {
                levels[j] = row.getKey();
                terrains[j] = row.getValue();
                j++;
            }
            TableModelEvent event = new TableModelEvent(this, 0, rows - 1);
            for (TableModelListener listener : listeners) {
                listener.tableChanged(event);
            }
            notifyChangeListener();
            break;
        }
    }
}
Also used : Terrain(org.pepsoft.worldpainter.Terrain) TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 37 with TableModelListener

use of javax.swing.event.TableModelListener in project netbeans-mmd-plugin by raydac.

the class FileListPanel method setValueAt.

@Override
public void setValueAt(@Nonnull final Object aValue, final int rowIndex, final int columnIndex) {
    final FileSelector selector = this.files.get(rowIndex);
    switch(columnIndex) {
        case 0:
            selector.setSelected((Boolean) aValue);
            break;
        // NOI18N
        default:
            throw new Error("unexpected column index");
    }
    final TableModelEvent event = new TableModelEvent(this, rowIndex, rowIndex, columnIndex);
    for (final TableModelListener l : this.listeners) {
        l.tableChanged(event);
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener)

Example 38 with TableModelListener

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

the class ManageAddOnsDialog method getInstalledAddOnsTable.

private ZapTable getInstalledAddOnsTable() {
    if (installedAddOnsTable == null) {
        installedAddOnsTable = createCustomZapTable();
        installedAddOnsModel.addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                getUpdateButton().setEnabled(installedAddOnsModel.canUpdateSelected());
                getUpdateAllButton().setEnabled(installedAddOnsModel.getAllUpdates().size() > 0);
                getUninstallButton().setEnabled(installedAddOnsModel.canUninstallSelected());
            }
        });
        installedAddOnsTable.setModel(installedAddOnsModel);
        // icon
        installedAddOnsTable.getColumnModel().getColumn(0).setMaxWidth(20);
        installedAddOnsTable.getColumnExt(0).setSortable(// icon doesn't need to be sortable
        false);
        // name
        installedAddOnsTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        // version
        installedAddOnsTable.getColumnModel().getColumn(2).setPreferredWidth(60);
        installedAddOnsTable.getColumnExt(2).setSortable(// version doesn't need to be sortable
        false);
        installedAddOnsTable.getColumnModel().getColumn(3).setPreferredWidth(// description
        400);
        installedAddOnsTable.getColumnExt(3).setSortable(// description doesn't need to be sortable
        false);
        // update
        installedAddOnsTable.getColumnModel().getColumn(4).setPreferredWidth(60);
        installedAddOnsTable.getColumnExt(4).setSortable(// update doesn't need to be sortable
        false);
        installedAddOnsTable.getColumnModel().getColumn(5).setPreferredWidth(40);
        installedAddOnsTable.getColumnExt(5).setSortable(// checkbox doesn't need to be sortable
        false);
        // Default sort by name (column 1)
        List<RowSorter.SortKey> sortKeys = new ArrayList<>(1);
        sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
        installedAddOnsTable.getRowSorter().setSortKeys(sortKeys);
        installedAddOnsTable.getColumnExt(0).setCellRenderer(new DefaultTableRenderer(new MappedValue(StringValues.EMPTY, IconValues.NONE), JLabel.CENTER));
        installedAddOnsTable.getColumnExt(0).setHighlighters(new CompoundHighlighter(new WarningRunningIssuesHighlighter(AddOnsTableModel.COLUMN_ADD_ON_WRAPPER), new WarningRunningIssuesToolTipHighlighter(AddOnsTableModel.COLUMN_ADD_ON_WRAPPER)));
        installedAddOnsTable.getColumnExt(3).setHighlighters(new CompoundHighlighter(new WarningUpdateIssuesHighlighter(AddOnsTableModel.COLUMN_ADD_ON_WRAPPER), new WarningUpdateIssuesToolTipHighlighter(AddOnsTableModel.COLUMN_ADD_ON_WRAPPER)));
        installedAddOnsTable.getColumnExt(4).addHighlighter(new DisableSelectionHighlighter(AddOnsTableModel.COLUMN_ADD_ON_WRAPPER));
    }
    return installedAddOnsTable;
}
Also used : RowSorter(javax.swing.RowSorter) TableModelEvent(javax.swing.event.TableModelEvent) ArrayList(java.util.ArrayList) MappedValue(org.jdesktop.swingx.renderer.MappedValue) DefaultTableRenderer(org.jdesktop.swingx.renderer.DefaultTableRenderer) TableModelListener(javax.swing.event.TableModelListener) CompoundHighlighter(org.jdesktop.swingx.decorator.CompoundHighlighter)

Example 39 with TableModelListener

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

the class ManageAddOnsDialog method getUninstalledAddOnsTable.

private ZapTable getUninstalledAddOnsTable() {
    if (uninstalledAddOnsTable == null) {
        uninstalledAddOnsTable = createCustomZapTable();
        uninstalledAddOnsModel.addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                getInstallButton().setEnabled(uninstalledAddOnsModel.canIinstallSelected());
                getInstallAllButton().setEnabled(uninstalledAddOnsModel.hasAvailableAddOns());
            }
        });
        uninstalledAddOnsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                getAddOnInfoButton().setEnabled(false);
                if (DesktopUtils.canOpenUrlInBrowser() && getUninstalledAddOnsTable().getSelectedRowCount() == 1) {
                    // convertRowIndexToModel in-case they sorted
                    AddOnWrapper ao = uninstalledAddOnsModel.getAddOnWrapper(getUninstalledAddOnsTable().convertRowIndexToModel(getUninstalledAddOnsTable().getSelectedRow()));
                    if (ao != null && ao.getAddOn().getInfo() != null) {
                        getAddOnInfoButton().setEnabled(true);
                    }
                }
            }
        });
        uninstalledAddOnsTable.setModel(uninstalledAddOnsModel);
        // Icon
        uninstalledAddOnsTable.getColumnModel().getColumn(0).setMaxWidth(20);
        // Icon doesn't need sorting
        uninstalledAddOnsTable.getColumnExt(0).setSortable(false);
        // Status
        uninstalledAddOnsTable.getColumnModel().getColumn(1).setPreferredWidth(50);
        // Name
        uninstalledAddOnsTable.getColumnModel().getColumn(2).setPreferredWidth(150);
        uninstalledAddOnsTable.getColumnModel().getColumn(3).setPreferredWidth(// Description
        300);
        uninstalledAddOnsTable.getColumnExt(3).setSortable(// Description doesn't need sorting
        false);
        uninstalledAddOnsTable.getColumnModel().getColumn(4).setPreferredWidth(// Update (version number)
        60);
        uninstalledAddOnsTable.getColumnExt(4).setSortable(// Update doesn't need sorting
        false);
        // Checkbox
        uninstalledAddOnsTable.getColumnModel().getColumn(5).setPreferredWidth(40);
        uninstalledAddOnsTable.getColumnExt(5).setSortable(// Checkbox doesn't need sorting
        false);
        // Default sort by status (column 1) descending (Release, Beta, Alpha), and name (column
        // 2) ascending
        List<RowSorter.SortKey> sortKeys = new ArrayList<>(2);
        sortKeys.add(new RowSorter.SortKey(1, SortOrder.DESCENDING));
        sortKeys.add(new RowSorter.SortKey(2, SortOrder.ASCENDING));
        uninstalledAddOnsTable.getRowSorter().setSortKeys(sortKeys);
        uninstalledAddOnsTable.getColumnExt(0).setCellRenderer(new DefaultTableRenderer(new MappedValue(StringValues.EMPTY, IconValues.NONE), JLabel.CENTER));
        uninstalledAddOnsTable.getColumnExt(0).setHighlighters(new CompoundHighlighter(new WarningRunningIssuesHighlighter(AddOnsTableModel.COLUMN_ADD_ON_WRAPPER), new WarningRunningIssuesToolTipHighlighter(UninstalledAddOnsTableModel.COLUMN_ADD_ON_WRAPPER)));
        uninstalledAddOnsTable.getColumnExt(5).addHighlighter(new DisableSelectionHighlighter(UninstalledAddOnsTableModel.COLUMN_ADD_ON_WRAPPER));
    }
    return uninstalledAddOnsTable;
}
Also used : RowSorter(javax.swing.RowSorter) TableModelEvent(javax.swing.event.TableModelEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ArrayList(java.util.ArrayList) MappedValue(org.jdesktop.swingx.renderer.MappedValue) DefaultTableRenderer(org.jdesktop.swingx.renderer.DefaultTableRenderer) ListSelectionListener(javax.swing.event.ListSelectionListener) TableModelListener(javax.swing.event.TableModelListener) CompoundHighlighter(org.jdesktop.swingx.decorator.CompoundHighlighter)

Example 40 with TableModelListener

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

the class TemplatePickerPanel method initializeComponents.

protected void initializeComponents(Class<T> type, LoaderButton<T> loaderButton) {
    int i = 0;
    if (loaderButton != null) {
        loaderButton.setListener(this);
        contentPanel.add(loaderButton, new GridBagConstraints(0, i++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
    }
    JScrollPane scroll = new JScrollPane();
    contentPanel.add(scroll, new GridBagConstraints(0, i, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
    {
        templatesTable = new JTable() {

            public Class getColumnClass(int column) {
                return column == 1 ? Boolean.class : super.getColumnClass(column);
            }

            @Override
            public Dimension getPreferredScrollableViewportSize() {
                Dimension dim = super.getPreferredScrollableViewportSize();
                dim.height = getPreferredSize().height;
                return dim;
            }
        };
        templatesTable.getTableHeader().setReorderingAllowed(false);
        templatesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        scroll.setViewportView(templatesTable);
        templatesTableModel = new DefaultTableModel(new String[0][0], new String[] { "Template", "Selected" });
        templatesTable.setModel(templatesTableModel);
        reloadTemplates();
        templatesTableModel.addTableModelListener(new TableModelListener() {

            public void tableChanged(TableModelEvent event) {
                if (event.getColumn() != 1)
                    return;
                int row = event.getFirstRow();
                boolean checked = (Boolean) templatesTable.getValueAt(row, 1);
                if (isOneModelSelectedRequired && (value.size == 1 && !checked)) {
                    EditorPanel.setValue(templatesTableModel, true, row, 1);
                    return;
                }
                templateChecked(row, checked);
            }
        });
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) TableModelEvent(javax.swing.event.TableModelEvent) JTable(javax.swing.JTable) DefaultTableModel(javax.swing.table.DefaultTableModel) TableModelListener(javax.swing.event.TableModelListener) Dimension(java.awt.Dimension)

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