| | |
| | | MOUSE_PRESSED, MOUSE_CLICKED, MOUSE_RELEASED |
| | | }; |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public void paintComponent(Graphics g) |
| | | { |
| | | int[] selectedRows = getSelectionRows(); |
| | |
| | | for ( int i = 0; i < nRows; i++) |
| | | { |
| | | int rowHeight = getRowBounds( i ).height; |
| | | boolean isSelected = false; |
| | | for (int j=0; j<selectedRows.length; j++) |
| | | { |
| | | if (selectedRows[j] == i) |
| | | { |
| | | isSelected = true; |
| | | break; |
| | | } |
| | | } |
| | | if (isSelected) |
| | | if (isRowSelected(selectedRows, i)) |
| | | { |
| | | g.setColor(TreeCellRenderer.selectionBackground); |
| | | } |
| | |
| | | setOpaque(isOpaque); |
| | | } |
| | | |
| | | private boolean isRowSelected(int[] selectedRows, int i) |
| | | { |
| | | for (int j=0; j<selectedRows.length; j++) |
| | | { |
| | | if (selectedRows[j] == i) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Sets a popup menu that will be displayed when the user clicks on the tree. |
| | | * @param popMenu the popup menu. |
| | |
| | | this.popupMenu = popMenu; |
| | | } |
| | | |
| | | /** |
| | | * Default constructor. |
| | | * |
| | | */ |
| | | /** Default constructor. */ |
| | | public CustomTree() |
| | | { |
| | | putClientProperty("JTree.lineStyle", "Angled"); |
| | |
| | | MouseListener mouseListener = new MouseAdapter() |
| | | { |
| | | private boolean ignoreEvents; |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public void mousePressed(MouseEvent ev) |
| | | { |
| | | if (ignoreEvents) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public void mouseReleased(MouseEvent ev) |
| | | { |
| | | if (ignoreEvents) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public void mouseClicked(MouseEvent ev) |
| | | { |
| | | if (ignoreEvents) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public void addMouseListener(MouseListener mouseListener) |
| | | { |
| | | super.addMouseListener(mouseListener); |
| | |
| | | mouseListeners.add(mouseListener); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public void removeMouseListener(MouseListener mouseListener) |
| | | { |
| | | super.removeMouseListener(mouseListener); |