use of javax.swing.table.TableColumn in project smile by haifengl.
the class TableColumnSettings method restoreSettings.
private void restoreSettings() {
TableColumnModel columnModel = table.getColumnModel();
// restore column width
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn col = columnModel.getColumn(i);
int idx = col.getModelIndex();
int width = prefs.getInt(id + "-column-width-" + idx, 0);
if (width != 0) {
col.setPreferredWidth(width);
}
}
// restore column order
TableColumn[] column = new TableColumn[columnModel.getColumnCount()];
for (int i = 0; i < column.length; i++) {
column[i] = columnModel.getColumn(i);
}
// remove all columns
while (columnModel.getColumnCount() > 0) {
columnModel.removeColumn(columnModel.getColumn(0));
}
// add them back with saved order
int visibleColumnCount = prefs.getInt(id + "-visible-column-count", column.length);
for (int i = 0; i < visibleColumnCount; i++) {
int idx = prefs.getInt(id + "-column-order-" + i, i);
columnModel.addColumn(column[idx]);
}
}
use of javax.swing.table.TableColumn in project gephi by gephi.
the class PartitionColorTransformerPanel method setup.
public void setup(PartitionFunction function) {
this.function = function;
NumberFormat formatter = NumberFormat.getPercentInstance();
formatter.setMaximumFractionDigits(2);
Partition partition = function.getPartition();
values = partition.getSortedValues();
List<Object> nullColors = new ArrayList<>();
Color defaultColor = Color.LIGHT_GRAY;
for (Object val : values) {
Color c = partition.getColor(val);
if (c == null) {
nullColors.add(val);
partition.setColor(val, defaultColor);
}
}
int valuesWithColors = values.size() - nullColors.size();
if (!nullColors.isEmpty() && valuesWithColors < 8) {
Color[] cls = PaletteGenerator.generatePalette(Math.min(8, values.size()), 5, new Random(42l));
int i = 0;
for (Object val : nullColors) {
int index = valuesWithColors + i++;
if (index < cls.length) {
partition.setColor(val, cls[index]);
}
}
}
//Model
String[] columnNames = new String[] { "Color", "Partition", "Percentage" };
DefaultTableModel model = new DefaultTableModel(columnNames, values.size()) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 0;
}
};
table.setModel(model);
String countMsg = NbBundle.getMessage(PartitionColorTransformerPanel.class, "PartitionColorTransformerPanel.tooltip.elementsCount");
TableColumn partCol = table.getColumnModel().getColumn(1);
partCol.setCellRenderer(new TextRenderer(null));
TableColumn percCol = table.getColumnModel().getColumn(2);
percCol.setCellRenderer(new TextRenderer(countMsg));
percCol.setPreferredWidth(60);
percCol.setMaxWidth(60);
TableColumn colorCol = table.getColumnModel().getColumn(0);
colorCol.setCellEditor(new ColorChooserEditor());
colorCol.setCellRenderer(new ColorChooserRenderer());
colorCol.setPreferredWidth(16);
colorCol.setMaxWidth(16);
int j = 0;
for (Object value : values) {
String displayName = value == null ? "null" : value.getClass().isArray() ? AttributeUtils.printArray(value) : value.toString();
int count = function.getPartition().count(value);
float percentage = function.getPartition().percentage(value) / 100f;
model.setValueAt(value, j, 0);
model.setValueAt(displayName, j, 1);
String percCount = count + "_(" + formatter.format(percentage) + ")";
model.setValueAt(percCount, j, 2);
j++;
}
}
use of javax.swing.table.TableColumn in project gephi by gephi.
the class PaletteGeneratorPanel method generate.
private void generate() {
int colorCount = Integer.parseInt(colorCountLabel.getText());
int paletteCount = colorCount;
if (limitColorsCheckbox.isSelected()) {
paletteCount = ((Number) limitColorSpinner.getValue()).intValue();
}
selectedPalette = PaletteManager.getInstance().generatePalette(paletteCount, selectedPreset);
if (paletteCount < colorCount) {
Color[] cols = Arrays.copyOf(selectedPalette.getColors(), colorCount);
for (int i = paletteCount; i < cols.length; i++) {
cols[i] = Color.LIGHT_GRAY;
}
selectedPalette = new Palette(cols);
}
String[] columnNames = new String[] { "Color" };
DefaultTableModel model = new DefaultTableModel(columnNames, colorCount) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
colorTable.setModel(model);
TableColumn colorCol = colorTable.getColumnModel().getColumn(0);
colorCol.setCellRenderer(new ColorCellRenderer());
int row = 0;
for (Color c : selectedPalette.getColors()) {
model.setValueAt(c, row++, 0);
}
}
use of javax.swing.table.TableColumn in project gitblit by gitblit.
the class Utils method packColumn.
// Sets the preferred width of the visible column specified by vColIndex.
// The column will be just wide enough to show the column head and the
// widest cell in the column. margin pixels are added to the left and right
// (resulting in an additional width of 2*margin pixels).
private static void packColumn(JTable table, int vColIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width = 0;
// Get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
// Get maximum width of column data
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
// Add margin
width += 2 * margin;
// Set the width
col.setPreferredWidth(width);
}
use of javax.swing.table.TableColumn in project pcgen by PCGen.
the class TableUtils method createToggleButtonSelectionPane.
private static JScrollPane createToggleButtonSelectionPane(JTable table, JTable rowheaderTable, JToggleButton button) {
rowheaderTable.setAutoCreateColumnsFromModel(false);
// force the tables to share models
rowheaderTable.setModel(table.getModel());
rowheaderTable.setSelectionModel(table.getSelectionModel());
rowheaderTable.setRowHeight(table.getRowHeight());
rowheaderTable.setIntercellSpacing(table.getIntercellSpacing());
rowheaderTable.setShowGrid(false);
rowheaderTable.setFocusable(false);
TableColumn column = new TableColumn(-1);
column.setHeaderValue(new Object());
column.setCellRenderer(new TableCellUtilities.ToggleButtonRenderer(button));
rowheaderTable.addColumn(column);
rowheaderTable.setPreferredScrollableViewportSize(new Dimension(20, 0));
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(table);
scrollPane.setRowHeaderView(rowheaderTable);
return scrollPane;
}
Aggregations