CustomTree.java revision cf364c082dfe5ea566abc3c20bc5546a4629c5eb
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2014 ForgeRock AS
*/
/**
* The tree that is used in different places in the Control Panel (schema
* browser, index browser or the LDAP entries browser). It renders in a
* different manner than the default tree (selection takes the whole width
* of the tree, in a similar manner as happens with trees in Mac OS).
*
*/
public class CustomTree extends JTree
{
private static final long serialVersionUID = -8351107707374485555L;
private JPopupMenu popupMenu;
private final int MAX_ICON_HEIGHT = 18;
/**
* Internal enumeration used to translate mouse events.
*
*/
private enum NewEventType
{
};
/**
* {@inheritDoc}
*/
public void paintComponent(Graphics g)
{
int[] selectedRows = getSelectionRows();
if (selectedRows == null)
{
selectedRows = new int[] {};
}
int nRows = getRowCount();
for ( int i = 0; i < nRows; i++)
{
boolean isSelected = false;
{
if (selectedRows[j] == i)
{
isSelected = true;
break;
}
}
if (isSelected)
{
}
else
{
}
y += rowHeight;
}
if ( remainder > 0 )
{
}
setOpaque(false);
super.paintComponent(g);
}
/**
* Sets a popup menu that will be displayed when the user clicks on the tree.
* @param popMenu the popup menu.
*/
{
}
/**
* Default constructor.
*
*/
public CustomTree()
{
// This mouse listener is used so that when the user clicks on a row,
// the items are selected (is not required to click directly on the label).
// This code tries to have a similar behavior as in Mac OS).
{
private boolean ignoreEvents;
/**
* {@inheritDoc}
*/
{
if (ignoreEvents)
{
return;
}
{
{
}
mods,
false,
// This is done to select the node when the user does a right
// click on Mac OS.
}
{
}
}
{
}
}
/**
* {@inheritDoc}
*/
{
if (ignoreEvents)
{
return;
}
{
}
}
{
}
}
/**
* {@inheritDoc}
*/
{
if (ignoreEvents)
{
return;
}
{
}
}
{
ignoreEvents = true;
// New ArrayList to avoid concurrent modifications (the listeners
// could be unregistering themselves).
for (MouseListener mouseListener :
{
if (mouseListener != this)
{
switch (type)
{
case MOUSE_RELEASED:
break;
case MOUSE_CLICKED:
break;
default:
}
}
}
ignoreEvents = false;
}
{
if (getPathForLocation(x, y) == null)
{
{
if (r != null)
{
// Simulate an event
newEvent = new MouseEvent(
ev.getComponent(),
ev.getModifiersEx(),
newX,
newY,
ev.getClickCount(),
ev.isPopupTrigger(),
}
}
}
return newEvent;
}
};
if (getRowHeight() <= MAX_ICON_HEIGHT)
{
}
}
/**
* {@inheritDoc}
*/
{
super.addMouseListener(mouseListener);
if (mouseListeners == null)
{
}
}
/**
* {@inheritDoc}
*/
{
super.removeMouseListener(mouseListener);
}
private TreePath getWidePathForLocation(int x, int y)
{
if (closestPath != null)
{
if (pathBounds != null &&
{
path = closestPath;
}
}
return path;
}
}