Class NodeTreeNodeRenderer

All Implemented Interfaces:
ItemListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditor, TreeCellEditor, TreeCellRenderer

public class NodeTreeNodeRenderer extends JPanel implements TreeCellRenderer, TreeCellEditor, ItemListener
Display and edit a JTree node representing a point-of-interest type in the OpenStreetMap data.
Author:
Andrew Pavlin, KA2DDO
See Also:
  • Constructor Details

    • NodeTreeNodeRenderer

      public NodeTreeNodeRenderer(VisibleCtls visibleCtls)
  • Method Details

    • getTreeCellRendererComponent

      public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
      Sets the value of the current tree cell to value. If selected is true, the cell will be drawn as if selected. If expanded is true the node is currently expanded and if leaf is true the node represents a leaf and if hasFocus is true the node currently has focus. tree is the JTree the receiver is being configured for. Returns the Component that the renderer uses to draw the value.

      The TreeCellRenderer is also responsible for rendering the the cell representing the tree's current DnD drop location if it has one. If this renderer cares about rendering the DnD drop location, it should query the tree directly to see if the given row represents the drop location: JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { // this row represents the current drop location // so render it specially, perhaps with a different color }

      Specified by:
      getTreeCellRendererComponent in interface TreeCellRenderer
      Returns:
      the Component that the renderer uses to draw the value
    • getTreeCellEditorComponent

      public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
      Sets an initial value for the editor. This will cause the editor to stopEditing and lose any partially edited value if the editor is editing when this method is called.

      Returns the component that should be added to the client's Component hierarchy. Once installed in the client's hierarchy this component will then be able to draw and receive user input.

      Specified by:
      getTreeCellEditorComponent in interface TreeCellEditor
      Parameters:
      tree - the JTree that is asking the editor to edit; this parameter can be null
      value - the value of the cell to be edited
      isSelected - true if the cell is to be rendered with selection highlighting
      expanded - true if the node is expanded
      leaf - true if the node is a leaf node
      row - the row index of the node being edited
      Returns:
      the component for editing
    • getCellEditorValue

      public Object getCellEditorValue()
      Returns the value contained in the editor.
      Specified by:
      getCellEditorValue in interface CellEditor
      Returns:
      the value contained in the editor
    • isCellEditable

      public boolean isCellEditable(EventObject anEvent)
      Asks the editor if it can start editing using anEvent. anEvent is in the invoking component coordinate system. The editor can not assume the Component returned by getCellEditorComponent is installed. This method is intended for the use of client to avoid the cost of setting up and installing the editor component if editing is not possible. If editing can be started this method returns true.
      Specified by:
      isCellEditable in interface CellEditor
      Parameters:
      anEvent - the event the editor should use to consider whether to begin editing or not
      Returns:
      true if editing can be started
      See Also:
    • shouldSelectCell

      public boolean shouldSelectCell(EventObject anEvent)
      Returns true if the editing cell should be selected, false otherwise. Typically, the return value is true, because is most cases the editing cell should be selected. However, it is useful to return false to keep the selection from changing for some types of edits. eg. A table that contains a column of check boxes, the user might want to be able to change those checkboxes without altering the selection. (See Netscape Communicator for just such an example) Of course, it is up to the client of the editor to use the return value, but it doesn't need to if it doesn't want to.
      Specified by:
      shouldSelectCell in interface CellEditor
      Parameters:
      anEvent - the event the editor should use to start editing
      Returns:
      true if the editor would like the editing cell to be selected; otherwise returns false
      See Also:
    • stopCellEditing

      public boolean stopCellEditing()
      Tells the editor to stop editing and accept any partially edited value as the value of the editor. The editor returns false if editing was not stopped; this is useful for editors that validate and can not accept invalid entries.
      Specified by:
      stopCellEditing in interface CellEditor
      Returns:
      true if editing was stopped; false otherwise
    • cancelCellEditing

      public void cancelCellEditing()
      Tells the editor to cancel editing and not accept any partially edited value.
      Specified by:
      cancelCellEditing in interface CellEditor
    • addCellEditorListener

      public void addCellEditorListener(CellEditorListener l)
      Adds a listener to the list that's notified when the editor stops, or cancels editing.
      Specified by:
      addCellEditorListener in interface CellEditor
      Parameters:
      l - the CellEditorListener
    • removeCellEditorListener

      public void removeCellEditorListener(CellEditorListener l)
      Removes a listener from the list that's notified
      Specified by:
      removeCellEditorListener in interface CellEditor
      Parameters:
      l - the CellEditorListener
    • itemStateChanged

      public void itemStateChanged(ItemEvent e)
      Invoked when an item has been selected or deselected by the user. The code written for this method performs the operations that need to occur when an item is selected (or deselected).
      Specified by:
      itemStateChanged in interface ItemListener