251 |
private PropertyChangeListener propertyChangeListener; |
private PropertyChangeListener propertyChangeListener; |
252 |
private FocusListener focusListener; |
private FocusListener focusListener; |
253 |
private TreeSelectionListener treeSelectionListener; |
private TreeSelectionListener treeSelectionListener; |
254 |
private MouseInputListener mouseInputListener; |
private MouseListener mouseListener; |
255 |
private KeyListener keyListener; |
private KeyListener keyListener; |
256 |
private PropertyChangeListener selectionModelPropertyChangeListener; |
private PropertyChangeListener selectionModelPropertyChangeListener; |
257 |
private ComponentListener componentListener; |
private ComponentListener componentListener; |
272 |
propertyChangeListener = createPropertyChangeListener(); |
propertyChangeListener = createPropertyChangeListener(); |
273 |
focusListener = createFocusListener(); |
focusListener = createFocusListener(); |
274 |
treeSelectionListener = createTreeSelectionListener(); |
treeSelectionListener = createTreeSelectionListener(); |
275 |
mouseInputListener = new MouseInputHandler(null, null, null); |
mouseListener = createMouseListener(); |
276 |
keyListener = createKeyListener(); |
keyListener = createKeyListener(); |
277 |
selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener(); |
selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener(); |
278 |
componentListener = createComponentListener(); |
componentListener = createComponentListener(); |
1019 |
tree.removePropertyChangeListener(propertyChangeListener); |
tree.removePropertyChangeListener(propertyChangeListener); |
1020 |
tree.removeFocusListener(focusListener); |
tree.removeFocusListener(focusListener); |
1021 |
tree.removeTreeSelectionListener(treeSelectionListener); |
tree.removeTreeSelectionListener(treeSelectionListener); |
1022 |
tree.removeMouseListener(mouseInputListener); |
tree.removeMouseListener(mouseListener); |
1023 |
tree.removeKeyListener(keyListener); |
tree.removeKeyListener(keyListener); |
1024 |
tree.removePropertyChangeListener(selectionModelPropertyChangeListener); |
tree.removePropertyChangeListener(selectionModelPropertyChangeListener); |
1025 |
tree.removeComponentListener(componentListener); |
tree.removeComponentListener(componentListener); |
1324 |
tree.addPropertyChangeListener(propertyChangeListener); |
tree.addPropertyChangeListener(propertyChangeListener); |
1325 |
tree.addFocusListener(focusListener); |
tree.addFocusListener(focusListener); |
1326 |
tree.addTreeSelectionListener(treeSelectionListener); |
tree.addTreeSelectionListener(treeSelectionListener); |
1327 |
tree.addMouseListener(mouseInputListener); |
tree.addMouseListener(mouseListener); |
1328 |
tree.addKeyListener(keyListener); |
tree.addKeyListener(keyListener); |
1329 |
tree.addPropertyChangeListener(selectionModelPropertyChangeListener); |
tree.addPropertyChangeListener(selectionModelPropertyChangeListener); |
1330 |
tree.addComponentListener(componentListener); |
tree.addComponentListener(componentListener); |
2225 |
*/ |
*/ |
2226 |
public void mousePressed(MouseEvent e) |
public void mousePressed(MouseEvent e) |
2227 |
{ |
{ |
2228 |
// TODO: What should be done here, if anything? |
Point click = e.getPoint(); |
2229 |
|
TreePath path = getClosestPathForLocation(tree, click.x, click.y); |
2230 |
|
|
2231 |
|
if (path != null) |
2232 |
|
{ |
2233 |
|
bounds = getPathBounds(tree, path); |
2234 |
|
int row = getRowForPath(tree, path); |
2235 |
|
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
2236 |
|
|
2237 |
|
boolean isLeaf = isLeaf(row); |
2238 |
|
|
2239 |
|
TreeCellRenderer tcr = getCellRenderer(); |
2240 |
|
Icon icon; |
2241 |
|
if (isLeaf) |
2242 |
|
icon = UIManager.getIcon("Tree.leafIcon"); |
2243 |
|
else if (tree.isExpanded(path)) |
2244 |
|
icon = UIManager.getIcon("Tree.openIcon"); |
2245 |
|
else |
2246 |
|
icon = UIManager.getIcon("Tree.closedIcon"); |
2247 |
|
|
2248 |
|
if (tcr instanceof DefaultTreeCellRenderer) |
2249 |
|
{ |
2250 |
|
Icon tmp = ((DefaultTreeCellRenderer) tcr).getIcon(); |
2251 |
|
if (tmp != null) |
2252 |
|
icon = tmp; |
2253 |
|
} |
2254 |
|
|
2255 |
|
// add gap*2 for the space before and after the text |
2256 |
|
if (icon != null) |
2257 |
|
bounds.width += icon.getIconWidth() + gap*2; |
2258 |
|
|
2259 |
|
boolean inBounds = bounds.contains(click.x, click.y); |
2260 |
|
if ((inBounds || cntlClick) && tree.isVisible(path)) |
2261 |
|
{ |
2262 |
|
selectPath(tree, path); |
2263 |
|
if (inBounds && e.getClickCount() == 2 && !isLeaf(row)) |
2264 |
|
toggleExpandState(path); |
2265 |
|
|
2266 |
|
if (cntlClick) |
2267 |
|
{ |
2268 |
|
handleExpandControlClick(path, click.x, click.y); |
2269 |
|
if (cellEditor != null) |
2270 |
|
cellEditor.cancelCellEditing(); |
2271 |
|
} |
2272 |
|
else if (tree.isEditable()) |
2273 |
|
startEditing(path, e); |
2274 |
|
} |
2275 |
|
} |
2276 |
} |
} |
2277 |
|
|
2278 |
/** |
/** |
2363 |
*/ |
*/ |
2364 |
public void mousePressed(MouseEvent e) |
public void mousePressed(MouseEvent e) |
2365 |
{ |
{ |
2366 |
Point click = e.getPoint(); |
// TODO: What should be done here, if anything? |
|
TreePath path = getClosestPathForLocation(tree, click.x, click.y); |
|
|
|
|
|
if (path != null) |
|
|
{ |
|
|
bounds = getPathBounds(tree, path); |
|
|
int row = getRowForPath(tree, path); |
|
|
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); |
|
|
|
|
|
boolean isLeaf = isLeaf(row); |
|
|
|
|
|
TreeCellRenderer tcr = getCellRenderer(); |
|
|
Icon icon; |
|
|
if (isLeaf) |
|
|
icon = UIManager.getIcon("Tree.leafIcon"); |
|
|
else if (tree.isExpanded(path)) |
|
|
icon = UIManager.getIcon("Tree.openIcon"); |
|
|
else |
|
|
icon = UIManager.getIcon("Tree.closedIcon"); |
|
|
|
|
|
if (tcr instanceof DefaultTreeCellRenderer) |
|
|
{ |
|
|
Icon tmp = ((DefaultTreeCellRenderer) tcr).getIcon(); |
|
|
if (tmp != null) |
|
|
icon = tmp; |
|
|
} |
|
|
|
|
|
// add gap*2 for the space before and after the text |
|
|
if (icon != null) |
|
|
bounds.width += icon.getIconWidth() + gap*2; |
|
|
|
|
|
boolean inBounds = bounds.contains(click.x, click.y); |
|
|
if ((inBounds || cntlClick) && tree.isVisible(path)) |
|
|
{ |
|
|
selectPath(tree, path); |
|
|
if (inBounds && e.getClickCount() == 2 && !isLeaf(row)) |
|
|
toggleExpandState(path); |
|
|
|
|
|
if (cntlClick) |
|
|
{ |
|
|
handleExpandControlClick(path, click.x, click.y); |
|
|
if (cellEditor != null) |
|
|
cellEditor.cancelCellEditing(); |
|
|
} |
|
|
else if (tree.isEditable()) |
|
|
startEditing(path, e); |
|
|
} |
|
|
} |
|
2367 |
} |
} |
2368 |
|
|
2369 |
/** |
/** |