Exemplo n.º 1
0
  private UDOCategory findParent(UDOCategory cat, Object obj) {

    if (ListUtil.containsByRef(cat.getUserDefinedOpcodes(), obj)
        || ListUtil.containsByRef(cat.getSubCategories(), obj)) {
      return cat;
    }

    for (Iterator iter = cat.getSubCategories().iterator(); iter.hasNext(); ) {
      UDOCategory c = (UDOCategory) iter.next();

      UDOCategory temp = findParent(c, obj);

      if (temp != null) {
        return temp;
      }
    }

    return null;
  }
Exemplo n.º 2
0
  public int getIndexOfChild(Object parent, Object child) {
    UDOCategory category = (UDOCategory) parent;

    if (category == null || child == null) {
      return -1;
    }

    int retVal = ListUtil.indexOfByRef(category.getSubCategories(), child);

    if (retVal >= 0) {
      return retVal;
    }

    retVal = ListUtil.indexOfByRef(category.getUserDefinedOpcodes(), child);

    if (retVal >= 0) {
      return retVal + category.getSubCategories().size();
    }

    return -1;
  }
Exemplo n.º 3
0
  private Object getPathForObject(UDOCategory current, Object obj, Vector v) {

    if (current == obj) {
      return v;
    }

    if (ListUtil.containsByRef(current.getUserDefinedOpcodes(), obj)) {
      v.add(current);
      return v;
    }

    for (Iterator iter = current.getSubCategories().iterator(); iter.hasNext(); ) {
      UDOCategory cat = (UDOCategory) iter.next();
      Object pathObj = getPathForObject(cat, obj, v);
      if (pathObj != null) {
        v.add(current);
        return v;
      }
    }

    return null;
  }
Exemplo n.º 4
0
  @Override
  public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    Object node = parentpath.getLastPathComponent();

    if (dtde.isDataFlavorSupported(TransferableUDO.UDO_CAT_FLAVOR)) {
      if (!(node instanceof UDOCategory)) {
        dtde.rejectDrop();
        return;
      }

      if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
        dtde.acceptDrop(dtde.getDropAction());

        Transferable tr = dtde.getTransferable();
        try {
          Object transferNode = tr.getTransferData(TransferableUDO.UDO_CAT_FLAVOR);

          UDOCategory udoCategory = (UDOCategory) transferNode;
          UDOCategory parentNode = (UDOCategory) node;

          UDOLibrary udoLibrary = (UDOLibrary) tree.getModel();

          udoLibrary.addCategory(parentNode, udoCategory);

          dtde.dropComplete(true);
        } catch (UnsupportedFlavorException | IOException e) {
          dtde.dropComplete(false);
        }
      } else {
        dtde.rejectDrop();
      }

    } else if (dtde.isDataFlavorSupported(TransferableUDO.UDO_FLAVOR)) {
      dtde.acceptDrop(dtde.getDropAction());

      try {
        Transferable tr = dtde.getTransferable();

        Object transferNode = tr.getTransferData(TransferableUDO.UDO_FLAVOR);

        UserDefinedOpcode udo = (UserDefinedOpcode) transferNode;
        UDOLibrary udoLibrary = (UDOLibrary) tree.getModel();

        // iLibrary.removeInstrument(instrument);
        if (node instanceof UDOCategory) {
          UDOCategory parentNode = (UDOCategory) node;

          udoLibrary.addUDO(parentNode, udo);
        } else if (node instanceof UserDefinedOpcode) {
          UDOCategory parentNode =
              (UDOCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);

          int index = ListUtil.indexOfByRef(parentNode.getUserDefinedOpcodes(), node);

          int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);

          Rectangle bounds = tree.getRowBounds(closestRow);

          if (pt.y > bounds.y + bounds.height) {
            udoLibrary.addUDO(parentNode, udo);
          } else {
            udoLibrary.addUDO(parentNode, index, udo);
          }
        }

        dtde.dropComplete(true);
      } catch (UnsupportedFlavorException | IOException e) {
        dtde.dropComplete(false);
      }
    } else {
      dtde.rejectDrop();
    }
  }