use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class DualView method createFlatComponent.
private Component createFlatComponent(DualViewColumnInfo[] columns) {
ArrayList<ColumnInfo> shownColumns = new ArrayList<>();
for (DualViewColumnInfo column : columns) {
if (column.shouldBeShownIsTheTable()) {
shownColumns.add(column);
}
}
ListTableModel flatModel = new ListTableModel(shownColumns.toArray(new ColumnInfo[shownColumns.size()]));
//noinspection unchecked
myFlatView = new TableView(flatModel) {
public TableCellRenderer getCellRenderer(int row, int column) {
return createWrappedRenderer(super.getCellRenderer(row, column));
}
@NotNull
@Override
public Component prepareRenderer(@NotNull TableCellRenderer renderer, int row, int column) {
final Component c = super.prepareRenderer(renderer, row, column);
if (c instanceof JComponent && !myFlatView.getCellSelectionEnabled()) {
((JComponent) c).setBorder(null);
}
return c;
}
@Override
public void doLayout() {
try {
mySuppressStore = true;
super.doLayout();
} finally {
mySuppressStore = false;
}
}
@Override
public void updateColumnSizes() {
// suppress automatic layout, use stored values instead
}
};
myFlatView.setCellSelectionEnabled(false);
myFlatView.setColumnSelectionAllowed(false);
myFlatView.setRowSelectionAllowed(true);
refreshFlatModel();
JPanel result = new JPanel(new BorderLayout());
result.add(ScrollPaneFactory.createScrollPane(myFlatView), BorderLayout.CENTER);
return result;
}
use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class DualView method createTreeColumns.
private static ColumnInfo[] createTreeColumns(DualViewColumnInfo[] columns) {
Collection<ColumnInfo> result = new ArrayList<>();
final ColumnInfo firstColumn = columns[0];
ColumnInfo firstTreeColumn = new ColumnInfo(firstColumn.getName()) {
public Object valueOf(Object object) {
return firstColumn.valueOf(object);
}
public Class getColumnClass() {
return TreeTableModel.class;
}
public boolean isCellEditable(Object o) {
return true;
}
};
result.add(firstTreeColumn);
for (int i = 1; i < columns.length; i++) {
DualViewColumnInfo column = columns[i];
if (column.shouldBeShownIsTheTree())
result.add(column);
}
return result.toArray(new ColumnInfo[result.size()]);
}
use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class TableView method updateColumnSizes.
public void updateColumnSizes() {
final JTableHeader header = getTableHeader();
final TableCellRenderer defaultRenderer = header == null ? null : header.getDefaultRenderer();
final RowSorter<? extends TableModel> sorter = getRowSorter();
final RowSorter.SortKey sortKey = sorter == null ? null : ContainerUtil.getFirstItem(sorter.getSortKeys());
ColumnInfo[] columnInfos = getListTableModel().getColumnInfos();
TableColumnModel columnModel = getColumnModel();
int visibleColumnCount = columnModel.getColumnCount();
int[] sizeMode = new int[visibleColumnCount];
int[] headers = new int[visibleColumnCount];
int[] widths = new int[visibleColumnCount];
int allColumnWidth = 0;
int allColumnCurrent = 0;
int varCount = 0;
Icon sortIcon = UIManager.getIcon("Table.ascendingSortIcon");
// calculate
for (int i = 0; i < visibleColumnCount; i++) {
final TableColumn column = columnModel.getColumn(i);
final ColumnInfo columnInfo = columnInfos[column.getModelIndex()];
TableCellRenderer columnHeaderRenderer = column.getHeaderRenderer();
if (columnHeaderRenderer == null) {
columnHeaderRenderer = defaultRenderer;
}
final Component headerComponent = columnHeaderRenderer == null ? null : columnHeaderRenderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, 0, i);
if (headerComponent != null) {
headers[i] = headerComponent.getPreferredSize().width;
// add sort icon width
if (sorter != null && columnInfo.isSortable() && sortIcon != null && (sortKey == null || sortKey.getColumn() != i)) {
headers[i] += sortIcon.getIconWidth() + (headerComponent instanceof JLabel ? ((JLabel) headerComponent).getIconTextGap() : 0);
}
}
final String maxStringValue;
final String preferredValue;
if (columnInfo.getWidth(this) > 0) {
sizeMode[i] = 1;
int width = columnInfo.getWidth(this);
widths[i] = width;
} else if ((maxStringValue = columnInfo.getMaxStringValue()) != null) {
sizeMode[i] = 2;
widths[i] = getFontMetrics(getFont()).stringWidth(maxStringValue) + columnInfo.getAdditionalWidth();
varCount++;
} else if ((preferredValue = columnInfo.getPreferredStringValue()) != null) {
sizeMode[i] = 3;
widths[i] = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth();
varCount++;
}
allColumnWidth += widths[i];
allColumnCurrent += column.getPreferredWidth();
}
allColumnWidth = Math.max(allColumnWidth, allColumnCurrent);
// apply: distribute available space between resizable columns
// and make sure that header will fit as well
int viewWidth = getParent() != null ? getParent().getWidth() : getWidth();
double gold = 0.5 * (3 - Math.sqrt(5));
int addendum = varCount == 0 || viewWidth < allColumnWidth ? 0 : (int) ((allColumnWidth < gold * viewWidth ? gold * viewWidth : allColumnWidth < (1 - gold) * viewWidth ? (1 - gold) * viewWidth : viewWidth) - allColumnWidth) / varCount;
for (int i = 0; i < visibleColumnCount; i++) {
TableColumn column = columnModel.getColumn(i);
int width = widths[i];
if (sizeMode[i] == 1) {
column.setMaxWidth(width);
column.setPreferredWidth(width);
column.setMinWidth(width);
} else if (sizeMode[i] == 2) {
// do not shrink columns
width = Math.max(column.getPreferredWidth(), Math.max(width + addendum, headers[i]));
column.setPreferredWidth(width);
column.setMaxWidth(width);
} else if (sizeMode[i] == 3) {
// do not shrink columns
width = Math.max(column.getPreferredWidth(), Math.max(width + addendum, headers[i]));
column.setPreferredWidth(width);
}
}
}
use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.
the class InjectionsSettingsUI method createInjectionColumnInfos.
private ColumnInfo[] createInjectionColumnInfos() {
final TableCellRenderer booleanCellRenderer = createBooleanCellRenderer();
final TableCellRenderer displayNameCellRenderer = createDisplayNameCellRenderer();
final TableCellRenderer languageCellRenderer = createLanguageCellRenderer();
final Comparator<InjInfo> languageComparator = (o1, o2) -> Comparing.compare(o1.injection.getInjectedLanguageId(), o2.injection.getInjectedLanguageId());
final Comparator<InjInfo> displayNameComparator = (o1, o2) -> {
final int support = Comparing.compare(o1.injection.getSupportId(), o2.injection.getSupportId());
if (support != 0)
return support;
return Comparing.compare(o1.injection.getDisplayName(), o2.injection.getDisplayName());
};
final ColumnInfo[] columnInfos = { new ColumnInfo<InjInfo, Boolean>(" ") {
@Override
public Class getColumnClass() {
return Boolean.class;
}
@Override
public Boolean valueOf(final InjInfo o) {
return o.injection.isEnabled();
}
@Override
public boolean isCellEditable(final InjInfo injection) {
return true;
}
@Override
public void setValue(final InjInfo injection, final Boolean value) {
injection.injection.setPlaceEnabled(null, value.booleanValue());
}
@Override
public TableCellRenderer getRenderer(final InjInfo injection) {
return booleanCellRenderer;
}
}, new ColumnInfo<InjInfo, InjInfo>("Name") {
@Override
public InjInfo valueOf(final InjInfo info) {
return info;
}
@Override
public Comparator<InjInfo> getComparator() {
return displayNameComparator;
}
@Override
public TableCellRenderer getRenderer(final InjInfo injection) {
return displayNameCellRenderer;
}
}, new ColumnInfo<InjInfo, InjInfo>("Language") {
@Override
public InjInfo valueOf(final InjInfo info) {
return info;
}
@Override
public Comparator<InjInfo> getComparator() {
return languageComparator;
}
@Override
public TableCellRenderer getRenderer(final InjInfo info) {
return languageCellRenderer;
}
} };
if (myInfos.length > 1) {
final TableCellRenderer typeRenderer = createTypeRenderer();
return ArrayUtil.append(columnInfos, new ColumnInfo<InjInfo, String>("Scope") {
@Override
public String valueOf(final InjInfo info) {
return info.bundled ? "Built-in" : info.cfgInfo.title;
}
@Override
public TableCellRenderer getRenderer(final InjInfo injInfo) {
return typeRenderer;
}
@Override
public int getWidth(final JTable table) {
return table.getFontMetrics(table.getFont()).stringWidth(StringUtil.repeatSymbol('m', 6));
}
@Override
public Comparator<InjInfo> getComparator() {
return (o1, o2) -> Comparing.compare(valueOf(o1), valueOf(o2));
}
});
}
return columnInfos;
}
use of com.intellij.util.ui.ColumnInfo in project intellij-plugins by JetBrains.
the class DartConfigurable method createUIComponents.
private void createUIComponents() {
mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
myDartiumPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
final CheckboxTree.CheckboxTreeCellRenderer checkboxTreeCellRenderer = new CheckboxTree.CheckboxTreeCellRenderer() {
@Override
public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (!(value instanceof CheckedTreeNode))
return;
final boolean dartSupportEnabled = myEnableDartSupportCheckBox.isSelected();
final CheckedTreeNode node = (CheckedTreeNode) value;
final Object userObject = node.getUserObject();
if (userObject instanceof Project) {
if (!dartSupportEnabled) {
//disabled state is also used as partially selected, that's why we do not change 'enabled' state if dartSupportEnabled
getCheckbox().setEnabled(false);
}
getTextRenderer().setEnabled(dartSupportEnabled);
getTextRenderer().append(DartBundle.message("project.0", ((Project) userObject).getName()));
} else if (userObject instanceof Module) {
getCheckbox().setEnabled(dartSupportEnabled);
getTextRenderer().setEnabled(dartSupportEnabled);
final Icon moduleIcon = ModuleType.get((Module) userObject).getIcon();
getTextRenderer().setIcon(dartSupportEnabled ? moduleIcon : IconLoader.getDisabledIcon(moduleIcon));
getTextRenderer().append(((Module) userObject).getName());
}
}
};
myModulesCheckboxTreeTable = new CheckboxTreeTable(null, checkboxTreeCellRenderer, new ColumnInfo[] { new TreeColumnInfo("") });
myModulesCheckboxTreeTable.addCheckboxTreeListener(new CheckboxTreeAdapter() {
@Override
public void nodeStateChanged(@NotNull CheckedTreeNode node) {
updateErrorLabel();
}
});
//myModulesCheckboxTreeTable.setRowHeight(myModulesCheckboxTreeTable.getRowHeight() + 2);
myModulesCheckboxTreeTable.getTree().addTreeWillExpandListener(new TreeWillExpandListener() {
public void treeWillExpand(final TreeExpansionEvent event) throws ExpandVetoException {
}
public void treeWillCollapse(final TreeExpansionEvent event) throws ExpandVetoException {
throw new ExpandVetoException(event);
}
});
}
Aggregations