Search in sources :

Example 61 with TableColumnModel

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

the class SlotMonDataModel method setColumnToHoldEStopButton.

void setColumnToHoldEStopButton(JTable slotTable, int column) {
    TableColumnModel tcm = slotTable.getColumnModel();
    // install the button renderers & editors in this column
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    tcm.getColumn(column).setCellRenderer(buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton()) {

        @Override
        public void mousePressed(MouseEvent e) {
            stopCellEditing();
        }
    };
    tcm.getColumn(column).setCellEditor(buttonEditor);
    // ensure the table rows, columns have enough room for buttons
    slotTable.setRowHeight(new JButton("  " + getValueAt(1, column)).getPreferredSize().height);
    slotTable.getColumnModel().getColumn(column).setPreferredWidth(new JButton("  " + getValueAt(1, column)).getPreferredSize().width);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) MouseEvent(java.awt.event.MouseEvent) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 62 with TableColumnModel

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

the class PacketDataModel method setColumnToHoldButton.

void setColumnToHoldButton(JTable slotTable, int column) {
    TableColumnModel tcm = slotTable.getColumnModel();
    // install the button renderers & editors in this column
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    tcm.getColumn(column).setCellRenderer(buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    tcm.getColumn(column).setCellEditor(buttonEditor);
    // ensure the table rows, columns have enough room for buttons
    slotTable.setRowHeight(new JButton("  " + getValueAt(1, column)).getPreferredSize().height);
    slotTable.getColumnModel().getColumn(column).setPreferredWidth(new JButton("  " + getValueAt(1, column)).getPreferredSize().width);
}
Also used : ButtonEditor(jmri.util.table.ButtonEditor) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) TableCellEditor(javax.swing.table.TableCellEditor) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 63 with TableColumnModel

use of javax.swing.table.TableColumnModel in project jdk8u_jdk by JetBrains.

the class SynthTableUI method paintGrid.

/*
     * Paints the grid lines within <I>aRect</I>, using the grid
     * color set with <I>setGridColor</I>. Paints vertical lines
     * if <code>getShowVerticalLines()</code> returns true and paints
     * horizontal lines if <code>getShowHorizontalLines()</code>
     * returns true.
     */
private void paintGrid(SynthContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) {
    g.setColor(table.getGridColor());
    Rectangle minCell = table.getCellRect(rMin, cMin, true);
    Rectangle maxCell = table.getCellRect(rMax, cMax, true);
    Rectangle damagedArea = minCell.union(maxCell);
    SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(context);
    if (table.getShowHorizontalLines()) {
        int tableWidth = damagedArea.x + damagedArea.width;
        int y = damagedArea.y;
        for (int row = rMin; row <= rMax; row++) {
            y += table.getRowHeight(row);
            synthG.drawLine(context, "Table.grid", g, damagedArea.x, y - 1, tableWidth - 1, y - 1);
        }
    }
    if (table.getShowVerticalLines()) {
        TableColumnModel cm = table.getColumnModel();
        int tableHeight = damagedArea.y + damagedArea.height;
        int x;
        if (table.getComponentOrientation().isLeftToRight()) {
            x = damagedArea.x;
            for (int column = cMin; column <= cMax; column++) {
                int w = cm.getColumn(column).getWidth();
                x += w;
                synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1);
            }
        } else {
            x = damagedArea.x;
            for (int column = cMax; column >= cMin; column--) {
                int w = cm.getColumn(column).getWidth();
                x += w;
                synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1);
            }
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) TableColumnModel(javax.swing.table.TableColumnModel) Point(java.awt.Point)

Example 64 with TableColumnModel

use of javax.swing.table.TableColumnModel in project jdk8u_jdk by JetBrains.

the class SynthTableUI method paintCells.

private void paintCells(SynthContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();
    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();
    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for (int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for (int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for (int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for (int column = cMin + 1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }
    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }
    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
Also used : Rectangle(java.awt.Rectangle) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point)

Example 65 with TableColumnModel

use of javax.swing.table.TableColumnModel in project intellij-plugins by JetBrains.

the class TreeTableRowSorter method sortOnKey.

private void sortOnKey(SortKey key) {
    if (key.getSortOrder() == SortOrder.UNSORTED) {
        return;
    }
    final int columnModelIndex = key.getColumn();
    TableColumnModel colModel = table.getColumnModel();
    int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
    if (modelIndex < 0 || getComparator(modelIndex) == null) {
        return;
    }
    final Comparator<TreeNode> comparator = new ComparatorWrapper<>(getComparator(modelIndex), key.getSortOrder() == SortOrder.ASCENDING);
    final List<TreePath> paths = TreeUtil.collectExpandedPaths(table.getTree());
    if (JTreeUtil.isSorted(paths, comparator, table.getTableModel())) {
        return;
    }
    for (TreePath path : paths) {
        Object node = path.getLastPathComponent();
        if (!(node instanceof DefaultMutableTreeNode)) {
            continue;
        }
        JTreeUtil.sortChildren((DefaultMutableTreeNode) node, comparator, table.getTableModel().getChildCount(node));
    }
    table.reload();
    TreeUtil.restoreExpandedPaths(table.getTree(), paths);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TableColumnModel(javax.swing.table.TableColumnModel)

Aggregations

TableColumnModel (javax.swing.table.TableColumnModel)168 TableColumn (javax.swing.table.TableColumn)66 JTable (javax.swing.JTable)34 JScrollPane (javax.swing.JScrollPane)31 JButton (javax.swing.JButton)30 BoxLayout (javax.swing.BoxLayout)24 TableCellEditor (javax.swing.table.TableCellEditor)23 ButtonEditor (jmri.util.table.ButtonEditor)23 ButtonRenderer (jmri.util.table.ButtonRenderer)23 JLabel (javax.swing.JLabel)22 JPanel (javax.swing.JPanel)22 ActionEvent (java.awt.event.ActionEvent)20 ActionListener (java.awt.event.ActionListener)16 FlowLayout (java.awt.FlowLayout)15 Border (javax.swing.border.Border)13 Iterator (java.util.Iterator)12 Set (java.util.Set)12 JTableHeader (javax.swing.table.JTableHeader)12 TableCellRenderer (javax.swing.table.TableCellRenderer)12 Container (java.awt.Container)10