use of javax.swing.table.TableCellRenderer in project adempiere by adempiere.
the class CTable method packColumn.
// autoSize
public void packColumn(TableColumn column) {
int width = 0;
// Header
TableCellRenderer renderer = column.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = null;
if (renderer != null)
comp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, 0, 0);
//
if (comp != null) {
width = comp.getPreferredSize().width;
width = Math.max(width, comp.getWidth());
// Cells
int col = column.getModelIndex();
int maxRow = Math.min(20, getRowCount());
try {
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
if (comp != null) {
int rowWidth = comp.getPreferredSize().width;
width = Math.max(width, rowWidth);
}
}
} catch (Exception e) {
log.log(Level.SEVERE, column.getIdentifier().toString(), e);
}
// Width not greater than 250
width = Math.min(MAXSIZE, width + SLACK);
}
//
column.setPreferredWidth(width);
}
use of javax.swing.table.TableCellRenderer in project adempiere by adempiere.
the class CTable method autoSize.
// stopEditor
/**************************************************************************
* Size Columns.
* @param useColumnIdentifier if false uses plain content -
* otherwise uses Column Identifier to indicate displayed columns
*/
public void autoSize(boolean useColumnIdentifier) {
TableModel model = this.getModel();
int size = model.getColumnCount();
// for all columns
for (int c = 0; c < size; c++) {
TableColumn column = getColumnModel().getColumn(c);
// Not displayed columns
if (useColumnIdentifier && (column.getIdentifier() == null || column.getMaxWidth() == 0 || column.getIdentifier().toString().length() == 0))
continue;
int width = 0;
// Header
TableCellRenderer renderer = column.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = null;
if (renderer != null)
comp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, 0, 0);
//
if (comp != null) {
width = comp.getPreferredSize().width;
width = Math.max(width, comp.getWidth());
// Cells
int col = column.getModelIndex();
int maxRow = Math.min(20, getRowCount());
try {
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
if (comp != null) {
int rowWidth = comp.getPreferredSize().width;
width = Math.max(width, rowWidth);
}
}
} catch (Exception e) {
log.log(Level.SEVERE, column.getIdentifier().toString(), e);
}
// Width not greater than 250
width = Math.min(MAXSIZE, width + SLACK);
}
//
column.setPreferredWidth(width);
}
// for all columns
}
use of javax.swing.table.TableCellRenderer in project adempiere by adempiere.
the class VBrowserTable method autoSize.
/**
* Size Columns.
* Uses Mimimun Column Size
*/
public void autoSize() {
if (!autoResize)
return;
long start = System.currentTimeMillis();
//
// making sure it fits in a column
final int SLACK = 8;
// max size of a column
final int MAXSIZE = 300;
//
TableModel model = this.getModel();
int size = model.getColumnCount();
// for all columns
for (int col = 0; col < size; col++) {
// Column & minimum width
TableColumn tc = this.getColumnModel().getColumn(col);
int width = 0;
if (m_minWidth.size() > col)
width = ((Integer) m_minWidth.get(col)).intValue();
// log.config( "Column=" + col + " " + column.getHeaderValue());
// Header
TableCellRenderer renderer = tc.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
// log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
width = Math.max(width, comp.getPreferredSize().width + SLACK);
// Cells
// first 30 rows
int maxRow = Math.min(30, getRowCount());
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
if (comp != null) {
int rowWidth = comp.getPreferredSize().width + SLACK;
width = Math.max(width, rowWidth);
}
}
// Width not greater ..
width = Math.min(MAXSIZE, width);
tc.setPreferredWidth(width);
// log.fine( "width=" + width);
}
// for all columns
log.finer("Cols=" + size + " - " + (System.currentTimeMillis() - start) + "ms");
}
use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.
the class ExtractedSettingsDialog method buildExtractedSettingsTree.
protected JComponent buildExtractedSettingsTree() {
Collection<Value> unusedValues = ContainerUtil.newHashSet(myValues);
myRoot = new DefaultMutableTreeNode();
for (Map.Entry<LanguageCodeStyleSettingsProvider.SettingsType, Map<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>>> typeEntry : myNameProvider.mySettings.entrySet()) {
DefaultMutableTreeNode settingsNode = null;
for (Map.Entry<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>> groupEntry : typeEntry.getValue().entrySet()) {
CodeStyleSettingPresentation.SettingsGroup group = groupEntry.getKey();
List<CodeStyleSettingPresentation> representations = groupEntry.getValue();
List<CodeStyleSettingPresentation> children = ContainerUtil.emptyList();
DefaultMutableTreeNode groupNode = null;
if (group.name == null && !representations.isEmpty()) {
//there is a setting with name coinciding with group name
if (representations.size() > 1) {
children = representations.subList(1, representations.size());
}
CodeStyleSettingPresentation headRep = representations.get(0);
Value myValue = CodeStyleSettingsNameProvider.getValue(headRep, myValues);
if (myValue == null) {
//value was not found (was not selected)
groupNode = new SettingsTreeNode(headRep.getUiName());
} else {
groupNode = new SettingsTreeNode(headRep.getUiName());
groupNode.add(new SettingsTreeNode(headRep.getValueUiName(myValue.value), headRep, true, myValue));
unusedValues.remove(myValue);
}
} else {
children = representations;
}
for (CodeStyleSettingPresentation representation : children) {
Value myValue = CodeStyleSettingsNameProvider.getValue(representation, myValues);
if (myValue != null) {
if (groupNode == null) {
groupNode = new SettingsTreeNode(group.name);
}
groupNode.add(new SettingsTreeNode(representation.getValueUiName(myValue.value), representation, false, myValue));
unusedValues.remove(myValue);
}
}
if (groupNode != null && !groupNode.isLeaf()) {
if (settingsNode == null) {
settingsNode = new SettingsTreeNode(CodeStyleSettingsNameProvider.getSettingsTypeName(typeEntry.getKey()));
}
settingsNode.add(groupNode);
}
}
if (settingsNode != null) {
myRoot.add(settingsNode);
}
}
//TODO: for now, settings without UI presentation are not displayed. Do something about it.
//unusedValues = ContainerUtil.filter(unusedValues, new Condition<Value>(){
// @Override
// public boolean value(Value value) {
// return value.state == Value.STATE.SELECTED;
// }
//});
//
//DefaultMutableTreeNode unnamedNode = null;
//for (Value value: unusedValues) {
// if (unnamedNode == null) {
// unnamedNode = new SettingsTreeNode("Settings without UI representation");
// }
// unnamedNode.add(new SettingsTreeNode(value.value.toString(), null, false, value.name, value));
//}
//
//if (unnamedNode != null) {
// myRoot.add(unnamedNode);
//}
final ColumnInfo[] COLUMNS = new ColumnInfo[] { getTitleColumnInfo(), getValueColumnInfo() };
ListTreeTableModel model = new ListTreeTableModel(myRoot, COLUMNS);
final TreeTable treeTable = new TreeTable(model) {
@Override
public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
UIUtil.setLineStyleAngled(tableRenderer);
tableRenderer.setRootVisible(false);
tableRenderer.setShowsRootHandles(true);
return tableRenderer;
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellRenderer(row, column);
Object node = treePath.getLastPathComponent();
TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
return renderer == null ? super.getCellRenderer(row, column) : renderer;
}
@Override
public TableCellEditor getCellEditor(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellEditor(row, column);
Object node = treePath.getLastPathComponent();
TableCellEditor editor = COLUMNS[column].getEditor(node);
return editor == null ? super.getCellEditor(row, column) : editor;
}
};
new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
treeTable.setRootVisible(false);
final JTree tree = treeTable.getTree();
tree.setCellRenderer(myTitleRenderer);
tree.setShowsRootHandles(true);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
treeTable.setTableHeader(null);
TreeUtil.expandAll(tree);
treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
titleColumn.setPreferredWidth(maxWidth);
titleColumn.setMinWidth(maxWidth);
titleColumn.setMaxWidth(maxWidth);
titleColumn.setResizable(false);
final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
treeTable.setBackground(UIUtil.getPanelBackground());
treeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
final Dimension screenSize = treeTable.getToolkit().getScreenSize();
JBScrollPane scroller = new JBScrollPane(treeTable) {
@Override
public Dimension getMinimumSize() {
return super.getPreferredSize();
}
};
final Dimension preferredSize = new Dimension(Math.min(screenSize.width / 2, treeTable.getPreferredSize().width), Math.min(screenSize.height / 2, treeTable.getPreferredSize().height));
getRootPane().setPreferredSize(preferredSize);
return scroller;
}
use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.
the class OptionTableWithPreviewPanel method createOptionsTree.
protected TreeTable createOptionsTree(CodeStyleSettings settings) {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
Map<String, DefaultMutableTreeNode> groupsMap = new THashMap<>();
List<Option> sorted = sortOptions(ContainerUtil.concat(myOptions, myCustomOptions));
for (Option each : sorted) {
if (!(myCustomOptions.contains(each) || myAllowedOptions.contains(each.field.getName()) || myShowAllStandardOptions))
continue;
String group = each.groupName;
MyTreeNode newNode = new MyTreeNode(each, each.title, settings);
DefaultMutableTreeNode groupNode = groupsMap.get(group);
if (groupNode != null) {
groupNode.add(newNode);
} else {
String groupName;
if (group == null) {
groupName = each.title;
groupNode = newNode;
} else {
groupName = group;
groupNode = new DefaultMutableTreeNode(groupName);
groupNode.add(newNode);
}
groupsMap.put(groupName, groupNode);
rootNode.add(groupNode);
}
}
ListTreeTableModel model = new ListTreeTableModel(rootNode, COLUMNS);
TreeTable treeTable = new TreeTable(model) {
@Override
public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
UIUtil.setLineStyleAngled(tableRenderer);
tableRenderer.setRootVisible(false);
tableRenderer.setShowsRootHandles(true);
return tableRenderer;
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellRenderer(row, column);
Object node = treePath.getLastPathComponent();
@SuppressWarnings("unchecked") TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
return renderer == null ? super.getCellRenderer(row, column) : renderer;
}
@Override
public TableCellEditor getCellEditor(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null)
return super.getCellEditor(row, column);
Object node = treePath.getLastPathComponent();
@SuppressWarnings("unchecked") TableCellEditor editor = COLUMNS[column].getEditor(node);
return editor == null ? super.getCellEditor(row, column) : editor;
}
};
new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
treeTable.setRootVisible(false);
final JTree tree = treeTable.getTree();
tree.setCellRenderer(myTitleRenderer);
tree.setShowsRootHandles(true);
//myTreeTable.setRowHeight(new JComboBox(new String[]{"Sample Text"}).getPreferredSize().height);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
treeTable.setTableHeader(null);
TreeUtil.expandAll(tree);
treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
titleColumn.setPreferredWidth(maxWidth);
titleColumn.setMinWidth(maxWidth);
titleColumn.setMaxWidth(maxWidth);
titleColumn.setResizable(false);
//final TableColumn levelColumn = treeTable.getColumnModel().getColumn(1);
//TODO[max]: better preffered size...
//TODO[kb]: Did I fixed it by making the last column floating?
//levelColumn.setPreferredWidth(valueSize.width);
//levelColumn.setMaxWidth(valueSize.width);
//levelColumn.setMinWidth(valueSize.width);
//levelColumn.setResizable(false);
final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
return treeTable;
}
Aggregations