Class GraphPalette

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.graph.GraphPalette
All Implemented Interfaces:
Animation, Editable, StyleListener

public class GraphPalette extends Component

The kinds of node a NodeGraph can be given, as a strip of items to drag onto it: the shapes of a flow chart, or the node types of a node editor.

Form form = new Form("Diagram", new BorderLayout());
NodeGraph graph = new NodeGraph();
form.add(BorderLayout.CENTER, graph);
GraphPalette palette = new GraphPalette(graph);
palette.add(new GraphNodeTemplate("Step").setShape(GraphShapes.RECT));
palette.add(new GraphNodeTemplate("Decision").setShape(GraphShapes.DECISION));
form.add(BorderLayout.WEST, palette);
form.show();

Dragging an item over the graph and letting go adds a node there. Tapping an item arms it instead, and the next tap on the graph's background adds the node, which is the way without a drag. Either way the node is offered to the graph's listeners and its model, as NodeGraph.createNode does.

The palette does not scroll; give it the items that fit, or several palettes.

  • Constructor Details

    • GraphPalette

      public GraphPalette(NodeGraph graph)
      A vertical palette for a graph.
  • Method Details

    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component
    • getGraph

      public NodeGraph getGraph()
      The graph the items are added to.
    • add

      public GraphPalette add(GraphNodeTemplate template)
      Adds an item.
    • remove

      public void remove(GraphNodeTemplate template)
      Removes an item.
    • getTemplates

      public List<GraphNodeTemplate> getTemplates()
      The items, in order. Do not modify the list.
    • isHorizontal

      public boolean isHorizontal()
      True when the items are laid in a row.
    • setHorizontal

      public void setHorizontal(boolean horizontal)
      Lays the items in a row, for a palette above or below the graph, or in a column, the default.
    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

      Parameters
      • g: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component
    • isStickyDrag

      protected boolean isStickyDrag()
      Description copied from class: Component

      Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries. This is useful for spinners etc. where the motion might continue beyond the size of the component

      Returns

      false by default

      Overrides:
      isStickyDrag in class Component
    • pointerPressed

      public void pointerPressed(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer pressed event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerPressed in class Component
    • pointerDragged

      public void pointerDragged(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer dragged event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerDragged in class Component
    • pointerReleased

      public void pointerReleased(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer released event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerReleased in class Component