Search in sources :

Example 36 with TableColumnModel

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

the class ResultTable method setModel.

//  ResultTable
/**
	 *  Set Model
	 *  @param reportModel
	 */
public void setModel(RModel reportModel) {
    log.config(reportModel.toString());
    m_model = reportModel;
    super.setModel(new ResultTableModel(reportModel));
    //
    TableColumnModel tcm = getColumnModel();
    //  Set Editor/Renderer
    for (int i = 0; i < tcm.getColumnCount(); i++) {
        TableColumn tc = tcm.getColumn(i);
        RColumn rc = reportModel.getRColumn(i);
        if (rc.getColHeader().equals(tc.getHeaderValue())) {
            ResultTableCellRenderer rtcr = new ResultTableCellRenderer(reportModel, rc);
            tc.setCellRenderer(rtcr);
        //
        } else
            log.log(Level.SEVERE, "RColumn=" + rc.getColHeader() + " <> TableColumn=" + tc.getHeaderValue());
    }
    autoSize();
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 37 with TableColumnModel

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

the class VHeaderRenderer method handleClickEvent.

//	getTableCellRendererComponent
protected void handleClickEvent(MouseEvent e) {
    JTableHeader header = (JTableHeader) (e.getSource());
    JTable tableView = header.getTable();
    TableColumnModel columnModel = tableView.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = tableView.convertColumnIndexToModel(viewColumn);
    if (viewColumn == m_column && e.getClickCount() == 1 && column != -1) {
        m_check.doClick();
    }
}
Also used : JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel)

Example 38 with TableColumnModel

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

the class ShowUsagesTableCellRenderer method textComponentSpanningWholeRow.

@NotNull
private static Component textComponentSpanningWholeRow(@NotNull SimpleColoredComponent chunks, Color panelBackground, Color panelForeground, final int column, @NotNull final JTable table) {
    final SimpleColoredComponent component = new SimpleColoredComponent() {

        @Override
        protected void doPaint(Graphics2D g) {
            int offset = 0;
            int i = 0;
            final TableColumnModel columnModel = table.getColumnModel();
            while (i < column) {
                offset += columnModel.getColumn(i).getWidth();
                i++;
            }
            g.translate(-offset, 0);
            //if (column == columnModel.getColumnCount()-1) {
            //}
            // should increase the column width so that selection background will be visible even after offset translation
            setSize(getWidth() + offset, getHeight());
            super.doPaint(g);
            g.translate(+offset, 0);
        }

        @NotNull
        @Override
        public Dimension getPreferredSize() {
            //return super.getPreferredSize();
            return column == table.getColumnModel().getColumnCount() - 1 ? super.getPreferredSize() : new Dimension(0, 0);
        // it should span the whole row, so we can't return any specific value here,
        // because otherwise it would be used in the "max width" calculation in com.intellij.find.actions.ShowUsagesAction.calcMaxWidth
        }
    };
    component.setBackground(panelBackground);
    component.setForeground(panelForeground);
    for (SimpleColoredComponent.ColoredIterator iterator = chunks.iterator(); iterator.hasNext(); ) {
        iterator.next();
        String fragment = iterator.getFragment();
        SimpleTextAttributes attributes = iterator.getTextAttributes();
        attributes = attributes.derive(attributes.getStyle(), panelForeground, panelBackground, attributes.getWaveColor());
        component.append(fragment, attributes);
    }
    return component;
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TableColumnModel(javax.swing.table.TableColumnModel) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with TableColumnModel

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

the class EncapsulateFieldsDialog method createTable.

private JComponent createTable() {
    myTableModel = new MyTableModel();
    myTable = new JBTable(myTableModel);
    myTable.setSurrendersFocusOnKeystroke(true);
    MyTableRenderer renderer = new MyTableRenderer();
    TableColumnModel columnModel = myTable.getColumnModel();
    columnModel.getColumn(CHECKED_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    columnModel.getColumn(FIELD_COLUMN).setCellRenderer(renderer);
    columnModel.getColumn(GETTER_COLUMN).setCellRenderer(renderer);
    columnModel.getColumn(SETTER_COLUMN).setCellRenderer(renderer);
    TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECKED_COLUMN));
    myTable.setPreferredScrollableViewportSize(new Dimension(550, myTable.getRowHeight() * 12));
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
    //    JLabel label = new JLabel("Fields to Encapsulate");
    //    CompTitledBorder titledBorder = new CompTitledBorder(label);
    JPanel panel = new JPanel(new BorderLayout());
    Border border = IdeBorderFactory.createTitledBorder(RefactoringBundle.message("encapsulate.fields.fields.to.encapsulate.border.title"), false);
    panel.setBorder(border);
    panel.add(scrollPane);
    // make ESC and ENTER work when focus is in the table
    myTable.registerKeyboardAction(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            TableCellEditor editor = myTable.getCellEditor();
            if (editor != null) {
                editor.cancelCellEditing();
            } else {
                doCancelAction();
            }
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    // make SPACE check/uncheck selected rows
    @NonNls InputMap inputMap = myTable.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
    @NonNls ActionMap actionMap = myTable.getActionMap();
    actionMap.put("enable_disable", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (myTable.isEditing())
                return;
            int[] rows = myTable.getSelectedRows();
            if (rows.length > 0) {
                boolean valueToBeSet = false;
                for (int row : rows) {
                    if (!myCheckedMarks[row]) {
                        valueToBeSet = true;
                        break;
                    }
                }
                for (int row : rows) {
                    myCheckedMarks[row] = valueToBeSet;
                }
                myTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]);
                TableUtil.selectRows(myTable, rows);
            }
        }
    });
    // make ENTER work when the table has focus
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "invokeImpl");
    actionMap.put("invokeImpl", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            TableCellEditor editor = myTable.getCellEditor();
            if (editor != null) {
                editor.stopCellEditing();
            } else {
                clickDefaultButton();
            }
        }
    });
    return panel;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) TableCellEditor(javax.swing.table.TableCellEditor) Border(javax.swing.border.Border)

Example 40 with TableColumnModel

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

the class DualView method addWidthListenersTo.

private void addWidthListenersTo(JTable treeView) {
    TableColumnModel columnModel = treeView.getColumnModel();
    int columnCount = columnModel.getColumnCount();
    for (int i = 0; i < columnCount; i++) {
        columnModel.getColumn(i).addPropertyChangeListener(myPropertyChangeListener);
    }
}
Also used : 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