Search in sources :

Example 41 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project cuba by cuba-platform.

the class VclTestApp method createTableTab.

private Component createTableTab() {
    final JPanel box = new JPanel();
    box.setFocusable(false);
    MigLayout boxLayout = new MigLayout("fill");
    box.setLayout(boxLayout);
    final JScrollPane outerScrollPane = new JScrollPane();
    outerScrollPane.setViewportView(box);
    outerScrollPane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            final Dimension minimumSize = box.getMinimumSize();
            final int width = Math.max(minimumSize.width, outerScrollPane.getViewport().getWidth());
            box.setPreferredSize(new Dimension(width, minimumSize.height));
        }
    });
    JPanel tablePanel = new JPanel();
    MigLayout tablePanellayout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]");
    tablePanel.setLayout(tablePanellayout);
    JPanel topPanel = new JPanel(new FlowLayout());
    topPanel.setVisible(true);
    tablePanel.add(topPanel);
    topPanel.add(new JButton("Button1"));
    topPanel.add(new JButton("Button2"));
    topPanel.add(new JButton("Button3"));
    topPanel.add(new JButton("Button4"));
    topPanel.add(new JButton("Button5"));
    JXTableExt table = new JXTableExt();
    JScrollPane tableScrollPane = new JScrollPane(table);
    // table.setFillsViewportHeight(true);
    tablePanel.add(tableScrollPane, "grow");
    table.setShowGrid(true);
    table.setGridColor(Color.lightGray);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setColumnControlVisible(true);
    table.setModel(new AbstractTableModel() {

        @Override
        public int getRowCount() {
            return 20;
        }

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

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            return rowIndex + "-" + columnIndex;
        }
    });
    CC cc = new CC();
    // cc.growX(0);
    // cc.width("300!");
    cc.width("100%");
    // cc.growY(0.0f);
    cc.height("200!");
    // cc.height("100%");
    box.add(tablePanel);
    boxLayout.setComponentConstraints(tablePanel, cc);
    return outerScrollPane;
}
Also used : CC(net.miginfocom.layout.CC) MigLayout(net.miginfocom.swing.MigLayout) AbstractTableModel(javax.swing.table.AbstractTableModel) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 42 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project cayenne by apache.

the class MergerTokenSelectorController method checkAllAction.

public void checkAllAction() {
    stopEditing();
    final boolean isCheckAllSelected = view.getCheckAll().isSelected();
    if (isCheckAllSelected) {
        excludedTokens.clear();
    } else {
        excludedTokens.addAll(selectableTokensList);
    }
    final AbstractTableModel model = (AbstractTableModel) view.getTokens().getModel();
    model.fireTableDataChanged();
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 43 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project omegat by omegat-org.

the class RepositoriesMappingController method initTableModels.

@SuppressWarnings("serial")
void initTableModels() {
    modelRepo = new AbstractTableModel() {

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (rowIndex >= listRepo.size()) {
                return null;
            }
            RowRepo r = listRepo.get(rowIndex);
            switch(columnIndex) {
                case 0:
                    return r.type == null ? null : r.type.getLocalizedString();
                case 1:
                    return r.url;
            }
            return null;
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            RowRepo r = listRepo.get(rowIndex);
            switch(columnIndex) {
                case 0:
                    r.type = (RepoType) aValue;
                    break;
                case 1:
                    String old = r.url;
                    r.url = (String) aValue;
                    changeRepoUrl(old, r.url);
                    reinitRepoUrlDropdown();
                    break;
            }
            repoSizer.reset();
            repoSizer.adjustTableColumns();
        }

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

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

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

        @Override
        public String getColumnName(int column) {
            switch(column) {
                case 0:
                    return OStrings.getString("RMD_TABLE_REPOSITORIES_TYPE");
                case 1:
                    return OStrings.getString("RMD_TABLE_REPOSITORIES_URL");
            }
            return null;
        }
    };
    dialog.tableRepositories.setModel(modelRepo);
    JComboBox<RepoType> comboBox = new JComboBox<>(RepoType.values());
    comboBox.setRenderer(new DelegatingComboBoxRenderer<RepoType, String>() {

        @Override
        protected String getDisplayText(RepoType value) {
            return value == null ? "" : value.getLocalizedString();
        }
    });
    dialog.tableRepositories.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox));
    modelMapping = new AbstractTableModel() {

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (rowIndex >= listMapping.size()) {
                return null;
            }
            RowMapping r = listMapping.get(rowIndex);
            switch(columnIndex) {
                case 0:
                    return r.repoUrl;
                case 1:
                    return r.local;
                case 2:
                    return r.remote;
                case 3:
                    return r.excludes;
                case 4:
                    return r.includes;
            }
            return null;
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            RowMapping r = listMapping.get(rowIndex);
            switch(columnIndex) {
                case 0:
                    r.repoUrl = (String) aValue;
                    break;
                case 1:
                    r.local = (String) aValue;
                    break;
                case 2:
                    r.remote = (String) aValue;
                    break;
                case 3:
                    r.excludes = (String) aValue;
                    break;
                case 4:
                    r.includes = (String) aValue;
                    break;
            }
            mappingSizer.reset();
            mappingSizer.adjustTableColumns();
        }

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

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

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

        @Override
        public String getColumnName(int column) {
            switch(column) {
                case 0:
                    return OStrings.getString("RMD_TABLE_MAPPING_REPO");
                case 1:
                    return OStrings.getString("RMD_TABLE_MAPPING_LOCAL");
                case 2:
                    return OStrings.getString("RMD_TABLE_MAPPING_REMOTE");
                case 3:
                    return OStrings.getString("RMD_TABLE_MAPPING_EXCLUDES");
                case 4:
                    return OStrings.getString("RMD_TABLE_MAPPING_INCLUDES");
            }
            return null;
        }
    };
    dialog.tableMapping.setModel(modelMapping);
}
Also used : JComboBox(javax.swing.JComboBox) AbstractTableModel(javax.swing.table.AbstractTableModel) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 44 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project omegat by omegat-org.

