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();
}
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();
}
}
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;
}
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;
}
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);
}
}
Aggregations