Search in sources :

Example 16 with TableModel

use of javax.swing.table.TableModel in project intellij-community by JetBrains.

the class TableUtil method moveSelectedItemsUp.

public static int moveSelectedItemsUp(@NotNull JTable table) {
    if (table.isEditing()) {
        table.getCellEditor().stopCellEditing();
    }
    TableModel model = table.getModel();
    ListSelectionModel selectionModel = table.getSelectionModel();
    int counter = 0;
    for (int row = 0; row < model.getRowCount(); row++) {
        if (selectionModel.isSelectedIndex(row)) {
            counter++;
            for (int column = 0; column < model.getColumnCount(); column++) {
                Object temp = model.getValueAt(row, column);
                model.setValueAt(model.getValueAt(row - 1, column), row, column);
                model.setValueAt(temp, row - 1, column);
            }
            selectionModel.removeSelectionInterval(row, row);
            selectionModel.addSelectionInterval(row - 1, row - 1);
        }
    }
    Rectangle cellRect = table.getCellRect(selectionModel.getMinSelectionIndex(), 0, true);
    if (cellRect != null) {
        table.scrollRectToVisible(cellRect);
    }
    table.repaint();
    return counter;
}
Also used : TableModel(javax.swing.table.TableModel)

Example 17 with TableModel

use of javax.swing.table.TableModel in project android by JetBrains.

the class ThemeEditorTable method updateRowHeights.

public void updateRowHeights() {
    TableModel rawModel = getModel();
    if (!(rawModel instanceof CellSpanModel)) {
        return;
    }
    CellSpanModel myModel = (CellSpanModel) rawModel;
    int defaultRowHeight = myClassHeights.get(Object.class);
    setRowHeight(defaultRowHeight);
    for (int row = 0; row < myModel.getRowCount(); row++) {
        // Find the maximum row height
        int maxRowHeight = -1;
        for (int col = 0; col < myModel.getColumnCount(); col += myModel.getColumnSpan(row, col)) {
            Class<?> cellClass = myModel.getCellClass(row, col);
            Integer rowHeight = myClassHeights.get(cellClass);
            if (rowHeight != null) {
                maxRowHeight = Math.max(maxRowHeight, rowHeight);
            }
        }
        if (maxRowHeight == -1) {
            // Leave the default size
            continue;
        }
        int viewRow = convertRowIndexToView(row);
        if (viewRow != -1) {
            setRowHeight(viewRow, maxRowHeight);
        }
    }
}
Also used : CellSpanModel(spantable.CellSpanModel) TableModel(javax.swing.table.TableModel) AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel)

Example 18 with TableModel

use of javax.swing.table.TableModel in project android by JetBrains.

the class ThemeEditorTable method getPopupMenuAtCell.

private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
    if (row < 0 || column < 0) {
        return null;
    }
    TableModel rawModel = getModel();
    if (!(rawModel instanceof AttributesTableModel)) {
        return null;
    }
    final AttributesTableModel model = (AttributesTableModel) rawModel;
    AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
    if (contents instanceof AttributesTableModel.AttributeContents) {
        final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
        final EditedStyleItem item = attribute.getValue();
        if (item == null) {
            return null;
        }
        final JBPopupMenu popupMenu = new JBPopupMenu();
        if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
            popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    myGoToListener.goTo(item);
                }
            });
        } else {
            final ResourceResolver resolver = myContext.getResourceResolver();
            assert resolver != null;
            final Project project = myContext.getProject();
            final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
            final File file = new File(resourceValue.getValue());
            final VirtualFileManager manager = VirtualFileManager.getInstance();
            final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
            if (virtualFile != null) {
                popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
                        FileEditorManager.getInstance(project).openEditor(descriptor, true);
                    }
                });
            }
        }
        myJavadocAction.setCurrentItem(item);
        popupMenu.add(myJavadocAction);
        final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
        if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
            popupMenu.add(new AbstractAction("Reset value") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    selectedStyle.removeAttribute(item.getQualifiedName());
                    model.fireTableCellUpdated(attribute.getRowIndex(), 0);
                }
            });
        }
        return popupMenu;
    } else if (contents instanceof AttributesTableModel.ParentAttribute) {
        final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
        if (parentStyle == null) {
            return null;
        }
        final JBPopupMenu menu = new JBPopupMenu();
        menu.add(new AbstractAction(GO_TO_DECLARATION) {

            @Override
            public void actionPerformed(ActionEvent e) {
                myGoToListener.goToParent();
            }
        });
        return menu;
    }
    return null;
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) ActionEvent(java.awt.event.ActionEvent) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) Project(com.intellij.openapi.project.Project) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TableModel(javax.swing.table.TableModel) AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel)