the class FilenamePatternsEditorController method show.

public static List<String> show(List<String> excludes) {
    result = null;
    data = new ArrayList<String>(excludes);
    final FilenamePatternsEditor dialog = new FilenamePatternsEditor(Core.getMainWindow().getApplicationFrame(), true);
    @SuppressWarnings("serial") final AbstractTableModel model = new AbstractTableModel() {

        public int getColumnCount() {
            return 1;
        }

        public String getColumnName(int column) {
            return OStrings.getString("FILENAMEPATTERNS_MASK");
        }

        public int getRowCount() {
            return data.size();
        }

        public Object getValueAt(int row, int col) {
            return data.get(row);
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            data.set(rowIndex, aValue.toString());
        }

        public boolean isCellEditable(int row, int col) {
            return true;
        }
    };
    dialog.table.setModel(model);
    dialog.btnOk.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (dialog.table.getCellEditor() != null) {
                dialog.table.getCellEditor().stopCellEditing();
            }
            result = data;
            dialog.dispose();
        }
    });
    dialog.btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });
    dialog.btnAdd.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            data.add("");
            model.fireTableDataChanged();
            dialog.table.changeSelection(data.size() - 1, 0, false, false);
            dialog.table.editCellAt(data.size() - 1, 0);
            dialog.table.transferFocus();
        }
    });
    dialog.btnRemove.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (dialog.table.getSelectedRow() >= 0 && dialog.table.getSelectedRow() < data.size()) {
                data.remove(dialog.table.getSelectedRow());
            }
            model.fireTableDataChanged();
        }
    });
    ListSelectionListener listener = e -> dialog.btnRemove.setEnabled(dialog.table.getSelectedRow() != -1);
    dialog.table.getSelectionModel().addListSelectionListener(listener);
    listener.valueChanged(null);
    dialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
    StaticUIUtils.setEscapeClosable(dialog);
    dialog.getRootPane().setDefaultButton(dialog.btnOk);
    dialog.setVisible(true);
    return result;
}
Also used : List(java.util.List) ActionListener(java.awt.event.ActionListener) Core(org.omegat.core.Core) OStrings(org.omegat.util.OStrings) AbstractTableModel(javax.swing.table.AbstractTableModel) StaticUIUtils(org.omegat.util.gui.StaticUIUtils) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AbstractTableModel(javax.swing.table.AbstractTableModel) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 45 with AbstractTableModel

use of javax.swing.table.AbstractTableModel in project MtgDesktopCompanion by nicho92.

the class DrawProbabilityPanel method initDeck.

private void initDeck() {
    model = new AbstractTableModel() {

        @Override
        public String getColumnName(int t) {
            if (t == 0)
                return "Card";
            else
                return "Turn " + t;
        }

        @Override
        public Object getValueAt(int r, int c) {
            if (c == 0) {
                return calc.getUniqueCards().get(r);
            } else {
                return calc.format(calc.getProbability(c - 1, calc.getUniqueCards().get(r)));
            }
        }

        @Override
        public int getRowCount() {
            return calc.getDeck().getMap().keySet().size();
        }

        @Override
        public int getColumnCount() {
            return maxTurn + 1;
        }
    };
    table.setModel(model);
    model.fireTableDataChanged();
    table.packAll();
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel)

Aggregations

AbstractTableModel (javax.swing.table.AbstractTableModel)46 TableModel (javax.swing.table.TableModel)8 JTable (javax.swing.JTable)7 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 PackageEntry (com.intellij.psi.codeStyle.PackageEntry)4 JFrame (javax.swing.JFrame)4 JBTable (com.intellij.ui.table.JBTable)3 JPanel (javax.swing.JPanel)3 EmptyBorder (javax.swing.border.EmptyBorder)3 JTableHeader (javax.swing.table.JTableHeader)3 IndTestDSep (edu.cmu.tetrad.search.IndTestDSep)2 IntTextField (edu.cmu.tetradapp.util.IntTextField)2 Font (java.awt.Font)2 Point (java.awt.Point)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2