Package mindmap.client

Source Code of mindmap.client.NodeLayout

package mindmap.client;

import com.smartgwt.client.types.DragAppearance;
import com.smartgwt.client.types.Positioning;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.DragRepositionMoveEvent;
import com.smartgwt.client.widgets.events.DragRepositionMoveHandler;
import com.smartgwt.client.widgets.events.DragRepositionStartEvent;
import com.smartgwt.client.widgets.events.DragRepositionStartHandler;
import com.smartgwt.client.widgets.events.DragRepositionStopEvent;
import com.smartgwt.client.widgets.events.DragRepositionStopHandler;
import com.smartgwt.client.widgets.events.MouseOutEvent;
import com.smartgwt.client.widgets.events.MouseOutHandler;
import com.smartgwt.client.widgets.events.MouseOverEvent;
import com.smartgwt.client.widgets.events.MouseOverHandler;
import com.smartgwt.client.widgets.layout.VLayout;

/**
* A VLayout displaying the entity including the Icon and the operations.
* @author Stuart Clarke
*/
public class NodeLayout extends VLayout implements Comparable<NodeLayout>{
 
  /**
   * The ID of the entity this NodeLayout represents.
   */
  protected int ENTITY_ID;
   
  /**
   * Constructs the NodeLayout using the Icon and Operations.
   * Sets is draggable and applies drag and mouse handlers as required.
   * @param entity The entity associated with this NodeLayout.
   * @param icon The Icon associated with this NodeLayout.
   * @param operations The Operations associated with this NodeLayout.
   */
  public NodeLayout(final MindMap entity, Img icon, final Operations operations){
    ENTITY_ID = entity.ID;
    Label name = new Label("<b>" + entity.NAME + "</b>");
    Label type = new Label("<p align=\"right\"><i><font size=\"1\">" + entity.TYPE + "</font></span></i></p>");
    type.setAutoHeight();
    type.setWidth(Home.IMAGE_SIZE);
    name.setAutoFit(true);
    name.setWrap(true);
    addMember(type);
    addMember(icon);
    addMember(name);
    operations.getMenu();
    addMember(operations.LAYOUT);
    setCanDragReposition(true);
    setDragAppearance(DragAppearance.TARGET);
    setAutoHeight();
    setAutoWidth();
    addMouseOverHandler(new MouseOverHandler(){
      /* (non-Javadoc)
       * @see com.smartgwt.client.widgets.events.MouseOverHandler#onMouseOver(com.smartgwt.client.widgets.events.MouseOverEvent)
       */
      public void onMouseOver(MouseOverEvent event){
        if(entity.ICON_IMG.isVisible())
          bringToFront();
          operations.show();
      }
    });
    addMouseOutHandler(new MouseOutHandler(){
      /* (non-Javadoc)
       * @see com.smartgwt.client.widgets.events.MouseOutHandler#onMouseOut(com.smartgwt.client.widgets.events.MouseOutEvent)
       */
      public void onMouseOut(MouseOutEvent event){
        operations.hide();
      }
    });
    setPosition(Positioning.ABSOLUTE);
    setLeft(entity.POSITION.COORD.LEFT);
    setTop(entity.POSITION.COORD.TOP);
  }
 
  /* (non-Javadoc)
   * @see com.smartgwt.client.widgets.Canvas#setCanDragReposition(java.lang.Boolean)
   */
  public void setCanDragReposition(Boolean canDragReposition){

    super.setCanDragReposition(canDragReposition);
    final MindMap entity = MindMap.get(ENTITY_ID);
    addDragRepositionStartHandler(new DragRepositionStartHandler(){
      /* (non-Javadoc)
       * @see com.smartgwt.client.widgets.events.DragRepositionStartHandler#onDragRepositionStart(com.smartgwt.client.widgets.events.DragRepositionStartEvent)
       */
      public void onDragRepositionStart(DragRepositionStartEvent event){
        Position.cancel();
      }
    });
    addDragRepositionMoveHandler(new DragRepositionMoveHandler(){
      /* (non-Javadoc)
       * @see com.smartgwt.client.widgets.events.DragRepositionMoveHandler#onDragRepositionMove(com.smartgwt.client.widgets.events.DragRepositionMoveEvent)
       */
      public void onDragRepositionMove(DragRepositionMoveEvent event) {
        Connection.update(entity.LOCAL_CONNECTIONS.values());
      }
    });
    addDragRepositionStopHandler(new DragRepositionStopHandler(){
      /* (non-Javadoc)
       * @see com.smartgwt.client.widgets.events.DragRepositionStopHandler#onDragRepositionStop(com.smartgwt.client.widgets.events.DragRepositionStopEvent)
       */
      public void onDragRepositionStop(DragRepositionStopEvent event) {
        entity.POSITION.COORD.LEFT = getLeft();
        entity.POSITION.COORD.TOP = getTop();
        Position.forceDrivenPositioning();
      }
    });
  }

  /* (non-Javadoc)
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  public int compareTo(NodeLayout node){
      final int BEFORE = -1;
      final int EQUAL = 0;
      final int AFTER = 1;
     
      if(MindMap.get(this.ENTITY_ID).POSITION.COORD.OUT < MindMap.get(node.ENTITY_ID).POSITION.COORD.OUT) return BEFORE;
      if(MindMap.get(this.ENTITY_ID).POSITION.COORD.OUT > MindMap.get(node.ENTITY_ID).POSITION.COORD.OUT) return AFTER;
     
      if(this.ENTITY_ID < node.ENTITY_ID) return BEFORE;
      if(this.ENTITY_ID > node.ENTITY_ID) return AFTER;
     
    return EQUAL;
  }
   
  /**
   * Determines whether this NodeLayout is equal to the specified NodeLayout
   * dependannt on the ID of the entity associated with the NodeLayout.
   * @param node The NodeLayout to compare with.
   * @return true is the ID's are equal, false otherwise.
   */
  public boolean equals(NodeLayout node){
    return (this.ENTITY_ID == node.ENTITY_ID);
  }
}
TOP

Related Classes of mindmap.client.NodeLayout

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.