Example 19 with TableModel

use of javax.swing.table.TableModel in project android by JetBrains.

the class ParentRendererEditor method getRendererComponent.

@Override
public Component getRendererComponent(JTable table, ConfiguredThemeEditorStyle value, boolean isSelected, boolean hasFocus, int row, int column) {
    final TableModel model = table.getModel();
    final ConfiguredThemeEditorStyle parent = value.getParent();
    Font font = table.getFont();
    Font scaledFont = ThemeEditorUtils.scaleFontForAttribute(font);
    myParentComboBox.setFont(scaledFont);
    myLabel.setFont(scaledFont);
    myParentComboBox.setEnabled(model.isCellEditable(row, column));
    if (parent == null) {
        myParentComboBox.setModel(NO_PARENT_MODEL);
        myItem = null;
    } else {
        ImmutableList<String> defaultThemeNames = ThemeEditorUtils.getDefaultThemeNames(myContext.getThemeResolver());
        myParentComboBox.setModel(new ParentThemesListModel(defaultThemeNames, parent.getQualifiedName()));
        myItem = value;
    }
    updateVariantsCombo();
    return myPanel;
}
Also used : ParentThemesListModel(com.android.tools.idea.editors.theme.ParentThemesListModel) TableModel(javax.swing.table.TableModel) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 20 with TableModel

use of javax.swing.table.TableModel in project JMRI by JMRI.

the class PaneProgPane method makeCvTable.

void makeCvTable(GridBagConstraints cs, GridBagLayout g, JPanel c) {
    log.debug("starting to build CvTable pane");
    TableRowSorter<TableModel> sorter = new TableRowSorter<>(_cvModel);
    JTable cvTable = new JTable(_cvModel);
    sorter.setComparator(CvTableModel.NUMCOLUMN, new jmri.util.PreferNumericComparator());
    List<RowSorter.SortKey> sortKeys = new ArrayList<>();
    sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
    sorter.setSortKeys(sortKeys);
    cvTable.setRowSorter(sorter);
    cvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
    cvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
    cvTable.setDefaultEditor(JTextField.class, new ValueEditor());
    cvTable.setDefaultEditor(JButton.class, new ValueEditor());
    cvTable.setRowHeight(new JButton("X").getPreferredSize().height);
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    // instead of forcing the columns to fill the frame (and only fill)
    cvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    JScrollPane cvScroll = new JScrollPane(cvTable);
    cvScroll.setColumnHeaderView(cvTable.getTableHeader());
    cs.gridheight = GridBagConstraints.REMAINDER;
    g.setConstraints(cvScroll, cs);
    c.add(cvScroll);
    cs.gridheight = 1;
    // remember which CVs to read/write
    isCvTablePane = true;
    setCvListFromTable();
    _cvTable = true;
    log.debug("end of building CvTable pane");
}
Also used : JScrollPane(javax.swing.JScrollPane) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ArrayList(java.util.ArrayList) ValueEditor(jmri.jmrit.symbolicprog.ValueEditor) JButton(javax.swing.JButton) ValueRenderer(jmri.jmrit.symbolicprog.ValueRenderer) JTable(javax.swing.JTable) TableRowSorter(javax.swing.table.TableRowSorter) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) TableModel(javax.swing.table.TableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel)

Aggregations

TableModel (javax.swing.table.TableModel)53 AbstractTableModel (javax.swing.table.AbstractTableModel)11 JTable (javax.swing.JTable)9 DefaultTableModel (javax.swing.table.DefaultTableModel)9 TableColumn (javax.swing.table.TableColumn)9 ArrayList (java.util.ArrayList)8 TableRowSorter (javax.swing.table.TableRowSorter)8 TableCellRenderer (javax.swing.table.TableCellRenderer)6 ActionEvent (java.awt.event.ActionEvent)5 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 TableCellEditor (javax.swing.table.TableCellEditor)5 Component (java.awt.Component)4 ActionListener (java.awt.event.ActionListener)4 List (java.util.List)4 Set (java.util.Set)4 TableColumnModel (javax.swing.table.TableColumnModel)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)2