1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
public class TreeTableCellRenderer extends JTree implements TableCellRenderer {
/** Last table/tree row asked to renderer. */
protected int visibleRow;
public TreeTableCellRenderer(TreeModel model) {
super(model);
}
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
//*********************
// pour changer l'icone des feuilles
Icon leafIcon = dtcr.getLeafIcon();
Icon closedIcon = dtcr.getClosedIcon();
Icon openIcon = dtcr.getOpenIcon();
Icon defaultClosedIcon = dtcr.getDefaultClosedIcon();
Icon disabledIcon = dtcr.getDisabledIcon();
Icon icon = dtcr.getIcon();
// dtcr.setLeafIcon(null);
dtcr.setClosedIcon(defaultClosedIcon);
// dtcr.setOpenIcon(defaultClosedIcon);
dtcr.setDisabledIcon(closedIcon);
// dtcr.setIcon(closedIcon);
// dtcr.setOpenIcon(closedIcon);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
/**
* Sets the row height of the tree, and forwards the row height to the
* table.
*/
public void setRowHeight(int rowHeight) {
if (rowHeight > 0) {
super.setRowHeight(rowHeight);
if (JTreeTable.this != null
&& JTreeTable.this.getRowHeight() != rowHeight) {
JTreeTable.this.setRowHeight(getRowHeight());
}
}
}
/**
* This is overridden to set the height to match that of the JTable.
*/
public void setBounds(int x, int y, int w, int h) {
super.setBounds(x, 0, w, JTreeTable.this.getHeight());
}
/**
* Sublcassed to translate the graphics such that the last visible row
* will be drawn at 0,0.
*/
public void paint(Graphics g) {
g.translate(0, -visibleRow * getRowHeight());
super.paint(g);
}
/**
* TreeCellRenderer method. Overridden to update the visible row.
*/
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
if (isSelected)
setBackground(table.getSelectionBackground());
else
setBackground(table.getBackground());
visibleRow = row;
return this;
}
public void removeNode(DefectNode node) {
DefectNode parent = node.getParent();
parent.removeChild(node);
// if the node is a sub-node, update the group is a son of.
parent.refresh();
}
} |
Partager