use of javax.swing.table.TableCellRenderer in project jgnash by ccavanaugh.
the class ExpandingTable method prepareRenderer.
/**
* Override prepareRenderer instead of using a custom renderer so the look and feel is preserved
*
* @see javax.swing.JTable#prepareRenderer(javax.swing.table.TableCellRenderer, int, int)
*/
@SuppressWarnings("MagicConstant")
@Override
public Component prepareRenderer(final TableCellRenderer renderer, final int row, final int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (c instanceof JLabel) {
if (!defaultSaved.get()) {
// save the defaults so they can be restored
defaultForeground = c.getForeground();
defaultAlignment = ((JLabel) c).getHorizontalAlignment();
defaultSaved.set(true);
}
E object = model.get(row);
if (column == 0) {
c.setForeground(defaultForeground);
((JLabel) c).setHorizontalAlignment(SwingConstants.LEFT);
if (object != null) {
Icon cachedIcon;
int indent = iconIndent * (model.getVisibleDepth(object) - 1);
if (model.isParent(object)) {
if (model.isExpanded(object)) {
String key = "eo" + indent;
cachedIcon = iconCache.computeIfAbsent(key, k -> IconUtils.createImageIcon(new IndentedIcon(new Icon[] { expandedIcon, openIcon }, indent, iconSpacing)));
} else {
String key = "co" + indent;
cachedIcon = iconCache.computeIfAbsent(key, k -> IconUtils.createImageIcon(new IndentedIcon(new Icon[] { collapsedIcon, closedIcon }, indent, iconSpacing)));
}
} else {
// child without children
String key = "el" + indent;
cachedIcon = iconCache.computeIfAbsent(key, k -> IconUtils.createImageIcon(new IndentedIcon(new Icon[] { new EmptyIndentedIcon(new Icon[] { expandedIcon }, 0), leafIcon }, indent, iconSpacing)));
}
((JLabel) c).setIcon(cachedIcon);
}
} else {
c.setForeground(defaultForeground);
((JLabel) c).setHorizontalAlignment(defaultAlignment);
((JLabel) c).setIcon(null);
}
}
return c;
}
use of javax.swing.table.TableCellRenderer in project cytoscape-api by cytoscape.
the class JTreeTable method getToolTipText.
/**
* The code in this method is copy and pasted from source code to the same
* method in javax.swing.JTable, except for one value change on one line. If
* you'd like to see the change, please read the source code below.
* @param event the mouse event we're reacting to
*/
@Override
public String getToolTipText(MouseEvent event) {
String tip = null;
Point p = event.getPoint();
// Locate the renderer under the event location
int hitColumnIndex = columnAtPoint(p);
int hitRowIndex = rowAtPoint(p);
if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);
// getting the tip
if (component instanceof JComponent) {
// Convert the event to the renderer's coordinate system
Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
// HERE IS THE MODIFICATION FROM javax.swing.JTable:
// p.translate(-cellRect.x, -cellRect.y);
p.translate(-cellRect.x, 0);
// END OF MODIFICATION
MouseEvent newEvent = new MouseEvent(component, event.getID(), event.getWhen(), event.getModifiers(), p.x, p.y, event.getClickCount(), event.isPopupTrigger());
tip = ((JComponent) component).getToolTipText(newEvent);
}
}
// No tip from the renderer get our own tip
if (tip == null)
tip = getToolTipText();
return tip;
}
use of javax.swing.table.TableCellRenderer in project processdash by dtuma.
the class TeamMemberListTable method setupTableColumnHeader.
/** Create and configure the column header for the table */
private void setupTableColumnHeader() {
// do not allow columns to be reordered. (That wouldn't make sense for
// our weekly data columns, which appear in chronological order.
getTableHeader().setReorderingAllowed(false);
// set the first few "fixed" columns to use a default header renderer,
// and set their size to our predefined column widths.
TableCellRenderer plainRenderer = getTableHeader().getDefaultRenderer();
for (int i = 0; i < COL_WIDTHS.length; i++) {
getColumnModel().getColumn(i).setHeaderRenderer(plainRenderer);
fixWidth(getColumnModel().getColumn(i), COL_WIDTHS[i]);
}
getColumnModel().getColumn(0).setMinWidth(10);
getColumnModel().getColumn(0).setMaxWidth(Integer.MAX_VALUE);
// install a DateHeaderRenderer for all remaining columns, and
// configure the height of the regular renderer to match.
DateHeaderRenderer dateHeaderRenderer = new DateHeaderRenderer(this);
getTableHeader().setDefaultRenderer(dateHeaderRenderer);
if (plainRenderer instanceof JComponent) {
JComponent jc = (JComponent) plainRenderer;
jc.setPreferredSize(dateHeaderRenderer.getPreferredSize());
}
}
use of javax.swing.table.TableCellRenderer in project processdash by dtuma.
the class BlameValueTable method getPreferredCellWidth.
private int getPreferredCellWidth(int row, int column) {
TableCellRenderer cellRenderer = getCellRenderer(row, column);
Component c = prepareRenderer(cellRenderer, row, column);
int width = c.getPreferredSize().width + getIntercellSpacing().width;
return width;
}
use of javax.swing.table.TableCellRenderer in project processdash by dtuma.
the class WBSExcelWriter method writeCellsForNodeData.
private void writeCellsForNodeData(HSSFRow row, WBSNode node, TableColumnModel columns) {
for (int c = 0; c < columns.getColumnCount(); c++) {
TableColumn col = columns.getColumn(c);
int columnIndex = col.getModelIndex();
Object value = data.getValueAt(node, columnIndex);
TableCellRenderer rend = col.getCellRenderer();
if (rend == null)
rend = table.getDefaultRenderer(data.getColumnClass(columnIndex));
Component comp = rend.getTableCellRendererComponent(table, value, false, false, 99, 99);
HSSFCell cell = row.createCell(s(c + 1));
copyCellData(cell, rend, comp, value);
}
}
Aggregations