use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class ProjectStartupConfigurable method installRenderers.
private void installRenderers() {
final TableColumn checkboxColumn = myTable.getColumnModel().getColumn(ProjectStartupTasksTableModel.IS_SHARED_COLUMN);
final String header = checkboxColumn.getHeaderValue().toString();
final FontMetrics fm = myTable.getFontMetrics(myTable.getTableHeader().getFont());
final int width = -new JBCheckBox().getPreferredSize().width + fm.stringWidth(header + "ww");
TableUtil.setupCheckboxColumn(checkboxColumn, width);
checkboxColumn.setCellRenderer(new BooleanTableCellRenderer());
myTable.getTableHeader().setResizingAllowed(false);
myTable.getTableHeader().setReorderingAllowed(false);
final TableColumn nameColumn = myTable.getColumnModel().getColumn(ProjectStartupTasksTableModel.NAME_COLUMN);
nameColumn.setCellRenderer(new ColoredTableCellRenderer() {
@Override
protected void customizeCellRenderer(JTable table, @Nullable Object value, boolean selected, boolean hasFocus, int row, int column) {
final RunnerAndConfigurationSettings settings = myModel.getAllConfigurations().get(row);
setIcon(settings.getConfiguration().getIcon());
append(settings.getName());
}
});
}
use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class DetectedRootsChooser method setElements.
public void setElements(List<? extends DetectedRootData> roots) {
Set<String> rootTypes = new HashSet<>();
for (DetectedRootData root : roots) {
for (DetectedProjectRoot projectRoot : root.getAllRoots()) {
rootTypes.add(projectRoot.getRootTypeName());
}
}
myModel.setColumnInfos(new ColumnInfo[] { myIncludedColumn, ROOT_COLUMN, ROOT_TYPE_COLUMN });
int max = 0;
for (String rootType : rootTypes) {
max = Math.max(max, myTable.getFontMetrics(myTable.getFont()).stringWidth(rootType));
}
final TableColumn column = myTable.getColumnModel().getColumn(2);
//add space for combobox button
int width = max + 20;
column.setPreferredWidth(width);
column.setMaxWidth(width);
myTable.updateColumnSizes();
List<DetectedRootData> sortedRoots = new ArrayList<>(roots);
Collections.sort(sortedRoots, Comparator.comparing(DetectedRootData::getDirectory));
myModel.setItems(sortedRoots);
}
use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class JavaChangeSignatureDialog method customizeParametersTable.
@Override
protected void customizeParametersTable(TableView<ParameterTableModelItemBase<ParameterInfoImpl>> table) {
final JTable t = table.getComponent();
final TableColumn defaultValue = t.getColumnModel().getColumn(2);
final TableColumn varArg = t.getColumnModel().getColumn(3);
t.removeColumn(defaultValue);
t.removeColumn(varArg);
t.getModel().addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
if (e.getType() == TableModelEvent.INSERT) {
t.getModel().removeTableModelListener(this);
final TableColumnAnimator animator = new TableColumnAnimator(t);
animator.setStep(48);
animator.addColumn(defaultValue, (t.getWidth() - 48) / 3);
animator.addColumn(varArg, 48);
animator.startAndDoWhenDone(() -> t.editCellAt(t.getRowCount() - 1, 0));
animator.start();
}
}
});
}
use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class ChangeClassSignatureDialog method createCenterPanel.
protected JComponent createCenterPanel() {
myTable = new JBTable(myTableModel);
myTable.setStriped(true);
TableColumn nameColumn = myTable.getColumnModel().getColumn(NAME_COLUMN);
TableColumn boundColumn = myTable.getColumnModel().getColumn(BOUND_VALUE_COLUMN);
TableColumn valueColumn = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
Project project = myClass.getProject();
nameColumn.setCellRenderer(new MyCellRenderer());
nameColumn.setCellEditor(new StringTableCellEditor(project));
boundColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
boundColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
valueColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
valueColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
myTable.setPreferredScrollableViewportSize(new Dimension(210, myTable.getRowHeight() * 4));
myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myTable.getSelectionModel().setSelectionInterval(0, 0);
myTable.setSurrendersFocusOnKeystroke(true);
myTable.setCellSelectionEnabled(true);
myTable.setFocusCycleRoot(true);
if (myHideDefaultValueColumn) {
final TableColumn defaultValue = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
myTable.removeColumn(defaultValue);
myTable.getModel().addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
if (e.getType() == TableModelEvent.INSERT) {
myTable.getModel().removeTableModelListener(this);
final TableColumnAnimator animator = new TableColumnAnimator(myTable);
animator.setStep(20);
animator.addColumn(defaultValue, myTable.getWidth() / 2);
animator.startAndDoWhenDone(() -> myTable.editCellAt(myTable.getRowCount() - 1, 0));
animator.start();
}
}
});
}
final JPanel panel = new JPanel(new BorderLayout());
panel.add(SeparatorFactory.createSeparator(RefactoringBundle.message("changeClassSignature.parameters.panel.border.title"), myTable), BorderLayout.NORTH);
panel.add(ToolbarDecorator.createDecorator(myTable).createPanel(), BorderLayout.CENTER);
return panel;
}
use of javax.swing.table.TableColumn in project jgnash by ccavanaugh.
the class JTableUtils method packTable.
public static void packTable(final JTable table) {
if (!(table.getModel() instanceof PackableTableModel)) {
packGenericTable(table);
return;
}
PackableTableModel model = (PackableTableModel) table.getModel();
/*
* Get width of printable portion of the page to control column widths
*/
int tableWidth = table.getWidth();
// calculated optimal widths
int[] widths = new int[model.getColumnCount()];
// total of calculated widths
int tWidth = 0;
for (int i = 0; i < model.getColumnCount(); i++) {
TableColumn col = table.getColumnModel().getColumn(i);
// Get the column header width
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
int width = comp.getMinimumSize().width;
// Find the largest width in the column
int rows = table.getRowCount();
for (int r = 0; r < rows; r++) {
renderer = table.getCellRenderer(r, i);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, i), false, false, r, i);
width = Math.max(width, comp.getMinimumSize().width);
}
widths[i] = width;
if (i != model.getColumnCount() - 1) {
widths[i] += 4;
} else {
widths[i] += MIN_WIDTH_PADDING;
}
tWidth += widths[i];
}
int[] optimizedWidths = widths.clone();
if (tWidth > tableWidth) {
// calculated width is wider than the page... need to compress columns
// integer widths to calc percentage widths
// create a clone so return array is not modified
int[] columnWeights = model.getPreferredColumnWeights().clone();
// total fixed width of columns
int fixedWidth = 0;
for (int i = 0; i < optimizedWidths.length; i++) {
if (columnWeights[i] == 0) {
fixedWidth += optimizedWidths[i];
}
}
// remaining non fixed width that must be compressed
int diff = tableWidth - fixedWidth;
// used to calculate percentages
int totalWeight = 0;
for (int columnWeight : columnWeights) {
totalWeight += columnWeight;
}
int i = 0;
while (i < columnWeights.length) {
if (columnWeights[i] > 0) {
int adj = (int) ((float) columnWeights[i] / (float) totalWeight * diff);
if (optimizedWidths[i] > adj) {
// only change if necessary
optimizedWidths[i] = adj;
} else {
// available difference is reduced
diff -= optimizedWidths[i];
// adjust the weighting
totalWeight -= columnWeights[i];
// reset widths
optimizedWidths = widths.clone();
// do not try to adjust width again
columnWeights[i] = 0;
// restart the loop from the beginning
i = -1;
}
}
i++;
}
}
for (int i = 0; i < model.getColumnCount(); i++) {
TableColumn col = table.getColumnModel().getColumn(i);
col.setPreferredWidth(optimizedWidths[i]);
}
}
Aggregations